Пример #1
0
 /**
  * Event onBeforeBuildMageBridge
  */
 public function onBeforeBuildMageBridge()
 {
     // Get base variables
     $application = JFactory::getApplication();
     // Get the current Magento request
     $request = MageBridgeUrlHelper::getRequest();
     // Check for the logout-page
     if ($request == 'customer/account/logoutSuccess') {
         $application->logout();
     }
     // When visiting the checkout/cart/add URL without a valid session, the action will fail because the session does not exist yet
     // The following workaround makes sure we first redirect to another page (to initialize the session) after which we can add the product
     if (preg_match('/checkout\\/cart\\/add\\//', $request) && !preg_match('/redirect=1/', $request)) {
         $bridge = MageBridgeModelBridge::getInstance();
         $session = $bridge->getMageSession();
         // Check for the Magento session-key stored in the Joomla! session
         // Session is NOT yet initialized, therefor addtocart is not working yet either
         if (empty($session) && !empty($_COOKIE)) {
             // Redirect the client to an intermediate page to properly initialize the session
             $bridge->setHttpReferer(MageBridgeUrlHelper::route($request . '?redirect=1'));
             MageBridgeUrlHelper::setRequest('magebridge/redirect/index/url/' . base64_encode($request));
             MageBridgeModelBridgeMeta::getInstance()->reset();
         }
     }
 }
Пример #2
0
 public function display($tpl = null)
 {
     // Get useful variables
     $application = JFactory::getApplication();
     // Set the admin-request
     MageBridgeUrlHelper::setRequest(JRequest::getVar('request', 'admin'));
     // Set which block to display
     $this->setBlock('root');
     // Build the bridge right away, because we need data from Magento
     $block = $this->build();
     echo $block;
     $application->close();
     exit;
 }
Пример #3
0
 /**
  * Method to correct the request URI depending on what is asked
  * 
  * @param array $data
  * @return array
  */
 private function doCorrectRequest($data)
 {
     // If the data do not include any visual elements, setting the Request URI is not needed
     $url_needed = false;
     foreach ($data as $index => $segment) {
         if ($index == 'breadcrumbs' || $index == 'headers' || $segment['name'] == 'block') {
             $url_needed = true;
             break;
         }
     }
     // Reset the Request URI if it is not needed
     if ($url_needed == false && isset($data['meta']['arguments']['request_uri'])) {
         // Change the META-data
         $data['meta']['arguments']['request_uri'] = '/';
         // Correct the helper so it returns the new value
         MageBridgeUrlHelper::setRequest('/');
         // Reset the proxy to make sure 404s or other status codes are not preventing us from building the bridge again
         MageBridgeModelProxy::getInstance()->reset();
     }
     return $data;
 }
Пример #4
0
 /**
  * Event onAfterRender
  *
  * @access public
  * @param null
  * @return null
  */
 public function onAfterRender()
 {
     // Don't do anything if MageBridge is not enabled
     if ($this->isEnabled() == false) {
         return false;
     }
     if (JFactory::getApplication()->input->getCmd('option') == 'com_zoo') {
         $body = JResponse::getBody();
         // Check for Magento CMS-tags
         if (preg_match('/\\{\\{([^}]+)\\}\\}/', $body) || preg_match('/\\{mb([^}]+)\\}/', $body)) {
             // Get system variables
             $bridge = MageBridgeModelBridge::getInstance();
             $register = MageBridgeModelRegister::getInstance();
             // Detect the request-tag
             if (preg_match_all('/\\{mbrequest url="([^\\"]+)"\\}/', $body, $matches)) {
                 foreach ($matches[0] as $matchIndex => $match) {
                     $url = $matches[1][$matchIndex];
                     MageBridgeUrlHelper::setRequest($url);
                     $body = str_replace($match, '', $body);
                 }
             }
             // Detect block-names
             if (preg_match_all('/\\{mbblock name="([^\\"]+)"\\}/', $body, $matches)) {
                 foreach ($matches[0] as $matchIndex => $match) {
                     $block_name = $matches[1][$matchIndex];
                     $register->add('block', $block_name);
                 }
             }
             // Include the MageBridge register
             $key = md5(var_export($body, true)) . ':' . JFactory::getApplication()->input->getCmd('option');
             $text = MageBridgeEncryptionHelper::base64_encode($body);
             // Conditionally load CSS
             if ($this->params->get('load_css') == 1 || $this->params->get('load_js') == 1) {
                 $bridge->register('headers');
             }
             // Build the bridge
             $segment_id = $bridge->register('filter', $key, $text);
             $bridge->build();
             // Load CSS if needed
             if ($this->params->get('load_css') == 1) {
                 $bridge->setHeaders('css');
             }
             // Load JavaScript if needed
             if ($this->params->get('load_js') == 1) {
                 $bridge->setHeaders('js');
             }
             // Get the result from the bridge
             $result = $bridge->getSegmentData($segment_id);
             $result = MageBridgeEncryptionHelper::base64_decode($result);
             // Only replace the original if the new content exists
             if (!empty($result)) {
                 $body = $result;
             }
             // Detect block-names
             if (preg_match_all('/\\{mbblock name="([^\\"]+)"\\}/', $body, $matches)) {
                 foreach ($matches[0] as $matchIndex => $match) {
                     $block_name = $matches[1][$matchIndex];
                     $block = $bridge->getBlock($block_name);
                     $body = str_replace($match, $block, $body);
                 }
             }
         }
         if (!empty($body)) {
             JResponse::setBody($body);
         }
     }
 }
Пример #5
0
 /**
  * Helper-method to set the request as REQUEST-variable
  *
  * @param string $request
  * @return null
  */
 public function setRequest($request)
 {
     $segments = explode('/', $request);
     if (!empty($segments)) {
         foreach ($segments as $index => $segment) {
             $segments[$index] = preg_replace('/^([a-zA-Z0-9]+)\\:/', '\\1-', $segment);
         }
         $request = implode('/', $segments);
     }
     MageBridgeUrlHelper::setRequest($request);
 }