Files
@ f43d1a4680a9
Branch filter:
Location: hot67beta/components/com_weblinks/router.php
f43d1a4680a9
7.7 KiB
text/x-php
menubar 0 to 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | <?php
/**
* @version $Id: router.php 10752 2008-08-23 01:53:31Z eddieajau $
* @package Joomla
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
function WeblinksBuildRoute(&$query)
{
static $items;
$segments = array();
$itemid = null;
// Break up the weblink/category id into numeric and alias values.
if (isset($query['id']) && strpos($query['id'], ':')) {
list($query['id'], $query['alias']) = explode(':', $query['id'], 2);
}
// Break up the category id into numeric and alias values.
if (isset($query['catid']) && strpos($query['catid'], ':')) {
list($query['catid'], $query['catalias']) = explode(':', $query['catid'], 2);
}
// Get the menu items for this component.
if (!$items) {
$component = &JComponentHelper::getComponent('com_weblinks');
$menu = &JSite::getMenu();
$items = $menu->getItems('componentid', $component->id);
}
// Search for an appropriate menu item.
if (is_array($items))
{
// If only the option and itemid are specified in the query, return that item.
if (!isset($query['view']) && !isset($query['id']) && !isset($query['catid']) && isset($query['Itemid'])) {
$itemid = (int) $query['Itemid'];
}
// Search for a specific link based on the critera given.
if (!$itemid)
{
foreach ($items as $item)
{
// Check if this menu item links to this view.
if (isset($item->query['view']) && $item->query['view'] == 'weblink'
&& isset($query['view']) && $query['view'] != 'category'
&& isset($item->query['id']) && $item->query['id'] == $query['id'])
{
$itemid = $item->id;
}
elseif (isset($item->query['view']) && $item->query['view'] == 'category'
&& isset($query['view']) && $query['view'] != 'weblink'
&& isset($item->query['catid']) && $item->query['catid'] == $query['catid'])
{
$itemid = $item->id;
}
}
}
// If no specific link has been found, search for a general one.
if (!$itemid)
{
foreach ($items as $item)
{
if (isset($query['view']) && $query['view'] == 'weblink'
&& isset($item->query['view']) && $item->query['view'] == 'category'
&& isset($item->query['id']) && isset($query['catid'])
&& $query['catid'] == $item->query['id'])
{
// This menu item links to the weblink view but we need to append the weblink id to it.
$itemid = $item->id;
$segments[] = isset($query['catalias']) ? $query['catid'].':'.$query['catalias'] : $query['catid'];
$segments[] = isset($query['alias']) ? $query['id'].':'.$query['alias'] : $query['id'];
break;
}
elseif (isset($query['view']) && $query['view'] == 'category'
&& isset($item->query['view']) && $item->query['view'] == 'category'
&& isset($item->query['id']) && isset($query['id']) && $item->query['id'] != $query['id'])
{
// This menu item links to the category view but we need to append the category id to it.
$itemid = $item->id;
$segments[] = isset($query['alias']) ? $query['id'].':'.$query['alias'] : $query['id'];
break;
}
}
}
// Search for an even more general link.
if (!$itemid)
{
foreach ($items as $item)
{
if (isset($query['view']) && $query['view'] == 'weblink' && isset($item->query['view'])
&& $item->query['view'] == 'categories' && isset($query['catid']) && isset($query['id']))
{
// This menu item links to the categories view but we need to append the category and weblink id to it.
$itemid = $item->id;
$segments[] = isset($query['catalias']) ? $query['catid'].':'.$query['catalias'] : $query['catid'];
$segments[] = isset($query['alias']) ? $query['id'].':'.$query['alias'] : $query['id'];
break;
}
elseif (isset($query['view']) && $query['view'] == 'category' && isset($item->query['view'])
&& $item->query['view'] == 'categories' && !isset($query['catid']))
{
// This menu item links to the categories view but we need to append the category id to it.
$itemid = $item->id;
$segments[] = isset($query['alias']) ? $query['id'].':'.$query['alias'] : $query['id'];
break;
}
}
}
}
// Check if the router found an appropriate itemid.
if (!$itemid)
{
// Check if a category was specified
if (isset($query['view']) && $query['view'] == 'category' && isset($query['id']))
{
if (isset($query['alias'])) {
$query['id'] .= ':'.$query['alias'];
}
// Push the catid onto the stack.
$segments[] = $query['id'];
unset($query['view']);
unset($query['id']);
unset($query['alias']);
}
// Check if a id was specified.
elseif (isset($query['id']))
{
if (isset($query['catalias'])) {
$query['catid'] .= ':'.$query['catalias'];
}
// Push the catid onto the stack.
$segments[] = $query['catid'];
if (isset($query['alias'])) {
$query['id'] .= ':'.$query['alias'];
}
// Push the id onto the stack.
$segments[] = $query['id'];
unset($query['view']);
unset($query['id']);
unset($query['alias']);
unset($query['catid']);
unset($query['catalias']);
}
elseif (isset($query['catid']))
{
if (isset($query['alias'])) {
$query['catid'] .= ':'.$query['catalias'];
}
// Push the catid onto the stack.
$segments[] = 'category';
$segments[] = $query['catid'];
unset($query['view']);
unset($query['catid']);
unset($query['catalias']);
unset($query['alias']);
}
else
{
// Categories view.
unset($query['view']);
}
}
else
{
$query['Itemid'] = $itemid;
// Remove the unnecessary URL segments.
unset($query['view']);
unset($query['id']);
unset($query['alias']);
unset($query['catid']);
unset($query['catalias']);
}
return $segments;
}
function WeblinksParseRoute($segments)
{
$vars = array();
// Get the active menu item.
$menu = &JSite::getMenu();
$item = &$menu->getActive();
// Check if we have a valid menu item.
if (is_object($item))
{
// Proceed through the possible variations trying to match the most specific one.
if (isset($item->query['view']) && $item->query['view'] == 'weblink' && isset($segments[0]))
{
// Contact view.
$vars['view'] = 'weblink';
$vars['id'] = $segments[0];
}
elseif (isset($item->query['view']) && $item->query['view'] == 'category' && count($segments) == 2)
{
// Weblink view.
$vars['view'] = 'weblink';
$vars['id'] = $segments[1];
$vars['catid'] = $segments[0];
}
elseif (isset($item->query['view']) && $item->query['view'] == 'category' && isset($segments[0]))
{
// Category view.
$vars['view'] = 'category';
$vars['id'] = $segments[0];
}
elseif (isset($item->query['view']) && $item->query['view'] == 'categories' && count($segments) == 2)
{
// Weblink view.
$vars['view'] = 'weblink';
$vars['id'] = $segments[1];
$vars['catid'] = $segments[0];
}
elseif (isset($item->query['view']) && $item->query['view'] == 'categories' && isset($segments[0]))
{
// Category view.
$vars['view'] = 'category';
$vars['id'] = $segments[0];
}
}
else
{
// Count route segments
$count = count($segments);
// Check if there are any route segments to handle.
if ($count)
{
if ($count == 2)
{
// We are viewing a weblink.
$vars['view'] = 'weblink';
$vars['catid'] = $segments[$count-2];
$vars['id'] = $segments[$count-1];
}
else
{
// We are viewing a category.
$vars['view'] = 'category';
$vars['id'] = $segments[$count-1];
}
}
}
return $vars;
}
|