Пример #1
0
 /**
  * Try to match one of the direct output URLs
  *
  * @param string $response
  */
 protected function matchDirectOutputUrls($response)
 {
     $direct_output_urls = MageBridgeHelper::csvToArray(MagebridgeModelConfig::load('direct_output'));
     $direct_output_urls[] = 'checkout/onepage/getAdditional';
     if (!empty($direct_output_urls)) {
         $current_url = MageBridgeUrlHelper::getRequest();
         foreach ($direct_output_urls as $direct_output_url) {
             $direct_output_url = trim($direct_output_url);
             if (!empty($direct_output_url) && strstr($current_url, $direct_output_url)) {
                 $this->debug->trace('Detecting non-bridge output through MageBridge configuration', $direct_output_url);
                 $this->sendDirectOutputUrlResponse($response);
             }
         }
     }
 }
Пример #2
0
 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;
 }