function shDoTitleTags(&$buffer) { // Replace TITLE and DESCRIPTION and KEYWORDS if (empty($buffer)) { return; } global $shCustomTitleTag, $shCustomDescriptionTag, $shCustomKeywordsTag, $shCustomRobotsTag, $shCustomLangTag, $shHomeLink, $shMosConfig_lang, $shMosConfig_locale; $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; } // fix bug in Joomla search //$shUri = null; //$shOriginalUri = null; //$buffer = str_replace( 'action="index.php"', 'action="'.shSefRelToabs('index.php', '', $shUri, $shUri, $shOriginalUri).'"', $buffer); // 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 $option = JRequest::getVar('option'); $shDoNotOverride = in_array(str_replace('com_', '', $option), $sefConfig->shDoNotOverrideOwnSef); if (file_exists(sh404SEF_ABS_PATH . 'components/' . $option . '/meta_ext/' . $option . '.php') && ($shDoNotOverride || !$shDoNotOverride && !file_exists(sh404SEF_ABS_PATH . 'components/com_sh404sef/meta_ext/' . $option . '.php'))) { _log('Loading component own meta plugin'); // Load the plug-in file include sh404SEF_ABS_PATH . 'components/' . $option . '/meta_ext/' . $option . '.php'; } else { if (file_exists(sh404SEF_ABS_PATH . 'components/com_sh404sef/meta_ext/' . $option . '.php')) { _log('Loading built-in meta plugin'); include sh404SEF_ABS_PATH . 'components/com_sh404sef/meta_ext/' . $option . '.php'; } } // is this homepage ? set flag for future use $isHome = shSortUrl($shPageInfo->shCurrentPageNonSef) == 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 { // 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; } $shPageInfo->shCurrentPageNonSef = shSortUrl($shPageInfo->shCurrentPageNonSef); $sql = 'SELECT id, metadesc, metakey, metatitle, metalang, metarobots FROM #__sh404SEF_meta WHERE newurl = \'' . ltrim($shPageInfo->shCurrentPageNonSef, '/') . '\''; } $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; $buffer = preg_replace('/\\<\\s*title\\s*\\>.*\\<\\s*\\/title\\s*\\>/isU', '<title>' . shCleanUpTitle($prepend . $shCustomTitleTag . $append) . '</title>', $buffer); $buffer = preg_replace('/\\<\\s*meta\\s+name\\s*=\\s*"title.*\\/\\>/isU', '', $buffer); // remove Joomla title meta } if (!is_null($shCustomDescriptionTag)) { $buffer = preg_replace('/\\<\\s*meta\\s+name\\s*=\\s*"description.*\\/\\>/isU', '<meta name="description" content="' . shCleanUpDesc($shCustomDescriptionTag) . '" />', $buffer); } if (!is_null($shCustomKeywordsTag)) { $buffer = preg_replace('/\\<\\s*meta\\s+name\\s*=\\s*"keywords.*\\/\\>/isU', '<meta name="keywords" content="' . shCleanUpDesc($shCustomKeywordsTag) . '" />', $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'); } } // 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 = JURI::base() . $targetLang[0] . '/'; $buffer = preg_replace('#<div class="module_menu(.*)href="' . $badHomeLink . '"#isU', '<div class="module_menu$1href="' . $goodHomeLink . '"', $buffer); } // insert pageId if tag found, except if editing item on frontend if (strpos($buffer, '{sh404sef_pageid}') !== false) { // pull out contents of editor to prevent URL changes inside edit area $editor =& JFactory::getEditor(); $regex = '#' . $editor->_tagForSEF['start'] . '(.*)' . $editor->_tagForSEF['end'] . '#Us'; preg_match_all($regex, $buffer, $editContents, PREG_PATTERN_ORDER); // create an array to hold the placeholder text (in case there are more than one editor areas) $placeholders = array(); for ($i = 0; $i < count($editContents[0]); $i++) { $placeholders[] = $editor->_tagForSEF['start'] . $i . $editor->_tagForSEF['end']; } // replace editor contents with placeholder text $buffer = str_replace($editContents[0], $placeholders, $buffer); // fetch pageId for current page and replace $sql = 'SELECT pageid FROM #__sh404sef_pageids WHERE newurl = \'' . ltrim($shPageInfo->shCurrentPageNonSef, '/') . '\''; $database->setQuery($sql); $pageId = $database->loadResult(); $buffer = str_replace('{sh404sef_pageid}', $pageId, $buffer); // restore the editor contents $buffer = str_replace($placeholders, $editContents[0], $buffer); } // all done return $buffer; } }
function shInsertOpenGraphData(&$buffer) { // get sh404sef config $sefConfig =& Sh404sefFactory::getConfig(); $pageInfo =& Sh404sefFactory::getPageInfo(); if (empty($sefConfig->shMetaManagementActivated) || !isset($sefConfig) || empty($pageInfo->currentNonSefUrl) || !empty($pageInfo->httpStatus) && $pageInfo->httpStatus == 404) { return; } $nonSef = shGetCurrentNonSef(); $customData = shGetCustomMetaData($nonSef); // user can disable per url if ($customData->og_enable == SH404SEF_OPTION_VALUE_NO || empty($sefConfig->enableOpenGraphData) && $customData->og_enable == SH404SEF_OPTION_VALUE_USE_DEFAULT) { return; } $openGraphData = ''; $ogNameSpace = ''; $fbNameSpace = ''; // add locale - FB use underscore in language tags $locale = str_replace('-', '_', JFactory::getLanguage()->getTag()); $openGraphData .= "\n" . ' <meta property="og:locale" content="' . $locale . '" />'; // insert title if (!empty($pageInfo->pageTitle)) { $openGraphData .= "\n" . ' <meta property="og:title" content="' . $pageInfo->pageTitle . '" />'; } // insert description if (($sefConfig->ogEnableDescription && $customData->og_enable_description == SH404SEF_OPTION_VALUE_USE_DEFAULT || $customData->og_enable_description == SH404SEF_OPTION_VALUE_YES) && !empty($pageInfo->pageDescription)) { $openGraphData .= "\n" . ' <meta property="og:description" content="' . $pageInfo->pageDescription . '" />'; } // insert type $content = $customData->og_type == SH404SEF_OPTION_VALUE_USE_DEFAULT ? $sefConfig->ogType : $customData->og_type; if (!empty($content)) { $openGraphData .= "\n" . ' <meta property="og:type" content="' . $content . '" />'; } // insert url. If any, we insert the canonical url rather than current, to consolidate $content = empty($pageInfo->pageCanonicalUrl) ? $pageInfo->currentSefUrl : $pageInfo->pageCanonicalUrl; $content = Sh404sefHelperGeneral::stripTrackingVarsFromSef($content); $openGraphData .= "\n" . ' <meta property="og:url" content="' . htmlspecialchars($content, ENT_COMPAT, 'UTF-8') . '" />'; // insert image $content = empty($customData->og_image) ? $sefConfig->ogImage : $customData->og_image; if (!empty($content)) { $content = JURI::root(false, '') . JString::ltrim($content, '/'); $openGraphData .= "\n" . ' <meta property="og:image" content="' . $content . '" />'; } // insert site name if ($sefConfig->ogEnableSiteName && $customData->og_enable_site_name == SH404SEF_OPTION_VALUE_USE_DEFAULT || $customData->og_enable_site_name == SH404SEF_OPTION_VALUE_YES) { $content = empty($customData->og_site_name) ? $sefConfig->ogSiteName : $customData->og_site_name; $content = empty($content) ? JFactory::getApplication()->getCfg('sitename') : $content; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:site_name" content="' . $content . '" />'; } } // insert location // disabled: Facebook removed all of that after reducing number of object types to bare minimum if (false && ($sefConfig->ogEnableLocation && $customData->og_enable_location == SH404SEF_OPTION_VALUE_USE_DEFAULT || $customData->og_enable_location == SH404SEF_OPTION_VALUE_YES)) { $content = empty($customData->og_latitude) ? $sefConfig->ogLatitude : $customData->og_latitude; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:latitude" content="' . $content . '" />'; } $content = empty($customData->og_longitude) ? $sefConfig->ogLongitude : $customData->og_longitude; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:longitude" content="' . $content . '" />'; } $content = empty($customData->og_street_address) ? $sefConfig->ogStreetAddress : $customData->og_street_address; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:street-address" content="' . $content . '" />'; } $content = empty($customData->og_locality) ? $sefConfig->ogLocality : $customData->og_locality; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:locality" content="' . $content . '" />'; } $content = empty($customData->og_postal_code) ? $sefConfig->ogPostalCode : $customData->og_postal_code; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:postal-code" content="' . $content . '" />'; } $content = empty($customData->og_region) ? $sefConfig->ogRegion : $customData->og_region; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:region" content="' . $content . '" />'; } $content = empty($customData->og_country_name) ? $sefConfig->ogCountryName : $customData->og_country_name; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:country-name" content="' . $content . '" />'; } } // insert contact // disabled: Facebook removed all of that after reducing number of object types to bare minimum if (false && ($sefConfig->ogEnableContact && $customData->og_enable_contact == SH404SEF_OPTION_VALUE_USE_DEFAULT || $customData->og_enable_contact == SH404SEF_OPTION_VALUE_YES)) { $content = empty($customData->og_email) ? $sefConfig->ogEmail : $customData->og_email; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:email" content="' . $content . '" />'; } $content = empty($customData->og_phone_number) ? $sefConfig->ogPhoneNumber : $customData->og_phone_number; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:phone_number" content="' . $content . '" />'; } $content = empty($customData->og_fax_number) ? $sefConfig->ogFaxNumber : $customData->og_fax_number; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:fax_number" content="' . $content . '" />'; } } if (!empty($openGraphData)) { $ogNameSpace = 'xmlns:og="http://ogp.me/ns#"'; } // insert fb admin id if (!empty($sefConfig->fbAdminIds) && $customData->og_enable_fb_admin_ids == SH404SEF_OPTION_VALUE_USE_DEFAULT || $customData->og_enable_fb_admin_ids == SH404SEF_OPTION_VALUE_YES) { $content = empty($customData->fb_admin_ids) ? $sefConfig->fbAdminIds : $customData->fb_admin_ids; if ($customData->og_enable_fb_admin_ids != SH404SEF_OPTION_VALUE_NO && !empty($content)) { $openGraphData .= "\n" . ' <meta property="fb:admins" content="' . $content . '" />'; $fbNameSpace = 'xmlns:fb="https://www.facebook.com/2008/fbml"'; } } // actually insert the tags if (!empty($openGraphData)) { $buffer = shInsertCustomTagInBuffer($buffer, '<head>', 'after', $openGraphData, 'first'); } if (!empty($fbNameSpace) || !empty($ogNameSpace)) { // insert as well namespaces $buffer = str_replace('<html ', '<html ' . $ogNameSpace . ' ' . $fbNameSpace . ' ', $buffer); } }
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; } }