0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: router.php.tar
home/academiac/www/components/com_finder/router.php 0000644 00000005025 15137155146 0016544 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_finder * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('_JEXEC') or die; // Register dependent classes. /** * Method to build a SEF route. * * @param array &$query An array of route variables. * * @return array An array of route segments. * * @since 2.5 */ function FinderBuildRoute(&$query) { static $menu; $segments = array(); // Load the menu if necessary. if (!$menu) { $menu = JFactory::getApplication('site')->getMenu(); } /* * First, handle menu item routes first. When the menu system builds a * route, it only provides the option and the menu item id. We don't have * to do anything to these routes. */ if (count($query) === 2 && isset($query['Itemid']) && isset($query['option'])) { return $segments; } /* * Next, handle a route with a supplied menu item id. All system generated * routes should fall into this group. We can assume that the menu item id * is the best possible match for the query but we need to go through and * see which variables we can eliminate from the route query string because * they are present in the menu item route already. */ if (!empty($query['Itemid'])) { // Get the menu item. $item = $menu->getItem($query['Itemid']); // Check if the view matches. if ($item && @$item->query['view'] === @$query['view']) { unset($query['view']); } // Check if the search query filter matches. if ($item && @$item->query['f'] === @$query['f']) { unset($query['f']); } // Check if the search query string matches. if ($item && @$item->query['q'] === @$query['q']) { unset($query['q']); } return $segments; } /* * Lastly, handle a route with no menu item id. Fortunately, we only need * to deal with the view as the other route variables are supposed to stay * in the query string. */ if (isset($query['view'])) { // Add the view to the segments. $segments[] = $query['view']; unset($query['view']); } return $segments; } /** * Method to parse a SEF route. * * @param array $segments An array of route segments. * * @return array An array of route variables. * * @since 2.5 */ function FinderParseRoute($segments) { $vars = array(); // Check if the view segment is set and it equals search or advanced. if (@$segments[0] === 'search' || @$segments[0] === 'advanced') { $vars['view'] = $segments[0]; } return $vars; } home/academiac/www/components/com_search/router.php 0000644 00000001166 15137155151 0016540 0 ustar 00 <?php /** * @package Joomla.Site * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; /** * @param array * @return array */ function SearchBuildRoute(&$query) { $segments = array(); if (isset($query['view'])) { unset($query['view']); } return $segments; } /** * @param array * @return array */ function SearchParseRoute($segments) { $vars = array(); $searchword = array_shift($segments); $vars['searchword'] = $searchword; $vars['view'] = 'search'; return $vars; } home/academiac/www/components/com_xmap/router.php 0000604 00000011213 15137156506 0016233 0 ustar 00 <?php /** * @version $Id$ * @copyright Copyright (C) 2005 - 2009 Joomla! Vargas. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @author Guillermo Vargas (guille@vargas.co.cr) */ defined( '_JEXEC' ) or die( 'Restricted access' ); /** * Content Component Route Helper * * @package Xmap * @subpackage com_xmap * @since 2.0 */ class XmapRoute { /** * @param int $id The id of the article. * @param int $categoryId An optional category id. * * @return string The routed link. */ public static function sitemap($id, $view = 'html') { $needles = array( 'html' => (int) $id ); //Create the link $link = 'index.php?option=com_xmap&view='.$view.'&id='. $id; if ($itemId = self::_findItemId($needles)) { $link .= '&Itemid='.$itemId; }; return $link; } protected static function _findItemId($needles) { // Prepare the reverse lookup array. if (self::$lookup === null) { self::$lookup = array(); $component = &JComponentHelper::getComponent('com_xmap'); $menus = &JApplication::getMenu('site', array()); $items = $menus->getItems('component_id', $component->id); foreach ($items as &$item) { if (isset($item->query) && isset($item->query['view'])) { $view = $item->query['view']; if (!isset(self::$lookup[$view])) { self::$lookup[$view] = array(); } if (isset($item->query['id'])) { self::$lookup[$view][$item->query['id']] = $item->id; } } } } $match = null; foreach ($needles as $view => $id) { if (isset(self::$lookup[$view])) { if (isset(self::$lookup[$view][$id])) { return self::$lookup[$view][$id]; } } } return null; } } /** * Build the route for the com_content component * * @param array An array of URL arguments * * @return array The URL arguments to use to assemble the subsequent URL. */ function XmapBuildRoute(&$query) { $segments = array(); // get a menu item based on Itemid or currently active $app = JFactory::getApplication(); $menu = $app->getMenu(); if (empty($query['Itemid'])) { $menuItem = $menu->getActive(); } else { $menuItem = $menu->getItem($query['Itemid']); } $mView = (empty($menuItem->query['view'])) ? null : $menuItem->query['view']; $mId = (empty($menuItem->query['id'])) ? null : $menuItem->query['id']; if ( !empty($query['Itemid']) ) { unset($query['view']); unset($query['id']); } else { if ( !empty($query['view']) ) { $segments[] = $query['view']; } } if (isset($query['id'])) { if (empty($query['Itemid'])) { $segments[] = $query['id']; } else { if (isset($menuItem->query['id'])) { if ($query['id'] != $mId) { $segments[] = $query['id']; } } else { $segments[] = $query['id']; } } unset($query['id']); }; if (isset($query['layout'])) { if (!empty($query['Itemid']) && isset($menuItem->query['layout'])) { if ($query['layout'] == $menuItem->query['layout']) { unset($query['layout']); } } else { if ($query['layout'] == 'default') { unset($query['layout']); } } }; return $segments; } /** * Parse the segments of a URL. * * @param array The segments of the URL to parse. * * @return array The URL attributes to be used by the application. */ function XmapParseRoute($segments) { $vars = array(); //G et the active menu item. $app = JFactory::getApplication(); $menu = $app->getMenu(); $item = $menu->getActive(); // Count route segments $count = count($segments); // Standard routing for articles. if (!isset($item)) { $vars['view'] = $segments[0]; $vars['id'] = $segments[$count - 1]; return $vars; } $vars['view'] = $item->query['view']; $vars['id'] = $item->query['id']; return $vars; } home/academiac/www/components/com_virtuemart/router.php 0000604 00000122754 15137204721 0017476 0 ustar 00 <?php if( !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); /** * * @package VirtueMart * @Author Kohl Patrick * @subpackage router * @version $Id$ * ${PHING.VM.COPYRIGHT} * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart 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 /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details. * * http://virtuemart.net */ function virtuemartBuildRoute(&$query) { $segments = array(); $helper = vmrouterHelper::getInstance($query); /* simple route , no work , for very slow server or test purpose */ if ($helper->router_disabled) { foreach ($query as $key => $value){ if ($key != 'option') { if ($key != 'Itemid') { $segments[]=$key.'/'.$value; unset($query[$key]); } } } return $segments; } if ($helper->edit) return $segments; /* Full route , heavy work*/ // $lang = $helper->lang ; $view = ''; $jmenu = $helper->menu ; if(isset($query['langswitch'])) unset($query['langswitch']); if(isset($query['view'])){ $view = $query['view']; unset($query['view']); } switch ($view) { case 'virtuemart'; $query['Itemid'] = $jmenu['virtuemart'] ; break; /* Shop category or virtuemart view All ideas are wellcome to improve this because is the biggest and more used */ case 'category'; $start = null; $limitstart = null; $limit = null; if ( isset($query['virtuemart_manufacturer_id']) ) { $segments[] = $helper->lang('manufacturer').'/'.$helper->getManufacturerName($query['virtuemart_manufacturer_id']) ; unset($query['virtuemart_manufacturer_id']); } if ( isset($query['search']) ) { $segments[] = $helper->lang('search') ; unset($query['search']); } if ( isset($query['keyword'] )) { $segments[] = $query['keyword']; unset($query['keyword']); } if ( isset($query['virtuemart_category_id']) ) { if (isset($jmenu['virtuemart_category_id'][ $query['virtuemart_category_id'] ] ) ) $query['Itemid'] = $jmenu['virtuemart_category_id'][$query['virtuemart_category_id']]; else { $categoryRoute = $helper->getCategoryRoute($query['virtuemart_category_id']); if ($categoryRoute->route) $segments[] = $categoryRoute->route; //http://forum.virtuemart.net/index.php?topic=121642.0 if (!empty($categoryRoute->itemId)) { $query['Itemid'] = $categoryRoute->itemId; } else { $query['Itemid'] = false; } } unset($query['virtuemart_category_id']); } if ( isset($jmenu['category']) ) $query['Itemid'] = $jmenu['category']; if ( isset($query['orderby']) ) { $segments[] = $helper->lang('by').','.$helper->lang( $query['orderby']) ; unset($query['orderby']); } if ( isset($query['dir']) ) { if ($query['dir'] =='DESC'){ $dir = 'dirDesc'; } else { $dir = 'dirAsc'; } $segments[] = $dir;//$helper->lang('dir'.$dir) ; unset($query['dir']); } // Joomla replace before route limitstart by start but without SEF this is start ! if ( isset($query['limitstart'] ) ) { $limitstart = $query['limitstart'] ; unset($query['limitstart']); } if ( isset($query['start'] ) ) { $start = $query['start'] ; unset($query['start']); } if ( isset($query['limit'] ) ) { $limit = $query['limit'] ; unset($query['limit']); } if ($start !== null && $limitstart!== null ) { //$segments[] = $helper->lang('results') .',1-'.$start ; } else if ( $start>0 ) { // using general limit if $limit is not set if ($limit === null) $limit= vmrouterHelper::$limit ; $segments[] = $helper->lang('results') .','. ($start+1).'-'.($start+$limit); } else if ($limit !== null && $limit != vmrouterHelper::$limit ) $segments[] = $helper->lang('results') .',1-'.$limit ;//limit change return $segments; break; /* Shop product details view */ case 'productdetails'; $virtuemart_product_id = false; if (isset($jmenu['virtuemart_product_id'][ $query['virtuemart_product_id'] ] ) ) { $query['Itemid'] = $jmenu['virtuemart_product_id'][$query['virtuemart_product_id']]; unset($query['virtuemart_product_id']); unset($query['virtuemart_category_id']); } else { if(isset($query['virtuemart_product_id'])) { if ($helper->use_id) $segments[] = $query['virtuemart_product_id']; $virtuemart_product_id = $query['virtuemart_product_id']; unset($query['virtuemart_product_id']); } if(empty( $query['virtuemart_category_id'])){ $query['virtuemart_category_id'] = $helper->getParentProductcategory($virtuemart_product_id); } if(!empty( $query['virtuemart_category_id'])){ $categoryRoute = $helper->getCategoryRoute($query['virtuemart_category_id']); if ($categoryRoute->route) $segments[] = $categoryRoute->route; if ($categoryRoute->itemId) $query['Itemid'] = $categoryRoute->itemId; else $query['Itemid'] = $jmenu['virtuemart']; } else { $query['Itemid'] = $jmenu['virtuemart']?$jmenu['virtuemart']:@$jmenu['virtuemart_category_id'][0]; } unset($query['virtuemart_category_id']); if($virtuemart_product_id) $segments[] = $helper->getProductName($virtuemart_product_id); } if (!count($query)) return $segments; break; case 'manufacturer'; if(isset($query['virtuemart_manufacturer_id'])) { if (isset($jmenu['virtuemart_manufacturer_id'][ $query['virtuemart_manufacturer_id'] ] ) ) { $query['Itemid'] = $jmenu['virtuemart_manufacturer_id'][$query['virtuemart_manufacturer_id']]; } else { $segments[] = $helper->lang('manufacturers').'/'.$helper->getManufacturerName($query['virtuemart_manufacturer_id']) ; if ( isset($jmenu['manufacturer']) ) $query['Itemid'] = $jmenu['manufacturer']; else $query['Itemid'] = $jmenu['virtuemart']; } unset($query['virtuemart_manufacturer_id']); } else { if ( isset($jmenu['manufacturer']) ) $query['Itemid'] = $jmenu['manufacturer']; else $query['Itemid'] = $jmenu['virtuemart']; } break; case 'user'; if ( isset($jmenu['user']) ) $query['Itemid'] = $jmenu['user']; else { $segments[] = $helper->lang('user') ; $query['Itemid'] = $jmenu['virtuemart']; } if (isset($query['task'])) { //vmdebug('my task in user view',$query['task']); if($query['task']=='editaddresscart'){ if ($query['addrtype'] == 'ST'){ $segments[] = $helper->lang('editaddresscartST') ; } else { $segments[] = $helper->lang('editaddresscartBT') ; } } else if($query['task']=='editaddresscheckout'){ if ($query['addrtype'] == 'ST'){ $segments[] = $helper->lang('editaddresscheckoutST') ; } else { $segments[] = $helper->lang('editaddresscheckoutBT') ; } } else if($query['task']=='editaddress'){ if (isset($query['addrtype']) and $query['addrtype'] == 'ST'){ $segments[] = $helper->lang('editaddressST') ; } else { $segments[] = $helper->lang('editaddressBT') ; } } else { $segments[] = $helper->lang($query['task']); } /* if ($query['addrtype'] == 'BT' && $query['task']='editaddresscart') $segments[] = $helper->lang('editaddresscartBT') ; elseif ($query['addrtype'] == 'ST' && $query['task']='editaddresscart') $segments[] = $helper->lang('editaddresscartST') ; elseif ($query['addrtype'] == 'BT') $segments[] = $helper->lang('editaddresscheckoutST') ; elseif ($query['addrtype'] == 'ST') $segments[] = $helper->lang('editaddresscheckoutST') ; else $segments[] = $query['task'] ;*/ unset ($query['task'] , $query['addrtype']); } break; case 'vendor'; /* VM208 */ if(isset($query['virtuemart_vendor_id'])) { if (isset($jmenu['virtuemart_vendor_id'][ $query['virtuemart_vendor_id'] ] ) ) { $query['Itemid'] = $jmenu['virtuemart_vendor_id'][$query['virtuemart_vendor_id']]; } else { if ( isset($jmenu['vendor']) ) { $query['Itemid'] = $jmenu['vendor']; } else { $segments[] = $helper->lang('vendor') ; $query['Itemid'] = $jmenu['virtuemart']; } } } else if ( isset($jmenu['vendor']) ) { $query['Itemid'] = $jmenu['vendor']; } else { $segments[] = $helper->lang('vendor') ; $query['Itemid'] = $jmenu['virtuemart']; } if (isset($query['virtuemart_vendor_id'])) { //$segments[] = $helper->lang('vendor').'/'.$helper->getVendorName($query['virtuemart_vendor_id']) ; $segments[] = $helper->getVendorName($query['virtuemart_vendor_id']) ; unset ($query['virtuemart_vendor_id'] ); } break; case 'cart'; if ( isset($jmenu['cart']) ) $query['Itemid'] = $jmenu['cart']; else { $segments[] = $helper->lang('cart') ; $query['Itemid'] = $jmenu['virtuemart']; } break; case 'orders'; if ( isset($jmenu['orders']) ) $query['Itemid'] = $jmenu['orders']; else { $segments[] = $helper->lang('orders') ; $query['Itemid'] = $jmenu['virtuemart']; } if ( isset($query['order_number']) ) { $segments[] = 'number/'.$query['order_number']; unset ($query['order_number'],$query['layout']); } else if ( isset($query['virtuemart_order_id']) ) { $segments[] = 'id/'.$query['virtuemart_order_id']; unset ($query['virtuemart_order_id'],$query['layout']); } //else unset ($query['layout']); break; // sef only view default ; $segments[] = $view; } // if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'config.php'); // vmdebug("case 'productdetails'",$query); if (isset($query['task'])) { $segments[] = $helper->lang($query['task']); unset($query['task']); } if (isset($query['layout'])) { $segments[] = $helper->lang($query['layout']) ; unset($query['layout']); } // sef the slimbox View /* if (isset($query['tmpl'])) { //if ( $query['tmpl'] = 'component') $segments[] = 'modal' ; $segments[] = $query['tmpl'] ; unset($query['tmpl']); }*/ return $segments; } /* This function can be slower because is used only one time to find the real URL*/ function virtuemartParseRoute($segments) { $vars = array(); $helper = vmrouterHelper::getInstance(); if ($helper->router_disabled) { $total = count($segments); for ($i = 0; $i < $total; $i=$i+2) { $vars[ $segments[$i] ] = $segments[$i+1]; } return $vars; } if (empty($segments)) { return $vars; } //$lang = $helper->lang ; // revert '-' (Joomla change - to :) // foreach ($segments as &$value) { $value = str_replace(':', '-', $value); } /*$vars['view'] = 'category'; if(isset($helper->activeMenu->virtuemart_category_id)){ $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id ; }*/ // $splitted = explode(',',$segments[0],2); $splitted = explode(',',end($segments),2); if ( $helper->compareKey($splitted[0] ,'results')){ // array_shift($segments); array_pop($segments); $results = explode('-',$splitted[1],2); //Pagination has changed, removed the -1 note by Max Milbers NOTE: Works on j1.5, but NOT j1.7 // limitstart is swapped by joomla to start ! See includes/route.php if ($start = $results[0]-1) $vars['limitstart'] = $start; else $vars['limitstart'] = 0 ; $vars['limit'] = $results[1]-$results[0]+1; } else { $vars['limitstart'] = 0 ; if(vmrouterHelper::$limit === null){ vmrouterHelper::$limit = VmConfig::get('list_limit', 20); } $vars['limit'] = vmrouterHelper::$limit; } if (empty($segments)) { $vars['view'] = 'category'; $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id ; return $vars; } //Translation of the ordering direction is not really useful and costs just energy //if ( $helper->compareKey(end($segments),'dirDesc') ){ if ( end($segments) == 'dirDesc' ){ $vars['dir'] ='DESC' ; array_pop($segments); if (empty($segments)) { $vars['view'] = 'category'; $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id ; return $vars; } } else //if ( $helper->compareKey(end($segments),'dirAsc') ){ if ( end($segments) == 'dirAsc' ){ $vars['dir'] ='ASC' ; array_pop($segments); if (empty($segments)) { $vars['view'] = 'category'; $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id ; return $vars; } } // $orderby = explode(',',$segments[0],2); $orderby = explode(',',end($segments),2); if ( $helper->compareKey($orderby[0] , 'by') ) { $vars['orderby'] = $helper->getOrderingKey($orderby[1]) ; // array_shift($segments); array_pop($segments); if (empty($segments)) { $vars['view'] = 'category'; $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id ; return $vars; } } if ( $segments[0] == 'product') { $vars['view'] = 'product'; $vars['task'] = $segments[1]; $vars['tmpl'] = 'component'; return $vars; } if ( $segments[0] == 'checkout') { $vars['view'] = 'cart'; $vars['task'] = $segments[0]; return $vars; } if ( $helper->compareKey($segments[0] ,'manufacturer') ) { if(!empty($segments[1])){ array_shift($segments); $vars['virtuemart_manufacturer_id'] = $helper->getManufacturerId($segments[0]); } array_shift($segments); // OSP 2012-02-29 removed search malforms SEF path and search is performed // $vars['search'] = 'true'; if (empty($segments)) { $vars['view'] = 'category'; $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id ; return $vars; } } /* added in vm208 */ // if no joomla link: vendor/vendorname/layout // if joomla link joomlalink/vendorname/layout if ( $helper->compareKey($segments[0] ,'vendor') ) { $vars['virtuemart_vendor_id'] = $helper->getVendorId($segments[1]); // OSP 2012-02-29 removed search malforms SEF path and search is performed // $vars['search'] = 'true'; // this can never happen if (empty($segments)) { $vars['view'] = 'vendor'; $vars['virtuemart_vendor_id'] = $helper->activeMenu->virtuemart_vendor_id ; return $vars; } } if ( $helper->compareKey($segments[0] ,'search') ) { $vars['search'] = 'true'; array_shift($segments); if ( !empty ($segments) ) { $vars['keyword'] = array_shift($segments); } $vars['view'] = 'category'; $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id ; if (empty($segments)) return $vars; } if (end($segments) == 'modal') { $vars['tmpl'] = 'component'; array_pop($segments); } if ( $helper->compareKey(end($segments) ,'askquestion') ) { $vars = (array)$helper->activeMenu ; $vars['task'] = 'askquestion'; array_pop($segments); } elseif ( $helper->compareKey(end($segments) ,'recommend') ) { $vars = (array)$helper->activeMenu ; $vars['task'] = 'recommend'; array_pop($segments); } elseif ( $helper->compareKey(end($segments) ,'notify') ) { $vars = (array)$helper->activeMenu ; $vars['layout'] = 'notify'; array_pop($segments); } if (empty($segments)) return $vars ; // View is first segment now $view = $segments[0]; if ( $helper->compareKey($view,'orders') || $helper->activeMenu->view == 'orders') { $vars['view'] = 'orders'; if ( $helper->compareKey($view,'orders')){ array_shift($segments); } if (empty($segments)) { $vars['layout'] = 'list'; } else if ($helper->compareKey($segments[0],'list') ) { $vars['layout'] = 'list'; array_shift($segments); } if ( !empty($segments) ) { if ($segments[0] =='number') $vars['order_number'] = $segments[1] ; else $vars['virtuemart_order_id'] = $segments[1] ; $vars['layout'] = 'details'; } return $vars; } else if ( $helper->compareKey($view,'user') || $helper->activeMenu->view == 'user') { $vars['view'] = 'user'; if ( $helper->compareKey($view,'user') ) { array_shift($segments); } if ( !empty($segments) ) { if ( $helper->compareKey($segments[0] ,'editaddresscartBT') ) { $vars['addrtype'] = 'BT' ; $vars['task'] = 'editaddresscart' ; } elseif ( $helper->compareKey($segments[0] ,'editaddresscartST') ) { $vars['addrtype'] = 'ST' ; $vars['task'] = 'editaddresscart' ; } elseif ( $helper->compareKey($segments[0] ,'editaddresscheckoutBT') ) { $vars['addrtype'] = 'BT' ; $vars['task'] = 'editaddresscheckout' ; } elseif ( $helper->compareKey($segments[0] ,'editaddresscheckoutST') ) { $vars['addrtype'] = 'ST' ; $vars['task'] = 'editaddresscheckout' ; } elseif ( $helper->compareKey($segments[0] ,'editaddressST') ) { $vars['addrtype'] = 'ST' ; $vars['task'] = 'editaddressST' ; } elseif ( $helper->compareKey($segments[0] ,'editaddressBT') ) { $vars['addrtype'] = 'BT' ; $vars['task'] = 'edit' ; $vars['layout'] = 'edit' ; //I think that should be the layout, not the task } elseif ( $helper->compareKey($segments[0] ,'edit') ) { $vars['layout'] = 'edit' ; //uncomment and lets test } else $vars['task'] = $segments[0] ; } return $vars; } else if ( $helper->compareKey($view,'vendor') || $helper->activeMenu->view == 'vendor') { /* vm208 */ $vars['view'] = 'vendor'; if ( $helper->compareKey($view,'vendor') ) { array_shift($segments); if (empty($segments)) return $vars; } //$vars['virtuemart_vendor_id'] = array_shift($segments);//// already done //array_shift($segments); $vars['virtuemart_vendor_id'] = $helper->getVendorId($segments[0]); array_shift($segments); if(!empty($segments)) { if ( $helper->compareKey($segments[0] ,'contact') ) $vars['layout'] = 'contact' ; elseif ( $helper->compareKey($segments[0] ,'tos') ) $vars['layout'] = 'tos' ; elseif ( $helper->compareKey($segments[0] ,'details') ) $vars['layout'] = 'details' ; } else $vars['layout'] = 'details' ; return $vars; } elseif ( $helper->compareKey($segments[0] ,'pluginresponse') ) { $vars['view'] = 'pluginresponse'; array_shift($segments); if ( !empty ($segments) ) { $vars['task'] = $segments[0]; array_shift($segments); } if ( isset($segments[0]) && $segments[0] == 'modal') { $vars['tmpl'] = 'component'; array_shift($segments); } return $vars; } else if ( $helper->compareKey($view,'cart') || $helper->activeMenu->view == 'cart') { $vars['view'] = 'cart'; if ( $helper->compareKey($view,'cart') ) { array_shift($segments); if (empty($segments)) return $vars; } if ( $helper->compareKey($segments[0] ,'edit_shipment') ) $vars['task'] = 'edit_shipment' ; elseif ( $helper->compareKey($segments[0] ,'editpayment') ) $vars['task'] = 'editpayment' ; elseif ( $helper->compareKey($segments[0] ,'delete') ) $vars['task'] = 'delete' ; elseif ( $helper->compareKey($segments[0] ,'checkout') ) $vars['task'] = 'checkout' ; else $vars['task'] = $segments[0]; return $vars; } else if ( $helper->compareKey($view,'manufacturers') || $helper->activeMenu->view == 'manufacturer') { $vars['view'] = 'manufacturer'; if ( $helper->compareKey($view,'manufacturers') ) { array_shift($segments); } if (!empty($segments) ) { $vars['virtuemart_manufacturer_id'] = $helper->getManufacturerId($segments[0]); array_shift($segments); } if ( isset($segments[0]) && $segments[0] == 'modal') { $vars['tmpl'] = 'component'; array_shift($segments); } // if (isset($helper->activeMenu->virtuemart_manufacturer_id)) // $vars['virtuemart_manufacturer_id'] = $helper->activeMenu->virtuemart_manufacturer_id ; vmdebug('my parsed URL vars',$vars); return $vars; } /* * seo_sufix must never be used in category or router can't find it * eg. suffix as "-suffix", a category with "name-suffix" get always a false return * Trick : YOu can simply use "-p","-x","-" or ".htm" for better seo result if it's never in the product/category name ! */ /* if (substr(end($segments ), -(int)$helper->seo_sufix_size ) == $helper->seo_sufix ) { vmdebug('$segments productdetail',$segments,end($segments ));*/ $last_elem = end($segments); $slast_elem = prev($segments); if ( (substr($last_elem, -(int)$helper->seo_sufix_size ) == $helper->seo_sufix) || ($last_elem=='notify' && substr($slast_elem, -(int)$helper->seo_sufix_size ) == $helper->seo_sufix) ) { $vars['view'] = 'productdetails'; if($last_elem=='notify') { $vars['layout'] = 'notify'; array_pop($segments); } if (!$helper->use_id ) { $product = $helper->getProductId($segments ,$helper->activeMenu->virtuemart_category_id); $vars['virtuemart_product_id'] = $product['virtuemart_product_id']; $vars['virtuemart_category_id'] = $product['virtuemart_category_id']; //vmdebug('View productdetails, using case !$helper->use_id',$vars,$helper->activeMenu); } elseif (isset($segments[1]) ){ $vars['virtuemart_product_id'] = $segments[0]; $vars['virtuemart_category_id'] = $segments[1]; //vmdebug('View productdetails, using case isset($segments[1]',$vars); } else { $vars['virtuemart_product_id'] = $segments[0]; $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id ; //vmdebug('View productdetails, using case "else", which uses $helper->activeMenu->virtuemart_category_id ',$vars); } } elseif (!$helper->use_id && ($helper->activeMenu->view == 'category' ) ) { $vars['virtuemart_category_id'] = $helper->getCategoryId (end($segments) ,$helper->activeMenu->virtuemart_category_id); $vars['view'] = 'category' ; } elseif (isset($segments[0]) && ctype_digit ($segments[0]) || $helper->activeMenu->virtuemart_category_id>0 ) { $vars['virtuemart_category_id'] = $segments[0]; $vars['view'] = 'category'; } elseif ($helper->activeMenu->virtuemart_category_id >0 && $vars['view'] != 'productdetails') { $vars['virtuemart_category_id'] = $helper->activeMenu->virtuemart_category_id ; $vars['view'] = 'category'; } elseif ($id = $helper->getCategoryId (end($segments) ,$helper->activeMenu->virtuemart_category_id )) { // find corresponding category . If not, segment 0 must be a view $vars['virtuemart_category_id'] = $id; $vars['view'] = 'category' ; } else { $vars['view'] = $segments[0] ; if ( isset($segments[1]) ) { $vars['task'] = $segments[1] ; } } //vmdebug('Router vars',$vars); return $vars; } class vmrouterHelper { /* language array */ public $lang = null ; public $query = array(); /* Joomla menus ID object from com_virtuemart */ public $menu = null ; /* Joomla active menu( itemId ) object */ public $activeMenu = null ; public $menuVmitems = null; /* * $use_id type boolean * Use the Id's of categorie and product or not */ public $use_id = false ; public $seo_translate = false ; private $orderings = null ; public static $limit = null ; /* * $router_disabled type boolean * true = don't Use the router */ public $router_disabled = false ; /* instance of class */ private static $_instance = false; private static $_catRoute = array (); public $CategoryName = array(); private $dbview = array('vendor' =>'vendor','category' =>'category','virtuemart' =>'virtuemart','productdetails' =>'product','cart' => 'cart','manufacturer' => 'manufacturer','user'=>'user'); private function __construct($query) { if (!$this->router_disabled = VmConfig::get('seo_disabled', false)) { $this->seo_translate = VmConfig::get('seo_translate', false); $this->vmlang = VMLANG; if ( $this->seo_translate ) { $this->Jlang = VmConfig::loadJLang('com_virtuemart.sef',true); } else { $this->Jlang = JFactory::getLanguage(); } if ( JVM_VERSION===1 ) $this->setMenuItemId(); else $this->setMenuItemIdJ17(); $this->setActiveMenu(); $this->use_id = VmConfig::get('seo_use_id', false); $this->seo_sufix = VmConfig::get('seo_sufix', '-detail'); $this->seo_sufix_size = strlen($this->seo_sufix) ; $this->edit = ('edit' == JRequest::getCmd('task') ); // if language switcher we must know the $query $this->query = $query; } } public static function getInstance(&$query = null) { if (!class_exists( 'VmConfig' )) { require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'config.php'); } VmConfig::loadConfig(); if (! self::$_instance){ self::$_instance = new vmrouterHelper ($query); if (self::$limit===null){ $mainframe = Jfactory::getApplication(); ; $view = 'virtuemart'; if(isset($query['view'])) $view = $query['view']; self::$limit= $mainframe->getUserStateFromRequest('com_virtuemart.'.$view.'.limit', VmConfig::get('list_limit', 20), 'int'); // self::$limit= $mainframe->getUserStateFromRequest('global.list.limit', 'limit', VmConfig::get('list_limit', 20), 'int'); } } return self::$_instance; } /* Set $this-lang (Translator for language from virtuemart string) to load only once*/ /*public function setLangs(){ $this->vmlang = VMLANG; $this->Jlang = JFactory::getLanguage(); if ( $this->seo_translate ) { // use translator $extension = 'com_virtuemart.sef'; $base_dir = JPATH_SITE; $this->Jlang->load($extension, $base_dir); } }/*/ public function getCategoryRoute($virtuemart_category_id){ $cache = JFactory::getCache('_virtuemart',''); $key = $virtuemart_category_id. $this->vmlang ; // internal cache key if (!($CategoryRoute = $cache->get($key))) { $CategoryRoute = $this->getCategoryRouteNocache($virtuemart_category_id); $cache->store($CategoryRoute, $key); } return $CategoryRoute ; } /* Get Joomla menu item and the route for category */ public function getCategoryRouteNocache($virtuemart_category_id){ if (! array_key_exists ($virtuemart_category_id . $this->vmlang, self::$_catRoute)){ $category = new stdClass(); $category->route = ''; $category->itemId = 0; $menuCatid = 0 ; $ismenu = false ; // control if category is joomla menu if (isset($this->menu['virtuemart_category_id'])) { if (isset( $this->menu['virtuemart_category_id'][$virtuemart_category_id])) { $ismenu = true; $category->itemId = $this->menu['virtuemart_category_id'][$virtuemart_category_id] ; } else { $CatParentIds = $this->getCategoryRecurse($virtuemart_category_id,0) ; /* control if parent categories are joomla menu */ foreach ($CatParentIds as $CatParentId) { // No ? then find the parent menu categorie ! if (isset( $this->menu['virtuemart_category_id'][$CatParentId]) ) { $category->itemId = $this->menu['virtuemart_category_id'][$CatParentId] ; $menuCatid = $CatParentId; break; } } } } if ($ismenu==false) { if ( $this->use_id ) $category->route = $virtuemart_category_id.'/'; if (!isset ($this->CategoryName[$virtuemart_category_id])) { $this->CategoryName[$virtuemart_category_id] = $this->getCategoryNames($virtuemart_category_id, $menuCatid ); } $category->route .= $this->CategoryName[$virtuemart_category_id] ; if ($menuCatid == 0 && $this->menu['virtuemart']) $category->itemId = $this->menu['virtuemart'] ; } self::$_catRoute[$virtuemart_category_id . $this->vmlang] = $category; } return self::$_catRoute[$virtuemart_category_id . $this->vmlang] ; } /*get url safe names of category and parents categories */ public function getCategoryNames($virtuemart_category_id,$catMenuId=0){ static $categoryNamesCache = array(); $strings = array(); $db = JFactory::getDBO(); $parents_id = array_reverse($this->getCategoryRecurse($virtuemart_category_id,$catMenuId)) ; foreach ($parents_id as $id ) { if(!isset($categoryNamesCache[$id])){ $q = 'SELECT `slug` as name FROM `#__virtuemart_categories_'.$this->vmlang.'` WHERE `virtuemart_category_id`='.(int)$id; $db->setQuery($q); $cslug = $db->loadResult(); $categoryNamesCache[$id] = $cslug; $strings[] = $cslug; } else { $strings[] = $categoryNamesCache[$id]; } } if(function_exists('mb_strtolower')){ return mb_strtolower(implode ('/', $strings ) ); } else { return strtolower(implode ('/', $strings ) ); } } /* Get parents of category*/ public function getCategoryRecurse($virtuemart_category_id,$catMenuId,$first=true ) { static $idsArr = array(); if ($first==true) $idsArr = array(); $db = JFactory::getDBO(); $q = "SELECT `category_child_id` AS `child`, `category_parent_id` AS `parent` FROM #__virtuemart_category_categories AS `xref` WHERE `xref`.`category_child_id`= ".(int)$virtuemart_category_id; $db->setQuery($q); $ids = $db->loadObject(); if (isset ($ids->child)) { $idsArr[] = $ids->child; if($ids->parent != 0 and $catMenuId != $virtuemart_category_id and $catMenuId != $ids->parent) { $this->getCategoryRecurse($ids->parent,$catMenuId,false); } } return $idsArr ; } /* return id of categories * $names are segments * $virtuemart_category_ids is joomla menu virtuemart_category_id */ public function getCategoryId($slug,$virtuemart_category_id ){ $db = JFactory::getDBO(); $q = "SELECT `virtuemart_category_id` FROM `#__virtuemart_categories_".$this->vmlang."` WHERE `slug` LIKE '".$db->getEscaped($slug)."' "; $db->setQuery($q); if (!$category_id = $db->loadResult()) { $category_id = $virtuemart_category_id; } return $category_id ; } /* Get URL safe Product name */ public function getProductName($id){ static $productNamesCache = array(); if(!isset($productNamesCache[$id])){ $db = JFactory::getDBO(); $query = 'SELECT `slug` FROM `#__virtuemart_products_'.$this->vmlang.'` ' . ' WHERE `virtuemart_product_id` = ' . (int) $id; $db->setQuery($query); $name = $db->loadResult(); $productNamesCache[$id] = $name ; } else { $name = $productNamesCache[$id]; } return $name.$this->seo_sufix; } var $counter = 0; /* Get parent Product first found category ID */ public function getParentProductcategory($id){ $virtuemart_category_id = 0; $db = JFactory::getDBO(); $query = 'SELECT `product_parent_id` FROM `#__virtuemart_products` ' . ' WHERE `virtuemart_product_id` = ' . (int) $id; $db->setQuery($query); /* If product is child then get parent category ID*/ if ($parent_id = $db->loadResult()) { $query = 'SELECT `virtuemart_category_id` FROM `#__virtuemart_product_categories` ' . ' WHERE `virtuemart_product_id` = ' . $parent_id; $db->setQuery($query); //When the child and parent id is the same, this creates a deadlock //add $counter, dont allow more then 10 levels if (!$virtuemart_category_id = $db->loadResult()){ $this->counter++; if($this->counter<10){ $this->getParentProductcategory($parent_id) ; } } } $this->counter = 0; return $virtuemart_category_id ; } /* get product and category ID */ public function getProductId($names,$virtuemart_category_id = NULL ){ $productName = array_pop($names); $productName = substr($productName, 0, -(int)$this->seo_sufix_size ); $product = array(); $categoryName = end($names); $product['virtuemart_category_id'] = $this->getCategoryId($categoryName,$virtuemart_category_id ) ; $db = JFactory::getDBO(); $q = 'SELECT `p`.`virtuemart_product_id` FROM `#__virtuemart_products_'.$this->vmlang.'` AS `p` LEFT JOIN `#__virtuemart_product_categories` AS `xref` ON `p`.`virtuemart_product_id` = `xref`.`virtuemart_product_id` WHERE `p`.`slug` LIKE "'.$db->getEscaped($productName).'" '; //$q .= " AND `xref`.`virtuemart_category_id` = ".(int)$product['virtuemart_category_id']; $db->setQuery($q); $product['virtuemart_product_id'] = $db->loadResult(); /* WARNING product name must be unique or you can't acces the product */ return $product ; } /* Get URL safe Manufacturer name */ public function getManufacturerName($virtuemart_manufacturer_id ){ $db = JFactory::getDBO(); $query = 'SELECT `slug` FROM `#__virtuemart_manufacturers_'.$this->vmlang.'` WHERE virtuemart_manufacturer_id='.(int)$virtuemart_manufacturer_id; $db->setQuery($query); return $db->loadResult(); } /* Get Manufacturer id */ public function getManufacturerId($slug ){ $db = JFactory::getDBO(); $query = "SELECT `virtuemart_manufacturer_id` FROM `#__virtuemart_manufacturers_".$this->vmlang."` WHERE `slug` LIKE '".$db->getEscaped($slug)."' "; $db->setQuery($query); return $db->loadResult(); } /* Get URL safe Manufacturer name */ public function getVendorName($virtuemart_vendor_id ){ $db = JFactory::getDBO(); $query = 'SELECT `slug` FROM `#__virtuemart_vendors_'.$this->vmlang.'` WHERE virtuemart_vendor_id='.(int)$virtuemart_vendor_id; $db->setQuery($query); return $db->loadResult(); } /* Get Manufacturer id */ public function getVendorId($slug ){ $db = JFactory::getDBO(); $query = "SELECT `virtuemart_vendor_id` FROM `#__virtuemart_vendors_".$this->vmlang."` WHERE `slug` LIKE '".$db->getEscaped($slug)."' "; $db->setQuery($query); return $db->loadResult(); } /* Set $this->menu with the Item ID from Joomla Menus */ private function setMenuItemIdJ17(){ $home = false ; $component = JComponentHelper::getComponent('com_virtuemart'); //else $items = $menus->getItems('component_id', $component->id); //get all vm menus $db = JFactory::getDBO(); $fallback = ''; $jLangTag = $this->Jlang->getTag(); if($jLangTag!=VmConfig::$langTag){ $fallback= 'or language = "'.$jLangTag.'"'; } $query = 'SELECT * FROM `#__menu` where `link` like "index.php?option=com_virtuemart%" and client_id=0 and published=1 and (language="*" or language = "'.VmConfig::$langTag.'" '.$fallback.' )' ; $db->setQuery($query); // vmdebug('setMenuItemIdJ17 q',$query); $this->menuVmitems= $db->loadObjectList(); $homeid =0; if(empty($this->menuVmitems)){ VmConfig::loadJLang('com_virtuemart', true); vmWarn(JText::_('COM_VIRTUEMART_ASSIGN_VM_TO_MENU')); } else { // Search Virtuemart itemID in joomla menu foreach ($this->menuVmitems as $item) { $linkToSplit= explode ('&',$item->link); $link =array(); foreach ($linkToSplit as $tosplit) { $splitpos = strpos($tosplit, '='); $link[ (substr($tosplit, 0, $splitpos) ) ] = substr($tosplit, $splitpos+1); } //vmDebug('menu view link',$link); //This is fix to prevent entries in the errorlog. if(!empty($link['view'])){ $view = $link['view'] ; if (array_key_exists($view,$this->dbview) ){ $dbKey = $this->dbview[$view]; } else { $dbKey = false ; } if ( isset($link['virtuemart_'.$dbKey.'_id']) && $dbKey ){ $this->menu['virtuemart_'.$dbKey.'_id'][ $link['virtuemart_'.$dbKey.'_id'] ] = $item->id; } elseif ($home == $view ) continue; else $this->menu[$view]= $item->id ; if ((int)$item->home === 1) { $home = $view; $homeid = $item->id; } } else { vmdebug('my item with empty $link["view"]',$item); vmError('$link["view"] is empty'); } } } // init unsetted views to defaut front view or nothing(prevent duplicates routes) if ( !isset( $this->menu['virtuemart']) ) { if (isset ($this->menu['virtuemart_category_id'][0]) ) { $this->menu['virtuemart'] = $this->menu['virtuemart_category_id'][0] ; }else $this->menu['virtuemart'] = $homeid; } // if ( !isset( $this->menu['manufacturer']) ) { // $this->menu['manufacturer'] = $this->menu['virtuemart'] ; // } // if ( !isset( $this->menu['vendor']) ) { // $this->menu['manufacturer'] = $this->menu['virtuemart'] ; // } } /* Set $this->menu with the Item ID from Joomla Menus */ private function setMenuItemId(){ $app = JFactory::getApplication(); $menus = $app->getMenu('site'); $component = JComponentHelper::getComponent('com_virtuemart'); $items = $menus->getItems('componentid', $component->id); if(empty($items)){ VmConfig::loadJLang('com_virtuemart', true); vmWarn(JText::_('COM_VIRTUEMART_ASSIGN_VM_TO_MENU')); } else { // Search Virtuemart itemID in joomla menu foreach ($items as $item) { $view = $item->query['view'] ; if ($view=='virtuemart') $this->menu['virtuemart'] = $item->id; $dbKey = $this->dbview[$view]; if ( isset($item->query['virtuemart_'.$dbKey.'_id']) ) $this->menu['virtuemart_'.$dbKey.'_id'][ $item->query['virtuemart_'.$dbKey.'_id'] ] = $item->id; else $this->menu[$view]= $item->id ; } } // init unsetted views to defaut front view or nothing(prevent duplicates routes) if ( !isset( $this->menu['virtuemart'][0]) ) { $this->menu['virtuemart'][0] = null; } if ( !isset( $this->menu['manufacturer']) ) { $this->menu['manufacturer'] = $this->menu['virtuemart'][0] ; } } /* Set $this->activeMenu to current Item ID from Joomla Menus */ private function setActiveMenu(){ if ($this->activeMenu === null ) { //$menu = JSite::getMenu(); //$menu = JFactory::getApplication()->getMenu(); $app = JFactory::getApplication(); $menu = $app->getMenu('site'); if ($Itemid = JRequest::getInt('Itemid',0) ) { $menuItem = $menu->getItem($Itemid); } else { $menuItem = $menu->getActive(); } //vmdebug('What is my active menu now?',$menuItem); $this->activeMenu = new stdClass(); $this->activeMenu->view = (empty($menuItem->query['view'])) ? null : $menuItem->query['view']; $this->activeMenu->virtuemart_category_id = (empty($menuItem->query['virtuemart_category_id'])) ? 0 : $menuItem->query['virtuemart_category_id']; $this->activeMenu->virtuemart_product_id = (empty($menuItem->query['virtuemart_product_id'])) ? null : $menuItem->query['virtuemart_product_id']; $this->activeMenu->virtuemart_manufacturer_id = (empty($menuItem->query['virtuemart_manufacturer_id'])) ? null : $menuItem->query['virtuemart_manufacturer_id']; /* added in 208 */ $this->activeMenu->virtuemart_vendor_id = (empty($menuItem->query['virtuemart_vendor_id'])) ? null : $menuItem->query['virtuemart_vendor_id']; $this->activeMenu->Component = (empty($menuItem->component)) ? null : $menuItem->component; } } /* * Get language key or use $key in route */ public function lang($key) { if ($this->seo_translate ) { $jtext = (strtoupper( $key ) ); if ($this->Jlang->hasKey('COM_VIRTUEMART_SEF_'.$jtext) ){ //vmdebug('router lang translated '.$jtext); return JText::_('COM_VIRTUEMART_SEF_'.$jtext); } } //vmdebug('router lang '.$key); //falldown return $key; } /* * revert key or use $key in route */ public function getOrderingKey($key) { if ($this->seo_translate ) { if ($this->orderings == null) { $this->orderings = array( 'virtuemart_product_id'=> JText::_('COM_VIRTUEMART_SEF_PRODUCT_ID'), 'product_sku' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_SKU'), 'product_price' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_PRICE'), 'category_name' => JText::_('COM_VIRTUEMART_SEF_CATEGORY_NAME'), 'category_description'=> JText::_('COM_VIRTUEMART_SEF_CATEGORY_DESCRIPTION'), 'mf_name' => JText::_('COM_VIRTUEMART_SEF_MF_NAME'), 'product_s_desc' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_S_DESC'), 'product_desc' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_DESC'), 'product_weight' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_WEIGHT'), 'product_weight_uom'=> JText::_('COM_VIRTUEMART_SEF_PRODUCT_WEIGHT_UOM'), 'product_length' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_LENGTH'), 'product_width' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_WIDTH'), 'product_height' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_HEIGHT'), 'product_lwh_uom' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_LWH_UOM'), 'product_in_stock' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_IN_STOCK'), 'low_stock_notification'=> JText::_('COM_VIRTUEMART_SEF_LOW_STOCK_NOTIFICATION'), 'product_available_date'=> JText::_('COM_VIRTUEMART_SEF_PRODUCT_AVAILABLE_DATE'), 'product_availability' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_AVAILABILITY'), 'product_special' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_SPECIAL'), 'created_on' => JText::_('COM_VIRTUEMART_SEF_CREATED_ON'), // 'p.modified_on' => JText::_('COM_VIRTUEMART_SEF_MDATE'), 'product_name' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_NAME'), 'product_sales' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_SALES'), 'product_unit' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_UNIT'), 'product_packaging' => JText::_('COM_VIRTUEMART_SEF_PRODUCT_PACKAGING'), 'intnotes' => JText::_('COM_VIRTUEMART_SEF_INTNOTES'), 'pc.ordering' => JText::_('COM_VIRTUEMART_SEF_ORDERING') ); } if ($result = array_search($key,$this->orderings )) { return $result; } } return $key; } /* * revert string key or use $key in route */ public function compareKey($string, $key) { if ($this->seo_translate ) { if (JText::_('COM_VIRTUEMART_SEF_'.$key) == $string ) { return true; } } if ($string == $key) return true; return false; } } // pure php no closing tag home/academiac/www/components/com_users/router.php 0000644 00000011614 15137253130 0016427 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_users * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; /** * Function to build a Users URL route. * * @param array The array of query string values for which to build a route. * @return array The URL route with segments represented as an array. * @since 1.5 */ function UsersBuildRoute(&$query) { // Declare static variables. static $items; static $default; static $registration; static $profile; static $login; static $remind; static $resend; static $reset; // Initialise variables. $segments = array(); // Get the relevant menu items if not loaded. if (empty($items)) { // Get all relevant menu items. $app = JFactory::getApplication(); $menu = $app->getMenu(); $items = $menu->getItems('component', 'com_users'); // Build an array of serialized query strings to menu item id mappings. for ($i = 0, $n = count($items); $i < $n; $i++) { // Check to see if we have found the resend menu item. if (empty($resend) && !empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'resend')) { $resend = $items[$i]->id; } // Check to see if we have found the reset menu item. if (empty($reset) && !empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'reset')) { $reset = $items[$i]->id; } // Check to see if we have found the remind menu item. if (empty($remind) && !empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'remind')) { $remind = $items[$i]->id; } // Check to see if we have found the login menu item. if (empty($login) && !empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'login')) { $login = $items[$i]->id; } // Check to see if we have found the registration menu item. if (empty($registration) && !empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'registration')) { $registration = $items[$i]->id; } // Check to see if we have found the profile menu item. if (empty($profile) && !empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'profile')) { $profile = $items[$i]->id; } } // Set the default menu item to use for com_users if possible. if ($profile) { $default = $profile; } elseif ($registration) { $default = $registration; } elseif ($login) { $default = $login; } } if (!empty($query['view'])) { switch ($query['view']) { case 'reset': if ($query['Itemid'] = $reset) { unset ($query['view']); } else { $query['Itemid'] = $default; } break; case 'resend': if ($query['Itemid'] = $resend) { unset ($query['view']); } else { $query['Itemid'] = $default; } break; case 'remind': if ($query['Itemid'] = $remind) { unset ($query['view']); } else { $query['Itemid'] = $default; } break; case 'login': if ($query['Itemid'] = $login) { unset ($query['view']); } else { $query['Itemid'] = $default; } break; case 'registration': if ($query['Itemid'] = $registration) { unset ($query['view']); } else { $query['Itemid'] = $default; } break; default: case 'profile': if (!empty($query['view'])) { $segments[] = $query['view']; } unset ($query['view']); if ($query['Itemid'] = $profile) { unset ($query['view']); } else { $query['Itemid'] = $default; } // Only append the user id if not "me". $user = JFactory::getUser(); if (!empty($query['user_id']) && ($query['user_id'] != $user->id)) { $segments[] = $query['user_id']; } unset ($query['user_id']); break; } } return $segments; } /** * Function to parse a Users URL route. * * @param array The URL route with segments represented as an array. * @return array The array of variables to set in the request. * @since 1.5 */ function UsersParseRoute($segments) { // Initialise variables. $vars = array(); // Only run routine if there are segments to parse. if (count($segments) < 1) { return; } // Get the package from the route segments. $userId = array_pop($segments); if (!is_numeric($userId)) { $vars['view'] = 'profile'; return $vars; } if (is_numeric($userId)) { // Get the package id from the packages table by alias. $db = JFactory::getDbo(); $db->setQuery( 'SELECT '.$db->quoteName('id') . ' FROM '.$db->quoteName('#__users') . ' WHERE '.$db->quoteName('id').' = '.(int) $userId ); $userId = $db->loadResult(); } // Set the package id if present. if ($userId) { // Set the package id. $vars['user_id'] = (int)$userId; // Set the view to package if not already set. if (empty($vars['view'])) { $vars['view'] = 'profile'; } } else { JError::raiseError(404, JText::_('JGLOBAL_RESOURCE_NOT_FOUND')); } return $vars; } home/academiac/www/libraries/joomla/application/router.php 0000644 00000021775 15137260376 0020026 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Application * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; /** * Set the available masks for the routing mode */ define('JROUTER_MODE_RAW', 0); define('JROUTER_MODE_SEF', 1); /** * Class to create and parse routes * * @package Joomla.Platform * @subpackage Application * @since 11.1 */ class JRouter extends JObject { /** * The rewrite mode * * @var integer * @since 11.1 */ protected $mode = null; /** * The rewrite mode * * @var integer * @since 11.1 * @deprecated use $mode declare as private */ protected $_mode = null; /** * An array of variables * * @var array * @since 11.1 */ protected $vars = array(); /** * An array of variables * * @var array * @since 11.1 * @deprecated use $vars declare as private */ protected $_vars = array(); /** * An array of rules * * @var array * @since 11.1 */ protected $rules = array( 'build' => array(), 'parse' => array() ); /** * An array of rules * * @var array * @since 11.1 * @deprecated use $rules declare as private */ protected $_rules = array( 'build' => array(), 'parse' => array() ); /** * @var array JRouter instances container. * @since 11.3 */ protected static $instances = array(); /** * Class constructor * * @param array $options Array of options * * @since 11.1 */ public function __construct($options = array()) { if (array_key_exists('mode', $options)) { $this->_mode = $options['mode']; } else { $this->_mode = JROUTER_MODE_RAW; } } /** * Returns the global JRouter object, only creating it if it * doesn't already exist. * * @param string $client The name of the client * @param array $options An associative array of options * * @return JRouter A JRouter object. * * @since 11.1 */ public static function getInstance($client, $options = array()) { if (empty(self::$instances[$client])) { // Load the router object $info = JApplicationHelper::getClientInfo($client, true); $path = $info->path . '/includes/router.php'; if (file_exists($path)) { include_once $path; // Create a JRouter object $classname = 'JRouter' . ucfirst($client); $instance = new $classname($options); } else { $error = JError::raiseError(500, JText::sprintf('JLIB_APPLICATION_ERROR_ROUTER_LOAD', $client)); return $error; } self::$instances[$client] = & $instance; } return self::$instances[$client]; } /** * Function to convert a route to an internal URI * * @param JURI &$uri The uri. * * @return array * * @since 11.1 */ public function parse(&$uri) { $vars = array(); // Process the parsed variables based on custom defined rules $vars = $this->_processParseRules($uri); // Parse RAW URL if ($this->_mode == JROUTER_MODE_RAW) { $vars += $this->_parseRawRoute($uri); } // Parse SEF URL if ($this->_mode == JROUTER_MODE_SEF) { $vars += $this->_parseSefRoute($uri); } return array_merge($this->getVars(), $vars); } /** * Function to convert an internal URI to a route * * @param string $url The internal URL * * @return string The absolute search engine friendly URL * * @since 11.1 */ public function build($url) { // Create the URI object $uri = $this->_createURI($url); // Process the uri information based on custom defined rules $this->_processBuildRules($uri); // Build RAW URL if ($this->_mode == JROUTER_MODE_RAW) { $this->_buildRawRoute($uri); } // Build SEF URL : mysite/route/index.php?var=x if ($this->_mode == JROUTER_MODE_SEF) { $this->_buildSefRoute($uri); } return $uri; } /** * Get the router mode * * @return integer * * @since 11.1 */ public function getMode() { return $this->_mode; } /** * Set the router mode * * @param integer $mode The routing mode. * * @return void * * @since 11.1 */ public function setMode($mode) { $this->_mode = $mode; } /** * Set a router variable, creating it if it doesn't exist * * @param string $key The name of the variable * @param mixed $value The value of the variable * @param boolean $create If True, the variable will be created if it doesn't exist yet * * @return void * * @since 11.1 */ public function setVar($key, $value, $create = true) { if ($create || array_key_exists($key, $this->_vars)) { $this->_vars[$key] = $value; } } /** * Set the router variable array * * @param array $vars An associative array with variables * @param boolean $merge If True, the array will be merged instead of overwritten * * @return void * * @since 11.1 */ public function setVars($vars = array(), $merge = true) { if ($merge) { $this->_vars = array_merge($this->_vars, $vars); } else { $this->_vars = $vars; } } /** * Get a router variable * * @param string $key The name of the variable * * @return mixed Value of the variable * * @since 11.1 */ public function getVar($key) { $result = null; if (isset($this->_vars[$key])) { $result = $this->_vars[$key]; } return $result; } /** * Get the router variable array * * @return array An associative array of router variables * * @since 11.1 */ public function getVars() { return $this->_vars; } /** * Attach a build rule * * @param callback $callback The function to be called * * @return void * * @since 11.1. */ public function attachBuildRule($callback) { $this->_rules['build'][] = $callback; } /** * Attach a parse rule * * @param callback $callback The function to be called. * * @return void * * @since 11.1 */ public function attachParseRule($callback) { $this->_rules['parse'][] = $callback; } /** * Function to convert a raw route to an internal URI * * @param JURI &$uri The raw route * * @return boolean * * @since 11.1 */ protected function _parseRawRoute(&$uri) { return false; } /** * Function to convert a sef route to an internal URI * * @param JURI &$uri The sef URI * * @return string Internal URI * * @since 11.1 */ protected function _parseSefRoute(&$uri) { return false; } /** * Function to build a raw route * * @param JURI &$uri The internal URL * * @return string Raw Route * * @since 11.1 */ protected function _buildRawRoute(&$uri) { } /** * Function to build a sef route * * @param JURI &$uri The uri * * @return string The SEF route * * @since 11.1 */ protected function _buildSefRoute(&$uri) { } /** * Process the parsed router variables based on custom defined rules * * @param JURI &$uri The URI to parse * * @return array The array of processed URI variables * * @since 11.1 */ protected function _processParseRules(&$uri) { $vars = array(); foreach ($this->_rules['parse'] as $rule) { $vars += call_user_func_array($rule, array(&$this, &$uri)); } return $vars; } /** * Process the build uri query data based on custom defined rules * * @param JURI &$uri The URI * * @return void * * @since 11.1 */ protected function _processBuildRules(&$uri) { foreach ($this->_rules['build'] as $rule) { call_user_func_array($rule, array(&$this, &$uri)); } } /** * Create a uri based on a full or partial url string * * @param string $url The URI * * @return JURI * * @since 11.1 */ protected function _createURI($url) { // Create full URL if we are only appending variables to it if (substr($url, 0, 1) == '&') { $vars = array(); if (strpos($url, '&') !== false) { $url = str_replace('&', '&', $url); } parse_str($url, $vars); $vars = array_merge($this->getVars(), $vars); foreach ($vars as $key => $var) { if ($var == "") { unset($vars[$key]); } } $url = 'index.php?' . JURI::buildQuery($vars); } // Decompose link into url component parts return new JURI($url); } /** * Encode route segments * * @param array $segments An array of route segments * * @return array Array of encoded route segments * * @since 11.1 */ protected function _encodeSegments($segments) { $total = count($segments); for ($i = 0; $i < $total; $i++) { $segments[$i] = str_replace(':', '-', $segments[$i]); } return $segments; } /** * Decode route segments * * @param array $segments An array of route segments * * @return array Array of decoded route segments * * @since 11.1 */ protected function _decodeSegments($segments) { $total = count($segments); for ($i = 0; $i < $total; $i++) { $segments[$i] = preg_replace('/-/', ':', $segments[$i], 1); } return $segments; } } home/academiac/www/administrator/includes/router.php 0000644 00000001700 15137315147 0016733 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage Application * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('JPATH_BASE') or die; /** * Class to create and parse routes * * @package Joomla.Administrator * @since 1.5 */ class JRouterAdministrator extends JRouter { /** * Function to convert a route to an internal URI */ public function parse(&$uri) { return array(); } /** * Function to convert an internal URI to a route * * @param string $uri The internal URL * * @return string The absolute search engine friendly URL * @since 1.5 */ function build($url) { // Create the URI object $uri = parent::build($url); // Get the path data $route = $uri->getPath(); //Add basepath to the uri $uri->setPath(JURI::base(true).'/'.$route); return $uri; } } home/academiac/www/components/com_contact/router.php 0000644 00000011142 15137337454 0016731 0 ustar 00 <?php /** * @package Joomla.Site * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; jimport('joomla.application.categories'); /** * Build the route for the com_contact component * * @param array An array of URL arguments * * @return array The URL arguments to use to assemble the subsequent URL. */ function ContactBuildRoute(&$query){ $segments = array(); // get a menu item based on Itemid or currently active $app = JFactory::getApplication(); $menu = $app->getMenu(); $params = JComponentHelper::getParams('com_contact'); $advanced = $params->get('sef_advanced_link', 0); if (empty($query['Itemid'])) { $menuItem = $menu->getActive(); } else { $menuItem = $menu->getItem($query['Itemid']); } $mView = (empty($menuItem->query['view'])) ? null : $menuItem->query['view']; $mCatid = (empty($menuItem->query['catid'])) ? null : $menuItem->query['catid']; $mId = (empty($menuItem->query['id'])) ? null : $menuItem->query['id']; if (isset($query['view'])) { $view = $query['view']; if (empty($query['Itemid'])) { $segments[] = $query['view']; } unset($query['view']); }; // are we dealing with a contact that is attached to a menu item? if (isset($view) && ($mView == $view) and (isset($query['id'])) and ($mId == intval($query['id']))) { unset($query['view']); unset($query['catid']); unset($query['id']); return $segments; } if (isset($view) and ($view == 'category' or $view == 'contact')) { if ($mId != intval($query['id']) || $mView != $view) { if($view == 'contact' && isset($query['catid'])) { $catid = $query['catid']; } elseif(isset($query['id'])) { $catid = $query['id']; } $menuCatid = $mId; $categories = JCategories::getInstance('Contact'); $category = $categories->get($catid); if($category) { //TODO Throw error that the category either not exists or is unpublished $path = array_reverse($category->getPath()); $array = array(); foreach($path as $id) { if((int) $id == (int)$menuCatid) { break; } if($advanced) { list($tmp, $id) = explode(':', $id, 2); } $array[] = $id; } $segments = array_merge($segments, array_reverse($array)); } if($view == 'contact') { if($advanced) { list($tmp, $id) = explode(':', $query['id'], 2); } else { $id = $query['id']; } $segments[] = $id; } } unset($query['id']); unset($query['catid']); } if (isset($query['layout'])) { if (!empty($query['Itemid']) && isset($menuItem->query['layout'])) { if ($query['layout'] == $menuItem->query['layout']) { unset($query['layout']); } } else { if ($query['layout'] == 'default') { unset($query['layout']); } } }; return $segments; } /** * Parse the segments of a URL. * * @param array The segments of the URL to parse. * * @return array The URL attributes to be used by the application. */ function ContactParseRoute($segments) { $vars = array(); //Get the active menu item. $app = JFactory::getApplication(); $menu = $app->getMenu(); $item = $menu->getActive(); $params = JComponentHelper::getParams('com_contact'); $advanced = $params->get('sef_advanced_link', 0); // Count route segments $count = count($segments); // Standard routing for newsfeeds. if (!isset($item)) { $vars['view'] = $segments[0]; $vars['id'] = $segments[$count - 1]; return $vars; } // From the categories view, we can only jump to a category. $id = (isset($item->query['id']) && $item->query['id'] > 1) ? $item->query['id'] : 'root'; $contactCategory = JCategories::getInstance('Contact')->get($id); $categories = ($contactCategory) ? $contactCategory->getChildren() : array(); $vars['catid'] = $id; $vars['id'] = $id; $found = 0; foreach($segments as $segment) { $segment = $advanced ? str_replace(':', '-', $segment) : $segment; foreach($categories as $category) { if ($category->slug == $segment || $category->alias == $segment) { $vars['id'] = $category->id; $vars['catid'] = $category->id; $vars['view'] = 'category'; $categories = $category->getChildren(); $found = 1; break; } } if ($found == 0) { if($advanced) { $db = JFactory::getDBO(); $query = 'SELECT id FROM #__contact_details WHERE catid = '.$vars['catid'].' AND alias = '.$db->Quote($segment); $db->setQuery($query); $nid = $db->loadResult(); } else { $nid = $segment; } $vars['id'] = $nid; $vars['view'] = 'contact'; } $found = 0; } return $vars; } home/academiac/www/components/com_content/router.php 0000644 00000017735 15137337457 0016771 0 ustar 00 <?php /** * @package Joomla.Site * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; jimport('joomla.application.categories'); /** * Build the route for the com_content component * * @param array An array of URL arguments * @return array The URL arguments to use to assemble the subsequent URL. * @since 1.5 */ function ContentBuildRoute(&$query) { $segments = array(); // get a menu item based on Itemid or currently active $app = JFactory::getApplication(); $menu = $app->getMenu(); $params = JComponentHelper::getParams('com_content'); $advanced = $params->get('sef_advanced_link', 0); // we need a menu item. Either the one specified in the query, or the current active one if none specified if (empty($query['Itemid'])) { $menuItem = $menu->getActive(); $menuItemGiven = false; } else { $menuItem = $menu->getItem($query['Itemid']); $menuItemGiven = true; } if (isset($query['view'])) { $view = $query['view']; } else { // we need to have a view in the query or it is an invalid URL return $segments; } // are we dealing with an article or category that is attached to a menu item? if (($menuItem instanceof stdClass) && $menuItem->query['view'] == $query['view'] && isset($query['id']) && $menuItem->query['id'] == intval($query['id'])) { unset($query['view']); if (isset($query['catid'])) { unset($query['catid']); } if (isset($query['layout'])) { unset($query['layout']); } unset($query['id']); return $segments; } if ($view == 'category' || $view == 'article') { if (!$menuItemGiven) { $segments[] = $view; } unset($query['view']); if ($view == 'article') { if (isset($query['id']) && isset($query['catid']) && $query['catid']) { $catid = $query['catid']; // Make sure we have the id and the alias if (strpos($query['id'], ':') === false) { $db = JFactory::getDbo(); $aquery = $db->setQuery($db->getQuery(true) ->select('alias') ->from('#__content') ->where('id='.(int)$query['id']) ); $alias = $db->loadResult(); $query['id'] = $query['id'].':'.$alias; } } else { // we should have these two set for this view. If we don't, it is an error return $segments; } } else { if (isset($query['id'])) { $catid = $query['id']; } else { // we should have id set for this view. If we don't, it is an error return $segments; } } if ($menuItemGiven && isset($menuItem->query['id'])) { $mCatid = $menuItem->query['id']; } else { $mCatid = 0; } $categories = JCategories::getInstance('Content'); $category = $categories->get($catid); if (!$category) { // we couldn't find the category we were given. Bail. return $segments; } $path = array_reverse($category->getPath()); $array = array(); foreach($path as $id) { if ((int)$id == (int)$mCatid) { break; } list($tmp, $id) = explode(':', $id, 2); $array[] = $id; } $array = array_reverse($array); if (!$advanced && count($array)) { $array[0] = (int)$catid.':'.$array[0]; } $segments = array_merge($segments, $array); if ($view == 'article') { if ($advanced) { list($tmp, $id) = explode(':', $query['id'], 2); } else { $id = $query['id']; } $segments[] = $id; } unset($query['id']); unset($query['catid']); } if ($view == 'archive') { if (!$menuItemGiven) { $segments[] = $view; unset($query['view']); } if (isset($query['year'])) { if ($menuItemGiven) { $segments[] = $query['year']; unset($query['year']); } } if (isset($query['year']) && isset($query['month'])) { if ($menuItemGiven) { $segments[] = $query['month']; unset($query['month']); } } } // if the layout is specified and it is the same as the layout in the menu item, we // unset it so it doesn't go into the query string. if (isset($query['layout'])) { if ($menuItemGiven && isset($menuItem->query['layout'])) { if ($query['layout'] == $menuItem->query['layout']) { unset($query['layout']); } } else { if ($query['layout'] == 'default') { unset($query['layout']); } } } return $segments; } /** * Parse the segments of a URL. * * @param array The segments of the URL to parse. * * @return array The URL attributes to be used by the application. * @since 1.5 */ function ContentParseRoute($segments) { $vars = array(); //Get the active menu item. $app = JFactory::getApplication(); $menu = $app->getMenu(); $item = $menu->getActive(); $params = JComponentHelper::getParams('com_content'); $advanced = $params->get('sef_advanced_link', 0); $db = JFactory::getDBO(); // Count route segments $count = count($segments); // Standard routing for articles. If we don't pick up an Itemid then we get the view from the segments // the first segment is the view and the last segment is the id of the article or category. if (!isset($item)) { $vars['view'] = $segments[0]; $vars['id'] = $segments[$count - 1]; return $vars; } // if there is only one segment, then it points to either an article or a category // we test it first to see if it is a category. If the id and alias match a category // then we assume it is a category. If they don't we assume it is an article if ($count == 1) { // we check to see if an alias is given. If not, we assume it is an article if (strpos($segments[0], ':') === false) { $vars['view'] = 'article'; $vars['id'] = (int)$segments[0]; return $vars; } list($id, $alias) = explode(':', $segments[0], 2); // first we check if it is a category $category = JCategories::getInstance('Content')->get($id); if ($category && $category->alias == $alias) { $vars['view'] = 'category'; $vars['id'] = $id; return $vars; } else { $query = 'SELECT alias, catid FROM #__content WHERE id = '.(int)$id; $db->setQuery($query); $article = $db->loadObject(); if ($article) { if ($article->alias == $alias) { $vars['view'] = 'article'; $vars['catid'] = (int)$article->catid; $vars['id'] = (int)$id; return $vars; } } } } // if there was more than one segment, then we can determine where the URL points to // because the first segment will have the target category id prepended to it. If the // last segment has a number prepended, it is an article, otherwise, it is a category. if (!$advanced) { $cat_id = (int)$segments[0]; $article_id = (int)$segments[$count - 1]; if ($article_id > 0) { $vars['view'] = 'article'; $vars['catid'] = $cat_id; $vars['id'] = $article_id; } else { $vars['view'] = 'category'; $vars['id'] = $cat_id; } return $vars; } // we get the category id from the menu item and search from there $id = $item->query['id']; $category = JCategories::getInstance('Content')->get($id); if (!$category) { JError::raiseError(404, JText::_('COM_CONTENT_ERROR_PARENT_CATEGORY_NOT_FOUND')); return $vars; } $categories = $category->getChildren(); $vars['catid'] = $id; $vars['id'] = $id; $found = 0; foreach($segments as $segment) { $segment = str_replace(':', '-', $segment); foreach($categories as $category) { if ($category->alias == $segment) { $vars['id'] = $category->id; $vars['catid'] = $category->id; $vars['view'] = 'category'; $categories = $category->getChildren(); $found = 1; break; } } if ($found == 0) { if ($advanced) { $db = JFactory::getDBO(); $query = 'SELECT id FROM #__content WHERE catid = '.$vars['catid'].' AND alias = '.$db->Quote($segment); $db->setQuery($query); $cid = $db->loadResult(); } else { $cid = $segment; } $vars['id'] = $cid; if ($item->query['view'] == 'archive' && $count != 1){ $vars['year'] = $count >= 2 ? $segments[$count-2] : null; $vars['month'] = $segments[$count-1]; $vars['view'] = 'archive'; } else { $vars['view'] = 'article'; } } $found = 0; } return $vars; } home/academiac/www/includes/router.php 0000644 00000030144 15137364535 0014064 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage Application * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('JPATH_BASE') or die; /** * Class to create and parse routes for the site application * * @package Joomla.Site * @subpackage Application * @since 1.5 */ class JRouterSite extends JRouter { /** * Parse the URI * * @param object The URI * * @return array */ public function parse(&$uri) { $vars = array(); // Get the application $app = JApplication::getInstance('site'); if ($app->getCfg('force_ssl') == 2 && strtolower($uri->getScheme()) != 'https') { //forward to https $uri->setScheme('https'); $app->redirect((string)$uri); } // Get the path $path = $uri->getPath(); // Remove the base URI path. $path = substr_replace($path, '', 0, strlen(JURI::base(true))); // Check to see if a request to a specific entry point has been made. if (preg_match("#.*?\.php#u", $path, $matches)) { // Get the current entry point path relative to the site path. $scriptPath = realpath($_SERVER['SCRIPT_FILENAME'] ? $_SERVER['SCRIPT_FILENAME'] : str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED'])); $relativeScriptPath = str_replace('\\', '/', str_replace(JPATH_SITE, '', $scriptPath)); // If a php file has been found in the request path, check to see if it is a valid file. // Also verify that it represents the same file from the server variable for entry script. if (file_exists(JPATH_SITE.$matches[0]) && ($matches[0] == $relativeScriptPath)) { // Remove the entry point segments from the request path for proper routing. $path = str_replace($matches[0], '', $path); } } // Identify format if ($this->_mode == JROUTER_MODE_SEF) { if ($app->getCfg('sef_suffix') && !(substr($path, -9) == 'index.php' || substr($path, -1) == '/')) { if ($suffix = pathinfo($path, PATHINFO_EXTENSION)) { $vars['format'] = $suffix; } } } //Set the route $uri->setPath(trim($path , '/')); $vars += parent::parse($uri); return $vars; } public function build($url) { $uri = parent::build($url); // Get the path data $route = $uri->getPath(); //Add the suffix to the uri if ($this->_mode == JROUTER_MODE_SEF && $route) { $app = JApplication::getInstance('site'); if ($app->getCfg('sef_suffix') && !(substr($route, -9) == 'index.php' || substr($route, -1) == '/')) { if ($format = $uri->getVar('format', 'html')) { $route .= '.'.$format; $uri->delVar('format'); } } if ($app->getCfg('sef_rewrite')) { //Transform the route if ($route == 'index.php') { $route = ''; } else { $route = str_replace('index.php/', '', $route); } } } //Add basepath to the uri $uri->setPath(JURI::base(true).'/'.$route); return $uri; } protected function _parseRawRoute(&$uri) { $vars = array(); $app = JApplication::getInstance('site'); $menu = $app->getMenu(true); //Handle an empty URL (special case) if (!$uri->getVar('Itemid') && !$uri->getVar('option')) { $item = $menu->getDefault(JFactory::getLanguage()->getTag()); if (!is_object($item)) { // No default item set return $vars; } //Set the information in the request $vars = $item->query; //Get the itemid $vars['Itemid'] = $item->id; // Set the active menu item $menu->setActive($vars['Itemid']); return $vars; } //Get the variables from the uri $this->setVars($uri->getQuery(true)); //Get the itemid, if it hasn't been set force it to null $this->setVar('Itemid', JRequest::getInt('Itemid', null)); // Only an Itemid OR if filter language plugin set? Get the full information from the itemid if (count($this->getVars()) == 1 || ( $app->getLanguageFilter() && count( $this->getVars()) == 2 )) { $item = $menu->getItem($this->getVar('Itemid')); if ($item !== NULL && is_array($item->query)) { $vars = $vars + $item->query; } } // Set the active menu item $menu->setActive($this->getVar('Itemid')); return $vars; } protected function _parseSefRoute(&$uri) { $vars = array(); $app = JApplication::getInstance('site'); $menu = $app->getMenu(true); $route = $uri->getPath(); // Remove the suffix if ($this->_mode == JROUTER_MODE_SEF) { if ($app->getCfg('sef_suffix')) { if ($suffix = pathinfo($route, PATHINFO_EXTENSION)) { $route = str_replace('.' . $suffix, '', $route); } } } // Get the variables from the uri $vars = $uri->getQuery(true); // Handle an empty URL (special case) if (empty($route)) { // If route is empty AND option is set in the query, assume it's non-sef url, and parse apropriately if (isset($vars['option']) || isset($vars['Itemid'])) { return $this->_parseRawRoute($uri); } $item = $menu->getDefault(JFactory::getLanguage()->getTag()); // if user not allowed to see default menu item then avoid notices if(is_object($item)) { //Set the information in the request $vars = $item->query; //Get the itemid $vars['Itemid'] = $item->id; // Set the active menu item $menu->setActive($vars['Itemid']); } return $vars; } /* * Parse the application route */ $segments = explode('/', $route); if (count($segments) > 1 && $segments[0] == 'component') { $vars['option'] = 'com_'.$segments[1]; $vars['Itemid'] = null; $route = implode('/', array_slice($segments, 2)); } else { //Need to reverse the array (highest sublevels first) $items = array_reverse($menu->getMenu()); $found = false; $route_lowercase = JString::strtolower($route); $lang_tag = JFactory::getLanguage()->getTag(); foreach ($items as $item) { //sqlsrv change if(isset($item->language)){ $item->language = trim($item->language); } $length = strlen($item->route); //get the length of the route if ($length > 0 && JString::strpos($route_lowercase.'/', $item->route.'/') === 0 && $item->type != 'menulink' && (!$app->getLanguageFilter() || $item->language == '*' || $item->language == $lang_tag)) { // We have exact item for this language if ($item->language == $lang_tag) { $found = $item; break; } // Or let's remember an item for all languages elseif (!$found) { $found = $item; } } } if (!$found) { $found = $menu->getDefault($lang_tag); } else { $route = substr($route, strlen($found->route)); if ($route) { $route = substr($route, 1); } } $vars['Itemid'] = $found->id; $vars['option'] = $found->component; } // Set the active menu item if (isset($vars['Itemid'])) { $menu->setActive( $vars['Itemid']); } // Set the variables $this->setVars($vars); /* * Parse the component route */ if (!empty($route) && isset($this->_vars['option'])) { $segments = explode('/', $route); if (empty($segments[0])) { array_shift($segments); } // Handle component route $component = preg_replace('/[^A-Z0-9_\.-]/i', '', $this->_vars['option']); // Use the component routing handler if it exists $path = JPATH_SITE . '/components/' . $component . '/router.php'; if (file_exists($path) && count($segments)) { if ($component != "com_search") { // Cheap fix on searches //decode the route segments $segments = $this->_decodeSegments($segments); } else { // fix up search for URL $total = count($segments); for ($i=0; $i<$total; $i++) { // urldecode twice because it is encoded twice $segments[$i] = urldecode(urldecode(stripcslashes($segments[$i]))); } } require_once $path; $function = substr($component, 4).'ParseRoute'; $function = str_replace(array("-", "."), "", $function); $vars = $function($segments); $this->setVars($vars); } } else { //Set active menu item if ($item = $menu->getActive()) { $vars = $item->query; } } return $vars; } protected function _buildRawRoute(&$uri) { } protected function _buildSefRoute(&$uri) { // Get the route $route = $uri->getPath(); // Get the query data $query = $uri->getQuery(true); if (!isset($query['option'])) { return; } $app = JApplication::getInstance('site'); $menu = $app->getMenu(); /* * Build the component route */ $component = preg_replace('/[^A-Z0-9_\.-]/i', '', $query['option']); $tmp = ''; // Use the component routing handler if it exists $path = JPATH_SITE . '/components/' . $component . '/router.php'; // Use the custom routing handler if it exists if (file_exists($path) && !empty($query)) { require_once $path; $function = substr($component, 4).'BuildRoute'; $function = str_replace(array("-", "."), "", $function); $parts = $function($query); // encode the route segments if ($component != 'com_search') { // Cheep fix on searches $parts = $this->_encodeSegments($parts); } else { // fix up search for URL $total = count($parts); for ($i = 0; $i < $total; $i++) { // urlencode twice because it is decoded once after redirect $parts[$i] = urlencode(urlencode(stripcslashes($parts[$i]))); } } $result = implode('/', $parts); $tmp = ($result != "") ? $result : ''; } /* * Build the application route */ $built = false; if (isset($query['Itemid']) && !empty($query['Itemid'])) { $item = $menu->getItem($query['Itemid']); if (is_object($item) && $query['option'] == $item->component) { if (!$item->home || $item->language!='*') { $tmp = !empty($tmp) ? $item->route.'/'.$tmp : $item->route; } $built = true; } } if (!$built) { $tmp = 'component/'.substr($query['option'], 4).'/'.$tmp; } if ($tmp) { $route .= '/'.$tmp; } elseif ($route=='index.php') { $route = ''; } // Unset unneeded query information if (isset($item) && $query['option'] == $item->component) { unset($query['Itemid']); } unset($query['option']); //Set query again in the URI $uri->setQuery($query); $uri->setPath($route); } protected function _processParseRules(&$uri) { // Process the attached parse rules $vars = parent::_processParseRules($uri); // Process the pagination support if ($this->_mode == JROUTER_MODE_SEF) { $app = JApplication::getInstance('site'); if ($start = $uri->getVar('start')) { $uri->delVar('start'); $vars['limitstart'] = $start; } } return $vars; } protected function _processBuildRules(&$uri) { // Make sure any menu vars are used if no others are specified if (($this->_mode != JROUTER_MODE_SEF) && $uri->getVar('Itemid') && count($uri->getQuery(true)) == 2) { $app = JApplication::getInstance('site'); $menu = $app->getMenu(); // Get the active menu item $itemid = $uri->getVar('Itemid'); $item = $menu->getItem($itemid); if ($item) { $uri->setQuery($item->query); } $uri->setVar('Itemid', $itemid); } // Process the attached build rules parent::_processBuildRules($uri); // Get the path data $route = $uri->getPath(); if ($this->_mode == JROUTER_MODE_SEF && $route) { $app = JApplication::getInstance('site'); if ($limitstart = $uri->getVar('limitstart')) { $uri->setVar('start', (int) $limitstart); $uri->delVar('limitstart'); } } $uri->setPath($route); } protected function _createURI($url) { //Create the URI $uri = parent::_createURI($url); // Set URI defaults $app = JApplication::getInstance('site'); $menu = $app->getMenu(); // Get the itemid form the URI $itemid = $uri->getVar('Itemid'); if (is_null($itemid)) { if ($option = $uri->getVar('option')) { $item = $menu->getItem($this->getVar('Itemid')); if (isset($item) && $item->component == $option) { $uri->setVar('Itemid', $item->id); } } else { if ($option = $this->getVar('option')) { $uri->setVar('option', $option); } if ($itemid = $this->getVar('Itemid')) { $uri->setVar('Itemid', $itemid); } } } else { if (!$uri->getVar('option')) { if ($item = $menu->getItem($itemid)) { $uri->setVar('option', $item->component); } } } return $uri; } } home/academiac/www/components/com_wrapper/router.php 0000644 00000001112 15137401505 0016737 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_wrapper * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; /** * @param array * @return array */ function WrapperBuildRoute(&$query) { $segments = array(); if (isset($query['view'])) { unset($query['view']); } return $segments; } /** * @param array * @return array */ function WrapperParseRoute($segments) { $vars = array(); $vars['view'] = 'wrapper'; return $vars; } home/academiac/www/components/com_weblinks/router.php 0000644 00000011563 15137412662 0017116 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_weblinks * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ /* Weblinks Component Route Helper * * @package Joomla.Site * @subpackage com_weblinks * @since 1.6 */ defined('_JEXEC') or die; jimport('joomla.application.categories'); /** * Build the route for the com_weblinks component * * @param array An array of URL arguments * * @return array The URL arguments to use to assemble the subsequent URL. */ function WeblinksBuildRoute(&$query) { $segments = array(); // get a menu item based on Itemid or currently active $app = JFactory::getApplication(); $menu = $app->getMenu(); $params = JComponentHelper::getParams('com_weblinks'); $advanced = $params->get('sef_advanced_link', 0); // we need a menu item. Either the one specified in the query, or the current active one if none specified if (empty($query['Itemid'])) { $menuItem = $menu->getActive(); } else { $menuItem = $menu->getItem($query['Itemid']); } $mView = (empty($menuItem->query['view'])) ? null : $menuItem->query['view']; $mCatid = (empty($menuItem->query['catid'])) ? null : $menuItem->query['catid']; $mId = (empty($menuItem->query['id'])) ? null : $menuItem->query['id']; if (isset($query['view'])) { $view = $query['view']; if (empty($query['Itemid'])) { $segments[] = $query['view']; } // We need to keep the view for forms since they never have their own menu item if ($view != 'form') { unset($query['view']); } } // are we dealing with an weblink that is attached to a menu item? if (isset($query['view']) && ($mView == $query['view']) and (isset($query['id'])) and ($mId == intval($query['id']))) { unset($query['view']); unset($query['catid']); unset($query['id']); return $segments; } if (isset($view) and ($view == 'category' or $view == 'weblink' )) { if ($mId != intval($query['id']) || $mView != $view) { if ($view == 'weblink' && isset($query['catid'])) { $catid = $query['catid']; } elseif (isset($query['id'])) { $catid = $query['id']; } $menuCatid = $mId; $categories = JCategories::getInstance('Weblinks'); $category = $categories->get($catid); if ($category) { //TODO Throw error that the category either not exists or is unpublished $path = $category->getPath(); $path = array_reverse($path); $array = array(); foreach($path as $id) { if ((int) $id == (int)$menuCatid) { break; } if ($advanced) { list($tmp, $id) = explode(':', $id, 2); } $array[] = $id; } $segments = array_merge($segments, array_reverse($array)); } if ($view == 'weblink') { if ($advanced) { list($tmp, $id) = explode(':', $query['id'], 2); } else { $id = $query['id']; } $segments[] = $id; } } unset($query['id']); unset($query['catid']); } if (isset($query['layout'])) { if (!empty($query['Itemid']) && isset($menuItem->query['layout'])) { if ($query['layout'] == $menuItem->query['layout']) { unset($query['layout']); } } else { if ($query['layout'] == 'default') { unset($query['layout']); } } }; return $segments; } /** * Parse the segments of a URL. * * @param array The segments of the URL to parse. * * @return array The URL attributes to be used by the application. */ function WeblinksParseRoute($segments) { $vars = array(); //Get the active menu item. $app = JFactory::getApplication(); $menu = $app->getMenu(); $item = $menu->getActive(); $params = JComponentHelper::getParams('com_weblinks'); $advanced = $params->get('sef_advanced_link', 0); // Count route segments $count = count($segments); // Standard routing for weblinks. if (!isset($item)) { $vars['view'] = $segments[0]; $vars['id'] = $segments[$count - 1]; return $vars; } // From the categories view, we can only jump to a category. $id = (isset($item->query['id']) && $item->query['id'] > 1) ? $item->query['id'] : 'root'; $category = JCategories::getInstance('Weblinks')->get($id); $categories = $category->getChildren(); $found = 0; foreach($segments as $segment) { foreach($categories as $category) { if (($category->slug == $segment) || ($advanced && $category->alias == str_replace(':', '-', $segment))) { $vars['id'] = $category->id; $vars['view'] = 'category'; $categories = $category->getChildren(); $found = 1; break; } } if ($found == 0) { if ($advanced) { $db = JFactory::getDBO(); $query = 'SELECT id FROM #__weblinks WHERE catid = '.$vars['id'].' AND alias = '.$db->Quote(str_replace(':', '-', $segment)); $db->setQuery($query); $id = $db->loadResult(); } else { $id = $segment; } $vars['id'] = $id; $vars['view'] = 'weblink'; break; } $found = 0; } return $vars; } home/academiac/www/components/com_newsfeeds/router.php 0000644 00000011163 15137443337 0017262 0 ustar 00 <?php /** * @package Joomla.Site * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ /* Newsfeeds Component Route Helper * * @package Joomla.Site * @subpackage com_newsfeeds * @since 1.6 */ defined('_JEXEC') or die; jimport('joomla.application.categories'); /** * Build the route for the com_newsfeeds component * * @param array An array of URL arguments * * @return array The URL arguments to use to assemble the subsequent URL. */ function NewsfeedsBuildRoute(&$query) { $segments = array(); // get a menu item based on Itemid or currently active $app = JFactory::getApplication(); $menu = $app->getMenu(); $params = JComponentHelper::getParams('com_newsfeeds'); $advanced = $params->get('sef_advanced_link', 0); if (empty($query['Itemid'])) { $menuItem = $menu->getActive(); } else { $menuItem = $menu->getItem($query['Itemid']); } $mView = (empty($menuItem->query['view'])) ? null : $menuItem->query['view']; $mCatid = (empty($menuItem->query['catid'])) ? null : $menuItem->query['catid']; $mId = (empty($menuItem->query['id'])) ? null : $menuItem->query['id']; if (isset($query['view'])) { $view = $query['view']; if (empty($query['Itemid'])) { $segments[] = $query['view']; } unset($query['view']); }; // are we dealing with an newsfeed that is attached to a menu item? if (isset($query['view']) && ($mView == $query['view']) and (isset($query['id'])) and ($mId == intval($query['id']))) { unset($query['view']); unset($query['catid']); unset($query['id']); return $segments; } if (isset($view) and ($view == 'category' or $view == 'newsfeed')) { if ($mId != intval($query['id']) || $mView != $view) { if($view == 'newsfeed' && isset($query['catid'])) { $catid = $query['catid']; } elseif(isset($query['id'])) { $catid = $query['id']; } $menuCatid = $mId; $categories = JCategories::getInstance('Newsfeeds'); $category = $categories->get($catid); if ($category) { $path = $category->getPath(); $path = array_reverse($path); $array = array(); foreach($path as $id) { if((int) $id == (int)$menuCatid) { break; } if($advanced) { list($tmp, $id) = explode(':', $id, 2); } $array[] = $id; } $segments = array_merge($segments, array_reverse($array)); } if($view == 'newsfeed') { if($advanced) { list($tmp, $id) = explode(':', $query['id'], 2); } else { $id = $query['id']; } $segments[] = $id; } } unset($query['id']); unset($query['catid']); } if (isset($query['layout'])) { if (!empty($query['Itemid']) && isset($menuItem->query['layout'])) { if ($query['layout'] == $menuItem->query['layout']) { unset($query['layout']); } } else { if ($query['layout'] == 'default') { unset($query['layout']); } } }; return $segments; } /** * Parse the segments of a URL. * * @param array The segments of the URL to parse. * * @return array The URL attributes to be used by the application. */ function NewsfeedsParseRoute($segments) { $vars = array(); //Get the active menu item. $app = JFactory::getApplication(); $menu = $app->getMenu(); $item = $menu->getActive(); $params = JComponentHelper::getParams('com_newsfeeds'); $advanced = $params->get('sef_advanced_link', 0); // Count route segments $count = count($segments); // Standard routing for newsfeeds. if (!isset($item)) { $vars['view'] = $segments[0]; $vars['id'] = $segments[$count - 1]; return $vars; } // From the categories view, we can only jump to a category. $id = (isset($item->query['id']) && $item->query['id'] > 1) ? $item->query['id'] : 'root'; $categories = JCategories::getInstance('Newsfeeds')->get($id)->getChildren(); $vars['catid'] = $id; $vars['id'] = $id; $found = 0; foreach($segments as $segment) { $segment = $advanced ? str_replace(':', '-', $segment) : $segment; foreach($categories as $category) { if ($category->slug == $segment || $category->alias == $segment) { $vars['id'] = $category->id; $vars['catid'] = $category->id; $vars['view'] = 'category'; $categories = $category->getChildren(); $found = 1; break; } } if ($found == 0) { if($advanced) { $db = JFactory::getDBO(); $query = 'SELECT id FROM #__newsfeeds WHERE catid = '.$vars['catid'].' AND alias = '.$db->Quote($segment); $db->setQuery($query); $nid = $db->loadResult(); } else { $nid = $segment; } $vars['id'] = $nid; $vars['view'] = 'newsfeed'; } $found = 0; } return $vars; } home/academiac/www/components/com_banners/router.php 0000644 00000002222 15137771760 0016727 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_banners * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; /** * @param array A named array * @return array */ function BannersBuildRoute(&$query) { $segments = array(); if (isset($query['task'])) { $segments[] = $query['task']; unset($query['task']); } if (isset($query['id'])) { $segments[] = $query['id']; unset($query['id']); } return $segments; } /** * @param array A named array * @param array * * Formats: * * index.php?/banners/task/id/Itemid * * index.php?/banners/id/Itemid */ function BannersParseRoute($segments) { $vars = array(); // view is always the first element of the array $count = count($segments); if ($count) { $count--; $segment = array_shift($segments); if (is_numeric($segment)) { $vars['id'] = $segment; } else { $vars['task'] = $segment; } } if ($count) { $count--; $segment = array_shift($segments) ; if (is_numeric($segment)) { $vars['id'] = $segment; } } return $vars; }
©
2018.