예제 #1
0
 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;
 }
예제 #2
0
 protected function getInput()
 {
     $name = $this->name;
     $fieldName = $name;
     $value = $this->value;
     // Only build a dropdown when the API-widgets are enabled
     if (MagebridgeModelConfig::load('api_widgets') == true) {
         // Fetch the widget data from the API
         $options = MageBridgeWidgetHelper::getWidgetData('website');
         // Parse the result into an HTML form-field
         if (!empty($options) && is_array($options)) {
             foreach ($options as $index => $option) {
                 // Customize the return-value when the attribute "output" is defined
                 $output = (string) $this->element['output'];
                 if (!empty($output) && array_key_exists($output, $option)) {
                     $option['value'] = $option[$output];
                 }
                 // Customize the label
                 $option['label'] = $option['label'] . ' (' . $option['value'] . ') ';
                 // Add the option back to the list of options
                 $options[$index] = $option;
             }
             // Return a dropdown list
             array_unshift($options, array('value' => '', 'label' => ''));
             return JHTML::_('select.genericlist', $options, $fieldName, null, 'value', 'label', $value);
             // Fetching data from the bridge failed, so report a warning
         } else {
             MageBridgeModelDebug::getInstance()->warning('Unable to obtain MageBridge API Widget "website": ' . var_export($options, true));
         }
     }
     // Return a simple input-field by default
     return '<input type="text" name="' . $fieldName . '" value="' . $value . '" />';
 }
예제 #3
0
 protected function getInput()
 {
     $name = $this->name;
     $fieldName = $name;
     $value = $this->value;
     if (MagebridgeModelConfig::load('api_widgets') == true) {
         $cache = JFactory::getCache('com_magebridge_admin');
         $cache->setCaching(0);
         $options = $cache->call(array('JElementStoreview', 'getResult'));
         // Parse the result into an HTML form-field
         if (!empty($options) && is_array($options)) {
             foreach ($options as $index => $option) {
                 if (!isset($option[$return])) {
                     $return = 'value';
                 }
                 $option['label'] = $option['label'] . ' (' . $option[$return] . ') ';
                 $option['value'] = $option[$return];
                 $options[$index] = $option;
             }
             array_unshift($options, array('value' => '', 'label' => ''));
             return JHTML::_('select.genericlist', $options, $fieldName, null, 'value', 'label', $value);
         } else {
             MageBridgeModelDebug::getInstance()->warning('Unable to obtain MageBridge API Widget "storeview": ' . var_export($options, true));
         }
     }
     return '<input type="text" name="' . $fieldName . '" value="' . $value . '" />';
 }
예제 #4
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;
 }
예제 #5
0
 /**
  * Method to handle Magento events
  */
 public function setEvents($events = null)
 {
     static $set = false;
     if ($set == true) {
         return false;
     }
     if (empty($events)) {
         $data = $this->getResponseData();
         if (empty($data['data'])) {
             return false;
         }
         $events = $data['data'];
     }
     if (!empty($events)) {
         foreach ($events as $event) {
             if (!empty($event['type']) && $event['type'] == 'magento' && !empty($event['group']) && !empty($event['event'])) {
                 if (!is_array($event['arguments'])) {
                     $event['arguments'] = array();
                 }
                 MageBridgeModelDebug::getInstance()->notice('Bridge feedback: firing mageEvent ' . $event['event'] . ' of group ' . $event['group']);
                 JPluginHelper::importPlugin($event['group']);
                 JFactory::getApplication()->triggerEvent($event['event'], array($event['arguments']));
             }
         }
     }
     $set = true;
     return true;
 }
 /**
  * Handle the event that is generated when an user tries to login
  * 
  * @access public
  * @param string $context
  * @param object $row
  * @param string $params
  * @param mixed $page
  * @return null
  */
 public function onContentPrepare($context, $row, $params, $page)
 {
     // Do not continue if not enabled
     if ($this->isEnabled() == false) {
         return false;
     }
     // Get system variables
     $bridge = MageBridgeModelBridge::getInstance();
     // Load plugin paramaters
     jimport('joomla.html.parameter');
     $plugin = JPluginHelper::getPlugin('content', 'magebridgetags');
     $pluginParams = new JParameter($plugin->params);
     $max = $pluginParams->get('max_products', 10);
     // Find related data
     $tags = $this->getTags($row);
     // If there are no tags, don't do anything
     if (empty($tags)) {
         return false;
     }
     // Build the bridge
     $segment_id = $bridge->register('api', 'magebridge_tag.list', $tags);
     $bridge->build();
     $products = $bridge->getSegmentData($segment_id);
     // Do not continue if the result is empty
     if (empty($products)) {
         return false;
     }
     // Do not continue if the result is not an array
     if (!is_array($products)) {
         MageBridgeModelDebug::getInstance()->error("Fetching tags resulted in non-array: " . var_export($products, true));
         return false;
     }
     // Only show the needed amount of tags
     $products = array_slice($products, 0, $max);
     // Load the template script (and allow for overrides)
     jimport('joomla.filesystem.path');
     $template_dir = JPATH_THEMES . '/' . JFactory::getApplication()->getTemplate();
     // Determine the right folder
     if (is_dir(dirname(__FILE__) . '/tmpl')) {
         $tmplDir = 'tmpl';
     } else {
         $tmplDir = 'magebridgetags';
     }
     // Load the layout file
     $layout = $template_dir . '/html/plg_magebridgetags/default.php';
     if (!is_file($layout) || !is_readable($layout)) {
         $layout = dirname(__FILE__) . '/' . $tmplDir . '/default.php';
     }
     // Prepare the variables
     $tagstring = implode(', ', $tags);
     // Read the template
     ob_start();
     include $layout;
     $output = ob_get_contents();
     ob_end_clean();
     // Append the result to the content
     $row->text .= MageBridgeModelBridgeBlock::filterHtml($output);
     return true;
 }
