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(); 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 } if (!$sefConfig->Enabled) { // go away if not enabled return; } 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'); } // include more sh404SEF stuff require_once JPATH_ROOT . DS . 'components' . DS . 'com_sh404sef' . DS . 'shCache.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; // load plugins, as per configuration $this->_loadPlugins($type = 'sh404sefcore'); // start decoding URL + decide possible redirects include JPATH_ROOT . DS . 'components' . DS . 'com_sh404sef' . DS . 'shInit.php'; } }
/** * Actual method performing parsing of a request as described * by an JURI object * * Also performs additional duties, like checking on aliases, * searching alternates syntax (add/remove trailing slash), * auto-redirect from non-sef to sef, etc * Possibly trigger a 404 if url can't be parsed to a valid * non sef url * * @see JRouter::_parseSefRoute() */ protected function _parseSefRoute(&$uri) { // will hold query vars parsed $vars = array(); // general config $sefConfig = Sh404sefFactory::getConfig(); // we'll need to work on the menu, get it $menu = JFactory::getApplication()->getMenu(true); // get request path and try to decode it $path = $uri->getPath(); // home page if (empty($path)) { // check more redirects: from non sef to sef $this->_checkNonSefToSefRedirects($uri); // now if no query vars, this is really home page $uriVars = $uri->getQuery(true); if (empty($uriVars)) { $menuItem = $menu->getDefault(JFactory::getLanguage()->getTag()); //get home menu item query vars $vars = $menuItem->query; //Get its Itemid $vars['Itemid'] = $menuItem->id; } else { // if some query vars, just pass them thru $vars = $uriVars; } } // non home page if (!empty($path)) { // fix the path before checking url. Joomla unfortunately remove // the trailing slash from the path $trailingSlash = $this->_hasTrailingSlash($uri); if ($trailingSlash & JString::substr($path, -1) != '/') { // if trailing slash on original request, but not on path // put it back $path .= '/'; } // lookup db for this sef $lookUp = $this->_lookupSef($uri, $vars, $path); // store the fetched data, if any $vars = $lookUp->vars; // and take additional actions based on the result of the lookup switch ($lookUp->urlType) { // existing matching url case sh404SEF_URLTYPE_AUTO: case sh404SEF_URLTYPE_CUSTOM: // permanently fix the path, if we had to fix it for a missing trailing slash // TODO: check how this would affect Joomla! // may not be a good idea // actually it won't hurt J! as we're working on a clone of $uri if ($trailingSlash) { $uri->setPath($path); } break; // 404 or some kind of redirect // 404 or some kind of redirect default: // try using J! router // if at least one extension uses Joomla! router, we must first try to use that if (!empty(Sh404sefFactory::getConfig()->useJoomlaRouter)) { // use parent parser $vars = parent::_parseSefRoute($uri); // if we found something, raise a flag self::$parsedWithJoomlaRouter = true; // collect vars that may have been stored by J! such as Itemid $vars = array_merge(Sh404sefFactory::getPageInfo()->router->getVars(), $vars); $this->setVars(array()); // and cut through the rest of the processing break; } // check more redirects: from Joomla SEF to our SEF $this->_checkJoomlaSefToSefRedirects($uri); // try find similar urls to redirect to: with or without trailing slash $this->_checkTrailingSlash($uri); // there might be an alias we're supposed to redirect current request to $this->_checkAliases($uri); // check if this is a short url $this->_checkShurls($uri); // if no alternative found, issue a 404 $vars = $this->_do404($uri); break; } } // Set the menu item as active, if we found any // this would normally be done by Joomla own _parseSefRoute() method // except it's not gonna be run as we changed the routing mode from // JROUTER_MODE_SEF to our own (ROUTER_MODE_SH404SEF) if (!empty($vars['Itemid'])) { $menu->setActive($vars['Itemid']); } // do security checks after decoding url if ($sefConfig->shSecEnableSecurity) { require_once JPATH_ROOT . DS . 'components' . DS . 'com_sh404sef' . DS . 'shSec.php'; // do security checks shDoSecurityChecks($uri->get('_uri'), false); // check this newly created URL } return $vars; }
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'; } }
$pos = array_search($_REQUEST['amp;option'], $path_array); } } if (!($sef_ext_class == "sef_content" or $sef_ext_class == "sef_component")) { if ($pos == 0) { array_unshift($path_array, "option"); } } $_SEF_SPACE = $sefConfig->replacement; // search for the non-sef equivalent of incoming SEF url $shPageInfo->QUERY_STRING = $sef_ext->revert($path_array, $pos); _log('Reverted query string = ' . $shPageInfo->QUERY_STRING); if ($sefConfig->shSecEnableSecurity) { require_once JPATH_ROOT . DS . 'components' . DS . 'com_sh404sef' . DS . 'shSec.php'; // do security checks shDoSecurityChecks($shPageInfo->QUERY_STRING, false); // check this newly created URL } // V 1.2.4.l added automatic redirect of Joomla standard SEF to sh404SEF URL. // V 1.2.4.p restrict automatic redirect to Joomla own sef, otherwise it breaks opensef/sefadvance sef_ext files // V x : allow redirect even if Joomfish, if URL is already in DB but check if reverted string is valid // may not be so in case of attacks or badly formed J! SEF url if (is_valid($shPageInfo->QUERY_STRING) && ($sef_ext_class == 'sef_content' || $sef_ext_class == 'sef_component')) { // if we have Joomla standard SEF if (empty($shPageInfo->autoRedirectsDisabled) && $sefConfig->shRedirectJoomlaSefToSef && $shPageInfo->URI->url && empty($_POST)) { // and are set to auto-redirect to SEF URLs // try fetching from DB $shSefUrl = null; $nonSefURL = 'index.php?' . $shPageInfo->QUERY_STRING; if (strpos($nonSefURL, 'lang=') === false) { $nonSefURL = shSetURLVar($nonSefURL, 'lang', shGetIsoCodeFromName($GLOBALS['shMosConfig_locale']));
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()); } }