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