コード例 #1
0
ファイル: metas.php プロジェクト: sangkasi/joomla
 /**
  * Save a list of meta data as entered by user in backend to the database
  *
  * @param string $metaData an array of meta key/meta value from user. Also include nonsef url
  *
  * @return boolean true on success
  */
 public function save($metaDatas)
 {
     $this->_db =& JFactory::getDBO();
     $row =& JTable::getInstance($this->_defaultTable, 'Sh404sefTable');
     // attach incoming data to table object
     $status = $row->bind($metaDatas);
     // add language code if missing, except on home page
     if ($status && $row->newurl != sh404SEF_HOMEPAGE_CODE && !preg_match('/(&|\\?)lang=[a-zA-Z]{2,3}/iU', $row->newurl)) {
         // no lang string, let's add default
         $shTemp = explode('-', shGetDefaultLang());
         $shLangTemp = $shTemp[0] ? $shTemp[0] : 'en';
         $row->newurl .= '&lang=' . $shLangTemp;
     }
     // sort url params, except on home page
     if ($status && $row->newurl != sh404SEF_HOMEPAGE_CODE) {
         $row->newurl = shSortUrl($row->newurl);
     }
     // pre-save checks
     $status = $status && $row->check();
     // save the changes
     $status = $status && $row->store();
     // store error message
     if (!$status) {
         $error = $row->getError();
         $this->setError($error);
     }
     // return true if no error
     $errors = $this->getError();
     return empty($errors);
 }
コード例 #2
0
ファイル: metas.php プロジェクト: lautarodragan/ideary
 /**
  * Save a list of meta data as entered by user in backend to the database
  *
  * @param string $metaData an array of meta key/meta value from user. Also include nonsef url
  * @return boolean true on success
  */
 public function save($metaDatas)
 {
     $this->_db =& JFactory::getDBO();
     $row =& JTable::getInstance($this->_defaultTable, 'Sh404sefTable');
     // only save if there is actually some metas data
     // at least on new records
     $metas = '';
     foreach ($metaDatas as $key => $value) {
         if ($key != 'meta_id' && (substr($key, 0, 4) == 'meta' || substr($key, 0, 3) == 'fb_' || substr($key, 0, 3) == 'og_' || $key == 'canonical')) {
             $metas .= $value;
         }
     }
     // if there is no meta data entered, don't save
     if (!empty($metas) && $metas == SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT) {
         if (!empty($metaDatas['id'])) {
             // there is an existing record, meta data was cleared by user, we can delete the record altogether
             try {
                 Sh404sefHelperDb::delete('#__sh404sef_metas', array('id' => $metaDatas['id']));
                 return true;
             } catch (Sh404sefExceptionDefault $e) {
                 $this->setError($e->getMessage());
                 return false;
             }
         }
         // in any case, don't save anything
         return true;
     }
     $status = true;
     // load pre-existing values
     if (!empty($metaDatas['id'])) {
         $status = $row->load($metaDatas['id']);
     }
     // attach incoming data to table object
     $status = $status && $row->bind($metaDatas);
     // add language code if missing, except on home page
     if ($status && $row->newurl != sh404SEF_HOMEPAGE_CODE && !preg_match('/(&|\\?)lang=[a-zA-Z]{2,3}/iU', $row->newurl)) {
         // no lang string, let's add default
         $shTemp = explode('-', shGetDefaultLang());
         $shLangTemp = $shTemp[0] ? $shTemp[0] : 'en';
         $row->newurl .= '&lang=' . $shLangTemp;
     }
     // sort url params, except on home page
     if ($status && $row->newurl != sh404SEF_HOMEPAGE_CODE) {
         $row->newurl = shSortUrl($row->newurl);
     }
     // pre-save checks
     $status = $status && $row->check();
     // save the changes
     $status = $status && $row->store();
     // store error message
     if (!$status) {
         $error = $row->getError();
         $this->setError($error);
     }
     // return true if no error
     $errors = $this->getError();
     return empty($errors);
 }
コード例 #3
0
ファイル: shPageRewrite.php プロジェクト: alesconti/FF_2015
 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;
     }
 }
