[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/components/com_content/ -> router.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: router.php 14401 2010-01-26 14:10:00Z louis $
   4  * @package        Joomla
   5  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   6  * @license        GNU/GPL, see LICENSE.php
   7  * Joomla! is free software. This version may have been modified pursuant
   8  * to the GNU General Public License, and as distributed it includes or
   9  * is derivative of works licensed under the GNU General Public License or
  10  * other free or open source software licenses.
  11  * See COPYRIGHT.php for copyright notices and details.
  12  */
  13  
  14  function ContentBuildRoute(&$query)
  15  {
  16      $segments = array();
  17  
  18      // get a menu item based on Itemid or currently active
  19      $menu = &JSite::getMenu();
  20      if (empty($query['Itemid'])) {
  21          $menuItem = &$menu->getActive();
  22      } else {
  23          $menuItem = &$menu->getItem($query['Itemid']);
  24      }
  25      $mView    = (empty($menuItem->query['view'])) ? null : $menuItem->query['view'];
  26      $mCatid    = (empty($menuItem->query['catid'])) ? null : $menuItem->query['catid'];
  27      $mId    = (empty($menuItem->query['id'])) ? null : $menuItem->query['id'];
  28  
  29      if(isset($query['view']))
  30      {
  31          $view = $query['view'];
  32          if(empty($query['Itemid'])) {
  33              $segments[] = $query['view'];
  34          }
  35          unset($query['view']);
  36      };
  37  
  38      // are we dealing with an article that is attached to a menu item?
  39      if (($mView == 'article') and (isset($query['id'])) and ($mId == intval($query['id']))) {
  40          unset($query['view']);
  41          unset($query['catid']);
  42          unset($query['id']);
  43      }
  44  
  45      if (isset($view) and ($view == 'section' && !empty($query['Itemid']))) {
  46          if (($mView != 'section') or ($mView == 'section' and $mId != intval($query['id']))) {
  47              $segments[] = 'section';
  48              unset($query['Itemid']);
  49          }
  50      }
  51  
  52      if (isset($view) and $view == 'category') {
  53          if ($mId != intval($query['id']) || $mView != $view) {
  54              $segments[] = $query['id'];
  55          }
  56          unset($query['id']);
  57      }
  58  
  59      if (isset($query['catid'])) {
  60          // if we are routing an article or category where the category id matches the menu catid, don't include the category segment
  61          if ((($view == 'article') and ($mView != 'category') and ($mView != 'article') and ($mCatid != intval($query['catid'])))) {
  62              $segments[] = $query['catid'];
  63          }
  64          unset($query['catid']);
  65      };
  66  
  67      if(isset($query['id'])) {
  68          if (empty($query['Itemid'])) {
  69              $segments[] = $query['id'];
  70          } else {
  71              if (isset($menuItem->query['id'])) {
  72                  if($query['id'] != $mId) {
  73                      $segments[] = $query['id'];
  74                  }
  75              } else {
  76                  $segments[] = $query['id'];
  77              }
  78          }
  79          unset($query['id']);
  80      };
  81  
  82      if(isset($query['year'])) {
  83  
  84          if(!empty($query['Itemid'])) {
  85              $segments[] = $query['year'];
  86              unset($query['year']);
  87          }
  88      };
  89  
  90      if(isset($query['month'])) {
  91  
  92          if(!empty($query['Itemid'])) {
  93              $segments[] = $query['month'];
  94              unset($query['month']);
  95          }
  96      };
  97  
  98      if(isset($query['layout']))
  99      {
 100          if(!empty($query['Itemid']) && isset($menuItem->query['layout'])) {
 101              if ($query['layout'] == $menuItem->query['layout']) {
 102  
 103                  unset($query['layout']);
 104              }
 105          } else {
 106              if($query['layout'] == 'default') {
 107                  unset($query['layout']);
 108              }
 109          }
 110      };
 111  
 112      return $segments;
 113  }
 114  
 115  function ContentParseRoute($segments)
 116  {
 117      $vars = array();
 118  
 119      //Get the active menu item
 120      $menu =& JSite::getMenu();
 121      $item =& $menu->getActive();
 122  
 123      // Count route segments
 124      $count = count($segments);
 125  
 126      //Standard routing for articles
 127      if(!isset($item))
 128      {
 129          $vars['view']  = $segments[0];
 130          $vars['id']    = $segments[$count - 1];
 131          return $vars;
 132      }
 133  
 134      //Handle View and Identifier
 135      switch($item->query['view'])
 136      {
 137          case 'section' :
 138          {
 139              if($count == 1) {
 140                  $vars['view'] = 'category';
 141  
 142                  if(isset($item->query['layout']) && $item->query['layout'] == 'blog') {
 143                      $vars['layout'] = 'blog';
 144                  }
 145              }
 146  
 147              if($count == 2) {
 148                  $vars['view']  = 'article';
 149                  $vars['catid'] = $segments[$count-2];
 150              }
 151  
 152              $vars['id']    = $segments[$count-1];
 153  
 154          } break;
 155  
 156          case 'category'   :
 157          {
 158              $vars['id']   = $segments[$count-1];
 159              $vars['view'] = 'article';
 160  
 161          } break;
 162  
 163          case 'frontpage'   :
 164          {
 165              $vars['id']   = $segments[$count-1];
 166              $vars['view'] = 'article';
 167  
 168          } break;
 169  
 170          case 'article' :
 171          {
 172              $vars['id']      = $segments[$count-1];
 173              $vars['view'] = 'article';
 174          } break;
 175  
 176          case 'archive' :
 177          {
 178              if($count != 1)
 179              {
 180                  $vars['year']  = $count >= 2 ? $segments[$count-2] : null;
 181                  $vars['month'] = $segments[$count-1];
 182                  $vars['view']  = 'archive';
 183              } else {
 184                  $vars['id']      = $segments[$count-1];
 185                  $vars['view'] = 'article';
 186              }
 187          }
 188      }
 189  
 190      return $vars;
 191  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1