Exemple #1
0
 /**
  * Checks the found row
  *
  */
 function _checkRow(&$row, $ignoreSource, $Itemid, $url, &$metadata, $temploc, $priority, $option, $check = false, $host, $sitemapParams = null)
 {
     $realloc = null;
     $db =& JFactory::getDBO();
     $sefConfig =& SEFConfig::getConfig();
     $numberDuplicates = $sefConfig->numberDuplicates;
     if (!empty($option)) {
         $params =& SEFTools::getExtParams($option);
         $extDuplicates = $params->get('numberDuplicates', '2');
         if ($extDuplicates != '2') {
             $numberDuplicates = $extDuplicates;
         }
     }
     if ($row != false && !is_null($row)) {
         if ($ignoreSource || !$ignoreSource && (empty($Itemid) || $row->Itemid == $Itemid)) {
             // ... check that it matches original URL
             if ($row->origurl == $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 = $row->sefurl;
             } else {
                 if ($sefConfig->langPlacement == _COM_SEF_LANG_DOMAIN) {
                     // check if the urls differ only by lang variable
                     if (SEFTools::removeVariable($row->origurl, 'lang') == SEFTools::removeVariable($url, 'lang')) {
                         $db->setQuery("UPDATE `#__sefurls` SET `origurl` = '" . SEFTools::removeVariable($row->origurl, 'lang') . "' WHERE `id` = '" . $row->id . "' LIMIT 1");
                         // if error occured.
                         if (!$db->query()) {
                             JError::raiseError('JoomSEF Error', JText::_('COM_SEF_ERROR_SEF_URL_UPDATE') . $db->getErrorMsg());
                         }
                         $realloc = $row->sefurl;
                     }
                 }
             }
         }
         // The found URL is not the same
         if (!$numberDuplicates) {
             // But duplicates management is turned on
             // so we can save the same SEF URL for different non-SEF URL
             if (!$check) {
                 JoomSEF::_saveNewURL($Itemid, $metadata, $priority, $temploc, $url, $host, $sitemapParams);
             }
             $realloc = $temploc;
         }
     } else {
         // first, try to search among 404s
         $query = "SELECT `id` FROM `#__sefurls` WHERE `sefurl` = '{$temploc}' AND `origurl` = ''";
         $db->setQuery($query);
         $id = $db->loadResult();
         // if 404 exists, rewrite it to the new URL
         if (!is_null($id)) {
             $sqlId = !empty($Itemid) ? ", `Itemid` = '{$Itemid}'" : '';
             $query = "UPDATE `#__sefurls` SET `origurl` = " . $db->quote(html_entity_decode(urldecode($url))) . "{$sqlId}, `priority` = '{$priority}' WHERE `id` = '{$id}' LIMIT 1";
             $db->setQuery($query);
             // if error occured
             if (!$db->query()) {
                 JError::raiseError('JoomSEF Error', JText::_('COM_SEF_ERROR_SEF_URL_UPDATE') . $db->getErrorMsg());
             }
         } else {
             if (!$check) {
                 JoomSEF::_saveNewURL($Itemid, $metadata, $priority, $temploc, $url, $host, $sitemapParams);
             }
         }
         $realloc = $temploc;
     }
     return $realloc;
 }
 /**
  * Checks the found row
  *
  */
 function _checkRow(&$row, $ignoreSource, $Itemid, $url, &$metadata, $temploc, $priority, $option, $host, $sitemapParams)
 {
     $realloc = null;
     $db =& JFactory::getDBO();
     $sefConfig =& SEFConfig::getConfig();
     $numberDuplicates = $sefConfig->numberDuplicates;
     if (!empty($option)) {
         $params =& SEFTools::getExtParams($option);
         $extDuplicates = $params->get('numberDuplicates', '2');
         if ($extDuplicates != '2') {
             $numberDuplicates = $extDuplicates;
         }
     }
     if ($row != false && !is_null($row)) {
         if ($ignoreSource || !$ignoreSource && (empty($Itemid) || $row->Itemid == $Itemid)) {
             // ... check that it matches original URL
             if ($row->origurl == $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 = $row->sefurl;
             } else {
                 if ($sefConfig->langPlacement == _COM_SEF_LANG_DOMAIN) {
                     // check if the urls differ only by lang variable
                     if (SEFTools::removeVariable($row->origurl, 'lang') == SEFTools::removeVariable($url, 'lang')) {
                         $db->setQuery("UPDATE `#__sefurls` SET `origurl` = " . $db->Quote(SEFTools::removeVariable($row->origurl, 'lang')) . " WHERE `id` = '{$row->id}' LIMIT 1");
                         // if error occured.
                         if (!$db->query()) {
                             $msg = JText::_('Could not update SEF URL in database');
                             if (JDEBUG) {
                                 $msg .= ': ' . $db->getErrorMsg();
                             }
                             JError::raiseError('JoomSEF Error', $msg);
                         }
                         $realloc = $row->sefurl;
                     }
                 }
             }
         }
         // The found URL is not the same
         if (!$numberDuplicates) {
             // But duplicates management is turned on
             // so we can save the same SEF URL for different non-SEF URL
             JoomSEF::_saveNewURL($Itemid, $metadata, $priority, $temploc, $url, false, $host, $sitemapParams);
             $realloc = $temploc;
         }
     } else {
         // Save URL in the database
         JoomSEF::_saveNewURL($Itemid, $metadata, $priority, $temploc, $url, true, $host, $sitemapParams);
         $realloc = $temploc;
     }
     return $realloc;
 }
 /**
  * Tries to find a SEF URL corresponding with given nonSEF URL
  *
  * @param string $nonsef
  * @param string $Itemid
  * @return string
  */
 function getSefUrl($nonsef, $Itemid = null)
 {
     $sefConfig =& SEFConfig::getConfig();
     // Load the cache if needed
     if (!$this->cacheLoaded) {
         $this->LoadCache();
     }
     // Check if the cache was loaded successfully
     if (!$this->cacheLoaded) {
         return false;
     }
     // Check if non-sef url doesn't contain Itemid
     $vars = array();
     parse_str(str_replace('index.php?', '', $nonsef), $vars);
     if (is_null($Itemid) && strpos($nonsef, 'Itemid=')) {
         if (isset($vars['Itemid'])) {
             $Itemid = $vars['Itemid'];
         }
         $nonsef = SEFTools::removeVariable($nonsef, 'Itemid');
     }
     // Get the ignoreSource parameter
     if (isset($vars['option'])) {
         $params = SEFTools::getExtParams($vars['option']);
         $extIgnore = $params->get('ignoreSource', 2);
     } else {
         $extIgnore = 2;
     }
     $ignoreSource = $extIgnore == 2 ? $sefConfig->ignoreSource : $extIgnore;
     // If Itemid is set as ignored for the component, set ignoreSource to 1
     if (!is_null($Itemid) && isset($vars['option'])) {
         if (SEFTools::isItemidIgnored($vars['option'], $Itemid)) {
             $ignoreSource = 1;
         }
     }
     // Get all sef urls matching non-sef url
     if (isset($this->cache[$nonsef]) && is_array($this->cache[$nonsef]) && count($this->cache[$nonsef]) > 0) {
         // Search with Itemid if set to and Itemid set
         if (!$ignoreSource && !is_null($Itemid)) {
             $nullId = null;
             for ($i = 0, $n = count($this->cache[$nonsef]); $i < $n; $i++) {
                 $row = $this->cache[$nonsef][$i];
                 if (isset($row->Itemid) && $row->Itemid == $Itemid) {
                     return $row;
                 }
                 if (empty($row->Itemid)) {
                     $nullId = $i;
                 }
             }
             // Not found with correct itemid, try to find without itemid
             if (!is_null($nullId)) {
                 // Update Itemid in cache
                 $this->cache[$nonsef][$i]->Itemid = $Itemid;
                 $row = $this->cache[$nonsef][$i];
                 // Save the cache
                 $this->saveCache();
                 // Return found row
                 return $row;
             }
         } else {
             return $this->cache[$nonsef][0];
         }
     }
     // URL does not exist in the cache
     return false;
 }
Exemple #4
0
 function extractVariable(&$url, $var)
 {
     $value = SEFTools::getVariable($url, $var);
     $url = SEFTools::removeVariable($url, $var);
     return $value;
 }