コード例 #4
0
ファイル: sef_ext.php プロジェクト: sangkasi/joomla
 /**
  * Vul in de array $title de onderdelen waaruit de link moet bestaan
  * Bijvoorbeeld: menuitem, categorie, itemnaam
  * Deze functie last de boel aan elkaar
  *
  * @param  string $url
  * @param  array $title
  * @param  string $task
  * @param  int $limit
  * @param  int $limitstart
  * @return sefurl
  */
 function sefGetLocation($url, &$title, $task = null, $limit = null, $limitstart = null, $langParam = null, $showall = null)
 {
     global $shMosConfig_locale, $option, $shHomeLink;
     $sefConfig =& shRouter::shGetConfig();
     // get DB
     $database =& JFactory::getDBO();
     $lang = empty($langParam) ? $shMosConfig_locale : $langParam;
     // V 1.2.4.k added homepage check : needed in case homepage is not com_frontpage
     if (empty($shHomeLink)) {
         $menu =& shRouter::shGetMenu();
         $shHomePage =& $menu->getDefault();
         if ($shHomePage) {
             if (substr($shHomePage->link, 0, 9) == 'index.php' && !preg_match('/Itemid=[0-9]*/', $shHomePage->link)) {
                 // and it does not have an Itemid
                 $shHomePage->link .= ($shHomePage->link == 'index.php' ? '?' : '&') . 'Itemid=' . $shHomePage->id;
                 // then add itemid
             }
             $shHomeLink = $shHomePage->link;
             //$shHomeLink = 'index.php';
             if (!strpos($shHomeLink, 'lang=')) {
                 $shDefaultIso = shGetIsoCodeFromName(shGetDefaultLang());
                 $shSepString = substr($shHomeLink, -9) == 'index.php' ? '?' : '&';
                 $shHomeLink .= $shSepString . 'lang=' . $shDefaultIso;
             }
             $shHomeLink = shSortUrl($shHomeLink);
             // $homeLink has lang info, whereas $homepage->link may or may not
         }
     }
     // shumisha : try to avoid duplicate content when using Joomfish by always adding &lang=xx to url (stored in DB).
     // warning : must add &lang=xx only if it does not exists already, which happens for the joomfish language selection modules or search results
     if (!strpos($url, 'lang=')) {
         $shSepString = substr($url, -9) == 'index.php' ? '?' : '&';
         $url .= $shSepString . 'lang=' . shGetIsoCodeFromName($lang);
     }
     // shumisha end of fix
     //shorten the url for storage and for consistancy
     $url = str_replace('&amp;', '&', $url);
     // V 1.2.4.q detect multipage homepage
     $shMultiPageHomePageFlag = shIsHomepage($url);
     // get all the titles ready for urls
     $location = array();
     foreach ($title as $titlestring) {
         // V 1.2.4.t removed array_filter as it prevents '0' values in URL
         $location[] = titleToLocation(urldecode($titlestring));
     }
     $location = implode("/", $location);
     // V 1.2.4.t
     // V 1.2.4.t remove duplicate /
     $location = preg_replace('/\\/{2,}/', '/', $location);
     $location = JString::substr($location, 0, sh404SEF_MAX_SEF_URL_LENGTH);
     // trim to max length V 1.2.4.t
     // shumisha protect against querying for empty location
     if (empty($location)) {
         // V 1.2.4.t
         if ((!shIsMultilingual() || shIsMultilingual() && shIsDefaultlang($lang)) && !$sefConfig->addFile && !$shMultiPageHomePageFlag) {
             // V 1.2.4.q : need to go further and add pagination
             return '';
         }
     }
     // if location is empty, and no Joomfish, or Joomfish but this is default language, then there is nothing to add to url before querying DB
     // shumisha end of change
     //check for non-sef url first and avoid repeative lookups
     //we only want to look for title variations when adding new
     //this should also help eliminate duplicates.
     // shumisha 2003-03-13 added URL Caching
     $realloc = '';
     $urlType = Sh404sefHelperCache::getSefUrlFromCache($url, $realloc);
     if ($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) {
         // V 1.2.4.t
         // shumisha end of addition
         $realloc = false;
         if ($urlType == sh404SEF_URLTYPE_NONE) {
             $query = "SELECT oldurl from #__redirection WHERE newurl = " . $database->Quote($url);
             $database->setQuery($query);
             //if ($realloc = $database->loadResult()) {
             if ($shTemp = $database->loadObject()) {
                 $realloc = $shTemp->oldurl;
             }
         }
         if ($realloc) {
             // found a match, so we aredone
             //Dat betekent dus, dat de functie create(), slecht gekozen is
             // shumisha : removed this die() that I do not understand!
             //die('regel292 in sef_ext.php');
             // shumisha end of removal
         } else {
             // this is new, so we need to insert the new title.
             //Hier worden eindelijk de nieuwe links gemaakt
             $iteration = 1;
             $realloc = false;
             $prev_temploc = '';
             do {
                 // temploc is $location, unless we're on a second or greater iteration,
                 // then its $location.$iteration
                 if (!empty($location)) {
                     $shSeparator = JString::substr($location, -1) == '/' ? '' : '/';
                 } else {
                     $shSeparator = '';
                 }
                 $temploc = shAddPaginationInfo($limit, $limitstart, $showall, $iteration, $url, $location, $shSeparator);
                 // v 1.2.4.t
                 // V 1.2.4.t
                 if ($shMultiPageHomePageFlag && '/' . $temploc == $location && (!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)) {
                         // V 1.2.4.t
                         return str_replace($GLOBALS['shConfigLiveSite'] . '/', '', $sefConfig->shForcedHomePage);
                     } else {
                         return '';
                     }
                 }
                 // V 1.2.4.k here we need to check for other-than-default-language homepage
                 // remove lang
                 $v1 = shCleanUpLang($url);
                 // V 1.2.4.t
                 $v2 = shCleanUpLang($shHomeLink);
                 // V 1.24.t
                 if ($v1 == $v2 || $v1 == 'index.php') {
                     // check if this is homepage
                     if (shIsMultilingual() && !shIsDefaultLang($lang)) {
                         // V 1.2.4.m : insert language code based on param
                         $temploc = shGetIsoCodeFromName($lang) . '/';
                     } else {
                         $temploc = '';
                     }
                     // if homepage in not-default-language, then add language code even if param says opposite
                     // as we otherwise would not be able to switch language on the frontpage
                 } else {
                     if (shInsertIsoCodeInUrl($option, $lang)) {
                         // V 1.2.4.m : insert language code based on param
                         // V 1.2.4.q : pass URL lang info, as may not be current lang
                         $temploc = shGetIsoCodeFromName($lang) . '/' . $temploc;
                         // V 1.2.4.q  must be forced lang, not default
                     }
                 }
                 if ($temploc != '') {
                     // see if we have a result for this location
                     // V 1.2.4.r without mod_rewrite
                     $temploc = shAdjustToRewriteMode($temploc);
                     $sql = "SELECT id, newurl, rank, dateadd FROM #__redirection WHERE oldurl = " . $database->Quote($temploc) . " ORDER BY rank ASC";
                     // V 1.2.4.q
                     $database->setQuery($sql);
                     if ($iteration > 9999) {
                         //var_dump($sql);
                         JError::raiseError(500, 'Too many pages :' . $temploc . '##');
                     }
                     $dburl = null;
                     // V 1.2.4.t initialize $dburl to avoid notices error if cache disabled
                     $dbUrlId = null;
                     // V 1.2.4.t
                     $urlType = sh404SEF_URLTYPE_NONE;
                     // shumisha 2007-03-13 added URL caching, check for various URL for same content
                     if ($sefConfig->shUseURLCache) {
                         $urlType = Sh404sefHelperCache::getNonSefUrlFromCache($temploc, $dburl);
                     }
                     $newMaxRank = 0;
                     $shDuplicate = false;
                     if ($sefConfig->shRecordDuplicates || $urlType == sh404SEF_URLTYPE_NONE) {
                         // V 1.2.4.s
                         $dbUrlList = $database->loadObjectList();
                         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
                                 $urlType = sh404SEF_URLTYPE_404;
                             } else {
                                 $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 && $urlType != sh404SEF_URLTYPE_404) {
                         if ($dburl == $url) {
                             // found the matching object
                             // it probably should have been found sooner
                             // but is checked again here just for CYA purposes
                             // and to end the loop
                             $realloc = $temploc;
                         } else {
                             $shDuplicate = true;
                         }
                         // else, didn't find it, increment and try again
                         // shumisha added this to close the loop if working on frontpage
                         // as domain.tld/index.php?lang=xx and domain.tld/index.php?option=com_frontpage&Itemid=1&lang=xx both must end up in domain.tld/xx/ (if xx is not default language of course - in that case, they must endup in domain.tld)
                         // this is true also if Joomfish is not installed and there is no language information in the url
                         // V 1.2.4.q  this is a duplicate so we must indert it with incremented rank;
                         if ($shDuplicate && $sefConfig->shRecordDuplicates) {
                             shAddSefUrlToDBAndCache($url, $temploc, $shDuplicate ? $newMaxRank : 0, $urlType);
                         }
                         $realloc = $temploc;
                         // to close the loop
                         // shumisha end of addition
                     } else {
                         //title not found, chechk 404
                         $dbUrlId = empty($dbUrlId) ? 0 : intval($dbUrlId);
                         if ($sefConfig->shLog404Errors) {
                             // V 1.2.4.m
                             if ($urlType == sh404SEF_URLTYPE_404 && !empty($dbUrlId)) {
                                 // we already have seen that it is a 404
                                 $id = $dbUrlId;
                                 // V 1.2.4.t
                             } elseif ($urlType == sh404SEF_URLTYPE_404) {
                                 $query = "SELECT `id` FROM #__redirection WHERE `oldurl` = " . $database->Quote($temploc) . " AND `newurl` = ''";
                                 $database->setQuery($query);
                                 $id = $database->loadResult();
                             } else {
                                 $id = null;
                             }
                         } else {
                             $id = null;
                         }
                         // V 1.2.4.m if we are not logging 404 errors, then no need to check for
                         // previous hit of this page.
                         if (!empty($id)) {
                             // V 1.2.4.q : need to update dateadd to 0, as otherwise this redir will be seen as a custom redir
                             // this makes all such 404 errors 'disappear' from the 404 log, but no other solution
                             $query = "UPDATE #__redirection SET `newurl` = " . $database->Quote($url) . ",`dateadd` = '0000-00-00' WHERE `id` = '{$id}'";
                             $database->setQuery($query);
                             if (!$database->query()) {
                                 _log('error adding new sef url to db:' . $database->getErrorMsg());
                                 //var_dump($query);
                             } else {
                                 Sh404sefHelperCache::addSefUrlToCache($url, $temploc, sh404SEF_URLTYPE_AUTO);
                                 // v 1.2.4.t
                             }
                         } else {
                             /* put it in the database */
                             shAddSefUrlToDBAndCache($url, $temploc, 0, sh404SEF_URLTYPE_AUTO);
                         }
                         $realloc = $temploc;
                     }
                 }
                 $prev_temploc = $temploc;
                 $iteration++;
                 // shumisha allow loop exit if $temploc = '' (homepage)
                 //} while (!$realloc);
             } while (!$realloc && $temploc != '');
         }
     }
     // shumisha : enf of check if URL is in cache
     return $realloc;
 }
