29
0
mirror of https://github.com/joomla/joomla-cms.git synced 2024-06-30 17:13:41 +00:00
cms/administrator/components/com_languages/src/Controller/InstalledController.php

119 lines
3.0 KiB
PHP
Raw Normal View History

<?php
/**
2012-06-30 21:09:54 +00:00
* @package Joomla.Administrator
* @subpackage com_languages
*
* @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
*/
2017-05-13 17:05:05 +00:00
namespace Joomla\Component\Languages\Administrator\Controller;
2020-03-24 22:21:49 +00:00
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
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
/**
* Languages Controller.
*
* @since 1.5
*/
class InstalledController extends BaseController
{
/**
* Task to set the default language.
*
* @return void
*/
public function setDefault()
{
// Check for request forgeries.
$this->checkToken();
2012-07-13 14:24:46 +00:00
2022-03-29 13:27:09 +00:00
$cid = (string) $this->input->get('cid', '', 'string');
$model = $this->getModel('installed');
if ($model->publish($cid))
{
2016-02-18 13:59:12 +00:00
// Switching to the new administrator language for the message
2016-02-19 07:20:39 +00:00
if ($model->getState('client_id') == 1)
2016-02-18 13:59:12 +00:00
{
$language = Factory::getLanguage();
$newLang = Language::getInstance($cid);
Factory::$language = $newLang;
$this->app->loadLanguage($language = $newLang);
2016-02-18 13:59:12 +00:00
$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
{
2016-09-22 11:57:42 +00:00
$msg = $model->getError();
$type = 'error';
}
2016-02-19 08:54:27 +00:00
$clientId = $model->getState('client_id');
2016-09-22 11:57:42 +00:00
$this->setRedirect('index.php?option=com_languages&view=installed&client=' . $clientId, $msg, $type);
}
2016-02-15 09:02:18 +00:00
/**
* Task to switch the administrator language.
*
* @return void
*/
public function switchAdminLanguage()
{
// Check for request forgeries.
$this->checkToken();
2016-02-15 09:02:18 +00:00
2022-03-29 13:27:09 +00:00
$cid = (string) $this->input->get('cid', '', 'string');
2016-02-15 09:02:18 +00:00
$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';
}
2022-03-29 13:27:09 +00:00
$info = LanguageHelper::parseXMLLanguageFile($file);
2016-02-15 09:02:18 +00:00
if ($model->switchAdminLanguage($cid))
{
// Switching to the new language for the message
2022-03-29 13:27:09 +00:00
$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);
2016-02-15 09:02:18 +00:00
$type = 'message';
}
else
{
2016-09-22 11:57:42 +00:00
$msg = $model->getError();
2016-02-15 09:02:18 +00:00
$type = 'error';
}
2016-09-22 11:57:42 +00:00
$this->setRedirect('index.php?option=com_languages&view=installed', $msg, $type);
2016-02-15 09:02:18 +00:00
}
}