예제 #7
0
 public function __construct($config = array())
 {
     $rt = parent::__construct($config);
     MageBridgeModelDebug::getDebugOrigin(MageBridgeModelDebug::MAGEBRIDGE_DEBUG_ORIGIN_JOOMLA_JSONRPC);
     $this->debug = MageBridgeModelDebug::getInstance();
     $this->app = JFactory::getApplication();
     return $rt;
 }
예제 #8
0
 /**
  * Fetch the content from the bridge
  *
  * @param string $function
  * @param string $name
  * @param mixed $arguments
  * @return mixed
  */
 public static function getCall($function, $name, $arguments = null)
 {
     // Include the MageBridge bridge
     $bridge = MageBridgeModelBridge::getInstance();
     // Build the bridge
     MageBridgeModelDebug::getInstance()->notice('Bridge called for ' . $function . ' "' . $name . '"');
     $build = $bridge->build();
     return $bridge->{$function}($name, $arguments);
 }
예제 #9
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->bridge = MageBridgeModelBridge::getInstance();
     $this->debug = MageBridgeModelDebug::getInstance();
     $this->app = JFactory::getApplication();
     $this->helper = new MageBridgeProxyHelper($this->app);
     $this->input = $this->app->input;
     $this->config = JFactory::getConfig();
 }
예제 #10
0
 public function fetchElement($name, $value, &$node, $control_name)
 {
     if (MagebridgeModelConfig::load('api_widgets') == true) {
         $options = MageBridgeWidgetHelper::getWidgetData('theme');
         if (!empty($options) && is_array($options)) {
             array_unshift($options, array('value' => '', 'label' => '-- Select --'));
             return JHTML::_('select.genericlist', $options, $name, null, 'value', 'label', $value);
         } else {
             MageBridgeModelDebug::getInstance()->warning('Unable to obtain MageBridge API Widget "theme": ' . var_export($options, true));
         }
     }
     return '<input type="text" name="' . $name . '" value="' . $value . '" />';
 }
예제 #11
0
 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;
     }
     // Foreach of these conditions, run the appropriate connector method
     foreach ($conditions as $condition) {
         $connector = $this->getConnector($condition->connector);
         if (!empty($condition->connector_value) && !empty($connector)) {
             if (!empty($condition->params)) {
                 jimport('joomla.html.parameter');
                 $params = new JParameter($condition->params);
                 $only_completed = $params->get('only_completed', false);
                 $expire_amount = $params->get('expire_amount', 0);
                 $expire_unit = $params->get('expire_unit', 'day');
             } else {
                 $only_completed = false;
                 $expire_amount = 0;
                 $expire_unit = null;
             }
             // Do not continue if we are only supposed to run on completed orders
             if ($status != 'complete' && $only_completed == true) {
                 continue;
             }
             // Try to call the connector-method
             $rt = false;
             if (method_exists($connector, 'onPurchase')) {
                 try {
                     if ($qty < 1) {
                         $qty = 1;
                     }
                     for ($i = 0; $i < $qty; $i++) {
                         $rt = $connector->onPurchase($condition->connector_value, $user, $status);
                     }
                 } catch (Exception $e) {
                     MageBridgeModelDebug::getInstance()->trace('Product Connector failed', $e->getMessage());
                 }
                 $this->saveLog($user->id, $sku, $expire_unit, $expire_amount);
             }
             // If this result is false (read: an error), do not continue with other product relations
             //if ($rt == false) break;
         }
     }
     // Refresh the user session, just in case
     MageBridge::getUser()->updateSession(JFactory::getUser());
 }
 private function authenticate($auth)
 {
     if (!empty($auth) && !empty($auth['api_user']) && !empty($auth['api_key'])) {
         $api_user = MageBridgeEncryptionHelper::decrypt($auth['api_user']);
         $api_key = MageBridgeEncryptionHelper::decrypt($auth['api_key']);
         if ($api_user != MagebridgeModelConfig::load('api_user')) {
             MageBridgeModelDebug::getInstance()->error('XML-RPC plugin: API-authentication failed: Username did not match');
         } elseif ($api_key != MagebridgeModelConfig::load('api_key')) {
             MageBridgeModelDebug::getInstance()->error('XML-RPC plugin: API-authentication failed: Key did not match');
         } else {
             MageBridgeModelDebug::getInstance()->notice('XML-RPC plugin: API-authentication succeeded');
             return true;
         }
     }
     return false;
 }
 public function fetchElement($name, $value, &$node, $control_name)
 {
     // Add the control name
     if (!empty($control_name)) {
         $name = $control_name . '[' . $name . ']';
     }
     // Only build a dropdown when the API-widgets are enabled
     if (MagebridgeModelConfig::load('api_widgets') == true) {
         // Fetch the widget data from the API
         $cache = JFactory::getCache('com_magebridge_admin');
         $cache->setCaching(0);
         $options = $cache->call(array('JElementCustomerGroup', 'getResult'));
         // Parse the result into an HTML form-field
         if (!empty($options) && is_array($options)) {
             foreach ($options as $index => $option) {
                 // Set default return-value
                 $option['value'] = $option['customer_group_id'];
                 // Customize the return-value when the XML-attribute "output" is defined
                 if (is_object($node)) {
                     $output = $node->attributes('output');
                     if (!empty($output) && array_key_exists($output, $option)) {
                         $option['value'] = $option[$output];
                     }
                 }
                 // Strip empty options (like the "NOT LOGGED IN" group)
                 if (empty($option['value']) || $option['value'] == 0) {
                     unset($options[$index]);
                     continue;
                 }
                 // Customize the label
                 $option['label'] = $option['customer_group_code'];
                 // Add the option back to the list of options
                 $options[$index] = $option;
             }
             // Return a dropdown list
             array_unshift($options, array('value' => '', 'label' => ''));
             return JHTML::_('select.genericlist', $options, $name, null, 'value', 'label', $value);
             // Fetching data from the bridge failed, so report a warning
         } else {
             MageBridgeModelDebug::getInstance()->warning('Unable to obtain MageBridge API Widget "customer group": ' . var_export($options, true));
         }
     }
     // Return a simple input-field by default
     return '<input type="text" name="' . $name . '" value="' . $value . '" />';
 }
예제 #14
0
 public function display($tpl = null)
 {
     //JToolBarHelper::help( 'screen.magebridge.usage' );
     $this->addMenuItems();
     $this->addCss('backend.css', 'media/com_magebridge/css/');
     if (JRequest::getCmd('view') == 'home') {
         $this->addCss('backend-home.css', 'media/com_magebridge/css/');
     }
     if (!MageBridgeHelper::isJoomla15()) {
         $this->addCss('backend-j16.css', 'media/com_magebridge/css/');
     }
     // If we detect the API is down, report it
     $bridge = MageBridgeModelBridge::getInstance();
     if ($bridge->getApiState() != null) {
         $message = null;
         switch (strtoupper($bridge->getApiState())) {
             case 'EMPTY METADATA':
                 $message = JText::_('The bridge-data arrived empty in Magento.');
                 break;
             case 'LICENSE FAILED':
                 $message = JText::sprintf('The Joomla! support-key is different from the one in Magento (%s).', $bridge->getApiExtra());
                 break;
             case 'AUTHENTICATION FAILED':
                 $message = JText::_('API authentication failed. Please check your API-user and API-key.');
                 break;
             case 'INTERNAL ERROR':
                 $help = MageBridgeHelper::getHelpText('troubleshooting');
                 $message = JText::sprintf('Bridge encountered a 500 Internal Server Error. Please check out the %s for more information.', $help);
                 break;
             case 'FAILED LOAD':
                 $help = MageBridgeHelper::getHelpText('faq-troubleshooting:api-widgets');
                 $message = JText::sprintf('Failed to load API-widgets. Please check out the %s for more information.', $help);
                 break;
             default:
                 $message = JText::_('An API-error occurred: ' . $bridge->getApiState());
                 break;
         }
         MageBridgeModelDebug::getInstance()->feedback($message);
     }
     // If debugging is enabled report it
     if (MagebridgeModelConfig::load('debug') == 1 && JRequest::getCmd('tmpl') != 'component' && in_array(JRequest::getCmd('view'), array('config', 'home'))) {
         MageBridgeModelDebug::getInstance()->feedback('Debugging is currently enabled');
     }
     parent::display($tpl);
 }
