/** * 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; }
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; }
/** * Method to load feeds * * @param array $headers * @return null */ public function loadRss($headers) { // Dot not load if this is not the right document-class $document = JFactory::getDocument(); if ($document->getType() != 'html') { return false; } // Loop through the items if (!empty($headers['items'])) { foreach ($headers['items'] as $item) { // Fetch RSS-items if ($item['type'] == 'rss') { $url = $item['name']; $url = preg_replace('/(.*)index.php?option=com_magebridge/', '', $url); $url = MageBridgeHelper::filterUrl($url); $document->addHeadLink($url, 'alternate', 'rel', array('type' => 'application/rss+xml', 'title' => 'RSS 2.0')); } } } }