Exemple #1
0
 function beforeBuild(&$uri)
 {
     Mijosef::get('uri')->fixUriVar($uri, 'id');
     Mijosef::get('uri')->fixUriVar($uri, 'catid');
     // Change task=view to view=article for old urls
     if (!is_null($uri->getVar('task')) && $uri->getVar('task') == 'view') {
         $uri->delVar('task');
         $uri->setVar('view', 'article');
     }
     if (is_null($uri->getVar('limitstart')) && !is_null($uri->getVar('start'))) {
         $uri->setVar('limitstart', $uri->getVar('start'));
         $uri->delVar('start');
     }
     // Remove the limitstart and limit variables if they point to the first page
     if (is_null($uri->getVar('limitstart')) || $uri->getVar('limitstart') == '0') {
         $uri->delVar('limitstart');
         $uri->delVar('limit');
     }
     if (!is_null($uri->getVar('view')) && $uri->getVar('view') == 'article' && (is_null($uri->getVar('catid')) || $uri->getVar('catid') == 0) && !is_null($uri->getVar('id'))) {
         $catid = self::_getItemCatId(intval($uri->getVar('id')));
         if (!empty($catid)) {
             $uri->setVar('catid', $catid);
         }
     }
     // Add the view variable if it's not set
     if (!self::_is16()) {
         if (is_null($uri->getVar('view'))) {
             if (is_null($uri->getVar('id'))) {
                 $uri->setVar('view', 'frontpage');
             } else {
                 $uri->setVar('view', 'article');
             }
         }
     } else {
         if (is_null($uri->getVar('view'))) {
             if (is_null($uri->getVar('limitstart'))) {
                 $uri->setVar('view', 'categories');
             } elseif (is_null($uri->getVar('id'))) {
                 $uri->setVar('view', 'featured');
             } else {
                 $uri->setVar('view', 'category');
             }
         }
     }
     // Fix for AlphaContent
     if (!is_null($uri->getVar('directory'))) {
         $uri->delVar('directory');
     }
     if ($this->params->get('smart_itemid', '1') == '2' && !is_null($uri->getVar('view'))) {
         if (!class_exists('ContentRoute')) {
             return;
         }
         if (!method_exists('ContentRoute', '_findItemExt')) {
             return;
         }
         if (!self::_is16() && $uri->getVar('view') == 'section' && !is_null($uri->getVar('id'))) {
             $id = $uri->getVar('id');
             $needles = array('section' => (int) $id);
             $item = ContentRoute::_findItemExt($needles);
             if (!empty($item)) {
                 $uri->setVar('Itemid', $item->id);
             }
         }
         if ($uri->getVar('view') == 'category' && !is_null($uri->getVar('id'))) {
             $id = $uri->getVar('id');
             if (self::_is16()) {
                 $needles = array('category' => array((int) $id));
             } else {
                 $needles = array('category' => (int) $id);
             }
             $item = ContentRoute::_findItemExt($needles);
             if (!empty($item)) {
                 if (self::_is16()) {
                     $uri->setVar('Itemid', $item);
                 } else {
                     $uri->setVar('Itemid', $item->id);
                 }
             }
         }
         if ($uri->getVar('view') == 'article' && !is_null($uri->getVar('id'))) {
             $id = $uri->getVar('id');
             $catid = 0;
             if (!is_null($uri->getVar('catid'))) {
                 $catid = $uri->getVar('catid');
             }
             if (self::_is16()) {
                 $needles = array('article' => array((int) $id), 'category' => array((int) $catid));
             } else {
                 $needles = array('article' => (int) $id, 'category' => (int) $catid, 'section' => 0);
             }
             $item = ContentRoute::_findItemExt($needles);
             if (!empty($item)) {
                 if (self::_is16()) {
                     $uri->setVar('Itemid', $item);
                 } else {
                     $uri->setVar('Itemid', $item->id);
                 }
             }
         }
     }
 }