Exemplo n.º 1
0
 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());
         }
     }
 }
Exemplo n.º 2
0
 public static function updateShurls()
 {
     $sefConfig =& shRouter::shGetConfig();
     // set the short link tag
     $shPageInfo =& shRouter::shPageInfo();
     $shPageInfo->shURL = '';
     if ($sefConfig->enablePageId && !$sefConfig->stopCreatingShurls) {
         try {
             jimport('joomla.utilities.string');
             $nonSefUrl = JString::ltrim($shPageInfo->shCurrentPageNonSef, '/');
             $nonSefUrl = shSortURL($nonSefUrl);
             // remove tracking vars (Google Analytics)
             $nonSefUrl = Sh404sefHelperGeneral::stripTrackingVarsFromNonSef($nonSefUrl);
             // try to get the current shURL, if any
             $shURL = Sh404sefHelperDb::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($GLOBALS['shConfigLiveSite'], '/') . '/' . $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
                 $shPageInfo->shURL = $shURL;
             }
         } catch (Sh404sefExceptionDefault $e) {
         }
     }
 }
Exemplo n.º 3
0
 function shGetCurrentNonSef()
 {
     // remove Google tracking vars, would prevent us to find the correct meta tags
     $nonSef = Sh404sefHelperGeneral::stripTrackingVarsFromNonSef(Sh404sefFactory::getPageInfo()->currentNonSefUrl);
     // normalize, set variables in alpha order
     return shSortUrl($nonSef);
 }
Exemplo n.º 4
0
         } else {
             $shMultPageLength = '';
         }
         if (!empty($sefConfig->pageTexts[$shPageInfo->currentLanguageTag]) && false !== strpos($sefConfig->pageTexts[$shPageInfo->currentLanguageTag], '%s')) {
             $pattern = str_replace($sefConfig->pagerep, ' ', $sefConfig->pageTexts[$shPageInfo->currentLanguageTag]);
             $title[] = str_replace('%s', $pagenum, $pattern) . $shMultPageLength;
         } else {
             $title[] = ' ' . $pagenum . $shMultPageLength;
         }
     }
     $shCustomTitleTag = JString::ltrim(implode(' | ', $title), '/ | ');
     break;
 default:
     // calculate canonical
     if ($view == 'article') {
         $nonSef = Sh404sefHelperGeneral::stripTrackingVarsFromNonSef($shPageInfo->currentNonSefUrl);
         $nonSef = str_replace(array('format=pdf', 'print=1'), '', $nonSef);
         $shCanonicalTag = JRoute::_($nonSef);
     }
     // use regular function to get content titles, as per out specific settings
     $customConfig = clone $sefConfig;
     $customConfig->includeContentCat = $sefConfig->contentTitleIncludeCat;
     $customConfig->UseAlias = $sefConfig->ContentTitleUseAlias;
     $customConfig->useCatAlias = $sefConfig->ContentTitleUseCatAlias;
     $customConfig->LowerCase = false;
     $customConfig->ContentTitleInsertArticleId = false;
     // V 1.2.4.t protect against sef_ext.php not being included
     if (!class_exists('sef_404')) {
         require_once sh404SEF_ABS_PATH . 'components/com_sh404sef/sef_ext.php';
     }
     $layout = isset($layout) ? $layout : null;
Exemplo n.º 5
0
         $q = 'SELECT id, title FROM #__sections WHERE id = ' . intval($sectionid);
         $database->setQuery($q);
         if (shTranslateUrl($option, $shLangName)) {
             // V 1.2.4.m
             $sectionTitle = $database->loadObject();
         } else {
             $sectionTitle = $database->loadObject(false);
         }
         if ($sectionTitle) {
             $title[] = $sectionTitle->title;
         }
     }
 }
 // calculate canonical
 if ($view == 'article' && !empty($print)) {
     $nonSef = Sh404sefHelperGeneral::stripTrackingVarsFromNonSef($shPageInfo->shCurrentPageNonSef);
     $nonSef = str_replace(array('format=pdf', 'print=1'), '', $nonSef);
     $shCanonicalTag = JRoute::_($nonSef);
 }
 // use regular function to get content titles, as per out specific settings
 $customConfig = clone $sefConfig;
 $customConfig->includeContentCat = $sefConfig->contentTitleIncludeCat;
 $customConfig->UseAlias = $sefConfig->ContentTitleUseAlias;
 $customConfig->useCatAlias = $sefConfig->ContentTitleUseCatAlias;
 $customConfig->LowerCase = false;
 $customConfig->ContentTitleInsertArticleId = false;
 // V 1.2.4.t protect against sef_ext.php not being included
 if (!class_exists('sef_404')) {
     require_once sh404SEF_ABS_PATH . 'components/com_sh404sef/sef_ext.php';
 }
 $layout = isset($layout) ? $layout : null;
