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 . '" />';
 }
Example #2
0
 /**
  * Helper-method to determine if it's possible to run this event
  *
  * @param string $event
  * @param array $options
  * @return bool
  */
 public static function allowEvent($event, $options = array())
 {
     static $denied_events = array();
     // Do not run this event if the bridge itself is offline
     if (MageBridge::getBridge()->isOffline()) {
         MageBridgeModelDebug::getInstance()->notice("Plugin helper detects bridge is offline");
         return false;
     }
     // Do not run this event if the option "disable_bridge" is set to true
     if (isset($options['disable_bridge']) && $options['disable_bridge'] == true) {
         MageBridgeModelDebug::getInstance()->notice("Plugin helper detects event '{$event}' is currently disabled");
         return false;
     }
     // Do not execute additional plugin-events on the success-page (to prevent refreshing)
     $request = MageBridgeUrlHelper::getRequest();
     if (preg_match('/checkout\\/onepage\\/success/', $request)) {
         MageBridgeModelDebug::getInstance()->notice("Plugin helper detects checkout/onepage/success page");
         return false;
     }
     // Do not execute this event if we are in XML-RPC or JSON-RPC
     if (MageBridge::isApiPage() == true) {
         return false;
     }
     // Check if this event is the list of events already thrown
     if (in_array($event, $denied_events)) {
         MageBridgeModelDebug::getInstance()->notice("Plugin helper detects event '{$event}' is already run");
         return false;
     }
     MageBridgeModelDebug::getInstance()->notice("Plugin helper allows event '{$event}'");
     $denied_events[] = $event;
     return true;
 }
Example #3
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;
 }
