Exemple #1
0
 /**
  * Inserts new SEF URL to database
  *
  */
 function _saveNewURL($Itemid, &$metadata, $priority, $temploc, $url, $host, $sitemapParams)
 {
     $db =& JFactory::getDBO();
     $col = $val = '';
     if (!empty($Itemid)) {
         $col = ', `Itemid`';
         $val = ", '{$Itemid}'";
     }
     $metakeys = $metavals = '';
     if (is_array($metadata) && count($metadata) > 0) {
         foreach ($metadata as $metakey => $metaval) {
             $metakeys .= ", `{$metakey}`";
             $metavals .= ", '" . str_replace(array("\\", "'", ';'), array("\\\\", "\\'", "\\;"), $metaval) . "'";
         }
     }
     // get trace information if set to
     $sefConfig =& SEFConfig::getConfig();
     if (@$sefConfig->trace) {
         $traceinfo = $db->quote(JoomSEF::_getDebugInfo($sefConfig->traceLevel));
     } else {
         $traceinfo = "NULL";
     }
     // Sitemap default values
     $sm_indexed = isset($sitemapParams['indexed']) ? $sitemapParams['indexed'] : ($sefConfig->sitemap_indexed ? 1 : 0);
     $sm_date = date('Y-m-d');
     $sm_frequency = isset($sitemapParams['frequency']) ? $sitemapParams['frequency'] : $sefConfig->sitemap_frequency;
     $sm_priority = isset($sitemapParams['priority']) ? $sitemapParams['priority'] : $sefConfig->sitemap_priority;
     $autolock = (int) $sefConfig->autolock_urls;
     $query = 'INSERT INTO `#__sefurls` (`sefurl`, `origurl`, `priority`' . $col . $metakeys . ', `trace`, `sm_indexed`, `sm_date`, `sm_frequency`, `sm_priority`,`locked`,`host`) ' . "VALUES ('" . $temploc . "', " . $db->quote(html_entity_decode(urldecode($url))) . ", '{$priority}'" . $val . $metavals . ", " . $traceinfo . ", '{$sm_indexed}', '{$sm_date}', '{$sm_frequency}', '{$sm_priority}'," . $autolock . ",'" . $host . "')";
     $db->setQuery($query);
     // if error occured
     if (!$db->query()) {
         JError::raiseError('JoomSEF Error', JText::_('COM_SEF_ERROR_SEF_URL_STORE') . $db->getErrorMsg());
     }
 }
 /**
  * Inserts new SEF URL to database
  *
  */
 function _saveNewURL($Itemid, &$metadata, $priority, $temploc, $url, $check404 = false, $host = null, $sitemapParams = null)
 {
     $db =& JFactory::getDBO();
     // First try to find and recycle the trashed URL
     $query = "SELECT `id` FROM `#__sefurls` WHERE `origurl` = " . $db->Quote(html_entity_decode(urldecode($url))) . " AND `trashed` = '1'";
     if (!empty($Itemid)) {
         $query .= " AND `Itemid` = '{$Itemid}'";
     } else {
         $query .= " AND `Itemid` IS NULL";
     }
     $db->setQuery($query);
     $row = $db->loadObject();
     if (!is_null($row)) {
         // We've found trashed URL, let's reuse it
         $query = "UPDATE `#__sefurls` SET `sefurl` = " . $db->Quote($temploc) . ", `trashed` = '0' WHERE `id` = '{$row->id}' LIMIT 1";
         $db->setQuery($query);
         if (!$db->query()) {
             $msg = JText::_('Could not update the SEF URL in database');
             if (JDEBUG) {
                 $msg .= ': ' . $db->getErrorMsg();
             }
             JError::raiseError('JoomSEF Error', $msg);
         }
         // Remove any remaining same 404 URL
         $db->setQuery("DELETE FROM `#__sefurls` WHERE `sefurl` = " . $db->Quote($temploc) . " AND `origurl` = '' LIMIT 1");
         if (!$db->query()) {
             $msg = JText::_('Could not update the SEF URL in database');
             if (JDEBUG) {
                 $msg .= ': ' . $db->getErrorMsg();
             }
             JError::raiseError('JoomSEF Error', $msg);
         }
         return;
     }
     // No trashed URL found, try to find the 404 URL if set to
     if ($check404) {
         $query = "SELECT `id` FROM `#__sefurls` WHERE `sefurl` = " . $db->Quote($temploc) . " AND `origurl` = ''";
         $db->setQuery($query);
         $id = $db->loadResult();
         // if 404 exists, rewrite it to the new URL
         if (!is_null($id)) {
             // TODO: update meta tags
             $sqlId = !empty($Itemid) ? ", `Itemid` = '{$Itemid}'" : '';
             $query = "UPDATE `#__sefurls` SET `origurl` = " . $db->Quote(html_entity_decode(urldecode($url))) . "{$sqlId}, `priority` = " . $db->Quote($priority) . " WHERE `id` = '{$id}' LIMIT 1";
             $db->setQuery($query);
             // 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);
             }
             return;
         }
     }
     // No URL found
     $col = $val = '';
     if (!empty($Itemid)) {
         $col = ', `Itemid`';
         $val = ", '{$Itemid}'";
     }
     $metakeys = $metavals = '';
     if (is_array($metadata) && count($metadata) > 0) {
         foreach ($metadata as $metakey => $metaval) {
             $metakeys .= ", `{$metakey}`";
             $metavals .= ", " . $db->Quote($metaval);
         }
     }
     // get trace information if set to
     $sefConfig =& SEFConfig::getConfig();
     if (@$sefConfig->trace) {
         $traceinfo = $db->Quote(JoomSEF::_getDebugInfo($sefConfig->traceLevel));
     } else {
         $traceinfo = "NULL";
     }
     // Sitemap default values
     $sm_indexed = isset($sitemapParams['indexed']) ? $sitemapParams['indexed'] : ($sefConfig->sitemap_indexed ? 1 : 0);
     $sm_date = date('Y-m-d');
     $sm_frequency = isset($sitemapParams['frequency']) ? $sitemapParams['frequency'] : $sefConfig->sitemap_frequency;
     $sm_priority = isset($sitemapParams['priority']) ? $sitemapParams['priority'] : $sefConfig->sitemap_priority;
     $autolock = (int) $sefConfig->autolock_urls;
     $query = 'INSERT INTO `#__sefurls` (`sefurl`, `origurl`, `priority`' . $col . $metakeys . ', `trace`, `sm_indexed`, `sm_date`, `sm_frequency`, `sm_priority`, `locked`, `host`) ' . "VALUES (" . $db->Quote($temploc) . ", " . $db->Quote(html_entity_decode(urldecode($url))) . ", " . $db->Quote($priority) . $val . $metavals . ", " . $traceinfo . ", '{$sm_indexed}', '{$sm_date}', '{$sm_frequency}', '{$sm_priority}', '{$autolock}', '{$host}')";
     $db->setQuery($query);
     // if error occured
     if (!$db->query()) {
         $msg = JText::_('Could not save the SEF URL to database');
         if (JDEBUG) {
             $msg .= ': ' . $db->getErrorMsg();
         }
         JError::raiseError('JoomSEF Error', $msg);
     }
 }