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;
 }
Beispiel #2
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 #3
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]);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 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]);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #5
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;
 }