示例#1
0
 /**
  * Load the parameters of the User-plugin
  * 
  * @access private
  * @param null
  * @return JParameter
  */
 private function getUserParams()
 {
     require_once JPATH_SITE . '/components/com_magebridge/helpers/loader.php';
     $plugin = JPluginHelper::getPlugin('user', 'magebridge');
     $params = YireoHelper::toRegistry($plugin->params);
     return $params;
 }
示例#2
0
 /**
  * Display method
  *
  * @param string $tpl
  * @return null
  */
 public function display($tpl = null)
 {
     // Fetch this item
     $this->fetchItem();
     // Initialize the form-file
     $file = JPATH_ADMINISTRATOR . '/components/com_magebridge/models/product.xml';
     // Prepare the params-form
     $params = YireoHelper::toRegistry($this->item->params)->toArray();
     $params_form = JForm::getInstance('params', $file);
     $params_form->bind(array('params' => $params));
     $this->params_form = $params_form;
     // Prepare the actions-form
     $actions = YireoHelper::toRegistry($this->item->actions)->toArray();
     $actions_form = JForm::getInstance('actions', $file);
     JPluginHelper::importPlugin('magebridgeproduct');
     JFactory::getApplication()->triggerEvent('onMageBridgeProductPrepareForm', array(&$actions_form, (array) $this->item));
     $actions_form->bind(array('actions' => $actions));
     $this->actions_form = $actions_form;
     // Build the fields
     $this->lists['product'] = MageBridgeFormHelper::getField('magebridge.product', 'sku', $this->item->sku, null);
     // Check for a previous connector-value
     if (!empty($this->item->connector)) {
         $plugin = JPluginHelper::getPlugin('magebridgeproduct', $this->item->connector);
         if (empty($plugin)) {
             $plugin_warning = JText::sprintf('COM_MAGEBRIDGE_PRODUCT_PLUGIN_WARNING', $this->item->connector);
             JError::raiseWarning(500, $plugin_warning);
         }
     }
     parent::display($tpl);
 }
示例#3
0
 /**
  * Method to get the current store definition
  *
  * @param null
  * @return array
  */
 public function getStore()
 {
     // If the database configuration specified no stores, skip this step
     if (MagebridgeModelConfig::load('load_stores') == 0) {
         return null;
     }
     // Get the conditions
     $db = JFactory::getDBO();
     $db->setQuery("SELECT * FROM #__magebridge_stores WHERE `published`=1 ORDER BY `ordering`");
     $conditions = $db->loadObjectList();
     if (empty($conditions)) {
         return null;
     }
     // Import the plugins
     JPluginHelper::importPlugin('magebridgestore');
     $plugins = JPluginHelper::getPlugin('magebridgestore');
     // Try to match a condition with one of the connectors
     foreach ($conditions as $condition) {
         // Extract the parameters and make sure there's something to do
         $actions = YireoHelper::toRegistry($condition->actions)->toArray();
         // Detect the deprecated connector-architecture
         if (!empty($condition->connector) && !empty($condition->connector_value)) {
             JFactory::getApplication()->triggerEvent('onMageBridgeStoreConvertField', array($condition, &$actions));
         }
         // With empty actions, there is nothing to do
         if (empty($actions)) {
             continue;
         }
         // Loop through the plugins and validate the stored actions
         foreach ($plugins as $plugin) {
             $className = 'plg' . $plugin->type . $plugin->name;
             if (class_exists($className)) {
                 $plugin = new $className($this, (array) $plugin);
                 // Validate the stored actions
                 if ($rt = $plugin->onMageBridgeValidate($actions, $condition)) {
                     // Construct the condition parameters
                     $name = $condition->name;
                     $type = $condition->type == 'storeview' ? 'store' : 'group';
                     // Check for the return value
                     if (is_array($rt)) {
                         return $rt;
                     }
                     // Return the store-configuration of this condition
                     return array('type' => $type, 'name' => $name);
                 }
             }
         }
     }
     return null;
 }
示例#4
0
 /**
  * Method to do something on purchase
  *
  * @param string $sku
  * @param JUser $user
  * @param string $status
  * @return mixed
  */
 public function runOnPurchase($sku = null, $qty = 1, $user = null, $status = null, $arguments = null)
 {
     // Get the conditions
     $conditions = $this->getConditions($sku);
     if (empty($conditions)) {
         return null;
     }
     // Import the plugins
     JPluginHelper::importPlugin('magebridgeproduct');
     // Foreach of these conditions, run the product-plugins
     foreach ($conditions as $condition) {
         // Extract the parameters and make sure there's something to do
         $actions = YireoHelper::toRegistry($condition->actions)->toArray();
         // Detect the deprecated connector-architecture
         if (!empty($condition->connector) && !empty($condition->connector_value)) {
             JFactory::getApplication()->triggerEvent('onMageBridgeProductConvertField', array($condition, &$actions));
         }
         // With empty actions, there is nothing to do
         if (empty($actions)) {
             continue;
         }
         // Check for the parameters
         if (!empty($condition->params)) {
             $params = YireoHelper::toRegistry($condition->params);
             $allowed_statuses = $params->get('allowed_status', array('any'));
             $expire_amount = $params->get('expire_amount', 0);
             $expire_unit = $params->get('expire_unit', 'day');
         } else {
             $allowed_statuses = array('any');
             $expire_amount = 0;
             $expire_unit = null;
         }
         // Do not continue if the order-status is not matched
         if (!empty($allowed_statuses) && !in_array('any', $allowed_statuses) && !in_array($status, $allowed_statuses)) {
             continue;
         }
         // Run the product plugins
         JFactory::getApplication()->triggerEvent('onMageBridgeProductPurchase', array($actions, $user, $status, $sku));
         // Log this event
         $this->saveLog($user->id, $sku, $expire_unit, $expire_amount);
     }
 }
示例#5
0
/**
 * Function to convert a system URL to a SEF URL
 */