コード例 #5
0
ファイル: sh404sef.class.php プロジェクト: sangkasi/joomla
function getMenuTitle($option, $task, $id = null, $string = null, $shLanguage = null)
{
    global $shHomeLink;
    $sefConfig =& shRouter::shGetConfig();
    $database =& JFactory::getDBO();
    $shLanguage = empty($shLanguage) ? $GLOBALS['shMosConfig_locale'] : $shLanguage;
    // V 1.2.4.q must also check if homepage, in any language. If homepage, must return $title[]='/'
    // language info and limit/limistart pagination will be added at final stage by sefGetLocation()
    // V 1.2.4.t must also check that menu item is published !!
    $nameField = $sefConfig->useMenuAlias ? 'alias' : 'name';
    if (!empty($string)) {
        // V 1.2.4.q replaced isset by empty
        $sql = "SELECT " . $nameField . ", link,id FROM #__menu WHERE link = " . $database->Quote($string) . " AND published = '1'";
    } elseif (!empty($id)) {
        $sql = "SELECT " . $nameField . ", link,id FROM #__menu WHERE id = " . intval($id) . " AND published='1'";
    } elseif (!empty($option)) {
        $sql = 'SELECT ' . $nameField . ', link,id FROM #__menu WHERE published=\'1\' AND link LIKE \'index.php?option=' . $database->getEscaped($option) . '%\'';
    } else {
        return '/';
        // don't know what else we could do, just go home
    }
    $database->setQuery($sql);
    if (isset($shLanguage) && shIsMultilingual()) {
        $rows = @$database->loadObjectList('', true, $shLanguage);
    } else {
        $rows = @$database->loadObjectList();
    }
    if ($database->getErrorNum()) {
        die($database->stderr());
    } elseif (@count($rows) > 0) {
        $shLink = shSortUrl($rows[0]->link . ($rows[0]->link == 'index.php' ? '?' : '&') . 'Itemid=' . $rows[0]->id);
        if (!shIsHomepage($shLink)) {
            // V1.2.4.q homepage detection
            if (!empty($rows[0]->{$nameField})) {
                $title = $rows[0]->{$nameField};
            }
        } else {
            $title = '/';
        }
        // this is homepage
    } else {
        $title = str_replace('com_', '', $option);
    }
    return $title;
}
コード例 #6
0
ファイル: editurl.php プロジェクト: sangkasi/joomla
 /**
  * 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');
     // 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}/iU', $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 #__redirection WHERE oldurl = ' . $this->_db->Quote($row->oldurl) . ' ORDER BY rank ASC';
     $this->_db->setQuery($query);
     $dbUrlList = $this->_db->loadObjectList();
     // do we have urls in the db with same SEF ?
     if (count($dbUrlList) > 0) {
         // yes we do
         // get config object
         $sefConfig = shRouter::shGetConfig();
         if (!$sefConfig->shRecordDuplicates) {
             // we don't allow duplicates : reject this URL
             $this->setError(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(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 #__redirection WHERE oldurl = ' . $this->_db->Quote($previousSefUrl);
                     $this->_db->setQuery($query);
                     $isThere = $this->_db->loadResult();
                     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 #__redirection WHERE oldurl = ' . $this->_db->Quote($previousSefUrl) . ' ORDER BY rank ASC';
                 $this->_db->setQuery($query);
                 $previousRanked2 = $this->_db->loadObject();
                 // there was more than one duplicate in the same series, promote #2 to top spot
                 if (!empty($previousRanked2)) {
                     $query = 'UPDATE #__redirection SET rank="0" WHERE id = ' . $this->_db->Quote($previousRanked2->id);
                     $this->_db->setQuery($query);
                     $this->_db->query();
                 }
             }
         }
     } 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 #__redirection WHERE oldurl = ' . $this->_db->Quote($previousSefUrl);
             $this->_db->setQuery($query);
             $isThere = $this->_db->loadResult();
             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 #__redirection WHERE oldurl = ' . $this->_db->Quote($previousSefUrl) . ' ORDER BY rank ASC';
             $this->_db->setQuery($query);
             $previousRanked2 = $this->_db->loadObject();
             // there was more than one duplicate in the same series, promote #2 to top spot
             if (!empty($previousRanked2)) {
                 $query = 'UPDATE #__redirection SET rank="0" WHERE id = ' . $this->_db->Quote($previousRanked2->id);
                 $this->_db->setQuery($query);
                 $this->_db->query();
             }
         }
     }
     // store saved url object
     $this->_url = $row;
     // return what should be a non-zero id
     return $this->_url->id;
 }
コード例 #7
0
function shIsAnyHomepage( $string) {

  static $pages = array();
  static $home = '';
  static $cleanedHomeLinks = array();

  if( !isset( $pages[$string])) {
    $pageInfo = & Sh404sefFactory::getPageInfo();
    if(empty( $cleanedHomeLinks)) {
      foreach( $pageInfo->homeLinks as $link) {
        $cleanedHomeLinks[] = shCleanUpPag( $link);
      }
    }

    $shTempString = JString::rtrim(str_replace($pageInfo->getDefaultLiveSite(), '', $string), '/');
    $shTempString = shSortUrl(shCleanUpPag($shTempString));

    // check all homepages
    $pages[$string] = false;
    foreach( $cleanedHomeLinks as $link) {
      if( $link == $shTempString) {
        $pages[$string] = true;
      }
    }

  }
  return $pages[$string];
}
コード例 #8
0
ファイル: shPageRewrite.php プロジェクト: justinlyon/scc
 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;
     }
 }
コード例 #9
0
ファイル: shPageRewrite.php プロジェクト: sangkasi/joomla
 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;
     }
 }
コード例 #10
0
ファイル: metas.php プロジェクト: alesconti/FF_2015
 /**
  * Save a list of meta data as entered by user in backend to the database
  *
  * @param string $metaData an array of meta key/meta value from user. Also include nonsef url
  * @return boolean true on success
  */
 public function save($dataArray = null)
 {
     $this->_db = ShlDbHelper::getDb();
     $row = JTable::getInstance($this->_defaultTable, 'Sh404sefTable');
     // only save if there is actually some metas data
     // at least on new records
     $metas = '';
     foreach ($dataArray as $key => $value) {
         if ($key != 'meta_id' && (substr($key, 0, 4) == 'meta' || substr($key, 0, 3) == 'fb_' || substr($key, 0, 3) == 'og_' || $key == 'canonical')) {
             $metas .= $value;
         }
     }
     // if there is no meta data entered, and this is an existing record, delete it, or at least do not save
     if (!empty($metas) && $metas == SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT) {
         if (!empty($dataArray['meta_id'])) {
             // there is an existing record, meta data was cleared by user, we can delete the record altogether
             try {
                 ShlDbHelper::delete('#__sh404sef_metas', array('id' => $dataArray['meta_id']));
                 return true;
             } catch (Exception $e) {
                 $this->setError($e->getMessage());
                 return false;
             }
         }
         // in any case, don't save anything
         return true;
     }
     if (empty($metas) && empty($dataArray['meta_id'])) {
         // avoid creating a new (and empty) record when savnig a record from the "metas" page
         // where we're editing several records at a time
         // This would pass the test just above, because we do not have any values for fb_*, og_*, etc
         // fields as we're only editing title and description
         return true;
     }
     $status = true;
     // load pre-existing values
     if (!empty($dataArray['meta_id'])) {
         $status = $row->load($dataArray['meta_id']);
     }
     // attach incoming data to table object
     $status = $status && $row->bind($dataArray);
     // add language code if missing, except on home page
     if ($status && $row->newurl != sh404SEF_HOMEPAGE_CODE && !preg_match('/(&|\\?)lang=[a-zA-Z]{2,3}/iuU', $row->newurl)) {
         // no lang string, let's add default
         $shTemp = explode('-', shGetDefaultLang());
         $shLangTemp = $shTemp[0] ? $shTemp[0] : 'en';
         $row->newurl .= '&lang=' . $shLangTemp;
     }
     // sort url params, except on home page
     if ($status && $row->newurl != sh404SEF_HOMEPAGE_CODE) {
         $row->newurl = shSortUrl($row->newurl);
     }
     // pre-save checks
     $status = $status && $row->check();
     // save the changes
     $status = $status && $row->store();
     // store error message
     if (!$status) {
         $error = $row->getError();
         $this->setError($error);
     }
     // return true if no error
     $errors = $this->getError();
     return empty($errors);
 }
