⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 factory.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/** * @version		$Id: factory.php 11680 2009-03-08 20:51:13Z willebil $ * @package		Joomla.Framework * @copyright	Copyright (C) 2005 - 2008 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 * * @static * @package		Joomla.Framework * @since	1.5 */class JFactory{	/**	 * Get a application object	 *	 * Returns a reference to the global {@link JApplication} object, only creating it	 * if it doesn't already exist.	 *	 * @access public	 * @param	mixed	$id 		A client identifier or name.	 * @param	array	$config 	An optional associative array of configuration settings.	 * @return object JApplication	 */	function &getApplication($id = null, $config = array(), $prefix='J')	{		static $instance;		if (!is_object($instance))		{			jimport( 'joomla.application.application' );			if (!$id) {				JError::raiseError(500, 'Application Instantiation Error');			}			$instance = JApplication::getInstance($id, $config, $prefix);		}		return $instance;	}	/**	 * Get a configuration object	 *	 * Returns a reference to the global {@link JRegistry} object, only creating it	 * if it doesn't already exist.	 *	 * @access public	 * @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')	{		static $instance;		if (!is_object($instance))		{			if ($file === null) {				$file = dirname(__FILE__).DS.'config.php';			}			$instance = JFactory::_createConfig($file, $type);		}		return $instance;	}	/**	 * Get a session object	 *	 * Returns a reference to the global {@link JSession} object, only creating it	 * if it doesn't already exist.	 *	 * @access public	 * @param array An array containing session options	 * @return object JSession	 */	function &getSession($options = array())	{		static $instance;		if (!is_object($instance)) {			$instance = JFactory::_createSession($options);		}		return $instance;	}	/**	 * Get a language object	 *	 * Returns a reference to the global {@link JLanguage} object, only creating it	 * if it doesn't already exist.	 *	 * @access public	 * @return object JLanguage	 */	function &getLanguage()	{		static $instance;		if (!is_object($instance))		{			//get the debug configuration setting			$conf =& JFactory::getConfig();			$debug = $conf->getValue('config.debug_lang');			$instance = JFactory::_createLanguage();			$instance->setDebug($debug);		}		return $instance;	}	/**	 * Get a document object	 *	 * Returns a reference to the global {@link JDocument} object, only creating it	 * if it doesn't already exist.	 *	 * @access public	 * @return object JLanguage	 */	function &getDocument()	{		static $instance;		if (!is_object( $instance )) {			$instance = JFactory::_createDocument();		}		return $instance;	}	/**	 * Get an user object	 *	 * Returns a reference to the global {@link JUser} object, only creating it	 * if it doesn't already exist.	 *	 * @param 	int 	$id 	The user to load - Can be an integer or string - If string, it is converted to ID automatically.	 *	 * @access public	 * @return object JUser	 */	function &getUser($id = null)	{		jimport('joomla.user.user');		if(is_null($id))		{			$session  =& JFactory::getSession();			$instance =& $session->get('user');			if (!is_a($instance, 'JUser')) {				$instance =& JUser::getInstance();			}		}		else		{			$instance =& JUser::getInstance($id);		}		return $instance;	}	/**	 * Get a cache object	 *	 * Returns a reference to the global {@link JCache} object	 *	 * @access public	 * @param string The cache group name	 * @param string The handler to use	 * @param string The storage method	 * @return object JCache	 */	function &getCache($group = '', $handler = 'callback', $storage = null)	{		$handler = ($handler == 'function') ? 'callback' : $handler;		$conf =& JFactory::getConfig();		if(!isset($storage)) {			$storage = $conf->getValue('config.cache_handler', 'file');		}		$options = array(			'defaultgroup' 	=> $group,			'cachebase' 	=> $conf->getValue('config.cache_path'),			'lifetime' 		=> $conf->getValue('config.cachetime') * 60,	// minutes to seconds			'language' 		=> $conf->getValue('config.language'),			'storage'		=> $storage		);		jimport('joomla.cache.cache');		$cache =& JCache::getInstance( $handler, $options );		$cache->setCaching($conf->getValue('config.caching'));		return $cache;	}	/**	 * Get an authorization object	 *	 * Returns a reference to the global {@link JAuthorization} object, only creating it	 * if it doesn't already exist.	 *	 * @access public	 * @return object JAuthorization	 */	function &getACL( )	{		static $instance;		if (!is_object($instance)) {			$instance = JFactory::_createACL();		}		return $instance;	}	/**	 * Get a template object	 *	 * Returns a reference to the global {@link JTemplate} object, only creating it	 * if it doesn't already exist.	 *	 * @access public	 * @return object JTemplate	 */	function &getTemplate( )	{		static $instance;		if (!is_object($instance)) {			$instance = JFactory::_createTemplate();		}		return $instance;	}	/**	 * Get a database object	 *	 * Returns a reference to the global {@link JDatabase} object, only creating it	 * if it doesn't already exist.	 *	 * @return object JDatabase	 */	function &getDBO()	{		static $instance;		if (!is_object($instance))		{			//get the debug configuration setting			$conf =& JFactory::getConfig();			$debug = $conf->getValue('config.debug');			$instance = JFactory::_createDBO();			$instance->debug($debug);		}		return $instance;	}	/**	 * Get a mailer object	 *	 * Returns a reference to the global {@link JMail} object, only creating it	 * if it doesn't already exist	 *	 * @access public	 * @return object JMail	 */	function &getMailer( )	{		static $instance;		if ( ! is_object($instance) ) {			$instance = JFactory::_createMailer();		}		// Create a copy of this object - do not return the original because it may be used several times		// PHP4 copies objects by value whereas PHP5 copies by reference		$copy	= (PHP_VERSION < 5) ? $instance : clone($instance);		return $copy;	}	/**	 * Get an XML document	 *	 * @access public	 * @param string The type of xml parser needed 'DOM', 'RSS' or 'Simple'	 * @param array:	 * 		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	 */	 function &getXMLParser( $type = 'DOM', $options = array())	 {		$doc = null;		switch (strtolower( $type ))		{			case 'rss' :			case 'atom' :			{				if (!is_null( $options['rssUrl'] ))				{					jimport ('simplepie.simplepie');					if(!is_writable(JPATH_BASE.DS.'cache')) {						$options['cache_time'] = 0;					}					$simplepie = new SimplePie(						$options['rssUrl'],						JPATH_BASE.DS.'cache',						isset( $options['cache_time'] ) ? $options['cache_time'] : 0					);					$simplepie->handle_content_type();					if ($simplepie->init()) {						$doc = $simplepie;					} else {						JError::raiseWarning( 'SOME_ERROR_CODE', JText::_('ERROR LOADING FEED DATA') );					}				}			}	break;			case 'simple' :			{				jimport('joomla.utilities.simplexml');				$doc = new JSimpleXML();			}	break;			case 'dom'  :			default :			{				if (!isset($options['lite']) || $options['lite'])				{					jimport('domit.xml_domit_lite_include');					$doc = new DOMIT_Lite_Document();				}				else				{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -