Source code for file /joomla/application/application.php
Documentation is available at application.php
* @version $Id: application.php 6760 2007-03-03 02:50:10Z Jinx $
* @package Joomla.Framework
* @subpackage Application
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
// Include library dependencies
jimport('joomla.application.plugin.*');
* Base class for a Joomla! application.
* Acts as a Factory class for application specific objects and provides many
* supporting API functions. Derived clases should supply the execute() and dispaly()
* @package Joomla.Framework
* @subpackage Application
* @var object JRouter object
* The application message queue.
* @param integer A client identifier.
$this->set( 'requestTime', date('Y-m-d H:i', time()) );
* Initialise the application.
* @param array An optional associative array of configuration settings.
//Set the language in the class
$conf->setValue('config.language', $options['language']);
//set language debug -> lazy load it later
$lang->setDebug($this->getCfg('debug_lang'));
// create the backward compatible language value for old 3PD components
if($conf->getValue('config.legacy')) {
$GLOBALS['mosConfig_lang'] =
$lang->getBackwardLang();
//create the router -> lazy load it later
* Routing is the process of examining the request environment to determine which
* which component should receive the request. This component optional parameters
* are then set in the request object to be processed when the application is being
// get the full request URI
$router->parse($uri->toString());
* Dispatch the applicaiton.
* Dispatching is the process of pulling the option from the request object and
* mapping them to a component. If the component do not exist, it handles
* determining a default component to dispatch
* Render the application.
* Rendering is the process of rendering the application into the JResponse buffer
function close( $code =
0 )
* Redirect to another URL.
* Optionally enqueues a message in the system message queue (which will be displayed
* the next time a page is loaded) using the enqueueMessage method. If the headers have
* not been sent the redirect will be accomplished using a "301 Moved Permanently"
* code in the header pointing to the new location. If the headers have already been
* sent this will be accomplished using a JavaScript statement.
* @param string $url The URL to redirect to.
* @param string $msg An optional message to display on redirect.
* @param string $msgType An optional message type.
* @return none; calls exit().
* @see JApplication::enqueueMessage()
function redirect( $url, $msg=
'', $msgType=
'message' )
// check for relative internal links
// If the message exists, enqueue it
// Persist messages if they exist
* If the headers have been sent, then we cannot send an additional location header
* so we will output a javascript redirect statement.
echo
"<script>document.location.href='$url';</script>\n";
//@ob_end_clean(); // clear output buffer
header( 'HTTP/1.1 301 Moved Permanently' );
header( 'Location: ' .
$url );
* Enqueue a system message.
* @param string $msg The message to enqueue.
* @param string $type The message type.
// For empty queue, if messages exists in the session, enqueue them first
$sessionQueue =
$session->get('application.queue');
if (count($sessionQueue)) {
$session->set('application.queue', null);
* Get the system message queue.
* @return The system message queue.
// For empty queue, if messages exists in the session, enqueue them
$sessionQueue =
$session->get('application.queue');
if (count($sessionQueue)) {
$session->set('application.queue', null);
* Gets a configuration value.
* @param string The name of the value to get.
* @return The user state.
* @example application/japplication-getcfg.php Getting a configuration value
return $config->getValue('config.' .
$varname);
* @param string The path of the state.
* @return mixed The user state.
$registry =
& $session->get('registry');
return $registry->getValue($key);
* Sets the value of a user state variable.
* @param string The path of the state.
* @param string The value of the variable.
* @return mixed The previous state, if one existed.
$registry =
& $session->get('registry');
return $registry->setValue($key, $value);
* Gets the value of a user state variable.
* @param string The key of the user state variable.
* @param string The name of the variable passed in a request.
* @param string The default value for the variable if not found. Optional.
* @return The request user state.
$key =
'request.' .
$key;
$cur_state =
(!is_null($old_state)) ?
$old_state :
$default;
* Registers a handler to a particular event group.
* @param string The event name.
* @param mixed The handler, a function or an instance of a event object.
$dispatcher->register($event, $handler);
* Calls all handlers associated with an event group.
* @param string The event name.
* @param array An array of arguments.
* @return array An array of results from each function call.
return $dispatcher->trigger($event, $args);
* Login authentication function.
* Username and encoded password are passed the the onLoginUser event which
* is responsible for the user validation. A successful validation updates
* the current session record with the users details.
* Username and encoded password are sent as credentials (along with other
* possibilities) to each observer (JAuthenticatePlugin) for user
* validation. Successful validation will update the current session with
* @param string The username.
* @param string The password.
* @param boolean True, if the user login needs to be remembered by the application.
* @return boolean True on success.
function login($username, $password, $remember)
/*if (empty($username)) {
return JError::raiseWarning('SOME_ERROR_CODE', JText::_('E_LOGIN_USERNAME'));
return JError::raiseWarning('SOME_ERROR_CODE', JText::_('E_LOGIN_PASSWORD'));
// Build the credentials array
$credentials['username'] =
$username;
$credentials['password'] =
$password;
// Get the global JAuthenticate object
jimport( 'joomla.user.authenticate');
$response =
$authenticate->authenticate($username, $password);
if (is_a($response, 'JAuthenticateResponse'))
// Import the user plugin group
// OK, the credentials are authenticated. Lets fire the onLogin event
$results =
$this->triggerEvent('onLoginUser', array((array)
$response, $remember));
* If any of the user plugins did not successfully
* complete the login routine then the whole method fails. Any
* errors raised should be done in the plugin as this provides the
* ability to provide much more information about why the routine
//TODO :: need to handle error reporting here
* Logout authentication function.
* Passed the current user information to the onLogoutUser event and reverts the current
* session record back to 'anonymous' parameters.
// Get a user object from the JApplication
// Hit the user last visit field
// Build the credentials array
$parameters['username'] =
$user->get('username');
$parameters['id'] =
$user->get('id');
// Import the user plugin group
// OK, the credentials are built. Lets fire the onLogout event
$results =
$this->triggerEvent('onLogoutUser', array($parameters));
* If any of the authentication plugins did not successfully complete
* the logout routine then the whole method fails. Any errors raised
* should be done in the plugin as this provides the ability to provide
* much more information about why the routine may have failed.
* @param string The session's name.
$session =
& $this->_createSession($name);
// Set user specific editor
$editor =
$user->getParam('editor', $this->getCfg('editor'));
$config->setValue('config.editor', $editor);
* @param string The path to the configuration file
* @param string The type of the configuration file
$config =
& $this->_createConfiguration($file);
// Set the database debug
$db->debug( $config->debug_db );
* Gets the name of the current template.
* Return a reference to the JRouter object.
* @return object JRouter.
* Create the configuration registry
* @param string $file The path to the configuration file
function &_createConfiguration($file)
jimport( 'joomla.registry.registry' );
// Create the JConfig object
// Get the global configuration object
// Load the configuration values into the registry
$registry->loadObject($config);
* Create the user session.
* Old sessions are flushed based on the configuration value for the cookie
* lifetime. If an existing session, then the last access time is updated.
* If a new session, a session id is generated and a record is created in
* @param string The sessions name.
* @return object JSession on success. May call exit() on database error.
function &_createSession( $name )
$options['name'] =
$name;
$storage->purge($session->getExpire() *
60);
// Session exists and is not expired, update time in session table
if ($storage->load($session->getId())) {
//Session doesn't exist yet, initalise and store it in the session table
$session->set('registry', new JRegistry('session'));
$session->set('user' , new JUser());
if (!$storage->insert( $session->getId(), $this->getClientId())) {
die( $storage->getError());
//TODO::Fix remember me (harden and move out of function)
//$usercookie = JRequest::getVar( 'usercookie', null, 'COOKIE' );
// Remember me cookie exists. Login with usercookie info.
// $this->login( $usercookie['username'], $usercookie['password'] );
* Create a JRouter object
* @return object JRouter.
function &_createRouter()
//Load the pathway object
jimport( 'joomla.application.router' );
$options['mode'] =
$this->getCfg('sef');
if($this->getCfg('sef_rewrite')) {
// Create a JRouter object
* Gets the client id of the current running application.
* @return int A client identifier.
* @return boolean True if this application is administrator.
* @return boolean True if this application is site.
* Deprecated, use JPathWay->addItem() method instead.
* @deprecated As of version 1.5
* @see JPathWay::addItem()
* To provide backward compatability if no second parameter is set
// Add item to the pathway object
if ($this->_pathway->addItem($name, $link)) {
* Deprecated, use JPathWay->getPathWayNames() method instead.
* @deprecated As of version 1.5
* @see JPathWay::getPathWayNames()
return $this->_pathway->getPathWayNames();
* Deprecated, use JDocument->get( 'head' ) instead.
* @deprecated As of version 1.5
return $document->get('head');
* Deprecated, use JDocument->setMetaData instead.
* @deprecated As of version 1.5
* @param string Name of the metadata tag
* @param string Content of the metadata tag
* @param string Deprecated, ignored
* @param string Deprecated, ignored
* @see JDocument::setMetaData()
function addMetaTag( $name, $content, $prepend =
'', $append =
'' )
$document->setMetadata($name, $content);
* Deprecated, use JDocument->setMetaData instead.
* @deprecated As of version 1.5
* @param string Name of the metadata tag
* @param string Content of the metadata tag
* @see JDocument::setMetaData()
* Deprecated, use JDocument->setMetaData instead
* @deprecated As of version 1.5
* @param string Name of the metadata tag
* @param string Content of the metadata tag
* @see JDocument::setMetaData()
* Deprecated, use JDocument->addCustomTag instead (only when document type is HTML).
* @deprecated As of version 1.5
* @param string Valid HTML
* @see JDocumentHTML::addCustomTag()
if($document->getType() ==
'html') {
$document->addCustomTag($html);
* @deprecated As of version 1.5
return count($menus->getItems('type', 'content_blog_section'));
* @deprecated As of version 1.5
return count($menus->getItems('type', 'content_blog_category'));
* @deprecated As of version 1.5
return count($menus->getItems('type', 'content_blog_section'));
* @deprecated As of version 1.5
return count($menus->getItems('type', 'content_typed'));
* @deprecated As of version 1.5
return count($menus->getItems('type', 'content_item_link'));
* Deprecated, use JApplicationHelper::getPath instead.
* @deprecated As of version 1.5
* @see JApplicationHelper::getPath()
function getPath($varname, $user_option =
null)
jimport('joomla.application.helper');
* Deprecated, use JURI::base() instead.
* @deprecated As of version 1.5
function getBasePath($client=
0, $addTrailingSlash =
true)
* Deprecated, use JFactory::getUser instead.
* @deprecated As of version 1.5
* @see JFactory::getUser()
* Deprecated, use JContentHelper::getItemid instead.
* @deprecated As of version 1.5
* @see JContentHelper::getItemid()
require_once JPATH_SITE .
'/components/com_content/helpers/content.php';
// Load the article data to know what section/category it is in.
return JContentHelper::getItemid($id, $article->catid, $article->sectionid);