[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/components/com_weblinks/helpers/ -> route.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  // no direct access
  10  defined('_JEXEC') or die;
  11  
  12  // Component Helper
  13  jimport('joomla.application.component.helper');
  14  jimport('joomla.application.categories');
  15  
  16  /**
  17   * Weblinks Component Route Helper
  18   *
  19   * @static
  20   * @package        Joomla.Site
  21   * @subpackage    com_weblinks
  22   * @since 1.5
  23   */
  24  abstract class WeblinksHelperRoute
  25  {
  26      protected static $lookup;
  27  
  28      /**
  29       * @param    int    The route of the weblink
  30       */
  31  	public static function getWeblinkRoute($id, $catid)
  32      {
  33          $needles = array(
  34              'weblink'  => array((int) $id)
  35          );
  36  
  37          //Create the link
  38          $link = 'index.php?option=com_weblinks&view=weblink&id='. $id;
  39          if ($catid > 1) {
  40              $categories = JCategories::getInstance('Weblinks');
  41              $category = $categories->get($catid);
  42  
  43              if($category) {
  44                  $needles['category'] = array_reverse($category->getPath());
  45                  $needles['categories'] = $needles['category'];
  46                  $link .= '&catid='.$catid;
  47              }
  48          }
  49  
  50          if ($item = self::_findItem($needles)) {
  51              $link .= '&Itemid='.$item;
  52          }
  53          elseif ($item = self::_findItem()) {
  54              $link .= '&Itemid='.$item;
  55          }
  56  
  57          return $link;
  58      }
  59  
  60      /**
  61       * @param    int        $id        The id of the weblink.
  62       * @param    string    $return    The return page variable.
  63       */
  64  	public static function getFormRoute($id, $return = null)
  65      {
  66          // Create the link.
  67          if ($id) {
  68              $link = 'index.php?option=com_weblinks&task=weblink.edit&w_id='. $id;
  69          }
  70          else {
  71              $link = 'index.php?option=com_weblinks&task=weblink.add&w_id=0';
  72          }
  73  
  74          if ($return) {
  75              $link .= '&return='.$return;
  76          }
  77  
  78          return $link;
  79      }
  80  
  81  	public static function getCategoryRoute($catid)
  82      {
  83          if ($catid instanceof JCategoryNode) {
  84              $id = $catid->id;
  85              $category = $catid;
  86          }
  87          else {
  88              $id = (int) $catid;
  89              $category = JCategories::getInstance('Weblinks')->get($id);
  90          }
  91  
  92          if ($id < 1) {
  93              $link = '';
  94          }
  95          else {
  96              $needles = array(
  97                  'category' => array($id)
  98              );
  99  
 100              if ($item = self::_findItem($needles)) {
 101                  $link = 'index.php?Itemid='.$item;
 102              }
 103              else {
 104                  //Create the link
 105                  $link = 'index.php?option=com_weblinks&view=category&id='.$id;
 106  
 107                  if ($category) {
 108                      $catids = array_reverse($category->getPath());
 109                      $needles = array(
 110                          'category' => $catids,
 111                          'categories' => $catids
 112                      );
 113  
 114                      if ($item = self::_findItem($needles)) {
 115                          $link .= '&Itemid='.$item;
 116                      }
 117                      elseif ($item = self::_findItem()) {
 118                          $link .= '&Itemid='.$item;
 119                      }
 120                  }
 121              }
 122          }
 123  
 124          return $link;
 125      }
 126  
 127  	protected static function _findItem($needles = null)
 128      {
 129          $app        = JFactory::getApplication();
 130          $menus        = $app->getMenu('site');
 131  
 132          // Prepare the reverse lookup array.
 133          if (self::$lookup === null) {
 134              self::$lookup = array();
 135  
 136              $component    = JComponentHelper::getComponent('com_weblinks');
 137              $items        = $menus->getItems('component_id', $component->id);
 138  
 139              if ($items) {
 140                  foreach ($items as $item)
 141                  {
 142                      if (isset($item->query) && isset($item->query['view'])) {
 143                          $view = $item->query['view'];
 144  
 145                          if (!isset(self::$lookup[$view])) {
 146                              self::$lookup[$view] = array();
 147                          }
 148  
 149                          if (isset($item->query['id'])) {
 150                              self::$lookup[$view][$item->query['id']] = $item->id;
 151                          }
 152                      }
 153                  }
 154              }
 155          }
 156  
 157          if ($needles) {
 158              foreach ($needles as $view => $ids)
 159              {
 160                  if (isset(self::$lookup[$view])) {
 161                      foreach($ids as $id)
 162                      {
 163                          if (isset(self::$lookup[$view][(int)$id])) {
 164                              return self::$lookup[$view][(int)$id];
 165                          }
 166                      }
 167                  }
 168              }
 169          }
 170          else {
 171              $active = $menus->getActive();
 172              if ($active) {
 173                  return $active->id;
 174              }
 175          }
 176  
 177          return null;
 178      }
 179  }


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