示例#1
0
文件: shsef.php 项目: sangkasi/joomla
 function onAfterInitialise()
 {
     $mainframe =& JFactory::getApplication();
     // register our autoloader
     $this->_registerAutoloader();
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_sh404sef' . DS . 'sh404sef.class.php';
     // for now we declare sefConfig as global, as this would break
     //too many 3rd party plugins if otherwise
     // TODO : update doc so that new plugins use new method to get config
     global $sefConfig;
     $sefConfig =& shRouter::shGetConfig();
     // prevent timezone not set warnings to appear all over,
     // especially for PHP 5.3.3+
     $oldLevel = error_reporting(0);
     $serverTimezone = date_default_timezone_get();
     error_reporting($oldLevel);
     date_default_timezone_set($serverTimezone);
     if (!$mainframe->isAdmin() && $sefConfig->shSecEnableSecurity) {
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_sh404sef' . DS . 'shSec.php';
         // do security checks
         shDoSecurityChecks();
         shCleanUpSecLogFiles();
         // see setting in class file for clean up frequency
     }
     // optionnally collect page creation time
     if (!$mainframe->isAdmin() && $sefConfig->analyticsEnableTimeCollection) {
         jimport('joomla.error.profiler');
         // creating the profiler object will start the counter
         $profiler =& JProfiler::getInstance('sh404sef_profiler');
     }
     // load plugins, as per configuration
     $this->_loadPlugins($type = 'sh404sefcore');
     // load extension plugins, created by others
     $this->_loadPlugins($type = 'sh404sefext');
     // hook to be able to install other SEF extension plugins
     Sh404sefHelperExtplugins::loadInstallAdapters();
     // another hook to allow other SEF extensions language file to be loaded
     Sh404sefHelperExtplugins::loadLanguageFiles();
     if (!$sefConfig->Enabled) {
         // go away if not enabled
         return;
     }
     if (!defined('SH404SEF_IS_RUNNING')) {
         DEFINE('SH404SEF_IS_RUNNING', 1);
     }
     if (!$mainframe->isAdmin()) {
         // setup our JPagination replacement, so as to bring
         // back # of items per page in the url, in order
         // to properly calculate pagination
         // will only work if php > 5, so test for that
         if (version_compare(phpversion(), '5.0') >= 0) {
             // this register the old file, but do not load it if PHP5
             // will prevent further calls to the same jimport()
             // to actually do anything, because the 'joomla.html.pagination' key
             // is now registered statically in Jloader::import()
             jimport('joomla.html.pagination');
             // now we can register our own path
             JLoader::register('JPagination', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_sh404sef' . DS . 'pagination.php');
         }
         // override router class with our :
         $previousRouter =& $mainframe->getRouter();
         // create an instance of our class
         $shRouter = new shRouter();
         // store the previous router
         $shRouter->jRouter = clone $previousRouter;
         // make sure the cloned Joomla router is activated
         $shRouter->jRouter->setMode(JROUTER_MODE_SEF);
         // then override
         $previousRouter = $shRouter;
         // start decoding URL + decide possible redirects
         include JPATH_ROOT . DS . 'components' . DS . 'com_sh404sef' . DS . 'shInit.php';
     }
 }
示例#2
0
 function create($string, &$vars, &$shAppendString, $shLanguage, $shSaveString = '', &$originalUri)
 {
     $sefConfig =& shRouter::shGetConfig();
     // get DB
     $database =& JFactory::getDBO();
     _log('Calling sef404 create function with ' . $string);
     if ($sefConfig->shInsertGlobalItemidIfNone && !empty($GLOBALS['Itemid'])) {
         // V 1.2.4.t
         $shCurrentItemid = $GLOBALS['Itemid'];
     } else {
         $shCurrentItemid = null;
     }
     _log('CurrentItemid = ' . $shCurrentItemid);
     $index = str_replace($GLOBALS['shConfigLiveSite'], '', $_SERVER['PHP_SELF']);
     $base = dirname($index);
     $base .= $base == '/' ? '' : '/';
     _log('Extracting $vars:', $vars);
     extract($vars);
     if (isset($title)) {
         // V 1.2.4.r : protect against components using 'title' as GET vars (com_jim for instance)
         $sh404SEF_title = $title;
     }
     // means that $sh404SEF_title has to be used in plugins or extensions
     $title = array();
     // V 1.2.4.r
     // get extension plugin
     $extPlugin =& Sh404sefFactory::getExtensionPlugin($option);
     // which plugin file are we supposed to use?
     $extPluginPath = $extPlugin->getSefPluginPath($vars);
     $pluginType = $extPlugin->getPluginType();
     // use Joomla router.php file in extension dir
     switch ($pluginType) {
         case Sh404sefClassBaseextplugin::TYPE_JOOMLA_ROUTER:
             // Load the plug-in file.
             _log('Loading component own router.php file');
             $functionName = ucfirst(str_replace('com_', '', $option)) . 'BuildRoute';
             if (!function_exists($functionName)) {
                 include JPATH_ROOT . DS . 'components' . DS . $option . DS . 'router.php';
             }
             $originalVars = empty($originalUri) ? $vars : $originalUri->getQuery($asArray = true);
             $title = $functionName($originalVars);
             //$title = shRemoveSlugs( $title, $removeWhat = 'removeId');
             global $mainframe;
             $router =& $mainframe->getRouter();
             $title = $router->_encodeSegments($title);
             // manage GET var lists ourselves, as Joomla router.php does not do it
             if (!empty($vars)) {
                 // there are some unused GET vars, we must transfer them to our mechanism, so
                 // that they are eventually appended to the sef url
                 foreach ($vars as $k => $v) {
                     switch ($k) {
                         case 'option':
                         case 'Itemid':
                             shRemoveFromGETVarsList($k);
                             break;
                         default:
                             // if variable has not been used in sef url, add it to list of variables to be
                             // appended to the url as query string elements
                             if (array_key_exists($k, $originalVars)) {
                                 shAddToGETVarsList($k, $v);
                             } else {
                                 shRemoveFromGETVarsList($k);
                             }
                             break;
                     }
                 }
             }
             // special case for search component, as router.php encode the search word in the url
             // wa can't do that, as we are storing each url in the db
             if (isset($originalVars['option']) && $originalVars['option'] == 'com_search' && !empty($vars['searchword'])) {
                 // router.php has encoded that in the url, we need to undo
                 $title = array();
                 $originalVars['searchword'] = $vars['searchword'];
                 shAddToGETVarsList('searchword', $vars['searchword']);
                 if (!empty($vars['view'])) {
                     $vars['view'] = $vars['view'];
                     shAddToGETVarsList('view', $vars['view']);
                 }
             }
             // handle menu items, having only a single Itemid in the url
             // (router.php will return an empty array in that case, even if we have restored
             // the full non-sef url, as we already did)
             /*
              * Build the application route
              */
             $tmp = '';
             if (empty($title) && isset($vars['Itemid']) && !empty($vars['Itemid'])) {
                 $menu =& shRouter::shGetMenu();
                 $item = $menu->getItem($vars['Itemid']);
                 if (is_object($item) && $vars['option'] == $item->component) {
                     $title[] = $item->route;
                 }
             }
             if (empty($title)) {
                 //$title[] = 'comp';
                 $title[] = substr($vars['option'], 4);
             }
             // add user defined prefix
             $prefix = shGetComponentPrefix($option);
             if (!empty($prefix)) {
                 array_unshift($title, $prefix);
             }
             // now process the resulting title string
             $string = shFinalizePlugin($string, $title, $shAppendString, '', isset($limit) ? @$limit : null, isset($limitstart) ? @$limitstart : null, isset($shLangName) ? @$shLangName : null, isset($showall) ? @$showall : null);
             break;
             // use sh404sef plugins, either in ext. dir or in sh404sef dir
         // use sh404sef plugins, either in ext. dir or in sh404sef dir
         case Sh404sefClassBaseextplugin::TYPE_SH404SEF_ROUTER:
             _log('Loading sh404SEF plugin in ' . $extPluginPath);
             include $extPluginPath;
             break;
         case Sh404sefClassBaseextplugin::TYPE_JOOMSEF_ROUTER:
             Sh404sefHelperExtplugins::loadJoomsefCompatLibs();
             include_once $extPluginPath;
             $className = 'SefExt_' . $option;
             $plugin = new $className();
             if (!shIsHomepage($string)) {
                 // make sure the plugin does not try to calculate pagination
                 $params =& SEFTools::GetExtParams('com_content');
                 $params->set('pagination', '1');
                 // ask plugin to build url
                 $plugin->beforeCreate($originalUri);
                 $result = $plugin->create($originalUri);
                 $title = empty($result['title']) ? array() : $result['title'];
                 $plugin->afterCreate($originalUri);
                 // make sure we have a url
                 if (empty($title) && isset($vars['Itemid']) && !empty($vars['Itemid'])) {
                     $menu =& shRouter::shGetMenu();
                     $item = $menu->getItem($vars['Itemid']);
                     if (is_object($item) && $vars['option'] == $item->component) {
                         $title[] = $item->route;
                     }
                 }
                 $prefix = shGetComponentPrefix($option);
                 if (!empty($prefix)) {
                     array_unshift($title, $prefix);
                 }
                 if (empty($title) && !shIsHomepage($string)) {
                     $title[] = substr($vars['option'], 4);
                 }
                 list($usedVars, $ignore) = $plugin->getNonSefVars($result);
                 if (!empty($ignore)) {
                     $usedVars = array_merge($usedVars, $ignore);
                 }
             } else {
                 $string = '';
                 $title[] = '/';
                 $usedVars = array();
             }
             // post process result to adjust to our workflow
             if (!empty($vars)) {
                 foreach ($vars as $key => $value) {
                     if (!array_key_exists($key, $usedVars)) {
                         shRemoveFromGETVarsList($key);
                     }
                 }
             }
             // finalize url
             $string = shFinalizePlugin($string, $title, $shAppendString = '', $shItemidString = '', isset($limit) ? @$limit : null, isset($limitstart) ? @$limitstart : null, isset($shLangName) ? @$shLangName : null, isset($showall) ? @$showall : null);
             break;
         case Sh404sefClassBaseextplugin::TYPE_ACESEF_ROUTER:
             Sh404sefHelperExtplugins::loadAcesefCompatLibs();
             include_once $extPluginPath;
             $className = 'AceSEF_' . $option;
             $plugin = new $className();
             $plugin->AcesefConfig = AcesefFactory::getConfig();
             // some plugins appear to not call the constructor parent, and so AcesefConfig is not set
             $tmp =& JPluginHelper::getPlugin('sh404sefextacesef', $option);
             $params = new JParameter($tmp->params);
             $plugin->setParams($params);
             $segments = array();
             $do_sef = true;
             $metadata = array();
             $item_limitstart = 0;
             $plugin->beforeBuild($originalUri);
             $originalVars = empty($originalUri) ? $vars : $originalUri->getQuery($asArray = true);
             $plugin->build($originalVars, $title, $do_sef, $metadata, $item_limitstart);
             $plugin->afterBuild($originalUri);
             $prefix = shGetComponentPrefix($option);
             if (empty($title) && isset($vars['Itemid']) && !empty($vars['Itemid'])) {
                 $menu =& shRouter::shGetMenu();
                 $item = $menu->getItem($vars['Itemid']);
                 if (is_object($item) && $vars['option'] == $item->component) {
                     $title[] = $item->route;
                 }
             }
             if (!empty($prefix)) {
                 array_unshift($title, $prefix);
             }
             if (empty($title) && !shIsHomepage($string)) {
                 $title[] = substr($vars['option'], 4);
             }
             // acesef plugin don't remove used vars from our GET var manager
             // we'll do it now. Vars used are those not present anymore in
             // $originalVars
             // they will be reappended to the SEF url by shFinalizePlugin
             $usedVars = array_diff($vars, $originalVars);
             if (!empty($usedVars)) {
                 foreach ($usedVars as $key => $value) {
                     shRemoveFromGETVarsList($key);
                 }
             }
             // remove Itemid and option, as these are not unset by plugin
             shRemoveFromGETVarsList('Itemid');
             shRemoveFromGETVarsList('option');
             // finalize url
             $string = shFinalizePlugin($string, $title, $shAppendString = '', $shItemidString = '', isset($limit) ? @$limit : null, isset($limitstart) ? @$limitstart : null, isset($shLangName) ? @$shLangName : null, isset($showall) ? @$showall : null);
             break;
         default:
             _log('Falling back to sefGetLocation');
             if (empty($sefConfig->defaultComponentStringList[str_replace('com_', '', $option)])) {
                 $title[] = getMenuTitle($option, isset($task) ? @$task : null, null, null, $shLanguage);
             } else {
                 $title[] = $sefConfig->defaultComponentStringList[str_replace('com_', '', $option)];
             }
             if ($title[0] != '/') {
                 $title[] = '/';
             }
             // V 1.2.4.q getMenuTitle can now return '/'
             if (count($title) > 0) {
                 // V 1.2.4.q use $shLanguage insted of $lang  (lang name rather than lang code)
                 $string = sef_404::sefGetLocation($string, $title, isset($task) ? @$task : null, isset($limit) ? @$limit : null, isset($limitstart) ? @$limitstart : null, isset($shLanguage) ? @$shLanguage : null);
             }
             break;
     }
     return $string;
 }
示例#3
0
 public function onAfterInitialise()
 {
     // prevent warning on php5.3+
     $this->_fixTimeWarning();
     // get joomla application object
     $app =& JFactory::getApplication();
     // register our autoloader
     $this->_registerAutoloader();
     require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_sh404sef' . DS . 'sh404sef.class.php';
     // get our configuration
     $sefConfig =& Sh404sefFactory::getConfig();
     // hook for a few SEO hacks
     if ($app->isSite()) {
         $this->_hacks(JRequest::get(), $sefConfig);
     }
     // security layer
     if (!$app->isAdmin() && $sefConfig->shSecEnableSecurity) {
         require_once JPATH_ROOT . DS . 'components' . DS . 'com_sh404sef' . DS . 'shSec.php';
         // do security checks
         shDoSecurityChecks();
         shCleanUpSecLogFiles();
         // see setting in class file for clean up frequency
     }
     // optionnally collect page creation time
     if (!$app->isAdmin() && $sefConfig->analyticsEnableTimeCollection) {
         jimport('joomla.error.profiler');
         // creating the profiler object will start the counter
         $profiler =& JProfiler::getInstance('sh404sef_profiler');
     }
     // load plugins, as per configuration
     $this->_loadPlugins($type = 'sh404sefcore');
     // load extension plugins, created by others
     $this->_loadPlugins($type = 'sh404sefext');
     // hook to be able to install other SEF extension plugins
     Sh404sefHelperExtplugins::loadInstallAdapters();
     // another hook to allow other SEF extensions language file to be loaded
     Sh404sefHelperExtplugins::loadLanguageFiles();
     if (!$sefConfig->Enabled) {
         // go away if not enabled
         return;
     }
     // fake language filter
     if ($sefConfig->enableMultiLingualSupport) {
         $app->set('menu_associations', 1);
         if (!$app->isAdmin()) {
             $app->setLanguageFilter(true);
         }
     }
     if (!defined('SH404SEF_IS_RUNNING')) {
         DEFINE('SH404SEF_IS_RUNNING', 1);
     }
     if (!$app->isAdmin()) {
         // setup our JPagination replacement, so as to bring
         // back # of items per page in the url, in order
         // to properly calculate pagination
         // will only work if php > 5, so test for that
         if (version_compare(phpversion(), '5.0') >= 0) {
             // this register the old file, but do not load it if PHP5
             // will prevent further calls to the same jimport()
             // to actually do anything, because the 'joomla.html.pagination' key
             // is now registered statically in Jloader::import()
             jimport('joomla.html.pagination');
             // now we can register our own path
             JLoader::register('JPagination', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_sh404sef' . DS . 'pagination.php');
         }
         // attach parse and build rules to Joomla router
         $joomlaRouter = $app->getRouter();
         $pageInfo =& Sh404sefFactory::getPageInfo();
         $pageInfo->router = new Sh404sefClassRouter();
         $joomlaRouter->attachParseRule(array($pageInfo->router, 'parseRule'));
         $joomlaRouter->attachBuildRule(array($pageInfo->router, 'buildRule'));
         // forece J! router config to SEF if at least one of the installed
         // components has been set to use raw J! router
         if (!empty(Sh404sefFactory::getConfig()->useJoomlaRouter)) {
             $joomlaRouter->setMode(JROUTER_MODE_SEF);
         }
         // pretend SEF is on, mostly for Joomla SEF plugin to work
         // as it checks directly 'sef' value in config, instead of
         // usgin $router->getMode()
         JFactory::$config->set('sef', 1);
         // kill Joomla suffix, so that it doesn't add or remove it in the parsing/building process
         JFactory::$config->set('sef_suffix', 0);
         // we use opposite setting from J!
         $mode = 1 - $sefConfig->shRewriteMode;
         JFactory::$config->set('sef_rewrite', $mode);
         // perform startup operations, such as detecting request caracteristics
         // and checking redirections
         $pageInfo->router->startup(JURI::getInstance());
     }
 }