2009-09-28 05:15:19 +00:00
|
|
|
<?php
|
2022-06-27 18:18:44 +00:00
|
|
|
|
2009-09-28 05:15:19 +00:00
|
|
|
/**
|
2012-06-30 21:09:54 +00:00
|
|
|
* @package Joomla.Administrator
|
|
|
|
* @subpackage com_languages
|
|
|
|
*
|
2020-11-28 01:33:45 +00:00
|
|
|
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
2012-06-30 21:09:54 +00:00
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
2009-09-28 05:15:19 +00:00
|
|
|
*/
|
2018-08-10 04:22:52 +00:00
|
|
|
|
2017-05-13 17:05:05 +00:00
|
|
|
namespace Joomla\Component\Languages\Administrator\Controller;
|
2009-09-28 05:15:19 +00:00
|
|
|
|
2020-03-24 22:21:49 +00:00
|
|
|
\defined('_JEXEC') or die;
|
2009-09-28 05:15:19 +00:00
|
|
|
|
2018-08-06 14:48:56 +00:00
|
|
|
use Joomla\CMS\Factory;
|
2021-07-26 19:34:08 +00:00
|
|
|
use Joomla\CMS\Language\LanguageHelper;
|
2018-10-19 04:46:15 +00:00
|
|
|
use Joomla\CMS\Language\Language;
|
2019-04-05 12:49:50 +00:00
|
|
|
use Joomla\CMS\Language\Multilanguage;
|
2018-10-19 04:46:15 +00:00
|
|
|
use Joomla\CMS\Language\Text;
|
|
|
|
use Joomla\CMS\MVC\Controller\BaseController;
|
2017-05-13 17:05:05 +00:00
|
|
|
|
2009-09-28 05:15:19 +00:00
|
|
|
/**
|
2014-10-12 10:59:19 +00:00
|
|
|
* Languages Controller.
|
2009-09-28 05:15:19 +00:00
|
|
|
*
|
2014-10-12 15:13:02 +00:00
|
|
|
* @since 1.5
|
2009-09-28 05:15:19 +00:00
|
|
|
*/
|
2017-09-20 11:51:48 +00:00
|
|
|
class InstalledController extends BaseController
|
2009-09-28 05:15:19 +00:00
|
|
|
{
|
2022-06-27 18:18:44 +00:00
|
|
|
/**
|
|
|
|
* Task to set the default language.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setDefault()
|
|
|
|
{
|
|
|
|
// Check for request forgeries.
|
|
|
|
$this->checkToken();
|
|
|
|
|
|
|
|
$cid = (string) $this->input->get('cid', '', 'string');
|
|
|
|
$model = $this->getModel('installed');
|
|
|
|
|
|
|
|
if ($model->publish($cid)) {
|
|
|
|
// Switching to the new administrator language for the message
|
|
|
|
if ($model->getState('client_id') == 1) {
|
|
|
|
$language = Factory::getLanguage();
|
|
|
|
$newLang = Language::getInstance($cid);
|
|
|
|
Factory::$language = $newLang;
|
|
|
|
$this->app->loadLanguage($language = $newLang);
|
|
|
|
$newLang->load('com_languages', JPATH_ADMINISTRATOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Multilanguage::isEnabled() && $model->getState('client_id') == 0) {
|
|
|
|
$msg = Text::_('COM_LANGUAGES_MSG_DEFAULT_MULTILANG_SAVED');
|
|
|
|
$type = 'message';
|
|
|
|
} else {
|
|
|
|
$msg = Text::_('COM_LANGUAGES_MSG_DEFAULT_LANGUAGE_SAVED');
|
|
|
|
$type = 'message';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$msg = $model->getError();
|
|
|
|
$type = 'error';
|
|
|
|
}
|
|
|
|
|
|
|
|
$clientId = $model->getState('client_id');
|
|
|
|
$this->setRedirect('index.php?option=com_languages&view=installed&client=' . $clientId, $msg, $type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Task to switch the administrator language.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function switchAdminLanguage()
|
|
|
|
{
|
|
|
|
// Check for request forgeries.
|
|
|
|
$this->checkToken();
|
|
|
|
|
|
|
|
$cid = (string) $this->input->get('cid', '', 'string');
|
|
|
|
$model = $this->getModel('installed');
|
|
|
|
|
|
|
|
// Fetching the language name from the langmetadata.xml or xx-XX.xml respectively.
|
|
|
|
$file = JPATH_ADMINISTRATOR . '/language/' . $cid . '/langmetadata.xml';
|
|
|
|
|
|
|
|
if (!is_file($file)) {
|
|
|
|
$file = JPATH_ADMINISTRATOR . '/language/' . $cid . '/' . $cid . '.xml';
|
|
|
|
}
|
|
|
|
|
|
|
|
$info = LanguageHelper::parseXMLLanguageFile($file);
|
|
|
|
|
|
|
|
if ($model->switchAdminLanguage($cid)) {
|
|
|
|
// Switching to the new language for the message
|
|
|
|
$languageName = $info['nativeName'];
|
|
|
|
$language = Factory::getLanguage();
|
|
|
|
$newLang = Language::getInstance($cid);
|
|
|
|
Factory::$language = $newLang;
|
|
|
|
$this->app->loadLanguage($language = $newLang);
|
|
|
|
$newLang->load('com_languages', JPATH_ADMINISTRATOR);
|
|
|
|
|
|
|
|
$msg = Text::sprintf('COM_LANGUAGES_MSG_SWITCH_ADMIN_LANGUAGE_SUCCESS', $languageName);
|
|
|
|
$type = 'message';
|
|
|
|
} else {
|
|
|
|
$msg = $model->getError();
|
|
|
|
$type = 'error';
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->setRedirect('index.php?option=com_languages&view=installed', $msg, $type);
|
|
|
|
}
|
2009-09-28 05:15:19 +00:00
|
|
|
}
|