Source code for file /joomla/factory.php
Documentation is available at factory.php
* @version $Id: factory.php 6725 2007-02-26 11:20:17Z tcp $
* @package Joomla.Framework
* @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.
* Joomla Framework Factory class
* @package Joomla.Framework
* Get a configuration object
* Returns a reference to the global {@link JRegistry} object, only creating it
* if it doesn't already exist.
* @param string The path to the configuration file
* @param string The type of the configuration file
* @return object JRegistry
function &getConfig($file =
null, $type =
'PHP')
$instance =
JFactory::_createConfig($file, $type);
* Returns a reference to the global {@link JSession} object, only creating it
* if it doesn't already exist.
* @param array An array containing session options
* @return object JSession
$instance =
JFactory::_createSession($options);
* Returns a reference to the global {@link JLanguage} object, only creating it
* if it doesn't already exist.
* @return object JLanguage
$instance =
JFactory::_createLanguage();
* Returns a reference to the global {@link JDocument} object, only creating it
* if it doesn't already exist.
* @return object JLanguage
$instance =
JFactory::_createDocument();
* Returns a reference to the global {@link JUser} object, only creating it
* if it doesn't already exist.
$instance =
& $session->get('user');
* Returns a reference to the global {@link JCache} object, only creating it
* if it doesn't already exist.
* @param string The cache group name
* @param string The cache class name
function &getCache($group=
'', $handler =
'callback')
$handler =
($handler ==
'function') ?
'callback' :
$handler;
// If we are in the installation application, we don't need to be
// creating any directories or have caching on
'cachebase' =>
JPATH_CACHE,
'defaultgroup' =>
$group,
'lifetime' =>
$conf->getValue('config.cachetime')
$cache->setCaching($conf->getValue('config.caching'));
* Get an authorization object
* Returns a reference to the global {@link JAuthorization} object, only creating it
* if it doesn't already exist.
* @return object JAuthorization
* Returns a reference to the global {@link JTemplate} object, only creating it
* if it doesn't already exist.
* @return object JTemplate
$instance =
JFactory::_createTemplate();
* Returns a reference to the global {@link JDatabase} object, only creating it
* if it doesn't already exist.
* @return object JDatabase
//get the debug configuration setting
$debug =
$conf->getValue('config.debug');
$instance->debug($debug);
* Returns a reference to the global {@link JMail} object, only creating it
* if it doesn't already exist
* @param string The type of xml parser needed 'DOM', 'RSS' or 'Simple'
* boolean ['lite'] When using 'DOM' if true or not defined then domit_lite is used
* string ['rssUrl'] the rss url to parse when using "RSS"
* string ['cache_time'] with 'RSS' - feed cache time. If not defined defaults to 3600 sec
* @return object Parsed XML document object
if (!is_null( $options['rssUrl'] )) {
$simplepie->feed_url($options['rssUrl']);
$simplepie->cache_location(JPATH_BASE.
DS.
'cache');
$simplepie->handle_content_type();
jimport('joomla.utilities.simplexml');
if (!isset
($options['lite']) ||
$options['lite'])
jimport('domit.xml_domit_lite_include');
$doc =
new DOMIT_Lite_Document();
jimport('domit.xml_domit_include');
$doc =
new DOMIT_Document();
* @param string $editor The editor to load, depends on the editor plugins that are installed
//get the editor configuration setting
$editor =
$conf->getValue('config.editor');
* Return a reference to the {@link JURI} object
function &getURI($uri =
'SERVER')
* Create a configuration object
* @param string The path to the configuration file
* @param string The type of the configuration file
* @return object JRegistry
function &_createConfig($file, $type =
'PHP')
jimport('joomla.registry.registry');
// Create the registry with a default namespace of config
// Create the JConfig object
// Load the configuration values into the registry
$registry->loadObject($config);
* Create a session object
* @param array $options An array containing session options
* @return object JSession
function &_createSession( $options =
array())
jimport('joomla.environment.session');
//get the editor configuration setting
$handler =
$conf->getValue('config.session_handler', 'none');
$options['expire'] =
$conf->getValue('config.lifetime', 15);
if ($session->getState() ==
'expired') {
* @return object JAuthorization
//TODO :: take the authorization class out of the application package
jimport( 'joomla.user.authorization' );
'db_table_prefix' =>
$db->getPrefix() .
'core_acl_',
* Create an database object
* @return object JDatabase
jimport('joomla.database.database');
$host =
$conf->getValue('config.host');
$user =
$conf->getValue('config.user');
$password =
$conf->getValue('config.password');
$db =
$conf->getValue('config.db');
$dbprefix =
$conf->getValue('config.dbprefix');
$dbtype =
$conf->getValue('config.dbtype');
$debug =
$conf->getValue('config.debug');
if ($db->getErrorNum() >
0) {
JError::raiseError('joomla.library:'.
$db->getErrorNum(), 'JDatabase::getInstance: Could not connect to database <br/>' .
$db->getErrorMsg() );
function &_createMailer()
$sendmail =
$conf->getValue('config.sendmail');
$smtpauth =
$conf->getValue('config.smtpauth');
$smtpuser =
$conf->getValue('config.smtpuser');
$smtppass =
$conf->getValue('config.smtppass');
$smtphost =
$conf->getValue('config.smtphost');
$mailfrom =
$conf->getValue('config.mailfrom');
$fromname =
$conf->getValue('config.fromname');
$mailer =
$conf->getValue('config.mailer');
$mail->setSender(array ($mailfrom, $fromname));
// Default mailer is to use PHP's mail function
$mail->useSMTP($smtpauth, $smtphost, $smtpuser, $smtppass);
* Create a template object
* @param array An array of support template files to load
* @return object JTemplate
function &_createTemplate($files =
array())
jimport('joomla.template.template');
if ($conf->getValue('config.caching')) {
$tmpl->enableTemplateCache( 'File', JPATH_BASE.
DS.
'cache'.
DS);
$tmpl->setNamespace( 'jtmpl' );
// load the wrapper and common templates
$tmpl->readTemplatesFromFile( 'page.html' );
$tmpl->applyInputFilter('ShortModifiers');
// load the stock templates
foreach ($files as $file) {
$tmpl->readTemplatesFromInput( $file );
$tmpl->addGlobalVar( 'option', $GLOBALS['option'] );
$tmpl->addGlobalVar( 'self', $_SERVER['PHP_SELF'] );
$tmpl->addGlobalVar( 'uri_query', $_SERVER['QUERY_STRING'] );
$tmpl->addGlobalVar( 'itemid', $GLOBALS['Itemid'] );
* Create a language object
* @return object JLanguage
function &_createLanguage()
$locale =
$conf->getValue('config.language');
$lang->setDebug($conf->getValue('config.debug_lang'));
* Create a document object
* @return object JDocument
function &_createDocument()
jimport('joomla.document.document');
jimport('joomla.environment.request');
//Keep backwards compatibility with Joomla! 1.0
$type =
JRequest::getVar( 'format', $raw ?
'raw' :
'html', '', 'string' );
'language' =>
$lang->getTag(),
'direction' =>
$lang->isRTL() ?
'rtl' :
'ltr'