/** * Send non-bridge output response * * @param string $response * @param string $decodedResponse */ protected function sendNonBridgeOutputResponse($response, $decodedResponse) { // Detect Content-Type $contentType = null; if (preg_match('/Content-Type: (.*)/i', $this->head['headers'], $match)) { $contentType = strtolower(trim($match[1])); $this->head['info']['content_type'] = $contentType; } // Spoof the current HTTP-headers $this->spoofHeaders($response); // Detect JSON and replace any URL-redirects if (is_array($decodedResponse) && isset($decodedResponse['redirect'])) { $url = $decodedResponse['redirect']; if (preg_match('/^index\\.php\\?option\\=com/', $url)) { $newUrl = MageBridgeHelper::filterUrl($url); if (!empty($newUrl)) { $decodedResponse['redirect'] = $newUrl; } $this->data = $this->encode($decodedResponse); } } // Detect HTML and parse it anyway if (preg_match('/<\\/html>$/', $response)) { $response = MageBridgeHelper::filterContent($response); } // Output the raw content $skipContentTypes = array('application/pdf'); if (!in_array($contentType, $skipContentTypes)) { // Detect HTML and parse it anyway if (preg_match('/<\\/html>$/', $response)) { $response = MageBridgeHelper::filterContent($response); } header('Content-Length: ' . YireoHelper::strlen($response)); } // Nothing is compressed with this bridge header('Content-Encoding: none'); if (!empty($this->head['info']['content_type'])) { header('Content-Type: ' . $this->head['info']['content_type']); } elseif (preg_match('/^\\{\\"/', $response)) { header('Content-Type: application/javascript'); } print $response; $this->debug->warning("Non-bridge output from Magento"); //$this->debug->trace( "Output", $response ); $this->app->close(); }
public function build($data) { if ($this->_init != MAGEBRIDGE_PROXY_ERROR) { $application = JFactory::getApplication(); $bridge = MageBridgeModelBridge::getInstance(); // If the request-data is empty, there's no point in making a call if (empty($data)) { return null; } // Loop through the registry and encode it for transferral if (!empty($data)) { foreach ($data as $index => $segment) { if (empty($segment['data'])) { $data[$index] = $this->encode($segment); } } } // Fetch the data by using POST $raw = $this->getRemote($bridge->getMagentoBridgeUrl(), $data, MagebridgeModelConfig::load('method'), true); // Decode the reply $decoded = $this->decode($raw); // Increase the counter to make sure endless redirects don't happen $this->_count++; //MageBridgeModelDebug::getInstance()->trace( 'Proxy raw response', $raw ); //MageBridgeModelDebug::getInstance()->trace( 'Proxy decoded response', $decoded ); // Determine whether this is non-bridge output $nonbridge = false; if ($this->isValidResponse($decoded) == false) { MageBridgeModelDebug::getInstance()->notice('Empty decoded response suggests non-bridge output'); $nonbridge = true; } // Check whether the Content-Type is indicating non-bridge output if (!empty($this->_head['headers']) && preg_match('/Content-Type: (application|text)\\/(xml|javascript|octetstream)/', $this->_head['headers'])) { MageBridgeModelDebug::getInstance()->trace('Detecting non-bridge output in HTTP headers', $this->_head['headers']); $nonbridge = true; } // Check whether the current URL is listed for direct output $direct_output_urls = MageBridgeHelper::csvToArray(MagebridgeModelConfig::load('direct_output')); if (!empty($direct_output_urls)) { foreach ($direct_output_urls as $direct_output_url) { $current_url = MageBridgeUrlHelper::getRequest(); if (!empty($direct_output_url) && strstr($current_url, $direct_output_url)) { MageBridgeModelDebug::getInstance()->trace('Detecting non-bridge output through MageBridge configuration', $direct_output_url); print $raw; return $application->close(); } } } // Handle non-bridge output if ($nonbridge == true) { // Redirect if needed $this->redirect(); if (empty($this->_head['http_code'])) { $this->_head['http_code'] = 200; } if ($this->_head['http_code'] == 200 && !empty($raw)) { // Spoof the current HTTP-headers $this->spoofHeaders($raw); // Detect JSON and replace any URL-redirects if (is_array($decoded) && isset($decoded['redirect'])) { $url = $decoded['redirect']; if (preg_match('/^index\\.php\\?option\\=com/', $url)) { $newurl = MageBridgeHelper::filterUrl($url); if (!empty($newurl)) { $decoded['redirect'] = $newurl; } $data = $this->encode($decoded); } } // Detect HTML and parse it anyway if (preg_match('/<\\/html>$/', $raw)) { $raw = MageBridgeHelper::filterContent($raw); } // Output the raw content print $raw; MageBridgeModelDebug::getInstance()->warning("Non-bridge output from Magento"); //MageBridgeModelDebug::getInstance()->trace( "Output", $raw ); $application->close(); } else { return null; } } else { $data = $decoded; } // Detect events and run them if (!empty($data['events']['data'])) { $bridge->setEvents($data['events']['data']); } // Redirect if needed $this->redirect(); $this->_data = $data; $this->_init = MAGEBRIDGE_PROXY_SUCCESS; } return $this->_data; }
public function filterHtml($html) { // Fix everything regarding URLs $html = MageBridgeHelper::filterContent($html); // Replace URLs where neccessary $replacement_urls = MageBridgeUrlHelper::getReplacementUrls(); if (!empty($replacement_urls)) { foreach ($replacement_urls as $replacement_url) { $source = $replacement_url->source; $destination = $replacement_url->destination; // Prepare the source URL if ($replacement_url->source_type == 0) { $source = MageBridgeUrlHelper::route($source); } else { $source = str_replace('/', '\\/', $source); } // Prepare the destination URL if (preg_match('/^index\\.php\\?option=/', $destination)) { $destination = JRoute::_($destination); } // Replace the actual URLs if ($replacement_url->source_type == 0) { $html = str_replace($source . '\'', $destination . '\'', $html); $html = str_replace($source . '"', $destination . '"', $html); } else { $html = preg_replace('/href=\\"([^\\"]+)' . $source . '([^\\"]+)/', 'href="' . $destination, $html); } } } return $html; }
/** * Send non-bridge output response * * @param string $response * @param string $decodedResponse */ protected function sendNonBridgeOutputResponse($response, $decodedResponse) { // Spoof the current HTTP-headers $this->spoofHeaders($response); // Detect JSON and replace any URL-redirects if (is_array($decodedResponse) && isset($decodedResponse['redirect'])) { $url = $decodedResponse['redirect']; if (preg_match('/^index\\.php\\?option\\=com/', $url)) { $newUrl = MageBridgeHelper::filterUrl($url); if (!empty($newUrl)) { $decodedResponse['redirect'] = $newUrl; } $this->data = $this->encode($decodedResponse); } } // Detect HTML and parse it anyway if (preg_match('/<\\/html>$/', $response)) { $response = MageBridgeHelper::filterContent($response); } // Output the raw content header('Content-Encoding: none'); header('Content-Length: ' . YireoHelper::strlen($response)); if (preg_match('/^\\{\\"/', $response)) { header('Content-Type: application/javascript'); } print $response; $this->debug->warning("Non-bridge output from Magento"); //$this->debug->trace( "Output", $response ); $this->app->close(); }