Source for file administrator.php

Documentation is available at administrator.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  Application
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Joomla! Administrator Application class
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  Application
  17.  * @since       3.2
  18.  */
  19. {
  20.     /**
  21.      * Class constructor.
  22.      *
  23.      * @param   mixed  $input   An optional argument to provide dependency injection for the application's
  24.      *                           input object.  If the argument is a JInput object that object will become
  25.      *                           the application's input object, otherwise a default input object is created.
  26.      * @param   mixed  $config  An optional argument to provide dependency injection for the application's
  27.      *                           config object.  If the argument is a JRegistry object that object will become
  28.      *                           the application's config object, otherwise a default config object is created.
  29.      * @param   mixed  $client  An optional argument to provide dependency injection for the application's
  30.      *                           client object.  If the argument is a JApplicationWebClient object that object will become
  31.      *                           the application's client object, otherwise a default client object is created.
  32.      *
  33.      * @since   3.2
  34.      */
  35.     public function __construct(JInput $input nullJRegistry $config nullJApplicationWebClient $client null)
  36.     {
  37.         // Register the application name
  38.         $this->_name = 'administrator';
  39.  
  40.         // Register the client ID
  41.         $this->_clientId = 1;
  42.  
  43.         // Execute the parent constructor
  44.         parent::__construct($input$config$client);
  45.  
  46.         // Set the root in the URI based on the application name
  47.         JUri::root(nullstr_ireplace('/' $this->getName()''JUri::base(true)));
  48.     }
  49.  
  50.     /**
  51.      * Dispatch the application
  52.      *
  53.      * @param   string  $component  The component which is being rendered.
  54.      *
  55.      * @return  void 
  56.      *
  57.      * @since   3.2
  58.      */
  59.     public function dispatch($component null)
  60.     {
  61.         if ($component === null)
  62.         {
  63.             $component JAdministratorHelper::findOption();
  64.         }
  65.  
  66.         // Load the document to the API
  67.         $this->loadDocument();
  68.  
  69.         // Set up the params
  70.         $document JFactory::getDocument();
  71.  
  72.         // Register the document object with JFactory
  73.         JFactory::$document $document;
  74.  
  75.         switch ($document->getType())
  76.         {
  77.             case 'html':
  78.                 $document->setMetaData('keywords'$this->get('MetaKeys'));
  79.  
  80.                 // Get the template
  81.                 $template $this->getTemplate(true);
  82.  
  83.                 // Store the template and its params to the config
  84.                 $this->set('theme'$template->template);
  85.                 $this->set('themeParams'$template->params);
  86.  
  87.                 break;
  88.  
  89.             default:
  90.                 break;
  91.         }
  92.  
  93.         $document->setTitle($this->get('sitename'' - ' JText::_('JADMINISTRATION'));
  94.         $document->setDescription($this->get('MetaDesc'));
  95.         $document->setGenerator('Joomla! - Open Source Content Management');
  96.  
  97.         $contents JComponentHelper::renderComponent($component);
  98.         $document->setBuffer($contents'component');
  99.  
  100.         // Trigger the onAfterDispatch event.
  101.         JPluginHelper::importPlugin('system');
  102.         $this->triggerEvent('onAfterDispatch');
  103.     }
  104.  
  105.     /**
  106.      * Method to run the Web application routines.
  107.      *
  108.      * @return  void 
  109.      *
  110.      * @since   3.2
  111.      */
  112.     protected function doExecute()
  113.     {
  114.         // Initialise the application
  115.         $this->initialiseApp(array('language' => $this->getUserState('application.lang')));
  116.  
  117.         // Test for magic quotes
  118.         if (get_magic_quotes_gpc())
  119.         {
  120.             $lang $this->getLanguage();
  121.  
  122.             if ($lang->hasKey('JERROR_MAGIC_QUOTES'))
  123.             {
  124.                 $this->enqueueMessage(JText::_('JERROR_MAGIC_QUOTES')'error');
  125.             }
  126.             else
  127.             {
  128.                 $this->enqueueMessage('Your host needs to disable magic_quotes_gpc to run this version of Joomla!''error');
  129.             }
  130.         }
  131.  
  132.         // Mark afterInitialise in the profiler.
  133.         JDEBUG $this->profiler->mark('afterInitialise'null;
  134.  
  135.         // Route the application
  136.         $this->route();
  137.  
  138.         // Mark afterRoute in the profiler.
  139.         JDEBUG $this->profiler->mark('afterRoute'null;
  140.  
  141.         // Dispatch the application
  142.         $this->dispatch();
  143.  
  144.         // Mark afterDispatch in the profiler.
  145.         JDEBUG $this->profiler->mark('afterDispatch'null;
  146.     }
  147.  
  148.     /**
  149.      * Return a reference to the JRouter object.
  150.      *
  151.      * @param   string  $name     The name of the application.
  152.      * @param   array   $options  An optional associative array of configuration settings.
  153.      *
  154.      * @return  JRouter 
  155.      *
  156.      * @since    3.2
  157.      */
  158.     public static function getRouter($name 'administrator'array $options array())
  159.     {
  160.         return parent::getRouter($name$options);
  161.     }
  162.  
  163.     /**
  164.      * Gets the name of the current template.
  165.      *
  166.      * @param   boolean  $params  True to return the template parameters
  167.      *
  168.      * @return  string  The name of the template.
  169.      *
  170.      * @since   3.2
  171.      * @throws  InvalidArgumentException
  172.      */
  173.     public function getTemplate($params false)
  174.     {
  175.         if (is_object($this->template))
  176.         {
  177.             if ($params)
  178.             {
  179.                 return $this->template;
  180.             }
  181.  
  182.             return $this->template->template;
  183.         }
  184.  
  185.         $admin_style JFactory::getUser()->getParam('admin_style');
  186.  
  187.         // Load the template name from the database
  188.         $db JFactory::getDbo();
  189.         $query $db->getQuery(true)
  190.             ->select('template, s.params')
  191.             ->from('#__template_styles as s')
  192.             ->join('LEFT''#__extensions as e ON e.type=' $db->quote('template'' AND e.element=s.template AND e.client_id=s.client_id');
  193.  
  194.         if ($admin_style)
  195.         {
  196.             $query->where('s.client_id = 1 AND id = ' . (int) $admin_style ' AND e.enabled = 1''OR');
  197.         }
  198.  
  199.         $query->where('s.client_id = 1 AND home = ' $db->quote('1')'OR')
  200.             ->order('home');
  201.         $db->setQuery($query);
  202.         $template $db->loadObject();
  203.  
  204.         $template->template JFilterInput::getInstance()->clean($template->template'cmd');
  205.         $template->params new JRegistry($template->params);
  206.  
  207.         if (!file_exists(JPATH_THEMES '/' $template->template '/index.php'))
  208.         {
  209.             $this->enqueueMessage(JText::_('JERROR_ALERTNOTEMPLATE')'error');
  210.             $template->params new JRegistry;
  211.             $template->template 'isis';
  212.         }
  213.  
  214.         // Cache the result
  215.         $this->template = $template;
  216.  
  217.         if (!file_exists(JPATH_THEMES '/' $template->template '/index.php'))
  218.         {
  219.             throw new InvalidArgumentException(JText::sprintf('JERROR_COULD_NOT_FIND_TEMPLATE'$template->template));
  220.         }
  221.  
  222.         if ($params)
  223.         {
  224.             return $template;
  225.         }
  226.  
  227.         return $template->template;
  228.     }
  229.  
  230.     /**
  231.      * Initialise the application.
  232.      *
  233.      * @param   array  $options  An optional associative array of configuration settings.
  234.      *
  235.      * @return  void 
  236.      *
  237.      * @since   3.2
  238.      */
  239.     protected function initialiseApp($options array())
  240.     {
  241.         $user JFactory::getUser();
  242.  
  243.         // If the user is a guest we populate it with the guest user group.
  244.         if ($user->guest)
  245.         {
  246.             $guestUsergroup JComponentHelper::getParams('com_users')->get('guest_usergroup'1);
  247.             $user->groups array($guestUsergroup);
  248.         }
  249.  
  250.         // If a language was specified it has priority, otherwise use user or default language settings
  251.         if (empty($options['language']))
  252.         {
  253.             $lang $user->getParam('admin_language');
  254.  
  255.             // Make sure that the user's language exists
  256.             if ($lang && JLanguage::exists($lang))
  257.             {
  258.                 $options['language'$lang;
  259.             }
  260.             else
  261.             {
  262.                 $params JComponentHelper::getParams('com_languages');
  263.                 $options['language'$params->get('administrator'$this->get('language''en-GB'));
  264.             }
  265.         }
  266.  
  267.         // One last check to make sure we have something
  268.         if (!JLanguage::exists($options['language']))
  269.         {
  270.             $lang $this->get('language''en-GB');
  271.  
  272.             if (JLanguage::exists($lang))
  273.             {
  274.                 $options['language'$lang;
  275.             }
  276.             else
  277.             {
  278.                 // As a last ditch fail to english
  279.                 $options['language''en-GB';
  280.             }
  281.         }
  282.  
  283.         // Execute the parent initialiseApp method.
  284.         parent::initialiseApp($options);
  285.  
  286.         // Load the language to the API
  287.         $this->loadLanguage();
  288.  
  289.         // Load the language from the API
  290.         $lang $this->getLanguage();
  291.  
  292.         // Register the language object with JFactory
  293.         JFactory::$language $lang;
  294.  
  295.         // Load Library language
  296.         $lang->load('lib_joomla'JPATH_ADMINISTRATOR);
  297.     }
  298.  
  299.     /**
  300.      * Login authentication function
  301.      *
  302.      * @param   array  $credentials  Array('username' => string, 'password' => string)
  303.      * @param   array  $options      Array('remember' => boolean)
  304.      *
  305.      * @return  boolean  True on success.
  306.      *
  307.      * @since   3.2
  308.      */
  309.     public function login($credentials$options array())
  310.     {
  311.         // The minimum group
  312.         $options['group''Public Backend';
  313.  
  314.         // Make sure users are not auto-registered
  315.         $options['autoregister'false;
  316.  
  317.         // Set the application login entry point
  318.         if (!array_key_exists('entry_url'$options))
  319.         {
  320.             $options['entry_url'JUri::base('index.php?option=com_users&task=login';
  321.         }
  322.  
  323.         // Set the access control action to check.
  324.         $options['action''core.login.admin';
  325.  
  326.         $result parent::login($credentials$options);
  327.  
  328.         if (!($result instanceof Exception))
  329.         {
  330.             $lang $this->input->getCmd('lang''en-GB');
  331.             $lang preg_replace('/[^A-Z-]/i'''$lang);
  332.             $this->setUserState('application.lang'$lang);
  333.  
  334.             static::purgeMessages();
  335.         }
  336.  
  337.         return $result;
  338.     }
  339.  
  340.     /**
  341.      * Purge the jos_messages table of old messages
  342.      *
  343.      * @return  void 
  344.      *
  345.      * @since   3.2
  346.      */
  347.     public static function purgeMessages()
  348.     {
  349.         $user JFactory::getUser();
  350.         $userid $user->get('id');
  351.  
  352.         $db JFactory::getDbo();
  353.         $query $db->getQuery(true)
  354.             ->select('*')
  355.             ->from($db->quoteName('#__messages_cfg'))
  356.             ->where($db->quoteName('user_id'' = ' . (int) $userid'AND')
  357.             ->where($db->quoteName('cfg_name'' = ' $db->quote('auto_purge')'AND');
  358.         $db->setQuery($query);
  359.         $config $db->loadObject();
  360.  
  361.         // Check if auto_purge value set
  362.         if (is_object($configand $config->cfg_name == 'auto_purge')
  363.         {
  364.             $purge $config->cfg_value;
  365.         }
  366.         else
  367.         {
  368.             // If no value set, default is 7 days
  369.             $purge 7;
  370.         }
  371.  
  372.         // If purge value is not 0, then allow purging of old messages
  373.         if ($purge 0)
  374.         {
  375.             // Purge old messages at day set in message configuration
  376.             $past JFactory::getDate(time($purge 86400);
  377.             $pastStamp $past->toSql();
  378.  
  379.             $query->clear()
  380.                 ->delete($db->quoteName('#__messages'))
  381.                 ->where($db->quoteName('date_time'' < ' $db->Quote($pastStamp)'AND')
  382.                 ->where($db->quoteName('user_id_to'' = ' . (int) $userid'AND');
  383.             $db->setQuery($query);
  384.             $db->execute();
  385.         }
  386.     }
  387.  
  388.     /**
  389.      * Rendering is the process of pushing the document buffers into the template
  390.      * placeholders, retrieving data from the document and pushing it into
  391.      * the application response buffer.
  392.      *
  393.      * @return  void 
  394.      *
  395.      * @since   3.2
  396.      */
  397.     protected function render()
  398.     {
  399.         // Get the JInput object
  400.         $input $this->input;
  401.  
  402.         $component $input->getCmd('option''com_login');
  403.         $file      $input->getCmd('tmpl''index');
  404.  
  405.         if ($component == 'com_login')
  406.         {
  407.             $file 'login';
  408.         }
  409.  
  410.         $this->set('themeFile'$file '.php');
  411.  
  412.         // Safety check for when configuration.php root_user is in use.
  413.         $config JFactory::getConfig();
  414.         $rootUser $config->get('root_user');
  415.  
  416.         if (property_exists('JConfig''root_user')
  417.             && (JFactory::getUser()->get('username'== $rootUser || JFactory::getUser()->id === (string) $rootUser))
  418.         {
  419.             $this->enqueueMessage(
  420.                 JText::sprintf(
  421.                     'JWARNING_REMOVE_ROOT_USER',
  422.                     'index.php?option=com_config&task=application.removeroot&' JSession::getFormToken('=1'
  423.                 ),
  424.                 'notice'
  425.             );
  426.         }
  427.  
  428.         parent::render();
  429.     }
  430.  
  431.     /**
  432.      * Route the application.
  433.      *
  434.      * Routing is the process of examining the request environment to determine which
  435.      * component should receive the request. The component optional parameters
  436.      * are then set in the request object to be processed when the application is being
  437.      * dispatched.
  438.      *
  439.      * @return  void 
  440.      *
  441.      * @since   3.2
  442.      */
  443.     protected function route()
  444.     {
  445.         $uri JUri::getInstance();
  446.  
  447.         if ($this->get('force_ssl'>= && strtolower($uri->getScheme()) != 'https')
  448.         {
  449.             // Forward to https
  450.             $uri->setScheme('https');
  451.             $this->redirect((string) $uri);
  452.         }
  453.  
  454.         // Trigger the onAfterRoute event.
  455.         JPluginHelper::importPlugin('system');
  456.         $this->triggerEvent('onAfterRoute');
  457.     }
  458. }

Documentation generated on Tue, 19 Nov 2013 14:53:35 +0100 by phpDocumentor 1.4.3