1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage HTML
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * Utility class working with content language select lists
14 *
15 * @since 1.6
16 */
17 abstract class JHtmlContentLanguage
18 {
19 /**
20 * Cached array of the content language items.
21 *
22 * @var array
23 * @since 1.6
24 */
25 protected static $items = null;
26
27 /**
28 * Get a list of the available content language items.
29 *
30 * @param boolean $all True to include All (*)
31 * @param boolean $translate True to translate All
32 *
33 * @return string
34 *
35 * @see JFormFieldContentLanguage
36 * @since 1.6
37 */
38 public static function existing($all = false, $translate = false)
39 {
40 if (empty(static::$items))
41 {
42 // Get the database object and a new query object.
43 $db = JFactory::getDbo();
44 $query = $db->getQuery(true);
45
46 // Build the query.
47 $query->select('a.lang_code AS value, a.title AS text, a.title_native')
48 ->from('#__languages AS a')
49 ->where('a.published >= 0')
50 ->order('a.title');
51
52 // Set the query and load the options.
53 $db->setQuery($query);
54 static::$items = $db->loadObjectList();
55 }
56
57 if ($all)
58 {
59 $all_option = array(new JObject(array('value' => '*', 'text' => $translate ? JText::alt('JALL', 'language') : 'JALL_LANGUAGE')));
60
61 return array_merge($all_option, static::$items);
62 }
63 else
64 {
65 return static::$items;
66 }
67 }
68 }
69