[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

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

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


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