1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage Language
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 * Utitlity class for multilang
14 *
15 * @since 2.5.4
16 */
17 class JLanguageMultilang
18 {
19 /**
20 * Method to determine if the language filter plugin is enabled.
21 * This works for both site and administrator.
22 *
23 * @return boolean True if site is supporting multiple languages; false otherwise.
24 *
25 * @since 2.5.4
26 */
27 public static function isEnabled()
28 {
29 // Flag to avoid doing multiple database queries.
30 static $tested = false;
31
32 // Status of language filter plugin.
33 static $enabled = false;
34
35 // Get application object.
36 $app = JFactory::getApplication();
37
38 // If being called from the frontend, we can avoid the database query.
39 if ($app->isClient('site'))
40 {
41 $enabled = $app->getLanguageFilter();
42
43 return $enabled;
44 }
45
46 // If already tested, don't test again.
47 if (!$tested)
48 {
49 // Determine status of language filter plugin.
50 $db = JFactory::getDbo();
51 $query = $db->getQuery(true)
52 ->select('enabled')
53 ->from($db->quoteName('#__extensions'))
54 ->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
55 ->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
56 ->where($db->quoteName('element') . ' = ' . $db->quote('languagefilter'));
57 $db->setQuery($query);
58
59 $enabled = $db->loadResult();
60 $tested = true;
61 }
62
63 return (bool) $enabled;
64 }
65
66 /**
67 * Method to return a list of published site languages.
68 *
69 * @return array of language extension objects.
70 *
71 * @since 3.5
72 * @deprecated 3.7.0 Use JLanguageHelper::getInstalledLanguages(0) instead.
73 */
74 public static function getSiteLangs()
75 {
76 JLog::add(__METHOD__ . ' is deprecated. Use JLanguageHelper::getInstalledLanguages(0) instead.', JLog::WARNING, 'deprecated');
77
78 return JLanguageHelper::getInstalledLanguages(0);
79 }
80
81 /**
82 * Method to return a list of language home page menu items.
83 *
84 * @return array of menu objects.
85 *
86 * @since 3.5
87 */
88 public static function getSiteHomePages()
89 {
90 // To avoid doing duplicate database queries.
91 static $multilangSiteHomePages = null;
92
93 if (!isset($multilangSiteHomePages))
94 {
95 // Check for Home pages languages.
96 $db = JFactory::getDbo();
97 $query = $db->getQuery(true)
98 ->select('language')
99 ->select('id')
100 ->from($db->quoteName('#__menu'))
101 ->where('home = 1')
102 ->where('published = 1')
103 ->where('client_id = 0');
104 $db->setQuery($query);
105
106 $multilangSiteHomePages = $db->loadObjectList('language');
107 }
108
109 return $multilangSiteHomePages;
110 }
111 }
112