Source for file joomla.php
Documentation is available at joomla.php
* @package FrameworkOnFramework
* @copyright Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
// Protect from unauthorized access
* Part of the FOF Platform Abstraction Layer.
* This implements the platform class for Joomla! 2.5 or later
* @package FrameworkOnFramework
* Is this platform enabled?
* @see FOFPlatformInterface::isEnabled()
// Make sure _JEXEC is defined
// We need JVERSION to be defined
// Check if JFactory exists
// Check if JApplication exists
* Main function to detect if we're running in a CLI environment and we're admin
* @return array isCLI and isAdmin. It's not an associtive array, so we can use list.
if (is_null($isCLI) &&
is_null($isAdmin))
if (is_null(JFactory::$application))
$isCLI =
JFactory::getApplication() instanceof
JException;
$isAdmin =
!JFactory::$application ?
false :
JFactory::getApplication()->isAdmin();
return array($isCLI, $isAdmin);
* Returns the base (root) directories for a given component.
* @param string $component The name of the component. For Joomla! this
* is something like "com_example"
* @see FOFPlatformInterface::getComponentBaseDirs()
* @return array A hash array with keys main, alt, site and admin.
$mainPath =
JPATH_SITE .
'/components/' .
$component;
$altPath =
JPATH_SITE .
'/components/' .
$component;
'site' =>
JPATH_SITE .
'/components/' .
$component,
* Return a list of the view template paths for this component.
* @param string $component The name of the component. For Joomla! this
* is something like "com_example"
* @param string $view The name of the view you're looking a
* @param string $layout The layout name to load, e.g. 'default'
* @param string $tpl The sub-template name to load (null by default)
* @param boolean $strict If true, only the specified layout will be searched for.
* Otherwise we'll fall back to the 'default' layout if the
* specified layout is not found.
* @see FOFPlatformInterface::getViewTemplateDirs()
public function getViewTemplatePaths($component, $view, $layout =
'default', $tpl =
null, $strict =
false)
$basePath =
$isAdmin ?
'admin:' :
'site:';
$basePath .=
$component .
'/';
$altBasePath =
$basePath;
$basePath .=
$view .
'/';
$basePath .
$layout .
($tpl ?
"_$tpl" :
''),
$altBasePath .
$layout .
($tpl ?
"_$tpl" :
''),
$basePath .
$layout .
($tpl ?
"_$tpl" :
''),
$basePath .
'default' .
($tpl ?
"_$tpl" :
''),
$altBasePath .
$layout .
($tpl ?
"_$tpl" :
''),
$altBasePath .
'default' .
($tpl ?
"_$tpl" :
''),
$altBasePath .
'default',
* Get application-specific suffixes to use with template paths. This allows
* you to look for view template overrides based on the application version.
* @return array A plain array of suffixes to try in template names
$versionParts =
explode('.', $jversion->RELEASE);
'.j' .
str_replace('.', '', $jversion->getHelpVersion()),
* Return the absolute path to the application's template overrides
* directory for a specific component. We will use it to look for template
* files instead of the regular component directorues. If the application
* does not have such a thing as template overrides return an empty string.
* @param string $component The name of the component for which to fetch the overrides
* @param boolean $absolute Should I return an absolute or relative path?
* @return string The path to the template overrides directory
$path =
$isAdmin ?
'administrator/templates/' :
'templates/';
if (substr($component, 0, 7) ==
'media:/')
$directory =
'media/' .
substr($component, 7);
$directory =
'html/' .
$component;
* Load the translation files for a given component.
* @param string $component The name of the component. For Joomla! this
* is something like "com_example"
* @see FOFPlatformInterface::loadTranslations()
$jlang->load($component, $paths[0], 'en-GB', true);
$jlang->load($component, $paths[0], null, true);
$jlang->load($component, $paths[1], 'en-GB', true);
$jlang->load($component, $paths[1], null, true);
* Authorise access to the component in the back-end.
* @param string $component The name of the component.
* @see FOFPlatformInterface::authorizeAdmin()
* @return boolean True to allow loading the component, false to halt loading
// Master access check for the back-end, Joomla! 1.6 style.
if (!$user->authorise('core.manage', $component)
&&
!$user->authorise('core.admin', $component))
* @param integer $id The user ID to load. Skip or use null to retrieve
* the object for the currently logged in user.
* @see FOFPlatformInterface::getUser()
* @return JUser The JUser object for the specified user
public function getUser($id =
null)
* Returns the JDocument object which handles this component's response.
* @see FOFPlatformInterface::getDocument()
* This method will try retrieving a variable from the request (input) data.
* @param string $key The user state key for the variable
* @param string $request The request variable name for the variable
* @param FOFInput $input The FOFInput object with the request (input) data
* @param mixed $default The default value. Default: null
* @param string $type The filter type for the variable data. Default: none (no filtering)
* @param boolean $setUserState Should I set the user state with the fetched value?
* @see FOFPlatformInterface::getUserStateFromRequest()
* @return mixed The value of the variable
public function getUserStateFromRequest($key, $request, $input, $default =
null, $type =
'none', $setUserState =
true)
return $input->get($request, $default, $type);
$old_state =
$app->getUserState($key, $default);
$cur_state =
(!is_null($old_state)) ?
$old_state :
$default;
$new_state =
$input->get($request, null, $type);
// Save the new value only if it was set in this request
$app->setUserState($key, $new_state);
* Load plugins of a specific type. Obviously this seems to only be required
* @param string $type The type of the plugins to be loaded
* @see FOFPlatformInterface::importPlugin()
* Execute plugins (system-level triggers) and fetch back an array with
* @param string $event The event (trigger) name, e.g. onBeforeScratchMyEar
* @param array $data A hash array of data sent to the plugins as part of the trigger
* @see FOFPlatformInterface::runPlugins()
* @return array A simple array containing the resutls of the plugins triggered
return $dispatcher->trigger($event, $data);
* @param string $action The ACL privilege to check, e.g. core.edit
* @param string $assetname The asset name to check, typically the component's name
* @see FOFPlatformInterface::authorise()
* @return boolean True if the user is allowed this action
public function authorise($action, $assetname)
* Is this the administrative section of the component?
* @see FOFPlatformInterface::isBackend()
return $isAdmin &&
!$isCli;
* Is this the public section of the component?
* @see FOFPlatformInterface::isFrontend()
return !$isAdmin &&
!$isCli;
* Is this a component running in a CLI application?
* @see FOFPlatformInterface::isCli()
return !$isAdmin &&
$isCli;
* Is AJAX re-ordering supported? This is 100% Joomla!-CMS specific. All
* other platforms should return false and never ask why.
* @see FOFPlatformInterface::supportsAjaxOrdering()
* Is the global FOF cache enabled?
* Saves something to the cache. This is supposed to be used for system-wide
* FOF data, not application data.
* @param string $key The key of the data to save
* @param string $content The actual data to save
* @return boolean True on success
public function setCache($key, $content)
$registry =
$this->getCacheObject();
$registry->set($key, $content);
return $this->saveCache();
* Retrieves data from the cache. This is supposed to be used for system-side
* FOF data, not application data.
* @param string $key The key of the data to retrieve
* @param string $default The default value to return if the key is not found or the cache is not populated
* @return string The cached value
public function getCache($key, $default =
null)
$registry =
$this->getCacheObject();
return $registry->get($key, $default);
* Gets a reference to the cache object, loading it from the disk if
* @param boolean $force Should I forcibly reload the registry?
private function &getCacheObject($force =
false)
// Check if we have to load the cache file or we are forced to do that
if (is_null($this->_cache) ||
$force)
// Create a new JRegistry object
// Try to get data from Joomla!'s cache
$data =
$cache->get('cache', 'fof');
// If data is not found, fall back to the legacy (FOF 2.1.rc3 and earlier) method
// Find the path to the file
$filename =
$cachePath .
'/cache.php';
// Load the cache file if it exists. JRegistryFormatPHP fails
// miserably, so I have to work around it.
$className =
'FOFCacheStorage';
$object =
new $className;
$this->_cache->loadObject($object);
'class' =>
'FOFCacheStorage'
$cache->store($this->_cache, 'cache', 'fof');
* Save the cache object back to disk
* @return boolean True on success
private function saveCache()
// Get the JRegistry object of our cached data
$registry =
$this->getCacheObject();
return $cache->store($registry, 'cache', 'fof');
* Clears the cache of system-wide FOF data. You are supposed to call this in
* your components' installation script post-installation and post-upgrade
* methods or whenever you are modifying the structure of database tables
* accessed by FOF. Please note that FOF's cache never expires and is not
* purged by Joomla!. You MUST use this method to manually purge the cache.
* @return boolean True on success
$cache->store($false, 'cache', 'fof');
* @param array $authInfo authentification information
* @return boolean True on success
$options =
array('remember' =>
false);
$response =
$authenticate->authenticate($authInfo, $options);
$results =
$this->runPlugins('onLoginUser', array((array)
$response, $options));
$session->set('user', $user);
* @return boolean True on success
$options =
array('remember' =>
false);
$parameters =
array('username' =>
$this->getUser()->username);
return $app->triggerEvent('onLogoutUser', array($parameters, $options));
Documentation generated on Tue, 19 Nov 2013 15:06:10 +0100 by phpDocumentor 1.4.3