first commit
This commit is contained in:
20
modules/mod_languages/mod_languages.php
Normal file
20
modules/mod_languages/mod_languages.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_languages
|
||||
*
|
||||
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Helper\ModuleHelper;
|
||||
use Joomla\Module\Languages\Site\Helper\LanguagesHelper;
|
||||
|
||||
$headerText = $params->get('header_text');
|
||||
$footerText = $params->get('footer_text');
|
||||
$list = LanguagesHelper::getList($params);
|
||||
|
||||
require ModuleHelper::getLayoutPath('mod_languages', $params->get('layout', 'default'));
|
||||
151
modules/mod_languages/mod_languages.xml
Normal file
151
modules/mod_languages/mod_languages.xml
Normal file
@ -0,0 +1,151 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="module" client="site" method="upgrade">
|
||||
<name>mod_languages</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2010-02</creationDate>
|
||||
<copyright>(C) 2010 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>3.5.0</version>
|
||||
<description>MOD_LANGUAGES_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Module\Languages</namespace>
|
||||
<files>
|
||||
<filename module="mod_languages">mod_languages.php</filename>
|
||||
<folder>src</folder>
|
||||
<folder>tmpl</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/mod_languages.ini</language>
|
||||
<language tag="en-GB">language/en-GB/mod_languages.sys.ini</language>
|
||||
</languages>
|
||||
<help key="Site_Modules:_Language_Switcher" />
|
||||
<config>
|
||||
<fieldset>
|
||||
<field
|
||||
name="language"
|
||||
type="list"
|
||||
label="JFIELD_LANGUAGE_LABEL"
|
||||
description="JFIELD_MODULE_LANGUAGE_DESC"
|
||||
validate="options"
|
||||
>
|
||||
<option value="*">JALL</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
<fields name="params">
|
||||
<fieldset name="basic">
|
||||
<field
|
||||
name="header_text"
|
||||
type="textarea"
|
||||
label="MOD_LANGUAGES_FIELD_HEADER_LABEL"
|
||||
filter="safehtml"
|
||||
rows="3"
|
||||
cols="40"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="footer_text"
|
||||
type="textarea"
|
||||
label="MOD_LANGUAGES_FIELD_FOOTER_LABEL"
|
||||
filter="safehtml"
|
||||
rows="3"
|
||||
cols="40"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="dropdown"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="MOD_LANGUAGES_FIELD_DROPDOWN_LABEL"
|
||||
default="0"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="dropdownimage"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="MOD_LANGUAGES_FIELD_DROPDOWN_IMAGE_LABEL"
|
||||
default="1"
|
||||
filter="integer"
|
||||
showon="dropdown:1"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="image"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="MOD_LANGUAGES_FIELD_USEIMAGE_LABEL"
|
||||
default="1"
|
||||
filter="integer"
|
||||
showon="dropdown:0"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="full_name"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="MOD_LANGUAGES_FIELD_FULL_NAME_LABEL"
|
||||
showon="dropdown:1[OR]image:0"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="show_active"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="MOD_LANGUAGES_FIELD_ACTIVE_LABEL"
|
||||
default="1"
|
||||
showon="dropdownimage:1[OR]dropdown:0"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="inline"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="MOD_LANGUAGES_FIELD_INLINE_LABEL"
|
||||
default="1"
|
||||
filter="integer"
|
||||
showon="dropdown:0"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
<fieldset name="advanced">
|
||||
<field
|
||||
name="layout"
|
||||
type="modulelayout"
|
||||
label="JFIELD_ALT_LAYOUT_LABEL"
|
||||
class="form-select"
|
||||
validate="moduleLayout"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="moduleclass_sfx"
|
||||
type="textarea"
|
||||
label="COM_MODULES_FIELD_MODULECLASS_SFX_LABEL"
|
||||
rows="3"
|
||||
validate="CssIdentifier"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
137
modules/mod_languages/src/Helper/LanguagesHelper.php
Normal file
137
modules/mod_languages/src/Helper/LanguagesHelper.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_languages
|
||||
*
|
||||
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Module\Languages\Site\Helper;
|
||||
|
||||
use Joomla\CMS\Association\AssociationServiceInterface;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\CMS\Language\LanguageHelper;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Component\Menus\Administrator\Helper\MenusHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Helper for mod_languages
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
abstract class LanguagesHelper
|
||||
{
|
||||
/**
|
||||
* Gets a list of available languages
|
||||
*
|
||||
* @param \Joomla\Registry\Registry &$params module params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getList(&$params)
|
||||
{
|
||||
$user = Factory::getUser();
|
||||
$lang = Factory::getLanguage();
|
||||
$languages = LanguageHelper::getLanguages();
|
||||
$app = Factory::getApplication();
|
||||
$menu = $app->getMenu();
|
||||
$active = $menu->getActive();
|
||||
|
||||
// Get menu home items
|
||||
$homes = [];
|
||||
$homes['*'] = $menu->getDefault('*');
|
||||
|
||||
foreach ($languages as $item) {
|
||||
$default = $menu->getDefault($item->lang_code);
|
||||
|
||||
if ($default && $default->language === $item->lang_code) {
|
||||
$homes[$item->lang_code] = $default;
|
||||
}
|
||||
}
|
||||
|
||||
// Load associations
|
||||
$assoc = Associations::isEnabled();
|
||||
|
||||
if ($assoc) {
|
||||
if ($active) {
|
||||
$associations = MenusHelper::getAssociations($active->id);
|
||||
}
|
||||
|
||||
$option = $app->getInput()->get('option');
|
||||
$component = $app->bootComponent($option);
|
||||
|
||||
if ($component instanceof AssociationServiceInterface) {
|
||||
$cassociations = $component->getAssociationsExtension()->getAssociationsForItem();
|
||||
} else {
|
||||
// Load component associations
|
||||
$class = str_replace('com_', '', $option) . 'HelperAssociation';
|
||||
\JLoader::register($class, JPATH_SITE . '/components/' . $option . '/helpers/association.php');
|
||||
|
||||
if (class_exists($class) && \is_callable([$class, 'getAssociations'])) {
|
||||
$cassociations = \call_user_func([$class, 'getAssociations']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$levels = $user->getAuthorisedViewLevels();
|
||||
$sitelangs = LanguageHelper::getInstalledLanguages(0);
|
||||
$multilang = Multilanguage::isEnabled();
|
||||
|
||||
// Filter allowed languages
|
||||
foreach ($languages as $i => &$language) {
|
||||
// Do not display language without frontend UI
|
||||
if (!\array_key_exists($language->lang_code, $sitelangs)) {
|
||||
unset($languages[$i]);
|
||||
} elseif (!isset($homes[$language->lang_code])) {
|
||||
// Do not display language without specific home menu
|
||||
unset($languages[$i]);
|
||||
} elseif (isset($language->access) && $language->access && !\in_array($language->access, $levels)) {
|
||||
// Do not display language without authorized access level
|
||||
unset($languages[$i]);
|
||||
} else {
|
||||
$language->active = ($language->lang_code === $lang->getTag());
|
||||
|
||||
// Fetch language rtl
|
||||
// If loaded language get from current JLanguage metadata
|
||||
if ($language->active) {
|
||||
$language->rtl = $lang->isRtl();
|
||||
} else {
|
||||
// If not loaded language fetch metadata directly for performance
|
||||
$languageMetadata = LanguageHelper::getMetadata($language->lang_code);
|
||||
$language->rtl = $languageMetadata['rtl'];
|
||||
}
|
||||
|
||||
if ($multilang) {
|
||||
if (isset($cassociations[$language->lang_code])) {
|
||||
$language->link = Route::_($cassociations[$language->lang_code]);
|
||||
} elseif (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) {
|
||||
$itemid = $associations[$language->lang_code];
|
||||
$language->link = Route::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
|
||||
} elseif ($active && $active->language === '*') {
|
||||
$language->link = Route::_('index.php?lang=' . $language->sef . '&Itemid=' . $active->id);
|
||||
} else {
|
||||
if ($language->active) {
|
||||
$language->link = Uri::getInstance()->toString(['path', 'query']);
|
||||
} else {
|
||||
$itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
|
||||
$language->link = Route::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$language->link = Route::_('&Itemid=' . $homes['*']->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $languages;
|
||||
}
|
||||
}
|
||||
120
modules/mod_languages/tmpl/default.php
Normal file
120
modules/mod_languages/tmpl/default.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_languages
|
||||
*
|
||||
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = $app->getDocument()->getWebAssetManager();
|
||||
$wa->registerAndUseStyle('mod_languages', 'mod_languages/template.css');
|
||||
?>
|
||||
<div class="mod-languages">
|
||||
<p class="visually-hidden" id="language_picker_des_<?php echo $module->id; ?>"><?php echo Text::_('MOD_LANGUAGES_DESC'); ?></p>
|
||||
|
||||
<?php if ($headerText) : ?>
|
||||
<div class="mod-languages__pretext pretext"><p><?php echo $headerText; ?></p></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($params->get('dropdown', 0)) : ?>
|
||||
<?php HTMLHelper::_('bootstrap.dropdown', '.dropdown-toggle'); ?>
|
||||
<div class="mod-languages__select btn-group">
|
||||
<?php foreach ($list as $language) : ?>
|
||||
<?php if ($language->active) : ?>
|
||||
<button id="language_btn_<?php echo $module->id; ?>" type="button" data-bs-toggle="dropdown" class="btn btn-secondary dropdown-toggle" aria-haspopup="listbox" aria-labelledby="language_picker_des_<?php echo $module->id; ?> language_btn_<?php echo $module->id; ?>" aria-expanded="false">
|
||||
<?php if ($params->get('dropdownimage', 1) && ($language->image)) : ?>
|
||||
<?php echo HTMLHelper::_('image', 'mod_languages/' . $language->image . '.gif', $params->get('full_name') ? '' : $language->title_native, null, true); ?>
|
||||
<?php endif; ?>
|
||||
<?php echo $params->get('full_name', 1) ? $language->title_native : strtoupper($language->sef); ?>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<ul aria-labelledby="language_picker_des_<?php echo $module->id; ?>" class="lang-block dropdown-menu">
|
||||
|
||||
<?php foreach ($list as $language) : ?>
|
||||
<?php
|
||||
$lbl = '';
|
||||
if ($params->get('full_name') === 0) {
|
||||
$lbl = 'aria-label="' . $language->title_native . '"';
|
||||
}
|
||||
?>
|
||||
<?php if (!$language->active) : ?>
|
||||
<li>
|
||||
<a <?php echo $lbl; ?> href="<?php echo htmlspecialchars_decode(htmlspecialchars($language->link, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES); ?>">
|
||||
<?php if ($params->get('dropdownimage', 1) && ($language->image)) : ?>
|
||||
<?php echo HTMLHelper::_('image', 'mod_languages/' . $language->image . '.gif', $params->get('full_name') ? '' : $language->title_native, null, true); ?>
|
||||
<?php endif; ?>
|
||||
<?php echo $params->get('full_name', 1) ? $language->title_native : strtoupper($language->sef); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php elseif ($params->get('show_active', 1)) : ?>
|
||||
<?php $base = Uri::getInstance(); ?>
|
||||
<li class="lang-active">
|
||||
<a aria-current="true" <?php echo $lbl; ?> href="<?php echo htmlspecialchars_decode(htmlspecialchars($base, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES); ?>">
|
||||
<?php if ($params->get('dropdownimage', 1) && ($language->image)) : ?>
|
||||
<?php echo HTMLHelper::_('image', 'mod_languages/' . $language->image . '.gif', $params->get('full_name') ? '' : $language->title_native, null, true); ?>
|
||||
<?php endif; ?>
|
||||
<?php echo $params->get('full_name', 1) ? $language->title_native : strtoupper($language->sef); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<ul aria-labelledby="language_picker_des_<?php echo $module->id; ?>" class="mod-languages__list <?php echo $params->get('inline', 1) ? 'lang-inline' : 'lang-block'; ?>">
|
||||
|
||||
<?php foreach ($list as $language) : ?>
|
||||
<?php
|
||||
$lbl = '';
|
||||
if ((($params->get('full_name') === 0) && ($params->get('image') === 0)) || (!$language->image)) {
|
||||
$lbl = 'aria-label="' . $language->title_native . '"';
|
||||
}
|
||||
?>
|
||||
<?php if (!$language->active) : ?>
|
||||
<li>
|
||||
<a <?php echo $lbl; ?> href="<?php echo htmlspecialchars_decode(htmlspecialchars($language->link, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES); ?>">
|
||||
<?php if ($params->get('image', 1)) : ?>
|
||||
<?php if ($language->image) : ?>
|
||||
<?php echo HTMLHelper::_('image', 'mod_languages/' . $language->image . '.gif', $language->title_native, ['title' => $language->title_native], true); ?>
|
||||
<?php else : ?>
|
||||
<span class="label" title="<?php echo $language->title_native; ?>"><?php echo strtoupper($language->sef); ?></span>
|
||||
<?php endif; ?>
|
||||
<?php else : ?>
|
||||
<?php echo $params->get('full_name', 1) ? $language->title_native : strtoupper($language->sef); ?>
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php elseif ($params->get('show_active', 1)) : ?>
|
||||
<?php $base = Uri::getInstance(); ?>
|
||||
<li class="lang-active">
|
||||
<a aria-current="true" <?php echo $lbl; ?> href="<?php echo htmlspecialchars_decode(htmlspecialchars($base, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES); ?>">
|
||||
<?php if ($params->get('image', 1)) : ?>
|
||||
<?php if ($language->image) : ?>
|
||||
<?php echo HTMLHelper::_('image', 'mod_languages/' . $language->image . '.gif', $language->title_native, ['title' => $language->title_native], true); ?>
|
||||
<?php else : ?>
|
||||
<span class="badge bg-secondary" title="<?php echo $language->title_native; ?>"><?php echo strtoupper($language->sef); ?></span>
|
||||
<?php endif; ?>
|
||||
<?php else : ?>
|
||||
<?php echo $params->get('full_name', 1) ? $language->title_native : strtoupper($language->sef); ?>
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($footerText) : ?>
|
||||
<div class="mod-languages__posttext posttext"><p><?php echo $footerText; ?></p></div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
Reference in New Issue
Block a user