function shFetchPostId($show, $option, $shLangName) { if (empty($show)) { return null; } try { $postId = ShlDbHelper::selectResult('#__myblog_permalinks', 'contentid', array('permalink' => $show)); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } return isset($postId) ? $postId : ''; }
public static function getDefinitions() { if (is_null(self::$_definitions)) { jimport('joomla.utilities.xmlelement'); // Disable libxml errors and allow to fetch error information as needed $errorSetting = libxml_use_internal_errors(true); self::$_definitions = JFactory::getXML(sh404SEF_ADMIN_ABS_PATH . 'helpers/ogp.xml'); libxml_use_internal_errors($errorSetting); if (!self::$_definitions) { foreach (libxml_get_errors() as $error) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $error); } } } return self::$_definitions; }
public static function updateShurls() { $pageInfo =& Sh404sefFactory::getPageInfo(); $sefConfig =& Sh404sefFactory::getConfig(); $pageInfo->shURL = empty($pageInfo->shURL) ? '' : $pageInfo->shURL; if ($sefConfig->enablePageId && !$sefConfig->stopCreatingShurls) { try { jimport('joomla.utilities.string'); $nonSefUrl = JString::ltrim($pageInfo->currentNonSefUrl, '/'); $nonSefUrl = shSortURL($nonSefUrl); // make sure we have a language $nonSefUrl = shSetURLVar($nonSefUrl, 'lang', $pageInfo->currentLanguageShortTag); // remove tracking vars (Google Analytics) $nonSefUrl = Sh404sefHelperGeneral::stripTrackingVarsFromNonSef($nonSefUrl); // try to get the current shURL, if any $shURL = ShlDbHelper::selectResult('#__sh404sef_pageids', array('pageid'), array('newurl' => $nonSefUrl)); // if none, we may have to create one if (empty($shURL)) { $shURL = self::_createShurl($nonSefUrl); } // insert in head and header, if not empty if (!empty($shURL)) { $fullShURL = JString::ltrim($pageInfo->getDefaultFrontLiveSite(), '/') . '/' . $shURL; $document = JFactory::getDocument(); if ($sefConfig->insertShortlinkTag) { $document->addHeadLink($fullShURL, 'shortlink'); // also add header, especially for HEAD requests JResponse::setHeader('Link', '<' . $fullShURL . '>; rel=shortlink', true); } if ($sefConfig->insertRevCanTag) { $document->addHeadLink($fullShURL, 'canonical', 'rev', array('type' => 'text/html')); } if ($sefConfig->insertAltShorterTag) { $document->addHeadLink($fullShURL, 'alternate shorter'); } // store for reuse $pageInfo->shURL = $shURL; } } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } } }
function shGetJSVideoTitle($id, $option, $shLangName) { $sefConfig =& Sh404sefFactory::getConfig(); try { $result = ShlDbHelper::selectObject('#__community_videos', array('id', 'title', 'category_id'), array('id' => $id)); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } $videoName = ($sefConfig->shJSInsertVideoId ? $id . $sefConfig->replacement : '') . $result->title; // optionnally insert video category if ($sefConfig->shJSInsertVideoCat) { $title = array(shGetJSVideoCategoryTitle($result->category_id, $option, $shLangName), $videoName); } else { $title = array($videoName); } return $title; }
function shSefRelToAbs($string, $shLanguageParam, &$uri, &$originalUri) { global $_SEF_SPACE, $shGETVars, $shRebuildNonSef; ShlSystem_Log::debug('sh404sef', 'Entering shSefRelToAbs with ' . $string . ' | Lang = ' . $shLanguageParam); $mainframe = JFactory::getApplication(); $pageInfo =& Sh404sefFactory::getPageInfo(); $sefConfig =& Sh404sefFactory::getConfig(); // if superadmin, display non-sef URL, for testing/setting up purposes if (sh404SEF_NON_SEF_IF_SUPERADMIN) { $user = JFactory::getUser(); if ($user->usertype == 'Super Administrator') { ShlSystem_Log::debug('sh404sef', 'Returning non-sef because superadmin said so.'); return 'index.php'; } } // return unmodified anchors if (JString::substr($string, 0, 1) == '#') { // V 1.2.4.t return $string; } // Quick fix for shared SSL server : if https, switch to non sef $id = shGetURLVar($string, 'Itemid', JRequest::getInt('Itemid')); $secure = 'yes' == shGetMenuItemSsl($id); if ($secure && $sefConfig->shForceNonSefIfHttps) { ShlSystem_Log::debug('sh404sef', 'Returning shSefRelToAbs : Forced non sef if https'); return shFinalizeURL($string); } $database = ShlDbHelper::getDb(); $shOrigString = $string; $shMosMsg = shGetMosMsg($string); // V x 01/09/2007 22:45:52 $string = shCleanUpMosMsg($string); // V x 01/09/2007 22:45:52 // V x : removed shJoomfish module. Now we set $mosConfi_lang here $shOrigLang = $pageInfo->currentLanguageTag; // save current language $shLanguage = shGetURLLang($string); // target language in URl is always first choice // second choice is param if (empty($shLanguage)) { $shLanguage = !empty($shLanguageParam) ? $shLanguageParam : $shLanguage; } // third choice is to read from menu, based on Itemid // but only for Joomla multilingual, this breaks // Joomfish/Falang, as current menu language may not be correct if (($pageInfo->isMultilingual === false || $pageInfo->isMultilingual == 'joomla') && empty($shLanguage) && !empty($id)) { $shLanguage = shGetMenuItemLanguage($id); } if (empty($shLanguage)) { $shLanguage = !empty($shLanguageParam) ? $shLanguageParam : $pageInfo->currentLanguageTag; } // V 1.3.1 protect against those drop down lists if (strpos($string, 'this.options[selectedIndex].value') !== false) { $string .= '&lang=' . shGetIsoCodeFromName($shLanguage); return $string; } $pageInfo->currentLanguageTag = $shLanguage; ShlSystem_Log::debug('sh404sef', 'Language used : ' . $shLanguage); // V 1.2.4.t workaround for old links like option=compName instead of option=com_compName if (strpos(strtolower($string), 'option=login') === false && strpos(strtolower($string), 'option=logout') === false && strpos(strtolower($string), 'option=&') === false && JString::substr(strtolower($string), -7) != 'option=' && strpos(strtolower($string), 'option=cookiecheck') === false && strpos(strtolower($string), 'option=') !== false && strpos(strtolower($string), 'option=com_') === false) { $string = str_replace('option=', 'option=com_', $string); } // V 1.2.4.j string to be appended to URL, but not saved to DB $shAppendString = ''; $shRebuildNonSef = array(); $shComponentType = ''; // V w initialize var to avoid notices if ($pageInfo->homeLink) { // now check URL against our homepage, so as to always return / if homepage $v1 = JString::ltrim(str_replace($pageInfo->getDefaultFrontLiveSite(), '', $string), '/'); // V 1.2.4.m : remove anchor if any $v2 = explode('#', $v1); $v1 = $v2[0]; $shAnchor = isset($v2[1]) ? '#' . $v2[1] : ''; $shSepString = JString::substr($v1, -9) == 'index.php' || strpos($v1, '?') === false ? '?' : '&'; $shLangString = 'lang=' . shGetIsoCodeFromName($shLanguage); if (!strpos($v1, 'lang=')) { $v1 .= $shSepString . $shLangString; } $v1 = str_replace('&', '&', shSortURL($v1)); // V 1.2.4.t check also without pagination info if (strpos($v1, 'limitstart=0') !== false) { // the page has limitstart=0 $stringNoPag = shCleanUpPag($v1); // remove paging info to be sure this is not homepage } else { $stringNoPag = null; } if ($v1 == $pageInfo->homeLink || $v1 == $pageInfo->allLangHomeLink || $v1 == 'index.php?' . $shLangString || $stringNoPag == $pageInfo->homeLink || $stringNoPag == $pageInfo->allLangHomeLink) { $shTemp = $v1 == $pageInfo->homeLink || shIsDefaultLang($shLanguage) ? '' : shGetIsoCodeFromName($shLanguage) . '/'; if (!empty($sefConfig->shForcedHomePage)) { // V 1.2.4.t $shTmp = $shTemp . $shAnchor; $ret = shFinalizeURL($sefConfig->shForcedHomePage . (empty($shTmp) ? '' : '/' . $shTmp)); if (empty($uri)) { // if no URI, append remaining vars directly to the string $ret .= $shAppendString; } else { shRebuildVars($shAppendString, $uri); } $pageInfo->currentLanguageTag = $shOrigLang; ShlSystem_Log::debug('sh404sef', 'Returning shSefRelToAbs 1 with ' . $ret); return $ret; } else { $shRewriteBit = shIsDefaultLang($shLanguage) ? '/' : $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode]; $ret = shFinalizeURL($pageInfo->getDefaultFrontLiveSite() . $shRewriteBit . $shTemp . $shAnchor); if (empty($uri)) { // if no URI, append remaining vars directly to the string $ret .= $shAppendString; } else { shRebuildVars($shAppendString, $uri); } $pageInfo->currentLanguageTag = $shOrigLang; ShlSystem_Log::debug('sh404sef', 'Returning shSefRelToAbs 2 with ' . $ret); return $ret; } } } $newstring = str_replace($pageInfo->getDefaultFrontLiveSite() . '/', '', $string); $letsGo = JString::substr($newstring, 0, 9) == 'index.php' && strpos($newstring, 'this.options[selectedIndex\\].value') === false; $letsGoSsl = false; if ($letsGo || $letsGoSsl) { // Replace & character variations. $string = str_replace(array('&', '&'), array('&', '&'), $letsGo ? $newstring : $newStringSsl); $newstring = $string; // V 1.2.4.q $shSaveString = $string; // warning : must add &lang=xx (only if it does not exists already), so as to be able to recognize the SefURL in the db if it's there if (!strpos($string, 'lang=')) { $shSepString = JString::substr($string, -9) == 'index.php' ? '?' : '&'; $anchorTable = explode('#', $string); // V 1.2.4.m remove anchor before adding language $string = $anchorTable[0]; $string .= $shSepString . 'lang=' . shGetIsoCodeFromName($shLanguage) . (!empty($anchorTable[1]) ? '#' . $anchorTable[1] : ''); // V 1.2.4.m then stitch back anchor } $URI = new sh_Net_URL($string); // V 1.2.4.l need to save unsorted URL if (count($URI->querystring) > 0) { // Import new vars here. $option = null; $task = null; //$sid = null; V 1.2.4.s // sort GET parameters to avoid some issues when same URL is produced with options not // in the same order, ie index.php?option=com_virtuemart&category_id=3&Itemid=2&lang=fr // Vs index.php?category_id=3&option=com_virtuemart&Itemid=2&lang=fr ksort($URI->querystring); // sort URL array $string = shSortUrl($string); // now we are ready to extract vars $shGETVars = $URI->querystring; extract($URI->querystring, EXTR_REFS); } if (empty($option)) { // V 1.2.4.r protect against empty $option : we won't know what to do $pageInfo->currentLanguageTag = $shOrigLang; ShlSystem_Log::debug('sh404sef', 'Returning shSefRelToAbs 3 with ' . $shOrigString); return $shOrigString; } // get plugin associated with the extension $extPlugin =& Sh404sefFactory::getExtensionPlugin($option); // get component type $shComponentType = $extPlugin->getComponentType(); $shOption = str_replace('com_', '', $option); //list of extension we always skip $alwaysSkip = array('jce', 'akeeba', 'media'); if (in_array($shOption, $alwaysSkip)) { $shComponentType = Sh404sefClassBaseextplugin::TYPE_SKIP; } // V 1.2.4.s : fallback to to JoomlaSEF if no extension available // V 1.2.4.t : this is too early ; it prevents manual custom redirect to be checked agains the requested non-sef URL ShlSystem_Log::debug('sh404sef', 'Component type = ' . $shComponentType); // is there a named anchor attached to $string? If so, strip it off, we'll put it back later. if ($URI->anchor) { $string = str_replace('#' . $URI->anchor, '', $string); } // V 1.2.4.m // shumisha special homepage processing (in other than default language) if (shIsAnyHomePage($string) || $string == 'index.php') { $sefstring = ''; $urlType = shGetSefURLFromCacheOrDB($string, $sefstring); // still use it so we need it both ways if (($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) && empty($showall) && (!empty($limit) || !isset($limit) && !empty($limitstart))) { $urlType = shGetSefURLFromCacheOrDB(shCleanUpPag($string), $sefstring); // V 1.2.4.t check also without page info //to be able to add pagination on custom //redirection or multi-page homepage if ($urlType != sh404SEF_URLTYPE_NONE && $urlType != sh404SEF_URLTYPE_404) { $sefstring = shAddPaginationInfo(@$limit, @$limitstart, @showall, 1, $string, $sefstring, null); // a special case : com_content does not calculate pagination right // for frontpage and blog, they include links shown at the bottom in the calculation of number of items // For instance, with joomla sample data, the frontpage has only 5 articles // but the view sets $limit to 9 !!! if ($option == 'com_content' && isset($layout) && $layout == 'blog' || $option == 'com_content' && isset($view) && $view == 'featured') { $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true); $string = shSetURLVar($string, 'limit', $listLimit); $string = shSortUrl($string); } // that's a new URL, so let's add it to DB and cache shAddSefUrlToDBAndCache($string, $sefstring, 0, $urlType); // created url must be of same type as original } if ($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) { require_once sh404SEF_FRONT_ABS_PATH . 'sef_ext.php'; $sef_ext = new sef_404(); // Rewrite the URL now. // a special case : com_content does not calculate pagination right // for frontpage and blog, they include links shown at the bottom in the calculation of number of items // For instance, with joomla sample data, the frontpage has only 5 articles // but the view sets $limit to 9 !!! if ($option == 'com_content' && isset($layout) && $layout == 'blog' || $option == 'com_content' && isset($view) && $view == 'featured') { $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true); $string = shSetURLVar($string, 'limit', $listLimit); $string = shSortUrl($string); //$URI->addQueryString( 'limit', $listLimit); } $urlVars = is_array($URI->querystring) ? array_map('urldecode', $URI->querystring) : $URI->querystring; $sefstring = $sef_ext->create($string, $urlVars, $shAppendString, $shLanguage, $shOrigString, $originalUri); // V 1.2.4.s added original string } } else { if ($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) { // not found but no $limit or $limitstart $sefstring = shGetIsoCodeFromName($shLanguage) . '/'; shAddSefUrlToDBAndCache($string, $sefstring, 0, sh404SEF_URLTYPE_AUTO); // create it } } // V 1.2.4.j : added $shAppendString to pass non sef parameters. For use with parameters that won't be stored in DB $ret = $pageInfo->getDefaultFrontLiveSite() . (empty($sefstring) ? '' : $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode] . $sefstring); $ret = shFinalizeURL($ret); if (empty($uri)) { // if no URI, append remaining vars directly to the string $ret .= $shAppendString; } else { shRebuildVars($shAppendString, $uri); } $pageInfo->currentLanguageTag = $shOrigLang; ShlSystem_Log::debug('sh404sef', 'Returning shSefRelToAbs 4 with ' . $ret); return $ret; } if (isset($option) && !($option == 'com_content' && @$task == 'edit') && strtolower($option) != 'com_sh404sef') { // V x 29/08/2007 23:19:48 // check also that option = com_content, otherwise, breaks some comp switch ($shComponentType) { case Sh404sefClassBaseextplugin::TYPE_SKIP: $sefstring = $shSaveString; // V 1.2.4.q : restore untouched URL, except anchor which will be added later // J! 1.6 kill all query vars $shGETVars = array(); $uri->setQuery(array()); break; case Sh404sefClassBaseextplugin::TYPE_SIMPLE: // check for custom urls $sefstring = ''; $urlType = shGetSefURLFromCacheOrDB($string, $sefstring); // if no custom found, then build default url if ($urlType != sh404SEF_URLTYPE_CUSTOM) { // if not found then fall back to Joomla! SEF if (isset($URI)) { unset($URI); } $sefstring = 'component/'; $URI = new sh_Net_URL(shSortUrl($shSaveString)); // can't remove yet, anchor is use later down $jUri = new JUri(shSortUrl($shSaveString)); $uriVars = $jUri->getQuery($asArray = true); if (count($uriVars) > 0) { foreach ($uriVars as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { // fix for arrays, thanks doorknob $sefstring .= $key . '[' . $k . '],' . $v . '/'; } } else { $sefstring .= $key . ',' . $value . '/'; } } $sefstring = str_replace('option,', '', $sefstring); } } break; default: $sefstring = ''; // base case: $urlType = shGetSefURLFromCacheOrDB($string, $sefstring); // first special case. User may have customized paginated urls // this will be picked up by the line above, except if we're talking about // a category or section blog layout, where Joomla does not uses the correct // value for limit if (($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) && empty($showall) && (!empty($limit) || !isset($limit) && !empty($limitstart))) { if ($option == 'com_content' && isset($layout) && $layout == 'blog' || $option == 'com_content' && isset($view) && $view == 'featured') { $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true); $tmpString = shSetURLVar($string, 'limit', $listLimit); $tmpString = shSortUrl($tmpString); $urlType = shGetSefURLFromCacheOrDB($tmpString, $sefstring); if ($urlType != sh404SEF_URLTYPE_NONE && $urlType != sh404SEF_URLTYPE_404) { // we found a match with pagination info! $string = $tmpString; } } } // now let's try again without any pagination at all /* if (($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) && empty( $showall) && (!empty($limit) || (!isset($limit) && !empty($limitstart)))) { $urlType = shGetSefURLFromCacheOrDB(shCleanUpPag($string), $sefstring); // search without pagination info if ($urlType != sh404SEF_URLTYPE_NONE && $urlType != sh404SEF_URLTYPE_404) { $sefstring = shAddPaginationInfo( @$limit, @$limitstart, @showall, 1, $string, $sefstring, null); // a special case : com_content does not calculate pagination right // for frontpage and blog, they include links shown at the bottom in the calculation of number of items // For instance, with joomla sample data, the frontpage has only 5 articles // but the view sets $limit to 9 !!! if (($option == 'com_content' && isset($layout) && $layout == 'blog') || ($option == 'com_content' && isset( $view) && $view == 'featured' )) { $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true); $string = shSetURLVar( $string, 'limit', $listLimit); $string = shSortUrl($string); } // that's a new URL, so let's add it to DB and cache ShlSystem_Log::debug( 'sh404sef', 'Created url based on non paginated base url:' . $string); shAddSefUrlToDBAndCache( $string, $sefstring, 0, $urlType); } } */ if ($urlType == sh404SEF_URLTYPE_NONE) { // If component has its own sef_ext plug-in included. $shDoNotOverride = in_array($shOption, $sefConfig->shDoNotOverrideOwnSef); if (shFileExists(sh404SEF_ABS_PATH . 'components/' . $option . '/sef_ext.php') && ($shDoNotOverride || !$shDoNotOverride && (!shFileExists(sh404SEF_ABS_PATH . 'components/com_sh404sef/sef_ext/' . $option . '.php') && !shFileExists(sh404SEF_ABS_PATH . 'components/' . $option . '/sef_ext/' . $option . '.php')))) { // Load the plug-in file. V 1.2.4.s changed require_once to include include_once sh404SEF_ABS_PATH . 'components/' . $option . '/sef_ext.php'; $_SEF_SPACE = $sefConfig->replacement; $comp_name = str_replace('com_', '', $option); $className = 'sef_' . $comp_name; $sef_ext = new $className(); // V x : added default string in params if (empty($sefConfig->defaultComponentStringList[$comp_name])) { $title[] = getMenuTitle($option, null, isset($Itemid) ? @$Itemid : null, null, $shLanguage); } else { $title[] = $sefConfig->defaultComponentStringList[$comp_name]; } // V 1.2.4.r : clean up URL BEFORE sending it to sef_ext files, to have control on what they do // remove lang information, we'll put it back ourselves later //$shString = preg_replace( '/(&|\?)lang=[a-zA-Z]{2,3}/iU' ,'', $string); // V 1.2.4.t use original non-sef string. Some sef_ext files relies on order of params, which may // have been changed by sh404SEF $shString = preg_replace('/(&|\\?)lang=[a-zA-Z]{2,3}/iu', '', $shSaveString); $finalstrip = explode("|", $sefConfig->stripthese); $shString = str_replace('&', '&', $shString); ShlSystem_Log::debug('sh404sef', 'Sending to own sef_ext.php plugin : ' . $shString); $sefstring = $sef_ext->create($shString); ShlSystem_Log::debug('sh404sef', 'Created by sef_ext.php plugin : ' . $sefstring); $sefstring = str_replace("%10", "%2F", $sefstring); $sefstring = str_replace("%11", $sefConfig->replacement, $sefstring); $sefstring = rawurldecode($sefstring); if ($sefstring == $string) { if (!empty($shMosMsg)) { // V x 01/09/2007 22:48:01 $string .= '?' . $shMosMsg; } $ret = shFinalizeURL($string); $pageInfo->currentLanguageTag = $shOrigLang; ShlSystem_Log::debug('sh404sef', 'Returning shSefRelToAbs 5 with ' . $ret); return $ret; } else { // V 1.2.4.p : sef_ext extensions for opensef/SefAdvance do not always replace ' $sefstring = str_replace('\'', $sefConfig->replacement, $sefstring); // some ext. seem to html_special_chars URL ? $sefstring = str_replace(''', $sefConfig->replacement, $sefstring); // V w 27/08/2007 13:23:56 $sefstring = str_replace(' ', $_SEF_SPACE, $sefstring); $sefstring = str_replace(' ', '', (shInsertIsoCodeInUrl($option, $shLanguage) ? shGetIsoCodeFromName($shLanguage) . '/' : '') . titleToLocation($title[0]) . '/' . $sefstring . ($sefstring != '' ? $sefConfig->suffix : '')); if (!empty($sefConfig->suffix)) { $sefstring = str_replace('/' . $sefConfig->suffix, $sefConfig->suffix, $sefstring); } //$finalstrip = explode("|", $sefConfig->stripthese); $sefstring = str_replace($finalstrip, $sefConfig->replacement, $sefstring); $sefstring = str_replace($sefConfig->replacement . $sefConfig->replacement . $sefConfig->replacement, $sefConfig->replacement, $sefstring); $sefstring = str_replace($sefConfig->replacement . $sefConfig->replacement, $sefConfig->replacement, $sefstring); $suffixthere = 0; if (!empty($sefConfig->suffix) && strpos($sefstring, $sefConfig->suffix) !== false) { // V 1.2.4.s $suffixthere = strlen($sefConfig->suffix); } $takethese = str_replace("|", "", $sefConfig->friendlytrim); $sefstring = JString::trim(JString::substr($sefstring, 0, strlen($sefstring) - $suffixthere), $takethese); $sefstring .= $suffixthere == 0 ? '' : $sefConfig->suffix; // version u 26/08/2007 17:27:16 // V 1.2.4.m store it in DB so as to be able to use sef_ext plugins really ! $string = str_replace('&', '&', $string); // V 1.2.4.r without mod_rewrite $shSefString = shAdjustToRewriteMode($sefstring); // V 1.2.4.p check for various URL for same content $dburl = ''; // V 1.2.4.t prevent notice error $urlType = sh404SEF_URLTYPE_NONE; if ($sefConfig->shUseURLCache) { $urlType = Sh404sefHelperCache::getNonSefUrlFromCache($shSefString, $dburl); } $newMaxRank = 0; // V 1.2.4.s $shDuplicate = false; if ($sefConfig->shRecordDuplicates || $urlType == sh404SEF_URLTYPE_NONE) { try { $sql = "SELECT newurl, rank, dateadd FROM #__sh404sef_urls WHERE oldurl = " . $database->Quote($shSefString) . " ORDER BY rank ASC"; $database->setQuery($sql); $dbUrlList = $database->shlLoadObjectList(); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); $dbUrlList = array(); } if (count($dbUrlList) > 0) { $dburl = $dbUrlList[0]->newurl; $newMaxRank = $dbUrlList[count($dbUrlList) - 1]->rank + 1; $urlType = $dbUrlList[0]->dateadd == '0000-00-00' ? sh404SEF_URLTYPE_AUTO : sh404SEF_URLTYPE_CUSTOM; } } if ($urlType != sh404SEF_URLTYPE_NONE && $dburl != $string) { $shDuplicate = true; } $urlType = $urlType == sh404SEF_URLTYPE_NONE ? sh404SEF_URLTYPE_AUTO : $urlType; ShlSystem_Log::debug('sh404sef', 'Adding from sef_ext to DB : ' . $shSefString . ' | rank = ' . ($shDuplicate ? $newMaxRank : 0)); shAddSefUrlToDBAndCache($string, $shSefString, $shDuplicate ? $newMaxRank : 0, $urlType); } } else { $string = JString::trim($string, "&?"); // V 1.2.4.q a trial in better handling homepage articles // disabled in J! 1.6. Becomes too complex with multi-language // TODO: remove guessItemidOnHomepage setting if (false && shIsCurrentPageHome() && $option == 'com_content' && isset($task) && $task == 'view' && $sefConfig->guessItemidOnHomepage) { $string = preg_replace('/(&|\\?)Itemid=[^&]*/iu', '', $string); // we remove Itemid, as com_content plugin $Itemid = null; // will hopefully do a better job at finding the right one unset($URI->querystring['Itemid']); unset($shGETVars['Itemid']); } require_once sh404SEF_FRONT_ABS_PATH . 'sef_ext.php'; $sef_ext = new sef_404(); // Rewrite the URL now. // V 1.2.4.s added original string // a special case : com_content does not calculate pagination right // for frontpage and blog, they include links shown at the bottom in the calculation of number of items // For instance, with joomla sample data, the frontpage has only 5 articles // but the view sets $limit to 9 !!! if ($option == 'com_content' && isset($layout) && $layout == 'blog' || $option == 'com_content' && isset($view) && $view == 'featured') { $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true); $string = shSetURLVar($string, 'limit', $listLimit); $string = shSortUrl($string); //$URI->addQueryString( 'limit', $listLimit); } $sefstring = $sef_ext->create($string, $URI->querystring, $shAppendString, $shLanguage, $shOrigString, $originalUri); ShlSystem_Log::debug('sh404sef', 'Created sef url from default plugin: ' . $sefstring); } } } // end of cache check shumisha if (isset($sef_ext)) { unset($sef_ext); } // if string has not been modified, then we have decided for a non-sef if ($string == $sefstring) { // J! 1.6 kill all query vars $shGETVars = array(); $uri->setQuery(array()); } else { // include rewrite mode bit $shRewriteBit = $shComponentType == Sh404sefClassBaseextplugin::TYPE_SKIP ? '/' : $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode]; if (strpos($sefstring, 'index.php') === 0) { $shRewriteBit = '/'; } // V 1.2.4.t bug #119 $string = $pageInfo->getDefaultFrontLiveSite() . $shRewriteBit . JString::ltrim($sefstring, '/') . ($URI->anchor ? "#" . $URI->anchor : ''); } } else { // V x 03/09/2007 13:47:37 editing content $shComponentType = Sh404sefClassBaseextplugin::TYPE_SKIP; // will prevent turning & into & ShlSystem_Log::debug('sh404sef', 'shSefrelfToAbs: option not set, skipping'); } $ret = $string; // $ret = str_replace('itemid', 'Itemid', $ret); // V 1.2.4.t bug #125 ShlSystem_Log::debug('sh404sef', '(1) Setting shSefRelToAbs return string as: ' . $ret); } if (!isset($ret)) { $ret = $string; ShlSystem_Log::debug('sh404sef', '(2) Setting shSefRelToAbs return string as: ' . $ret); } $ret = $shComponentType == Sh404sefClassBaseextplugin::TYPE_DEFAULT ? shFinalizeURL($ret) : $ret; // V w 27/08/2007 13:21:28 ShlSystem_Log::debug('sh404sef', '(3) shSefRelToAbs return string after shFinalize: ' . $ret); if (empty($uri) || $shComponentType == Sh404sefClassBaseextplugin::TYPE_SKIP) { // we don't have a uri : we must be doing a redirect from non-sef to sef or similar $ret .= $shAppendString; // append directly to url ShlSystem_Log::debug('sh404sef', '(4) shSefRelToAbs return string after appendString: ' . $ret); } else { if (empty($sefstring) || !empty($sefstring) && strpos($sefstring, 'index.php') !== 0) { shRebuildVars($shAppendString, $uri); // instead, add to uri. Joomla will put everything together. Only do this if we have a sef url, and not if we have a non-sef ShlSystem_Log::debug('sh404sef', '(5) shSefRelToAbs no sefstring, adding rebuild vars : ' . $shAppendString); } } $pageInfo->currentLanguageTag = $shOrigLang; ShlSystem_Log::debug('sh404sef', 'shSefRelToAbs: finally returning: ' . $ret); return $ret; }
/** * Finds the sef url record to which an * alias record, identified by its id, * elongs to * * @param integer $aliasId */ public function getUrlByAliasId($aliasId) { $aliasId = empty($aliasId) ? 0 : intval($aliasId); $query = 'select r.* from ' . $this->_db->quoteName('#__sh404sef_urls') . ' as r' . ' left join ' . $this->_db->quoteName('#__sh404sef_aliases') . ' as a' . ' on a.' . $this->_db->quoteName('newurl') . ' = r.' . $this->_db->quoteName('newurl') . ' where a.' . $this->_db->quoteName('id') . ' = ' . $this->_db->Quote($aliasId) . ' order by ' . $this->_db->quoteName('rank'); try { $this->_db->setQuery($query); $url = $this->_db->shlLoadObject(); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); $this->setError('Internal database error # ' . $e->getMessage()); } return $url; }
public function loadHomepages() { $app = JFactory::getApplication(); if ($app->isAdmin()) { return; } // store default links in each language jimport('joomla.language.helper'); $languages = JLanguageHelper::getLanguages(); $this->isMultilingual = shIsMultilingual(); $defaultLanguage = shGetDefaultLang(); if ($this->isMultilingual === false || $this->isMultilingual == 'joomla') { $menu = JFactory::getApplication()->getMenu(); foreach ($languages as $language) { $menuItem = $menu->getDefault($language->lang_code); if (!empty($menuItem)) { $this->homeLinks[$language->lang_code] = $this->_prepareLink($menuItem); if ($language->lang_code == $defaultLanguage) { $this->homeLink = $this->homeLinks[$language->lang_code]; $this->homeItemid = $menuItem->id; } } } // find about the "All" languages home link $menuItem = $menu->getDefault('*'); if (!empty($menuItem)) { $this->allLangHomeLink = $this->_prepareLink($menuItem); } } else { // trouble starts $db = ShlDbHelper::getDb(); $query = $db->getQuery(true); $query->select('id,language,link'); $query->from('#__menu'); $query->where('home <> 0'); try { $db->setQuery($query); $items = $db->shlloadObjectList('language'); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } if (!empty($items)) { if (count($items) == 1) { $tmp = array_values($items); $defaultItem = $tmp[0]; } if (empty($defaultItem)) { $defaultItem = empty($items[$defaultLanguage]) ? null : $items[$defaultLanguage]; } if (empty($defaultItem)) { $defaultItem = empty($items['*']) ? null : $items['*']; } foreach ($languages as $language) { if (!empty($items[$language->lang_code])) { $this->homeLinks[$language->lang_code] = $this->_prepareLink($items[$language->lang_code]); } else { // no menu item for home link // let's try to build one $this->homeLinks[$language->lang_code] = $this->_prepareLink($defaultItem, shGetIsoCodeFromName($language->lang_code)); } if ($language->lang_code == $defaultLanguage) { $this->homeLink = $this->homeLinks[$language->lang_code]; $this->homeItemid = $defaultItem->id; $this->allLangHomeLink = shCleanUpLang($this->homeLinks[$language->lang_code]); } } } } ShlSystem_Log::debug('sh404sef', 'HomeLinks = %s', print_r($this->homeLinks, true)); }
function shDoTitleTags(&$buffer) { // Replace TITLE and DESCRIPTION and KEYWORDS if (empty($buffer)) { return; } global $shCustomTitleTag, $shCustomDescriptionTag, $shCustomKeywordsTag, $shCustomRobotsTag, $shCustomLangTag, $shCanonicalTag; $database = ShlDbHelper::getDb(); $shPageInfo =& Sh404sefFactory::getPageInfo(); $sefConfig =& Sh404sefFactory::getConfig(); $document = JFactory::getDocument(); $headData = $document->getHeadData(); // V 1.2.4.t protect against error if using shCustomtags without sh404SEF activated // this should not happen, so we simply do nothing if (!isset($sefConfig) || empty($shPageInfo->currentNonSefUrl)) { return; } // check if there is a manually created set of tags from tags file // need to get them from DB if ($sefConfig->shMetaManagementActivated) { shIncludeMetaPlugin(); // is this homepage ? set flag for future use // V 1.2.4.t make sure we have lang info and properly sorted params if (!preg_match('/(&|\\?)lang=[a-zA-Z]{2,3}/iuU', $shPageInfo->currentNonSefUrl)) { // no lang string, let's add default $shTemp = explode('-', $shPageInfo->currentLanguageTag); $shLangTemp = $shTemp[0] ? $shTemp[0] : 'en'; $shPageInfo->currentNonSefUrl .= '&lang=' . $shLangTemp; } $nonSef = shGetCurrentNonSef(); $isHome = $nonSef == shSortUrl(shCleanUpAnchor(Sh404sefFactory::getPageInfo()->homeLink)); $shCustomTags = shGetCustomMetaData($isHome ? sh404SEF_HOMEPAGE_CODE : $nonSef); // J! 2.5 finder canonical handling/hack $highlight = shGetURLVar($nonSef, 'highlight', null); if (!empty($highlight) && empty($shCanonicalTag)) { $searchCanoNonSef = str_replace('?highlight=' . $highlight, '', $nonSef); $searchCanoNonSef = str_replace('&highlight=' . $highlight, '', $searchCanoNonSef); $shCanonicalTag = JRoute::_($searchCanoNonSef); } $tagsToInsert = ''; // group new tags insertion, better perf if (!empty($shCustomTags)) { $shCustomTitleTag = !empty($shCustomTags->metatitle) ? $shCustomTags->metatitle : $shCustomTitleTag; $shCustomDescriptionTag = !empty($shCustomTags->metadesc) ? $shCustomTags->metadesc : $shCustomDescriptionTag; $shCustomKeywordsTag = !empty($shCustomTags->metakey) ? $shCustomTags->metakey : $shCustomKeywordsTag; $shCustomRobotsTag = !empty($shCustomTags->metarobots) ? $shCustomTags->metarobots : $shCustomRobotsTag; $shCustomLangTag = !empty($shCustomTags->metalang) ? $shCustomTags->metalang : $shCustomLangTag; $shCanonicalTag = !empty($shCustomTags->canonical) ? $shCustomTags->canonical : $shCanonicalTag; } // then insert them in page if (empty($shCustomTitleTag)) { $shCustomTitleTag = $document->getTitle(); } if (!empty($shCustomTitleTag)) { $prepend = $isHome ? '' : $sefConfig->prependToPageTitle; $append = $isHome ? '' : $sefConfig->appendToPageTitle; $shPageInfo->pageTitle = htmlspecialchars(shCleanUpTitle($prepend . $shCustomTitleTag . $append), ENT_COMPAT, 'UTF-8'); $buffer = ShlSystem_Strings::pr('/\\<\\s*title\\s*\\>.*\\<\\s*\\/title\\s*\\>/isuU', '<title>' . $shPageInfo->pageTitle . '</title>', $buffer); $buffer = ShlSystem_Strings::pr('/\\<\\s*meta\\s+name\\s*=\\s*"title.*\\/\\>/isuU', '', $buffer); // remove any title meta } if (!is_null($shCustomDescriptionTag)) { $t = htmlspecialchars(shCleanUpDesc($shCustomDescriptionTag), ENT_COMPAT, 'UTF-8'); $shPageInfo->pageDescription = ShlSystem_Strings::pr('#\\$([0-9]*)#u', '\\\\$${1}', $t); if (strpos($buffer, '<meta name="description" content=') !== false) { $buffer = ShlSystem_Strings::pr('/\\<\\s*meta\\s+name\\s*=\\s*"description.*\\/\\>/isUu', '<meta name="description" content="' . $shPageInfo->pageDescription . '" />', $buffer); } else { $tagsToInsert .= "\n" . '<meta name="description" content="' . $shPageInfo->pageDescription . '" />'; } } else { // read Joomla! description if none set by us if (empty($shPageInfo->pageDescription)) { $shPageInfo->pageDescription = empty($headData['description']) ? '' : htmlspecialchars(shCleanUpDesc($headData['description']), ENT_COMPAT, 'UTF-8'); } } if (!is_null($shCustomKeywordsTag)) { $t = htmlspecialchars(shCleanUpDesc($shCustomKeywordsTag), ENT_COMPAT, 'UTF-8'); $shPageInfo->pageKeywords = ShlSystem_Strings::pr('#\\$([0-9]*)#u', '\\\\$${1}', $t); if (strpos($buffer, '<meta name="keywords" content=') !== false) { $buffer = ShlSystem_Strings::pr('/\\<\\s*meta\\s+name\\s*=\\s*"keywords.*\\/\\>/isUu', '<meta name="keywords" content="' . $shPageInfo->pageKeywords . '" />', $buffer); } else { $tagsToInsert .= "\n" . '<meta name="keywords" content="' . $shPageInfo->pageKeywords . '" />'; } } else { // read Joomla! description if none set by us if (empty($shPageInfo->pageKeywords)) { $shPageInfo->pageKeywords = empty($headData['metaTags']['standard']['keywords']) ? '' : htmlspecialchars(shCleanUpDesc($headData['metaTags']['standard']['keywords']), ENT_COMPAT, 'UTF-8'); } } if (!is_null($shCustomRobotsTag)) { $shPageInfo->pageRobotsTag = $shCustomRobotsTag; if (strpos($buffer, '<meta name="robots" content="') !== false) { $buffer = ShlSystem_Strings::pr('/\\<\\s*meta\\s+name\\s*=\\s*"robots.*\\/\\>/isUu', '<meta name="robots" content="' . $shCustomRobotsTag . '" />', $buffer); } else { if (!empty($shCustomRobotsTag)) { $tagsToInsert .= "\n" . '<meta name="robots" content="' . $shCustomRobotsTag . '" />'; } } } else { // read Joomla! description if none set by us if (empty($shPageInfo->pageRobotsTag)) { $shPageInfo->pageRobotsTag = empty($headData['metaTags']['standard']['robots']) ? '' : htmlspecialchars(shCleanUpDesc($headData['metaTags']['standard']['robots']), ENT_COMPAT, 'UTF-8'); } } if (!is_null($shCustomLangTag)) { $shLang = $shCustomLangTag; $shPageInfo->pageLangTag = $shCustomLangTag; if (strpos($buffer, '<meta http-equiv="Content-Language"') !== false) { $buffer = ShlSystem_Strings::pr('/\\<\\s*meta\\s+http-equiv\\s*=\\s*"Content-Language".*\\/\\>/isUu', '<meta http-equiv="Content-Language" content="' . $shCustomLangTag . '" />', $buffer); } else { $tagsToInsert .= "\n" . '<meta http-equiv="Content-Language" content="' . $shCustomLangTag . '" />'; } } // custom handling of canonical $canonicalPattern = '/\\<\\s*link[^>]+rel\\s*=\\s*"canonical[^>]+\\/\\>/isUu'; $matches = array(); $canonicalCount = preg_match_all($canonicalPattern, $buffer, $matches); // more than one canonical already: kill them all if ($canonicalCount > 1 && Sh404sefFactory::getConfig()->removeOtherCanonicals) { $buffer = ShlSystem_Strings::pr($canonicalPattern, '', $buffer); $canonicalCount = 0; } // more than one and J3: must be the one inserted by J3 SEF plugin if ($canonicalCount > 0 && Sh404sefFactory::getConfig()->removeOtherCanonicals && version_compare(JVERSION, '3.0', 'ge')) { // kill it, if asked to $buffer = ShlSystem_Strings::pr($canonicalPattern, '', $buffer); $canonicalCount = 0; } // if there' a custom canonical for that page, insert it, or replace any existing ones if (!empty($shCanonicalTag) && $canonicalCount == 0) { // insert a new canonical $tagsToInsert .= "\n" . '<link href="' . htmlspecialchars($shCanonicalTag, ENT_COMPAT, 'UTF-8') . '" rel="canonical" />' . "\n"; } else { if (!empty($shCanonicalTag)) { // replace existing canonical $buffer = ShlSystem_Strings::pr($canonicalPattern, '<link href="' . htmlspecialchars($shCanonicalTag, ENT_COMPAT, 'UTF-8') . '" rel="canonical" />', $buffer); } } // insert all tags in one go if (!empty($tagsToInsert)) { $buffer = shInsertCustomTagInBuffer($buffer, '<head>', 'after', $tagsToInsert, 'first'); } // remove Generator tag if ($sefConfig->shRemoveGeneratorTag) { $buffer = ShlSystem_Strings::pr('/<meta\\s*name="generator"\\s*content=".*\\/>/isUu', '', $buffer); } // put <h1> tags around content elements titles if ($sefConfig->shPutH1Tags) { if (strpos($buffer, 'class="componentheading') !== false) { $buffer = ShlSystem_Strings::pr('/<div class="componentheading([^>]*)>\\s*(.*)\\s*<\\/div>/isUu', '<div class="componentheading$1><h1>$2</h1></div>', $buffer); $buffer = ShlSystem_Strings::pr('/<td class="contentheading([^>]*)>\\s*(.*)\\s*<\\/td>/isUu', '<td class="contentheading$1><h2>$2</h2></td>', $buffer); } else { // replace contentheading by h1 $buffer = ShlSystem_Strings::pr('/<td class="contentheading([^>]*)>\\s*(.*)\\s*<\\/td>/isUu', '<td class="contentheading$1><h1>$2</h1></td>', $buffer); } } // version x : if multiple h1 headings, replace them by h2 if ($sefConfig->shMultipleH1ToH2 && substr_count(JString::strtolower($buffer), '<h1>') > 1) { $buffer = str_replace('<h1>', '<h2>', $buffer); $buffer = str_replace('<H1>', '<h2>', $buffer); $buffer = str_replace('</h1>', '</h2>', $buffer); $buffer = str_replace('</H1>', '</h2>', $buffer); } // V 1.3.1 : replace outbounds links by internal redirects if (sh404SEF_REDIRECT_OUTBOUND_LINKS) { $tmp = preg_replace_callback('/<\\s*a\\s*href\\s*=\\s*"(.*)"/isUu', 'shDoRedirectOutboundLinksCallback', $buffer); if (empty($tmp)) { ShlSystem_Log::error('shlib', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, 'RegExp failed: invalid character on page ' . Sh404sefFactory::getPageInfo()->currentSefUrl); } else { $buffer = $tmp; } } // V 1.3.1 : add symbol to outbounds links if ($sefConfig->shInsertOutboundLinksImage) { $tmp = preg_replace_callback("/<\\s*a\\s*href\\s*=\\s*(\"|').*(\"|')\\s*>.*<\\/a>/isUu", 'shDoInsertOutboundLinksImageCallback', $buffer); if (empty($tmp)) { ShlSystem_Log::error('shlib', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, 'RegExp failed: invalid character on page ' . Sh404sefFactory::getPageInfo()->currentSefUrl); } else { $buffer = $tmp; } } // fix homepage link when using Joomfish in non default languages, error in joomla mainmenu helper /* if (sh404SEF_PROTECT_AGAINST_BAD_NON_DEFAULT_LANGUAGE_MENU_HOMELINK && !shIsDefaultLang( $shPageInfo->currentLanguageTag)) { $badHomeLink = preg_quote(JURI::base()); $targetLang = explode( '-', $shPageInfo->currentLanguageTag); $goodHomeLink = rtrim(JURI::base(), '/') . $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode] . $targetLang[0] . '/'; $buffer = preg_replace( '#<div class="module_menu(.*)href="' . $badHomeLink . '"#isU', '<div class="module_menu$1href="' . $goodHomeLink . '"', $buffer); $buffer = preg_replace( '#<div class="moduletable_menu(.*)href="' . $badHomeLink . '"#isU', '<div class="moduletable_menu$1href="' . $goodHomeLink . '"', $buffer); } */ // all done return $buffer; } }
/** * Save an url to the database, updating various elements * at the same time like ranking of duplicates * * @param integer $type force url type, used when saving a custom url */ private function _saveUrl($type = sh404SEF_URLTYPE_AUTO) { // check for homepage handling if (!empty($this->_data['newurl']) && ($this->_data['newurl'] == '/' || $this->_data['newurl'] == sh404SEF_HOMEPAGE_CODE)) { $this->_saveHomeUrl(); return sh404SEF_HOMEPAGE_CODE; } // check for importing urls : if importing, rank will already be set in // incoming data. If saving a url from the UI, rank is never set // as it is caculated upon saving the url $importing = isset($this->_data['rank']); // get required tools jimport('joomla.database.table'); $row = JTable::getInstance($this->_defaultTable, 'Sh404sefTable'); try { // now bind incoming data to table row if (!$row->bind($this->_data)) { $this->setError($row->getError()); return 0; } // pre-save checks if (!$row->check()) { $this->setError($row->getError()); return 0; } // must load cache from disk, so that it can be written back later, with new url require_once JPATH_ROOT . '/components/com_sh404sef/shCache.php'; shLoadURLCache(); // find if we are adding a custom or automatic url $urlType = $row->dateadd == '0000-00-00' ? sh404SEF_URLTYPE_AUTO : sh404SEF_URLTYPE_CUSTOM; // override with user supplied if (!empty($type)) { $urlType = $type; } // adjust date added field if needed if ($urlType == sh404SEF_URLTYPE_CUSTOM) { $row->dateadd = date("Y-m-d"); } // if custom url, and no language string, let's add default one if ($urlType == sh404SEF_URLTYPE_CUSTOM && !preg_match('/(&|\\?)lang=[a-zA-Z]{2,3}/iUu', $row->newurl)) { $shTemp = explode('-', shGetDefaultLang()); $shLangTemp = $shTemp[0] ? $shTemp[0] : 'en'; $row->newurl .= '&lang=' . $shLangTemp; } // normalize the non-sef url representation, sorting query parts alphabetically $row->newurl = shSortUrl($row->newurl); // retrieve previous values of sef and non sef urls $previousSefUrl = JRequest::getVar('previousSefUrl', null, 'POST'); $previousNonSefUrl = JRequest::getVar('previousNonSefUrl', null, 'POST'); // if both were set, and nothing has changed, then nothing to do if (!empty($previousSefUrl) && !empty($previousNonSefUrl) && $previousNonSefUrl == $row->newurl && $previousSefUrl == $row->oldurl) { // nothing changed ! must be changing meta or aliases $this->_url = $row; return $row->id; } // search DB for urls pairs with same SEF url $query = 'SELECT * FROM #__sh404sef_urls WHERE binary oldurl = ' . $this->_db->Quote($row->oldurl) . ' ORDER BY rank ASC'; $this->_db->setQuery($query); $dbUrlList = $this->_db->shlLoadObjectList(); // do we have urls in the db with same SEF ? if (count($dbUrlList) > 0) { // yes we do // get config object $sefConfig = Sh404sefFactory::getConfig(); if (!$sefConfig->shRecordDuplicates) { // we don't allow duplicates : reject this URL $this->setError(JText::_('COM_SH404SEF_DUPLICATE_NOT_ALLOWED')); } else { // same SEF, but we allow duplicates $existingRecord = null; // importing meta data for instance foreach ($dbUrlList as $urlInDB) { // same SEF, but is the incoming non-sef in this list of URl with same SEF ? if ($urlInDB->newurl == $row->newurl) { $existingRecord = $urlInDB; $this->setError(JText::_('COM_SH404SEF_URLEXIST')); } } if (empty($existingRecord)) { // this new non-sef does not already exists $shTemp = array('nonSefURL' => $row->newurl); // which means we must update the record for the old non-sef url Sh404sefHelperCache::removeURLFromCache($shTemp); // remove the old url from cache // then find new rank (as we are adding a duplicate, we add it at the end of the duplicate list) // but only if not importing. When importing, rank is already set if (!$importing) { $row->rank = $dbUrlList[count($dbUrlList) - 1]->rank + 1; } // store will create a new record if id=0, or update existing if id non 0 $row->store(); // put custom URL in DB and cache Sh404sefHelperCache::addSefUrlToCache($row->newurl, $row->oldurl, $urlType); // we must add the previous SEF url to the alias list, only if // - not already there // - this sef url does not already exists in the DB; which will happen if the url // being saved was customized and also had duplicates // TODO this code is duplicated just a few line below, need refactoring if (!empty($previousSefUrl) && strpos($this->_data['shAliasList'], $previousSefUrl) === false) { // check if not already a valid SEF url in the DB $query = 'SELECT count(id) FROM #__sh404sef_urls WHERE binary oldurl = ' . $this->_db->Quote($previousSefUrl); $this->_db->setQuery($query); $isThere = $this->_db->shlLoadResult(); if (empty($isThere)) { $this->_data['shAliasList'] .= $previousSefUrl . "\n"; } } } else { // there is already a record with both this sef and non sef. // just do nothing but return success (ie: record id). // Later, controller may store new aliases or metas // This should never happen when saving regular data as we added // a check for this case earlier // May happen when importing though $this->_url = $row; return $row->id; } // additional step : if we are here, it may be because we have modified // an existing url, and specifically changed it sef value to something else // Now it may be that this record was the one with rank = 0 in a series // of duplicate urls. If so, the urls which was ranked above must now become // the main url, having rank = 0 // note : when importing, we don't enter this test as previousSefUrl is empty // TODO this code is duplicated just a few line below, need refactoring if (!empty($previousSefUrl) && $previousSefUrl != $row->newurl) { // search for the old #2 record in duplicate list $query = 'SELECT id FROM #__sh404sef_urls WHERE binary oldurl = ' . $this->_db->Quote($previousSefUrl) . ' ORDER BY rank ASC'; $this->_db->setQuery($query); $previousRanked2 = $this->_db->shlLoadObject(); // there was more than one duplicate in the same series, promote #2 to top spot if (!empty($previousRanked2)) { $query = 'UPDATE #__sh404sef_urls SET rank="0" WHERE id = ' . $this->_db->Quote($previousRanked2->id); $this->_db->setQuery($query); $this->_db->shlQuery(); } } } } else { // there is no URL with same SEF URL, we are customizing an existing SEF url $shTemp = array('nonSefURL' => $row->newurl); Sh404sefHelperCache::removeURLFromCache($shTemp); // remove it from cache // simply store URL. If there is already one with same non-sef, this will raise an error in store() // as we don't allow creating a custom url for an already existing non-sef. User should // directly edit the existing non-sef/sef pair if (!$row->check()) { $this->setError($row->getError()); return 0; } if (!$row->store()) { $this->setError($row->getError()); return 0; } // add also to cache if saved to db Sh404sefHelperCache::addSefUrlToCache($row->newurl, $row->oldurl, $urlType); // we must add the previous SEF url to the alias list, only if // - not already there // - this sef url does not already exists in the DB; which will happen if the url // begin saved was customized and also had duplicates // note : when importing, we don't enter this test as previousSefUrl is empty // TODO this code is duplicated just a few line above, need refactoring if (!empty($previousSefUrl) && strpos($this->_data['shAliasList'], $previousSefUrl) === false) { // check if not already a valid SEF url in the DB $query = 'SELECT count(id) FROM #__sh404sef_urls WHERE binary oldurl = ' . $this->_db->Quote($previousSefUrl); $this->_db->setQuery($query); $isThere = $this->_db->shlLoadResult(); if (empty($isThere)) { $this->_data['shAliasList'] .= $previousSefUrl . "\n"; } } // finally, also check db for urls with same sef as previous SEF if any. We need // to search for the first duplicate of this old sef, and set it to be // the new main url // note : when importing, we don't enter this test as previousSefUrl is empty // TODO this code is duplicated just a few line above, need refactoring if (!empty($previousSefUrl) && $previousSefUrl != $row->newurl) { // search for the old #2 record in duplicate list $query = 'SELECT id FROM #__sh404sef_urls WHERE binary oldurl = ' . $this->_db->Quote($previousSefUrl) . ' ORDER BY rank ASC'; $this->_db->setQuery($query); $previousRanked2 = $this->_db->shlLoadObject(); // there was more than one duplicate in the same series, promote #2 to top spot if (!empty($previousRanked2)) { ShlDbHelper::update('#__sh404sef_urls', array('rank' => 0), array('id' => $previousRanked2->id)); } } } // store saved url object $this->_url = $row; // return what should be a non-zero id return $this->_url->id; } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); $this->setError($e->getMessage()); return 0; } }
/** * Purge meta data records from the database * either all of them or the currently selected set * as per user filter settings in meta manager * * @param string $type either 'all' or 'selected' */ public function purgeMetas($type) { // make sure we use latest user state $this->_updateContextData(); // call the appropriate sub-method to get the db query $methodName = '_getPurgeQuery' . ucfirst($type); if (is_callable(array($this, $methodName))) { $deleteQuery = $this->{$methodName}(); } else { $this->setError('Invalid method call _purge ' . $type); return; } // then run the query if (!empty($deleteQuery)) { try { $this->_db->setQuery($deleteQuery); $this->_db->shlQuery(); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); $this->setError('Internal database error ' . $e->getMessage()); } // reset limit and limitstart variables, to avoid // issue when displaying again results $this->_setState('limitstart', 0); $this->_setState('limit', 0); } else { $this->setError(JText::_('COM_SH404SEF_NORECORDS')); } }
/** * Create or update a record to * DB from POST data or input array of data * * @param array $dataArray an array holding data to save. If empty, $_POST is used * @return integer id of created or updated record */ public function save($dataArray = null) { // get required tools jimport('joomla.database.table'); $this->_data = JTable::getInstance($this->_defaultTable, 'Sh404sefTable'); $post = is_null($dataArray) ? JRequest::get('post') : $dataArray; // use table save method try { $status = $this->_data->save($post); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); $this->_data->setError($e->getMessage()); $status = false; } // report error if (!$status) { JFactory::getApplication()->enqueuemessage($this->_data->getError()); return 0; } // if success, fetch last insert id and return that $tableDb = $this->_data->getDBO(); $keyName = $this->_data->getKeyName(); $id = empty($post[$keyName]) ? 0 : intval($post[$keyName]); $savedId = empty($id) ? $tableDb->insertid() : $id; return $savedId; }
/** * Push current error documents content * values into the view for edition * this is a altered version of the same * method in the old config view. */ private function _getErrorPageContent() { // find about sh404sef custom content category id $sh404sefContentCatId = Sh404sefHelperCategories::getSh404sefContentCat()->id; try { // read current content of 404 page in default language $article = ShlDbHelper::selectAssoc('#__content', array('id', 'introtext'), array('title' => '__404__', 'catid' => $sh404sefContentCatId, 'language' => '*')); $txt404 = empty($article['introtext']) ? JText::_('COM_SH404SEF_DEF_404_MSG') : $article['introtext']; } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); $txt404 = JText::_('COM_SH404SEF_DEF_404_MSG'); } // push params in to view return $txt404; }
function shKUTopicName($topicid, $option, $shLangIso, $shLangName) { static $topics = array(); $sefConfig =& Sh404sefFactory::getConfig(); if (empty($topicid) || !$sefConfig->shFbInsertMessageSubject) { return ''; } if (class_exists('KunenaForum')) { // Kunena 2.0 support $topic = KunenaForumTopic::getInstance($topicid); $topicsubject = $topic->subject; } elseif (class_exists('KunenaRouter')) { // Kunena 1.6 support if (empty(KunenaRouter::$msgidcache[$topicid])) { try { KunenaRouter::$msgidcache[$topicid] = ShlDbHelper::selectResult('#__kunena_messages', array('subject', 'id'), array('id' => $topicid)); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } } $topicsubject = KunenaRouter::$msgidcache[$topicid]; } else { // Kunena 1.0 / 1.5 support if (empty($topics[$topicid])) { try { $topicDetails = ShlDbHelper::selectObject('#__fb_messages', array('id', 'subject'), array('id' => $topicid)); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } $topics[$topicid] = empty($topicDetails) ? '' : $topicDetails->subject; } $topicsubject = $topics[$topicid]; } // we have a user name $topicstring = empty($topicsubject) ? 't' . $sefConfig->replacement . $topicid : ($sefConfig->shFbInsertMessageId ? $topicid . $sefConfig->replacement : ''); // if name, put ID only if requested $topicstring = $topicstring . (empty($topicsubject) ? '' : $topicsubject); return $topicstring; }
public function getUrlsCount($which = 'auto') { switch (strtolower($which)) { // we want to read all automatic urls (include duplicates) case 'auto': $numberOfUrls = ShlDbHelper::count($this->_getTableName(), '*', array('dateadd' => '0000-00-00')); break; // we want to read urls as per current selection input fields // ie : component, language, custom, ... // we want to read urls as per current selection input fields // ie : component, language, custom, ... case 'selected': $numberOfUrls = $this->getTotal(); break; case 'view404': case '404': $query = 'select count(*) from ' . $this->_db->quoteName($this->_getTableName()) . ' where ' . $this->_db->quoteName('dateadd') . '!=' . $this->_db->Quote('0000-00-00') . ' and ' . $this->_db->quoteName('newurl') . '=' . $this->_db->Quote(''); try { $this->_db->setQuery($query); $numberOfUrls = $this->_db->shlLoadResult(); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); $numberOfUrls = 0; } break; default: $numberOfUrls = 0; break; } return intval($numberOfUrls); }
/** * * @param string $url * @param array $title * @param string $task * @param int $limit * @param int $limitstart * @return sefurl */ public static function sefGetLocation($nonSefUrl, &$title, $task = null, $limit = null, $limitstart = null, $langParam = null, $showall = null, $suppressPagination = false) { try { $shPageInfo =& Sh404sefFactory::getPageInfo(); $sefConfig =& Sh404sefFactory::getConfig(); $lang = empty($langParam) ? $shPageInfo->currentLanguageTag : $langParam; // shumisha : try to avoid duplicate content on multilingual sites by always adding &lang=xx to url (stored in DB). // warning : must add &lang=xx only if it does not exists already if (!strpos($nonSefUrl, 'lang=')) { $shSepString = substr($nonSefUrl, -9) == 'index.php' ? '?' : '&'; $nonSefUrl .= $shSepString . 'lang=' . shGetIsoCodeFromName($lang); } // make sure url is consistent $nonSefUrl = str_replace('&', '&', $nonSefUrl); // detect multipage homepage $shMultiPageHomePageFlag = shIsHomepage($nonSefUrl); // get all the slugs ready for being urls bits $tempSefUrl = array(); foreach ($title as $titlestring) { $decodedTitletring = urldecode($titlestring); $tempSefUrl[] = titleToLocation($decodedTitletring); } // now build the URL $tempSefUrl = implode("/", $tempSefUrl); // remove duplicate / $tempSefUrl = ShlSystem_Strings::pr('/\\/{2,}/u', '/', $tempSefUrl); // and truncate to max length, according to param $tempSefUrl = JString::substr($tempSefUrl, 0, sh404SEF_MAX_SEF_URL_LENGTH); // trim to max length V 1.2.4.t // if URL is empty, and unless this is a paginated home page, or home page in non-default language, stop there if (empty($tempSefUrl)) { if ((!shIsMultilingual() || shIsMultilingual() && shIsDefaultlang($lang)) && !$sefConfig->addFile && !$shMultiPageHomePageFlag) { // return ''; } // if location is empty, and not multilingual site, or multilingual, but this is default language, then there is nothing to add to url } // we have a valid SEF url, built with the data ($title) sent // by plugin. Now we want to check if it's already in the db // and add it if not // first, we search the memory cache for the non-sef url // as it is faster than looking up the db $finalSefUrl = ''; $sefUrlType = Sh404sefHelperCache::getSefUrlFromCache($nonSefUrl, $finalSefUrl); // if non-sef was not found in cache - or found, but it was a 404 last time we saw it - // we should continue and try adding it if ($sefUrlType == sh404SEF_URLTYPE_NONE || $sefUrlType == sh404SEF_URLTYPE_404) { $finalSefUrl = false; // non-sef was not found in cache, let's look up the database if ($sefUrlType == sh404SEF_URLTYPE_NONE) { $finalSefUrl = ShlDbHelper::selectResult('#__sh404sef_urls', 'oldurl', array('newurl' => $nonSefUrl)); } // we found the sef url in database, we're done if (!empty($finalSefUrl)) { return $finalSefUrl; } // the non-sef url is not in memory cache, nor in database // that's a new one, we need to finalize its sef (add pagination and language information) // After finalizing it, we'll also check that sef is not in the db // as it can already be there, associated with another non-sef (ie: a duplicate) // Either way we'll add it in the db, but mark it as a duplicate if needed // add pagination information, unless we were instructed by extension plugin not to // find if we should separate pagination info from sef with a / or not if (!empty($tempSefUrl)) { $shSeparator = JString::substr($tempSefUrl, -1) == '/' ? '' : '/'; } else { $shSeparator = ''; } $finalSefUrl = $suppressPagination ? $tempSefUrl : shAddPaginationInfo($limit, $limitstart, $showall, 1, $nonSefUrl, $tempSefUrl, $shSeparator); // v 1.2.4.t // if home page, we don't record anything, just return "home page" if ($shMultiPageHomePageFlag && '/' . $finalSefUrl == $tempSefUrl && (!shIsMultilingual() || shIsMultilingual() && shIsDefaultLang($lang))) { // but this is default language // this is start page of multipage homepage, return home or forced home if (!empty($sefConfig->shForcedHomePage)) { return str_replace($shPageInfo->getDefaultFrontLiveSite() . '/', '', $sefConfig->shForcedHomePage); } else { return ''; } } // add language information // first, remove languages in non-sef, to see if we're on homepage // as handling is sligthly different for homepage $v1 = shCleanUpLang($nonSefUrl); $v2 = shCleanUpLang($shPageInfo->homeLink); if ($v1 == $v2 || $v1 == 'index.php') { // check if this is homepage if (shIsMultilingual() && !shIsDefaultLang($lang)) { // if homepage in not-default-language, then add language code regardless of user settings // as we otherwise would not be able to switch language on the frontpage $finalSefUrl = shGetIsoCodeFromName($lang) . '/'; } else { $finalSefUrl = ''; } } else { // not on homepage, insert lang code based on user setting $option = shGetURLVar($nonSefUrl, 'option', ''); if (shInsertIsoCodeInUrl($option, $lang)) { // insert language code based on param // pass URL lang info, as may not be current lang $finalSefUrl = shGetIsoCodeFromName($lang) . '/' . $finalSefUrl; // must be forced lang, not default } } // after adding pagination part of SEF, and adding language code // the new SEF url is now complete and we can try adding to it cache and db if ($finalSefUrl != '') { $dburl = null; $dbUrlId = null; $nonSefUrlType = sh404SEF_URLTYPE_NONE; // search the memory cache for this new sef if ($sefConfig->shUseURLCache) { $nonSefUrlType = Sh404sefHelperCache::getNonSefUrlFromCache($finalSefUrl, $dburl); } $newMaxRank = 0; // if the new SEF was not found in memory cache, or if it was found but // we're set to record duplicates, we search for it in the database if ($sefConfig->shRecordDuplicates || $nonSefUrlType == sh404SEF_URLTYPE_NONE) { $dbUrlList = ShlDbHelper::selectObjectList('#__sh404sef_urls', array('id', 'newurl', 'rank', 'dateadd'), array('oldurl' => $finalSefUrl), $aWhereData = array(), $orderBy = array('rank')); if (count($dbUrlList) > 0) { $dburl = $dbUrlList[0]->newurl; $dbUrlId = $dbUrlList[0]->id; if (empty($dburl)) { // V 1.2.4.t url was found in DB, but was a 404 $nonSefUrlType = sh404SEF_URLTYPE_404; } else { $newMaxRank = $dbUrlList[count($dbUrlList) - 1]->rank + 1; $nonSefUrlType = $dbUrlList[0]->dateadd == '0000-00-00' ? sh404SEF_URLTYPE_AUTO : sh404SEF_URLTYPE_CUSTOM; } } } if ($nonSefUrlType != sh404SEF_URLTYPE_NONE && $nonSefUrlType != sh404SEF_URLTYPE_404) { // we found the SEF, one or more times in the db, in records which do have a non-sef attached $isDuplicate = $dburl != $nonSefUrl; // This is a duplicate so we must indert it with incremented rank; if (is_null($dburl) || $isDuplicate && $sefConfig->shRecordDuplicates) { // shAddSefUrlToDBAndCache( $nonSefUrl, $finalSefUrl, ($isDuplicate ? $newMaxRank : 0), $nonSefUrlType); $dateAdd = $nonSefUrlType == sh404SEF_URLTYPE_AUTO ? '0000-00-00' : date("Y-m-d"); ShlDbHelper::insert('#__sh404sef_urls', array('oldurl' => $finalSefUrl, 'newurl' => $nonSefUrl, 'rank' => $isDuplicate ? $newMaxRank : 0, 'dateadd' => $dateAdd)); // store new sef/non-sef pair in memory cache Sh404sefHelperCache::addSefUrlToCache($nonSefUrl, $finalSefUrl, $nonSefUrlType); // create shURL : get a shURL model, and ask url creation $model = ShlMvcModel_Base::getInstance('pageids', 'Sh404sefModel'); $model->createPageId($finalSefUrl, $nonSefUrl); } } else { // we haven't found the non-sef/sef pair, but maybe there is a record for // a 404 with that SEF. If so, we will "upgrade" the 404 record to a // normal non-sef/sef pair $dbUrlId = empty($dbUrlId) ? 0 : intval($dbUrlId); if ($sefConfig->shLog404Errors) { if ($nonSefUrlType == sh404SEF_URLTYPE_404 && !empty($dbUrlId)) { // we already have seen that it is a 404 $id = $dbUrlId; } elseif ($nonSefUrlType == sh404SEF_URLTYPE_404) { $id = ShlDbHelper::selectResult('#__sh404sef_urls', 'id', array('oldurl' => $finalSefUrl, 'newurl' => '')); } else { $id = null; } } else { $id = null; // if we are not logging 404 errors, then no need to check for } // previous hit of this page. if (!empty($id)) { // we found a 404 record matching the SEF url just created. We'll update that record // instead of creating a new one // need to update dateadd to 0, as otherwise this sef/non-sef pair will be seen as custom // this makes all such 404 errors 'disappear' from the 404 log, but no other solution ShlDbHelper::updateIn('#__sh404sef_urls', array('newurl' => $nonSefUrl, 'dateadd' => '0000-00-00'), 'id', array($id)); Sh404sefHelperCache::addSefUrlToCache($nonSefUrl, $finalSefUrl, sh404SEF_URLTYPE_AUTO); } else { // standard case: creation of a totally new sef/non-sef pair ShlDbHelper::insert('#__sh404sef_urls', array('oldurl' => $finalSefUrl, 'newurl' => $nonSefUrl, 'rank' => 0, 'dateadd' => '0000-00-00')); // store new sef/non-sef pair in memory cache Sh404sefHelperCache::addSefUrlToCache($nonSefUrl, $finalSefUrl, sh404SEF_URLTYPE_AUTO); // create shURL : get a shURL model, and ask url creation $model = ShlMvcModel_Base::getInstance('pageids', 'Sh404sefModel'); $model->createPageId($finalSefUrl, $nonSefUrl); } } } } } catch (Exception $e) { $finalSefUrl = ''; ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } return $finalSefUrl; }
private function _prepareControlPanelData() { $sefConfig = Sh404sefFactory::getConfig(); $this->assign('sefConfig', $sefConfig); // update information $versionsInfo = Sh404sefHelperUpdates::getUpdatesInfos(); $this->assign('updates', $versionsInfo); // url databases stats $database = ShlDbHelper::getDb(); try { $sql = 'SELECT count(*) FROM #__sh404sef_urls WHERE '; $database->setQuery($sql . "`dateadd` > '0000-00-00' and `newurl` = '' "); // 404 $count404 = $database->shlLoadResult(); $database->setQuery($sql . "`dateadd` > '0000-00-00' and `newurl` != '' "); // custom $customCount = $database->shlLoadResult(); $database->setQuery($sql . "`dateadd` = '0000-00-00'"); // regular $sefCount = $database->shlLoadResult(); // calculate security stats $default = empty($sefConfig->shSecLastUpdated) ? '- -' : '0'; } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); $sefCount = 0; $count404 = 0; $customCount = 0; } $this->assign('sefCount', $sefCount); $this->assign('Count404', $count404); $this->assign('customCount', $customCount); }
/** * Creates a link to the shLib plugin page * @return string */ public static function getShLibPluginLink($xhtml = true) { try { $pluginId = ShlDbHelper::selectResult('#__extensions', array('extension_id'), array('type' => 'plugin', 'element' => 'shlib', 'folder' => 'system')); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', __CLASS__ . '/' . __METHOD__ . '/' . __LINE__ . ': ' . $e->getMessage()); } $link = ''; $pluginId = (int) $pluginId; if (!empty($pluginId)) { $link = 'index.php?option=com_plugins&task=plugin.edit&extension_id=' . $pluginId; } if ($xhtml) { $link = htmlspecialchars($link); } return $link; }
private function _getNextDBId($table) { if (empty($table)) { return false; } try { // need to force replace prefix $query = 'show table status like ' . $this->_db->Quote($table); $this->_db->setQuery($query); $status = $this->_db->shlLoadAssoc(); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } if (empty($status) || empty($status['Auto_increment'])) { return false; } else { return (int) $status['Auto_increment']; } }
case 'task2': $dosef = false; // these tasks do not require SEF URL break; default: $title[] = $sh_LANG[$shLangIso]['COM_SH404SEF_VIEW_SAMPLE']; // insert a 'View sample' string, // according to language // only if you have defined the if (!empty($sampleId)) { // fetch some data about the content try { // using shLib database helper is J2.x/J3.x safe $sampleTitle = ShlDbHelper::selectObject('#__sample_names', array('id', 'title'), array('id' => $sampleId)); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } if ($sampleTitle) { // if we found a title for this element $title[] = $sampleTitle->title; // insert it in URL array shRemoveFromGETVarsList('sampleId'); // remove sampleId var from GET vars list // as we have found a text equivalent shMustCreatePageId('set', true); // NEW: ask sh404sef to create a short URL for this SEF URL (pageId) } } shRemoveFromGETVarsList('task'); // also remove task, as it is not needed // because we can revert the SEF URL without
function shMTGetCustomFieldById($cfId) { static $fields = null; if (is_null($fields)) { try { $fields = ShlDbHelper::selectObjectList('#__mt_customfields', array('cf_id', 'caption'), $mWhere = '', $aWhereData = array(), $orderBy = array(), $offset = 0, $lines = 0, $key = 'cf_id'); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } } // check if we have this field $cfCaption = empty($fields[$cfId]) ? '' : $fields[$cfId]->caption; if (!empty($cfCaption)) { shRemoveFromGETVarsList('cf_id'); } return $cfCaption; }