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; }