mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 20:30:39 +02:00
cleanup, major JS/CSS loading issues fixed (mainly CDN related), a lot more cleanup required
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
/*
|
/*
|
||||||
* e107 website system
|
* e107 website system
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008-2011 e107 Inc (e107.org)
|
* Copyright (C) 2008-2012 e107 Inc (e107.org)
|
||||||
* Released under the terms and conditions of the
|
* Released under the terms and conditions of the
|
||||||
* GNU General Public License (http://gnu.org).
|
* GNU General Public License (http://gnu.org).
|
||||||
*
|
*
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
* $Id$
|
* $Id$
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
global $pref, $eplug_admin, $THEME_JSLIB, $THEME_CORE_JSLIB;
|
//global $pref, $eplug_admin, $THEME_JSLIB, $THEME_CORE_JSLIB;
|
||||||
|
|
||||||
class e_jsmanager
|
class e_jsmanager
|
||||||
{
|
{
|
||||||
@@ -168,6 +168,13 @@ class e_jsmanager
|
|||||||
* @var string null | prototype | jquery
|
* @var string null | prototype | jquery
|
||||||
*/
|
*/
|
||||||
protected $_dependence = null;
|
protected $_dependence = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loaded Framework Dependency
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_dependenceLoaded = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@@ -215,7 +222,8 @@ class e_jsmanager
|
|||||||
$this->setInAdmin(defset('e_ADMIN_AREA', false));
|
$this->setInAdmin(defset('e_ADMIN_AREA', false));
|
||||||
|
|
||||||
// Try to load browser cache id from core preferences
|
// Try to load browser cache id from core preferences
|
||||||
$this->setCacheId(deftrue('e_NOCACHE') ? time() : e107::getPref('e_jslib_browser_cache'));
|
//$this->setCacheId(deftrue('e_NOCACHE') ? time() : e107::getPref('e_jslib_browser_cache'));
|
||||||
|
$this->setCacheId(e107::getPref('e_jslib_browser_cache'), 0);
|
||||||
|
|
||||||
// Load stored in preferences core lib paths ASAP - FIXME - find better way to store libs - array structure and separate table row
|
// Load stored in preferences core lib paths ASAP - FIXME - find better way to store libs - array structure and separate table row
|
||||||
|
|
||||||
@@ -231,11 +239,12 @@ class e_jsmanager
|
|||||||
|
|
||||||
if(!$this->libDisabled($id,$vis))
|
if(!$this->libDisabled($id,$vis))
|
||||||
{
|
{
|
||||||
// echo "<h2>FRAMEWORK Loaded: ".$id." :: ".$vis."</h2>";
|
//echo "<h2>FRAMEWORK Loaded: ".$id." :: ".$vis."</h2>";
|
||||||
if(vartrue($this->_libraries[$id]))
|
if(vartrue($this->_libraries[$id]))
|
||||||
{
|
{
|
||||||
foreach($this->_libraries[$id] as $path)
|
foreach($this->_libraries[$id] as $path)
|
||||||
{
|
{
|
||||||
|
//echo "<h4>Loaded: ".$path." :: ".$vis."</h4>";
|
||||||
$core[$path] = $vis;
|
$core[$path] = $vis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,7 +257,7 @@ class e_jsmanager
|
|||||||
|
|
||||||
if($vis != 'auto')
|
if($vis != 'auto')
|
||||||
{
|
{
|
||||||
$this->coreLib($core);
|
$this->checkLibDependence(null, $core);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -588,8 +597,9 @@ class e_jsmanager
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return TRUE if the library is disabled. ie. prototype or jquery.
|
* Return TRUE if the library is disabled. ie. prototype or jquery.
|
||||||
|
* FIXME - remove $type & $loc
|
||||||
*/
|
*/
|
||||||
public function libDisabled($type, $loc)
|
public function libDisabled($type = null, $loc = null)
|
||||||
{
|
{
|
||||||
if($type == 'core' && ($loc == 'none'))
|
if($type == 'core' && ($loc == 'none'))
|
||||||
{
|
{
|
||||||
@@ -628,6 +638,68 @@ class e_jsmanager
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkLibDependence($rlocation, $libs = null)
|
||||||
|
{
|
||||||
|
// Load Required Library (prototype | jquery)
|
||||||
|
// called from addJs(), make isDisabled checks for smart runtime library detection
|
||||||
|
if($rlocation && $libs === null && $this->_dependence != null && isset($this->_libraries[$this->_dependence]) && !isset($this->_dependenceLoaded[$this->_dependence][$rlocation])) // load framework
|
||||||
|
{
|
||||||
|
if($this->libDisabled())
|
||||||
|
{
|
||||||
|
$this->_dependenceLoaded[$this->_dependence][$rlocation] = array();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($this->_libraries[$this->_dependence] as $inc)
|
||||||
|
{
|
||||||
|
if(strpos($inc,".css")!==false)
|
||||||
|
{
|
||||||
|
if(strpos($inc,"://")!==false) // cdn
|
||||||
|
{
|
||||||
|
$this->addJs('other_css', $inc, 'all', '<!-- AutoLoad -->');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->addJs('core_css', $inc, 'all', '<!-- AutoLoad -->');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->addJs('core', $inc, $rlocation, '<!-- AutoLoad -->');
|
||||||
|
}
|
||||||
|
$this->_dependenceLoaded[$this->_dependence][$rlocation][] = $inc;
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
// called on init time, isDisabled checks already done, just add stuff
|
||||||
|
if($rlocation === null && is_array($libs))
|
||||||
|
{
|
||||||
|
foreach ($libs as $inc => $rlocation)
|
||||||
|
{
|
||||||
|
if(isset($this->_dependenceLoaded[$this->_dependence][$rlocation]) && in_array($inc, $this->_dependenceLoaded[$this->_dependence][$rlocation]))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(strpos($inc,".css")!==false)
|
||||||
|
{
|
||||||
|
if(strpos($inc,"://")!==false) // cdn
|
||||||
|
{
|
||||||
|
$this->addJs('other_css', $inc, 'all', '<!-- AutoLoad -->');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->addJs('core_css', $inc, 'all', '<!-- AutoLoad -->');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->addJs('core', $inc, $rlocation, '<!-- AutoLoad -->');
|
||||||
|
}
|
||||||
|
$this->_dependenceLoaded[$this->_dependence][$rlocation][] = $inc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Require JS file(s). Used by corresponding public proxy methods.
|
* Require JS file(s). Used by corresponding public proxy methods.
|
||||||
@@ -660,36 +732,34 @@ class e_jsmanager
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prevent loop of death
|
||||||
// Load Required Library (prototype | jquery)
|
if($pre != '<!-- AutoLoad -->')
|
||||||
if($pre != '<!-- AutoLoad -->' && $this->_dependence != null && isset($this->_libraries[$this->_dependence])) // load framework
|
{
|
||||||
{
|
$rlocation = $runtime_location;
|
||||||
foreach($this->_libraries[$this->_dependence] as $inc)
|
if(is_numeric($runtime_location)) $rlocation = $this->isInAdmin() ? 'admin' : 'front';
|
||||||
|
|
||||||
|
$this->checkLibDependence($rlocation);
|
||||||
|
|
||||||
|
|
||||||
|
// FIXME - better performance - executed on every addJs call - BAD
|
||||||
|
//libraries handled only by checkLibDependence()
|
||||||
|
if(!is_array($file_path))
|
||||||
{
|
{
|
||||||
|
foreach ($this->_libraries as $l)
|
||||||
if(strpos($inc,".css")!==false)
|
|
||||||
{
|
{
|
||||||
if(strpos($inc,"://")!==false) // cdn
|
if(in_array($file_path, $l))
|
||||||
{
|
{
|
||||||
$this->addJs('other_css', $inc, 'all', '<!-- AutoLoad -->');
|
return $this;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->addJs('core_css', $inc, 'all', '<!-- AutoLoad -->');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->addJs('core', $inc, 'all', '<!-- AutoLoad -->');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($type == 'core' && !is_array($file_path) && substr($file_path,0,4)=='http' ) // Core using CDN.
|
// if($type == 'core' && !is_array($file_path) && substr($file_path,0,4)=='http' ) // Core using CDN.
|
||||||
{
|
// {
|
||||||
$type = 'header';
|
// $type = 'header';
|
||||||
$runtime_location = 1;
|
// $runtime_location = 1;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Possibly no longer needed.
|
// Possibly no longer needed.
|
||||||
// FIXME - this could break something after CSS support was added, move it to separate method(s), recursion by type!
|
// FIXME - this could break something after CSS support was added, move it to separate method(s), recursion by type!
|
||||||
@@ -734,7 +804,8 @@ class e_jsmanager
|
|||||||
switch($type)
|
switch($type)
|
||||||
{
|
{
|
||||||
case 'core':
|
case 'core':
|
||||||
$file_path = '{e_WEB_JS}'.trim($file_path, '/');
|
// added direct CDN support
|
||||||
|
$file_path = (strpos($file_path, 'http') !== 0 ? '{e_WEB_JS}' : '').trim($file_path, '/');
|
||||||
$registry = &$this->_e_jslib_core;
|
$registry = &$this->_e_jslib_core;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -750,7 +821,8 @@ class e_jsmanager
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'core_css': //FIXME - core CSS should point to new e_WEB/css; add one more case - js_css -> e_WEB/jslib/
|
case 'core_css': //FIXME - core CSS should point to new e_WEB/css; add one more case - js_css -> e_WEB/jslib/
|
||||||
$file_path = $runtime_location.'|{e_WEB_JS}'.trim($file_path, '/')."|{$pre}|{$post}";
|
// added direct CDN support
|
||||||
|
$file_path = $runtime_location.'|'.(strpos($file_path, 'http') !== 0 ? '{e_WEB_JS}' : '').trim($file_path, '/')."|{$pre}|{$post}";
|
||||||
if(!isset($this->_e_css['core'])) $this->_e_css['core'] = array();
|
if(!isset($this->_e_css['core'])) $this->_e_css['core'] = array();
|
||||||
$registry = &$this->_e_css['core'];
|
$registry = &$this->_e_css['core'];
|
||||||
$runtime = true;
|
$runtime = true;
|
||||||
@@ -1002,14 +1074,16 @@ class e_jsmanager
|
|||||||
$pre = varset($path[2]) ? $path[2]."\n" : '';
|
$pre = varset($path[2]) ? $path[2]."\n" : '';
|
||||||
$post = varset($path[3]) ? "\n".$path[3] : '';
|
$post = varset($path[3]) ? "\n".$path[3] : '';
|
||||||
$path = $path[1];
|
$path = $path[1];
|
||||||
|
if(strpos($path, 'http') !== 0) $path = $tp->replaceConstants($path, 'abs').'?external=1&'.$this->getCacheId();
|
||||||
|
|
||||||
echo $pre.'<link rel="stylesheet" media="'.$media.'" type="text/css" href="'.$tp->replaceConstants($path, 'abs').'?external=1&cacheid='.$this->getCacheId().'" />'.$post;
|
echo $pre.'<link rel="stylesheet" media="'.$media.'" type="text/css" href="'.$path.'" />'.$post;
|
||||||
echo "\n";
|
echo "\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
elseif($external) //true or 'js'
|
elseif($external) //true or 'js'
|
||||||
{
|
{
|
||||||
echo '<script type="text/javascript" src="'.$tp->replaceConstants($path, 'abs').'?external=1&cacheid='.$this->getCacheId().'"></script>';
|
if(strpos($path, 'http') !== 0) $path = $tp->replaceConstants($path, 'abs').'?external=1&'.$this->getCacheId();
|
||||||
|
echo '<script type="text/javascript" src="'.$path.'"></script>';
|
||||||
echo "\n";
|
echo "\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1029,16 +1103,17 @@ class e_jsmanager
|
|||||||
$pre = varset($path[2]) ? $path[2]."\n" : '';
|
$pre = varset($path[2]) ? $path[2]."\n" : '';
|
||||||
$post = varset($path[3]) ? "\n".$path[3] : '';
|
$post = varset($path[3]) ? "\n".$path[3] : '';
|
||||||
$path = $path[1];
|
$path = $path[1];
|
||||||
|
if(strpos($path, 'http') !== 0) $path = $tp->replaceConstants($path, 'abs').'?'.$this->getCacheId();
|
||||||
|
|
||||||
echo $pre.'<link rel="stylesheet" media="'.$media.'" type="text/css" href="'.$tp->replaceConstants($path, 'abs').'?'.$this->getCacheId().'" />'.$post;
|
echo $pre.'<link rel="stylesheet" media="'.$media.'" type="text/css" href="'.$path.'" />'.$post;
|
||||||
echo "\n";
|
echo "\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if($external)
|
if($external)
|
||||||
{
|
{
|
||||||
// Never use CacheID on a CDN script.
|
// Never use CacheID on a CDN script.
|
||||||
$src = (substr($path,0,4)=='http') ? $path : $tp->replaceConstants($path, 'abs').'?'.$this->getCacheId();
|
if(strpos($path, 'http') !== 0) $path = $tp->replaceConstants($path, 'abs').'?'.$this->getCacheId();
|
||||||
echo '<script type="text/javascript" src="'.$src.'"></script>';
|
echo '<script type="text/javascript" src="'.$path.'"></script>';
|
||||||
echo "\n";
|
echo "\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user