forked from joomla/joomla-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultilanguage.php
More file actions
125 lines (105 loc) · 3.6 KB
/
Multilanguage.php
File metadata and controls
125 lines (105 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Language;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Application\CMSWebApplicationInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Menu\MenuItem;
use Joomla\CMS\Menu\SiteMenu;
use Joomla\Database\DatabaseInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Utility class for multilang
*
* @since 2.5.4
*/
class Multilanguage
{
/**
* Flag indicating multilanguage functionality is enabled.
*
* @var boolean
* @since 4.0.0
*/
public static $enabled = false;
/**
* Method to determine if the language filter plugin is enabled.
* This works for both site and administrator.
*
* @param ?CMSApplication $app The application
* @param ?DatabaseInterface $db The database
*
* @return boolean True if site is supporting multiple languages; false otherwise.
*
* @since 2.5.4
*/
public static function isEnabled(?CMSApplication $app = null, ?DatabaseInterface $db = null)
{
// Flag to avoid doing multiple database queries.
static $tested = false;
// Do not proceed with testing if the flag is true
if (static::$enabled) {
return true;
}
// Get application object.
$app = $app ?: Factory::getApplication();
// If being called from the frontend, we can avoid the database query.
if ($app->isClient('site')) {
static::$enabled = $app->getLanguageFilter();
return static::$enabled;
}
// If already tested, don't test again.
if (!$tested) {
// Determine status of language filter plugin.
$db = $db ?: Factory::getDbo();
$query = $db->createQuery()
->select($db->quoteName('enabled'))
->from($db->quoteName('#__extensions'))
->where(
[
$db->quoteName('type') . ' = ' . $db->quote('plugin'),
$db->quoteName('folder') . ' = ' . $db->quote('system'),
$db->quoteName('element') . ' = ' . $db->quote('languagefilter'),
]
);
$db->setQuery($query);
static::$enabled = (bool) $db->loadResult();
$tested = true;
}
return static::$enabled;
}
/**
* Method to return a list of language home page menu items.
*
* @return MenuItem[] array of menu item objects.
*
* @since 3.5
*/
public static function getSiteHomePages(?DatabaseInterface $db = null)
{
$app = Factory::getApplication();
if ($app instanceof CMSWebApplicationInterface) {
return $app->getMenu('site')->getHomepages();
}
// To avoid doing duplicate discover.
static $multilangSiteHomePages;
if ($multilangSiteHomePages === null) {
$multilangSiteHomePages = [];
// Get all site homepages.
/** @var SiteMenu $menu */
$menu = Factory::getApplication()->getMenu('site');
$items = $menu->getItems(['home', 'language', 'access'], [1, null, null]);
foreach ($items as $item) {
$multilangSiteHomePages[$item->language] = $item;
}
}
return $multilangSiteHomePages;
}
}