public static function filterUrl($url, $use_sef = true) { if (empty($url)) { return null; } // Parse the query-part of the URL $q = explode('?', $url); array_shift($q); // Merge the Magento query with the Joomla! query $qs = implode('&', $q); $qs = str_replace('&', '&', $qs); parse_str($qs, $query); // Get rid of the annoying SID $sids = array('SID', 'sid', '__SID', '___SID'); foreach ($sids as $sid) { if (isset($query[$sid])) { unset($query[$sid]); } } // Construct the URL again $url = 'index.php?'; $url_segments = array(); foreach ($query as $name => $value) { $url_segments[] = $name . '=' . $value; } $url = 'index.php?' . implode('&', $url_segments); if ($use_sef == true) { $url = MageBridgeUrlHelper::getSefUrl($url); } $prefix = JURI::getInstance()->toString(array('scheme', 'host', 'port')); $path = str_replace($prefix, '', JURI::base()); $pos = strpos($url, $path); if (!empty($path) && $pos !== false) { $url = substr($url, $pos + strlen($path)); } return $url; }
/** * Method to redirect non-SEF URLs if enabled * * @access private * * @param null * * @return null */ private function redirectNonSef() { // Initialize variables $uri = JURI::getInstance(); $post = $this->input->post->getArray(); $enabled = $this->getParam('enable_nonsef_redirect', 1); // Redirect non-SEF URLs to their SEF-equivalent if ($enabled == 1 && empty($post) && JFactory::getConfig()->get('sef') == 1 && $this->input->getCmd('option') == 'com_magebridge') { $request = str_replace($uri->base(), '', $uri->toString()); // Detect the MageBridge component if (preg_match('/^index.php\\?option=com_magebridge/', $request)) { $view = $this->app->input->getCmd('view'); $controller = $this->app->input->getCmd('controller'); $task = $this->app->input->getCmd('task'); if ($request != JRoute::_($request) && $view != 'ajax' && $view != 'jsonrpc' && $view != 'block' && $controller != 'jsonrpc' && $task != 'login') { $request = MageBridgeUrlHelper::getSefUrl($request); $this->app->redirect($request); $this->app->close(); } } else { if ($this->loadConfig('enforce_rootmenu') == 1 && !empty($request)) { $url = MageBridgeUrlHelper::route(MageBridgeUrlHelper::getRequest()); if (!preg_match('/^\\//', $request)) { $request = '/' . $request; } if ($request != $url && $this->app->input->getCmd('view') != 'ajax' && !preg_match('/\\/?/', $url)) { $this->app->redirect($url); $this->app->close(); } } } } }