| [ 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 NewsfeedsBuildRoute(&$query) 15 { 16 static $items; 17 18 $segments = array(); 19 $itemid = null; 20 21 // Break up the newsfeed 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_newsfeeds'); 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 foreach ($items as $item) 49 { 50 // Check if this menu item links to this view. 51 if (isset($item->query['view']) && $item->query['view'] == 'newsfeed' 52 && isset($query['view']) && $query['view'] != 'category' 53 && isset($item->query['id']) && isset($query['id']) && $item->query['id'] == $query['id']) 54 { 55 $itemid = $item->id; 56 } 57 elseif (isset($item->query['view']) && $item->query['view'] == 'category' 58 && isset($query['view']) && $query['view'] != 'newsfeed' 59 && isset($item->query['catid']) && $item->query['catid'] == $query['catid']) 60 { 61 $itemid = $item->id; 62 } 63 } 64 } 65 66 // If no specific link has been found, search for a general one. 67 if (!$itemid) { 68 foreach ($items as $item) 69 { 70 //var_dump($item->query); 71 if (isset($query['view']) && $query['view'] == 'newsfeed' 72 && isset($item->query['view']) && $item->query['view'] == 'category' 73 && isset($item->query['id']) && isset($query['catid']) 74 && $query['catid'] == $item->query['id']) 75 { 76 // This menu item links to the newsfeed view but we need to append the newsfeed id to it. 77 $itemid = $item->id; 78 $segments[] = isset($query['catalias']) ? $query['catid'].':'.$query['catalias'] : $query['catid']; 79 $segments[] = isset($query['alias']) ? $query['id'].':'.$query['alias'] : $query['id']; 80 break; 81 } 82 elseif (isset($query['view']) && $query['view'] == 'category' 83 && isset($item->query['view']) && $item->query['view'] == 'category' 84 && isset($item->query['id']) && isset($query['id']) && $item->query['id'] != $query['id']) 85 { 86 // This menu item links to the category view but we need to append the category id to it. 87 $itemid = $item->id; 88 $segments[] = isset($query['alias']) ? $query['id'].':'.$query['alias'] : $query['id']; 89 break; 90 } 91 92 } 93 } 94 95 // Search for an even more general link. 96 if (!$itemid) 97 { 98 foreach ($items as $item) 99 { 100 if (isset($query['view']) && $query['view'] == 'newsfeed' && isset($item->query['view']) 101 && $item->query['view'] == 'categories' && isset($query['catid']) && isset($query['id'])) 102 { 103 // This menu item links to the categories view but we need to append the category and newsfeed id to it. 104 $itemid = $item->id; 105 $segments[] = isset($query['catalias']) ? $query['catid'].':'.$query['catalias'] : $query['catid']; 106 $segments[] = isset($query['alias']) ? $query['id'].':'.$query['alias'] : $query['id']; 107 break; 108 } 109 elseif (isset($query['view']) && $query['view'] == 'category' && isset($item->query['view']) 110 && $item->query['view'] == 'categories' && !isset($query['catid'])) 111 { 112 // This menu item links to the categories view but we need to append the category id to it. 113 $itemid = $item->id; 114 $segments[] = isset($query['alias']) ? $query['id'].':'.$query['alias'] : $query['id']; 115 break; 116 } 117 } 118 } 119 } 120 121 // Check if the router found an appropriate itemid. 122 if (!$itemid) 123 { 124 // Check if a id was specified. 125 if (isset($query['id'])) 126 { 127 if (isset($query['alias'])) { 128 $query['id'] .= ':'.$query['alias']; 129 } 130 131 // Push the id onto the stack. 132 $segments[] = $query['id']; 133 unset($query['view']); 134 unset($query['id']); 135 unset($query['alias']); 136 } 137 elseif (isset($query['catid'])) 138 { 139 if (isset($query['alias'])) { 140 $query['catid'] .= ':'.$query['catalias']; 141 } 142 143 // Push the catid onto the stack. 144 $segments[] = 'category'; 145 $segments[] = $query['catid']; 146 unset($query['view']); 147 unset($query['catid']); 148 unset($query['catalias']); 149 unset($query['alias']); 150 } 151 else 152 { 153 // Categories view. 154 unset($query['view']); 155 } 156 } 157 else 158 { 159 $query['Itemid'] = $itemid; 160 161 // Remove the unnecessary URL segments. 162 unset($query['view']); 163 unset($query['id']); 164 unset($query['alias']); 165 unset($query['catid']); 166 unset($query['catalias']); 167 } 168 169 return $segments; 170 } 171 172 function NewsfeedsParseRoute($segments) 173 { 174 $vars = array(); 175 176 // Get the active menu item. 177 $menu = &JSite::getMenu(); 178 $item = &$menu->getActive(); 179 180 // Check if we have a valid menu item. 181 if (is_object($item)) 182 { 183 // Proceed through the possible variations trying to match the most specific one. 184 if (isset($item->query['view']) && $item->query['view'] == 'newsfeed' && isset($segments[0])) 185 { 186 // Contact view. 187 $vars['view'] = 'newsfeed'; 188 $vars['id'] = $segments[0]; 189 } 190 elseif (isset($item->query['view']) && $item->query['view'] == 'category' && count($segments) == 2) 191 { 192 // Newsfeed view. 193 $vars['view'] = 'newsfeed'; 194 $vars['id'] = $segments[1]; 195 $vars['catid'] = $segments[0]; 196 } 197 elseif (isset($item->query['view']) && $item->query['view'] == 'category' && isset($segments[0])) 198 { 199 // Category view. 200 $vars['view'] = 'category'; 201 $vars['id'] = $segments[0]; 202 } 203 elseif (isset($item->query['view']) && $item->query['view'] == 'categories' && count($segments) == 2) 204 { 205 // Newsfeed view. 206 $vars['view'] = 'newsfeed'; 207 $vars['id'] = $segments[1]; 208 $vars['catid'] = $segments[0]; 209 } 210 elseif (isset($item->query['view']) && $item->query['view'] == 'categories' && isset($segments[0])) 211 { 212 // Category view. 213 $vars['view'] = 'category'; 214 $vars['id'] = $segments[0]; 215 } 216 } 217 else 218 { 219 // Count route segments 220 $count = count($segments); 221 222 // Check if there are any route segments to handle. 223 if ($count) 224 { 225 if (count($segments[0]) == 2) 226 { 227 // We are viewing a newsfeed. 228 $vars['view'] = 'newsfeed'; 229 $vars['id'] = $segments[$count-2]; 230 $vars['catid'] = $segments[$count-1]; 231 232 } 233 else 234 { 235 // We are viewing a category. 236 $vars['view'] = 'category'; 237 $vars['catid'] = $segments[$count-1]; 238 } 239 } 240 } 241 242 return $vars; 243 } 244 ?>
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 |