Beispiel #1
0
 function _newVars($old_uri, $sef_url, $query, $lang = null)
 {
     $mainframe = JFactory::getApplication();
     $vars = array();
     // A quick fix for not loading translated menus
     if (!empty($lang)) {
         $sef_url = $lang . '/' . $sef_url;
     }
     $row = AcesefCache::checkURL($sef_url, true);
     if (is_object($row) && AcesefUtility::getParam($row->params, 'published') == '1') {
         // Use the already created URL
         $url_real = $row->url_real;
         // Update hits
         AceDatabase::query("UPDATE #__acesef_urls SET hits = (hits+1) WHERE id = '{$row->id}'");
         // Set query string
         $url_real = str_replace('&', '&', $url_real);
         $QUERY_STRING = str_replace('index.php?', '', $url_real);
         parse_str($QUERY_STRING, $vars);
         // Set mainframe vars
         $mainframe->set('acesef.url.id', $row->id);
         $mainframe->set('acesef.url.sef', $row->url_sef);
         $mainframe->set('acesef.url.real', $row->url_real);
         $mainframe->set('acesef.url.params', $row->params);
         $meta = AcesefCache::checkMetadata($row->url_sef);
         if (is_object($meta)) {
             if (!empty($meta->title)) {
                 $mainframe->set('acesef.meta.title', $meta->title);
             }
             if (!empty($meta->description)) {
                 $mainframe->set('acesef.meta.desc', $meta->description);
             }
             if (!empty($meta->keywords)) {
                 $mainframe->set('acesef.meta.key', $meta->keywords);
             }
             if (!empty($meta->lang)) {
                 $mainframe->set('acesef.meta.lang', $meta->lang);
             }
             if (!empty($meta->robots)) {
                 $mainframe->set('acesef.meta.robots', $meta->robots);
             }
             if (!empty($meta->google)) {
                 $mainframe->set('acesef.meta.google', $meta->google);
             }
             if (!empty($meta->canonical)) {
                 $mainframe->set('acesef.link.canonical', $meta->canonical);
             }
         }
     } else {
         // Moved URL
         $m_url = $sef_url;
         if (!empty($query)) {
             $m_url .= '?' . $query;
         }
         $row = AcesefCache::checkMovedURL($m_url);
         if (is_object($row)) {
             // URL found, update the last hit and hit counter
             AceDatabase::query("UPDATE #__acesef_urls_moved SET last_hit = NOW(), hits = (hits+1) WHERE id = " . $row->id);
             $root = JURI::root();
             $f = $l = '';
             if (!headers_sent($f, $l)) {
                 // Let's build absolute URL from our link
                 if (strstr($row->url_new, $root) === false) {
                     if (preg_match("/^(https?|ftps?|itpc|telnet|gopher):\\/\\//i", $row->url_new)) {
                         $url = $row->url_new;
                     } else {
                         $url = $root;
                         if (substr($url, -1) != '/') {
                             $url .= '/';
                         }
                         if (substr($row->url_new, 0, 1) == '/') {
                             $row->url_new = substr($row->url_new, 1);
                         }
                         $url .= $row->url_new;
                     }
                 } else {
                     $url = $row->url_new;
                 }
                 // Use the link to redirect
                 header('HTTP/1.1 301 Moved Permanently');
                 header('Location: ' . $url);
                 header('Connection: close');
                 exit;
             } else {
                 self::headers_sent_error($f, $l, __FILE__, __LINE__);
             }
         } elseif ($this->AcesefConfig->jsef_to_acesef == 1) {
             // Joomla! SEF to AceSEF
             $juri = clone $old_uri;
             $router = $mainframe->get('acesef.global.jrouter');
             $jvars = $router->parse($old_uri);
             if (!empty($jvars) && (!empty($jvars['option']) || !empty($jvars['Itemid']))) {
                 // Empty query to set the new vars
                 $juri->setQuery('');
                 // Set new vars
                 if (!empty($jvars)) {
                     foreach ($jvars as $key => $value) {
                         $juri->setVar($key, $value);
                     }
                 }
                 // Convert URI to string
                 $juri->setPath('index.php');
                 $real_url = $juri->toString(array('path', 'query', 'fragment'));
                 if (!empty($real_url)) {
                     // Generate the new SEF URL using AceSEF
                     $new_sef_url = JRoute::_($real_url);
                     // Remove path from the URL that will be stored in db
                     $path = str_replace($juri->getScheme(), '', JURI::root());
                     $path = str_replace($juri->getHost(), '', $path);
                     $path = str_replace('://', '', $path);
                     $db_sef_url = str_replace($path, '', $new_sef_url);
                     // Store it to Moved URLs
                     AceDatabase::query("INSERT IGNORE INTO #__acesef_urls_moved (url_old, url_new) VALUES (" . AceDatabase::quote($sef_url) . ", " . AceDatabase::quote($db_sef_url) . ")");
                     $f = $l = '';
                     if (count($_POST) == 0 && !headers_sent($f, $l)) {
                         // Use the link to redirect
                         header('HTTP/1.1 301 Moved Permanently');
                         header('Location: ' . $new_sef_url);
                         header('Connection: close');
                         exit;
                     } else {
                         self::headers_sent_error($f, $l, __FILE__, __LINE__);
                     }
                 }
             }
         }
     }
     return $vars;
 }