/** * Event onAfterDispatch * * @access public * @param null * @return null */ public function onAfterDispatch() { // Don't do anything if MageBridge is not enabled if ($this->isEnabled() == false) { return false; } // Don't do anything in other applications than the frontend if (JFactory::getApplication()->isSite() == false) { return false; } // Read template-parameters and load specific stylesheet $application = JFactory::getApplication(); // Read the template-related files $ini = JPATH_THEMES . DS . $application->getTemplate() . DS . 'params.ini'; $ini_content = @file_get_contents($ini); $xml = JPATH_THEMES . DS . $application->getTemplate() . DS . 'templateDetails.xml'; // WARP-usage of "config" file if (!empty($ini_content)) { // Create the parameters object jimport('joomla.html.parameter'); $params = new JParameter($ini_content, $xml); // Load a specific stylesheet per color $color = $params->get('colorStyle'); if (!empty($color)) { MageBridgeTemplateHelper::load('css', 'color-' . $color . '.css'); } } // Check whether ProtoType is loaded, and add some fixes if (MageBridgeTemplateHelper::hasPrototypeJs()) { $document = JFactory::getDocument(); $document->addStyleDeclaration('div.fusion-submenu-wrapper { margin-top: -12px !important; }'); } }
public function getScript($block, $element, $url = null) { // Set the default AJAX-URL if (empty($url)) { $url = self::getUrl($block); } // Load ProtoType if (MageBridgeTemplateHelper::hasPrototypeJs() == true) { $script = "Event.observe(window,'load',function(){new Ajax.Updater('{$element}','{$url}',{method:'get'});});"; // Load jQuery } else { if (JFactory::getApplication()->get('jquery') == true) { $script = "jQuery(document).ready(function(){\n" . " jQuery('#" . $element . "').load('" . $url . "');" . "});\n"; // Load MooTools (Joomla!) } else { if (MageBridgeHelper::isJoomla15()) { JHTML::_('behavior.mootools'); $script = "window.addEvent('domready', function(){\n" . " var MBajax = new Ajax( '" . $url . "', {onSuccess: function(r){\n" . " \$('" . $element . "').innerHTML = r;\n" . " }});\n" . " MBajax.request();\n" . "});\n"; // Load MooTools (Joomla! 1.6) } else { JHTML::_('behavior.mootools'); $script = "window.addEvent('domready', function(){\n" . " var MBajax = new Request({\n" . " url: '" . $url . "', \n" . " onComplete: function(r){\n" . " \$('" . $element . "').innerHTML = r;\n" . " }\n" . " }).send();\n" . "});\n"; } } } return $script; }
/** * Event onAfterDispatch * * @access public * @param null * @return null */ public function onAfterDispatch() { // Don't do anything if MageBridge is not enabled if ($this->isEnabled() == false) { return false; } // Load the application $application = JFactory::getApplication(); // Don't do anything in other applications than the frontend if ($application->isSite() == false) { return false; } // Load the blacklist settings $blacklist = JFactory::getConfig()->get('magebridge.script.blacklist'); if (empty($blacklist)) { $blacklist = array(); } $blacklist[] = '/rokbox.js'; $blacklist[] = 'gantry/js/browser-engines.js'; JFactory::getConfig()->set('magebridge.script.blacklist', $blacklist); // Load the whitelist settings $whitelist = JFactory::getConfig()->get('magebridge.script.whitelist'); if (empty($whitelist)) { $whitelist = array(); } JFactory::getConfig()->set('magebridge.script.whitelist', $whitelist); // Read the template-related files $ini = JPATH_THEMES . '/' . $application->getTemplate() . '/params.ini'; $ini_content = @file_get_contents($ini); $xml = JPATH_THEMES . '/' . $application->getTemplate() . '/templateDetails.xml'; // WARP-usage of "config" file if (!empty($ini_content)) { // Create the parameters object jimport('joomla.html.parameter'); $params = new JParameter($ini_content, $xml); // Load a specific stylesheet per color $color = $params->get('colorStyle'); if (!empty($color)) { MageBridgeTemplateHelper::load('css', 'color-' . $color . '.css'); } } // Check whether ProtoType is loaded, and add some fixes if (MageBridgeTemplateHelper::hasPrototypeJs()) { $document = JFactory::getDocument(); if ($this->getParams()->get('fix_submenu_wrapper', 1)) { $document->addStyleDeclaration('div.fusion-submenu-wrapper { margin-top: -12px !important; }'); } if ($this->getParams()->get('fix_body_zindex', 1)) { $document->addStyleDeclaration('div#rt-body-surround { z-index:0 !important; }'); } $document->addStyleDeclaration('div.style-panel-container {left: -126px;}'); } }
/** * Helper-method to return the right AJAX-script * * @param string $block * @param string $element * @param string $url * @return bool */ public static function getScript($block, $element, $url = null) { // Set the default AJAX-URL if (empty($url)) { $url = self::getUrl($block); } // Load ProtoType if (MageBridgeTemplateHelper::hasPrototypeJs() == true) { $script = "Event.observe(window,'load',function(){new Ajax.Updater('{$element}','{$url}',{method:'get'});});"; // Load jQuery } else { if (JFactory::getApplication()->get('jquery') == true) { $script = "jQuery(document).ready(function(){\n" . "\tjQuery('#" . $element . "').load('" . $url . "');" . "});\n"; // Load jQuery ourselves } else { YireoHelper::jquery(); $script = "jQuery(document).ready(function(){\n" . "\tjQuery('#" . $element . "').load('" . $url . "');" . "});\n"; } } return $script; }
public static function debug() { $prototype_loaded = MageBridgeTemplateHelper::hasPrototypeJs() ? 'Yes' : 'No'; JError::raiseNotice('notice', JText::sprintf('View: %s', JRequest::getCmd('view'))); JError::raiseNotice('notice', JText::sprintf('Page layout: %s', MageBridgeTemplateHelper::getPageLayout())); JError::raiseNotice('notice', JText::sprintf('Prototype JavaScript loaded: %s', $prototype_loaded)); }
/** * Event onAfterRender * * @access public * @param null * @return null */ public function onAfterRender() { // Don't do anything if MageBridge is not enabled if ($this->isEnabled() == false) { return false; } $disable_js_mootools = MagebridgeModelConfig::load('disable_js_mootools'); if (MageBridgeTemplateHelper::hasPrototypeJs() && $disable_js_mootools == 1) { $body = JResponse::getBody(); $body = preg_replace('/Warp.Settings(.*);/', '', $body); JResponse::setBody($body); } }
/** * /** * 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); } } }