[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Application/ -> SiteApplication.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Application;
  11  
  12  use Joomla\Application\Web\WebClient;
  13  use Joomla\CMS\Cache\CacheControllerFactoryAwareTrait;
  14  use Joomla\CMS\Cache\Controller\OutputController;
  15  use Joomla\CMS\Component\ComponentHelper;
  16  use Joomla\CMS\Factory;
  17  use Joomla\CMS\Filter\InputFilter;
  18  use Joomla\CMS\Input\Input;
  19  use Joomla\CMS\Language\LanguageHelper;
  20  use Joomla\CMS\Language\Text;
  21  use Joomla\CMS\Pathway\Pathway;
  22  use Joomla\CMS\Plugin\PluginHelper;
  23  use Joomla\CMS\Router\Route;
  24  use Joomla\CMS\Router\SiteRouter;
  25  use Joomla\CMS\Uri\Uri;
  26  use Joomla\DI\Container;
  27  use Joomla\Registry\Registry;
  28  use Joomla\String\StringHelper;
  29  
  30  // phpcs:disable PSR1.Files.SideEffects
  31  \defined('JPATH_PLATFORM') or die;
  32  // phpcs:enable PSR1.Files.SideEffects
  33  
  34  /**
  35   * Joomla! Site Application class
  36   *
  37   * @since  3.2
  38   */
  39  final class SiteApplication extends CMSApplication
  40  {
  41      use CacheControllerFactoryAwareTrait;
  42      use MultiFactorAuthenticationHandler;
  43  
  44      /**
  45       * Option to filter by language
  46       *
  47       * @var    boolean
  48       * @since  4.0.0
  49       */
  50      protected $language_filter = false;
  51  
  52      /**
  53       * Option to detect language by the browser
  54       *
  55       * @var    boolean
  56       * @since  4.0.0
  57       */
  58      protected $detect_browser = false;
  59  
  60      /**
  61       * Class constructor.
  62       *
  63       * @param   Input      $input      An optional argument to provide dependency injection for the application's input
  64       *                                 object.  If the argument is a JInput object that object will become the
  65       *                                 application's input object, otherwise a default input object is created.
  66       * @param   Registry   $config     An optional argument to provide dependency injection for the application's config
  67       *                                 object.  If the argument is a Registry object that object will become the
  68       *                                 application's config object, otherwise a default config object is created.
  69       * @param   WebClient  $client     An optional argument to provide dependency injection for the application's client
  70       *                                 object.  If the argument is a WebClient object that object will become the
  71       *                                 application's client object, otherwise a default client object is created.
  72       * @param   Container  $container  Dependency injection container.
  73       *
  74       * @since   3.2
  75       */
  76      public function __construct(Input $input = null, Registry $config = null, WebClient $client = null, Container $container = null)
  77      {
  78          // Register the application name
  79          $this->name = 'site';
  80  
  81          // Register the client ID
  82          $this->clientId = 0;
  83  
  84          // Execute the parent constructor
  85          parent::__construct($input, $config, $client, $container);
  86      }
  87  
  88      /**
  89       * Check if the user can access the application
  90       *
  91       * @param   integer  $itemid  The item ID to check authorisation for
  92       *
  93       * @return  void
  94       *
  95       * @since   3.2
  96       *
  97       * @throws  \Exception When you are not authorised to view the home page menu item
  98       */
  99      protected function authorise($itemid)
 100      {
 101          $menus = $this->getMenu();
 102          $user = Factory::getUser();
 103  
 104          if (!$menus->authorise($itemid)) {
 105              if ($user->get('id') == 0) {
 106                  // Set the data
 107                  $this->setUserState('users.login.form.data', array('return' => Uri::getInstance()->toString()));
 108  
 109                  $url = Route::_('index.php?option=com_users&view=login', false);
 110  
 111                  $this->enqueueMessage(Text::_('JGLOBAL_YOU_MUST_LOGIN_FIRST'), 'error');
 112                  $this->redirect($url);
 113              } else {
 114                  // Get the home page menu item
 115                  $home_item = $menus->getDefault($this->getLanguage()->getTag());
 116  
 117                  // If we are already in the homepage raise an exception
 118                  if ($menus->getActive()->id == $home_item->id) {
 119                      throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
 120                  }
 121  
 122                  // Otherwise redirect to the homepage and show an error
 123                  $this->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error');
 124                  $this->redirect(Route::_('index.php?Itemid=' . $home_item->id, false));
 125              }
 126          }
 127      }
 128  
 129      /**
 130       * Dispatch the application
 131       *
 132       * @param   string  $component  The component which is being rendered.
 133       *
 134       * @return  void
 135       *
 136       * @since   3.2
 137       */
 138      public function dispatch($component = null)
 139      {
 140          // Get the component if not set.
 141          if (!$component) {
 142              $component = $this->input->getCmd('option', null);
 143          }
 144  
 145          // Load the document to the API
 146          $this->loadDocument();
 147  
 148          // Set up the params
 149          $document = $this->getDocument();
 150          $params   = $this->getParams();
 151  
 152          // Register the document object with Factory
 153          Factory::$document = $document;
 154  
 155          switch ($document->getType()) {
 156              case 'html':
 157                  // Set up the language
 158                  LanguageHelper::getLanguages('lang_code');
 159  
 160                  // Set metadata
 161                  $document->setMetaData('rights', $this->get('MetaRights'));
 162  
 163                  // Get the template
 164                  $template = $this->getTemplate(true);
 165  
 166                  // Store the template and its params to the config
 167                  $this->set('theme', $template->template);
 168                  $this->set('themeParams', $template->params);
 169  
 170                  // Add Asset registry files
 171                  $wr = $document->getWebAssetManager()->getRegistry();
 172  
 173                  if ($component) {
 174                      $wr->addExtensionRegistryFile($component);
 175                  }
 176  
 177                  if ($template->parent) {
 178                      $wr->addTemplateRegistryFile($template->parent, $this->getClientId());
 179                  }
 180  
 181                  $wr->addTemplateRegistryFile($template->template, $this->getClientId());
 182  
 183                  break;
 184  
 185              case 'feed':
 186                  $document->setBase(htmlspecialchars(Uri::current()));
 187                  break;
 188          }
 189  
 190          $document->setTitle($params->get('page_title'));
 191          $document->setDescription($params->get('page_description'));
 192  
 193          // Add version number or not based on global configuration
 194          if ($this->get('MetaVersion', 0)) {
 195              $document->setGenerator('Joomla! - Open Source Content Management - Version ' . JVERSION);
 196          } else {
 197              $document->setGenerator('Joomla! - Open Source Content Management');
 198          }
 199  
 200          $contents = ComponentHelper::renderComponent($component);
 201          $document->setBuffer($contents, 'component');
 202  
 203          // Trigger the onAfterDispatch event.
 204          PluginHelper::importPlugin('system');
 205          $this->triggerEvent('onAfterDispatch');
 206      }
 207  
 208      /**
 209       * Method to run the Web application routines.
 210       *
 211       * @return  void
 212       *
 213       * @since   3.2
 214       */
 215      protected function doExecute()
 216      {
 217          // Initialise the application
 218          $this->initialiseApp();
 219  
 220          // Mark afterInitialise in the profiler.
 221          JDEBUG ? $this->profiler->mark('afterInitialise') : null;
 222  
 223          // Route the application
 224          $this->route();
 225  
 226          // Mark afterRoute in the profiler.
 227          JDEBUG ? $this->profiler->mark('afterRoute') : null;
 228  
 229          if (!$this->isHandlingMultiFactorAuthentication()) {
 230              /*
 231               * Check if the user is required to reset their password
 232               *
 233               * Before $this->route(); "option" and "view" can't be safely read using:
 234               * $this->input->getCmd('option'); or $this->input->getCmd('view');
 235               * ex: due of the sef urls
 236               */
 237              $this->checkUserRequireReset('com_users', 'profile', 'edit', 'com_users/profile.save,com_users/profile.apply,com_users/user.logout');
 238          }
 239  
 240          // Dispatch the application
 241          $this->dispatch();
 242  
 243          // Mark afterDispatch in the profiler.
 244          JDEBUG ? $this->profiler->mark('afterDispatch') : null;
 245      }
 246  
 247      /**
 248       * Return the current state of the detect browser option.
 249       *
 250       * @return  boolean
 251       *
 252       * @since   3.2
 253       */
 254      public function getDetectBrowser()
 255      {
 256          return $this->detect_browser;
 257      }
 258  
 259      /**
 260       * Return the current state of the language filter.
 261       *
 262       * @return  boolean
 263       *
 264       * @since   3.2
 265       */
 266      public function getLanguageFilter()
 267      {
 268          return $this->language_filter;
 269      }
 270  
 271      /**
 272       * Get the application parameters
 273       *
 274       * @param   string  $option  The component option
 275       *
 276       * @return  Registry  The parameters object
 277       *
 278       * @since   3.2
 279       */
 280      public function getParams($option = null)
 281      {
 282          static $params = array();
 283  
 284          $hash = '__default';
 285  
 286          if (!empty($option)) {
 287              $hash = $option;
 288          }
 289  
 290          if (!isset($params[$hash])) {
 291              // Get component parameters
 292              if (!$option) {
 293                  $option = $this->input->getCmd('option', null);
 294              }
 295  
 296              // Get new instance of component global parameters
 297              $params[$hash] = clone ComponentHelper::getParams($option);
 298  
 299              // Get menu parameters
 300              $menus = $this->getMenu();
 301              $menu  = $menus->getActive();
 302  
 303              // Get language
 304              $lang_code = $this->getLanguage()->getTag();
 305              $languages = LanguageHelper::getLanguages('lang_code');
 306  
 307              $title = $this->get('sitename');
 308  
 309              if (isset($languages[$lang_code]) && $languages[$lang_code]->metadesc) {
 310                  $description = $languages[$lang_code]->metadesc;
 311              } else {
 312                  $description = $this->get('MetaDesc');
 313              }
 314  
 315              $rights = $this->get('MetaRights');
 316              $robots = $this->get('robots');
 317  
 318              // Retrieve com_menu global settings
 319              $temp = clone ComponentHelper::getParams('com_menus');
 320  
 321              // Lets cascade the parameters if we have menu item parameters
 322              if (\is_object($menu)) {
 323                  // Get show_page_heading from com_menu global settings
 324                  $params[$hash]->def('show_page_heading', $temp->get('show_page_heading'));
 325  
 326                  $params[$hash]->merge($menu->getParams());
 327                  $title = $menu->title;
 328              } else {
 329                  // Merge com_menu global settings
 330                  $params[$hash]->merge($temp);
 331  
 332                  // If supplied, use page title
 333                  $title = $temp->get('page_title', $title);
 334              }
 335  
 336              $params[$hash]->def('page_title', $title);
 337              $params[$hash]->def('page_description', $description);
 338              $params[$hash]->def('page_rights', $rights);
 339              $params[$hash]->def('robots', $robots);
 340          }
 341  
 342          return $params[$hash];
 343      }
 344  
 345      /**
 346       * Return a reference to the Pathway object.
 347       *
 348       * @param   string  $name     The name of the application.
 349       * @param   array   $options  An optional associative array of configuration settings.
 350       *
 351       * @return  Pathway  A Pathway object
 352       *
 353       * @since   3.2
 354       */
 355      public function getPathway($name = 'site', $options = array())
 356      {
 357          return parent::getPathway($name, $options);
 358      }
 359  
 360      /**
 361       * Return a reference to the Router object.
 362       *
 363       * @param   string  $name     The name of the application.
 364       * @param   array   $options  An optional associative array of configuration settings.
 365       *
 366       * @return  \Joomla\CMS\Router\Router
 367       *
 368       * @since      3.2
 369       *
 370       * @deprecated 5.0 Inject the router or load it from the dependency injection container
 371       */
 372      public static function getRouter($name = 'site', array $options = array())
 373      {
 374          return parent::getRouter($name, $options);
 375      }
 376  
 377      /**
 378       * Gets the name of the current template.
 379       *
 380       * @param   boolean  $params  True to return the template parameters
 381       *
 382       * @return  string  The name of the template.
 383       *
 384       * @since   3.2
 385       * @throws  \InvalidArgumentException
 386       */
 387      public function getTemplate($params = false)
 388      {
 389          if (\is_object($this->template)) {
 390              if ($this->template->parent) {
 391                  if (!is_file(JPATH_THEMES . '/' . $this->template->template . '/index.php')) {
 392                      if (!is_file(JPATH_THEMES . '/' . $this->template->parent . '/index.php')) {
 393                          throw new \InvalidArgumentException(Text::sprintf('JERROR_COULD_NOT_FIND_TEMPLATE', $this->template->template));
 394                      }
 395                  }
 396              } elseif (!is_file(JPATH_THEMES . '/' . $this->template->template . '/index.php')) {
 397                  throw new \InvalidArgumentException(Text::sprintf('JERROR_COULD_NOT_FIND_TEMPLATE', $this->template->template));
 398              }
 399  
 400              if ($params) {
 401                  return $this->template;
 402              }
 403  
 404              return $this->template->template;
 405          }
 406  
 407          // Get the id of the active menu item
 408          $menu = $this->getMenu();
 409          $item = $menu->getActive();
 410  
 411          if (!$item) {
 412              $item = $menu->getItem($this->input->getInt('Itemid', null));
 413          }
 414  
 415          $id = 0;
 416  
 417          if (\is_object($item)) {
 418              // Valid item retrieved
 419              $id = $item->template_style_id;
 420          }
 421  
 422          $tid = $this->input->getUint('templateStyle', 0);
 423  
 424          if (is_numeric($tid) && (int) $tid > 0) {
 425              $id = (int) $tid;
 426          }
 427  
 428          /** @var OutputController $cache */
 429          $cache = $this->getCacheControllerFactory()->createCacheController('output', ['defaultgroup' => 'com_templates']);
 430  
 431          if ($this->getLanguageFilter()) {
 432              $tag = $this->getLanguage()->getTag();
 433          } else {
 434              $tag = '';
 435          }
 436  
 437          $cacheId = 'templates0' . $tag;
 438  
 439          if ($cache->contains($cacheId)) {
 440              $templates = $cache->get($cacheId);
 441          } else {
 442              $templates = $this->bootComponent('templates')->getMVCFactory()
 443                  ->createModel('Style', 'Administrator')->getSiteTemplates();
 444  
 445              foreach ($templates as &$template) {
 446                  // Create home element
 447                  if ($template->home == 1 && !isset($template_home) || $this->getLanguageFilter() && $template->home == $tag) {
 448                      $template_home = clone $template;
 449                  }
 450  
 451                  $template->params = new Registry($template->params);
 452              }
 453  
 454              // Unset the $template reference to the last $templates[n] item cycled in the foreach above to avoid editing it later
 455              unset($template);
 456  
 457              // Add home element, after loop to avoid double execution
 458              if (isset($template_home)) {
 459                  $template_home->params = new Registry($template_home->params);
 460                  $templates[0] = $template_home;
 461              }
 462  
 463              $cache->store($templates, $cacheId);
 464          }
 465  
 466          if (isset($templates[$id])) {
 467              $template = $templates[$id];
 468          } else {
 469              $template = $templates[0];
 470          }
 471  
 472          // Allows for overriding the active template from the request
 473          $template_override = $this->input->getCmd('template', '');
 474  
 475          // Only set template override if it is a valid template (= it exists and is enabled)
 476          if (!empty($template_override)) {
 477              if (is_file(JPATH_THEMES . '/' . $template_override . '/index.php')) {
 478                  foreach ($templates as $tmpl) {
 479                      if ($tmpl->template === $template_override) {
 480                          $template = $tmpl;
 481                          break;
 482                      }
 483                  }
 484              }
 485          }
 486  
 487          // Need to filter the default value as well
 488          $template->template = InputFilter::getInstance()->clean($template->template, 'cmd');
 489  
 490          // Fallback template
 491          if (!empty($template->parent)) {
 492              if (!is_file(JPATH_THEMES . '/' . $template->template . '/index.php')) {
 493                  if (!is_file(JPATH_THEMES . '/' . $template->parent . '/index.php')) {
 494                      $this->enqueueMessage(Text::_('JERROR_ALERTNOTEMPLATE'), 'error');
 495  
 496                      // Try to find data for 'cassiopeia' template
 497                      $original_tmpl = $template->template;
 498  
 499                      foreach ($templates as $tmpl) {
 500                          if ($tmpl->template === 'cassiopeia') {
 501                              $template = $tmpl;
 502                              break;
 503                          }
 504                      }
 505  
 506                      // Check, the data were found and if template really exists
 507                      if (!is_file(JPATH_THEMES . '/' . $template->template . '/index.php')) {
 508                          throw new \InvalidArgumentException(Text::sprintf('JERROR_COULD_NOT_FIND_TEMPLATE', $original_tmpl));
 509                      }
 510                  }
 511              }
 512          } elseif (!is_file(JPATH_THEMES . '/' . $template->template . '/index.php')) {
 513              $this->enqueueMessage(Text::_('JERROR_ALERTNOTEMPLATE'), 'error');
 514  
 515              // Try to find data for 'cassiopeia' template
 516              $original_tmpl = $template->template;
 517  
 518              foreach ($templates as $tmpl) {
 519                  if ($tmpl->template === 'cassiopeia') {
 520                      $template = $tmpl;
 521                      break;
 522                  }
 523              }
 524  
 525              // Check, the data were found and if template really exists
 526              if (!is_file(JPATH_THEMES . '/' . $template->template . '/index.php')) {
 527                  throw new \InvalidArgumentException(Text::sprintf('JERROR_COULD_NOT_FIND_TEMPLATE', $original_tmpl));
 528              }
 529          }
 530  
 531          // Cache the result
 532          $this->template = $template;
 533  
 534          if ($params) {
 535              return $template;
 536          }
 537  
 538          return $template->template;
 539      }
 540  
 541      /**
 542       * Initialise the application.
 543       *
 544       * @param   array  $options  An optional associative array of configuration settings.
 545       *
 546       * @return  void
 547       *
 548       * @since   3.2
 549       */
 550      protected function initialiseApp($options = array())
 551      {
 552          $user = Factory::getUser();
 553  
 554          // If the user is a guest we populate it with the guest user group.
 555          if ($user->guest) {
 556              $guestUsergroup = ComponentHelper::getParams('com_users')->get('guest_usergroup', 1);
 557              $user->groups = array($guestUsergroup);
 558          }
 559  
 560          if ($plugin = PluginHelper::getPlugin('system', 'languagefilter')) {
 561              $pluginParams = new Registry($plugin->params);
 562              $this->setLanguageFilter(true);
 563              $this->setDetectBrowser($pluginParams->get('detect_browser', 1) == 1);
 564          }
 565  
 566          if (empty($options['language'])) {
 567              // Detect the specified language
 568              $lang = $this->input->getString('language', null);
 569  
 570              // Make sure that the user's language exists
 571              if ($lang && LanguageHelper::exists($lang)) {
 572                  $options['language'] = $lang;
 573              }
 574          }
 575  
 576          if (empty($options['language']) && $this->getLanguageFilter()) {
 577              // Detect cookie language
 578              $lang = $this->input->cookie->get(md5($this->get('secret') . 'language'), null, 'string');
 579  
 580              // Make sure that the user's language exists
 581              if ($lang && LanguageHelper::exists($lang)) {
 582                  $options['language'] = $lang;
 583              }
 584          }
 585  
 586          if (empty($options['language'])) {
 587              // Detect user language
 588              $lang = $user->getParam('language');
 589  
 590              // Make sure that the user's language exists
 591              if ($lang && LanguageHelper::exists($lang)) {
 592                  $options['language'] = $lang;
 593              }
 594          }
 595  
 596          if (empty($options['language']) && $this->getDetectBrowser()) {
 597              // Detect browser language
 598              $lang = LanguageHelper::detectLanguage();
 599  
 600              // Make sure that the user's language exists
 601              if ($lang && LanguageHelper::exists($lang)) {
 602                  $options['language'] = $lang;
 603              }
 604          }
 605  
 606          if (empty($options['language'])) {
 607              // Detect default language
 608              $params = ComponentHelper::getParams('com_languages');
 609              $options['language'] = $params->get('site', $this->get('language', 'en-GB'));
 610          }
 611  
 612          // One last check to make sure we have something
 613          if (!LanguageHelper::exists($options['language'])) {
 614              $lang = $this->config->get('language', 'en-GB');
 615  
 616              if (LanguageHelper::exists($lang)) {
 617                  $options['language'] = $lang;
 618              } else {
 619                  // As a last ditch fail to english
 620                  $options['language'] = 'en-GB';
 621              }
 622          }
 623  
 624          // Finish initialisation
 625          parent::initialiseApp($options);
 626      }
 627  
 628      /**
 629       * Load the library language files for the application
 630       *
 631       * @return  void
 632       *
 633       * @since   3.6.3
 634       */
 635      protected function loadLibraryLanguage()
 636      {
 637          /*
 638           * Try the lib_joomla file in the current language (without allowing the loading of the file in the default language)
 639           * Fallback to the default language if necessary
 640           */
 641          $this->getLanguage()->load('lib_joomla', JPATH_SITE)
 642              || $this->getLanguage()->load('lib_joomla', JPATH_ADMINISTRATOR);
 643      }
 644  
 645      /**
 646       * Login authentication function
 647       *
 648       * @param   array  $credentials  Array('username' => string, 'password' => string)
 649       * @param   array  $options      Array('remember' => boolean)
 650       *
 651       * @return  boolean  True on success.
 652       *
 653       * @since   3.2
 654       */
 655      public function login($credentials, $options = array())
 656      {
 657          // Set the application login entry point
 658          if (!\array_key_exists('entry_url', $options)) {
 659              $options['entry_url'] = Uri::base() . 'index.php?option=com_users&task=user.login';
 660          }
 661  
 662          // Set the access control action to check.
 663          $options['action'] = 'core.login.site';
 664  
 665          return parent::login($credentials, $options);
 666      }
 667  
 668      /**
 669       * Rendering is the process of pushing the document buffers into the template
 670       * placeholders, retrieving data from the document and pushing it into
 671       * the application response buffer.
 672       *
 673       * @return  void
 674       *
 675       * @since   3.2
 676       */
 677      protected function render()
 678      {
 679          switch ($this->document->getType()) {
 680              case 'feed':
 681                  // No special processing for feeds
 682                  break;
 683  
 684              case 'html':
 685              default:
 686                  $template = $this->getTemplate(true);
 687                  $file     = $this->input->get('tmpl', 'index');
 688  
 689                  if ($file === 'offline' && !$this->get('offline')) {
 690                      $this->set('themeFile', 'index.php');
 691                  }
 692  
 693                  if ($this->get('offline') && !Factory::getUser()->authorise('core.login.offline')) {
 694                      $this->setUserState('users.login.form.data', array('return' => Uri::getInstance()->toString()));
 695                      $this->set('themeFile', 'offline.php');
 696                      $this->setHeader('Status', '503 Service Temporarily Unavailable', 'true');
 697                  }
 698  
 699                  if (!is_dir(JPATH_THEMES . '/' . $template->template) && !$this->get('offline')) {
 700                      $this->set('themeFile', 'component.php');
 701                  }
 702  
 703                  // Ensure themeFile is set by now
 704                  if ($this->get('themeFile') == '') {
 705                      $this->set('themeFile', $file . '.php');
 706                  }
 707  
 708                  // Pass the parent template to the state
 709                  $this->set('themeInherits', $template->parent);
 710  
 711                  break;
 712          }
 713  
 714          parent::render();
 715      }
 716  
 717      /**
 718       * Route the application.
 719       *
 720       * Routing is the process of examining the request environment to determine which
 721       * component should receive the request. The component optional parameters
 722       * are then set in the request object to be processed when the application is being
 723       * dispatched.
 724       *
 725       * @return  void
 726       *
 727       * @since   3.2
 728       */
 729      protected function route()
 730      {
 731          // Get the full request URI.
 732          $uri = clone Uri::getInstance();
 733  
 734          // It is not possible to inject the SiteRouter as it requires a SiteApplication
 735          // and we would end in an infinite loop
 736          $result = $this->getContainer()->get(SiteRouter::class)->parse($uri, true);
 737  
 738          $active = $this->getMenu()->getActive();
 739  
 740          if (
 741              $active !== null
 742              && $active->type === 'alias'
 743              && $active->getParams()->get('alias_redirect')
 744              && \in_array($this->input->getMethod(), ['GET', 'HEAD'], true)
 745          ) {
 746              $item = $this->getMenu()->getItem($active->getParams()->get('aliasoptions'));
 747  
 748              if ($item !== null) {
 749                  $oldUri = clone Uri::getInstance();
 750  
 751                  if ($oldUri->getVar('Itemid') == $active->id) {
 752                      $oldUri->setVar('Itemid', $item->id);
 753                  }
 754  
 755                  $base = Uri::base(true);
 756                  $oldPath = StringHelper::strtolower(substr($oldUri->getPath(), \strlen($base) + 1));
 757                  $activePathPrefix = StringHelper::strtolower($active->route);
 758  
 759                  $position = strpos($oldPath, $activePathPrefix);
 760  
 761                  if ($position !== false) {
 762                      $oldUri->setPath($base . '/' . substr_replace($oldPath, $item->route, $position, \strlen($activePathPrefix)));
 763  
 764                      $this->setHeader('Expires', 'Wed, 17 Aug 2005 00:00:00 GMT', true);
 765                      $this->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT', true);
 766                      $this->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate', false);
 767                      $this->sendHeaders();
 768  
 769                      $this->redirect((string) $oldUri, 301);
 770                  }
 771              }
 772          }
 773  
 774          foreach ($result as $key => $value) {
 775              $this->input->def($key, $value);
 776          }
 777  
 778          // Trigger the onAfterRoute event.
 779          PluginHelper::importPlugin('system');
 780          $this->triggerEvent('onAfterRoute');
 781  
 782          $Itemid = $this->input->getInt('Itemid', null);
 783          $this->authorise($Itemid);
 784      }
 785  
 786      /**
 787       * Set the current state of the detect browser option.
 788       *
 789       * @param   boolean  $state  The new state of the detect browser option
 790       *
 791       * @return  boolean  The previous state
 792       *
 793       * @since   3.2
 794       */
 795      public function setDetectBrowser($state = false)
 796      {
 797          $old = $this->getDetectBrowser();
 798          $this->detect_browser = $state;
 799  
 800          return $old;
 801      }
 802  
 803      /**
 804       * Set the current state of the language filter.
 805       *
 806       * @param   boolean  $state  The new state of the language filter
 807       *
 808       * @return  boolean  The previous state
 809       *
 810       * @since   3.2
 811       */
 812      public function setLanguageFilter($state = false)
 813      {
 814          $old = $this->getLanguageFilter();
 815          $this->language_filter = $state;
 816  
 817          return $old;
 818      }
 819  
 820      /**
 821       * Overrides the default template that would be used
 822       *
 823       * @param   \stdClass|string $template    The template name or definition
 824       * @param   mixed            $styleParams The template style parameters
 825       *
 826       * @return  void
 827       *
 828       * @since   3.2
 829       */
 830      public function setTemplate($template, $styleParams = null)
 831      {
 832          if (is_object($template)) {
 833              $templateName        = empty($template->template)
 834                  ? ''
 835                  : $template->template;
 836              $templateInheritable = empty($template->inheritable)
 837                  ? 0
 838                  : $template->inheritable;
 839              $templateParent      = empty($template->parent)
 840                  ? ''
 841                  : $template->parent;
 842              $templateParams      = empty($template->params)
 843                  ? $styleParams
 844                  : $template->params;
 845          } else {
 846              $templateName        = $template;
 847              $templateInheritable = 0;
 848              $templateParent      = '';
 849              $templateParams      = $styleParams;
 850          }
 851  
 852          if (is_dir(JPATH_THEMES . '/' . $templateName)) {
 853              $this->template = new \stdClass();
 854              $this->template->template = $templateName;
 855  
 856              if ($templateParams instanceof Registry) {
 857                  $this->template->params = $templateParams;
 858              } else {
 859                  $this->template->params = new Registry($templateParams);
 860              }
 861  
 862              $this->template->inheritable = $templateInheritable;
 863              $this->template->parent      = $templateParent;
 864  
 865              // Store the template and its params to the config
 866              $this->set('theme', $this->template->template);
 867              $this->set('themeParams', $this->template->params);
 868          }
 869      }
 870  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer