mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 20:30:39 +02:00
JS libraries, CDN frameworks, external script loading should work now in all possible administration preference sets
This commit is contained in:
@@ -281,6 +281,12 @@ class e_jsmanager
|
|||||||
$theme_libs = array();
|
$theme_libs = array();
|
||||||
}
|
}
|
||||||
$this->themeLib($theme_libs);
|
$this->themeLib($theme_libs);
|
||||||
|
|
||||||
|
// TEST VALUES
|
||||||
|
// $this->_e_jslib_plugin[] = '{e_PLUGIN}myplug/test.js';
|
||||||
|
// $this->_e_jslib_plugin[] = 'http://somesite/myplug/test.js';
|
||||||
|
// $this->_e_jslib_theme[] = '{THEME}js/test.js';
|
||||||
|
// $this->_e_jslib_theme[] = 'http://somesite/js/test.js';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -942,8 +948,25 @@ class e_jsmanager
|
|||||||
|
|
||||||
switch($mod)
|
switch($mod)
|
||||||
{
|
{
|
||||||
|
case 'framework': // CDN frameworks - rendered before consolidation script (if enabled)
|
||||||
|
$fw = array();
|
||||||
|
foreach ($this->_libraries as $lib)
|
||||||
|
{
|
||||||
|
foreach ($lib as $path)
|
||||||
|
{
|
||||||
|
$erase = array_search($path, $this->_e_jslib_core);
|
||||||
|
if($erase !== false && strpos($path, 'http') === 0)
|
||||||
|
{
|
||||||
|
unset($this->_e_jslib_core[$erase]);
|
||||||
|
$fw[] = $path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->renderFile($fw, $external, 'CDN Framework', $mod, false);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'core': //e_jslib
|
case 'core': //e_jslib
|
||||||
$this->setLastModfied($mod, $this->renderFile($this->_e_jslib_core, $external, 'Core libraries'));
|
$this->setLastModfied($mod, $this->renderFile($this->_e_jslib_core, $external, 'Core libraries', $mod));
|
||||||
$this->_e_jslib_core = array();
|
$this->_e_jslib_core = array();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -952,37 +975,37 @@ class e_jsmanager
|
|||||||
{
|
{
|
||||||
$this->setLastModfied($mod, $this->renderFile($paths, $external, $plugname.' libraries'));
|
$this->setLastModfied($mod, $this->renderFile($paths, $external, $plugname.' libraries'));
|
||||||
}*/
|
}*/
|
||||||
$this->setLastModfied($mod, $this->renderFile($this->_e_jslib_plugin, $external, 'Plugin libraries'));
|
$this->setLastModfied($mod, $this->renderFile($this->_e_jslib_plugin, $external, 'Plugin libraries', $mod));
|
||||||
$this->_e_jslib_plugin = array();
|
$this->_e_jslib_plugin = array();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'theme': //e_jslib
|
case 'theme': //e_jslib
|
||||||
$this->setLastModfied($mod, $this->renderFile($this->_e_jslib_theme, $external, 'Theme libraries'));
|
$this->setLastModfied($mod, $this->renderFile($this->_e_jslib_theme, $external, 'Theme libraries', $mod));
|
||||||
$this->_e_jslib_theme = array();
|
$this->_e_jslib_theme = array();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'header':
|
case 'header':
|
||||||
$this->renderFile(varsettrue($this->_runtime_header[$zone], array()), $external, 'Header JS include - zone #'.$zone);
|
$this->renderFile(varsettrue($this->_runtime_header[$zone], array()), $external, 'Header JS include - zone #'.$zone, $mod);
|
||||||
unset($this->_runtime_header[$zone]);
|
unset($this->_runtime_header[$zone]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'core_css': //e_jslib
|
case 'core_css': //e_jslib
|
||||||
$this->renderFile(varset($this->_e_css['core'], array()), $external, 'Core CSS', false);
|
$this->renderFile(varset($this->_e_css['core'], array()), $external, 'Core CSS', $mod, false);
|
||||||
unset($this->_e_css['core']);
|
unset($this->_e_css['core']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'plugin_css': //e_jslib
|
case 'plugin_css': //e_jslib
|
||||||
$this->renderFile(varset($this->_e_css['plugin'], array()), $external, 'Plugin CSS', false);
|
$this->renderFile(varset($this->_e_css['plugin'], array()), $external, 'Plugin CSS', $mod, false);
|
||||||
unset($this->_e_css['plugin']);
|
unset($this->_e_css['plugin']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'theme_css': //e_jslib
|
case 'theme_css': //e_jslib
|
||||||
$this->renderFile(varset($this->_e_css['theme'], array()), $external, 'Theme CSS', false);
|
$this->renderFile(varset($this->_e_css['theme'], array()), $external, 'Theme CSS', $mod, false);
|
||||||
unset($this->_e_css['theme']);
|
unset($this->_e_css['theme']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'other_css':
|
case 'other_css':
|
||||||
$this->renderFile(varset($this->_e_css['other'], array()), $external, 'Other CSS', false);
|
$this->renderFile(varset($this->_e_css['other'], array()), $external, 'Other CSS', $mod, false);
|
||||||
unset($this->_e_css['other']);
|
unset($this->_e_css['other']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -998,13 +1021,13 @@ class e_jsmanager
|
|||||||
ksort($this->_runtime_footer, SORT_NUMERIC);
|
ksort($this->_runtime_footer, SORT_NUMERIC);
|
||||||
foreach ($this->_runtime_footer as $priority => $path_array)
|
foreach ($this->_runtime_footer as $priority => $path_array)
|
||||||
{
|
{
|
||||||
$this->renderFile($path_array, $external, 'Footer JS include - priority #'.$priority);
|
$this->renderFile($path_array, $external, 'Footer JS include - priority #'.$priority, $mod);
|
||||||
}
|
}
|
||||||
$this->_runtime_footer = array();
|
$this->_runtime_footer = array();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->renderFile(varsettrue($this->_runtime_footer[$zone], array()), $external, 'Footer JS include - priority #'.$zone);
|
$this->renderFile(varsettrue($this->_runtime_footer[$zone], array()), $external, 'Footer JS include - priority #'.$zone, $mod);
|
||||||
unset($this->_runtime_footer[$zone]);
|
unset($this->_runtime_footer[$zone]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1048,7 +1071,7 @@ class e_jsmanager
|
|||||||
* @param string $label added as comment if non-empty
|
* @param string $label added as comment if non-empty
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function renderFile($file_path_array, $external = false, $label = '', $checkModified = true)
|
public function renderFile($file_path_array, $external = false, $label = '', $mod = null, $checkModified = true)
|
||||||
{
|
{
|
||||||
if(empty($file_path_array))
|
if(empty($file_path_array))
|
||||||
{
|
{
|
||||||
@@ -1082,7 +1105,8 @@ class e_jsmanager
|
|||||||
}
|
}
|
||||||
elseif($external) //true or 'js'
|
elseif($external) //true or 'js'
|
||||||
{
|
{
|
||||||
if(strpos($path, 'http') !== 0) $path = $tp->replaceConstants($path, 'abs').'?external=1&'.$this->getCacheId();
|
if(strpos($path, 'http') == 0) continue; // not allowed
|
||||||
|
$path = $tp->replaceConstants($path, 'abs').'?external=1&'.$this->getCacheId();
|
||||||
echo '<script type="text/javascript" src="'.$path.'"></script>';
|
echo '<script type="text/javascript" src="'.$path.'"></script>';
|
||||||
echo "\n";
|
echo "\n";
|
||||||
continue;
|
continue;
|
||||||
@@ -1095,6 +1119,14 @@ class e_jsmanager
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// CDN fix, ignore URLs inside consolidation script, render as external scripts
|
||||||
|
$isExternal = false;
|
||||||
|
if(strpos($path, 'http') === 0)
|
||||||
|
{
|
||||||
|
if($external !== 'css') $isExternal = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if('css' === $external)
|
if('css' === $external)
|
||||||
{
|
{
|
||||||
$path = explode('|', $path, 4);
|
$path = explode('|', $path, 4);
|
||||||
@@ -1111,13 +1143,23 @@ class e_jsmanager
|
|||||||
}
|
}
|
||||||
if($external)
|
if($external)
|
||||||
{
|
{
|
||||||
// Never use CacheID on a CDN script.
|
// Never use CacheID on a CDN script, always render if it's CDN
|
||||||
if(strpos($path, 'http') !== 0) $path = $tp->replaceConstants($path, 'abs').'?'.$this->getCacheId();
|
if(!$isExternal)
|
||||||
|
{
|
||||||
|
// don't render non CDN libs as external script calls when script consolidation is enabled
|
||||||
|
if($mod === 'core' || $mod === 'plugin' || $mod === 'theme')
|
||||||
|
{
|
||||||
|
if(!e107::getPref('e_jslib_nocombine')) continue;
|
||||||
|
}
|
||||||
|
$path = $tp->replaceConstants($path, 'abs').'?'.$this->getCacheId();
|
||||||
|
}
|
||||||
echo '<script type="text/javascript" src="'.$path.'"></script>';
|
echo '<script type="text/javascript" src="'.$path.'"></script>';
|
||||||
echo "\n";
|
echo "\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// never try to consolidate external scripts
|
||||||
|
if($isExternal) continue;
|
||||||
$path = $tp->replaceConstants($path, '');
|
$path = $tp->replaceConstants($path, '');
|
||||||
if($checkModified) $lmodified = max($lmodified, filemtime($path));
|
if($checkModified) $lmodified = max($lmodified, filemtime($path));
|
||||||
echo file_get_contents($path);
|
echo file_get_contents($path);
|
||||||
|
@@ -52,10 +52,21 @@ class e_jslib
|
|||||||
// FIXED: option to use external sources (e.g. google) even if JS is combined (script tags for external sources)
|
// FIXED: option to use external sources (e.g. google) even if JS is combined (script tags for external sources)
|
||||||
if(!e107::getPref('e_jslib_nocombine'))
|
if(!e107::getPref('e_jslib_nocombine'))
|
||||||
{
|
{
|
||||||
|
$e_jsmanager = e107::getJs();
|
||||||
|
|
||||||
|
// render CDN frameworks
|
||||||
|
$ret .= $e_jsmanager->renderJs('framework', null, true, true);
|
||||||
|
|
||||||
$hash = md5(serialize(varset($pref['e_jslib'])).e107::getPref('e_jslib_browser_cache', 0).THEME.e_LANGUAGE.ADMIN).'_'.$where;
|
$hash = md5(serialize(varset($pref['e_jslib'])).e107::getPref('e_jslib_browser_cache', 0).THEME.e_LANGUAGE.ADMIN).'_'.$where;
|
||||||
// TODO disable cache in debug mod
|
// TODO disable cache in debug mod
|
||||||
$hash .= (e107::getPref('e_jslib_nocache')/* || deftrue('e_NOCACHE')*/ ? '_nocache' : '').(!e107::getPref('e_jslib_nobcache') || deftrue('e_NOCACHE') ? '_nobcache' : '').(e107::getPref('e_jslib_gzip') ? '' : '_nogzip');
|
$hash .= (e107::getPref('e_jslib_nocache')/* || deftrue('e_NOCACHE')*/ ? '_nocache' : '').(!e107::getPref('e_jslib_nobcache') || deftrue('e_NOCACHE') ? '_nobcache' : '').(e107::getPref('e_jslib_gzip') ? '' : '_nogzip');
|
||||||
$ret .= "<script type='text/javascript' src='".e_FILE_ABS."e_jslib.php?{$hash}'></script>\n";
|
$ret .= "<script type='text/javascript' src='".e_FILE_ABS."e_jslib.php?{$hash}'></script>\n";
|
||||||
|
|
||||||
|
// render CDN libraries asap
|
||||||
|
$ret .= $e_jsmanager->renderJs('core', null, true, true);
|
||||||
|
$ret .= $e_jsmanager->renderJs('plugin', null, true, true);
|
||||||
|
$ret .= $e_jsmanager->renderJs('theme', null, true, true);
|
||||||
|
|
||||||
if($return) return $ret;
|
if($return) return $ret;
|
||||||
echo $ret;
|
echo $ret;
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user