예제 #15
0
 public function fetchElement($name, $value, &$node, $control_name)
 {
     // Add the control name
     if (!empty($control_name)) {
         $name = $control_name . '[' . $name . ']';
     }
     // Only build a dropdown when the API-widgets are enabled
     if (MagebridgeModelConfig::load('api_widgets') == true) {
         // Fetch the widget data from the API
         $options = MageBridgeWidgetHelper::getWidgetData('cmspage');
         // Parse the result into an HTML form-field
         if (!empty($options) && is_array($options)) {
             foreach ($options as $index => $option) {
                 // Customize the return-value when the XML-attribute "output" is defined
                 if (is_object($node)) {
                     $output = $node->attributes('output');
                     if (!empty($output) && array_key_exists($output, $option)) {
                         $option['value'] = $option[$output];
                     }
                 }
                 // Customize the label
                 $option['label'] = $option['label'] . ' (' . $option['value'] . ') ';
                 // Add the option back to the list of options
                 $options[$index] = $option;
                 // Support the new format "[0-9]:(.*)"
                 if (preg_match('/([0-9]+)\\:/', $value) == false) {
                     $v = explode(':', $option['value']);
                     if ($v[1] == $value) {
                         $value = $option['value'];
                     }
                 }
             }
             // Return a dropdown list
             array_unshift($options, array('value' => '', 'label' => ''));
             return JHTML::_('select.genericlist', $options, $name, null, 'value', 'label', $value);
             // Fetching data from the bridge failed, so report a warning
         } else {
             MageBridgeModelDebug::getInstance()->warning('Unable to obtain MageBridge API Widget "cmspage": ' . var_export($options, true));
         }
     }
     // Return a simple input-field by default
     return '<input type="text" name="' . $name . '" value="' . $value . '" />';
 }
 public function fetchElement()
 {
     $options = null;
     if (MagebridgeModelConfig::load('api_widgets') == true) {
         $cache = JFactory::getCache('com_magebridge_admin');
         $cache->setCaching(0);
         $options = $cache->call(array('JElementStylesheets', 'getResult'));
         if (empty($options) && !is_array($options)) {
             MageBridgeModelDebug::getInstance()->trace('Unable to obtain MageBridge API Widget "stylesheets"', $options);
         }
     }
     MageBridgeTemplateHelper::load('jquery');
     JHTML::script('backend-customoptions.js', 'media/com_magebridge/js/');
     $html = '';
     $html .= JElementStylesheets::getRadioHTML();
     $html .= '<p/>';
     $html .= JElementStylesheets::getSelectHTML($options);
     return $html;
 }
예제 #17
0
 protected function getInput()
 {
     $name = $this->name;
     $fieldName = $name;
     $value = $this->value;
     // Are the API widgets enabled?
     if (MagebridgeModelConfig::load('api_widgets') == true) {
         $bridge = MageBridgeModelBridge::getInstance();
         $path = $bridge->getMageConfig('backend/path');
         if (!empty($path)) {
             $html = '<input type="text" value="' . $path . '" disabled="disabled" />';
             $html .= '<input type="hidden" name="' . $fieldName . '" value="' . $path . '" />';
             return $html;
         } else {
             MageBridgeModelDebug::getInstance()->warning('Unable to obtain MageBridge API Widget "backend"');
         }
     }
     return '<input type="text" name="' . $fieldName . '" value="' . $value . '" />';
 }
예제 #18
0
 /**
  * Display method
  *
  * @param string $tpl
  * @return null
  */
 public function display($tpl = null)
 {
     // Add CSS-code
     $this->addCss('backend.css', 'media/com_magebridge/css/');
     if (MageBridgeHelper::isJoomla25()) {
         $this->addCss('backend-j25.css', 'media/com_magebridge/css/');
     }
     if (MageBridgeHelper::isJoomla35()) {
         $this->addCss('backend-j35.css', 'media/com_magebridge/css/');
     }
     // If we detect the API is down, report it
     $bridge = MageBridgeModelBridge::getInstance();
     if ($bridge->getApiState() != null) {
         $message = null;
         switch (strtoupper($bridge->getApiState())) {
             case 'EMPTY METADATA':
                 $message = JText::_('COM_MAGEBRIDGE_VIEW_API_ERROR_EMPTY_METADATA');
                 break;
             case 'SUPPORTKEY FAILED':
                 $message = JText::sprintf('COM_MAGEBRIDGE_VIEW_API_ERROR_KEY_FAILED', $bridge->getApiExtra());
                 break;
             case 'AUTHENTICATION FAILED':
                 $message = JText::_('COM_MAGEBRIDGE_VIEW_API_ERROR_AUTHENTICATION_FAILED');
                 break;
             case 'INTERNAL ERROR':
                 $message = JText::sprintf('COM_MAGEBRIDGE_VIEW_API_ERROR_INTERNAL_ERROR', MageBridgeHelper::getHelpLink('troubleshooting'));
                 break;
             case 'FAILED LOAD':
                 $message = JText::sprintf('COM_MAGEBRIDGE_VIEW_API_ERROR_FAILED_LOAD', MageBridgeHelper::getHelpLink('faq-troubleshooting:api-widgets'));
                 break;
             default:
                 $message = JText::sprintf('COM_MAGEBRIDGE_VIEW_API_ERROR_GENERIC', $bridge->getApiState());
                 break;
         }
         MageBridgeModelDebug::getInstance()->feedback($message);
     }
     // If debugging is enabled report it
     if (MagebridgeModelConfig::load('debug') == 1 && JFactory::getApplication()->input->getCmd('tmpl') != 'component' && in_array(JFactory::getApplication()->input->getCmd('view'), array('config', 'home'))) {
         MageBridgeModelDebug::getInstance()->feedback('COM_MAGEBRIDGE_VIEW_API_DEBUGGING_ENABLED');
     }
     parent::display($tpl);
 }
예제 #19
0
 public function display($tpl = null)
 {
     // Automatically fetch items, total and pagination - and assign them to the template
     $this->fetchItems();
     // Toolbar options
     $this->loadToolbarEdit = false;
     $this->loadToolbarDelete = false;
     JToolBarHelper::custom('delete', 'delete', '', 'Truncate', false);
     JToolBarHelper::custom('refresh', 'preview', '', 'Refresh', false);
     JToolBarHelper::custom('export', 'archive', '', 'Export', false);
     // Custom filters
     $this->lists['remote_addr'] = $this->selectRemoteAddress($this->getFilter('remote_addr'));
     $this->lists['type'] = $this->selectType($this->getFilter('type'));
     $this->lists['origin'] = $this->selectOrigin($this->getFilter('origin'));
     // If debugging is enabled report it
     if ($this->countLogs() > 1000) {
         MageBridgeModelDebug::getInstance()->feedback('There are currently ' . (int) $this->countLogs() . ' log-records in the database. We recommend you delete these logs.');
     }
     parent::display($tpl);
 }
예제 #20
0
 /**
  * Method to get the HTML of this element
  *
  * @param null
  * @return string
  */
 protected function getInput()
 {
     $name = $this->name;
     $fieldName = $name;
     $value = $this->value;
     if (MagebridgeModelConfig::load('api_widgets') == true) {
         $cache = JFactory::getCache('com_magebridge.admin');
         $options = $cache->call(array('MagebridgeFormFieldScripts', 'getResult'));
         // Parse the result into an HTML form-field
         if (!empty($options) && is_array($options)) {
             $current_options = MageBridgeHelper::getDisableJs();
             $size = count($options) > 10 ? 10 : count($options);
             array_unshift($options, array('value' => '', 'label' => '- ' . JText::_('None') . ' -'));
             return JHTML::_('select.genericlist', $options, $name . '[]', 'multiple="multiple" size="' . $size . '"', 'value', 'label', $current_options);
         } else {
             MageBridgeModelDebug::getInstance()->warning('Unable to obtain MageBridge API Widget "scripts": ' . var_export($options, true));
         }
     }
     return '<input type="text" name="' . $name . '" value="' . $value . '" />';
 }
예제 #21
0
 /**
  * Display method
  *
  * @param string $tpl
  * @return null
  */
 public function display($tpl = null)
 {
     // Automatically fetch items, total and pagination - and assign them to the template
     $this->fetchItems();
     // Toolbar options
     $this->loadToolbarEdit = false;
     $this->loadToolbarDelete = false;
     JToolBarHelper::custom('delete', 'delete', '', 'COM_MAGEBRIDGE_VIEW_LOGS_TOOLBAR_TRUNCATE', false);
     JToolBarHelper::custom('refresh', 'preview', '', 'COM_MAGEBRIDGE_VIEW_LOGS_TOOLBAR_REFRESH', false);
     JToolBarHelper::custom('export', 'archive', '', 'COM_MAGEBRIDGE_VIEW_LOGS_TOOLBAR_EXPORT', false);
     // Custom filters
     $this->lists['remote_addr'] = $this->selectRemoteAddress($this->getFilter('remote_addr'));
     $this->lists['type'] = $this->selectType($this->getFilter('type'));
     $this->lists['origin'] = $this->selectOrigin($this->getFilter('origin'));
     // If debugging is enabled report it
     if ($this->countLogs() > 1000) {
         MageBridgeModelDebug::getInstance()->feedback(JText::sprintf('COM_MAGEBRIDGE_VIEW_LOGS_FLOOD_WARNING', (int) $this->countLogs()));
     }
     parent::display($tpl);
 }
예제 #22
0
 public function fetchElement($name, $value, &$node, $control_name)
 {
     // Add the control name
     if (!empty($control_name)) {
         $name = $control_name . '[' . $name . ']';
     }
     // Are the API widgets enabled?
     if (MagebridgeModelConfig::load('api_widgets') == true) {
         $bridge = MageBridgeModelBridge::getInstance();
         $path = $bridge->getMageConfig('backend/path');
         if (!empty($path)) {
             $html = '<input type="text" value="' . $path . '" disabled="disabled" />';
             $html .= '<input type="hidden" name="' . $name . '" value="' . $path . '" />';
             return $html;
         } else {
             MageBridgeModelDebug::getInstance()->warning('Unable to obtain MageBridge API Widget "backend"');
         }
     }
     return '<input type="text" name="' . $name . '" value="' . $value . '" />';
 }
예제 #23
0
 /**
  * Method to display the requested view
  */
 public function display($tpl = null)
 {
     // Determine which block to display
     $blockName = JFactory::getApplication()->input->getString('block');
     // Fetch the block
     if (!empty($blockName)) {
         // Get the register and add the block-request
         $register = MageBridgeModelRegister::getInstance();
         $register->clean();
         $register->add('block', $blockName);
         // Build the bridge
         MageBridgeModelDebug::getInstance()->notice('Building AJAX view for block "' . $blockName . '"');
         $bridge = MageBridgeModelBridge::getInstance();
         $bridge->build();
         // Query the bridge for the block
         $block = $bridge->getBlock($blockName);
         print $block;
     }
     // Close the application
     JFactory::getApplication()->close();
 }
예제 #24
0
 /**
  * Method to get the output of this element
  *
  * @param null
  * @return string
  */
 protected function getInput()
 {
     $name = $this->name;
     $fieldName = $name;
     $value = $this->value;
     $options = null;
     if (MagebridgeModelConfig::load('api_widgets') == true) {
         $cache = JFactory::getCache('com_magebridge.admin');
         $options = $cache->call(array('MagebridgeFormFieldStylesheets', 'getResult'));
         if (empty($options) && !is_array($options)) {
             MageBridgeModelDebug::getInstance()->trace('Unable to obtain MageBridge API Widget "stylesheets"', $options);
         }
     }
     MageBridgeTemplateHelper::load('jquery');
     JHTML::script('media/com_magebridge/js/backend-customoptions.js');
     $html = '';
     $html .= self::getRadioHTML();
     $html .= '<br/><br/>';
     $html .= self::getSelectHTML($options);
     return $html;
 }
예제 #25
0
 public function fetchElement($name, $value, &$node, $control_name)
 {
     if (MagebridgeModelConfig::load('api_widgets') == true) {
         $cache = JFactory::getCache('com_magebridge_admin');
         $cache->setCaching(0);
         $options = $cache->call(array('JElementScripts', 'getResult'));
         // Parse the result into an HTML form-field
         if (!empty($options) && is_array($options)) {
             $current_options = MageBridgeHelper::getDisableJs();
             array_unshift($options, array('value' => 'all', 'label' => '- ' . JText::_('All scripts') . ' -'));
             array_unshift($options, array('value' => '', 'label' => '- ' . JText::_('No scripts') . ' -'));
             $size = count($options);
             if ($size > 10) {
                 $size = 10;
             }
             return JHTML::_('select.genericlist', $options, $name . '[]', 'multiple size="' . $size . '"', 'value', 'label', $current_options);
         } else {
             MageBridgeModelDebug::getInstance()->warning('Unable to obtain MageBridge API Widget "scripts": ' . var_export($options, true));
         }
     }
     return '<input type="text" name="' . $name . '" value="' . $value . '" />';
 }
예제 #26
0
 public function fetchElement($name, $value, &$node, $control_name)
 {
     $fieldName = !empty($control_name) ? $control_name . '[' . $name . ']' : $name;
     // Are the API widgets enabled?
     if (MagebridgeModelConfig::load('api_widgets') == true) {
         $cache = JFactory::getCache('com_magebridge_admin');
         $cache->setCaching(0);
         $options = $cache->call(array('JElementStoregroup', 'getResult'));
         // Parse the result into an HTML form-field
         if (!empty($options) && is_array($options)) {
             foreach ($options as $index => $option) {
                 $option['label'] = $option['label'] . ' (' . $option['value'] . ') ';
                 $options[$index] = $option;
             }
             array_unshift($options, array('value' => '', 'label' => ''));
             return JHTML::_('select.genericlist', $options, $fieldName, null, 'value', 'label', $value);
         } else {
             MageBridgeModelDebug::getInstance()->warning('Unable to obtain MageBridge API Widget "storegroup": ' . var_export($options, true));
         }
     }
     return '<input type="text" name="' . $fieldName . '" value="' . $value . '" />';
 }
예제 #27
0
 public function fetchElement($name, $value = null, $node = null, $control_name = null, $extra = null)
 {
     // Add the control name
     if (!empty($control_name)) {
         $name = $control_name . '[' . $name . ']';
     }
     // Check whether the API widgets are enabled
     if (MagebridgeModelConfig::load('api_widgets') == true) {
         $rows = MageBridgeWidgetHelper::getWidgetData('store');
         // Parse the result into an HTML form-field
         $options = array();
         if (!empty($rows) && is_array($rows)) {
             foreach ($rows as $index => $group) {
                 if ($group['website'] != MageBridgeModelConfig::load('website')) {
                     continue;
                 }
                 $options[] = array('value' => 'g:' . $group['value'] . ':' . $group['label'], 'label' => $group['label'] . ' (' . $group['value'] . ') ');
                 if (preg_match('/^g\\:' . $group['value'] . '/', $value)) {
                     $value = 'g:' . $group['value'] . ':' . $group['label'];
                 }
                 if (!empty($group['childs'])) {
                     foreach ($group['childs'] as $child) {
                         $options[] = array('value' => 'v:' . $child['value'] . ':' . $child['label'], 'label' => '-- ' . $child['label'] . ' (' . $child['value'] . ') ');
                         if (preg_match('/^v\\:' . $child['value'] . '/', $value)) {
                             $value = 'v:' . $child['value'] . ':' . $child['label'];
                         }
                     }
                 }
             }
             array_unshift($options, array('value' => '', 'label' => '-- Select --'));
             return JHTML::_('select.genericlist', $options, $name, $extra, 'value', 'label', $value);
         } else {
             MageBridgeModelDebug::getInstance()->warning('Unable to obtain MageBridge API Widget "store": ' . var_export($options, true));
         }
     }
     return '<input type="text" name="' . $name . '" value="' . $value . '" />';
 }
예제 #28
0
 /**
  * Method to return the pending register-entries
  * 
  * @param array $data
  * @return array
  */
 public function merge($data)
 {
     // If there is no data yet, we are done pretty quickly
     if (empty($this->data)) {
         $this->data = $data;
         return true;
     }
     MageBridgeModelDebug::getInstance()->notice('Merging register (' . count($data) . ' segments)');
     // Merge the new data with the previous data
     if (!empty($data)) {
         foreach ($data as $id => $segment) {
             // Set the status to 1
             $segment['status'] = self::MAGEBRIDGE_SEGMENT_STATUS_SYNCED;
             // Insert the segment into the internal data
             $this->data[$id] = $segment;
             // Cache the block result
             if (!empty($segment['data']) && !empty($segment['type'])) {
                 // Determine per segment-type whether caching is available
                 switch ($segment['type']) {
                     case 'block':
                         if (isset($segment['meta']['allow_caching']) && $segment['meta']['allow_caching'] == 1 && isset($segment['meta']['cache_lifetime']) && $segment['meta']['cache_lifetime'] > 0) {
                             $cache = new MageBridgeModelCacheBlock($segment['name']);
                         } else {
                             $cache = null;
                         }
                         break;
                     case 'headers':
                         $cache = new MageBridgeModelCacheHeaders();
                         break;
                     case 'breadcrumbs':
                         $cache = new MageBridgeModelCacheBreadcrumbs();
                         break;
                     default:
                         $cache = null;
                         break;
                 }
                 // If there is a caching object, use it to transfer the data to cache-store
                 if (!empty($cache)) {
                     $cache->store($segment['data']);
                 }
             }
         }
     }
 }
예제 #29
0
 /**
  * Event onUserAfterSave
  * 
  * @access public
  * @param array $user
  * @param bool $isnew
  * @param bool $success
  * @param string $msg
  * @return bool
  */
 public function onUserAfterSave($user, $isnew, $success, $msg)
 {
     // Check if we can run this event or not
     if (MageBridgePluginHelper::allowEvent('onUserAfterSave') == false) {
         return;
     }
     // Get system variables
     $application = JFactory::getApplication();
     // Copy the username to the email address (if this is configured)
     if ($application->isSite() == true && $this->getParam('username_from_email') == 1 && $user['username'] != $user['email']) {
         MageBridgeModelDebug::getInstance()->notice("onUserAfterSave::bind on user " . $user['username']);
         // Load the right JUser object
         $data = array('username' => $user['email']);
         $object = new JUser();
         $object->load($user['id']);
         // Check whether user-syncing is allowed for this user
         if ($this->getUser()->allowSynchronization($object, 'save') == true) {
             // Change the record in the database
             $object->bind($data);
             $object->save();
             // Bind this new user-object into the session
             $session = JFactory::getSession();
             $session_user = $session->get('user');
             if ($session_user->id == $user['id']) {
                 $session_user->username = $user['email'];
             }
         }
     }
     // Synchronize this user-record with Magento
     if ($this->getParam('enable_usersync') == 1) {
         MageBridgeModelDebug::getInstance()->notice("onUserAfterSave::usersync on user " . $user['username']);
         // Sync this user-record with the bridge
         $this->getUser()->synchronize($user);
     }
     return true;
 }