function MagebridgeBuildRoute(&$query)
{
    // If there's only an Itemid (and an option), skip because this Menu-Item is fine already
    if (isset($query['Itemid']) && count($query) <= 2 && MageBridgeUrlHelper::enforceRootMenu() == false) {
        return array();
    }
    // Initialize some parts
    $segments = array();
    $Itemid = isset($query['Itemid']) ? $query['Itemid'] : 0;
    $orig_Itemid = $Itemid;
    // Get the menu items for this component
    $items = MageBridgeUrlHelper::getMenuItems();
    $current_item = MageBridgeUrlHelper::getItem($Itemid);
    // Strip the slug
    if (!empty($query['request']) && preg_match('/^([0-9]+)\\:(.*)/', $query['request'], $match)) {
        $query['id'] = $match[1];
        $query['request'] = $match[2];
    }
    // Try to match the current query with a Menu-Item
    if (!empty($items)) {
        foreach ($items as $item) {
            // Match a specific combination of view-layout-request
            if (!empty($item->query['request']) && !empty($query['request']) && isset($item->query['view']) && isset($query['view']) && $item->query['view'] == $query['view'] && isset($item->query['layout']) && isset($query['layout']) && $item->query['layout'] == $query['layout']) {
                // Match a specific combination of view-layout-request (string)
                if ($item->query['request'] == $query['request']) {
                    $query = array('option' => 'com_magebridge', 'Itemid' => $item->id);
                    return array();
                    // Match a specific combination of view-layout-request (ID)
                } else {
                    if (isset($query['id']) && $item->query['request'] == $query['id']) {
                        $query = array('option' => 'com_magebridge', 'Itemid' => $item->id);
                        return array();
                    }
                }
                // Match a specific combination of view-layout
            } else {
                if (empty($query['request']) && isset($item->query['view']) && isset($query['view']) && $item->query['view'] == $query['view'] && isset($item->query['layout']) && isset($query['layout']) && $item->query['layout'] == $query['layout']) {
                    $query = array('option' => 'com_magebridge', 'Itemid' => $item->id);
                    return array();
                }
            }
        }
    }
    // Fetch the Root-Item
    $query_option = isset($query['option']) ? $query['option'] : null;
    $query_view = isset($query['view']) ? $query['view'] : null;
    if ($query_option == 'com_magebridge' && $query_view == 'root' && !empty($query['Itemid'])) {
        $root_item = false;
        $root_item_id = false;
    } else {
        $root_item = MageBridgeUrlHelper::getRootItem();
        $root_item_id = $root_item && $root_item->id > 0 ? $root_item->id : false;
    }
    // Set a default empty view
    if (!isset($query['view'])) {
        $query['view'] = null;
    }
    // Reset fake views (used by JCE editor)
    if (in_array($query['view'], array('product', 'category'))) {
        $query['view'] = 'root';
    }
    // If there is a root-item (and therefor "use_rootmenu" is enabled), see if we need to replace the current URL with the root-items URL
    if ($root_item_id > 0) {
        // If there is a root-view or when "enforce_rootmenu" is enabled, reset the Itemid to the Root Menu-Item
        if ($query['view'] == 'root' || MageBridgeUrlHelper::enforceRootMenu()) {
            $query['Itemid'] = $root_item_id;
        }
        // Build the Magento request based upon the current Menu-Item
        if (!empty($current_item)) {
            // Get data from the current Menu-Item
            $cparams = YireoHelper::toRegistry($current_item->params);
            $cquery = $current_item->query;
            // Complete the Magento request if it is still empty
            if (empty($query['request']) && $query['Itemid'] == $root_item_id) {
                // Determine the request if set in the $query['link']
                if (empty($cquery['request'])) {
                    parse_str(preg_replace('/^index.php\\?/', '', $current_item->link), $link);
                    if (!empty($link['request'])) {
                        $cquery['request'] = $link['request'];
                    }
                }
                // Use the MVC-layout to determine the request
                if (!empty($query['layout'])) {
                    $query['request'] = MageBridgeUrlHelper::getLayoutUrl($query['layout']);
                    // Use the MVC-layout plus the current request to determine the request (f.i. configured Menu-Items)
                } else {
                    if (!empty($cquery['layout'])) {
                        $query['request'] = MageBridgeUrlHelper::getLayoutUrl($cquery['layout'], $cquery['request']);
                        // Use the Menu-Item request as Magento request
                    } else {
                        if (!empty($cquery['request'])) {
                            $query['request'] = $cquery['request'];
                            // Use the Menu-Item parameter as Magento request
                        } else {
                            if ($cparams->get('request') != '') {
                                $query['request'] = $cparams->get('request');
                                // Obsolete?
                                //} else if ($current_item->id != $root_item_id) {
                                //	$query['request'] = $current_item->route;
                            }
                        }
                    }
                }
            }
            if (isset($query['request']) && is_numeric($query['request']) && !empty($query['layout'])) {
                $query['request'] = MageBridgeUrlHelper::getLayoutUrl($query['layout'], $query['request']);
            }
            // Enforce the Itemid of the MageBridge Root upon the current route
            if (MageBridgeUrlHelper::enforceRootMenu() && !in_array($root_item_id, $current_item->tree)) {
                $query['Itemid'] = $root_item_id;
                $query['view'] = 'root';
                // If the request is not empty, set the route to the MageBridge Root
            } else {
                if (!empty($query['request'])) {
                    $query['Itemid'] = $root_item_id;
                }
            }
            // If there is no current item, assume to apply the Itemid of the MageBridge Root
        } else {
            $query['Itemid'] = $root_item_id;
        }
    }
    // Add the request as only segment
    if (!empty($query['request']) && !empty($query['Itemid']) && $query['Itemid'] == $root_item_id) {
        $segments[] = $query['request'];
    } else {
        if (!empty($query['request']) && (empty($root_item_id) && $query['view'] == 'root')) {
            $segments[] = $query['request'];
        }
    }
    // Unset an Itemid that does not make sense
    if (isset($query['Itemid']) && $query['Itemid'] == 0) {
        unset($query['Itemid']);
    }
    // Unset all unneeded query-parts because they should be now either segmented or referenced from the Itemid
    $unset_elements = array('view', 'task', 'request', 'layout', 'format', 'SID', 'language', 'id');
    foreach ($unset_elements as $u) {
        unset($query[$u]);
    }
    // Return the segments
    return $segments;
}
示例#6
0
 /**
  * Helper-method to get the specified Menu-Item
  *
  * @param int $id
  *
  * @return object
  */
 public static function getItem($id = 0)
 {
     $items = MageBridgeUrlHelper::getMenuItems();
     if (!empty($items)) {
         foreach ($items as $item) {
             if ($item->id == $id) {
                 if (!isset($item->route)) {
                     $item->route = null;
                 }
                 if (!isset($item->query)) {
                     $item->query = array();
                 }
                 if (!isset($item->query['view'])) {
                     $item->query['view'] = 'root';
                 }
                 if (!isset($item->query['request'])) {
                     $item->query['request'] = null;
                 }
                 if (!isset($item->query['layout'])) {
                     $item->query['layout'] = null;
                 }
                 // If the parameters include the request, set is as query-request
                 if (!empty($item->params)) {
                     if (is_object($item->params)) {
                         $item->params = YireoHelper::toRegistry($item->params);
                     }
                     if (is_object($item->params)) {
                         $item->query['request'] = $item->params->get('request');
                     }
                 }
                 return $item;
             }
         }
     }
     return null;
 }
