public function allowEvent($event, $options = array())
 {
     static $denied_events = array();
     // Do not run this event if the bridge itself is offline
     if (MageBridge::getBridge()->isOffline()) {
         MageBridgeModelDebug::getInstance()->notice("Plugin helper detects bridge is offline");
         return false;
     }
     // Do not run this event if the option "disable_bridge" is set to true
     if (isset($options['disable_bridge']) && $options['disable_bridge'] == true) {
         MageBridgeModelDebug::getInstance()->notice("Plugin helper detects event '{$event}' is currently disabled");
         return false;
     }
     // Do not execute this event if we are in XML-RPC or JSON-RPC
     if (MageBridge::isApiPage() == true) {
         return false;
     }
     // Check if this event is the list of events already thrown
     if (in_array($event, $denied_events)) {
         MageBridgeModelDebug::getInstance()->notice("Plugin helper detects event '{$event}' is already run");
         return false;
     }
     MageBridgeModelDebug::getInstance()->notice("Plugin helper allows event '{$event}'");
     $denied_events[] = $event;
     return true;
 }
 public function build()
 {
     static $block = null;
     if (empty($block)) {
         // Get the register and add all block-requirements to it
         $register = MageBridgeModelRegister::getInstance();
         $register->add('headers');
         $register->add('block', $this->block_name);
         // Only request breadcrumbs if we are loading another page than the homepage
         $request = MageBridgeUrlHelper::getRequest();
         if (!empty($request)) {
             $register->add('breadcrumbs');
         }
         // Build the bridge
         MageBridgeModelDebug::getInstance()->notice('Building view');
         $bridge = MageBridge::getBridge();
         $bridge->build();
         $bridge->setHeaders();
         // Add things for the frontend specifically
         $application = JFactory::getApplication();
         if ($application->isSite()) {
             $bridge->setBreadcrumbs();
         }
         // Query the bridge for the block
         $block = $bridge->getBlock($this->block_name);
         // Empty blocks
         if (empty($block)) {
             MageBridgeModelDebug::getInstance()->warning('JView: Empty block: ' . $this->block_name);
             $block = JText::_($this->getOfflineMessage());
         }
     }
     return $block;
 }
Beispiel #3
0
 /**
  * Helper-method to determine if it's possible to run this event
  *
  * @param string $event
  * @param array $options
  * @return bool
  */
 public static function allowEvent($event, $options = array())
 {
     static $denied_events = array();
     // Do not run this event if the bridge itself is offline
     if (MageBridge::getBridge()->isOffline()) {
         MageBridgeModelDebug::getInstance()->notice("Plugin helper detects bridge is offline");
         return false;
     }
     // Do not run this event if the option "disable_bridge" is set to true
     if (isset($options['disable_bridge']) && $options['disable_bridge'] == true) {
         MageBridgeModelDebug::getInstance()->notice("Plugin helper detects event '{$event}' is currently disabled");
         return false;
     }
     // Do not execute additional plugin-events on the success-page (to prevent refreshing)
     $request = MageBridgeUrlHelper::getRequest();
     if (preg_match('/checkout\\/onepage\\/success/', $request)) {
         MageBridgeModelDebug::getInstance()->notice("Plugin helper detects checkout/onepage/success page");
         return false;
     }
     // Do not execute this event if we are in XML-RPC or JSON-RPC
     if (MageBridge::isApiPage() == true) {
         return false;
     }
     // Check if this event is the list of events already thrown
     if (in_array($event, $denied_events)) {
         MageBridgeModelDebug::getInstance()->notice("Plugin helper detects event '{$event}' is already run");
         return false;
     }
     MageBridgeModelDebug::getInstance()->notice("Plugin helper allows event '{$event}'");
     $denied_events[] = $event;
     return true;
 }
Beispiel #4
0
 /**
  * Method to display the requested view
  */
 public function display($tpl = null)
 {
     // Set which block to display
     $this->setBlock('content');
     // Build the bridge right away, because we need data from Magento
     $block = $this->build();
     // Determine which template to display
     if (MageBridgeTemplateHelper::isProductPage()) {
         $tpl = 'product';
     } else {
         if (MageBridgeTemplateHelper::isCategoryPage()) {
             $tpl = 'category';
         }
     }
     // Output component-only pages
     $bridge = MageBridge::getBridge();
     if ($bridge->isAjax()) {
         print $block;
         JFactory::getApplication()->close();
     }
     // Add controller information
     $mageConfig = $bridge->getMageConfig();
     $this->mage_controller = isset($mageConfig['controller']) ? $mageConfig['controller'] : null;
     $this->mage_action = isset($mageConfig['action']) ? $mageConfig['action'] : null;
     // Assemble the page class
     $contentClass = array('magebridge-content');
     if (!empty($mageController)) {
         $contentClass[] = 'magebridge-' . $mageController;
     }
     if (!empty($mageAction)) {
         $contentClass[] = 'magebridge-' . $mageController . '-' . $mageAction;
     }
     $this->content_class = $contentClass;
     parent::display($tpl);
 }
 public function display($tpl = null)
 {
     // Set which block to display
     $this->setBlock('content');
     // Build the bridge right away, because we need data from Magento
     $this->build();
     // Determine which template to display
     if (MageBridgeTemplateHelper::isProductPage()) {
         $tpl = 'product';
     } else {
         if (MageBridgeTemplateHelper::isCategoryPage()) {
             $tpl = 'category';
         }
     }
     // Output component-only pages
     $bridge = MageBridge::getBridge();
     if ($bridge->isAjax()) {
         print $this->block;
         JFactory::getApplication()->close();
     }
     parent::display($tpl);
 }
 public function display($cachable = false, $urlparams = false)
 {
     // Check if the bridge is offline
     if (MageBridge::getBridge()->isOffline()) {
         JRequest::setVar('view', 'offline');
         JRequest::setVar('layout', 'default');
     }
     // Set a default view
     if (JRequest::getVar('view') == '') {
         JRequest::setVar('view', 'root');
     }
     // Check for a logout action and perform a logout in Joomla! first
     if (MageBridgeUrlHelper::getRequest() == 'customer/account/logout') {
         $session = JFactory::getSession();
         $session->destroy();
     }
     // Redirect if the layout is not supported by the view
     if (JRequest::getVar('view') == 'catalog' && !in_array(JRequest::getVar('layout'), array('product', 'category', 'addtocart'))) {
         $url = MageBridgeUrlHelper::route('/');
         $this->setRedirect($url);
         return;
     }
     parent::display($cachable, $urlparams);
 }
Beispiel #7
0
 /**
  * Helper method to generate a MageBridge URL
  *
  * @param string  $request
  * @param boolean $xhtml
  * @param array $arguments
  *
  * @return string
  */
 public static function route($request = null, $xhtml = true, $arguments = array())
 {
     if (preg_match('/^(http|https):\\/\\//', $request)) {
         // Try to strip domain part
         $url = JURI::base();
         $request = str_replace($url, '', $request);
         $request = str_replace(str_replace('https://', 'http://', $url), '', $request);
         $request = str_replace(str_replace('http://', 'https://', $url), '', $request);
         return $request;
     }
     $link_to_magento = MagebridgeModelConfig::load('link_to_magento');
     if ($link_to_magento == 1) {
         $bridge = MageBridge::getBridge();
         $config = JFactory::getConfig();
         if ((bool) $config->get('sef_suffix') == true) {
             if (preg_match('/\\/$/', $request) == false) {
                 $request .= '.html';
             }
         }
         return $bridge->getMagentoUrl() . $request;
     }
     $enforce_ssl = MagebridgeModelConfig::load('enforce_ssl');
     if ($enforce_ssl == 1 || $enforce_ssl == 2) {
         $ssl = 1;
     } else {
         if ($enforce_ssl == 3 && self::isSSLPage($request)) {
             $ssl = 1;
         } else {
             $ssl = -1;
         }
     }
     $url = 'index.php?option=com_magebridge&view=root&request=' . $request;
     $url .= '&Itemid=' . self::getItemId();
     if (!empty($arguments)) {
         $url .= '&' . http_build_query($arguments);
     }
     return JRoute::_($url, $xhtml, $ssl);
 }
Beispiel #8
0
 /**
  * Helper-method to return the current category path
  *
  * @access public
  * @param null
  * @return array
  */
 public static function getCurrentCategoryPath()
 {
     static $current_category_path = false;
     if ($current_category_path == false) {
         $config = MageBridge::getBridge()->getSessionData();
         $current_category_path = isset($config['current_category_path']) ? explode('/', $config['current_category_path']) : array();
     }
     return $current_category_path;
 }
 public static function addMagentoStylesheet($file = null, $theme = 'default', $interface = 'default', $attribs = array())
 {
     if (empty($file)) {
         return;
     }
     if (!preg_match('/^(http|https):\\/\\//', $file)) {
         $file = MageBridge::getBridge()->getMagentoUrl() . 'skin/frontend/' . $interface . '/' . $theme . '/css/' . $file;
     }
     $document = JFactory::getDocument();
     $document->addStylesheet($file, 'text/css', null, $attribs);
 }
 public function getHttpReferer()
 {
     if (preg_match('/\\/(uenc|referer)\\/([a-zA-Z0-9\\,]+)/', JURI::current(), $match)) {
         $this->_http_referer = MageBridgeEncryptionHelper::base64_decode($match[2]);
         // If this is a MageBridge page, use it only if its not a customer-page, or homepage
     } else {
         if (preg_match('/\\/customer\\/account\\//', JURI::current()) == false && preg_match('/\\/persistent\\/index/', JURI::current()) == false && preg_match('/\\/checkout\\/cart/', JURI::current()) == false && JURI::current() != MageBridge::getBridge()->getJoomlaBridgeUrl()) {
             $this->_http_referer = JURI::getInstance()->toString();
         } else {
             if (empty($this->_http_referer)) {
                 $session = JFactory::getSession();
                 $this->_http_referer = $session->get('magebridge.http_referer');
             }
         }
     }
     //if (empty($this->_http_referer) && isset($_SERVER['HTTP_REFERER'])) {
     //    $this->_http_referer = $_SERVER['HTTP_REFERER'];
     //}
     return $this->_http_referer;
 }
Beispiel #11
0
 /**
  * Get the Magento Base JS URL
  *
  * @access private
  *
  * @param null
  *
  * @return string
  */
 private function getBaseJsUrl()
 {
     $url = MageBridge::getBridge()->getSessionData('base_js_url');
     $url = preg_replace('/^(https|http):\\/\\//', '', $url);
     $url = preg_replace('/(js|js\\/)$/', '', $url);
     return $url;
 }
Beispiel #12
0
 /**
  * Method to get the total of products
  *
  * @return int
  */
 protected function getContentCount()
 {
     // Get the main variables
     $bridge = MageBridge::getBridge();
     $register = MageBridge::getRegister();
     // Register this API-request
     $arguments = array();
     $id = $register->add('api', 'magebridge_product.count', $arguments);
     // Build the bridge
     $bridge->build();
     // Return the product-count
     $count = $register->getDataById($id);
     return $count;
 }
 public function preBuildBridge()
 {
     // Register the needed segments
     $register = MageBridgeModelRegister::getInstance();
     $register->add('headers');
     $register->add('api', 'customer_group.list');
     $register->add('api', 'magebridge_websites.list');
     // Build the bridge and collect all segments
     $bridge = MageBridge::getBridge();
     $bridge->build();
 }
Beispiel #14
0
 public static function route($request = null, $xhtml = true)
 {
     $link_to_magento = MagebridgeModelConfig::load('link_to_magento');
     if ($link_to_magento == 1) {
         $bridge = MageBridge::getBridge();
         return $bridge->getMagentoUrl() . $request;
     }
     $enforce_ssl = MagebridgeModelConfig::load('enforce_ssl');
     if ($enforce_ssl == 1 || $enforce_ssl == 2) {
         $ssl = 1;
     } else {
         if ($enforce_ssl == 3 && self::isSSLPage($request)) {
             $ssl = 1;
         } else {
             $ssl = -1;
         }
     }
     return JRoute::_('index.php?option=com_magebridge&view=root&Itemid=' . self::getItemid() . '&request=' . $request, $xhtml, $ssl);
 }
Beispiel #15
0
 /**
  * Default method showing a JView
  *
  * @param boolean $cachable
  * @param boolean $urlparams
  *
  * @return null
  */
 public function display($cachable = false, $urlparams = false)
 {
     // Check if the bridge is offline
     if (MageBridge::getBridge()->isOffline()) {
         JFactory::getApplication()->input->set('view', 'offline');
         JFactory::getApplication()->input->set('layout', 'default');
     }
     // Set a default view
     if (JFactory::getApplication()->input->get('view') == '') {
         JFactory::getApplication()->input->set('view', 'root');
     }
     // Check for a logout action and perform a logout in Joomla! first
     $request = MageBridgeUrlHelper::getRequest();
     if ($request == 'customer/account/logout') {
         $session = JFactory::getSession();
         $session->destroy();
     }
     // Check for an admin request
     $backend = MageBridgeModelConfig::load('backend');
     if (!empty($backend) && substr($request, 0, strlen($backend)) === $backend) {
         $request = str_replace($backend, '', $request);
         $url = MageBridgeModelBridge::getInstance()->getMagentoAdminUrl($request);
         $this->setRedirect($url);
         return;
     }
     // Redirect if the layout is not supported by the view
     if (JFactory::getApplication()->input->get('view') == 'catalog' && !in_array(JFactory::getApplication()->input->get('layout'), array('product', 'category', 'addtocart'))) {
         $url = MageBridgeUrlHelper::route('/');
         $this->setRedirect($url);
         return;
     }
     parent::display($cachable, $urlparams);
 }
Beispiel #16
0
 /**
  * Method to load the JavaScript headers
  *
  * @param array $headers
  * @return null
  */
 public function loadJs($headers)
 {
     // Dot not load if this is not the right document-class
     $document = JFactory::getDocument();
     if ($document->getType() != 'html') {
         return false;
     }
     // Check whether all scripts are disabled
     $disable_js = MagebridgeModelConfig::load('disable_js_mage');
     if ($disable_js == 'all') {
         return false;
     }
     // Check whether the bridge is offline
     $offline = MageBridge::getBridge()->isOffline();
     if ($offline == true) {
         return false;
     }
     // Initialize the internal array
     $this->_scripts = array();
     // Get system variables
     $bridge = MageBridge::getBridge();
     $html = "<script type=\"text/javascript\">\n" . "//<![CDATA[\n" . "var BLANK_URL = '" . $this->getBaseJsUrl() . "blank.html';\n" . "var BLANK_IMG = '" . $this->getBaseJsUrl() . "spacer.gif';\n" . "//]]>\n" . "</script>\n";
     $document->addCustomTag($html);
     // Load Prototype
     if ($this->loadPrototype() == true) {
         $this->_has_prototype = true;
     }
     // Loop through all the header-items fetched from Magento
     if (!empty($headers['items'])) {
         $jslist = array();
         $jstags = array();
         foreach ($headers['items'] as $item) {
             if ($item['type'] == 'skin_js' || $item['type'] == 'js') {
                 if (MageBridgeHelper::jsIsDisabled($item['name']) == true) {
                     continue;
                 }
                 $this->_stylesheets[] = $item['name'];
                 $this->_scripts[] = $item['name'];
                 if (empty($item['name'])) {
                     continue;
                 }
                 // If this is a skin-script, construct the tag but add it later to the HTML-header
                 if ($item['type'] == 'skin_js') {
                     if (!preg_match('/^http/', $item['path'])) {
                         $item['path'] = $bridge->getMagentoUrl() . $item['path'];
                     }
                     $tag = '<script type="text/javascript" src="' . $item['path'] . '"></script>' . "\n";
                     $jstags[] = $tag;
                     continue;
                 }
                 // If this is a conditional script, construct the tag but add it later to the HTML-header
                 if (!empty($item['if'])) {
                     if (!preg_match('/^http/', $item['path'])) {
                         $item['path'] = $bridge->getMagentoUrl() . $item['path'];
                     }
                     $tag = '<script type="text/javascript" src="' . $item['path'] . '"></script>' . "\n";
                     $tag = '<!--[if ' . $item['if'] . ' ]>' . "\n" . $tag . '<![endif]-->' . "\n";
                     $jstags[] = $tag;
                     continue;
                 }
                 // Detect Prototype
                 if (strstr($item['path'], 'prototype') || strstr($item['path'], 'scriptaculous')) {
                     $this->_has_prototype = true;
                     // Load an optimized Prototype/script.acul.us version
                     if (MagebridgeModelConfig::load('use_protoaculous') == 1 || MagebridgeModelConfig::load('use_protoculous') == 1) {
                         $skip_scripts = array('prototype/prototype.js', 'scriptaculous/builder.js', 'scriptaculous/effects.js', 'scriptaculous/dragdrop.js', 'scriptaculous/controls.js', 'scriptaculous/slider.js');
                         if (in_array($item['name'], $skip_scripts)) {
                             continue;
                         }
                     }
                     // Skip these, if the Google API is already loaded
                     if (MagebridgeModelConfig::load('use_google_api') == 1) {
                         if (preg_match('/prototype.js$/', $item['name'])) {
                             continue;
                         }
                         if (preg_match('/scriptaculous.js$/', $item['name'])) {
                             continue;
                         }
                     }
                 }
                 // Detect jQuery and replace it
                 if (preg_match('/jquery-([0-9]+)\\.([0-9]+)\\.([0-9]+)/', $item['path']) || preg_match('/jquery.js$/', $item['path']) || preg_match('/jquery.min.js$/', $item['path'])) {
                     if (MagebridgeModelConfig::load('replace_jquery') == 1) {
                         MageBridgeTemplateHelper::load('jquery');
                         continue;
                     }
                 }
                 // Detect the translation script
                 if (strstr($item['name'], 'translate.js')) {
                     $translate = true;
                 }
                 // Load this script through JS merging or not
                 if (MagebridgeModelConfig::load('merge_js') == 1) {
                     $jslist[] = $item['name'];
                 } else {
                     if (MagebridgeModelConfig::load('merge_js') == 2 && !empty($headers['merge_js'])) {
                         // Don't do anything here yet
                     } else {
                         if (!preg_match('/^http/', $item['path'])) {
                             $item['path'] = $bridge->getMagentoUrl() . $item['path'];
                         }
                         $item['path'] = $this->convertUrl($item['path']);
                         $tag = '<script type="text/javascript" src="' . $item['path'] . '"></script>' . "\n";
                         $jstags[] = $tag;
                     }
                 }
             }
         }
         if (MagebridgeModelConfig::load('merge_js') == 2 && !empty($headers['merge_js'])) {
             $this->addScript($headers['merge_js']);
         } else {
             if (!empty($jslist)) {
                 $this->addScript($this->getBaseJsUrl() . 'index.php?c=auto&amp;f=,' . implode(',', $jslist));
             }
         }
         if (!empty($jstags)) {
             foreach ($jstags as $tag) {
                 if (!empty($tag)) {
                     $document->addCustomTag($tag);
                 }
             }
         }
     }
     // Load some extra JavaScript tags
     if (isset($headers['custom'])) {
         foreach ($headers['custom'] as $custom) {
             $custom = MageBridgeEncryptionHelper::base64_decode($custom);
             $custom = preg_replace('/Mage.Cookies.domain([^;]+)\\;/m', 'Mage.Cookies.domain = null;', $custom);
             $document->addCustomTag($custom);
         }
     } else {
         if (isset($translate) && $translate == true) {
             $html = '<script type="text/javascript">var Translator = new Translate([]);</script>';
             $document->addCustomTag($html);
         }
     }
     return;
 }
 /**
  * Perform a delayed login
  *
  * @access private
  * @param null
  * @return null
  */
 private function doDelayedLogin()
 {
     $bridge = MageBridge::getBridge();
     $user_email = $bridge->getMageConfig('customer/email');
     $user_id = $bridge->getMageConfig('customer/joomla_id');
     return MageBridge::getUser()->postlogin($user_email, $user_id);
 }
 public function getCssClass($params, $item, $level, $counter, $tree)
 {
     $config = MageBridge::getBridge()->getMageConfig();
     $current_category_id = isset($config['current_category_id']) ? $config['current_category_id'] : null;
     $current_category_path = isset($config['current_category_path']) ? explode('/', $config['current_category_path']) : array();
     $class = array();
     if (isset($item['entity_id'])) {
         if ($item['entity_id'] == $current_category_id) {
             $class[] = 'current';
         } elseif (in_array($item['entity_id'], $current_category_path)) {
             $class[] = 'active';
         }
     }
     if (isset($item['children_count']) && $item['children_count'] > 0) {
         $class[] = 'parent';
     }
     //if (isset($item['product_count']) && $item['product_count'] > 0) {
     //    $class[] = 'hasproducts';
     //}
     if ($params->get('css_level', 0) == 1) {
         $class[] = 'level' . $level;
     }
     if ($params->get('css_firstlast', 0) == 1) {
         if ($counter == 0) {
             $class[] = 'first';
         }
         if ($counter == count($tree)) {
             $class[] = 'last';
         }
     }
     if ($params->get('css_evenodd', 0) == 1) {
         if ($counter % 2 == 0) {
             $class[] = 'even';
         }
         if ($counter % 2 == 1) {
             $class[] = 'odd';
         }
     }
     $class = array_unique($class);
     $class = implode(' ', $class);
     return $class;
 }