[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

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

   1  <?php
   2  /**
   3   * @version        $Id: router.php 7380 2007-05-06 21:26:03Z eddieajau $
   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 ContactBuildRoute(&$query)
  15  {
  16      static $items;
  17  
  18      $segments    = array();
  19      $itemid        = null;
  20  
  21      // Get the menu items for this component.
  22      if (!$items) {
  23          $component    = &JComponentHelper::getComponent('com_contact');
  24          $menu        = &JSite::getMenu();
  25          $items        = $menu->getItems('componentid', $component->id);
  26      }
  27  
  28      // Break up the contact id into numeric and alias values.
  29      if (isset($query['id']) && strpos($query['id'], ':')) {
  30          list($query['id'], $query['alias']) = explode(':', $query['id'], 2);
  31      }
  32  
  33      // Break up the category id into numeric and alias values.
  34      if (isset($query['catid']) && strpos($query['catid'], ':')) {
  35          list($query['catid'], $query['catalias']) = explode(':', $query['catid'], 2);
  36      }
  37  
  38      // Search for an appropriate menu item.
  39      if (is_array($items))
  40      {
  41          // If only the option and itemid are specified in the query, return that item.
  42          if (!isset($query['view']) && !isset($query['id']) && !isset($query['catid']) && isset($query['Itemid'])) {
  43              $itemid = (int) $query['Itemid'];
  44          }
  45  
  46          // Search for a specific link based on the critera given.
  47          if (!$itemid)
  48          {
  49              foreach ($items as $item)
  50              {
  51                  if (isset($item->id) && isset($query['Itemid']) 
  52                      && $item->id != $query['Itemid'])
  53                  {
  54                      continue;
  55                  }
  56                  // Check if this menu item links to this view.
  57                  if (isset($item->query['view']) && $item->query['view'] == 'contact'
  58                      && isset($query['view']) && $query['view'] == 'contact'
  59                      && isset($item->query['id']) && $item->query['id'] == $query['id'])
  60                  {
  61                      $itemid    = $item->id;
  62                  }
  63                  elseif (isset($item->query['view']) && $item->query['view'] == 'category'
  64                          && isset($query['view']) && $query['view'] == 'category'
  65                          && isset($item->query['catid']) && $item->query['catid'] == $query['catid'])
  66                  {
  67                      $itemid    = $item->id;
  68                  }
  69              }
  70          }
  71  
  72          // If no specific link has been found, search for a general one.
  73          if (!$itemid)
  74          {
  75              foreach ($items as $item)
  76              {
  77                  if (isset($item->id) && isset($query['Itemid']) 
  78                      && $item->id != $query['Itemid'])
  79                  {
  80                      continue;
  81                  }
  82                  if (isset($query['view']) && $query['view'] == 'contact' && !isset($item->query['catid'])
  83                      && isset($item->query['view']) && $item->query['view'] == 'category')
  84                  {
  85                      // Check for an undealt with contact id.
  86                      if (isset($query['id']))
  87                      {
  88                          // This menu item links to the contact view but we need to append the contact id to it.
  89                          $itemid        = $item->id;
  90                          $segments[]    = isset($query['catalias']) ? $query['catid'].':'.$query['catalias'] : $query['catid'];
  91                          $segments[]    = isset($query['alias']) ? $query['id'].':'.$query['alias'] : $query['id'];
  92                          break;
  93                      }
  94                  }
  95                  elseif (isset($query['view']) && $query['view'] == 'category'
  96                      && isset($item->query['view']) && $item->query['view'] == 'category'
  97                      && isset($item->query['id']) && $item->query['id'] != $query['id'])
  98                  {
  99                      // Check for an undealt with category id.
 100                      if (isset($query['catid']))
 101                      {
 102                          // This menu item links to the category view but we need to append the category id to it.
 103                          $itemid        = $item->id;
 104                          $segments[]    = isset($query['alias']) ? $query['id'].':'.$query['alias'] : $query['id'];
 105                          break;
 106                      }
 107                  }
 108              }
 109          }
 110      }
 111  
 112      // Check if the router found an appropriate itemid.
 113      if (!$itemid)
 114      {
 115          // Check if a catid was specified.
 116          if (isset($query['catid']))
 117          {
 118              if (isset($query['catalias'])) {
 119                  $query['catid'] .= ':'.$query['catalias'];
 120              }
 121  
 122              $segments[] = $query['catid'];
 123  
 124              unset($query['view']);
 125              unset($query['catid']);
 126              unset($query['catalias']);
 127          }
 128  
 129          // Check if a id was specified.
 130          if (isset($query['id']))
 131          {
 132              if (isset($query['alias'])) {
 133                  $query['id'] .= ':'.$query['alias'];
 134              }
 135  
 136              // Push the id onto the stack.
 137              $segments[] = $query['id'];
 138  
 139              unset($query['view']);
 140              unset($query['id']);
 141              unset($query['alias']);
 142          }
 143      }
 144      else
 145      {
 146          $query['Itemid'] = $itemid;
 147  
 148          // Remove the unnecessary URL segments.
 149          unset($query['view']);
 150          unset($query['id']);
 151          unset($query['alias']);
 152          unset($query['catid']);
 153          unset($query['catalias']);
 154      }
 155  
 156      return $segments;
 157  }
 158  
 159  function ContactParseRoute($segments)
 160  {
 161      $vars    = array();
 162  
 163      // Get the active menu item.
 164      $menu    = &JSite::getMenu();
 165      $item    = &$menu->getActive();
 166  
 167      // Check if we have a valid menu item.
 168      if (is_object($item))
 169      {
 170          // Proceed through the possible variations trying to match the most specific one.
 171          if (isset($item->query['view']) && $item->query['view'] == 'contact' && isset($segments[0]))
 172          {
 173              // Break up the contact id into numeric and alias values.
 174              if (isset($segments[1]) && strpos($segments[1], ':')) {
 175                  list($id, $alias) = explode(':', $segments[1], 2);
 176              }
 177  
 178              // Contact view.
 179              $vars['view']    = 'contact';
 180              $vars['id']        = $id;
 181          }
 182          elseif (isset($item->query['view']) && $item->query['view'] == 'category' && count($segments) == 2)
 183          {
 184              // Break up the category id into numeric and alias values.
 185              if (isset($segments[0]) && strpos($segments[0], ':')) {
 186                  list($catid, $catalias) = explode(':', $segments[0], 2);
 187              }
 188  
 189              // Break up the contact id into numeric and alias values.
 190              if (isset($segments[1]) && strpos($segments[1], ':')) {
 191                  list($id, $alias) = explode(':', $segments[1], 2);
 192              }
 193  
 194              // Contact view.
 195              $vars['view']    = 'contact';
 196              $vars['id']        = $id;
 197              $vars['catid']    = $catid;
 198  
 199          }
 200          elseif (isset($item->query['view']) && $item->query['view'] == 'category' && isset($segments[0]))
 201          {
 202              // Break up the category id into numeric and alias values.
 203              if (isset($segments[0]) && strpos($segments[0], ':')) {
 204                  list($catid, $alias) = explode(':', $segments[0], 2);
 205              }
 206  
 207              // Category view.
 208              $vars['view']    = 'category';
 209              $vars['catid']    = $catid;
 210          }
 211      }
 212      else
 213      {
 214          // Count route segments
 215          $count = count($segments);
 216  
 217          // Check if there are any route segments to handle.
 218          if ($count)
 219          {
 220              if ($count == 2)
 221              {
 222                  // We are viewing a contact.
 223                  $vars['view']    = 'contact';
 224                  $vars['id']        = $segments[$count-1];
 225                  $vars['catid']    = $segments[$count-2];
 226              }
 227              else
 228              {
 229                  // We are viewing a category.
 230                  $vars['view']    = 'category';
 231                  $vars['catid']    = $segments[$count-1];
 232              }
 233          }
 234      }
 235  
 236      return $vars;
 237  }


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