示例#7
0
 /**
  * Helper-method to return the Joomla! usergroup based on the current Magento customergroup
  *
  * @param null
  * @return array
  */
 public static function getJoomlaGroupIds($customer, $current_groups = array())
 {
     if (!isset($customer['group_id'])) {
         return array();
     }
     static $rows = null;
     if (!is_array($rows)) {
         $db = JFactory::getDBO();
         $query = 'SELECT `magento_group`,`joomla_group`,`params` ' . ' FROM #__magebridge_usergroups WHERE `published`=1 ORDER BY `ordering`';
         $db->setQuery($query);
         $rows = $db->loadObjectList();
     }
     if (!empty($rows)) {
         foreach ($rows as $row) {
             if ($row->magento_group == $customer['group_id']) {
                 $override_existing = false;
                 $new_groups = array($row->joomla_group);
                 if (!empty($row->params)) {
                     $params = YireoHelper::toRegistry($row->params);
                     $override_existing = (bool) $params->get('override_existing');
                     $extra_groups = $params->get('usergroup');
                     if (!empty($extra_groups)) {
                         foreach ($extra_groups as $extra_group) {
                             $new_groups[] = $extra_group;
                         }
                     }
                     $new_groups = array_unique($new_groups);
                 }
                 if ($override_existing == true) {
                     return $new_groups;
                 } else {
                     return array_merge($current_groups, $new_groups);
                 }
             }
         }
     }
     return $current_groups;
 }
