[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

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

   1  <?php
   2  /**
   3   * @package        Joomla.Site
   4   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   5   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   6   */
   7  
   8  defined('_JEXEC') or die;
   9  
  10  jimport('joomla.application.categories');
  11  
  12  /**
  13   * Build the route for the com_contact component
  14   *
  15   * @param    array    An array of URL arguments
  16   *
  17   * @return    array    The URL arguments to use to assemble the subsequent URL.
  18   */
  19  function ContactBuildRoute(&$query){
  20      $segments = array();
  21  
  22      // get a menu item based on Itemid or currently active
  23      $app    = JFactory::getApplication();
  24      $menu    = $app->getMenu();
  25      $params    = JComponentHelper::getParams('com_contact');
  26      $advanced = $params->get('sef_advanced_link', 0);
  27  
  28      if (empty($query['Itemid'])) {
  29          $menuItem = $menu->getActive();
  30      } else {
  31          $menuItem = $menu->getItem($query['Itemid']);
  32      }
  33      $mView    = (empty($menuItem->query['view'])) ? null : $menuItem->query['view'];
  34      $mCatid    = (empty($menuItem->query['catid'])) ? null : $menuItem->query['catid'];
  35      $mId    = (empty($menuItem->query['id'])) ? null : $menuItem->query['id'];
  36  
  37      if (isset($query['view']))
  38      {
  39          $view = $query['view'];
  40          if (empty($query['Itemid'])) {
  41              $segments[] = $query['view'];
  42          }
  43          unset($query['view']);
  44      };
  45  
  46      // are we dealing with a contact that is attached to a menu item?
  47      if (isset($view) && ($mView == $view) and (isset($query['id'])) and ($mId == intval($query['id']))) {
  48          unset($query['view']);
  49          unset($query['catid']);
  50          unset($query['id']);
  51          return $segments;
  52      }
  53  
  54      if (isset($view) and ($view == 'category' or $view == 'contact')) {
  55          if ($mId != intval($query['id']) || $mView != $view) {
  56              if($view == 'contact' && isset($query['catid']))
  57              {
  58                  $catid = $query['catid'];
  59              } elseif(isset($query['id'])) {
  60                  $catid = $query['id'];
  61              }
  62              $menuCatid = $mId;
  63              $categories = JCategories::getInstance('Contact');
  64              $category = $categories->get($catid);
  65              if($category)
  66              {
  67                  //TODO Throw error that the category either not exists or is unpublished
  68                  $path = array_reverse($category->getPath());
  69  
  70                  $array = array();
  71                  foreach($path as $id)
  72                  {
  73                      if((int) $id == (int)$menuCatid)
  74                      {
  75                          break;
  76                      }
  77                      if($advanced)
  78                      {
  79                          list($tmp, $id) = explode(':', $id, 2);
  80                      }
  81                      $array[] = $id;
  82                  }
  83                  $segments = array_merge($segments, array_reverse($array));
  84              }
  85              if($view == 'contact')
  86              {
  87                  if($advanced)
  88                  {
  89                      list($tmp, $id) = explode(':', $query['id'], 2);
  90                  } else {
  91                      $id = $query['id'];
  92                  }
  93                  $segments[] = $id;
  94              }
  95          }
  96          unset($query['id']);
  97          unset($query['catid']);
  98      }
  99  
 100      if (isset($query['layout']))
 101      {
 102          if (!empty($query['Itemid']) && isset($menuItem->query['layout']))
 103          {
 104              if ($query['layout'] == $menuItem->query['layout']) {
 105  
 106                  unset($query['layout']);
 107              }
 108          }
 109          else
 110          {
 111              if ($query['layout'] == 'default') {
 112                  unset($query['layout']);
 113              }
 114          }
 115      };
 116  
 117      return $segments;
 118  }
 119  /**
 120   * Parse the segments of a URL.
 121   *
 122   * @param    array    The segments of the URL to parse.
 123   *
 124   * @return    array    The URL attributes to be used by the application.
 125   */
 126  function ContactParseRoute($segments)
 127  {
 128      $vars = array();
 129  
 130      //Get the active menu item.
 131      $app    = JFactory::getApplication();
 132      $menu    = $app->getMenu();
 133      $item    = $menu->getActive();
 134      $params = JComponentHelper::getParams('com_contact');
 135      $advanced = $params->get('sef_advanced_link', 0);
 136  
 137      // Count route segments
 138      $count = count($segments);
 139  
 140      // Standard routing for newsfeeds.
 141      if (!isset($item))
 142      {
 143          $vars['view']    = $segments[0];
 144          $vars['id']        = $segments[$count - 1];
 145          return $vars;
 146      }
 147  
 148      // From the categories view, we can only jump to a category.
 149      $id = (isset($item->query['id']) && $item->query['id'] > 1) ? $item->query['id'] : 'root';
 150      $categories = JCategories::getInstance('Contact')->get($id)->getChildren();
 151      $vars['catid'] = $id;
 152      $vars['id'] = $id;
 153      $found = 0;
 154      foreach($segments as $segment)
 155      {
 156          $segment = $advanced ? str_replace(':', '-', $segment) : $segment;
 157          foreach($categories as $category)
 158          {
 159              if ($category->slug == $segment || $category->alias == $segment)
 160              {
 161                  $vars['id'] = $category->id;
 162                  $vars['catid'] = $category->id;
 163                  $vars['view'] = 'category';
 164                  $categories = $category->getChildren();
 165                  $found = 1;
 166                  break;
 167              }
 168          }
 169          if ($found == 0)
 170          {
 171              if($advanced)
 172              {
 173                  $db = JFactory::getDBO();
 174                  $query = 'SELECT id FROM #__contact_details WHERE catid = '.$vars['catid'].' AND alias = '.$db->Quote($segment);
 175                  $db->setQuery($query);
 176                  $nid = $db->loadResult();
 177              } else {
 178                  $nid = $segment;
 179              }
 180              $vars['id'] = $nid;
 181              $vars['view'] = 'contact';
 182          }
 183          $found = 0;
 184      }
 185      return $vars;
 186  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1