_name = $this->getName();
$this->_clientId = $config['clientId'];
//Enable sessions by default
if(!isset($config['session'])) {
$config['session'] = true;
}
//Set the session default name
if(!isset($config['session_name'])) {
$config['session_name'] = $this->_name;
}
//Set the default configuration file
if(!isset($config['config_file'])) {
$config['config_file'] = 'configuration.php';
}
//create the configuration object
$this->_createConfiguration(JPATH_CONFIGURATION.DS.$config['config_file']);
//create the session if a session name is passed
if($config['session'] !== false) {
$this->_createSession(JUtility::getHash($config['session_name']));
}
$this->set( 'requestTime', gmdate('Y-m-d H:i') );
}
/**
* Returns a reference to the global JApplication object, only creating it if it
* doesn't already exist.
*
* This method must be invoked as:
*
$menu = &JApplication::getInstance();
*
* @access public
* @param mixed $id A client identifier or name.
* @param array $config An optional associative array of configuration settings.
* @return JApplication The appliction object.
* @since 1.5
*/
function &getInstance($client, $config = array(), $prefix = 'J')
{
static $instances;
if (!isset( $instances )) {
$instances = array();
}
if (empty($instances[$client]))
{
//Load the router object
jimport('joomla.application.helper');
$info =& JApplicationHelper::getClientInfo($client, true);
$path = $info->path.DS.'includes'.DS.'application.php';
if(file_exists($path))
{
//require_once $path; -->administrator/includes/application.php 移到上面定义
// Create a JRouter object
$classname = $prefix.ucfirst($client);
$instance = new $classname($config);
}
else
{
$error = JError::raiseError(500, 'Unable to load application: '.$client);
return $error;
}
$instances[$client] =& $instance;
}
return $instances[$client];
}
/**
* Initialise the application.
*
* @param array An optional associative array of configuration settings.
* @access public
*/
function initialise($options = array())
{
jimport('joomla.plugin.helper');
//Set the language in the class
$config =& JFactory::getConfig();
// Check that we were given a language in the array (since by default may be blank)
if(isset($options['language'])) {
$config->setValue('config.language', $options['language']);
}
// Set user specific editor
$user =& JFactory::getUser();
$editor = $user->getParam('editor', $this->getCfg('editor'));
$editor = JPluginHelper::isEnabled('editors', $editor) ? $editor : $this->getCfg('editor');
$config->setValue('config.editor', $editor);
}
/**
* Route the application.
*
* Routing is the process of examining the request environment to determine which
* component should receive the request. The component optional parameters
* are then set in the request object to be processed when the application is being
* dispatched.
*
* @abstract
* @access public
*/
function route()
{
// get the full request URI
$uri = clone(JURI::getInstance());
$router =& $this->getRouter();
$result = $router->parse($uri);
JRequest::set($result, 'get', false );
}
/**
* Dispatch the applicaiton.
*
* Dispatching is the process of pulling the option from the request object and
* mapping them to a component. If the component does not exist, it handles
* determining a default component to dispatch.
*
* @abstract
* @access public
*/
function dispatch($component)
{
$document =& JFactory::getDocument();
$document->setTitle( $this->getCfg('sitename' ). ' - ' .JText::_( 'Administration' ));
$document->setDescription( $this->getCfg('MetaDesc') );
$contents = JComponentHelper::renderComponent($component);
$document->setBuffer($contents, 'component');
}
/**
* Render the application.
*
* Rendering is the process of pushing the document buffers into the template
* placeholders, retrieving data from the document and pushing it into
* the JResponse buffer.
*
* @abstract
* @access public
*/
function render()
{
$params = array(
'template' => $this->getTemplate(),
'file' => 'index.php',
'directory' => JPATH_THEMES
);
$document =& JFactory::getDocument();
$data = $document->render($this->getCfg('caching'), $params );
JResponse::setBody($data);
}
/**
* Exit the application.
*
* @access public
* @param int Exit code
*/
function close( $code = 0 ) {
exit($code);
}
/**
* 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" or "303 See Other"
* code in the header pointing to the new location depending upon the moved flag. If the headers
* have already been sent this will be accomplished using a JavaScript statement.
*
* @access public
* @param string $url The URL to redirect to. Can only be http/https URL
* @param string $msg An optional message to display on redirect.
* @param string $msgType An optional message type.
* @param boolean True if the page is 301 Permanently Moved, otherwise 303 See Other is assumed.
* @return none; calls exit().
* @since 1.5
* @see JApplication::enqueueMessage()
*/
function redirect( $url, $msg='', $msgType='message', $moved = false )
{
// check for relative internal links
if (preg_match( '#^index[2]?.php#', $url )) {
$url = JURI::base() . $url;
}
// Strip out any line breaks
$url = preg_split("/[\r\n]/", $url);
$url = $url[0];
// If we don't start with a http we need to fix this before we proceed
// We could validly start with something else (e.g. ftp), though this would
// be unlikely and isn't supported by this API
if(!preg_match( '#^http#i', $url )) {
$uri =& JURI::getInstance();
$prefix = $uri->toString(Array('scheme', 'user', 'pass', 'host', 'port'));
if($url[0] == '/') {
// we just need the prefix since we have a path relative to the root
$url = $prefix . $url;
} else {
// its relative to where we are now, so lets add that
$parts = explode('/', $uri->toString(Array('path')));
array_pop($parts);
$path = implode('/',$parts).'/';
$url = $prefix . $path . $url;
}
}
// If the message exists, enqueue it
if (trim( $msg )) {
$this->enqueueMessage($msg, $msgType);
}
// Persist messages if they exist
if (count($this->_messageQueue))
{
$session =& JFactory::getSession();
$session->set('application.queue', $this->_messageQueue);
}
// If the headers have been sent, then we cannot send an additional location header
// so we will output a javascript redirect statement.
if (headers_sent()) {
echo "\n";
} else {
header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other');
header('Location: '.$url);
}
$this->close();
}
/**
* Enqueue a system message.
*
* @access public
* @param string $msg The message to enqueue.
* @param string $type The message type.
* @return void
* @since 1.5
*/
function enqueueMessage( $msg, $type = 'message' )
{
// For empty queue, if messages exists in the session, enqueue them first
if (!count($this->_messageQueue))
{
$session =& JFactory::getSession();
$sessionQueue = $session->get('application.queue');
if (count($sessionQueue)) {
$this->_messageQueue = $sessionQueue;
$session->set('application.queue', null);
}
}
// Enqueue the message
$this->_messageQueue[] = array('message' => $msg, 'type' => strtolower($type));
}
/**
* Get the system message queue.
*
* @access public
* @return The system message queue.
* @since 1.5
*/
function getMessageQueue()
{
// For empty queue, if messages exists in the session, enqueue them
if (!count($this->_messageQueue))
{
$session =& JFactory::getSession();
$sessionQueue = $session->get('application.queue');
if (count($sessionQueue)) {
$this->_messageQueue = $sessionQueue;
$session->set('application.queue', null);
}
}
return $this->_messageQueue;
}
/**
* Gets a configuration value.
*
* @access public
* @param string The name of the value to get.
* @return mixed The user state.
* @example application/japplication-getcfg.php Getting a configuration value
*/
function getCfg( $varname )
{
$config =& JFactory::getConfig();
return $config->getValue('config.' . $varname);
}
/**
* Method to get the application name
*
* The dispatcher name by default parsed using the classname, or it can be set
* by passing a $config['name'] in the class constructor
*
* @access public
* @return string The name of the dispatcher
* @since 1.5
*/
function getName()
{
$name = $this->_name;
if (empty( $name ))
{
$r = null;
if ( !preg_match( '/J(.*)/i', get_class( $this ), $r ) ) {
JError::raiseError(500, "JApplication::getName() : Can\'t get or parse class name.");
}
$name = strtolower( $r[1] );
}
return $name;
}
/**
* Gets a user state.
*
* @access public
* @param string The path of the state.
* @return mixed The user state.
*/
function getUserState( $key )
{
$session =& JFactory::getSession();
$registry =& $session->get('registry');
if(!is_null($registry)) {
return $registry->getValue($key);
}
return null;
}
/**
* Sets the value of a user state variable.
*
* @access public
* @param string The path of the state.
* @param string The value of the variable.
* @return mixed The previous state, if one existed.
*/
function setUserState( $key, $value )
{
$session =& JFactory::getSession();
$registry =& $session->get('registry');
if(!is_null($registry)) {
return $registry->setValue($key, $value);
}
return null;
}
/**
* Gets the value of a user state variable.
*
* @access public
* @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.
* @param string Filter for the variable, for valid values see {@link JFilterInput::clean()}. Optional.
* @return The request user state.
*/
function getUserStateFromRequest( $key, $request, $default = null, $type = 'none' )
{
$old_state = $this->getUserState( $key );
$cur_state = (!is_null($old_state)) ? $old_state : $default;
$new_state = JRequest::getVar($request, null, 'default', $type);
// Save the new value only if it was set in this request
if ($new_state !== null) {
$this->setUserState($key, $new_state);
} else {
$new_state = $cur_state;
}
return $new_state;
}
/**
* Registers a handler to a particular event group.
*
* @static
* @param string The event name.
* @param mixed The handler, a function or an instance of a event object.
* @return void
* @since 1.5
*/
function registerEvent($event, $handler)
{
$dispatcher =& JDispatcher::getInstance();
$dispatcher->register($event, $handler);
}
/**
* Calls all handlers associated with an event group.
*
* @static
* @param string The event name.
* @param array An array of arguments.
* @return array An array of results from each function call.
* @since 1.5
*/
function triggerEvent($event, $args=null)
{
$dispatcher =& JDispatcher::getInstance();
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 (authentication plugin) for user
* validation. Successful validation will update the current session with
* the user details.
*
* @param array Array( 'username' => string, 'password' => string )
* @param array Array( 'remember' => boolean )
* @return boolean True on success.
* @access public
* @since 1.5
*/
function login($credentials, $options = array())
{
// Get the global JAuthentication object
jimport( 'joomla.user.authentication');
$authenticate = & JAuthentication::getInstance();
$response = $authenticate->authenticate($credentials, $options);
if ($response->status === JAUTHENTICATE_STATUS_SUCCESS)
{
$session = &JFactory::getSession();
// we fork the session to prevent session fixation issues
$session->fork();
$this->_createSession($session->getId());
// Import the user plugin group
JPluginHelper::importPlugin('user');
// OK, the credentials are authenticated. Lets fire the onLogin event
$results = $this->triggerEvent('onLoginUser', array((array)$response, $options));
/*
* 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 may have failed.
*/
if (!in_array(false, $results, true))
{
// Set the remember me cookie if enabled
if (isset($options['remember']) && $options['remember'])
{
jimport('joomla.utilities.simplecrypt');
jimport('joomla.utilities.utility');
//Create the encryption key, apply extra hardening using the user agent string
$key = JUtility::getHash(@$_SERVER['HTTP_USER_AGENT']);
$crypt = new JSimpleCrypt($key);
$rcookie = $crypt->encrypt(serialize($credentials));
$lifetime = time() + 365*24*60*60;
setcookie( JUtility::getHash('JLOGIN_REMEMBER'), $rcookie, $lifetime, '/' );
}
return true;
}
}
// Trigger onLoginFailure Event
$this->triggerEvent('onLoginFailure', array((array)$response));
// If silent is set, just return false
if (isset($options['silent']) && $options['silent']) {
return false;
}
// Return the error
//return JError::raiseWarning('SOME_ERROR_CODE', JText::_('E_LOGIN_AUTHENTICATE'));
return false;
}
/**
* Logout authentication function.
*
* Passed the current user information to the onLogoutUser event and reverts the current
* session record back to 'anonymous' parameters.
*
* @param int $userid The user to load - Can be an integer or string - If string, it is converted to ID automatically
* @param array $options Array( 'clientid' => array of client id's )
*
* @access public
*/
function logout($userid = null, $options = array())
{
// Initialize variables
$retval = false;
// Get a user object from the JApplication
$user = &JFactory::getUser($userid);
// Build the credentials array
$parameters['username'] = $user->get('username');
$parameters['id'] = $user->get('id');
// Set clientid in the options array if it hasn't been set already
if(empty($options['clientid'])) {
$options['clientid'][] = $this->getClientId();
}
// Import the user plugin group
JPluginHelper::importPlugin('user');
// OK, the credentials are built. Lets fire the onLogout event
$results = $this->triggerEvent('onLogoutUser', array($parameters, $options));
/*
* 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.
*/
if (!in_array(false, $results, true)) {
setcookie( JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, '/' );
return true;
}
// Trigger onLoginFailure Event
$this->triggerEvent('onLogoutFailure', array($parameters));
return false;
}
/**
* Gets the name of the current template.
*
* @return string
*/
function getTemplate()
{
return 'system';
}
/**
* Return a reference to the application JRouter object.
*
* @access public
* @param array $options An optional associative array of configuration settings.
* @return JRouter.
* @since 1.5
*/
function &getRouter($name = null, $options = array())
{
if(!isset($name)) {
$name = $this->_name;
}
jimport( 'joomla.application.router' );
$router =& JRouter::getInstance($name, $options);
if (JError::isError($router)) {
$null = null;
return $null;
}
return $router;
}
/**
* Return a reference to the application JPathway object.
*
* @access public
* @param array $options An optional associative array of configuration settings.
* @return object JPathway.
* @since 1.5
*/
function &getPathway($name = null, $options = array())
{
if(!isset($name)) {
$name = $this->_name;
}
jimport( 'joomla.application.pathway' );
$pathway =& JPathway::getInstance($name, $options);
if (JError::isError($pathway)) {
$null = null;
return $null;
}
return $pathway;
}
/**
* Return a reference to the application JPathway object.
*
* @access public
* @param array $options An optional associative array of configuration settings.
* @return object JMenu.
* @since 1.5
*/
function &getMenu($name = null, $options = array())
{
if(!isset($name)) {
$name = $this->_name;
}
jimport( 'joomla.application.menu' );
$menu =& JMenu::getInstance($name, $options);
if (JError::isError($menu)) {
$null = null;
return $null;
}
return $menu;
}
/**
* Create the configuration registry
*
* @access private
* @param string $file The path to the configuration file
* return JConfig
*/
function &_createConfiguration($file)
{
jimport( 'joomla.registry.registry' );
require_once( $file );
// Create the JConfig object
$config = new JConfig();
// Get the global configuration object
$registry =& JFactory::getConfig();
// Load the configuration values into the registry
$registry->loadObject($config);
return $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
* the #__sessions table.
*
* @access private
* @param string The sessions name.
* @return object JSession on success. May call exit() on database error.
* @since 1.5
*/
function &_createSession( $name )
{
$options = array();
$options['name'] = $name;
switch($this->_clientId) {
case 0:
if($this->getCfg('force_ssl') == 2) {
$options['force_ssl'] = true;
}
break;
case 1:
if($this->getCfg('force_ssl') >= 1) {
$options['force_ssl'] = true;
}
break;
}
$session =& JFactory::getSession($options);
jimport('joomla.database.table');
$storage = & JTable::getInstance('session');
$storage->purge($session->getExpire());
// Session exists and is not expired, update time in session table
if ($storage->load($session->getId())) {
$storage->update();
return $session;
}
//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())) {
jexit( $storage->getError());
}
return $session;
}
/**
* Gets the client id of the current running application.
*
* @access public
* @return int A client identifier.
* @since 1.5
*/
function getClientId( )
{
return $this->_clientId;
}
/**
* Is admin interface?
*
* @access public
* @return boolean True if this application is administrator.
* @since 1.0.2
*/
function isAdmin()
{
return ($this->_clientId == 1);
}
/**
* Is site interface?
*
* @access public
* @return boolean True if this application is site.
* @since 1.5
*/
function isSite()
{
return ($this->_clientId == 0);
}
/**
* Deprecated functions
*/
/**
* Deprecated, use JPathWay->addItem() method instead.
*
* @since 1.0
* @deprecated As of version 1.5
* @see JPathWay::addItem()
*/
function appendPathWay( $name, $link = null )
{
/*
* To provide backward compatability if no second parameter is set
* set it to null
*/
if ($link == null) {
$link = '';
}
$pathway =& $this->getPathway();
if( defined( '_JLEGACY' ) && $link == '' )
{
$matches = array();
$links = preg_match_all ( '/]+href="([^"]*)"[^>]*>([^<]*)<\/a>/ui', $name, $matches, PREG_SET_ORDER );
foreach( $matches AS $match) {
// Add each item to the pathway object
if( !$pathway->addItem( $match[2], $match[1] ) ) {
return false;
}
}
return true;
}
else
{
// Add item to the pathway object
if ($pathway->addItem($name, $link)) {
return true;
}
}
return false;
}
/**
* Deprecated, use JPathway->getPathWayNames() method instead.
*
* @since 1.0
* @deprecated As of version 1.5
* @see JPathWay::getPathWayNames()
*/
function getCustomPathWay()
{
$pathway = $this->getPathway();
return $pathway->getPathWayNames();
}
/**
* Deprecated, use JDocument->get( 'head' ) instead.
*
* @since 1.0
* @deprecated As of version 1.5
* @see JDocument
* @see JObject::get()
*/
function getHead()
{
$document=& JFactory::getDocument();
return $document->get('head');
}
/**
* Deprecated, use JDocument->setMetaData instead.
*
* @since 1.0
* @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=& JFactory::getDocument();
$document->setMetadata($name, $content);
}
/**
* Deprecated, use JDocument->setMetaData instead.
*
* @since 1.0
* @deprecated As of version 1.5
* @param string Name of the metadata tag
* @param string Content of the metadata tag
* @see JDocument::setMetaData()
*/
function appendMetaTag( $name, $content )
{
$this->addMetaTag($name, $content);
}
/**
* Deprecated, use JDocument->setMetaData instead
*
* @since 1.0
* @deprecated As of version 1.5
* @param string Name of the metadata tag
* @param string Content of the metadata tag
* @see JDocument::setMetaData()
*/
function prependMetaTag( $name, $content )
{
$this->addMetaTag($name, $content);
}
/**
* Deprecated, use JDocument->addCustomTag instead (only when document type is HTML).
*
* @since 1.0
* @deprecated As of version 1.5
* @param string Valid HTML
* @see JDocumentHTML::addCustomTag()
*/
function addCustomHeadTag( $html )
{
$document=& JFactory::getDocument();
if($document->getType() == 'html') {
$document->addCustomTag($html);
}
}
/**
* Deprecated.
*
* @since 1.0
* @deprecated As of version 1.5
*/
function getBlogSectionCount( )
{
$menus = &JSite::getMenu();
return count($menus->getItems('type', 'content_blog_section'));
}
/**
* Deprecated.
*
* @since 1.0
* @deprecated As of version 1.5
*/
function getBlogCategoryCount( )
{
$menus = &JSite::getMenu();
return count($menus->getItems('type', 'content_blog_category'));
}
/**
* Deprecated.
*
* @since 1.0
* @deprecated As of version 1.5
*/
function getGlobalBlogSectionCount( )
{
$menus = &JSite::getMenu();
return count($menus->getItems('type', 'content_blog_section'));
}
/**
* Deprecated.
*
* @since 1.0
* @deprecated As of version 1.5
*/
function getStaticContentCount( )
{
$menus = &JSite::getMenu();
return count($menus->getItems('type', 'content_typed'));
}
/**
* Deprecated.
*
* @since 1.0
* @deprecated As of version 1.5
*/
function getContentItemLinkCount( )
{
$menus = &JSite::getMenu();
return count($menus->getItems('type', 'content_item_link'));
}
/**
* Deprecated, use JApplicationHelper::getPath instead.
*
* @since 1.0
* @deprecated As of version 1.5
* @see JApplicationHelper::getPath()
*/
function getPath($varname, $user_option = null)
{
jimport('joomla.application.helper');
return JApplicationHelper::getPath ($varname, $user_option);
}
/**
* Deprecated, use JURI::base() instead.
*
* @since 1.0
* @deprecated As of version 1.5
* @see JURI::base()
*/
function getBasePath($client=0, $addTrailingSlash = true)
{
return JURI::base();
}
/**
* Deprecated, use JFactory::getUser instead.
*
* @since 1.0
* @deprecated As of version 1.5
* @see JFactory::getUser()
*/
function &getUser()
{
$user =& JFactory::getUser();
return $user;
}
/**
* Deprecated, use ContentHelper::getItemid instead.
*
* @since 1.0
* @deprecated As of version 1.5
* @see ContentHelperRoute::getArticleRoute()
*/
function getItemid( $id )
{
require_once JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php';
// Load the article data to know what section/category it is in.
$article =& JTable::getInstance('content');
$article->load($id);
$needles = array(
'article' => (int) $id,
'category' => (int) $article->catid,
'section' => (int) $article->sectionid,
);
$item = ContentHelperRoute::_findItem($needles);
$return = is_object($item) ? $item->id : null;
return $return;
}
/**
* Deprecated, use JDocument::setTitle instead.
*
* @since 1.0
* @deprecated As of version 1.5
* @see JDocument::setTitle()
*/
function setPageTitle( $title=null )
{
$document=& JFactory::getDocument();
$document->setTitle($title);
}
/**
* Deprecated, use JDocument::getTitle instead.
*
* @since 1.0
* @deprecated As of version 1.5
* @see JDocument::getTitle()
*/
function getPageTitle()
{
$document=& JFactory::getDocument();
return $document->getTitle();
}
}
//-------------------application.application.php
//administrator/includes/application.php
//require_once( JPATH_COMPONENT.DS.'controller.php' );---从下面提上来
jimport('joomla.application.component.controller');
/**
* Content Component Controller
*
* @package Joomla
* @subpackage Content
* @since 1.5
*/
class ContentController extends JController
{
/**
* Articles element
*/
function element()
{
$model = &$this->getModel( 'element' );
$view = &$this->getView( 'element');
$view->setModel( $model, true );
$view->display();
}
/**
* Compiles a list of installed or defined modules
* @param database A database connector object
*/
function viewContent()
{
global $mainframe;
// Initialize variables
$db =& JFactory::getDBO();
$filter = null;
// Get some variables from the request
$sectionid = JRequest::getVar( 'sectionid', -1, '', 'int' );
$redirect = $sectionid;
$option = JRequest::getCmd( 'option' );
$context = 'com_content.viewcontent';
$filter_order = $mainframe->getUserStateFromRequest( $context.'filter_order', 'filter_order', '', 'cmd' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( $context.'filter_order_Dir', 'filter_order_Dir', '', 'word' );
$filter_state = $mainframe->getUserStateFromRequest( $context.'filter_state', 'filter_state', '', 'word' );
$catid = $mainframe->getUserStateFromRequest( $context.'catid', 'catid', 0, 'int' );
$filter_authorid = $mainframe->getUserStateFromRequest( $context.'filter_authorid', 'filter_authorid', 0, 'int' );
$filter_sectionid = $mainframe->getUserStateFromRequest( $context.'filter_sectionid', 'filter_sectionid', -1, 'int' );
$search = $mainframe->getUserStateFromRequest( $context.'search', 'search', '', 'string' );
if (strpos($search, '"') !== false) {
$search = str_replace(array('=', '<'), '', $search);
}
$search = JString::strtolower($search);
$limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
$limitstart = $mainframe->getUserStateFromRequest($context.'limitstart', 'limitstart', 0, 'int');
// In case limit has been changed, adjust limitstart accordingly
$limitstart = ( $limit != 0 ? (floor($limitstart / $limit) * $limit) : 0 );
//$where[] = "c.state >= 0";
$where[] = 'c.state != -2';
if (!$filter_order) {
$filter_order = 'section_name';
}
if ($filter_order == 'c.ordering') {
$order = ' ORDER BY section_name, cc.title, c.ordering '. $filter_order_Dir;
} else {
$order = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', section_name, cc.title, c.ordering';
}
$all = 1;
if ($filter_sectionid >= 0) {
$filter = ' WHERE cc.section = '. (int) $filter_sectionid;
}
$section->title = 'All Articles';
$section->id = 0;
/*
* Add the filter specific information to the where clause
*/
// Section filter
if ($filter_sectionid >= 0) {
$where[] = 'c.sectionid = ' . (int) $filter_sectionid;
}
// Category filter
if ($catid > 0) {
$where[] = 'c.catid = ' . (int) $catid;
}
// Author filter
if ($filter_authorid > 0) {
$where[] = 'c.created_by = ' . (int) $filter_authorid;
}
// Content state filter
if ($filter_state) {
if ($filter_state == 'P') {
$where[] = 'c.state = 1';
} else {
if ($filter_state == 'U') {
$where[] = 'c.state = 0';
} else if ($filter_state == 'A') {
$where[] = 'c.state = -1';
} else {
$where[] = 'c.state != -2';
}
}
}
// Keyword filter
if ($search) {
$where[] = '(LOWER( c.title ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false ) .
' OR c.id = ' . (int) $search . ')';
}
// Build the where clause of the content record query
$where = (count($where) ? ' WHERE '.implode(' AND ', $where) : '');
// Get the total number of records
$query = 'SELECT COUNT(*)' .
' FROM #__content AS c' .
' LEFT JOIN #__categories AS cc ON cc.id = c.catid' .
' LEFT JOIN #__sections AS s ON s.id = c.sectionid' .
$where;
$db->setQuery($query);
$total = $db->loadResult();
// Create the pagination object
jimport('joomla.html.pagination');
$pagination = new JPagination($total, $limitstart, $limit);
// Get the articles
$query = 'SELECT c.*, g.name AS groupname, cc.title AS name, u.name AS editor, f.content_id AS frontpage, s.title AS section_name, v.name AS author' .
' FROM #__content AS c' .
' LEFT JOIN #__categories AS cc ON cc.id = c.catid' .
' LEFT JOIN #__sections AS s ON s.id = c.sectionid' .
' LEFT JOIN #__groups AS g ON g.id = c.access' .
' LEFT JOIN #__users AS u ON u.id = c.checked_out' .
' LEFT JOIN #__users AS v ON v.id = c.created_by' .
' LEFT JOIN #__content_frontpage AS f ON f.content_id = c.id' .
$where .
$order;
$db->setQuery($query, $pagination->limitstart, $pagination->limit);
$rows = $db->loadObjectList();
// If there is a database query error, throw a HTTP 500 and exit
if ($db->getErrorNum()) {
JError::raiseError( 500, $db->stderr() );
return false;
}
// get list of categories for dropdown filter
$query = 'SELECT cc.id AS value, cc.title AS text, section' .
' FROM #__categories AS cc' .
' INNER JOIN #__sections AS s ON s.id = cc.section ' .
$filter .
' ORDER BY s.ordering, cc.ordering';
$lists['catid'] = ContentHelper::filterCategory($query, $catid);
// get list of sections for dropdown filter
$javascript = 'onchange="document.adminForm.submit();"';
$lists['sectionid'] = JHTML::_('list.section', 'filter_sectionid', $filter_sectionid, $javascript);
// get list of Authors for dropdown filter
$query = 'SELECT c.created_by, u.name' .
' FROM #__content AS c' .
' INNER JOIN #__sections AS s ON s.id = c.sectionid' .
' LEFT JOIN #__users AS u ON u.id = c.created_by' .
' WHERE c.state <> -1' .
' AND c.state <> -2' .
' GROUP BY u.name' .
' ORDER BY u.name';
$authors[] = JHTML::_('select.option', '0', '- '.JText::_('Select Author').' -', 'created_by', 'name');
$db->setQuery($query);
$authors = array_merge($authors, $db->loadObjectList());
$lists['authorid'] = JHTML::_('select.genericlist', $authors, 'filter_authorid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'created_by', 'name', $filter_authorid);
// state filter
$lists['state'] = JHTML::_('grid.state', $filter_state, 'Published', 'Unpublished', 'Archived');
// table ordering
$lists['order_Dir'] = $filter_order_Dir;
$lists['order'] = $filter_order;
// search filter
$lists['search'] = $search;
ContentView::showContent($rows, $lists, $pagination, $redirect);
}
/**
* Shows a list of archived articles
* @param int The section id
*/
function viewArchive()
{
global $mainframe;
// Initialize variables
$db =& JFactory::getDBO();
$sectionid = JRequest::getVar( 'sectionid', 0, '', 'int' );
$option = JRequest::getCmd( 'option' );
$filter_order = $mainframe->getUserStateFromRequest("$option.$sectionid.viewarchive.filter_order", 'filter_order', 'sectname', 'cmd');
$filter_order_Dir = $mainframe->getUserStateFromRequest("$option.$sectionid.viewarchive.filter_order_Dir", 'filter_order_Dir', '', 'word');
$catid = $mainframe->getUserStateFromRequest("$option.$sectionid.viewarchive.catid", 'catid', 0, 'int');
$limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
$limitstart = $mainframe->getUserStateFromRequest("$option.$sectionid.viewarchive.limitstart", 'limitstart', 0, 'int');
$filter_authorid = $mainframe->getUserStateFromRequest("$option.$sectionid.viewarchive.filter_authorid", 'filter_authorid', 0, 'int');
$filter_sectionid = $mainframe->getUserStateFromRequest("$option.$sectionid.viewarchive.filter_sectionid", 'filter_sectionid', 0, 'int');
$search = $mainframe->getUserStateFromRequest("$option.$sectionid.viewarchive.search", 'search', '', 'string');
if (strpos($search, '"') !== false) {
$search = str_replace(array('=', '<'), '', $search);
}
$search = JString::strtolower($search);
$redirect = $sectionid;
// A section id of zero means view all articles [all sections]
if ($sectionid == 0)
{
$where = array ('c.state = -1', 'c.catid = cc.id', 'cc.section = s.id', 's.scope = "content"');
$filter = ' , #__sections AS s WHERE s.id = c.section';
$all = 1;
}
else
{
//We are viewing a specific section
$where = array ('c.state = -1', 'c.catid = cc.id', 'cc.section = s.id', 's.scope = "content"', 'c.sectionid= '.(int) $sectionid);
$filter = ' WHERE section = '.$db->Quote($sectionid);
$all = NULL;
}
// Section filter
if ($filter_sectionid > 0)
{
$where[] = 'c.sectionid = ' . (int) $filter_sectionid;
}
// Author filter
if ($filter_authorid > 0)
{
$where[] = 'c.created_by = ' . (int) $filter_authorid;
}
// Category filter
if ($catid > 0)
{
$where[] = 'c.catid = ' . (int) $catid;
}
// Keyword filter
if ($search)
{
$where[] = 'LOWER( c.title ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
}
// TODO: Sanitise $filter_order
$filter_order_Dir = ($filter_order_Dir == 'ASC' ? 'ASC' : 'DESC');
$orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', sectname, cc.name, c.ordering';
$where = (count($where) ? ' WHERE '.implode(' AND ', $where) : '');
// get the total number of records
$query = 'SELECT COUNT(*)' .
' FROM #__content AS c' .
' LEFT JOIN #__categories AS cc ON cc.id = c.catid' .
' LEFT JOIN #__sections AS s ON s.id = c.sectionid' .
$where;
$db->setQuery($query);
$total = $db->loadResult();
jimport('joomla.html.pagination');
$pagination = new JPagination($total, $limitstart, $limit);
$query = 'SELECT c.*, g.name AS groupname, cc.name, v.name AS author, s.title AS sectname' .
' FROM #__content AS c' .
' LEFT JOIN #__categories AS cc ON cc.id = c.catid' .
' LEFT JOIN #__sections AS s ON s.id = c.sectionid' .
' LEFT JOIN #__groups AS g ON g.id = c.access' .
' LEFT JOIN #__users AS v ON v.id = c.created_by' .
$where .
$orderby;
$db->setQuery($query, $pagination->limitstart, $pagination->limit);
$rows = $db->loadObjectList();
// If there is a database query error, throw a HTTP 500 and exit
if ($db->getErrorNum())
{
JError::raiseError( 500, $db->stderr() );
return false;
}
// get list of categories for dropdown filter
$query = 'SELECT c.id AS value, c.title AS text' .
' FROM #__categories AS c' .
$filter .
' ORDER BY c.ordering';
$lists['catid'] = ContentHelper::filterCategory($query, $catid);
// get list of sections for dropdown filter
$javascript = 'onchange="document.adminForm.submit();"';
$lists['sectionid'] = JAdminMenus::SelectSection('filter_sectionid', $filter_sectionid, $javascript);
$section = & JTable::getInstance('section');
$section->load($sectionid);
// get list of Authors for dropdown filter
$query = 'SELECT c.created_by, u.name' .
' FROM #__content AS c' .
' INNER JOIN #__sections AS s ON s.id = c.sectionid' .
' LEFT JOIN #__users AS u ON u.id = c.created_by' .
' WHERE c.state = -1' .
' GROUP BY u.name' .
' ORDER BY u.name';
$db->setQuery($query);
$authors[] = JHTML::_('select.option', '0', '- '.JText::_('Select Author').' -', 'created_by', 'name');
$authors = array_merge($authors, $db->loadObjectList());
$lists['authorid'] = JHTML::_('select.genericlist', $authors, 'filter_authorid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'created_by', 'name', $filter_authorid);
// table ordering
$lists['order_Dir'] = $filter_order_Dir;
$lists['order'] = $filter_order;
// search filter
$lists['search'] = $search;
ContentView::showArchive($rows, $section, $lists, $pagination, $option, $all, $redirect);
}
/**
* Compiles information to add or edit the record
*
* @param database A database connector object
* @param integer The unique id of the record to edit (0 if new)
* @param integer The id of the content section
*/
function editContent($edit)
{
global $mainframe;
// Initialize variables
$db = & JFactory::getDBO();
$user = & JFactory::getUser();
$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
JArrayHelper::toInteger($cid, array(0));
$id = JRequest::getVar( 'id', $cid[0], '', 'int' );
$option = JRequest::getCmd( 'option' );
$nullDate = $db->getNullDate();
$contentSection = '';
$sectionid = 0;
// Create and load the content table row
$row = & JTable::getInstance('content');
if($edit)
$row->load($id);
if ($id) {
$sectionid = $row->sectionid;
if ($row->state < 0) {
$mainframe->redirect('index.php?option=com_content', JText::_('You cannot edit an archived item'));
}
}
// A sectionid of zero means grab from all sections
if ($sectionid == 0) {
$where = ' WHERE section NOT LIKE "%com_%"';
} else {
// Grab from the specific section
$where = ' WHERE section = '. $db->Quote( $sectionid );
}
/*
* If the item is checked out we cannot edit it... unless it was checked
* out by the current user.
*/
if ( JTable::isCheckedOut($user->get ('id'), $row->checked_out ))
{
$msg = JText::sprintf('DESCBEINGEDITTED', JText::_('The item'), $row->title);
$mainframe->redirect('index.php?option=com_content', $msg);
}
if ($id)
{
$row->checkout($user->get('id'));
if (trim($row->images)) {
$row->images = explode("\n", $row->images);
} else {
$row->images = array ();
}
$query = 'SELECT name' .
' FROM #__users'.
' WHERE id = '. (int) $row->created_by;
$db->setQuery($query);
$row->creator = $db->loadResult();
// test to reduce unneeded query
if ($row->created_by == $row->modified_by) {
$row->modifier = $row->creator;
} else {
$query = 'SELECT name' .
' FROM #__users' .
' WHERE id = '. (int) $row->modified_by;
$db->setQuery($query);
$row->modifier = $db->loadResult();
}
$query = 'SELECT COUNT(content_id)' .
' FROM #__content_frontpage' .
' WHERE content_id = '. (int) $row->id;
$db->setQuery($query);
$row->frontpage = $db->loadResult();
if (!$row->frontpage) {
$row->frontpage = 0;
}
}
else
{
if (!$sectionid && JRequest::getInt('filter_sectionid')) {
$sectionid =JRequest::getInt('filter_sectionid');
}
if (JRequest::getInt('catid'))
{
$row->catid = JRequest::getInt('catid');
$category = & JTable::getInstance('category');
$category->load($row->catid);
$sectionid = $category->section;
} else {
$row->catid = NULL;
}
$createdate =& JFactory::getDate();
$row->sectionid = $sectionid;
$row->version = 0;
$row->state = 1;
$row->ordering = 0;
$row->images = array ();
$row->publish_up = $createdate->toUnix();
$row->publish_down = JText::_('Never');
$row->creator = '';
$row->created = $createdate->toUnix();
$row->modified = $nullDate;
$row->modifier = '';
$row->frontpage = 0;
}
$javascript = "onchange=\"changeDynaList( 'catid', sectioncategories, document.adminForm.sectionid.options[document.adminForm.sectionid.selectedIndex].value, 0, 0);\"";
$query = 'SELECT s.id, s.title' .
' FROM #__sections AS s' .
' ORDER BY s.ordering';
$db->setQuery($query);
$sections[] = JHTML::_('select.option', '-1', '- '.JText::_('Select Section').' -', 'id', 'title');
$sections[] = JHTML::_('select.option', '0', JText::_('Uncategorized'), 'id', 'title');
$sections = array_merge($sections, $db->loadObjectList());
$lists['sectionid'] = JHTML::_('select.genericlist', $sections, 'sectionid', 'class="inputbox" size="1" '.$javascript, 'id', 'title', intval($row->sectionid));
foreach ($sections as $section)
{
$section_list[] = (int) $section->id;
// get the type name - which is a special category
if ($row->sectionid) {
if ($section->id == $row->sectionid) {
$contentSection = $section->title;
}
} else {
if ($section->id == $sectionid) {
$contentSection = $section->title;
}
}
}
$sectioncategories = array ();
$sectioncategories[-1] = array ();
$sectioncategories[-1][] = JHTML::_('select.option', '-1', JText::_( 'Select Category' ), 'id', 'title');
$section_list = implode('\', \'', $section_list);
$query = 'SELECT id, title, section' .
' FROM #__categories' .
' WHERE section IN ( \''.$section_list.'\' )' .
' ORDER BY ordering';
$db->setQuery($query);
$cat_list = $db->loadObjectList();
// Uncategorized category mapped to uncategorized section
$uncat = new stdClass();
$uncat->id = 0;
$uncat->title = JText::_('Uncategorized');
$uncat->section = 0;
$cat_list[] = $uncat;
foreach ($sections as $section)
{
$sectioncategories[$section->id] = array ();
$rows2 = array ();
foreach ($cat_list as $cat)
{
if ($cat->section == $section->id) {
$rows2[] = $cat;
}
}
foreach ($rows2 as $row2) {
$sectioncategories[$section->id][] = JHTML::_('select.option', $row2->id, $row2->title, 'id', 'title');
}
}
$sectioncategories['-1'][] = JHTML::_('select.option', '-1', JText::_( 'Select Category' ), 'id', 'title');
$categories = array();
foreach ($cat_list as $cat) {
if($cat->section == $row->sectionid)
$categories[] = $cat;
}
$categories[] = JHTML::_('select.option', '-1', JText::_( 'Select Category' ), 'id', 'title');
$lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox" size="1"', 'id', 'title', intval($row->catid));
// build the html select list for ordering
$query = 'SELECT ordering AS value, title AS text' .
' FROM #__content' .
' WHERE catid = ' . (int) $row->catid .
' AND state >= 0' .
' ORDER BY ordering';
if($edit)
$lists['ordering'] = JHTML::_('list.specificordering', $row, $id, $query, 1);
else
$lists['ordering'] = JHTML::_('list.specificordering', $row, '', $query, 1);
// build the html radio buttons for frontpage
$lists['frontpage'] = JHTML::_('select.booleanlist', 'frontpage', '', $row->frontpage);
// build the html radio buttons for published
$lists['state'] = JHTML::_('select.booleanlist', 'state', '', $row->state);
/*
* We need to unify the introtext and fulltext fields and have the
* fields separated by the {readmore} tag, so lets do that now.
*/
if (JString::strlen($row->fulltext) > 1) {
$row->text = $row->introtext . "
" . $row->fulltext;
} else {
$row->text = $row->introtext;
}
// Create the form
$form = new JParameter('', JPATH_COMPONENT.DS.'models'.DS.'article.xml');
// Details Group
$active = (intval($row->created_by) ? intval($row->created_by) : $user->get('id'));
$form->set('created_by', $active);
$form->set('access', $row->access);
$form->set('created_by_alias', $row->created_by_alias);
$form->set('created', JHTML::_('date', $row->created, '%Y-%m-%d %H:%M:%S'));
$form->set('publish_up', JHTML::_('date', $row->publish_up, '%Y-%m-%d %H:%M:%S'));
if (JHTML::_('date', $row->publish_down, '%Y') <= 1969 || $row->publish_down == $db->getNullDate()) {
$form->set('publish_down', JText::_('Never'));
} else {
$form->set('publish_down', JHTML::_('date', $row->publish_down, '%Y-%m-%d %H:%M:%S'));
}
// Advanced Group
$form->loadINI($row->attribs);
// Metadata Group
$form->set('description', $row->metadesc);
$form->set('keywords', $row->metakey);
$form->loadINI($row->metadata);
ContentView::editContent($row, $contentSection, $lists, $sectioncategories, $option, $form);
}
/**
* Saves the article an edit form submit
* @param database A database connector object
*/
function saveContent()
{
global $mainframe;
// Check for request forgeries
//JRequest::checkToken() or jexit( 'Invalid Token' );
$tmpvar=trim(str_replace(array(' '), '',$_POST['title']));
if (empty($tmpvar)){
echo('[err]标题不能为空[/err]');
return false;
}
$tmpvar=trim(str_replace(array(' '), '',$_POST['text']));
if (empty($tmpvar)){
echo('[err]正文不能为空[/err]');
return false;
}
// Initialize variables
$db = & JFactory::getDBO();
$user = & JFactory::getUser();
$dispatcher = & JDispatcher::getInstance();
JPluginHelper::importPlugin('content');
$details = JRequest::getVar( 'details', array(), 'post', 'array');
$option = JRequest::getCmd( 'option' );
$task = JRequest::getCmd( 'task' );
$sectionid = JRequest::getVar( 'sectionid', 0, '', 'int' );
$redirect = JRequest::getVar( 'redirect', $sectionid, 'post', 'int' );
$menu = JRequest::getVar( 'menu', 'mainmenu', 'post', 'cmd' );
$menuid = JRequest::getVar( 'menuid', 0, 'post', 'int' );
$nullDate = $db->getNullDate();
$row = & JTable::getInstance('content');
if (!$row->bind(JRequest::get('post'))) {
//JError::raiseError( 500, $db->stderr() );
echo('[err]获取参数失败[/err]');
return false;
}
$row->bind($details);
// sanitise id field
$row->id = (int) $row->id;
$isNew = true;
// Are we saving from an item edit?
if ($row->id) {
$isNew = false;
$datenow =& JFactory::getDate();
$row->modified = $datenow->toMySQL();
$row->modified_by = $user->get('id');
}
$row->created_by = $row->created_by ? $row->created_by : $user->get('id');
if(!empty($row->created)){
$row->created=str_replace(array('年', '月'), '-',$row->created);
$row->created=str_replace(array('日'), '',$row->created);
if ($row->created && strlen(trim( $row->created )) <= 10) {
$row->created .= ' 00:00:00';
}
if (strtotime($row->created)==false||strtotime($row->created)==-1){
echo("[err]文章发布时间格式错误[/err]");
exit();
}
}
else{
$row->created=date("Y-m-d H:i:s");
}
$config =& JFactory::getConfig();
$tzoffset = $config->getValue('config.offset');
$date =& JFactory::getDate($row->created, $tzoffset);
$row->created = $date->toMySQL();
//zzcity add
if (strlen(trim($row->publish_up))<4){
$row->publish_up=$row->created;
}
else{
// Append time if not added to publish date
if (strlen(trim($row->publish_up)) <= 10) {
$row->publish_up .= ' 00:00:00';
}
$date =& JFactory::getDate($row->publish_up, $tzoffset);
$row->publish_up = $date->toMySQL();
}
// Handle never unpublish date
if (trim($row->publish_down) == JText::_('Never') || trim( $row->publish_down ) == '')
{
$row->publish_down = $nullDate;
}
else
{
if (strlen(trim( $row->publish_down )) <= 10) {
$row->publish_down .= ' 00:00:00';
}
$date =& JFactory::getDate($row->publish_down, $tzoffset);
$row->publish_down = $date->toMySQL();
}
// Get a state and parameter variables from the request
$row->state = JRequest::getVar( 'state', 0, '', 'int' );
$params = JRequest::getVar( 'params', null, 'post', 'array' );
// Build parameter INI string
if (is_array($params))
{
$txt = array ();
foreach ($params as $k => $v) {
$txt[] = "$k=$v";
}
$row->attribs = implode("\n", $txt);
}
// Get metadata string
$metadata = JRequest::getVar( 'meta', null, 'post', 'array');
if (is_array($metadata))
{
$txt = array();
foreach ($metadata as $k => $v) {
if ($k == 'description') {
$row->metadesc = $v;
} elseif ($k == 'keywords') {
$row->metakey = $v;
} else {
$txt[] = "$k=$v";
}
}
$row->metadata = implode("\n", $txt);
}
// Prepare the content for saving to the database
ContentHelper::saveContentPrep( $row );
// Make sure the data is valid
if (!$row->check()) {
//JError::raiseError( 500, $db->stderr() );
echo('[err]一些参数取值无效[/err]');
return false;
}
// Increment the content version number
$row->version++;
$result = $dispatcher->trigger('onBeforeContentSave', array(&$row, $isNew));
if(in_array(false, $result, true)) {
JError::raiseError(500, $row->getError());
return false;
}
// Store the content to the database
if (!$row->store()) {
//JError::raiseError( 500, $db->stderr() );
echo('[err]保存数据失败[/err]');
return false;
}
// Check the article and update item order
$row->checkin();
$row->reorder('catid = '.(int) $row->catid.' AND state >= 0');
/*
* We need to update frontpage status for the article.
*
* First we include the frontpage table and instantiate an instance of it.
*/
require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_frontpage'.DS.'tables'.DS.'frontpage.php');
$fp = new TableFrontPage($db);
// Is the article viewable on the frontpage?
if (JRequest::getVar( 'frontpage', 0, '', 'int' ))
{
// Is the item already viewable on the frontpage?
if (!$fp->load($row->id))
{
// Insert the new entry
$query = 'INSERT INTO #__content_frontpage' .
' VALUES ( '. (int) $row->id .', 1 )';
$db->setQuery($query);
if (!$db->query())
{
JError::raiseError( 500, $db->stderr() );
return false;
}
$fp->ordering = 1;
}
}
else
{
// Delete the item from frontpage if it exists
if (!$fp->delete($row->id)) {
$msg .= $fp->stderr();
}
$fp->ordering = 0;
}
$fp->reorder();
$cache = & JFactory::getCache('com_content');
$cache->clean();
$dispatcher->trigger('onAfterContentSave', array(&$row, $isNew));
switch ($task)
{
case 'go2menu' :
$mainframe->redirect('index.php?option=com_menus&menutype='.$menu);
break;
case 'go2menuitem' :
$mainframe->redirect('index.php?option=com_menus&menutype='.$menu.'&task=edit&id='.$menuid);
break;
case 'menulink' :
ContentHelper::menuLink($redirect, $row->id);
break;
case 'resethits' :
ContentHelper::resetHits($redirect, $row->id);
break;
case 'apply' :
echo('[ok]');
//$msg = JText::sprintf('SUCCESSFULLY SAVED CHANGES TO ARTICLE', $row->title);
//$mainframe->redirect('index.php?option=com_content§ionid='.$redirect.'&task=edit&cid[]='.$row->id, $msg);
break;
case 'save' :
default :
$msg = JText::sprintf('Successfully Saved Article', $row->title);
$mainframe->redirect('index.php?option=com_content§ionid='.$redirect, $msg);
break;
}
}
/**
* Changes the state of one or more content pages
*
* @param string The name of the category section
* @param integer A unique category id (passed from an edit form)
* @param array An array of unique category id numbers
* @param integer 0 if unpublishing, 1 if publishing
* @param string The name of the current user
*/
function changeContent( $state = 0 )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db = & JFactory::getDBO();
$user = & JFactory::getUser();
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
JArrayHelper::toInteger($cid);
$option = JRequest::getCmd( 'option' );
$task = JRequest::getCmd( 'task' );
$rtask = JRequest::getCmd( 'returntask', '', 'post' );
if ($rtask) {
$rtask = '&task='.$rtask;
}
if (count($cid) < 1) {
$redirect = JRequest::getVar( 'redirect', '', 'post', 'int' );
$action = ($state == 1) ? 'publish' : ($state == -1 ? 'archive' : 'unpublish');
$msg = JText::_('Select an item to') . ' ' . JText::_($action);
$mainframe->redirect('index.php?option='.$option.$rtask.'§ionid='.$redirect, $msg, 'error');
}
// Get some variables for the query
$uid = $user->get('id');
$total = count($cid);
$cids = implode(',', $cid);
$query = 'UPDATE #__content' .
' SET state = '. (int) $state .
' WHERE id IN ( '. $cids .' ) AND ( checked_out = 0 OR (checked_out = '. (int) $uid .' ) )';
$db->setQuery($query);
if (!$db->query()) {
JError::raiseError( 500, $db->getErrorMsg() );
return false;
}
if (count($cid) == 1) {
$row = & JTable::getInstance('content');
$row->checkin($cid[0]);
}
switch ($state)
{
case -1 :
$msg = JText::sprintf('Item(s) successfully Archived', $total);
break;
case 1 :
$msg = JText::sprintf('Item(s) successfully Published', $total);
break;
case 0 :
default :
if ($task == 'unarchive') {
$msg = JText::sprintf('Item(s) successfully Unarchived', $total);
} else {
$msg = JText::sprintf('Item(s) successfully Unpublished', $total);
}
break;
}
$cache = & JFactory::getCache('com_content');
$cache->clean();
// Get some return/redirect information from the request
$redirect = JRequest::getVar( 'redirect', $row->sectionid, 'post', 'int' );
$mainframe->redirect('index.php?option='.$option.$rtask.'§ionid='.$redirect, $msg);
}
/**
* Changes the frontpage state of one or more articles
*
*/
function toggleFrontPage()
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db =& JFactory::getDBO();
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
$option = JRequest::getCmd( 'option' );
$msg = null;
JArrayHelper::toInteger($cid);
if (count($cid) < 1) {
$msg = JText::_('Select an item to toggle');
$mainframe->redirect('index.php?option='.$option, $msg, 'error');
}
/*
* We need to update frontpage status for the articles.
*
* First we include the frontpage table and instantiate an instance of
* it.
*/
require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_frontpage'.DS.'tables'.DS.'frontpage.php');
$fp = new TableFrontPage($db);
foreach ($cid as $id)
{
// toggles go to first place
if ($fp->load($id)) {
if (!$fp->delete($id)) {
$msg .= $fp->stderr();
}
$fp->ordering = 0;
} else {
// new entry
$query = 'INSERT INTO #__content_frontpage' .
' VALUES ( '. (int) $id .', 0 )';
$db->setQuery($query);
if (!$db->query()) {
JError::raiseError( 500, $db->stderr() );
return false;
}
$fp->ordering = 0;
}
$fp->reorder();
}
$cache = & JFactory::getCache('com_content');
$cache->clean();
$mainframe->redirect('index.php?option='.$option, $msg);
}
function removeContent()
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db = & JFactory::getDBO();
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
$option = JRequest::getCmd( 'option' );
$return = JRequest::getCmd( 'returntask', '', 'post' );
$nullDate = $db->getNullDate();
JArrayHelper::toInteger($cid);
if (count($cid) < 1) {
$msg = JText::_('Select an item to delete');
$mainframe->redirect('index.php?option='.$option, $msg, 'error');
}
// Removed content gets put in the trash [state = -2] and ordering is always set to 0
$state = '-2';
$ordering = '0';
// Get the list of content id numbers to send to trash.
$cids = implode(',', $cid);
// Update articles in the database
$query = 'UPDATE #__content' .
' SET state = '.(int) $state .
', ordering = '.(int) $ordering .
', checked_out = 0, checked_out_time = '.$db->Quote($nullDate).
' WHERE id IN ( '. $cids. ' )';
$db->setQuery($query);
if (!$db->query())
{
JError::raiseError( 500, $db->getErrorMsg() );
return false;
}
$cache = & JFactory::getCache('com_content');
$cache->clean();
$msg = JText::sprintf('Item(s) sent to the Trash', count($cid));
$mainframe->redirect('index.php?option='.$option.'&task='.$return, $msg);
}
/**
* Cancels an edit operation
*/
function cancelContent()
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db = & JFactory::getDBO();
// Check the article in if checked out
$row = & JTable::getInstance('content');
$row->bind(JRequest::get('post'));
$row->checkin();
$mainframe->redirect('index.php?option=com_content');
}
/**
* Moves the order of a record
* @param integer The increment to reorder by
*/
function orderContent($direction)
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db = & JFactory::getDBO();
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
if (isset( $cid[0] ))
{
$row = & JTable::getInstance('content');
$row->load( (int) $cid[0] );
$row->move($direction, 'catid = ' . (int) $row->catid . ' AND state >= 0' );
$cache = & JFactory::getCache('com_content');
$cache->clean();
}
$mainframe->redirect('index.php?option=com_content');
}
/**
* Form for moving item(s) to a different section and category
*/
function moveSection()
{
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db =& JFactory::getDBO();
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
$sectionid = JRequest::getVar( 'sectionid', 0, '', 'int' );
JArrayHelper::toInteger($cid);
if (count($cid) < 1) {
$msg = JText::_('Select an item to move');
$mainframe->redirect('index.php?option=com_content', $msg, 'error');
}
//seperate contentids
$cids = implode(',', $cid);
// Articles query
$query = 'SELECT a.title' .
' FROM #__content AS a' .
' WHERE ( a.id IN ( '. $cids .' ) )' .
' ORDER BY a.title';
$db->setQuery($query);
$items = $db->loadObjectList();
$query = 'SELECT CONCAT_WS( ", ", s.id, c.id ) AS `value`, CONCAT_WS( " / ", s.title, c.title ) AS `text`' .
' FROM #__sections AS s' .
' INNER JOIN #__categories AS c ON c.section = s.id' .
' WHERE s.scope = "content"' .
' ORDER BY s.title, c.title';
$db->setQuery($query);
$rows[] = JHTML::_('select.option', "0, 0", JText::_('UNCATEGORIZED'));
$rows = array_merge($rows, $db->loadObjectList());
// build the html select list
$sectCatList = JHTML::_('select.genericlist', $rows, 'sectcat', 'class="inputbox" size="8"', 'value', 'text', null);
ContentView::moveSection($cid, $sectCatList, 'com_content', $sectionid, $items);
}
/**
* Save the changes to move item(s) to a different section and category
*/
function moveSectionSave()
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db = & JFactory::getDBO();
$user = & JFactory::getUser();
$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
$sectionid = JRequest::getVar( 'sectionid', 0, '', 'int' );
$option = JRequest::getCmd( 'option' );
JArrayHelper::toInteger($cid, array(0));
$sectcat = JRequest::getVar( 'sectcat', '', 'post', 'string' );
$sectcat = explode(',', $sectcat);
$newsect = (int) @$sectcat[0];
$newcat = (int) @$sectcat[1];
if ((!$newsect || !$newcat) && ($sectcat !== array('0', ' 0'))) {
$mainframe->redirect("index.php?option=com_content§ionid=$sectionid", JText::_('An error has occurred'));
}
// find section name
$query = 'SELECT a.title' .
' FROM #__sections AS a' .
' WHERE a.id = '. (int) $newsect;
$db->setQuery($query);
$section = $db->loadResult();
// find category name
$query = 'SELECT a.title' .
' FROM #__categories AS a' .
' WHERE a.id = '. (int) $newcat;
$db->setQuery($query);
$category = $db->loadResult();
$total = count($cid);
$cids = implode(',', $cid);
$uid = $user->get('id');
$row = & JTable::getInstance('content');
// update old orders - put existing items in last place
foreach ($cid as $id)
{
$row->load(intval($id));
$row->ordering = 0;
$row->store();
$row->reorder('catid = '.(int) $row->catid.' AND state >= 0');
}
$query = 'UPDATE #__content SET sectionid = '.(int) $newsect.', catid = '.(int) $newcat.
' WHERE id IN ( '.$cids.' )' .
' AND ( checked_out = 0 OR ( checked_out = '.(int) $uid.' ) )';
$db->setQuery($query);
if (!$db->query())
{
JError::raiseError( 500, $db->getErrorMsg() );
return false;
}
// update new orders - put items in last place
foreach ($cid as $id)
{
$row->load(intval($id));
$row->ordering = 0;
$row->store();
$row->reorder('catid = '.(int) $row->catid.' AND state >= 0');
}
if ($section && $category) {
$msg = JText::sprintf('Item(s) successfully moved to Section', $total, $section, $category);
} else {
$msg = JText::sprintf('ITEM(S) SUCCESSFULLY MOVED TO UNCATEGORIZED', $total);
}
$mainframe->redirect('index.php?option='.$option.'§ionid='.$sectionid, $msg);
}
/**
* Form for copying item(s)
**/
function copyItem()
{
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db = & JFactory::getDBO();
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
$sectionid = JRequest::getVar( 'sectionid', 0, '', 'int' );
$option = JRequest::getCmd( 'option' );
JArrayHelper::toInteger($cid);
if (count($cid) < 1) {
$msg = JText::_('Select an item to move');
$mainframe->redirect('index.php?option='.$option, $msg, 'error');
}
//seperate contentids
$cids = implode(',', $cid);
## Articles query
$query = 'SELECT a.title' .
' FROM #__content AS a' .
' WHERE ( a.id IN ( '. $cids .' ) )' .
' ORDER BY a.title';
$db->setQuery($query);
$items = $db->loadObjectList();
## Section & Category query
$query = 'SELECT CONCAT_WS(",",s.id,c.id) AS `value`, CONCAT_WS(" / ", s.title, c.title) AS `text`' .
' FROM #__sections AS s' .
' INNER JOIN #__categories AS c ON c.section = s.id' .
' WHERE s.scope = "content"' .
' ORDER BY s.title, c.title';
$db->setQuery($query);
// Add a row for uncategorized content
$uncat = JHTML::_('select.option', '0,0', JText::_('UNCATEGORIZED'));
$rows = $db->loadObjectList();
array_unshift($rows, $uncat);
// build the html select list
$sectCatList = JHTML::_('select.genericlist', $rows, 'sectcat', 'class="inputbox" size="10"', 'value', 'text', NULL);
ContentView::copySection($option, $cid, $sectCatList, $sectionid, $items);
}
/**
* saves Copies of items
**/
function copyItemSave()
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db = & JFactory::getDBO();
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
$sectionid = JRequest::getVar( 'sectionid', 0, '', 'int' );
$option = JRequest::getCmd( 'option' );
JArrayHelper::toInteger($cid);
$item = null;
$sectcat = JRequest::getVar( 'sectcat', '-1,-1', 'post', 'string' );
//seperate sections and categories from selection
$sectcat = explode(',', $sectcat);
$newsect = (int) @$sectcat[0];
$newcat = (int) @$sectcat[1];
if (($newsect == -1) || ($newcat == -1)) {
$mainframe->redirect('index.php?option=com_content§ionid='.$sectionid, JText::_('An error has occurred'));
}
// find section name
$query = 'SELECT a.title' .
' FROM #__sections AS a' .
' WHERE a.id = '. (int) $newsect;
$db->setQuery($query);
$section = $db->loadResult();
// find category name
$query = 'SELECT a.title' .
' FROM #__categories AS a' .
' WHERE a.id = '. (int) $newcat;
$db->setQuery($query);
$category = $db->loadResult();
if (($newsect == 0) && ($newcat == 0))
{
$section = JText::_('UNCATEGORIZED');
$category = JText::_('UNCATEGORIZED');
}
$total = count($cid);
for ($i = 0; $i < $total; $i ++)
{
$row = & JTable::getInstance('content');
// main query
$query = 'SELECT a.*' .
' FROM #__content AS a' .
' WHERE a.id = '.(int) $cid[$i];
$db->setQuery($query, 0, 1);
$item = $db->loadObject();
// values loaded into array set for store
$row->id = NULL;
$row->sectionid = $newsect;
$row->catid = $newcat;
$row->hits = '0';
$row->ordering = '0';
$row->title = $item->title;
$row->alias = $item->alias;
$row->title_alias = $item->title_alias;
$row->introtext = $item->introtext;
$row->fulltext = $item->fulltext;
$row->state = $item->state;
$row->mask = $item->mask;
$row->created = $item->created;
$row->created_by = $item->created_by;
$row->created_by_alias = $item->created_by_alias;
$row->modified = $item->modified;
$row->modified_by = $item->modified_by;
$row->checked_out = $item->checked_out;
$row->checked_out_time = $item->checked_out_time;
$row->publish_up = $item->publish_up;
$row->publish_down = $item->publish_down;
$row->images = $item->images;
$row->attribs = $item->attribs;
$row->version = $item->parentid;
$row->parentid = $item->parentid;
$row->metakey = $item->metakey;
$row->metadesc = $item->metadesc;
$row->access = $item->access;
$row->metadata = $item->metadata;
if (!$row->check()) {
JError::raiseError( 500, $row->getError() );
return false;
}
if (!$row->store()) {
JError::raiseError( 500, $row->getError() );
return false;
}
$row->reorder('catid='.(int) $row->catid.' AND state >= 0');
}
$msg = JText::sprintf('Item(s) successfully copied to Section', $total, $section, $category);
$mainframe->redirect('index.php?option='.$option.'§ionid='.$sectionid, $msg);
}
/**
* @param integer The id of the article
* @param integer The new access level
* @param string The URL option
*/
function accessMenu($access)
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db = & JFactory::getDBO();
$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
$option = JRequest::getCmd( 'option' );
$cid = $cid[0];
// Create and load the article table object
$row = & JTable::getInstance('content');
$row->load($cid);
$row->access = $access;
// Ensure the article object is valid
if (!$row->check()) {
JError::raiseError( 500, $row->getError() );
return false;
}
// Store the changes
if (!$row->store()) {
JError::raiseError( 500, $row->getError() );
return false;
}
$cache = & JFactory::getCache('com_content');
$cache->clean();
$mainframe->redirect('index.php?option='.$option);
}
function saveOrder()
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
// Initialize variables
$db = & JFactory::getDBO();
$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
$order = JRequest::getVar( 'order', array (0), 'post', 'array' );
$redirect = JRequest::getVar( 'redirect', 0, 'post', 'int' );
$rettask = JRequest::getVar( 'returntask', '', 'post', 'cmd' );
$total = count($cid);
$conditions = array ();
JArrayHelper::toInteger($cid, array(0));
JArrayHelper::toInteger($order, array(0));
// Instantiate an article table object
$row = & JTable::getInstance('content');
// Update the ordering for items in the cid array
for ($i = 0; $i < $total; $i ++)
{
$row->load( (int) $cid[$i] );
if ($row->ordering != $order[$i]) {
$row->ordering = $order[$i];
if (!$row->store()) {
JError::raiseError( 500, $db->getErrorMsg() );
return false;
}
// remember to updateOrder this group
$condition = 'catid = '.(int) $row->catid.' AND state >= 0';
$found = false;
foreach ($conditions as $cond)
if ($cond[1] == $condition) {
$found = true;
break;
}
if (!$found)
$conditions[] = array ($row->id, $condition);
}
}
// execute updateOrder for each group
foreach ($conditions as $cond)
{
$row->load($cond[0]);
$row->reorder($cond[1]);
}
$cache = & JFactory::getCache('com_content');
$cache->clean();
$msg = JText::_('New ordering saved');
switch ($rettask)
{
case 'showarchive' :
$mainframe->redirect('index.php?option=com_content&task=showarchive§ionid='.$redirect, $msg);
break;
default :
$mainframe->redirect('index.php?option=com_content§ionid='.$redirect, $msg);
break;
}
}
function previewContent()
{
// Initialize variables
$document =& JFactory::getDocument();
$db =& JFactory::getDBO();
$id = JRequest::getVar( 'id', 0, '', 'int' );
$option = JRequest::getCmd( 'option' );
// Get the current default template
$query = 'SELECT template' .
' FROM #__templates_menu' .
' WHERE client_id = 0' .
' AND menuid = 0';
$db->setQuery($query);
$template = $db->loadResult();
// check if template editor stylesheet exists
if (!file_exists( JPATH_SITE.DS.'templates'.DS.$template.DS.'css'.DS.'editor.css' )) {
$template = 'system';
}
// Set page title
$document->setTitle(JText::_('Article Preview'));
$document->addStyleSheet(JURI::root() . 'templates/'.$template.'/css/editor.css');
$document->setBase(JUri::root());
// Render article preview
ContentView::previewContent();
}
function insertPagebreak()
{
$document =& JFactory::getDocument();
$document->setTitle(JText::_('PGB ARTICLE PAGEBRK'));
ContentView::insertPagebreak();
}
}
//-------------------require_once( JPATH_COMPONENT.DS.'controller.php' );
//jimport('joomla.application.component.helper');
class JComponentHelper
{
/**
* Get the component info
*
* @access public
* @param string $name The component name
* @param boolean $string If set and a component does not exist, the enabled attribue will be set to false
* @return object A JComponent object
*/
function &getComponent( $name, $strict = false )
{
$result = null;
$components = JComponentHelper::_load();
if (isset( $components[$name] ))
{
$result = &$components[$name];
}
else
{
$result = new stdClass();
$result->enabled = $strict ? false : true;
$result->params = null;
}
return $result;
}
/**
* Checks if the component is enabled
*
* @access public
* @param string $component The component name
* @param boolean $string If set and a component does not exist, false will be returned
* @return boolean
*/
function isEnabled( $component, $strict = false )
{
global $mainframe;
$result = &JComponentHelper::getComponent( $component, $strict );
return ($result->enabled | $mainframe->isAdmin());
}
/**
* Gets the parameter object for the component
*
* @access public
* @param string $name The component name
* @return object A JParameter object
*/
function &getParams( $name )
{
static $instances;
if (!isset( $instances[$name] ))
{
$component = &JComponentHelper::getComponent( $name );
$instances[$name] = new JParameter($component->params);
}
return $instances[$name];
}
function renderComponent($name = null, $params = array())
{
global $mainframe, $option;
if(empty($name)) {
// Throw 404 if no component
JError::raiseError(404, JText::_("Component Not Found"));
return;
}
$scope = $mainframe->scope; //record the scope
$mainframe->scope = $name; //set scope to component name
// Build the component path
$name = preg_replace('/[^A-Z0-9_\.-]/i', '', $name);
$file = substr( $name, 4 );
// Define component path
define( 'JPATH_COMPONENT', JPATH_BASE.DS.'components'.DS.$name);
define( 'JPATH_COMPONENT_SITE', JPATH_SITE.DS.'components'.DS.$name);
define( 'JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR.DS.'components'.DS.$name);
// get component path
if ( $mainframe->isAdmin() && file_exists(JPATH_COMPONENT.DS.'admin.'.$file.'.php') ) {
$path = JPATH_COMPONENT.DS.'admin.'.$file.'.php';
} else {
$path = JPATH_COMPONENT.DS.$file.'.php';
}
// If component disabled throw error
if (!JComponentHelper::isEnabled( $name ) || !file_exists($path)) {
JError::raiseError( 404, JText::_( 'Component Not Found' ) );
}
// Handle legacy globals if enabled
if ($mainframe->getCfg('legacy'))
{
// Include legacy globals
global $my, $database, $id, $acl, $task;
// For backwards compatibility extract the config vars as globals
$registry =& JFactory::getConfig();
foreach (get_object_vars($registry->toObject()) as $k => $v)
{
$varname = 'mosConfig_'.$k;
$$varname = $v;
}
$contentConfig = &JComponentHelper::getParams( 'com_content' );
foreach (get_object_vars($contentConfig->toObject()) as $k => $v)
{
$varname = 'mosConfig_'.$k;
$$varname = $v;
}
$usersConfig = &JComponentHelper::getParams( 'com_users' );
foreach (get_object_vars($usersConfig->toObject()) as $k => $v)
{
$varname = 'mosConfig_'.$k;
$$varname = $v;
}
}
$task = JRequest::getString( 'task' );
// Load common language files
$lang =& JFactory::getLanguage();
$lang->load($name);
// Handle template preview outlining
$contents = null;
// Execute the component
//ob_start();
//require_once $path;
//require_once( JPATH_COMPONENT.DS.'controller.php' );-->提到前面
require_once( JPATH_COMPONENT.DS.'helper.php' );
require_once (JApplicationHelper::getPath('admin_html'));
// Set the helper directory
JHTML::addIncludePath( JPATH_COMPONENT.DS.'helper' );
$controller = new ContentController();
$task = JRequest::getCmd('task');
ob_end_clean();
ContentController::saveContent();
exit;//zzcity add
$contents = ob_get_contents();
ob_end_clean();
// Build the component toolbar
jimport( 'joomla.application.helper' );
if (($path = JApplicationHelper::getPath( 'toolbar' )) && $mainframe->isAdmin()) {
// Get the task again, in case it has changed
$task = JRequest::getString( 'task' );
// Make the toolbar
include_once( $path );
}
$mainframe->scope = $scope; //revert the scope
return $contents;
}
/**
* Load components
*
* @access private
* @return array
*/
function _load()
{
static $components;
if (isset($components)) {
return $components;
}
$db = &JFactory::getDBO();
$query = 'SELECT *' .
' FROM #__components' .
' WHERE parent = 0';
$db->setQuery( $query );
if (!($components = $db->loadObjectList( 'option' ))) {
JError::raiseWarning( 'SOME_ERROR_CODE', "Error loading Components: " . $db->getErrorMsg());
return false;
}
return $components;
}
} //--------------------application.component.helper
/**
* Joomla! Application class
*
* Provide many supporting API functions
*
* @package Joomla
* @final
*/
class JAdministrator extends JApplication
{
/**
* Class constructor
*
* @access protected
* @param array An optional associative array of configuration settings.
* Recognized key values include 'clientId' (this list is not meant to be comprehensive).
*/
function __construct($config = array())
{
$config['clientId'] = 1;
parent::__construct($config);
//Set the root in the URI based on the application name
JURI::root(null, str_replace('/'.$this->getName(), '', JURI::base(true)));
}
/**
* Initialise the application.
*
* @access public
* @param array An optional associative array of configuration settings.
*/
function initialise($options = array())
{
// if a language was specified it has priority
// otherwise use user or default language settings
if (empty($options['language']))
{
$user = & JFactory::getUser();
$lang = $user->getParam( 'admin_language' );
// Make sure that the user's language exists
if ( $lang && JLanguage::exists($lang) ) {
$options['language'] = $lang;
} else {
$params = JComponentHelper::getParams('com_languages');
$client =& JApplicationHelper::getClientInfo($this->getClientId());
$options['language'] = $params->get($client->name, 'en-GB');
}
}
// One last check to make sure we have something
if ( ! JLanguage::exists($options['language']) ) {
$options['language'] = 'en-GB';
}
parent::initialise($options);
}
/**
* Route the application
*
* @access public
*/
function route()
{
$uri = JURI::getInstance();
if($this->getCfg('force_ssl') >= 1 && strtolower($uri->getScheme()) != 'https') {
//forward to https
$uri->setScheme('https');
$this->redirect($uri->toString());
}
}
/**
* Return a reference to the JRouter object.
*
* @access public
* @return JRouter.
* @since 1.5
*/
function &getRouter()
{
$router =& parent::getRouter('administrator');
return $router;
}
/**
* Dispatch the application
*
* @access public
*/
function dispatch($component)
{
$document =& JFactory::getDocument();
$user =& JFactory::getUser();
switch($document->getType())
{
case 'html' :
{
$document->setMetaData( 'keywords', $this->getCfg('MetaKeys') );
if ( $user->get('id') ) {
$document->addScript( JURI::root(true).'/includes/js/joomla.javascript.js');
}
JHTML::_('behavior.mootools');
} break;
default : break;
}
$document->setTitle( htmlspecialchars_decode($this->getCfg('sitename' )). ' - ' .JText::_( 'Administration' ));
$document->setDescription( $this->getCfg('MetaDesc') );
$contents = JComponentHelper::renderComponent($component);
$document->setBuffer($contents, 'component');
}
/**
* Display the application.
*
* @access public
*/
function render()
{
$component = JRequest::getCmd('option');
$template = $this->getTemplate();
$file = JRequest::getCmd('tmpl', 'index');
if($component == 'com_login') {
$file = 'login';
}
$params = array(
'template' => $template,
'file' => $file.'.php',
'directory' => JPATH_THEMES
);
$document =& JFactory::getDocument();
$data = $document->render($this->getCfg('caching'), $params );
JResponse::setBody($data);
}
/**
* Login authentication function
*
* @param array Array( 'username' => string, 'password' => string )
* @param array Array( 'remember' => boolean )
* @access public
* @see JApplication::login
*/
function login($credentials, $options = array())
{
//The minimum group
$options['group'] = 'Public Backend';
//Make sure users are not autoregistered
$options['autoregister'] = false;
//Set the application login entry point
if(!array_key_exists('entry_url', $options)) {
$options['entry_url'] = JURI::base().'index.php?option=com_user&task=login';
}
$result = parent::login($credentials, $options);
if(!JError::isError($result))
{
$lang = JRequest::getCmd('lang');
$lang = preg_replace( '/[^A-Z-]/i', '', $lang );
$this->setUserState( 'application.lang', $lang );
JAdministrator::purgeMessages();
}
return $result;
}
/**
* Get the template
*
* @return string The template name
* @since 1.0
*/
function getTemplate()
{
static $template;
if (!isset($template))
{
// Load the template name from the database
$db =& JFactory::getDBO();
$query = 'SELECT template'
. ' FROM #__templates_menu'
. ' WHERE client_id = 1'
. ' AND menuid = 0'
;
$db->setQuery( $query );
$template = $db->loadResult();
$template = JFilterInput::clean($template, 'cmd');
if (!file_exists(JPATH_THEMES.DS.$template.DS.'index.php')) {
$template = 'khepri';
}
}
return $template;
}
/**
* Purge the jos_messages table of old messages
*
* static method
* @since 1.5
*/
function purgeMessages()
{
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$userid = $user->get('id');
$query = 'SELECT *'
. ' FROM #__messages_cfg'
. ' WHERE user_id = ' . (int) $userid
. ' AND cfg_name = "auto_purge"'
;
$db->setQuery( $query );
$config = $db->loadObject( );
// check if auto_purge value set
if (is_object( $config ) and $config->cfg_name == 'auto_purge' )
{
$purge = $config->cfg_value;
}
else
{
// if no value set, default is 7 days
$purge = 7;
}
// calculation of past date
// if purge value is not 0, then allow purging of old messages
if ($purge > 0)
{
// purge old messages at day set in message configuration
$past =& JFactory::getDate(time() - $purge * 86400);
$pastStamp = $past->toMySQL();
$query = 'DELETE FROM #__messages'
. ' WHERE date_time < ' . $db->Quote( $pastStamp )
. ' AND user_id_to = ' . (int) $userid
;
$db->setQuery( $query );
$db->query();
}
}
/**
* Deprecated, use JURI::root() instead.
*
* @since 1.5
* @deprecated As of version 1.5
* @see JURI::root()
*/
function getSiteURL()
{
return JURI::root();
}
}
//---------------administrator/includes/application.php
/**
* 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';
$file = JPATH_SITE.DS.'libraries'.DS.'joomla'.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 JDocument
*/
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->force_feed(true);
$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
{
jimport('domit.xml_domit_include');
$doc = new DOMIT_Document();
}
}
}
return $doc;
}
/**
* Get an editor object
*
* @access public
* @param string $editor The editor to load, depends on the editor plugins that are installed
* @return object JEditor
*/
function &getEditor($editor = null)
{
jimport( 'joomla.html.editor' );
//get the editor configuration setting
if(is_null($editor))
{
$conf =& JFactory::getConfig();
$editor = $conf->getValue('config.editor');
}
$instance =& JEditor::getInstance($editor);
return $instance;
}
/**
* Return a reference to the {@link JURI} object
*
* @access public
* @return object JURI
* @since 1.5
*/
function &getURI($uri = 'SERVER')
{
jimport('joomla.environment.uri');
$instance =& JURI::getInstance($uri);
return $instance;
}
/**
* Return a reference to the {@link JDate} object
*
* @access public
* @param mixed $time The initial time for the JDate object
* @param int $tzOffset The timezone offset.
* @return object JDate
* @since 1.5
*/
function &getDate($time = 'now', $tzOffset = 0)
{
jimport('joomla.utilities.date');
static $instances;
static $classname;
static $mainLocale;
if(!isset($instances)) {
$instances = array();
}
$language =& JFactory::getLanguage();
$locale = $language->getTag();
if(!isset($classname) || $locale != $mainLocale) {
//Store the locale for future reference
$mainLocale = $locale;
$localePath = JPATH_ROOT . DS . 'language' . DS . $mainLocale . DS . $mainLocale . '.date.php';
if($mainLocale !== false && file_exists($localePath)) {
$classname = 'JDate'.str_replace('-', '_', $mainLocale);
JLoader::register( $classname, $localePath);
if(!class_exists($classname)) {
//Something went wrong. The file exists, but the class does not, default to JDate
$classname = 'JDate';
}
} else {
//No file, so default to JDate
$classname = 'JDate';
}
}
$key = $time . '-' . $tzOffset;
if(!isset($instances[$classname][$key])) {
$tmp = new $classname($time, $tzOffset);
//We need to serialize to break the reference
$instances[$classname][$key] = serialize($tmp);
unset($tmp);
}
$date = unserialize($instances[$classname][$key]);
return $date;
}
/**
* Create a configuration object
*
* @access private
* @param string The path to the configuration file
* @param string The type of the configuration file
* @return object JRegistry
* @since 1.5
*/
function &_createConfig($file, $type = 'PHP')
{
jimport('joomla.registry.registry');
require_once $file;
// Create the registry with a default namespace of config
$registry = new JRegistry('config');
// Create the JConfig object
$config = new JFrameworkConfig();
// Load the configuration values into the registry
$registry->loadObject($config);
return $registry;
}
/**
* Create a session object
*
* @access private
* @param array $options An array containing session options
* @return object JSession
* @since 1.5
*/
function &_createSession( $options = array())
{
jimport('joomla.session.session');
//get the editor configuration setting
$conf =& JFactory::getConfig();
$handler = $conf->getValue('config.session_handler', 'none');
// config time is in minutes
$options['expire'] = ($conf->getValue('config.lifetime')) ? $conf->getValue('config.lifetime') * 60 : 900;
$session = JSession::getInstance($handler, $options);
if ($session->getState() == 'expired') {
$session->restart();
}
return $session;
}
/**
* Create an ACL object
*
* @access private
* @return object JAuthorization
* @since 1.5
*/
function &_createACL()
{
//TODO :: take the authorization class out of the application package
jimport( 'joomla.user.authorization' );
$db =& JFactory::getDBO();
$options = array(
'db' => &$db,
'db_table_prefix' => $db->getPrefix() . 'core_acl_',
'debug' => 0
);
$acl = new JAuthorization( $options );
return $acl;
}
/**
* Create an database object
*
* @access private
* @return object JDatabase
* @since 1.5
*/
function &_createDBO()
{
jimport('joomla.database.database');
jimport( 'joomla.database.table' );
$conf =& JFactory::getConfig();
$host = $conf->getValue('config.host');
$user = $conf->getValue('config.user');
$password = $conf->getValue('config.password');
$database = $conf->getValue('config.db');
$prefix = $conf->getValue('config.dbprefix');
$driver = $conf->getValue('config.dbtype');
$debug = $conf->getValue('config.debug');
$options = array ( 'driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix );
$db =& JDatabase::getInstance( $options );
if ( JError::isError($db) ) {
jexit('Database Error: ' . $db->toString() );
}
if ($db->getErrorNum() > 0) {
JError::raiseError(500 , 'JDatabase::getInstance: Could not connect to database
' . 'joomla.library:'.$db->getErrorNum().' - '.$db->getErrorMsg() );
}
$db->debug( $debug );
return $db;
}
/**
* Create a mailer object
*
* @access private
* @return object JMail
* @since 1.5
*/
function &_createMailer()
{
jimport('joomla.mail.mail');
$conf =& JFactory::getConfig();
$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');
$smtpsecure = $conf->getValue('config.smtpsecure');
$smtpport = $conf->getValue('config.smtpport');
$mailfrom = $conf->getValue('config.mailfrom');
$fromname = $conf->getValue('config.fromname');
$mailer = $conf->getValue('config.mailer');
// Create a JMail object
$mail =& JMail::getInstance();
// Set default sender
$mail->setSender(array ($mailfrom, $fromname));
// Default mailer is to use PHP's mail function
switch ($mailer)
{
case 'smtp' :
$mail->useSMTP($smtpauth, $smtphost, $smtpuser, $smtppass, $smtpsecure, $smtpport);
break;
case 'sendmail' :
$mail->useSendmail($sendmail);
break;
default :
$mail->IsMail();
break;
}
return $mail;
}
/**
* Create a template object
*
* @access private
* @param array An array of support template files to load
* @return object JTemplate
* @since 1.5
*/
function &_createTemplate($files = array())
{
jimport('joomla.template.template');
$conf =& JFactory::getConfig();
$tmpl = new JTemplate;
// patTemplate
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
if (is_array( $files ))
{
foreach ($files as $file) {
$tmpl->readTemplatesFromInput( $file );
}
}
$tmpl->addGlobalVar( 'option', $GLOBALS['option'] );
$tmpl->addGlobalVar( 'self', str_replace(array('"', '<', '>', "'"), '', $_SERVER["PHP_SELF"]) );
$tmpl->addGlobalVar( 'uri_query', $_SERVER['QUERY_STRING'] );
$tmpl->addGlobalVar( 'REQUEST_URI', JRequest::getURI() );
if (isset($GLOBALS['Itemid'])) {
$tmpl->addGlobalVar( 'itemid', $GLOBALS['Itemid'] );
}
return $tmpl;
}
/**
* Create a language object
*
* @access private
* @return object JLanguage
* @since 1.5
*/
function &_createLanguage()
{
jimport('joomla.language.language');
$conf =& JFactory::getConfig();
$locale = $conf->getValue('config.language');
$lang =& JLanguage::getInstance($locale);
$lang->setDebug($conf->getValue('config.debug_lang'));
return $lang;
}
/**
* Create a document object
*
* @access private
* @return object JDocument
* @since 1.5
*/
function &_createDocument()
{
jimport('joomla.document.document');
$lang =& JFactory::getLanguage();
//Keep backwards compatibility with Joomla! 1.0
$raw = JRequest::getBool('no_html');
$type = JRequest::getWord('format', $raw ? 'raw' : 'html');
$attributes = array (
'charset' => 'utf-8',
'lineend' => 'unix',
'tab' => ' ',
'language' => $lang->getTag(),
'direction' => $lang->isRTL() ? 'rtl' : 'ltr'
);
$doc =& JDocument::getInstance($type, $attributes);
return $doc;
}
}
//-----------------joomla.factory
JLoader::import( 'joomla.version' );
if (!defined('JVERSION')) {
$version = new JVersion();
define('JVERSION', $version->getShortVersion());
}
//Error
JLoader::import( 'joomla.error.error' );
JLoader::import( 'joomla.error.exception' );
//Utilities
JLoader::import( 'joomla.utilities.arrayhelper' );
//Filters
JLoader::import( 'joomla.filter.filterinput' );
JLoader::import( 'joomla.filter.filteroutput' );
//Register class that don't follow one file per class naming conventions
//JLoader::register('JText' , dirname(__FILE__).DS.'methods.php');
//JLoader::register('JRoute', dirname(__FILE__).DS.'methods.php');
JLoader::register('JText' , JPATH_SITE.DS.'libraries'.DS.'joomla'.DS.'methods.php');
JLoader::register('JRoute', JPATH_SITE.DS.'libraries'.DS.'joomla'.DS.'methods.php');
//--------------------------'joomla'.DS.'import.php'
// Pre-Load configuration
require_once( JPATH_CONFIGURATION .DS.'configuration.php' );
// System configuration
$CONFIG = new JConfig();
if (@$CONFIG->error_reporting === 0) {
error_reporting( 0 );
} else if (@$CONFIG->error_reporting > 0) {
error_reporting( $CONFIG->error_reporting );
ini_set( 'display_errors', 1 );
}
define( 'JDEBUG', $CONFIG->debug );
unset( $CONFIG );
/*
* Joomla! framework loading
*/
// Include object abstract class
require_once(JPATH_SITE.DS.'libraries'.DS.'joomla'.DS.'utilities'.DS.'compat'.DS.'compat.php');
// System profiler
if (JDEBUG) {
jimport( 'joomla.error.profiler' );
$_PROFILER =& JProfiler::getInstance( 'Application' );
}
// Joomla! library imports
jimport( 'joomla.application.menu' );
jimport( 'joomla.user.user');
jimport( 'joomla.environment.uri' );
jimport( 'joomla.html.html' );
jimport( 'joomla.html.parameter' );
jimport( 'joomla.utilities.utility' );
jimport( 'joomla.event.event');
jimport( 'joomla.event.dispatcher');
jimport( 'joomla.language.language');
jimport( 'joomla.utilities.string' );
//-----------------------framework.php
require_once( JPATH_BASE .DS.'includes'.DS.'helper.php' );
require_once( JPATH_BASE .DS.'includes'.DS.'toolbar.php' );
JDEBUG ? $_PROFILER->mark( 'afterLoad' ) : null;
$mainframe =& JFactory::getApplication('administrator');
$mainframe->initialise(array(
'language' => $mainframe->getUserState( "application.lang", 'lang' )
));
//zzcity add
function login()
{
global $mainframe;
// Check for request forgeries
//JRequest::checkToken('request') or jexit( 'Invalid Token' );
$credentials = array();
$credentials['username'] = JRequest::getVar('username', '', 'method', 'username');
$credentials['password'] = JRequest::getVar('passwd', '', 'post', 'string', JREQUEST_ALLOWRAW);
$result = $mainframe->login($credentials);
return $result;
//if (!JError::isError($result)) {
// $mainframe->redirect('index.php');
//}
//LoginController::display();
}
if (!login()){
echo('[err]账号密码错误[/err]');
exit;
};
//zzcity add
JPluginHelper::importPlugin('system');
// trigger the onAfterInitialise events
JDEBUG ? $_PROFILER->mark('afterInitialise') : null;
$mainframe->triggerEvent('onAfterInitialise');
$mainframe->route();
// trigger the onAfterRoute events
JDEBUG ? $_PROFILER->mark('afterRoute') : null;
$mainframe->triggerEvent('onAfterRoute');
$option = JAdministratorHelper::findOption();
$mainframe->dispatch($option);
// trigger the onAfterDispatch events
JDEBUG ? $_PROFILER->mark('afterDispatch') : null;
$mainframe->triggerEvent('onAfterDispatch');
$mainframe->render();
exit;
?>