示例#8
0
 /**
  * Event onAfterDispatch
  *
  * @access public
  * @param null
  * @return null
  */
 public function onAfterDispatch()
 {
     // Don't do anything if MageBridge is not enabled
     if ($this->isEnabled() == false) {
         return false;
     }
     // Load variables
     $application = JFactory::getApplication();
     // Don't do anything in other applications than the frontend
     if ($application->isSite() == false) {
         return false;
     }
     // Load the whitelist settings
     $whitelist = JFactory::getConfig()->get('magebridge.script.whitelist');
     if (empty($whitelist)) {
         $whitelist = array();
     }
     if ($this->getParams()->get('enable_js_widgetkit', 1) == 1) {
         $whitelist[] = '/widgetkit/';
     }
     if ($this->getParams()->get('enable_js_warp', 1) == 1) {
         $whitelist[] = '/warp/';
     }
     if ($this->getParams()->get('enable_js_template', 1) == 1) {
         $whitelist[] = '/js/';
     }
     JFactory::getConfig()->set('magebridge.script.whitelist', $whitelist);
     // Read the template-related files
     $ini = JPATH_THEMES . '/' . $application->getTemplate() . '/params.ini';
     $conf = JPATH_THEMES . '/' . $application->getTemplate() . '/config';
     if (!file_exists($conf)) {
         $conf = JPATH_THEMES . '/' . $application->getTemplate() . '/config.json';
     }
     $xml = JPATH_THEMES . '/' . $application->getTemplate() . '/templateDetails.xml';
     $ini_content = @file_get_contents($ini);
     $conf_content = @file_get_contents($conf);
     // WARP-usage of "config" file
     if (!empty($conf_content)) {
         // Unjson the data-array
         $data = json_decode($conf_content, true);
         if (is_array($data)) {
             // Fetch the Itemid
             $Itemid = JFactory::getApplication()->input->getInt('Itemid');
             // Define the current profile-indications
             $profileDefault = isset($data['profile_default']) ? $data['profile_default'] : null;
             // Load the profile-specific CSS, set in GET
             $profileGet = JFactory::getApplication()->input->getCmd('profile');
             if (!empty($profileGet)) {
                 $profile = $profileGet;
                 MageBridgeTemplateHelper::load('css', 'profile-' . $profile . '.css');
                 // Load the profile-specific CSS, set through the Itemid-mapping
             } else {
                 if (isset($data['profile_map'][$Itemid])) {
                     $profileMapped = $data['profile_map'][$Itemid];
                     if (!empty($profileMapped)) {
                         $profile = $profileMapped;
                         MageBridgeTemplateHelper::load('css', 'profile-' . $profile . '.css');
                     }
                     // Load the default profile-CSS
                 } else {
                     if (!empty($profileDefault)) {
                         $profile = $profileDefault;
                         MageBridgeTemplateHelper::load('css', 'profile-' . $profile . '.css');
                     }
                 }
             }
             // Load a profile-specific color-definition
             if (!empty($profile) && isset($data['profile_data'][$profile]['color'])) {
                 $color = $data['profile_data'][$profile]['color'];
             } else {
                 if (isset($data['profile_data']['default']['color'])) {
                     $color = $data['profile_data']['default']['color'];
                 }
             }
             // If a color-definition is detected, load the CSS
             if (!empty($color)) {
                 MageBridgeTemplateHelper::load('css', 'color-' . $color . '.css');
             }
             // Load a profile-specific style-definition
             if (!empty($profile) && isset($data['profile_data'][$profile]['style'])) {
                 $style = $data['profile_data'][$profile]['style'];
             } else {
                 if (isset($data['profile_data']['default']['style'])) {
                     $style = $data['profile_data']['default']['style'];
                 }
             }
             // If a style-definition is detected, load the CSS
             if (!empty($style)) {
                 if ($style == 'default') {
                     $style = $profileDefault;
                 }
                 MageBridgeTemplateHelper::load('css', 'style-' . $style . '.css');
             }
             // Load a layout-specific style-definition
             if (!empty($profile) && isset($data['layouts'][$profile]['style'])) {
                 $layout = $data['layouts'][$profile]['style'];
             } else {
                 if (isset($data['layouts']['default']['style'])) {
                     $layout = $data['layouts']['default']['style'];
                 }
             }
             // If a style-definition is detected, load the CSS
             if (!empty($layout)) {
                 if ($layout == 'default') {
                     $layout = $profileDefault;
                 }
                 MageBridgeTemplateHelper::load('css', 'style-' . $layout . '.css');
             }
         }
         // Pre-WARP reading of Joomla! parameters
     } else {
         // Create the parameters object
         $params = YireoHelper::toRegistry($ini_content, $xml);
         // Load a specific stylesheet per color
         $color = $params->get('color');
         if (!empty($color)) {
             MageBridgeTemplateHelper::load('css', 'color-' . $color . '.css');
         }
         // Load a specific stylesheet per style
         $style = $params->get('style');
         if (!empty($style)) {
             MageBridgeTemplateHelper::load('css', 'style-' . $style . '.css');
         }
     }
 }
