function _parseSefUrl(&$uri, &$oldUri) { $mainframe =& JFactory::getApplication(); $db =& JFactory::getDBO(); $sefConfig =& SEFConfig::getConfig(); $route = $uri->getPath(); $oldRoute = $jSef = str_replace(' ', '+', urldecode($oldUri->getPath())); $oldRoute = ltrim($oldRoute, '/'); //Get the variables from the uri $vars = $uri->getQuery(true); // Should we generate canonical link automatically? $generateCanonical = count($vars) > 0; // handle an empty URL (special case) if (empty($route)) { if (count($vars) > 0 || count($_POST) > 0) { $redir = false; } else { $redir = true; } JoomSEF::_determineLanguage(JRequest::getVar('lang'), $redir, $redir); $menu =& JSite::getMenu(true); // if route is empty AND option is set in the query, assume it's non-sef url, and parse apropriately if (isset($vars['option']) || isset($vars['Itemid'])) { return JoomSEF::_parseRawRoute($uri); } $item = $menu->getDefault(); //Set the information in the request $vars = $item->query; //Get the itemid $vars['Itemid'] = $item->id; // Set the active menu item $menu->setActive($vars['Itemid']); // Create automatic canonical link if set to if ($generateCanonical) { $extAuto = 2; if (isset($vars['option'])) { $params =& SEFTools::getExtParams($vars['option']); $extAuto = $params->get('autoCanonical', 2); } $autoCanonical = $extAuto == 2 ? $sefConfig->autoCanonical : $extAuto; if ($extAuto) { JoomSEF::set('sef.link.canonical', JURI::root()); } } // MetaTags for frontpage $db->setQuery("SELECT `id` FROM `#__plugins` WHERE `element` = 'joomsef' AND `folder` = 'system' AND `published` = '1'"); if ($db->loadResult()) { // ... and frontpage has meta tags // If JoomFish installed, get all the URLs for frontpage and try to find the correct language $lang = JRequest::getVar('lang'); $query = "SELECT * FROM `#__sefurls` WHERE (`sefurl` = '' OR `sefurl` = 'index.php') AND `trashed` = '0'"; if (SEFTools::JoomFishInstalled() && !is_null($lang)) { $db->setQuery($query); $sefRows = $db->loadObjectList(); if (is_array($sefRows) && count($sefRows) > 0) { $noLang = null; foreach ($sefRows as $row) { if (preg_match('/[?&]lang=' . $lang . '($|&)/', $row->origurl) > 0) { $sefRow = $row; break; } // Save the first URL with no lang variable if (is_null($noLang)) { if (preg_match('/[?&]lang=[^&]*/', $row->origurl) == 0) { $noLang = $row; } } } // If not found, try to use the one without lang variable if (empty($sefRow) && !is_null($noLang)) { $sefRow = $noLang; } } } else { // Try to find it the old way $db->setQuery($query . ' LIMIT 1'); $sefRow = $db->loadObject(); } if (!empty($sefRow)) { $mainframe =& JFactory::getApplication(); if (!empty($sefRow->metatitle)) { JoomSEF::set('sef.meta.title', $sefRow->metatitle); } if (!empty($sefRow->metadesc)) { JoomSEF::set('sef.meta.desc', $sefRow->metadesc); } if (!empty($sefRow->metakey)) { JoomSEF::set('sef.meta.key', $sefRow->metakey); } if (!empty($sefRow->metalang)) { JoomSEF::set('sef.meta.lang', $sefRow->metalang); } if (!empty($sefRow->metarobots)) { JoomSEF::set('sef.meta.robots', $sefRow->metarobots); } if (!empty($sefRow->metagoogle)) { JoomSEF::set('sef.meta.google', $sefRow->metagoogle); } if (!empty($sefRow->canonicallink)) { JoomSEF::set('sef.link.canonical', $sefRow->canonicallink); } if (!empty($sefRow->metacustom)) { $metacustom = @unserialize($sefRow->metacustom); if (!empty($metacustom)) { JoomSEF::set('sef.meta.custom', $metacustom); } } } } return $vars; } $disabled = false; $sef_ext = new SefExt(); $newVars = $sef_ext->revert($route, $disabled); // We need to determine language BEFORE Joomla SEO // so the menu is translated correctly $config =& JFactory::getConfig(); $lang = $config->get('joomsef.domain_lang'); if (empty($lang)) { $lang = isset($newVars['lang']) ? $newVars['lang'] : (isset($vars['lang']) ? $vars['lang'] : null); } // If the URL was not parsed and we do not have a language, try to // parse it from URL in case the default router was used if (empty($newVars) && empty($lang) && SEFTools::JoomFishInstalled()) { $lang = JoomSEF::_parseLangFromRoute($route); if (!is_null($lang)) { $langRoute = $route; } } JoomSEF::_determineLanguage($lang, false, true); if (!empty($newVars) && !empty($vars)) { // If this was SEF url, consider the vars in query as nonsef $nonsef = array_diff_key($vars, $newVars); if (!empty($nonsef)) { JoomSEF::set('sef.global.nonsefvars', $nonsef); } } // try to parse joomla native seo if ($sefConfig->parseJoomlaSEO && empty($newVars)) { $oldUrl = $oldUri->toString(array('path', 'query', 'fragment')); if (isset($langRoute)) { $oldUri->setPath($langRoute); } $router = JoomSEF::get('sef.global.jrouter'); $jvars = $router->parse($oldUri); if (!empty($jvars['option']) || !empty($jvars['Itemid'])) { // Try to get the SEF URL $oldDisable = $sefConfig->disableNewSEF; $sefConfig->disableNewSEF = true; // Remove the default format if set if (isset($jvars['format']) && $jvars['format'] == 'html') { unset($jvars['format']); } $jUri = new JURI('index.php'); $jUri->setQuery($jvars); $jUrl = $jUri->toString(array('path', 'query', 'fragment')); $jSef = JRoute::_($jUrl); $jSef = str_replace('&', '&', $jSef); // Fix the spaces $oldUrl = str_replace(' ', '+', $oldUrl); $jSef = str_replace(' ', '+', urldecode($jSef)); // Restore the configuration $sefConfig->disableNewSEF = $oldDisable; // Redirect if possible if ($sefConfig->redirectJoomlaSEF && count($_POST) == 0) { // Non-SEF redirect if (strpos($jSef, 'index.php?') === false && $oldUrl != $jSef) { // Check start/limitstart - we don't want to redirect if this is the only difference if (str_replace('limitstart=', 'start=', $oldUrl) != str_replace('limitstart=', 'start=', $jSef)) { // Seems the URL is SEF, let's redirect $f = $l = ''; if (!headers_sent($f, $l)) { $mainframe =& JFactory::getApplication(); $mainframe->redirect($jSef, '', 'message', true); exit; } else { JoomSEF::_headers_sent_error($f, $l, __FILE__, __LINE__); } } } } // Redirect was not possible /* removed - causing problems // Check to see if the component is handled by the default joomla router if (!isset($jvars['option'])) { // Get the option from menu item $menu =& JSite::getMenu(true); $item =& $menu->getItem($jvars['Itemid']); if (!is_null($item) && isset($item->query['option'])) { $jopt = $item->query['option']; } } else { $jopt = $jvars['option']; } if (isset($jopt)) { $jparams = SEFTools::getExtParams($jopt); // Default Joomla router in use? if ($jparams->get('handling', '0') == '1') { // OK, we can show the page for this component $newVars = $jvars; } // JoomSEF router used? else if ($jparams->get('handling', '0') == '0') { // We can show the page only if there is no JoomSEF extension installed $ownExt = JPATH_ROOT.DS.'components'.DS.'com_sef'.DS.'sef_ext'.DS.$jopt.'.php'; if (!file_exists($ownExt)) { $newVars = $jvars; } } } */ // We should show the page, but use the canonical link if SEF exists but redirection was not possible $newVars = $jvars; if (strpos($jSef, 'index.php?') === false && $oldUrl != $jSef) { $jSef = rtrim(JURI::root(), '/') . '/' . ltrim($jSef, '/'); JoomSEF::set('sef.link.canonical', $jSef); } } } if (!empty($vars)) { // append the original query string because some components // (like SMF Bridge and SOBI2) use it $vars = array_merge($vars, $newVars); } else { $vars = $newVars; } if (!empty($newVars) && !$disabled) { // Parsed correctly and enabled JoomSEF::_sendHeader('HTTP/1.0 200 OK'); // Create automatic canonical link if set to and it is not already set $canonical = JoomSEF::get('sef.link.canonical'); if ($generateCanonical && empty($canonical)) { $extAuto = 2; if (isset($vars['option'])) { $params =& SEFTools::getExtParams($vars['option']); $extAuto = $params->get('autoCanonical', 2); } $autoCanonical = $extAuto == 2 ? $sefConfig->autoCanonical : $extAuto; if ($extAuto) { $canonical = rtrim(JURI::root(), '/') . '/' . $oldRoute; JoomSEF::set('sef.link.canonical', $canonical); } } } else { // set nonsef vars JoomSEF::set('sef.global.nonsefvars', $vars); // bad URL, so check to see if we've seen it before // 404 recording (only if enabled) if ($sefConfig->record404) { $query = 'SELECT `id` FROM `#__sefurls` WHERE `sefurl` = ' . $db->Quote($oldRoute) . " AND `trashed` = '0'"; $db->setQuery($query); $resultId = $db->loadResult(); if ($resultId) { // we have it, so update counter $db->setQuery("UPDATE `#__sefurls` SET `cpt`=(`cpt`+1) WHERE `id` = '{$resultId}'"); $db->query(); } else { // get trace info if (@$sefConfig->trace) { $traceinfo = $db->Quote(JoomSEF::_getDebugInfo($sefConfig->traceLevel, true)); } else { $traceinfo = "NULL"; } // record the bad URL $query = 'INSERT INTO `#__sefurls` (`cpt`, `sefurl`, `origurl`, `trace`, `dateadd`) ' . " VALUES ('1', " . $db->Quote($oldRoute) . ", '', {$traceinfo}, CURDATE())"; $db->setQuery($query); $db->query(); } } // redirect to the error page $vars = JoomSEF::_get404vars($route); } // Set QUERY_STRING if set to if ($sefConfig->setQueryString) { $qs = array(); foreach ($vars as $name => $val) { if (is_array($val)) { foreach ($val as $k => $v) { $qs[] = $name . '[' . $k . ']=' . urlencode($v); } } else { $qs[] = $name . '=' . urlencode($val); } } $qs = implode('&', $qs); if (!empty($qs)) { $_SERVER['QUERY_STRING'] = $qs; } } return $vars; }
function _parseSefUrl(&$uri, &$oldUri) { $mainframe =& JFactory::getApplication(); $db =& JFactory::getDBO(); $sefConfig =& SEFConfig::getConfig(); $route = $uri->getPath(); //Get the variables from the uri $vars = $uri->getQuery(true); // Should we generate canonical link automatically? $generateCanonical = count($vars) > 0; // handle an empty URL (special case) if (empty($route) || $route == JRequest::getVar('lang')) { if (count($vars) > 0) { $redir = false; } else { $redir = true; } $menu = $mainframe->getMenu('site'); // TODO: handle metatags for subdomains correctly // if route is empty AND option is set in the query, assume it's non-sef url, and parse apropriately if (isset($vars['option']) || isset($vars['Itemid'])) { return JoomSEF::_parseRawRoute($uri); } //$item = $menu->getDefault(); // Workaround until Joomla menu bug will be fixed $langs = JLanguageHelper::getLanguages('sef'); $items = null; if (isset($langs[JRequest::getVar('lang')])) { $items = $menu->getItems(array('home', 'language'), array('1', $langs[JRequest::getVar('lang')]->lang_code)); } if (!is_array($items) || count($items) == 0) { $items = $menu->getItems(array('home'), array('1')); } $item = $items[0]; //Set the information in the request $vars = $item->query; //Get the itemid $vars['Itemid'] = $item->id; // Set the active menu item $menu->setActive($vars['Itemid']); // Create automatic canonical link if set to if ($generateCanonical) { $extAuto = 2; if (isset($vars['option'])) { $params =& SEFTools::getExtParams($vars['option']); $extAuto = $params->get('autoCanonical', 2); } $autoCanonical = $extAuto == 2 ? $sefConfig->autoCanonical : $extAuto; if ($autoCanonical) { JoomSEF::set('sef.link.canonical', JURI::root()); } } // MetaTags for frontpage if (JPluginHelper::isEnabled('system', 'joomsef')) { // ... and frontpage has meta tags // Get all the URLs for frontpage and try to find the correct one $lang = JRequest::getVar('lang'); $query = "SELECT * FROM #__sefurls WHERE sefurl = " . $db->quote($route) . " ORDER BY `priority`"; $db->setQuery($query); $sefRows = $db->loadObjectList(); if (is_array($sefRows)) { $count = count($sefRows); if ($count == 1) { // Use the only one $sefRow = $sefRows[0]; } else { if ($count > 1) { // Loop through URLs and find the one corresponding to menu item and possibly language foreach ($sefRows as $row) { // Check if variables match $varsOk = true; parse_str(str_replace('index.php?', '', $row->origurl), $rowVars); foreach ($vars as $varKey => $varVal) { if ($varKey == 'Itemid') { if ($row->Itemid != $varVal) { $varsOk = false; break; } } else { if (!isset($rowVars[$varKey]) || $rowVars[$varKey] != $varVal) { $varsOk = false; break; } } } if (!$varsOk) { continue; } // Variables match, this seems to be home page URL, try checking language if (is_null($lang)) { // No language, use this URL $sefRow = $row; break; } else { // Check language if (isset($rowVars['lang'])) { if ($rowVars['lang'] == $lang) { // Found exact URL $sefRow = $row; break; } } else { if (empty($noLang)) { // This URL doesn't contain lang variable, store it for later use $noLang = $row; } } } } // If we didn't find correct URL, try to use the one without lang variable if (empty($sefRow) && !empty($noLang)) { $sefRow = $noLang; } } } } // Set meta tags if (!empty($sefRow)) { $mainframe =& JFactory::getApplication(); if (!empty($sefRow->metatitle)) { JoomSEF::set('sef.meta.title', $sefRow->metatitle); } if (!empty($sefRow->metadesc)) { JoomSEF::set('sef.meta.desc', $sefRow->metadesc); } if (!empty($sefRow->metakey)) { JoomSEF::set('sef.meta.key', $sefRow->metakey); } if (!empty($sefRow->metalang)) { JoomSEF::set('sef.meta.lang', $sefRow->metalang); } if (!empty($sefRow->metarobots)) { JoomSEF::set('sef.meta.robots', $sefRow->metarobots); } if (!empty($sefRow->metagoogle)) { JoomSEF::set('sef.meta.google', $sefRow->metagoogle); } if (!empty($sefRow->canonicallink)) { JoomSEF::set('sef.link.canonical', $sefRow->canonicallink); } if (isset($sefRow->showsitename)) { JoomSEF::set('sef.meta.showsitename', $sefRow->showsitename); } if (!empty($sefRow->metacustom)) { $metacustom = @unserialize($sefRow->metacustom); if (!empty($metacustom)) { JoomSEF::set('sef.meta.custom', $metacustom); } } // Update hits count if set to if ($sefConfig->homePageHits) { $db->setQuery("UPDATE #__sefurls SET cpt=(cpt+1) WHERE id = '{$sefRow->id}'"); $db->query(); } } } return $vars; } $disabled = false; $sef_ext = new SefExt(); $newVars = $sef_ext->revert($route, $disabled); // We need to determine language BEFORE Joomla SEO // so the menu is translated correctly $lang = self::get('domain_lang'); if (empty($lang)) { $lang = isset($newVars['lang']) ? $newVars['lang'] : (isset($vars['lang']) ? $vars['lang'] : null); } else { if ($sefConfig->wrongDomainHandling != _COM_SEF_WRONG_DOMAIN_DO_NOTHING) { // We have a language from domain, check if it corresponds to language in SEF URL if (isset($newVars['lang']) && $newVars['lang'] != $lang) { // Domain and SEF URL languages don't match if ($sefConfig->wrongDomainHandling == _COM_SEF_WRONG_DOMAIN_REDIRECT) { // Redirect to correct domain if (isset($sefConfig->subDomainsJoomla[$newVars['lang']])) { $domain = $sefConfig->subDomainsJoomla[$newVars['lang']]; $redir = JURI::getInstance(); $redir->setHost($domain); // Redirect SEFTools::redirect($redir->toString(), true); } // No domain found, show 404 $disabled = true; } else { // Show 404 page $disabled = true; } } } } if (!empty($newVars) && !empty($vars) && $sefConfig->nonSefQueryVariables) { // If this was SEF url, consider the vars in query as nonsef $nonsef = array_diff_key($vars, $newVars); if (!empty($nonsef)) { JoomSEF::set('sef.global.nonsefvars', $nonsef); } } // try to parse joomla native seo if ($sefConfig->parseJoomlaSEO && empty($newVars)) { $oldUrl = $oldUri->toString(array('path', 'query', 'fragment')); $router = $mainframe->getRouter(); $router->setMode(JROUTER_MODE_SEF); $jvars = $router->parse($oldUri); $router->setMode(JROUTER_MODE_DONT_PARSE); // Check 404 if (isset($jvars['option']) && $jvars['option'] == 'com_content' && isset($jvars['view']) && isset($jvars['id']) && $jvars['id'] == 0) { // 404 $jvars = array(); } if (!empty($jvars['option']) || !empty($jvars['Itemid'])) { // Fix Itemid if (array_key_exists('Itemid', $jvars) && is_null($jvars['Itemid'])) { unset($jvars['Itemid']); } // Try to get option from URL or menu item if (!isset($jvars['option'])) { // Get the option from menu item $menu = JFactory::getApplication()->getMenu('site'); $item =& $menu->getItem($jvars['Itemid']); if (!is_null($item) && isset($item->query['option'])) { $jopt = $item->query['option']; } } else { $jopt = $jvars['option']; } // Was it possible to retrieve component? if (isset($jopt)) { // If the component is not handled by default Joomla router // try to find corresponding SEF URL in JoomSEF's database require_once JPATH_ADMINISTRATOR . '/components/com_sef/models/extensions.php'; $handler = SEFModelExtensions::_getActiveHandler($jopt); if (!in_array($handler->code, array(_COM_SEF_HANDLER_ROUTER, _COM_SEF_HANDLER_JOOMLA, _COM_SEF_HANDLER_NONE))) { // Try to get the SEF URL $oldDisable = $sefConfig->disableNewSEF; $sefConfig->disableNewSEF = true; $jUri = new JURI('index.php'); $jUri->setQuery($jvars); if ($jUri->getVar('format') == 'html') { $jUri->delVar('format'); } $jUrl = $jUri->toString(array('path', 'query', 'fragment')); $jSefUri = new JURI(JRoute::_($jUrl)); $jSef = $jSefUri->toString(array('path', 'query', 'fragment')); //$jSef = urldecode(str_replace('&', '&', $jSef)); // Remove base $base = JURI::base(true); $baseLen = strlen($base); if (substr($oldUrl, 0, $baseLen) == $base) { $oldUrl = substr($oldUrl, $baseLen); } if (substr($jSef, 0, $baseLen) == $base) { $jSef = substr($jSef, $baseLen); } // Fix slashes - left $oldUrl = ltrim($oldUrl, '/'); $jSef = ltrim($jSef, '/'); // Fix slashes - right //$oldUrl = preg_replace('/^([^?]*)\/(\??)/', '$1$2', $oldUrl); //$jSef = preg_replace('/^([^?]*)\/(\??)/', '$1$2', $jSef); $oldUrl = JoomSEF::_removeRightSlash($oldUrl); $jSef = JoomSEF::_removeRightSlash($jSef); // Restore the configuration $sefConfig->disableNewSEF = $oldDisable; if (count($_POST) == 0) { // Non-SEF redirect if (strpos($jSef, 'index.php?') === false && $oldUrl != $jSef) { // Seems the URL is SEF, let's redirect SEFTools::redirect(JURI::root() . $jSef, true); } } } // OK, we can show the page for this component $newVars = $jvars; } } } if (!empty($vars)) { // append the original query string because some components // (like SMF Bridge and SOBI2) use it $vars = array_merge($vars, $newVars); } else { $vars = $newVars; } if (empty($newVars) == false && $disabled == false) { // Parsed correctly and enabled JoomSEF::_sendHeader('HTTP/1.0 200 OK'); // Create automatic canonical link if set to and it is not already set $canonical = JoomSEF::get('sef.link.canonical'); if ($generateCanonical && empty($canonical)) { $extAuto = 2; if (isset($vars['option'])) { $params =& SEFTools::getExtParams($vars['option']); $extAuto = $params->get('autoCanonical', 2); } $autoCanonical = $extAuto == 2 ? $sefConfig->autoCanonical : $extAuto; if ($autoCanonical) { JoomSEF::set('sef.link.canonical', JURI::root() . $route); } } } else { // 2.8.2013 dajo: don't set nonsef vars, this causes duplicate SEF URLs to be created, for example // when a search engine visits http://domain.com/non-existent-page?id=10 // (all menu links etc. have duplicates without the id variable created) // set nonsef vars //if (!$disabled) { // JoomSEF::set('sef.global.nonsefvars', $vars); //} // bad URL, so check to see if we've seen it before // 404 recording (only if enabled) if ($sefConfig->record404) { $query = "SELECT * FROM `#__sefurls` WHERE `sefurl` = '" . $route . "'"; $db->setQuery($query); $results = $db->loadObjectList(); if ($results) { // we have it, so update counter $db->setQuery("UPDATE `#__sefurls` SET `cpt`=(`cpt`+1) WHERE `sefurl` = '" . $route . "'"); $db->query(); } else { // get trace info if (@$sefConfig->trace) { $traceinfo = $db->quote(JoomSEF::_getDebugInfo($sefConfig->traceLevel, true)); } else { $traceinfo = "NULL"; } // record the bad URL $query = "INSERT INTO `#__sefurls` (`cpt`, `sefurl`, `origurl`, `trace`, `dateadd`) " . " VALUES ( '1', '{$route}', '', {$traceinfo}, CURDATE() )"; $db->setQuery($query); $db->query(); } } // redirect to the error page $vars = JoomSEF::_get404vars($route); } // Set QUERY_STRING if set to if ($sefConfig->setQueryString) { $qs = array(); self::_buildQueryStringValues($qs, '', $vars); $qs = implode('&', $qs); if (!empty($qs)) { $_SERVER['QUERY_STRING'] = $qs; } } return $vars; }
function SefExt_com_kunena() { if (is_null(self::$kunenaprefix)) { // Check Kunena component version $db =& JFactory::getDbo(); $query = "SELECT `manifest_cache` FROM `#__extensions` WHERE `type` = 'component' AND `element` = 'com_kunena'"; $db->setQuery($query); $data = $db->loadResult(); if (is_null($data)) { // Version < 1.6 (used manifest.xml) $ver = '1.5'; } else { // Check version $data = json_decode($data); if (isset($data->version)) { $ver = $data->version; } else { $ver = '1.5'; } } if (version_compare($ver, '1.6.0', '<')) { // Before 1.6 self::$kunenaprefix = 'fb'; self::$fieldCatParent = 'parent'; } else { // 1.6 or higher self::$is16 = true; self::$kunenaprefix = 'kunena'; if (version_compare($ver, '2.0.0', '<')) { // Lower than 2.0 self::$fieldCatParent = 'parent'; } else { // 2.0 or higher self::$is20 = true; self::$fieldCatParent = 'parent_id'; if (version_compare($ver, '2.0.2', '>=')) { // 2.0.2 or higher self::$hasAlias = true; } } } self::$tableMessages = '`#__' . self::$kunenaprefix . '_messages`'; self::$tableCategories = '`#__' . self::$kunenaprefix . '_categories`'; self::$tableAnnouncement = '`#__' . self::$kunenaprefix . '_announcement`'; // Get Kunena configuration global $fbConfig; if (is_object($fbConfig)) { self::$kunenaConfig = $fbConfig; } else { $file = JPATH_ROOT . '/administrator/components/com_kunena/libraries/config.php'; $file2 = JPATH_ROOT . '/components/com_kunena/lib/kunena.config.class.php'; $file3 = JPATH_ROOT . '/libraries/kunena/config.php'; if (file_exists($file3)) { jimport('kunena.config'); self::$kunenaConfig = KunenaConfig::getInstance(); } else { if (file_exists($file)) { require_once $file; self::$kunenaConfig = KunenaConfig::getInstance(); } else { if (file_exists($file2)) { require_once $file2; self::$kunenaConfig = new CKunenaConfig(); self::$kunenaConfig->load(); } } } $fbConfig = self::$kunenaConfig; } } // call parent constructor parent::__construct(); }