Exemple #1
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);
 }
Exemple #2
0
 /**
  * Helper-method to initialize YireoCommonView-based views
  *
  * @param string $name
  * @return mixed
  */
 public static function initialize($title)
 {
     // Load important variables
     $document = JFactory::getDocument();
     $view = JFactory::getApplication()->input->getCmd('view');
     // Add CSS-code
     $document->addStyleSheet(JURI::root() . 'media/com_magebridge/css/backend.css');
     $document->addStyleSheet(JURI::root() . 'media/com_magebridge/css/backend-view-' . $view . '.css');
     if (MageBridgeHelper::isJoomla25()) {
         $document->addStyleSheet(JURI::root() . 'media/com_magebridge/css/backend-j25.css');
     }
     if (MageBridgeHelper::isJoomla35()) {
         $document->addStyleSheet(JURI::root() . 'media/com_magebridge/css/backend-j35.css');
     }
     // Page title
     $title = JText::_('COM_MAGEBRIDGE_VIEW_' . strtoupper(str_replace(' ', '_', $title)));
     JToolBarHelper::title('MageBridge: ' . $title, 'logo.png');
     // Add the menu
     self::addMenuItems();
 }
 /**
  * /**
  * Method to determine which JavaScript to use and which not
  *
  * @access private
  *
  * @param null
  *
  * @return null
  */
 private function handleJavaScript()
 {
     // Get MageBridge variables
     $disableJsMootools = $this->loadConfig('disable_js_mootools');
     $disableJsFootools = $this->loadConfig('disable_js_footools');
     $disableJsFrototype = $this->loadConfig('disable_js_frototype');
     $disable_js_jquery = $this->loadConfig('disable_js_jquery');
     $disable_js_prototype = $this->loadConfig('disable_js_prototype');
     $disable_js_custom = $this->loadConfig('disable_js_custom');
     $disable_js_all = $this->loadConfig('disable_js_all');
     $magento_js = MageBridgeModelBridgeHeaders::getInstance()->getScripts();
     $uri = JURI::getInstance();
     $foo_script = JURI::root(true) . '/media/com_magebridge/js/foo.js';
     $footools_script = JURI::root(true) . '/media/com_magebridge/js/footools.min.js';
     $frototype_script = JURI::root(true) . '/media/com_magebridge/js/frototype.min.js';
     $base_url = $this->getBaseUrl();
     $base_js_url = $this->getBaseJsUrl();
     // Parse the disable_js_custom string into an array
     $disable_js_custom = explode(',', $disable_js_custom);
     foreach ($disable_js_custom as $index => $script) {
         $script = trim($script);
         if (!empty($script)) {
             $disable_js_custom[$index] = $script;
         }
     }
     // Fetch the body
     $body = JResponse::getBody();
     // Determine whether ProtoType is loaded
     $has_prototype = MageBridgeTemplateHelper::hasPrototypeJs();
     if ($has_prototype == false) {
         if (stristr($body, '/js/protoaculous') || stristr($body, '/js/protoculous') || stristr($body, '/prototype.js')) {
             $has_prototype = true;
         }
     }
     // Load the whitelist
     $whitelist = JFactory::getConfig()->get('magebridge.script.whitelist');
     if (!is_array($whitelist)) {
         $whitelist = array();
     }
     // Add some items to the whitelist
     if ($disable_js_jquery == false) {
         $whitelist[] = 'media/system/js/calendar.js';
         $whitelist[] = 'media/system/js/calendar-setup.js';
         $whitelist[] = '/com_jce/';
         $whitelist[] = '/footools.js';
         $whitelist[] = 'www.googleadservices.com';
         $whitelist[] = 'media/jui/js';
         $whitelist[] = 'protostar/js/template.js';
     }
     // Load the blacklist
     $blacklist = JFactory::getConfig()->get('magebridge.script.blacklist');
     // Only parse the body, if MageBridge has loaded the ProtoType library and only if configured
     if ($has_prototype == true && ($disable_js_all > 0 || $disableJsMootools == 1 || !empty($disable_js_custom))) {
         // Disable MooTools (and caption) and replace it with FooTools
         if ($disableJsMootools == 1 && $disableJsFootools == 0) {
             $this->console[] = 'MageBridge removed MooTools core and replaced it with FooTools';
             $footools_tag = '<script type="text/javascript" src="' . $footools_script . '"></script>';
             $body = preg_replace('/\\<script/', $footools_tag . "\n" . '<script ', $body, 1);
         }
         // Find all script tags
         preg_match_all('/\\<script([^<]+)\\>\\<\\/script\\>/', $body, $tags);
         $commented = array();
         foreach ($tags[0] as $tag) {
             // Filter the src="" attribute
             preg_match('/src=([\\"\']{1})([^\\"\']+)/', $tag, $src);
             if (is_array($src) && !empty($src[2])) {
                 $script = $src[2];
             } else {
                 continue;
             }
             // Load the whitelist
             if (!empty($whitelist) && is_array($whitelist)) {
                 $match = false;
                 foreach ($whitelist as $w) {
                     if (stristr($script, $w)) {
                         $match = true;
                         break;
                     }
                 }
                 if ($match == true) {
                     continue;
                 }
             }
             // If this looks like a jQuery script, skip it
             if (stristr($script, 'jquery') && $disable_js_jquery == 0) {
                 continue;
             }
             // If this looks like a ProtoType script, skip it
             if ((stristr($script, 'scriptaculous') || stristr($script, 'prototype')) && $disable_js_prototype == 0) {
                 continue;
             }
             // If this looks like a MageBridge script, skip it
             if (stristr($script, 'com_magebridge')) {
                 continue;
             }
             // Skip URLs that seem to belong to Magento
             if (!empty($base_url) && (strstr($script, 'http://' . $base_url) || strstr($script, 'https://' . $base_url))) {
                 continue;
             } else {
                 if (!empty($base_js_url) && (strstr($script, 'http://' . $base_js_url) || strstr($script, 'https://' . $base_js_url))) {
                     continue;
                     // Skip Magento frontend scripts
                 } else {
                     if (preg_match('/\\/skin\\/frontend\\//', $script)) {
                         continue;
                     } else {
                         // Do some more complex tests
                         $skip = false;
                         // Loop through the whitelist
                         if (!empty($magento_js)) {
                             foreach ($magento_js as $js) {
                                 if (strstr($script, $js)) {
                                     $skip = true;
                                     break;
                                 }
                             }
                         }
                         if ($skip == true) {
                             continue;
                         }
                         // Loop through the known Magento scripts
                         if (!empty($magento_js)) {
                             foreach ($magento_js as $js) {
                                 if (strstr($script, $js)) {
                                     $skip = true;
                                     break;
                                 }
                             }
                         }
                         if ($skip == true) {
                             continue;
                         }
                     }
                 }
             }
             // Decide whether to remove this script by default
             if ($disable_js_all == 1 || $disable_js_all == 3) {
                 $remove = true;
             } else {
                 $remove = false;
             }
             // Load the blacklist
             if (!empty($blacklist) && is_array($blacklist)) {
                 foreach ($blacklist as $b) {
                     if (preg_match('/' . str_replace('/', '\\/', $js) . '$/', $b)) {
                         $remove = true;
                         break;
                     }
                 }
             }
             // Scan for exceptions
             if ($disable_js_all > 1 && !empty($disable_js_custom)) {
                 foreach ($disable_js_custom as $js) {
                     if (preg_match('/' . str_replace('/', '\\/', $js) . '$/', $script)) {
                         $remove = $disable_js_all == 2 ? true : false;
                         break;
                     }
                 }
                 // Disable MooTools
             } else {
                 if ($disableJsMootools == 1) {
                     $mootools_scripts = array('media/system/js/modal.js', 'media/system/js/validate.js', 'beez_20/javascript/hide.js', 'md_stylechanger.js', 'media/com_finder/js/autocompleter.js');
                     if (MageBridgeHelper::isJoomla25()) {
                         $mootools_scripts[] = 'media/system/js/caption.js';
                     }
                     if (preg_match('/mootools/', $script)) {
                         $remove = true;
                     }
                     foreach ($mootools_scripts as $js) {
                         if (preg_match('/' . str_replace('/', '\\/', $js) . '$/', $script)) {
                             $remove = true;
                         }
                     }
                 }
             }
             // Remove this script
             if ($remove) {
                 // Decide how to remove the scripts
                 $filter = $this->getParam('filter_js', 'foo');
                 // Remove the script entirely from the page
                 if ($filter == 'remove') {
                     $body = str_replace($tag . "\n", '', $body);
                     $body = str_replace($tag, '', $body);
                     // Comment the tag
                 } else {
                     if ($filter == 'comment') {
                         if (!in_array($tag, $commented)) {
                             $commented[] = $tag;
                             $body = str_replace($tag, '<!-- MB: ' . $tag . ' -->', $body);
                         }
                         // Replace the script with the foo-script
                     } else {
                         $this->console[] = 'MageBridge removed ' . $script;
                         $body = str_replace($script, $foo_script, $body);
                     }
                 }
             }
         }
         // Log to the JavaScript Console
         if (MagebridgeModelDebug::isDebug() == true && $this->loadConfig('debug_console') == 1) {
             $console = '';
             foreach ($this->console as $c) {
                 $console .= 'console.warn("' . $c . '");';
             }
             $script = "<script type=\"text/javascript\">\n" . $console . "\n</script>";
             $body = str_replace('<head>', '<head>' . $script, $body);
         }
         // Set the body
         JResponse::setBody($body);
     } else {
         // Add FrotoType to the page
         if ($disableJsFrototype == 0) {
             $body = JResponse::getBody();
             $frototype_tag = '<script type="text/javascript" src="' . $frototype_script . '"></script>';
             $body = preg_replace('/\\<script/', $frototype_tag . "\n" . '<script ', $body, 1);
             JResponse::setBody($body);
         }
     }
 }