示例#9
0
 /**
  * Method to return a specific block
  *
  * @param string $block_name
  * @param mixed  $arguments
  *
  * @return string
  */
 public function getBlock($block_name, $arguments = null)
 {
     // Make sure the bridge is built
     MageBridgeModelBridge::getInstance()->build();
     // Get the response-data
     $segment = $this->getResponse('block', $block_name, $arguments);
     if (!isset($segment['data'])) {
         return null;
     }
     // Parse the response-data
     $block_data = $segment['data'];
     if (!empty($block_data)) {
         if (!isset($segment['cache'])) {
             $block_data = self::decode($block_data);
             $block_data = self::filterHtml($block_data);
         }
     }
     // Parse blocks
     $block_data = MageBridgeBlockHelper::parseBlock($block_data);
     // Replace Joomla! jdoc:include tags
     if (MagebridgeModelConfig::load('enable_jdoc_tags') == 1) {
         $block_data = MageBridgeBlockHelper::parseJdocTags($block_data);
     }
     // Run Content Plugins on this block-html
     if (MagebridgeModelConfig::load('enable_content_plugins') == 1) {
         // Prepare a simple item (like an article) for use with Content Plugins
         $item = (object) null;
         $item->text = $block_data;
         // Get a list of all Content Plugins except MageBridge plugins
         $plugins = MageBridgeModelBridgeBlock::getContentPlugins();
         if (!empty($plugins)) {
             foreach ($plugins as $plugin) {
                 JPluginHelper::importPlugin('content', $plugin);
             }
         }
         // Once the plugins are imported, trigger the content-event
         $dispatcher = JEventDispatcher::getInstance();
         $item->params = YireoHelper::toRegistry();
         $result = $dispatcher->trigger('onContentPrepare', array('com_magebridge.block', &$item, &$item->params, 0));
         // Move the modified contents into $block_data
         $block_data = $item->text;
         unset($item);
     }
     // Filter the block throw the "magebridge" plugin group
     if (MagebridgeModelConfig::load('enable_block_rendering') == 1) {
         JPluginHelper::importPlugin('magebridge');
         JFactory::getApplication()->triggerEvent('onBeforeDisplayBlock', array(&$block_name, $arguments, &$block_data));
     }
     return $block_data;
 }
示例#10
0
 /**
  * Get the connector-parameters
  *
  * @param string $type
  * @return JRegistry|JParameter
  */
 protected function _getParams($type)
 {
     static $params = null;
     if (empty($params)) {
         $file = self::_getPath($type, $this->name . '.xml');
         if (isset($this->params) && !empty($this->params)) {
             $params = YireoHelper::toRegistry($this->params, $file);
         } else {
             if ($file == true) {
                 $params = YireoHelper::toRegistry(null, $file);
             } else {
                 $params = YireoHelper::toRegistry();
             }
         }
     }
     return $params;
 }