예제 #30
0
 public static function filterContent($content)
 {
     // Allow to disable this filtering
     if (MagebridgeModelConfig::load('filter_content') == 0) {
         return $content;
     }
     // Get common variables
     $bridge = MageBridgeModelBridge::getInstance();
     // Convert all remaining Magento links to Joomla! links
     $content = str_replace($bridge->getMagentoUrl() . 'index.php/', $bridge->getJoomlaBridgeUrl(), $content);
     $content = str_replace($bridge->getMagentoUrl() . 'magebridge.php/', $bridge->getJoomlaBridgeUrl(), $content);
     // Implement a very dirty hack because PayPal converts URLs "&" to "and"
     $current = MageBridgeUrlHelper::current();
     if (strstr($current, 'paypal') && strstr($current, 'redirect')) {
         // Try to find the distorted URLs
         $matches = array();
         if (preg_match_all('/([^\\"\']+)com_magebridgeand([^\\"\']+)/', $content, $matches)) {
             foreach ($matches[0] as $match) {
                 // Replace the wrong "and" words with "&" again
                 $url = str_replace('com_magebridgeand', 'com_magebridge&', $match);
                 $url = str_replace('rootand', 'root&', $url);
                 // Replace the wrong URL with its correction
                 $content = str_replace($match, $url, $content);
             }
         }
     }
     // Replace all uenc-URLs from Magento with URLs parsed through JRoute
     $matches = array();
     $replaced = array();
     if (preg_match_all('/\\/uenc\\/([a-zA-Z0-9\\-\\_\\,]+)/', $content, $matches)) {
         foreach ($matches[1] as $match) {
             // Decode the match
             $original_url = MageBridgeEncryptionHelper::base64_decode($match);
             $url = $original_url;
             $url = MageBridgeUrlHelper::stripUrl($url);
             // Convert the non-SEF URL to a SEF URL
             if (preg_match('/^index.php\\?option=com_magebridge/', $url)) {
                 // Parse the URL but do NOT turn it into SEF because of Mage_Core_Controller_Varien_Action::_isUrlInternal()
                 $url = MageBridgeHelper::filterUrl(str_replace('/', urldecode('/'), $url), false);
                 $url = $bridge->getJoomlaBridgeSefUrl($url);
             } else {
                 if (!preg_match('/^(http|https)/', $url)) {
                     $url = $bridge->getJoomlaBridgeSefUrl($url);
                 }
                 $url = preg_replace('/\\?SID=([a-zA-Z0-9\\-\\_]{12,42})/', '', $url);
             }
             // Extra check on HTTPS
             if (JURI::getInstance()->isSSL() == true) {
                 $url = str_replace('http://', 'https://', $url);
             } else {
                 $url = str_replace('https://', 'http://', $url);
             }
             // Replace the URL in the content
             if ($original_url != $url && $original_url . '/' != $url && !in_array($match, $replaced)) {
                 MageBridgeModelDebug::getInstance()->notice('Translating uenc-URL from ' . $original_url . ' to ' . $url);
                 $base64_url = MageBridgeEncryptionHelper::base64_encode($url);
                 $content = str_replace($match, $base64_url, $content);
                 $replaced[] = $match;
             }
         }
     }
     // Match all URLs and filter them
     $matches = array();
     if (preg_match_all('/index.php\\?option=com_magebridge([^\'\\"\\<]+)([\'\\"\\<]{1})/', $content, $matches)) {
         for ($i = 0; $i < count($matches[0]); $i++) {
             $oldurl = 'index.php?option=com_magebridge' . $matches[1][$i];
             $end = $matches[2][$i];
             $newurl = MageBridgeHelper::filterUrl($oldurl);
             if (!empty($newurl)) {
                 $content = str_replace($oldurl . $end, $newurl . $end, $content);
             }
         }
     }
     // Clean-up left-overs
     $content = str_replace('?___SID=U', '', $content);
     $content = str_replace('?___SID=S', '', $content);
     $content = preg_replace('/\\?___store=([a-zA-Z0-9]+)/', '', $content);
     $content = preg_replace('/\\?SID=([a-zA-Z0-9\\-\\_]{12,42})/', '', $content);
     // Remove double-slashes
     //$basedir = preg_replace('/^([\/]?)(.*)([\/]?)$/', '\2', JURI::base(true));
     //$content = str_replace(JURI::base().$basedir, JURI::base(), $content);
     $content = str_replace(JURI::base() . '/', JURI::base(), $content);
     // Adjust wrong media-URLs
     if (JURI::getInstance()->isSSL() == true) {
         $non_https = preg_replace('/^https:/', 'http:', $bridge->getMagentoUrl());
         $https = preg_replace('/^http:/', 'https:', $bridge->getMagentoUrl());
         $content = str_replace($non_https, $https, $content);
     }
     // Adjust incorrect URLs with parameters starting with &
     if (preg_match_all('/(\'|\\")(http|https):\\/\\/([^\\&\\?\'\\"]+)\\&/', $content, $matches)) {
         foreach ($matches[0] as $index => $match) {
             $content = str_replace($matches[3][$index] . '&', $matches[3][$index] . '?', $content);
         }
     }
     return $content;
 }