コード例 #11
0
ファイル: sh404sef.inc.php プロジェクト: justinlyon/scc
 $shHomePage =& $menu->getDefault();
 if ($shHomePage) {
     _log('$shHomePage found from menu, link = ' . $shHomePage->link);
     if (substr($shHomePage->link, 0, 9) == 'index.php' && !preg_match('/Itemid=[0-9]*/', $shHomePage->link)) {
         // and it does not have an Itemid
         $shHomePage->link .= ($shHomePage->link == 'index.php' ? '?' : '&') . 'Itemid=' . $shHomePage->id;
         // then add itemid
     }
     $shHomeLink = $shHomePage->link;
     if (!strpos($shHomeLink, 'lang=')) {
         //V 1.2.4.q protect against not existing
         $shDefaultIso = shGetIsoCodeFromName(shGetDefaultLang());
         $shSepString = substr($shHomeLink, -9) == 'index.php' ? '?' : '&';
         $shHomeLink .= $shSepString . 'lang=' . $shDefaultIso;
     }
     $shHomeLink = shSortUrl($shHomeLink);
     // $shHomeLink has lang info, whereas $homepage->link may or may not
 }
 _log('$shHomeLink calculated as : ' . $shHomeLink);
 _log('$shPageInfo->index : ' . $shPageInfo->index);
 if (strtolower($shPageInfo->index) == 'index.php' && empty($_POST)) {
     // prevents loading homepage if accessing index2.php (ajax calls)
     _log('rendering home page');
     $vars['Itemid'] = $shHomePage->id;
     $_SERVER['QUERY_STRING'] = $shPageInfo->QUERY_STRING = str_replace('index.php?', '', $shHomeLink);
     $REQUEST_URI = $shPageInfo->base . 'index.php?' . $shPageInfo->QUERY_STRING;
     $_SERVER['REQUEST_URI'] = $REQUEST_URI;
     $shPageInfo->shCurrentPageNonSef = 'index.php?' . $shPageInfo->QUERY_STRING;
     // V 1.2.4.s
     _log('Homepage non-sef = ' . $shPageInfo->shCurrentPageNonSef);
     $matches = array();