Esempio n. 1
0
 function build(&$siteRouter, &$uri)
 {
     // Get correct URL for JoomSEF (menu items containing only Itemid, not option) and store the original path
     $origPath = $uri->getPath();
     $url = JoomSefUri::getUri($uri);
     $option = $uri->getVar('option');
     // Security - only allow colon in protocol part
     if (strpos($url, ':') !== false) {
         $offset = 0;
         if (substr($url, 0, 5) == 'http:') {
             $offset = 5;
         } elseif (substr($url, 0, 6) == 'https:') {
             $offset = 6;
         }
         $url = substr($url, 0, $offset) . str_replace(':', '%3A', substr($url, $offset));
     }
     // Fix the amp; as they shouldn't be present there - VirtueMart has problem with those
     $url = str_replace(array('?amp;', '&'), array('?', '&'), $url);
     // Update URI object
     JoomSefUri::updateUri($uri, $this->_prepareUrl($url));
     // Check the path part for URLs without mod_rewrite support
     $route = $uri->getPath();
     if (substr($route, 0, 10) == 'index.php/') {
         $route = substr($route, 10);
         $uri->setPath($route);
         return $uri;
     }
     // Last resort check for URLs that shouldn't be SEFed
     if (substr($route, 0, 9) != 'index.php') {
         return $uri;
     }
     // Set URI defaults
     $menu = JFactory::getApplication()->getMenu('site');
     // We don't want to add any variables if the URL is pure index.php
     if ($url != 'index.php') {
         // Get the itemid from the URI
         $Itemid = $uri->getVar('Itemid');
         if (is_null($Itemid)) {
             if ($option = $uri->getVar('option')) {
                 $item = $menu->getItem($this->joomlaRouter->getVar('Itemid'));
                 if (isset($item) && $item->component == $option) {
                     $uri->setVar('Itemid', $item->id);
                 }
             } else {
                 if ($Itemid = $this->joomlaRouter->getVar('Itemid')) {
                     $uri->setVar('Itemid', $Itemid);
                 }
             }
         }
         // If there is no option specified, try to get the query from menu item
         if (is_null($uri->getVar('option'))) {
             // Joomla pagination can generate only URL like ?limitstart=5 and Joomla router add into URL actual query automatically.
             if (count($vars = $uri->getQuery(true)) == 2 && isset($vars['Itemid']) && isset($vars['limitstart'])) {
                 foreach ($this->joomlaRouter->getVars() as $name => $value) {
                     if ($name != 'limitstart' && $name != 'start') {
                         $uri->setVar($name, $value);
                     }
                 }
                 if ($uri->getVar('limitstart') == 0) {
                     $uri->delVar('limitstart');
                 }
             } else {
                 if (!is_null($uri->getVar('Itemid'))) {
                     $item = $menu->getItem($uri->getVar('Itemid'));
                     $origId = $uri->getVar('Itemid');
                     while (is_object($item) && $item->type == 'alias') {
                         // Get aliased menu item
                         if (is_object($item->params)) {
                             $aliasId = $item->params->get('aliasoptions', null);
                             if (!is_null($aliasId) && $aliasId != $origId) {
                                 $item = $menu->getItem($aliasId);
                                 // Fix Itemid
                                 if (is_object($item)) {
                                     $uri->setVar('Itemid', $item->id);
                                 }
                             } else {
                                 break;
                             }
                         } else {
                             break;
                         }
                     }
                     if (is_object($item)) {
                         //$uri->setVar('option',$item->component);
                         foreach ($item->query as $k => $v) {
                             $test = $uri->getVar($k);
                             if (strlen($test) == 0) {
                                 $uri->setVar($k, $v);
                             }
                         }
                     }
                 } else {
                     // There is no option or Itemid specified, try to use current option
                     if ($option = $this->joomlaRouter->getVar('option')) {
                         $uri->setVar('option', $option);
                     }
                     // 10.6.2012 dajo: Removed, was behaving differently than Joomla router
                     //$item = $menu->getDefault();
                     // Workaround until Joomla menu bug will be fixed
                     //$items=$menu->getItems(array('home','language'),array('1','*'));
                     //$item=$items[0];
                     //if (is_object($item)) {
                     //    foreach($item->query as $k => $v) {
                     //        $uri->setVar($k, $v);
                     //    }
                     //    // Set Itemid
                     //    $uri->setVar('Itemid', $item->id);
                     //}
                 }
             }
         }
     } else {
         // Set the current menu item's query if set to
         // (default Joomla's behaviour)
         $sefConfig = SEFConfig::getConfig();
         if ($sefConfig->indexPhpCurrentMenu) {
             $itemid = $this->getVar('Itemid');
             if (!is_null($itemid)) {
                 $item = $menu->getItem($itemid);
                 if (is_object($item)) {
                     $uri->setQuery($item->query);
                     $uri->setVar('Itemid', $itemid);
                 }
             } else {
                 // Set at least option
                 $option = $this->getVar('option');
                 if (!is_null($option)) {
                     $uri->setVar('option', $option);
                 }
             }
         }
     }
     JoomSEF::build($uri);
     //$uri->setHost('joomla7.ar');
     // Combine original path with new path
     // It's not necesarry in new versions of Joomla and cause some problems
     /*$path = $uri->getPath();
       if ($path != "") {
           if (substr($origPath, 0, 10) == 'index.php/')
           {
               $origPath = substr($origPath, 10);
           }
           $path = rtrim($origPath, '/').$path;
       }
       $uri->setPath($path);*/
     return $uri;
 }
 function &build($url)
 {
     // Be tolerant to spaces around the URL
     $sefConfig =& SEFConfig::getConfig();
     if ($sefConfig->spaceTolerant) {
         $url = trim($url);
     }
     // Security - only allow colon in protocol part
     if (strpos($url, ':') !== false) {
         $offset = 0;
         if (substr($url, 0, 5) == 'http:') {
             $offset = 5;
         } elseif (substr($url, 0, 6) == 'https:') {
             $offset = 6;
         }
         $url = substr($url, 0, $offset) . str_replace(':', '%3A', substr($url, $offset));
     }
     // Create URI object
     $uri = $this->_createURI($url);
     // Check the path part for URLs without mod_rewrite support
     $route = $uri->getPath();
     if (substr($route, 0, 10) == 'index.php/') {
         $route = substr($route, 10);
         $uri->setPath($route);
         return $uri;
     }
     // Set URI defaults
     $menu =& JSite::getMenu();
     // We don't want to add any variables if the URL is pure index.php
     if ($url != 'index.php') {
         // Get the itemid from the URI
         $Itemid = $uri->getVar('Itemid');
         if (is_null($Itemid)) {
             if ($option = $uri->getVar('option')) {
                 $item = $menu->getItem($this->getVar('Itemid'));
                 if (isset($item) && $item->component == $option) {
                     $uri->setVar('Itemid', $item->id);
                 }
             } else {
                 if ($option = $this->getVar('option')) {
                     $uri->setVar('option', $option);
                 }
                 if ($Itemid = $this->getVar('Itemid')) {
                     $uri->setVar('Itemid', $Itemid);
                 }
             }
         }
         // If there is no option specified, try to get the query from menu item
         if (is_null($uri->getVar('option'))) {
             if (!is_null($uri->getVar('Itemid'))) {
                 $item = $menu->getItem($uri->getVar('Itemid'));
                 if (is_object($item)) {
                     foreach ($item->query as $k => $v) {
                         $uri->setVar($k, $v);
                     }
                 }
             } else {
                 // There is no option or Itemid specified, assume frontpage
                 $item = $menu->getDefault();
                 if (is_object($item)) {
                     foreach ($item->query as $k => $v) {
                         $uri->setVar($k, $v);
                     }
                     // Set Itemid
                     $uri->setVar('Itemid', $item->id);
                 }
             }
         }
     } else {
         // Set the current menu item's query if set to
         // (default Joomla's behaviour)
         if ($sefConfig->indexPhpCurrentMenu) {
             $itemid = $this->getVar('Itemid');
             if (!is_null($itemid)) {
                 $item = $menu->getItem($itemid);
                 if (is_object($item)) {
                     $uri->setQuery($item->query);
                     $uri->setVar('Itemid', $itemid);
                 }
             }
         }
     }
     JoomSEF::build($uri);
     return $uri;
 }