| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Site 4 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 5 * @license GNU General Public License version 2 or later; see LICENSE.txt 6 */ 7 8 /* Newsfeeds Component Route Helper 9 * 10 * @package Joomla.Site 11 * @subpackage com_newsfeeds 12 * @since 1.6 13 */ 14 15 defined('_JEXEC') or die; 16 17 jimport('joomla.application.categories'); 18 19 /** 20 * Build the route for the com_newsfeeds component 21 * 22 * @param array An array of URL arguments 23 * 24 * @return array The URL arguments to use to assemble the subsequent URL. 25 */ 26 function NewsfeedsBuildRoute(&$query) 27 { 28 $segments = array(); 29 30 // get a menu item based on Itemid or currently active 31 $app = JFactory::getApplication(); 32 $menu = $app->getMenu(); 33 $params = JComponentHelper::getParams('com_newsfeeds'); 34 $advanced = $params->get('sef_advanced_link', 0); 35 36 if (empty($query['Itemid'])) { 37 $menuItem = $menu->getActive(); 38 } 39 else { 40 $menuItem = $menu->getItem($query['Itemid']); 41 } 42 $mView = (empty($menuItem->query['view'])) ? null : $menuItem->query['view']; 43 $mCatid = (empty($menuItem->query['catid'])) ? null : $menuItem->query['catid']; 44 $mId = (empty($menuItem->query['id'])) ? null : $menuItem->query['id']; 45 46 if (isset($query['view'])) 47 { 48 $view = $query['view']; 49 if (empty($query['Itemid'])) { 50 $segments[] = $query['view']; 51 } 52 unset($query['view']); 53 }; 54 55 // are we dealing with an newsfeed that is attached to a menu item? 56 if (isset($query['view']) && ($mView == $query['view']) and (isset($query['id'])) and ($mId == intval($query['id']))) { 57 unset($query['view']); 58 unset($query['catid']); 59 unset($query['id']); 60 return $segments; 61 } 62 63 if (isset($view) and ($view == 'category' or $view == 'newsfeed')) { 64 if ($mId != intval($query['id']) || $mView != $view) { 65 if($view == 'newsfeed' && isset($query['catid'])) 66 { 67 $catid = $query['catid']; 68 } elseif(isset($query['id'])) { 69 $catid = $query['id']; 70 } 71 $menuCatid = $mId; 72 $categories = JCategories::getInstance('Newsfeeds'); 73 $category = $categories->get($catid); 74 if ($category) { 75 $path = $category->getPath(); 76 $path = array_reverse($path); 77 78 $array = array(); 79 foreach($path as $id) 80 { 81 if((int) $id == (int)$menuCatid) 82 { 83 break; 84 } 85 if($advanced) 86 { 87 list($tmp, $id) = explode(':', $id, 2); 88 } 89 $array[] = $id; 90 } 91 $segments = array_merge($segments, array_reverse($array)); 92 } 93 if($view == 'newsfeed') 94 { 95 if($advanced) 96 { 97 list($tmp, $id) = explode(':', $query['id'], 2); 98 } else { 99 $id = $query['id']; 100 } 101 $segments[] = $id; 102 } 103 } 104 unset($query['id']); 105 unset($query['catid']); 106 } 107 108 if (isset($query['layout'])) 109 { 110 if (!empty($query['Itemid']) && isset($menuItem->query['layout'])) 111 { 112 if ($query['layout'] == $menuItem->query['layout']) { 113 114 unset($query['layout']); 115 } 116 } 117 else 118 { 119 if ($query['layout'] == 'default') { 120 unset($query['layout']); 121 } 122 } 123 }; 124 125 return $segments; 126 } 127 /** 128 * Parse the segments of a URL. 129 * 130 * @param array The segments of the URL to parse. 131 * 132 * @return array The URL attributes to be used by the application. 133 */ 134 function NewsfeedsParseRoute($segments) 135 { 136 $vars = array(); 137 138 //Get the active menu item. 139 $app = JFactory::getApplication(); 140 $menu = $app->getMenu(); 141 $item = $menu->getActive(); 142 $params = JComponentHelper::getParams('com_newsfeeds'); 143 $advanced = $params->get('sef_advanced_link', 0); 144 145 // Count route segments 146 $count = count($segments); 147 148 // Standard routing for newsfeeds. 149 if (!isset($item)) 150 { 151 $vars['view'] = $segments[0]; 152 $vars['id'] = $segments[$count - 1]; 153 return $vars; 154 } 155 156 // From the categories view, we can only jump to a category. 157 $id = (isset($item->query['id']) && $item->query['id'] > 1) ? $item->query['id'] : 'root'; 158 $categories = JCategories::getInstance('Newsfeeds')->get($id)->getChildren(); 159 $vars['catid'] = $id; 160 $vars['id'] = $id; 161 $found = 0; 162 foreach($segments as $segment) 163 { 164 $segment = $advanced ? str_replace(':', '-', $segment) : $segment; 165 foreach($categories as $category) 166 { 167 if ($category->slug == $segment || $category->alias == $segment) 168 { 169 $vars['id'] = $category->id; 170 $vars['catid'] = $category->id; 171 $vars['view'] = 'category'; 172 $categories = $category->getChildren(); 173 $found = 1; 174 break; 175 } 176 } 177 if ($found == 0) 178 { 179 if($advanced) 180 { 181 $db = JFactory::getDBO(); 182 $query = 'SELECT id FROM #__newsfeeds WHERE catid = '.$vars['catid'].' AND alias = '.$db->Quote($segment); 183 $db->setQuery($query); 184 $nid = $db->loadResult(); 185 } else { 186 $nid = $segment; 187 } 188 $vars['id'] = $nid; 189 $vars['view'] = 'newsfeed'; 190 } 191 $found = 0; 192 } 193 194 return $vars; 195 }
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 |