示例#11
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]);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
示例#12
0
 /**
  * Static method to get data
  * 
  * @param string $element
  * @return mixed
  */
 public static function load($element = null, $overload = null)
 {
     $application = JFactory::getApplication();
     static $config = null;
     if (empty($config)) {
         // Parse the defaults
         $config = array();
         $model = self::getSingleton();
         foreach ($model->getDefaults() as $name => $value) {
             $config[$name] = array('id' => null, 'name' => $name, 'value' => $value, 'core' => 1, 'description' => null);
             if ($application->isAdmin()) {
                 $config[$name]['description'] = JText::_(strtoupper($name) . '_DESCRIPTION');
             }
         }
         // Fetch the current data
         $data = $model->getData();
         // Parse the current data into the config
         foreach ($config as $name => $c) {
             if (!empty($data)) {
                 foreach ($data as $d) {
                     if ($d->name == $c['name']) {
                         $core = $config[$name]['value'] == $d->value ? 1 : 0;
                         $config[$name] = array('id' => $d->id, 'name' => $d->name, 'value' => $d->value, 'core' => $core, 'description' => $c['description']);
                         break;
                     }
                 }
             }
         }
     }
     // Override certain values
     $config['method']['value'] = 'post';
     // Determine the right update format
     if ($config['update_format']['value'] == '') {
         jimport('joomla.application.component.helper');
         $component = JComponentHelper::getComponent('com_magebridge');
         require_once JPATH_ADMINISTRATOR . '/components/com_magebridge/libraries/helper.php';
         $params = YireoHelper::toRegistry($component->params);
         $value = $params->get('update_format', 'tar.gz');
         $config['update_format']['value'] = $value;
     }
     // Disable widgets if needed
     if (JFactory::getApplication()->input->getInt('widgets', 1) == 0) {
         $config['api_widgets']['value'] = 0;
     }
     // Overload a certain values when the Magento Admin Panel needs to be loaded
     $application = JFactory::getApplication();
     if ($application->isAdmin() && JFactory::getApplication()->input->getCmd('option') == 'com_magebridge' && JFactory::getApplication()->input->getCmd('view') == 'root') {
         //$config['debug']['value'] = 0;
         $config['disable_js_all']['value'] = 1;
         $config['disable_js_mootools']['value'] = 1;
     }
     // Allow overriding values
     if (!empty($element) && isset($config[$element]) && $overload !== null) {
         $config[$element]['value'] = $overload;
     }
     // Return the URL
     if ($element == 'url') {
         $url = null;
         if (!empty($config['host']['value'])) {
             $url = $config['protocol']['value'] . '://' . $config['host']['value'] . '/';
             if (!empty($config['basedir']['value'])) {
                 $url .= $config['basedir']['value'] . '/';
             }
         }
         return $url;
         // Return the port-number
     } else {
         if ($element == 'port') {
             return $config['protocol']['value'] == 'http' ? 80 : 443;
             // Return any other element
         } else {
             if ($element != null && isset($config[$element])) {
                 return $config[$element]['value'];
                 // Return no value
             } else {
                 if (!empty($element)) {
                     return null;
                     // Return the configuration itself
                 } else {
                     return $config;
                 }
             }
         }
     }
 }
示例#13
0
 /**
  * Method to get a list of all users
  *
  * @param array $params
  *
  * @return array
  */
 public function getUsers($params = array())
 {
     // System variables
     $db = JFactory::getDBO();
     // Construct the query
     $query = 'SELECT * FROM #__users';
     if (isset($params['search'])) {
         $query .= ' WHERE username LIKE ' . $db->Quote($params['search']);
     }
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     foreach ($rows as $index => $row) {
         require_once JPATH_ADMINISTRATOR . '/components/com_magebridge/libraries/helper.php';
         $params = YireoHelper::toRegistry($row->params);
         $row->params = $params->toArray();
         $rows[$index] = $row;
     }
     return $rows;
 }
示例#14
0
 /**
  * Method to get a XML-based form
  *
  * @access public
  * @subpackage Yireo
  * @param array $data
  * @param bool $loadData
  * @return mixed
  */
 public function getForm($data = array(), $loadData = true)
 {
     // Do not continue if this is not the right backend
     if ($this->app->isAdmin() == false && $this->_frontend_form == false) {
         return false;
     }
     // Do not continue if this is not a singular view
     if (method_exists($this, 'isSingular') && $this->isSingular() == false) {
         return false;
     }
     // Read the form from XML
     $xmlFile = JPATH_ADMINISTRATOR . '/components/' . $this->_option . '/models/' . $this->_form_name . '.xml';
     if (!file_exists($xmlFile)) {
         $xmlFile = JPATH_SITE . '/components/' . $this->_option . '/models/' . $this->_form_name . '.xml';
     }
     if (!file_exists($xmlFile)) {
         return false;
     }
     // Construct the form-object
     jimport('joomla.form.form');
     $form = JForm::getInstance('item', $xmlFile);
     if (empty($form)) {
         return false;
     }
     // Bind the data
     $data = $this->getData();
     $form->bind(array('item' => $data));
     // Insert the params-data if set
     if (!empty($data->params)) {
         $params = $data->params;
         if (is_string($params)) {
             $params = YireoHelper::toRegistry($params)->toArray();
         }
         $form->bind(array('params' => $params));
     }
     return $form;
 }