public function __construct(&$subject, $config) { parent::__construct($subject, $config); // Ensure that constructor is called one time self::$cookie = SID == ''; if (!self::$default_lang) { $app = JFactory::getApplication(); $router = $app->getRouter(); if (App::isSite()) { // setup language data self::$mode_sef = $router->getMode() == JROUTER_MODE_SEF ? true : false; self::$sefs = JLanguageHelper::getLanguages('sef'); self::$lang_codes = JLanguageHelper::getLanguages('lang_code'); self::$default_lang = Component::params('com_languages')->get('site', 'en-GB'); self::$default_sef = self::$lang_codes[self::$default_lang]->sef; self::$homes = MultilangstatusHelper::getHomepages(); $user = User::getRoot(); $levels = $user->getAuthorisedViewLevels(); foreach (self::$sefs as $sef => &$language) { if (isset($language->access) && $language->access && !in_array($language->access, $levels)) { unset(self::$sefs[$sef]); } } App::forget('language.filter'); App::set('language.filter', true); $uri = JFactory::getURI(); if (self::$mode_sef) { // Get the route path from the request. $path = JString::substr($uri->toString(), JString::strlen($uri->base())); // Apache mod_rewrite is Off $path = Config::get('sef_rewrite') ? $path : JString::substr($path, 10); // Trim any spaces or slashes from the ends of the path and explode into segments. $path = JString::trim($path, '/ '); $parts = explode('/', $path); // The language segment is always at the beginning of the route path if it exists. $sef = $uri->getVar('lang'); if (!empty($parts) && empty($sef)) { $sef = reset($parts); } } else { $sef = $uri->getVar('lang'); } if (isset(self::$sefs[$sef])) { $lang_code = self::$sefs[$sef]->lang_code; // Create a cookie $cookie_domain = Config::get('cookie_domain', ''); $cookie_path = Config::get('cookie_path', '/'); setcookie(App::hash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain); // set the request var Request::setVar('language', $lang_code); } } parent::__construct($subject, $config); // Detect browser feature if (App::isSite()) { $app->setDetectBrowser($this->params->get('detect_browser', '1') == '1'); } } }
/** * Initialise the application * * @param array $options an optional associative array of configuration settings. * @return void */ public function initialise($options = []) { $arguments = App::get('arguments'); $output = App::get('output'); try { $arguments->parse(); } catch (UnsupportedCommandException $e) { $output->error($e->getMessage()); } catch (UnsupportedTaskException $e) { $output->error($e->getMessage()); } // Check for interactivity flag and set on output accordingly if ($arguments->getOpt('non-interactive')) { $output->makeNonInteractive(); } // Check for color flag and set on output accordingly if ($arguments->getOpt('no-colors')) { $output->makeUnColored(); } // If task is help, set the output to our output class with extra methods for rendering help doc if ($arguments->get('task') == 'help') { $output = $output->getHelpOutput(); } // If the format opt is present, try to use the appropriate output subclass if ($arguments->getOpt('format')) { $output = $output->getOutputFormatter($arguments->getOpt('format')); } // Register any user specific events if ($hooks = Config::get('hooks')) { foreach ($hooks as $trigger => $scripts) { foreach ($scripts as $script) { Event::register($trigger, function () use($script, $output) { if ($output->getMode() != 'minimal') { $output->addLine("Running '{$script}'"); } shell_exec(escapeshellcmd($script)); }); } } } // Reset the output stored on the application App::forget('output'); App::set('output', $output); }