[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Installation 5 * @subpackage Controller 6 * 7 * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\CMS\Installation\Controller; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Installation\Model\SetupModel; 15 use Joomla\CMS\Language\Language; 16 use Joomla\CMS\Language\Text; 17 18 // phpcs:disable PSR1.Files.SideEffects 19 \defined('_JEXEC') or die; 20 // phpcs:enable PSR1.Files.SideEffects 21 22 /** 23 * Language controller class for the Joomla Installer. 24 * 25 * @since 3.1 26 */ 27 class LanguageController extends JSONController 28 { 29 /** 30 * Sets the language. 31 * 32 * @return void 33 * 34 * @since 4.0.0 35 */ 36 public function set() 37 { 38 $this->checkValidToken(); 39 40 // Check for potentially unwritable session 41 $session = $this->app->getSession(); 42 43 if ($session->isNew()) { 44 $this->sendJsonResponse(new \Exception(Text::_('INSTL_COOKIES_NOT_ENABLED'), 500)); 45 } 46 47 /** @var SetupModel $model */ 48 $model = $this->getModel('Setup'); 49 50 // Get the posted values from the request and validate them. 51 $data = $this->input->post->get('jform', [], 'array'); 52 $return = $model->validate($data, 'language'); 53 54 $r = new \stdClass(); 55 56 // Check for validation errors. 57 if ($return === false) { 58 /* 59 * The validate method enqueued all messages for us, so we just need to 60 * redirect back to the site setup screen. 61 */ 62 $r->view = $this->input->getWord('view', 'setup'); 63 $this->sendJsonResponse($r); 64 } 65 66 // Store the options in the session. 67 $model->storeOptions($return); 68 69 // Setup language 70 Factory::$language = Language::getInstance($return['language']); 71 72 // Redirect to the page. 73 $r->view = $this->input->getWord('view', 'setup'); 74 75 $this->sendJsonResponse($r); 76 } 77 78 /** 79 * Sets the default language. 80 * 81 * @return void 82 * 83 * @since 4.0.0 84 */ 85 public function setdefault() 86 { 87 $this->checkValidToken(); 88 89 $app = $this->app; 90 91 /** @var \Joomla\CMS\Installation\Model\LanguagesModel $model */ 92 $model = $this->getModel('Languages'); 93 94 // Check for request forgeries in the administrator language 95 $admin_lang = $this->input->getString('administratorlang', false); 96 97 // Check that the string is an ISO Language Code avoiding any injection. 98 if (!preg_match('/^[a-z]{2}(\-[A-Z]{2})?$/', $admin_lang)) { 99 $admin_lang = 'en-GB'; 100 } 101 102 // Attempt to set the default administrator language 103 if (!$model->setDefault($admin_lang, 'administrator')) { 104 // Create an error response message. 105 $this->app->enqueueMessage(Text::_('INSTL_DEFAULTLANGUAGE_ADMIN_COULDNT_SET_DEFAULT'), 'error'); 106 } else { 107 // Create a response body. 108 $app->enqueueMessage(Text::sprintf('INSTL_DEFAULTLANGUAGE_ADMIN_SET_DEFAULT', $admin_lang), 'message'); 109 } 110 111 // Check for request forgeries in the site language 112 $frontend_lang = $this->input->getString('frontendlang', false); 113 114 // Check that the string is an ISO Language Code avoiding any injection. 115 if (!preg_match('/^[a-z]{2}(\-[A-Z]{2})?$/', $frontend_lang)) { 116 $frontend_lang = 'en-GB'; 117 } 118 119 // Attempt to set the default site language 120 if (!$model->setDefault($frontend_lang, 'site')) { 121 // Create an error response message. 122 $app->enqueueMessage(Text::_('INSTL_DEFAULTLANGUAGE_FRONTEND_COULDNT_SET_DEFAULT'), 'error'); 123 } else { 124 // Create a response body. 125 $app->enqueueMessage(Text::sprintf('INSTL_DEFAULTLANGUAGE_FRONTEND_SET_DEFAULT', $frontend_lang), 'message'); 126 } 127 128 $r = new \stdClass(); 129 130 // Redirect to the final page. 131 $r->view = 'remove'; 132 $this->sendJsonResponse($r); 133 } 134 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |