| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Site 4 * @subpackage com_users 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 defined('_JEXEC') or die; 10 11 /** 12 * Function to build a Users URL route. 13 * 14 * @param array The array of query string values for which to build a route. 15 * @return array The URL route with segments represented as an array. 16 * @since 1.5 17 */ 18 function UsersBuildRoute(&$query) 19 { 20 // Declare static variables. 21 static $items; 22 static $default; 23 static $registration; 24 static $profile; 25 static $login; 26 static $remind; 27 static $resend; 28 static $reset; 29 30 // Initialise variables. 31 $segments = array(); 32 33 // Get the relevant menu items if not loaded. 34 if (empty($items)) { 35 // Get all relevant menu items. 36 $app = JFactory::getApplication(); 37 $menu = $app->getMenu(); 38 $items = $menu->getItems('component', 'com_users'); 39 40 // Build an array of serialized query strings to menu item id mappings. 41 for ($i = 0, $n = count($items); $i < $n; $i++) { 42 // Check to see if we have found the resend menu item. 43 if (empty($resend) && !empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'resend')) { 44 $resend = $items[$i]->id; 45 } 46 47 // Check to see if we have found the reset menu item. 48 if (empty($reset) && !empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'reset')) { 49 $reset = $items[$i]->id; 50 } 51 52 // Check to see if we have found the remind menu item. 53 if (empty($remind) && !empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'remind')) { 54 $remind = $items[$i]->id; 55 } 56 57 // Check to see if we have found the login menu item. 58 if (empty($login) && !empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'login')) { 59 $login = $items[$i]->id; 60 } 61 62 // Check to see if we have found the registration menu item. 63 if (empty($registration) && !empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'registration')) { 64 $registration = $items[$i]->id; 65 } 66 67 // Check to see if we have found the profile menu item. 68 if (empty($profile) && !empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'profile')) { 69 $profile = $items[$i]->id; 70 } 71 } 72 73 // Set the default menu item to use for com_users if possible. 74 if ($profile) { 75 $default = $profile; 76 } elseif ($registration) { 77 $default = $registration; 78 } elseif ($login) { 79 $default = $login; 80 } 81 } 82 83 if (!empty($query['view'])) { 84 switch ($query['view']) { 85 case 'reset': 86 if ($query['Itemid'] = $reset) { 87 unset ($query['view']); 88 } else { 89 $query['Itemid'] = $default; 90 } 91 break; 92 93 case 'resend': 94 if ($query['Itemid'] = $resend) { 95 unset ($query['view']); 96 } else { 97 $query['Itemid'] = $default; 98 } 99 break; 100 101 case 'remind': 102 if ($query['Itemid'] = $remind) { 103 unset ($query['view']); 104 } else { 105 $query['Itemid'] = $default; 106 } 107 break; 108 109 case 'login': 110 if ($query['Itemid'] = $login) { 111 unset ($query['view']); 112 } else { 113 $query['Itemid'] = $default; 114 } 115 break; 116 117 case 'registration': 118 if ($query['Itemid'] = $registration) { 119 unset ($query['view']); 120 } else { 121 $query['Itemid'] = $default; 122 } 123 break; 124 125 default: 126 case 'profile': 127 if (!empty($query['view'])) { 128 $segments[] = $query['view']; 129 } 130 unset ($query['view']); 131 if ($query['Itemid'] = $profile) { 132 unset ($query['view']); 133 } else { 134 $query['Itemid'] = $default; 135 } 136 137 // Only append the user id if not "me". 138 $user = JFactory::getUser(); 139 if (!empty($query['user_id']) && ($query['user_id'] != $user->id)) { 140 $segments[] = $query['user_id']; 141 } 142 unset ($query['user_id']); 143 144 break; 145 } 146 } 147 148 return $segments; 149 } 150 151 /** 152 * Function to parse a Users URL route. 153 * 154 * @param array The URL route with segments represented as an array. 155 * @return array The array of variables to set in the request. 156 * @since 1.5 157 */ 158 function UsersParseRoute($segments) 159 { 160 // Initialise variables. 161 $vars = array(); 162 163 // Only run routine if there are segments to parse. 164 if (count($segments) < 1) { 165 return; 166 } 167 168 // Get the package from the route segments. 169 $userId = array_pop($segments); 170 171 if (!is_numeric($userId)) { 172 $vars['view'] = 'profile'; 173 return $vars; 174 } 175 176 if (is_numeric($userId)) { 177 // Get the package id from the packages table by alias. 178 $db = JFactory::getDbo(); 179 $db->setQuery( 180 'SELECT '.$db->quoteName('id') . 181 ' FROM '.$db->quoteName('#__users') . 182 ' WHERE '.$db->quoteName('id').' = '.(int) $userId 183 ); 184 $userId = $db->loadResult(); 185 } 186 187 // Set the package id if present. 188 if ($userId) { 189 // Set the package id. 190 $vars['user_id'] = (int)$userId; 191 192 // Set the view to package if not already set. 193 if (empty($vars['view'])) { 194 $vars['view'] = 'profile'; 195 } 196 } else { 197 JError::raiseError(404, JText::_('JGLOBAL_RESOURCE_NOT_FOUND')); 198 } 199 200 return $vars; 201 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |