Beispiel #1
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 #2
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);
 }
Beispiel #3
0
 /**
  * Method to store the item
  *
  * @package MageBridge
  * @access public
  * @param array $data
  * @return bool
  */
 public function store($data)
 {
     if (!empty($data['store'])) {
         $values = explode(':', $data['store']);
         $data['type'] = $values[0] == 'g' ? 'storegroup' : 'storeview';
         $data['name'] = $values[1];
         $data['title'] = $values[2];
         unset($data['store']);
     } else {
         $this->setError(JText::_('COM_MAGEBRIDGE_MODEL_STORE_NO_STORE_SELECTED'));
         return false;
     }
     if (!empty($data['default']) && $data['default']) {
         $this->storeDefault($data['type'], $data['name']);
         return true;
     }
     if (empty($data['name']) || empty($data['title'])) {
         $this->setError(JText::_('COM_MAGEBRIDGE_MODEL_STORE_INVALID_STORE'));
         return false;
     }
     if (empty($data['label'])) {
         $data['label'] = $data['title'];
     }
     $rt = parent::store($data);
     if ($rt == true && $data['published'] == 1) {
         MageBridge::getConfig()->saveValue('load_stores', 1);
     }
     return $rt;
 }
 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;
 }
 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;
 }
 /**
  * Event onAfterInitialise
  */
 public function onAfterInitialise()
 {
     // Don't do anything if MageBridge is not enabled
     if ($this->isEnabled() == false) {
         return false;
     }
     // Perform actions on the frontend
     $application = JFactory::getApplication();
     // Check for postlogin-cookie
     if (isset($_COOKIE['mb_postlogin']) && !empty($_COOKIE['mb_postlogin'])) {
         // If the user is already logged in, remove the cookie
         if (JFactory::getUser()->id > 0) {
             setcookie('mb_postlogin', '', time() - 3600, '/', '.' . JURI::getInstance()->toString(array('host')));
         }
         // Otherwise decrypt the cookie and use it here
         $data = MageBridgeEncryptionHelper::decrypt($_COOKIE['mb_postlogin']);
         if (!empty($data)) {
             $customer_email = $data;
         }
     }
     // Perform a postlogin if needed
     $post = $application->input->post->getArray();
     if (empty($post)) {
         $postlogin_userevents = $this->params->get('postlogin_userevents', 0) == 1 ? true : false;
         if (empty($customer_email)) {
             $customer_email = MageBridgeModelBridge::getInstance()->getSessionData('customer/email');
         }
         if (!empty($customer_email)) {
             MageBridge::getUser()->postlogin($customer_email, null, $postlogin_userevents);
         }
     }
 }
Beispiel #7
0
 /**
  * Helper-method to determine whether an user is a backend user
  *
  * @param mixed $user User object or identifier
  * @param string $type Either object, email or username
  * @return boolean
  */
 public static function isBackendUser($user = null, $type = 'object')
 {
     // Check for empty user
     if (empty($user)) {
         return false;
     }
     // Get the right instance
     if ($user instanceof JUser == false) {
         if ($type == 'email') {
             $user = MageBridge::getUser()->loadByEmail($user);
         }
         if ($type == 'username') {
             $user = MageBridge::getUser()->loadByUsername($user);
         }
     }
     // Check the legacy usertype parameter
     if (!empty($user->usertype) && (stristr($user->usertype, 'administrator') || stristr($user->usertype, 'manager'))) {
         return false;
     }
     // Check for ACL access
     if (method_exists($user, 'authorise') && $user->authorise('core.admin')) {
         return true;
     }
     return false;
 }
 /**
  * Method to make login an user
  */
 public function login()
 {
     // Fetch the user-email
     $user_email = MageBridgeEncryptionHelper::decrypt(JFactory::getApplication()->input->getString('token'));
     $application = JFactory::getApplication();
     // Perform a post-login
     $rt = MageBridge::getUser()->postlogin($user_email, null, true);
     // Determine the redirect URL
     $redirectUrl = base64_decode(JFactory::getApplication()->input->getString('redirect'));
     if (empty($redirectUrl)) {
         $redirectUrl = MageBridgeModelBridge::getMagentoUrl();
     }
     // Redirect
     $application->redirect($redirectUrl);
     $application->close();
 }
 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 #11
0
 /**
  * Method to execute when the profile is saved
  * 
  * @param int $user_id
  * @return bool
  */
 public function synchronize($user_id = 0)
 {
     // Exit if there is no user_id
     if (empty($user_id)) {
         return false;
     }
     // Get a general user-array from Joomla! itself
     $db = JFactory::getDBO();
     $query = "SELECT `name`,`username`,`email` FROM `#__users` WHERE `id`=" . (int) $user_id;
     $db->setQuery($query);
     $user = $db->loadAssoc();
     // Exit if this is giving us no result
     if (empty($user)) {
         return false;
     }
     // Sync this user-record with the bridge
     MageBridgeModelDebug::getInstance()->trace('Synchronizing user', $user);
     MageBridge::getUser()->synchronize($user);
     $session = JFactory::getSession();
     $session->set('com_magebridge.task_queue', array());
     return true;
 }
Beispiel #12
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;
 }
Beispiel #13
0
if (file_exists($maintenanceFile)) {
    header('HTTP/1.1 503 Service Temporarily Unavailable');
    exit;
}
// Use this for profiling
define('yireo_starttime', microtime(true));
if (function_exists('yireo_benchmark') == false) {
    function yireo_benchmark($title)
    {
        $yireo_totaltime = round(microtime(true) - yireo_starttime, 4);
        Mage::getSingleton('magebridge/debug')->profiler($title . ': ' . $yireo_totaltime . ' seconds');
    }
}
// Initialize the bridge
require_once 'magebridge.class.php';
$magebridge = new MageBridge();
// Mask this request
$magebridge->premask();
// Support for Magento Compiler
$compilerConfig = 'includes/config.php';
if (file_exists($compilerConfig)) {
    include $compilerConfig;
}
// Initialize the Magento application
require_once 'app/Mage.php';
try {
    // Determine the Mage::app() arguments from the bridge
    $app_value = $magebridge->getMeta('app_value');
    $app_type = $magebridge->getMeta('app_type');
    // Doublecheck certain values
    if ($app_type == 'website' && $app_value != 'admin') {
Beispiel #14
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 #15
0
 /**
  * Return whether MageBridge is available or not
  *
  * @access private
  *
  * @param null
  *
  * @return mixed $value
  */
 private function isEnabled()
 {
     if (class_exists('MageBridgeModelBridge')) {
         if (MageBridgeModelBridge::getInstance()->isOffline()) {
             return false;
         } elseif (MageBridge::isApiPage() == true) {
             return false;
         }
         return true;
     }
     return false;
 }
Beispiel #16
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;
 }
 /**
  * Return the MageBridge user-object
  * 
  * @access private
  * @param string $name
  * @return mixed $value
  */
 private function getUser()
 {
     return MageBridge::getUser();
 }
Beispiel #18
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 static function getProductsByTags($tags = array())
 {
     return MageBridge::getAPI('magebridge_tag.list', $tags);
 }
 public static function preload()
 {
     // Don't preload anything if this is the API
     if (MageBridge::isApiPage() == true) {
         return null;
     }
     // Don't preload anything if the current output contains only the component-area
     if (in_array(JRequest::getCmd('tmpl'), array('component', 'raw'))) {
         return null;
     }
     // Fetch all the current modules
     $modules = MageBridgeModuleHelper::load();
     $register = MageBridgeModelRegister::getInstance();
     // Loop through all the available Joomla! modules
     if (!empty($modules)) {
         foreach ($modules as $module) {
             // Check the name to see if this is a MageBridge-related module
             if (preg_match('/^mod_magebridge_/', $module->module)) {
                 // Initialize variables
                 $type = null;
                 $name = null;
                 jimport('joomla.html.parameter');
                 $params = new JParameter($module->params);
                 $conf = JFactory::getConfig();
                 $user = JFactory::getUser();
                 // Check whether caching returns a valid module-output
                 if ($params->get('cache', 0) && $conf->getValue('config.caching')) {
                     $cache = JFactory::getCache($module->module);
                     $cache->setLifeTime($params->get('cache_time', $conf->getValue('config.cachetime') * 60));
                     $contents = $cache->get(array('JModuleHelper', 'renderModule'), array($module, $params->toArray()), $module->id . $user->get('aid', 0));
                     // If the contents are not empty, there is a cached version so we skip this
                     if (!empty($contents)) {
                         continue;
                     }
                     // If the contents are empty, make sure we have a fresh start
                     // @todo: Why was this needed? This causes under certain circumstances numerous bridge-calls which is bad.
                     //if (empty($contents)) {
                     //    $cache->clean();
                     //}
                 }
                 // If the layout is AJAX-ified, do not fetch the block at all
                 if ($params->get('layout') == 'ajax') {
                     continue;
                 }
                 // Try to include the helper-file
                 if (is_file(JPATH_SITE . '/modules/' . $module->module . '/helper.php')) {
                     $module_file = JPATH_SITE . '/modules/' . $module->module . '/helper.php';
                 } else {
                     if (is_file(JPATH_ADMINISTRATOR . '/modules/' . $module->module . '/helper.php')) {
                         $module_file = JPATH_ADMINISTRATOR . '/modules/' . $module->module . '/helper.php';
                     }
                 }
                 // If there is a module-file, include it
                 if (!empty($module_file) && is_file($module_file)) {
                     require_once $module_file;
                     // Construct and detect the module-class
                     $class = preg_replace('/_([a-z]{1})/', '\\1', $module->module) . 'Helper';
                     if (class_exists($class)) {
                         // Instantiate the class and check for the "register" method
                         $o = new $class();
                         if (method_exists($o, 'register')) {
                             // Fetch the requested tasks
                             $requests = $o->register($params);
                             if (is_array($requests) && count($requests) > 0) {
                                 foreach ($requests as $request) {
                                     // Add each requested task to the MageBridge register
                                     if (!empty($request[2])) {
                                         $register->add($request[0], $request[1], $request[2]);
                                     } else {
                                         if (!empty($request[1])) {
                                             $register->add($request[0], $request[1]);
                                         } else {
                                             $register->add($request[0]);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 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 #22
0
 /**
  * Helper method to sync the user
  *
  * @access private
  * @param object JUser
  * @return bool
  */
 private function syncUser($user = null)
 {
     // Check if we can run this event or not
     if (MageBridgePluginHelper::allowEvent('onUserDetailsUpdate') == false) {
         return;
     }
     // Copy the username to the email address
     if (JFactory::getApplication()->isSite() == true && $this->getUserParams()->get('username_from_email', 1) == 1 && $user->username != $user->email) {
         if ($this->getUser()->allowSynchronization($user, 'save') == true) {
             MageBridgeModelDebug::getInstance()->notice("onUserDetailsUpdate::bind on user " . $user->username);
             // Change the record in the database
             $user->email = $user->username;
             $user->save();
         }
     }
     // Synchronize this user-record with Magento
     if ($this->getUserParams()->get('user_sync', 1) == 1) {
         MageBridgeModelDebug::getInstance()->notice("onUserDetailsUpdate::usersync on user " . $user->username);
         // Convert this object to an array
         if (!is_array($user)) {
             jimport('joomla.utilities.arrayhelper');
             $user = JArrayHelper::fromObject($user, false);
         }
         // Sync this user-record with the bridge
         MageBridge::getUser()->synchronize($user);
     }
     return true;
 }
 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;
 }
 /**
  * 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 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);
 }
Beispiel #26
0
 /**
  * Handle the event that is generated after a customer is saved in Magento (JSON-RPC)
  *
  * @param array $arguments
  *
  * @return int
  */
 public function mageCustomerSaveAfter($arguments = array())
 {
     // Check if this call is valid
     if (!isset($arguments['customer'])) {
         return false;
     }
     if (!isset($arguments['customer']['email'])) {
         return false;
     }
     // Fetch the right variables
     $customer = $arguments['customer'];
     if (isset($customer['addresses'][0][0])) {
         $address = $customer['addresses'][0][0];
         unset($customer['addresses']);
     } else {
         $address = array();
     }
     // Try to load the user through the Joomla! ID stored in Magento
     if (isset($customer['joomla_id'])) {
         $user = JFactory::getUser();
         $user->load($customer['joomla_id']);
     }
     // Try to load the user through its email-address
     if (!isset($user) || !isset($user->id) || !$user->id > 0) {
         $user = $this->getUser()->loadByEmail($customer['email']);
     }
     // Encrypt the user-password before continuing
     if (isset($customer['password'])) {
         $customer['password'] = MageBridge::decrypt($customer['password']);
     }
     // Start building the data-input for creating the Joomla! user
     if (!empty($customer['name']) && !empty($customer['email'])) {
         $data = array();
         // Include the received email
         if (!empty($customer['email'])) {
             $data['email'] = $customer['email'];
         }
         // Include the real name
         $data['name'] = $this->getRealname($user, $customer);
         // Include the username
         $data['username'] = $this->getUsername($user, $customer);
         // Set the firstname and lastname
         $data['magebridgefirstlast'] = array('firstname' => $customer['firstname'], 'lastname' => $customer['lastname']);
         // Include the password
         if (!empty($customer['password'])) {
             $data['password'] = $customer['password'];
             $data['password2'] = $customer['password'];
         }
         // Activate this account, if it's also activated in Magento
         if (isset($customer['is_active'])) {
             if ($customer['is_active'] == 1) {
                 $data['activation'] = '';
                 $data['block'] = 0;
             } else {
                 $data['block'] = 1;
             }
         }
         // Add the usergroup ID to this user (based upon groups configured in #__magebridge_usergroups)
         $usergroups = is_array($user->groups) ? $user->groups : array();
         $customer['usergroup'] = MageBridgeUserHelper::getJoomlaGroupIds($customer, $usergroups);
         //MageBridgeModelDebug::getInstance()->trace("Customer group", $customer['usergroup']);
         if (!empty($customer['usergroup'])) {
             $user->groups = $customer['usergroup'];
         }
         // If this user did not exist yet, create it
         if ($this->params->get('autocreate', 1) == 1 && ($user == false || $user->id == 0)) {
             $user = $this->getUser()->create($data, true);
             if (is_object($user) && $user->id > 0) {
                 // Save the user through the Profile Connectors
                 $profile = new MageBridgeConnectorProfile();
                 $profile->onSave($user, $customer, $address);
                 // Return the new user-ID
                 return $user->id;
             } else {
                 return 3;
             }
         }
         // Bind the data to the current user
         if ($user->bind($data) == false) {
             return false;
         }
         // Save the user
         if ($user->save() == false) {
             return false;
         }
         // Save the user through the Profile Connectors
         $profile = new MageBridgeConnectorProfile();
         $profile->onSave($user, $customer, $address);
         // Run the newsletter plugins
         if (isset($customer['is_subscribed'])) {
             JPluginHelper::importPlugin('magebridgenewsletter');
             JFactory::getApplication()->triggerEvent('onNewsletterSubscribe', array($user, (bool) $customer['is_subscribed']));
         }
         // Return the user ID for convenience
         return $user->id;
     }
     return false;
 }
Beispiel #27
0
 /**
  * Pre-register the modules, because they are loaded after the component output
  *
  * @param null
  * @return null
  */
 public static function preload()
 {
     // Preload only once
     static $preload = false;
     if ($preload == true) {
         return null;
     }
     $preload = true;
     // Don't preload anything if this is the API
     if (MageBridge::isApiPage() == true) {
         return null;
     }
     // Don't preload anything if the current output contains only the component-area
     if (in_array(JFactory::getApplication()->input->getCmd('tmpl'), array('component', 'raw'))) {
         return null;
     }
     // Only preload once
     static $preloaded = false;
     if ($preloaded == false) {
         $preloaded = true;
     }
     // Fetch all the current modules
     $modules = MageBridgeModuleHelper::loadMageBridgeModules();
     $register = MageBridgeModelRegister::getInstance();
     // Loop through all the available Joomla! modules
     if (!empty($modules)) {
         foreach ($modules as $module) {
             // Check the name to see if this is a MageBridge-related module
             if (preg_match('/^mod_magebridge/', $module->module)) {
                 // Initialize variables
                 $type = null;
                 $name = null;
                 $params = YireoHelper::toRegistry($module->params);
                 $app = JFactory::getApplication();
                 $user = JFactory::getUser();
                 // Check whether caching returns a valid module-output
                 if ($params->get('cache', 0) && JFactory::getConfig()->get('caching')) {
                     $cache = JFactory::getCache($module->module);
                     $cache->setLifeTime($params->get('cache_time', JFactory::getConfig()->get('cachetime') * 60));
                     $contents = $cache->get(array('JModuleHelper', 'renderModule'), array($module, $params->toArray()), $module->id . $user->get('aid', 0));
                     $contents = trim($contents);
                     // If the contents are not empty, there is a cached version so we skip this
                     if (!empty($contents)) {
                         continue;
                     }
                 }
                 // If the layout is AJAX-ified, do not fetch the block at all
                 if ($params->get('layout') == 'ajax') {
                     continue;
                 }
                 // Try to include the helper-file
                 if (is_file(JPATH_SITE . '/modules/' . $module->module . '/helper.php')) {
                     $module_file = JPATH_SITE . '/modules/' . $module->module . '/helper.php';
                 } else {
                     if (is_file(JPATH_ADMINISTRATOR . '/modules/' . $module->module . '/helper.php')) {
                         $module_file = JPATH_ADMINISTRATOR . '/modules/' . $module->module . '/helper.php';
                     }
                 }
                 // If there is no module-file, skip this module
                 if (empty($module_file) || !is_file($module_file)) {
                     continue;
                 }
                 // Include the module file
                 require_once $module_file;
                 // Construct and detect the module-class
                 $class = preg_replace('/_([a-z]{1})/', '\\1', $module->module) . 'Helper';
                 // If the class does not exist, try it with a uppercase-first match
                 if (!class_exists($class)) {
                     $class = ucfirst($class);
                 }
                 // If the class does not exist, skip this module
                 if (!class_exists($class)) {
                     continue;
                 }
                 // Instantiate the class
                 $o = new $class();
                 // If the register-method does not exist, skip this module
                 if (!method_exists($o, 'register')) {
                     continue;
                 }
                 MageBridgeModelDebug::getInstance()->notice('Preloading module-resource for ' . $module->module);
                 // Fetch the requested tasks
                 $requests = $o->register($params);
                 if (is_array($requests) && count($requests) > 0) {
                     foreach ($requests as $request) {
                         // Add each requested task to the MageBridge register
                         if (!empty($request[2])) {
                             $register->add($request[0], $request[1], $request[2]);
                         } else {
                             if (!empty($request[1])) {
                                 $register->add($request[0], $request[1]);
                             } else {
                                 $register->add($request[0]);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #28
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 #29
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);
 }
 */
// Basic PHP settings that can be overwritten
ini_set('zlib.output_compression', 0);
//ini_set('display_errors', 1);
// Use this for profiling
define('yireo_starttime', microtime(true));
if (function_exists('yireo_benchmark') == false) {
    function yireo_benchmark($title)
    {
        $yireo_totaltime = round(microtime(true) - yireo_starttime, 4);
        Mage::getSingleton('magebridge/debug')->profiler($title . ': ' . $yireo_totaltime . ' seconds');
    }
}
// Initialize the bridge
require_once 'magebridge.class.php';
$magebridge = new MageBridge();
// Mask this request
$magebridge->premask();
// Support for Magento Compiler
$compilerConfig = 'includes/config.php';
if (file_exists($compilerConfig)) {
    include $compilerConfig;
}
// Initialize the Magento application
require_once 'app/Mage.php';
try {
    // Determine the Mage::app() arguments from the bridge
    $app_value = $magebridge->getMeta('app_value');
    $app_type = $magebridge->getMeta('app_type');
    // Doublecheck certain values
    if ($app_type == 'website' && $app_value != 'admin') {