- md5
- 27aa382a2e8dd28beb860cbe1e20e5f2
- sha1
- cbf298d52df4005fb406e3c2c3c423b013350d1a
- sha256
- efc7306e9a3e87d6bf9d6dbd6d7fdd032a1112d1d728d2201bc63cc64f2af863
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Weblinks Component Route Helper
*
* @static
* @package Joomla.Site
* @subpackage com_weblinks
* @since 1.5
*/
abstract class WeblinksHelperRoute
{
protected static $lookup;
/**
* @param int The route of the weblink
*/
public static function getWeblinkRoute($id, $catid)
{
$needles = array(
'weblink' => array((int) $id)
);
//Create the link
$link = 'index.php?option=com_weblinks&view=weblink&id='. $id;
if ($catid > 1) {
$categories = JCategories::getInstance('Weblinks');
$category = $categories->get($catid);
if($category) {
$needles['category'] = array_reverse($category->getPath());
$needles['categories'] = $needles['category'];
$link .= '&catid='.$catid;
}
}
if ($item = self::_findItem($needles)) {
$link .= '&Itemid='.$item;
}
elseif ($item = self::_findItem()) {
$link .= '&Itemid='.$item;
}
return $link;
}
/**
* @param int $id The id of the weblink.
* @param string $return The return page variable.
*/
public static function getFormRoute($id, $return = null)
{
// Create the link.
if ($id) {
$link = 'index.php?option=com_weblinks&task=weblink.edit&w_id='. $id;
}
else {
$link = 'index.php?option=com_weblinks&task=weblink.add&w_id=0';
}
if ($return) {
$link .= '&return='.$return;
}
return $link;
}
public static function getCategoryRoute($catid)
{
if ($catid instanceof JCategoryNode) {
$id = $catid->id;
$category = $catid;
}
else {
$id = (int) $catid;
$category = JCategories::getInstance('Weblinks')->get($id);
}
if ($id < 1) {
$link = '';
}
else {
$needles = array(
'category' => array($id)
);
if ($item = self::_findItem($needles)) {
$link = 'index.php?Itemid='.$item;
}
else {
//Create the link
$link = 'index.php?option=com_weblinks&view=category&id='.$id;
if ($category) {
$catids = array_reverse($category->getPath());
$needles = array(
'category' => $catids,
'categories' => $catids
);
if ($item = self::_findItem($needles)) {
$link .= '&Itemid='.$item;
}
elseif ($item = self::_findItem()) {
$link .= '&Itemid='.$item;
}
}
}
}
return $link;
}
protected static function _findItem($needles = null)
{
$app = JFactory::getApplication();
$menus = $app->getMenu('site');
// Prepare the reverse lookup array.
if (self::$lookup === null) {
self::$lookup = array();
$component = JComponentHelper::getComponent('com_weblinks');
$items = $menus->getItems('component_id', $component->id);
if ($items) {
foreach ($items as $item)
{
if (isset($item->query) && isset($item->query['view'])) {
$view = $item->query['view'];
if (!isset(self::$lookup[$view])) {
self::$lookup[$view] = array();
}
if (isset($item->query['id'])) {
self::$lookup[$view][$item->query['id']] = $item->id;
}
}
}
}
}
if ($needles) {
foreach ($needles as $view => $ids)
{
if (isset(self::$lookup[$view])) {
foreach($ids as $id)
{
if (isset(self::$lookup[$view][(int) $id])) {
return self::$lookup[$view][(int) $id];
}
}
}
}
}
else {
$active = $menus->getActive();
if ($active) {
return $active->id;
}
}
return null;
}
}
The same content is in 3 releases, Joomla 3.0.0 to 3.0.2. See them all, or every version of this file.