public function build($params = null)
 {
     $products = parent::getCall('getAPI', 'magebridge_product.list', modMageBridgeProductsHelper::getArguments($params));
     if (!empty($products)) {
         foreach ($products as $index => $product) {
             // Use the URL-key to build a URL
             if (!empty($product['url_store'])) {
                 $product['url'] = MageBridgeUrlHelper::route($product['url_store']);
             } elseif (!empty($product['url_path'])) {
                 $product['url'] = MageBridgeUrlHelper::route($product['url_path']);
             } elseif (empty($product['url'])) {
                 $product['url'] = MageBridgeUrlHelper::route($product['url_key']);
             }
             $product['addtocart_url'] = MageBridgeUrlHelper::route('checkout/cart/add/product/' . $product['product_id'] . '/');
             // Create labels
             $product['addtocart_label'] = JText::sprintf($params->get('addtocart', 'MOD_MAGEBRIDGE_PRODUCTS_ADDTOCART'), $product['label']);
             $product['addtocart_text'] = JText::sprintf($params->get('addtocart', 'MOD_MAGEBRIDGE_PRODUCTS_ADDTOCART'), $product['name']);
             $product['readmore_label'] = JText::sprintf($params->get('readmore', 'MOD_MAGEBRIDGE_PRODUCTS_READMORE'), $product['label']);
             $product['readmore_text'] = JText::sprintf($params->get('readmore', 'MOD_MAGEBRIDGE_PRODUCTS_READMORE'), $product['name']);
             // Remove the current product from the list
             if (JURI::getInstance()->toString(array('path')) == $product['url']) {
                 unset($products[$index]);
                 continue;
             }
             $products[$index] = $product;
         }
     }
     return $products;
 }
 public function build()
 {
     return parent::getCall('getAPI', 'magebridge_order.list');
 }
Example #3
0
 /**
  * Fetch the content from the bridge
  *
  * @access public
  * @param JRegistry $params
  * @return mixed
  */
 public static function build($params = null)
 {
     $arguments = modMageBridgeMenuHelper::getArguments($params);
     return parent::getCall('getAPI', 'magebridge_category.tree', $arguments);
 }
 public static function isLoaded()
 {
     if (JRequest::getCmd('option') == 'com_magebridge') {
         return true;
     } else {
         $document = JFactory::getDocument();
         $modules = MageBridgeModuleHelper::load();
         $buffer = $document->getBuffer();
         foreach ($modules as $module) {
             if (preg_match('/^mod_magebridge_/', $module->module)) {
                 return true;
             }
         }
     }
     return false;
 }
Example #5
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]);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }