/** * Helper-method to get the Root Menu-Item * * @param null * * @return object */ public static function getRootItem() { // Return false, if Root Menu-Item usage is disabled if (MagebridgeModelConfig::load('use_rootmenu') == false) { return false; } // Load the Root Menu-Items found in the Joomla! database static $root_items = null; if (empty($root_items)) { $items = MageBridgeUrlHelper::getMenuItems(); if (!empty($items)) { foreach ($items as $item) { if (isset($item->query['view']) && $item->query['view'] == 'root') { $root_items[] = $item; } } } } $current_item = MageBridgeUrlHelper::getCurrentItem(); if (!empty($root_items)) { // Loop through all Root Menu-Items found, and return the one matching the current ID foreach ($root_items as $root_item) { if (!empty($current_item) && $root_item->id == $current_item->id) { return $root_item; } else { if ($root_item->id == JFactory::getApplication()->input->getInt('Itemid')) { return $root_item; } else { if (!empty($current_item) && is_array($current_item->tree) && in_array($root_item->id, $current_item->tree)) { return $root_item; } } } } // Return the first Root Menu-Item found return $root_items[0]; } return false; }
/** * Method to set a redirect for later redirection * * @param string $redirect * @param int $max_redirects * * @return bool */ public function setRedirect($redirect = null, $max_redirects = 1) { // Do not redirect if the maximum redirect-count is reached if ($this->isMaxRedirect($redirect, $max_redirects) == true) { $this->debug->warning('Maximum redirects of ' . $max_redirects . ' reached'); return false; } // Strip the base-path from the URL $menuitem = MageBridgeUrlHelper::getRootItem(); if (empty($menuitem)) { $menuitem = MageBridgeUrlHelper::getCurrentItem(); } if (!empty($menuitem)) { $root_path = str_replace('/', '\\/', $menuitem->route); $redirect = preg_replace('/^\\//', '', $redirect); $redirect = preg_replace('/^' . $root_path . '/', '', $redirect); } // When the URL doesnt start with HTTP or HTTPS, assume it is still the original Magento request if (!preg_match('/^(http|https):\\/\\//', $redirect)) { $redirect = JURI::base() . 'index.php?option=com_magebridge&view=root&request=' . $redirect; } // Replace the System URL for the site if ($this->app->isSite() && preg_match('/index.php\\?(.*)$/', $redirect, $match)) { $redirect = str_replace($match[0], preg_replace('/^\\//', '', MageBridgeHelper::filterUrl($match[0])), $redirect); } $this->debug->warning('Redirect set to ' . $redirect); $this->redirectUrl = $redirect; return true; }