Exemplo n.º 6
0
 function shDoTitleTags(&$buffer)
 {
     // Replace TITLE and DESCRIPTION and KEYWORDS
     if (empty($buffer)) {
         return;
     }
     global $shCustomTitleTag, $shCustomDescriptionTag, $shCustomKeywordsTag, $shCustomRobotsTag, $shCustomLangTag, $shHomeLink, $shMosConfig_lang, $shMosConfig_locale, $shCanonicalTag;
     $database =& JFactory::getDBO();
     $sefConfig =& shRouter::shGetConfig();
     $shPageInfo =& shRouter::shPageInfo();
     // get page details gathered by system plugin
     // 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->shCurrentPageNonSef)) {
         return;
     }
     // check if there is a manually created set of tags from tags file
     // need to get them from DB
     if ($sefConfig->shMetaManagementActivated) {
         //  plugin system to automatically build title and description tags on a component per component basis
         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}/iU', $shPageInfo->shCurrentPageNonSef)) {
             // no lang string, let's add default
             $shTemp = explode('-', $GLOBALS['shMosConfig_locale']);
             $shLangTemp = $shTemp[0] ? $shTemp[0] : 'en';
             $shPageInfo->shCurrentPageNonSef .= '&lang=' . $shLangTemp;
         }
         // remove Google tracking vars, would prevent us to find the correct meta tags
         $nonSef = Sh404sefHelperGeneral::stripTrackingVarsFromNonSef($shPageInfo->shCurrentPageNonSef);
         // normalize, set variables in alpha order
         $nonSef = shSortUrl($nonSef);
         $isHome = $nonSef == shSortUrl(shCleanUpAnchor($shHomeLink));
         // now read manually setup tags
         if ($isHome) {
             // V 1.2.4.t homepage custom tags
             $sql = 'SELECT id, metadesc, metakey, metatitle, metalang, metarobots FROM #__sh404SEF_meta WHERE newurl = \'' . sh404SEF_HOMEPAGE_CODE . '\'';
         } else {
             $sql = 'SELECT id, metadesc, metakey, metatitle, metalang, metarobots FROM #__sh404SEF_meta WHERE newurl = ' . $database->Quote(ltrim($nonSef, '/'));
         }
         $shCustomTags = null;
         $database->setQuery($sql);
         $shCustomTags = $database->loadObject();
         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;
         }
         // then insert them in page
         if (empty($shCustomTitleTag)) {
             $document =& JFactory::getDocument();
             $shCustomTitleTag = $document->getTitle();
         }
         if (!empty($shCustomTitleTag)) {
             $prepend = $isHome ? '' : $sefConfig->prependToPageTitle;
             $append = $isHome ? '' : $sefConfig->appendToPageTitle;
             $t = htmlspecialchars(shCleanUpTitle($prepend . $shCustomTitleTag . $append), ENT_COMPAT, 'UTF-8');
             $buffer = preg_replace('/\\<\\s*title\\s*\\>.*\\<\\s*\\/title\\s*\\>/isU', '<title>' . $t . '</title>', $buffer);
             $buffer = preg_replace('/\\<\\s*meta\\s+name\\s*=\\s*"title.*\\/\\>/isU', '', $buffer);
             // remove Joomla title meta
         }
         if (!is_null($shCustomDescriptionTag)) {
             $t = htmlspecialchars(shCleanUpDesc($shCustomDescriptionTag), ENT_COMPAT, 'UTF-8');
             $t = preg_replace('#\\$([0-9]*)#', '\\\\$${1}', $t);
             $buffer = preg_replace('/\\<\\s*meta\\s+name\\s*=\\s*"description.*\\/\\>/isU', '<meta name="description" content="' . $t . '" />', $buffer);
         }
         if (!is_null($shCustomKeywordsTag)) {
             $t = htmlspecialchars(shCleanUpDesc($shCustomKeywordsTag), ENT_COMPAT, 'UTF-8');
             $t = preg_replace('#\\$([0-9]*)#', '\\\\$${1}', $t);
             $buffer = preg_replace('/\\<\\s*meta\\s+name\\s*=\\s*"keywords.*\\/\\>/isU', '<meta name="keywords" content="' . $t . '" />', $buffer);
         }
         if (!is_null($shCustomRobotsTag)) {
             if (strpos($buffer, '<meta name="robots" content="') !== false) {
                 $buffer = preg_replace('/\\<\\s*meta\\s+name\\s*=\\s*"robots.*\\/\\>/isU', '<meta name="robots" content="' . $shCustomRobotsTag . '" />', $buffer);
             } else {
                 if (!empty($shCustomRobotsTag)) {
                     $buffer = shInsertCustomTagInBuffer($buffer, '</head>', 'before', '<meta name="robots" content="' . $shCustomRobotsTag . '" />', 'first');
                 }
             }
         }
         if (!is_null($shCustomLangTag)) {
             $shLang = $shCustomLangTag;
             if (strpos($buffer, '<meta http-equiv="Content-Language"') !== false) {
                 $buffer = preg_replace('/\\<\\s*meta\\s+http-equiv\\s*=\\s*"Content-Language".*\\/\\>/isU', '<meta http-equiv="Content-Language" content="' . $shCustomLangTag . '" />', $buffer);
             } else {
                 $buffer = shInsertCustomTagInBuffer($buffer, '</head>', 'before', '<meta http-equiv="Content-Language" content="' . $shCustomLangTag . '" />', 'first');
             }
         }
         if (!empty($shCanonicalTag)) {
             if (strpos($buffer, '<link rel="canonical" href="') !== false) {
                 $buffer = preg_replace('/\\<\\s*link\\s+rel\\s*=\\s*"canonical.*\\/\\>/isU', '<link rel="canonical" href="' . $shCanonicalTag . '" />', $buffer);
             } else {
                 if (!empty($shCanonicalTag)) {
                     $buffer = shInsertCustomTagInBuffer($buffer, '</head>', 'before', '<link rel="canonical" href="' . $shCanonicalTag . '" />', 'first');
                     print_r($buffer);
                     die;
                 }
             }
         }
         // remove Generator tag
         if ($sefConfig->shRemoveGeneratorTag) {
             $buffer = preg_replace('/<meta\\s*name="Generator"\\s*content=".*\\/>/isU', '', $buffer);
         }
         // version x : add title to read on link
         if ($sefConfig->shInsertReadMorePageTitle) {
             if (strpos($buffer, 'class="readon"') !== false) {
                 $buffer = preg_replace_callback('/<td class="contentheading" width="100%">(.*)class="readon">(.*)<\\/a>/isU', 'shDoLinkReadMoreCallback', $buffer);
             }
         }
         // put <h1> tags around content elements titles
         if ($sefConfig->shPutH1Tags) {
             if (strpos($buffer, 'class="componentheading') !== false) {
                 $buffer = preg_replace('/<div class="componentheading([^>]*)>\\s*(.*)\\s*<\\/div>/isU', '<div class="componentheading$1><h1>$2</h1></div>', $buffer);
                 $buffer = preg_replace('/<td class="contentheading([^>]*)>\\s*(.*)\\s*<\\/td>/isU', '<td class="contentheading$1><h2>$2</h2></td>', $buffer);
             } else {
                 // replace contentheading by h1
                 $buffer = preg_replace('/<td class="contentheading([^>]*)>\\s*(.*)\\s*<\\/td>/isU', '<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) {
             $buffer = preg_replace_callback('/<\\s*a\\s*href\\s*=\\s*"(.*)"/isU', 'shDoRedirectOutboundLinksCallback', $buffer);
         }
         // V 1.3.1 : add symbol to outbounds links
         if ($sefConfig->shInsertOutboundLinksImage) {
             $buffer = preg_replace_callback("/<\\s*a\\s*href\\s*=\\s*(\"|').*(\"|')\\s*>.*<\\/a>/isU", 'shDoInsertOutboundLinksImageCallback', $buffer);
         }
         // 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($shMosConfig_locale)) {
             $badHomeLink = preg_quote(JURI::base());
             $targetLang = explode('-', $shMosConfig_locale);
             $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;
     }
 }