Example #1
0
 function getMenuTitle($Itemid, $start_level = 0, $length_level = 0)
 {
     if (empty($Itemid)) {
         return array();
     }
     static $menus = array();
     $id = $Itemid;
     if (!isset($menus[$id])) {
         $joomfish = $this->AcesefConfig->joomfish_trans_url ? ', id' : '';
         // Title or Alias
         $part = 'name';
         if ($this->AcesefConfig->menu_url_part == 'alias') {
             $part = 'alias';
         }
         $menus[$id] = array();
         while ($Itemid > 0) {
             $row = AceDatabase::loadObject("SELECT {$part} AS name, parent{$joomfish} FROM #__menu WHERE id = '{$Itemid}' AND published > 0");
             if (is_null($row)) {
                 break;
             }
             array_unshift($menus[$id], $row->name);
             $Itemid = $row->parent;
             if ($this->AcesefConfig->parent_menus == '0') {
                 break;
                 //  Only last one
             }
         }
     }
     if ($this->AcesefConfig->parent_menus == '1' && ($start_level != 0 || $length_level != 0) && !empty($menus[$id])) {
         if ($length_level != 0) {
             return array_slice($menus[$id], $start_level, $length_level);
         } else {
             return array_slice($menus[$id], $start_level);
         }
     }
     return $menus[$id];
 }
Example #2
0
 function parseURI($uri, $old_uri)
 {
     $mainframe = JFactory::getApplication();
     $vars = array();
     $route = $uri->getPath();
     $lang = $uri->getVar('lang');
     // Get the variables from the uri
     $vars = $uri->getQuery(true);
     // Handle an empty URL (special case)
     if (empty($route)) {
         self::determineLanguage(JRequest::getVar('lang'));
         $menu =& AcesefUtility::getMenu();
         // if route is empty AND option is set in the query, assume it's non-sef url, and parse apropriately
         if (isset($vars['option']) || isset($vars['Itemid'])) {
             return self::_parseRawRoute($uri);
         }
         $item = $menu->getDefault();
         //Set the information in the request
         $vars = $item->query;
         //Get the itemid
         $vars['Itemid'] = $item->id;
         // Set the active menu item
         $menu->setActive($vars['Itemid']);
         // Set mainframe vars
         $row = AcesefCache::checkURL('', true);
         if (is_object($row) && AcesefUtility::getParam($row->params, 'published') == '1') {
             $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);
                 }
             }
         }
         return $vars;
     }
     $q = $uri->getQuery();
     $new_vars = self::_newVars($old_uri, $route, $q, $lang);
     // Joomfish
     $lang = isset($new_vars['lang']) ? $new_vars['lang'] : (isset($vars['lang']) ? $vars['lang'] : null);
     self::determineLanguage($lang);
     if (!empty($new_vars) && !empty($vars)) {
         // If this was SEF url, consider the vars in query as nonsef
         $non_sef_vars = array_diff_key($vars, $new_vars);
         if (!empty($non_sef_vars)) {
             $mainframe->set('acesef.global.nonsefvars', $non_sef_vars);
         }
     }
     if (!empty($vars)) {
         // append the original query string because some components
         // (like SMF Bridge and SOBI2) use it
         $vars = array_merge($vars, $new_vars);
     } else {
         $vars = $new_vars;
     }
     if (!empty($new_vars)) {
         self::sendHeader('HTTP/1.0 200 OK');
     } else {
         // set nonsef vars
         $mainframe->set('acesef.global.nonsefvars', $vars);
         // Check if 404 records should be saved in DB
         if ($this->AcesefConfig->db_404_errors == 1) {
             $routee = AceDatabase::quote($route);
             $found = AceDatabase::loadObject("SELECT url_sef FROM #__acesef_urls WHERE url_sef = {$routee} AND params LIKE '%notfound=1%' LIMIT 1");
             if ($found) {
                 // Found, update hits
                 AceDatabase::query("UPDATE #__acesef_urls SET hits = (hits+1) WHERE url_sef = {$routee}");
             } else {
                 // Save 404 URL
                 $params = "custom=0";
                 $params .= "\npublished=0";
                 $params .= "\nlocked=0";
                 $params .= "\nblocked=0";
                 $params .= "\ntrashed=0";
                 $params .= "\nnotfound=1";
                 $params .= "\ntags=0";
                 $params .= "\nilinks=0";
                 $params .= "\nbookmarks=0";
                 $params .= "\nvisited=0";
                 $params .= "\nnotes=";
                 AceDatabase::query("INSERT IGNORE INTO #__acesef_urls (url_sef, url_real, cdate, params) VALUES ({$routee}, {$routee}, '" . date('Y-m-d H:i:s') . "', '{$params}')");
             }
         }
         // Check if should be written to a logfile
         if ($this->AcesefConfig->log_404_errors == '1' && $this->AcesefConfig->log_404_path != '') {
             AcesefUtility::import('library.error');
             AcesefError::logNotFoundURL($route);
         }
         if ($this->AcesefConfig->page404 == 'custom') {
             $_404 = '404' . $this->AcesefConfig->url_suffix;
             if ($url_real = AceDatabase::loadResult("SELECT url_real FROM #__acesef_urls WHERE url_sef = '{$_404}'")) {
                 $url_real = str_replace('&', '&', $url_real);
                 $QUERY_STRING = str_replace('index.php?', '', $url_real);
                 parse_str($QUERY_STRING, $vars);
                 if (!empty($vars['Itemid'])) {
                     AcesefUtility::getMenu()->setActive($vars['Itemid']);
                 }
             } elseif ($id = AceDatabase::loadResult("SELECT id FROM #__content WHERE title = '404' AND state = '1'")) {
                 $vars['option'] = 'com_content';
                 $vars['view'] = 'article';
                 $vars['id'] = $id;
                 $vars['Itemid'] = 99999;
             } else {
                 die(JText::_('ERROR_DEFAULT_404') . 'FILE NOT FOUND: ' . $route . "<br />URI:" . $_SERVER['REQUEST_URI']);
             }
         } elseif ($this->AcesefConfig->page404 == 'home') {
             $menu =& AcesefUtility::getMenu();
             $item = $menu->getDefault();
             //Get the vars
             $vars = $item->query;
             $vars['Itemid'] = $item->id;
             $menu->setActive($vars['Itemid']);
         }
         self::sendHeader('HTTP/1.0 404 NOT FOUND');
     }
     // Set QUERY_STRING if set to
     if ($this->AcesefConfig->set_query_string == 1) {
         $qs = array();
         foreach ($vars as $name => $val) {
             if (is_array($val)) {
                 foreach ($val as $k => $v) {
                     $qs[] = $name . '[' . $k . ']=' . urlencode($v);
                 }
             } else {
                 $qs[] = $name . '=' . urlencode($val);
             }
         }
         $qs = implode('&', $qs);
         if (!empty($qs)) {
             $_SERVER['QUERY_STRING'] = $qs;
         }
     }
     return $vars;
 }