/** * Method for logging out with Magento (Single Sign On) * * @param string $username * @return bool|exit */ public static function doSSOLogout($username = null) { // Abort if the input is not valid if (empty($username)) { return false; } // Get system variables $application = JFactory::getApplication(); $session = JFactory::getSession(); // Determine the application $application_name = $application->isAdmin() ? 'admin' : 'frontend'; // Get the security token $token = method_exists('JSession', 'getFormToken') ? JSession::getFormToken() : JUtility::getToken(); // Set the redirection URL if ($application_name == 'admin') { $redirect = JURI::current(); } else { $redirect = MageBridgeUrlHelper::current(); } // Construct the URL $arguments = array('sso=logout', 'app=' . $application_name, 'redirect=' . base64_encode($redirect), 'userhash=' . MageBridgeEncryptionHelper::encrypt($username), 'token=' . $token); $url = MageBridgeModelBridge::getInstance()->getMagentoBridgeUrl() . '?' . implode('&', $arguments); // Redirect the browser to Magento MageBridgeModelDebug::getInstance()->notice("SSO: Logout of '{$username}' from " . $application_name); $application->redirect($url); return true; }
public static function filterContent($content) { // Allow to disable this filtering if (MagebridgeModelConfig::load('filter_content') == 0) { return $content; } // Get common variables $bridge = MageBridgeModelBridge::getInstance(); // Convert all remaining Magento links to Joomla! links $content = str_replace($bridge->getMagentoUrl() . 'index.php/', $bridge->getJoomlaBridgeUrl(), $content); $content = str_replace($bridge->getMagentoUrl() . 'magebridge.php/', $bridge->getJoomlaBridgeUrl(), $content); // Implement a very dirty hack because PayPal converts URLs "&" to "and" $current = MageBridgeUrlHelper::current(); if (strstr($current, 'paypal') && strstr($current, 'redirect')) { // Try to find the distorted URLs $matches = array(); if (preg_match_all('/([^\\"\']+)com_magebridgeand([^\\"\']+)/', $content, $matches)) { foreach ($matches[0] as $match) { // Replace the wrong "and" words with "&" again $url = str_replace('com_magebridgeand', 'com_magebridge&', $match); $url = str_replace('rootand', 'root&', $url); // Replace the wrong URL with its correction $content = str_replace($match, $url, $content); } } } // Replace all uenc-URLs from Magento with URLs parsed through JRoute $matches = array(); $replaced = array(); if (preg_match_all('/\\/uenc\\/([a-zA-Z0-9\\-\\_\\,]+)/', $content, $matches)) { foreach ($matches[1] as $match) { // Decode the match $original_url = MageBridgeEncryptionHelper::base64_decode($match); $url = $original_url; $url = MageBridgeUrlHelper::stripUrl($url); // Convert the non-SEF URL to a SEF URL if (preg_match('/^index.php\\?option=com_magebridge/', $url)) { // Parse the URL but do NOT turn it into SEF because of Mage_Core_Controller_Varien_Action::_isUrlInternal() $url = MageBridgeHelper::filterUrl(str_replace('/', urldecode('/'), $url), false); $url = $bridge->getJoomlaBridgeSefUrl($url); } else { if (!preg_match('/^(http|https)/', $url)) { $url = $bridge->getJoomlaBridgeSefUrl($url); } $url = preg_replace('/\\?SID=([a-zA-Z0-9\\-\\_]{12,42})/', '', $url); } // Extra check on HTTPS if (JURI::getInstance()->isSSL() == true) { $url = str_replace('http://', 'https://', $url); } else { $url = str_replace('https://', 'http://', $url); } // Replace the URL in the content if ($original_url != $url && $original_url . '/' != $url && !in_array($match, $replaced)) { MageBridgeModelDebug::getInstance()->notice('Translating uenc-URL from ' . $original_url . ' to ' . $url); $base64_url = MageBridgeEncryptionHelper::base64_encode($url); $content = str_replace($match, $base64_url, $content); $replaced[] = $match; } } } // Match all URLs and filter them $matches = array(); if (preg_match_all('/index.php\\?option=com_magebridge([^\'\\"\\<]+)([\'\\"\\<]{1})/', $content, $matches)) { for ($i = 0; $i < count($matches[0]); $i++) { $oldurl = 'index.php?option=com_magebridge' . $matches[1][$i]; $end = $matches[2][$i]; $newurl = MageBridgeHelper::filterUrl($oldurl); if (!empty($newurl)) { $content = str_replace($oldurl . $end, $newurl . $end, $content); } } } // Clean-up left-overs $content = str_replace('?___SID=U', '', $content); $content = str_replace('?___SID=S', '', $content); $content = preg_replace('/\\?___store=([a-zA-Z0-9]+)/', '', $content); $content = preg_replace('/\\?SID=([a-zA-Z0-9\\-\\_]{12,42})/', '', $content); // Remove double-slashes //$basedir = preg_replace('/^([\/]?)(.*)([\/]?)$/', '\2', JURI::base(true)); //$content = str_replace(JURI::base().$basedir, JURI::base(), $content); $content = str_replace(JURI::base() . '/', JURI::base(), $content); // Adjust wrong media-URLs if (JURI::getInstance()->isSSL() == true) { $non_https = preg_replace('/^https:/', 'http:', $bridge->getMagentoUrl()); $https = preg_replace('/^http:/', 'https:', $bridge->getMagentoUrl()); $content = str_replace($non_https, $https, $content); } // Adjust incorrect URLs with parameters starting with & if (preg_match_all('/(\'|\\")(http|https):\\/\\/([^\\&\\?\'\\"]+)\\&/', $content, $matches)) { foreach ($matches[0] as $index => $match) { $content = str_replace($matches[3][$index] . '&', $matches[3][$index] . '?', $content); } } return $content; }
public function setBreadcrumbs() { static $set = false; if ($set == true) { return true; } else { $set = true; } if (JRequest::getCmd('view') != 'root') { return true; } $application = JFactory::getApplication(); $pathway = $application->getPathway(); $data = $this->getResponseData(); if (!is_array($data)) { $data = array(); } if (MageBridgeTemplateHelper::isCartPage()) { $pathway->addItem(JText::_('COM_MAGEBRIDGE_SHOPPING_CART'), MageBridgeUrlHelper::route('checkout/cart')); } else { if (MageBridgeTemplateHelper::isCheckoutPage()) { $pathway->addItem(JText::_('COM_MAGEBRIDGE_SHOPPING_CART'), MageBridgeUrlHelper::route('checkout/cart')); $pathway->addItem(JText::_('COM_MAGEBRIDGE_CHECKOUT'), MageBridgeUrlHelper::route('checkout')); } } @array_shift($data); if (empty($data)) { return true; } $pathway_items = array(); foreach ($pathway->getPathway() as $pathway_item) { $pathway_item->link = preg_replace('/\\/$/', '', JURI::root()) . JRoute::_($pathway_item->link); $pathway_items[] = $pathway_item; } @array_pop($pathway_items); foreach ($data as $item) { // Do not add the current link if (MageBridgeUrlHelper::current() == $item['link']) { continue; } // Loop through the current pathway-items to prevent double links if (!empty($pathway_items)) { $match = false; foreach ($pathway_items as $pathway_item) { if ($pathway_item->link == $item['link']) { $match = true; } } if ($match == true) { continue; } } $pathway_item = (object) null; $pathway_item->name = JText::_($item['label']); $pathway_item->link = $item['link']; $pathway_item->magento = 1; $pathway_items[] = $pathway_item; } $pathway->setPathway($pathway_items); return true; }