Example #4
0
 /**
  * Method to get the meta-data
  *
  * @return array
  */
 public function getRequestData()
 {
     // Compile the meta-data
     if (empty($this->_meta_data) || !is_array($this->_meta_data)) {
         $application = JFactory::getApplication();
         $input = $application->input;
         $user = JFactory::getUser();
         $uri = JURI::getInstance();
         $session = JFactory::getSession();
         $config = JFactory::getConfig();
         $storeHelper = MageBridgeStoreHelper::getInstance();
         $bridge = MageBridgeModelBridge::getInstance();
         $app_type = $storeHelper->getAppType();
         $app_value = $storeHelper->getAppValue();
         $arguments = array('api_session' => $bridge->getApiSession(), 'api_user' => MageBridgeEncryptionHelper::encrypt(MagebridgeModelConfig::load('api_user')), 'api_key' => MageBridgeEncryptionHelper::encrypt(MagebridgeModelConfig::load('api_key')), 'api_url' => JURI::root() . 'component/magebridge/?controller=jsonrpc&task=call', 'app' => $application->getClientId(), 'app_type' => $app_type, 'app_value' => $app_value, 'storeview' => MagebridgeModelConfig::load('storeview'), 'storegroup' => MagebridgeModelConfig::load('storegroup'), 'website' => MagebridgeModelConfig::load('website'), 'customer_group' => MagebridgeModelConfig::load('customer_group'), 'joomla_url' => $bridge->getJoomlaBridgeUrl(), 'joomla_sef_url' => $bridge->getJoomlaBridgeSefUrl(), 'joomla_sef_suffix' => (int) MageBridgeUrlHelper::hasUrlSuffix(), 'joomla_user_email' => $application->isSite() && !empty($user->email) ? $user->email : null, 'joomla_current_url' => $uri->current(), 'modify_url' => MagebridgeModelConfig::load('modify_url'), 'enforce_ssl' => MagebridgeModelConfig::load('enforce_ssl'), 'has_ssl' => (int) $uri->isSSL(), 'payment_urls' => MagebridgeModelConfig::load('payment_urls'), 'enable_messages' => MagebridgeModelConfig::load('enable_messages'), 'joomla_session' => session_id(), 'joomla_conf_caching' => $config->get('caching', 60), 'joomla_conf_lifetime' => $config->get('lifetime', 60) * 60, 'magento_session' => $bridge->getMageSession(), 'magento_persistent_session' => $bridge->getMagentoPersistentSession(), 'magento_user_allowed_save_cookie' => isset($_COOKIE['user_allowed_save_cookie']) ? $_COOKIE['user_allowed_save_cookie'] : null, 'request_uri' => MageBridgeUrlHelper::getRequest(), 'request_id' => md5(JURI::current() . serialize($input->get->getArray())), 'post' => !empty($_POST) ? $_POST : null, 'http_referer' => $bridge->getHttpReferer(), 'http_host' => $uri->toString(array('host')), 'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '', 'remote_addr' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', 'supportkey' => MagebridgeModelConfig::load('supportkey'), 'debug' => (int) MageBridgeModelDebug::isDebug(), 'debug_level' => MagebridgeModelConfig::load('debug_level'), 'debug_display_errors' => MagebridgeModelConfig::load('debug_display_errors'), 'protocol' => MagebridgeModelConfig::load('protocol'), 'state' => 'initializing', 'ajax' => (int) $bridge->isAjax(), 'disable_css' => MageBridgeHelper::getDisableCss(), 'disable_js' => MageBridgeHelper::getDisableJs());
         if (MageBridgeTemplateHelper::isMobile()) {
             $arguments['theme'] = MagebridgeModelConfig::load('mobile_magento_theme');
         } else {
             $arguments['theme'] = MagebridgeModelConfig::load('magento_theme');
         }
         foreach ($arguments as $name => $value) {
             if (is_string($value)) {
                 $arguments[$name] = MageBridgeEncryptionHelper::base64_encode($value);
             }
         }
         $this->_meta_data = $arguments;
     }
     return $this->_meta_data;
 }
 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 . '" />';
 }
 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;
 }
 /**
  * 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;
 }
 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;
 }
Example #9
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);
 }
Example #10
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();
 }
Example #11
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 . '" />';
 }
 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;
 }
Example #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);
 }
 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 . '" />';
 }
 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;
 }
 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 . '" />';
 }
 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 . '" />';
 }
Example #19
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);
 }
 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);
 }
Example #21
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 . '" />';
 }
Example #22
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);
 }
 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 . '" />';
 }
Example #24
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();
 }
Example #25
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;
 }
 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 . '" />';
 }
 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 . '" />';
 }
Example #28
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 . '" />';
 }
Example #29
0
 /**
  * Helper-method to determine the current Magento request
  *
  * @return string
  */
 public static function getRequest()
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     // Always override the current request with whatever comes from the bridge
     self::setRequest(MageBridgeModelBridge::getInstance()->getSessionData('request', false));
     // If the request is not set by Magento, and if it is not set earlier in MageBridge, set it
     if (empty(self::$request)) {
         // If this is not the frontend, default to the root
         if ($app->isSite() == false) {
             $request = null;
         } else {
             if ($input->getCmd('option') != 'com_magebridge') {
                 $request = null;
             } else {
                 if (empty($request)) {
                     $request = $input->getString('request');
                 }
                 // Build a list of current variables
                 $currentVars = array('option', 'view', 'layout', 'format', 'request', 'Itemid', 'lang', 'tmpl');
                 // Add the form token to current variables
                 $currentsVars[] = JSession::getFormToken();
                 // If the request is set, filter all rubbish
                 if (!empty($request)) {
                     // Parse the current request
                     $request = str_replace('index.php', '', $request);
                     $request = str_replace('//', '/', $request);
                     $request = str_replace('\\/', '/', $request);
                     $request = preg_replace('/(SID|sid)=(U|S)/', '', $request);
                     $request = preg_replace('/^\\//', '', $request);
                     // Convert the current request into an array (example: /checkout/cart)
                     /**$request_vars = explode('/', preg_replace('/\?([*]+)/', '', $request));
                      * if (!empty($request_vars)) {
                      * foreach ($request_vars as $var) {
                      * $currentVars[] = $var;
                      * }
                      * }*/
                     // Convert the current GET-variables into an array (example: ?limit=25)
                     if (preg_match('/([^\\?]+)\\?/', $request)) {
                         $query = preg_replace('/([^\\?]+)\\?/', '', $request);
                         parse_str($query, $query_array);
                         if (!empty($query_array)) {
                             foreach ($query_array as $name => $value) {
                                 $currentVars[] = $name;
                             }
                         }
                     }
                     // Catch illegal debugging entries
                     if (preg_match('/^magebridge\\//', $request) && !preg_match('/^magebridge\\/output\\//', $request) && MageBridgeModelDebug::isDebug() == false) {
                         $request = null;
                     }
                 }
                 // Add custom GET variables
                 $get = array();
                 $getVars = $input->get->getArray();
                 if (!empty($getVars)) {
                     foreach ($getVars as $name => $value) {
                         if (in_array($name, $currentVars)) {
                             continue;
                         }
                         if (preg_match('/^quot;/', $name)) {
                             continue;
                         }
                         if (strlen($name) == 32 && $value == 1) {
                             continue;
                         }
                         $get[$name] = $value;
                     }
                 }
                 if (!empty($get)) {
                     if (strstr($request, '?')) {
                         $request .= http_build_query($get);
                     } else {
                         $request .= '?' . http_build_query($get);
                     }
                 }
             }
         }
         $request = trim($request);
         if (!empty($request)) {
             self::$request = $request;
         }
     }
     return self::$request;
 }
Example #30
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']);
                 }
             }
         }
     }
 }