From 892bf211e412710dc6be0df89ed703b48b512a6c Mon Sep 17 00:00:00 2001 From: SecretR Date: Wed, 16 Oct 2013 18:20:21 +0300 Subject: [PATCH] Allow IE conditions when adding JS (theme and url only at this time) --- e107_handlers/e107_class.php | 10 ++++----- e107_handlers/js_manager.php | 41 ++++++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 4b16e05cd..50b4c85b2 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -1598,7 +1598,7 @@ class e107 * @param integer $zone [optional] leave it null for default zone * @param string $dep dependence : null | prototype | jquery */ - public static function js($type, $data, $dep = null, $zone = null) + public static function js($type, $data, $dep = null, $zone = null, $pre = '', $post = '') { $jshandler = e107::getJs(); $jshandler->setDependency($dep); @@ -1618,8 +1618,8 @@ class e107 case 'theme': // data is e.g. 'jslib/mytheme.js' - if(null !== $zone) $jshandler->headerTheme($data, $zone); - else $jshandler->headerTheme($data); + if(null !== $zone) $jshandler->headerTheme($data, $zone, $pre, $post); + else $jshandler->headerTheme($data, 5, $pre, $post); break; case 'inline': @@ -1636,8 +1636,8 @@ class e107 case 'url': // data is e.g. 'http://cdn.somesite.com/some.js' - if(null !== $zone) $jshandler->headerFile($data, $zone); - else $jshandler->headerFile($data); + if(null !== $zone) $jshandler->headerFile($data, $zone, $pre, $post); + else $jshandler->headerFile($data, 5, $pre, $post); break; case 'footer': diff --git a/e107_handlers/js_manager.php b/e107_handlers/js_manager.php index ccaad9a10..800549008 100644 --- a/e107_handlers/js_manager.php +++ b/e107_handlers/js_manager.php @@ -498,9 +498,9 @@ class e_jsmanager * @param integer $zone 1-5 (see header.php) * @return e_jsmanager */ - public function headerFile($file_path, $zone = 5) + public function headerFile($file_path, $zone = 5, $pre = '', $post = '') { - $this->addJs('header', $file_path, $zone); + $this->addJs('header', $file_path, $zone, $pre, $post); return $this; } @@ -524,9 +524,9 @@ class e_jsmanager * @param integer $zone 1-5 (see header.php) * @return e_jsmanager */ - public function headerTheme($file_path, $zone = 5) + public function headerTheme($file_path, $zone = 5, $pre = '', $post = '') { - $this->headerFile(THEME.trim($file_path, '/'), $zone); + $this->headerFile(THEME.trim($file_path, '/'), $zone, $pre, $post); return $this; } @@ -850,13 +850,13 @@ class e_jsmanager case 'plugin': $file_path = explode(':', $file_path); - $file_path = '{e_PLUGIN}'.$file_path[0].'/'.trim($file_path[1], '/'); + $file_path = '{e_PLUGIN}'.$file_path[0].'/'.trim($file_path[1], '/')."|{$pre}|{$post}"; $registry = &$this->_e_jslib_plugin; break; case 'theme': - $file_path = '{e_THEME}'.$this->getCurrentTheme().'/'.trim($file_path, '/'); - echo "file-Path = ".$file_path; + $file_path = '{e_THEME}'.$this->getCurrentTheme().'/'.trim($file_path, '/')."|{$pre}|{$post}"; + //echo "file-Path = ".$file_path; $registry = &$this->_e_jslib_theme; break; @@ -884,7 +884,7 @@ class e_jsmanager break; case 'other_css': - $file_path = $runtime_location.'|'.$tp->createConstants($file_path, 'mix'); + $file_path = $runtime_location.'|'.$tp->createConstants($file_path, 'mix')."|{$pre}|{$post}"; if(!isset($this->_e_css['other'])) $this->_e_css['other'] = array(); $registry = &$this->_e_css['other']; $runtime = true; @@ -898,7 +898,7 @@ class e_jsmanager case 'header': - $file_path = $tp->createConstants($file_path, 'mix'); + $file_path = $tp->createConstants($file_path, 'mix')."|{$pre}|{$post}"; $zone = intval($runtime_location); if($zone > 5 || $zone < 1) { @@ -913,7 +913,7 @@ class e_jsmanager break; case 'footer': - $file_path = $tp->createConstants($file_path, 'mix'); + $file_path = $tp->createConstants($file_path, 'mix')."|{$pre}|{$post}"; $zone = intval($runtime_location); if($zone > 5 || $zone < 1) { @@ -1139,10 +1139,17 @@ class e_jsmanager } elseif($external) //true or 'js' { - if(strpos($path, 'http') === 0) continue; // not allowed + + $path = explode('|', $path, 3); + $pre = varset($path[1], ''); + if($pre) $pre .= "\n"; + $post = varset($path[2], ''); + if($post) $post = "\n".$post; + $path = $path[0]; + $path = $tp->replaceConstants($path, 'abs').'?external=1&'.$this->getCacheId(); - echo ''; + echo $pre.''.$post; echo "\n"; continue; } @@ -1176,6 +1183,14 @@ class e_jsmanager echo "\n"; continue; } + + $path = explode('|', $path, 3); + $pre = varset($path[1], ''); + if($pre) $pre .= "\n"; + $post = varset($path[2], ''); + if($post) $post = "\n".$post; + $path = $path[0]; + if($external) { // Never use CacheID on a CDN script, always render if it's CDN @@ -1188,7 +1203,7 @@ class e_jsmanager } $path = $tp->replaceConstants($path, 'abs').'?'.$this->getCacheId(); } - echo ''; + echo $pre.''.$post; echo "\n"; continue; }