1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-18 05:09:05 +01:00

JS Manager handler - almost ready, awaiting for theme.xml & plugin.xml required additions, admin header.php synchronized with the changes, e107::getJs() proxy method added, new js related preferences - Work in progress

This commit is contained in:
secretr 2009-09-29 17:40:56 +00:00
parent e9fd4e9127
commit 88d969fab3
6 changed files with 453 additions and 124 deletions

View File

@ -12,9 +12,9 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_admin/header.php,v $ | $Source: /cvs_backup/e107_0.8/e107_admin/header.php,v $
| $Revision: 1.45 $ | $Revision: 1.46 $
| $Date: 2009-08-31 13:12:03 $ | $Date: 2009-09-29 17:40:56 $
| $Author: e107coders $ | $Author: secretr $
+---------------------------------------------------------------+ +---------------------------------------------------------------+
*/ */
@ -25,6 +25,10 @@ if(!defined('ADMIN_AREA'))
define("ADMIN_AREA", TRUE); define("ADMIN_AREA", TRUE);
} }
define("USER_AREA", FALSE); define("USER_AREA", FALSE);
// Header included notification
define('HEADER_INIT', TRUE);
$sql->db_Mark_Time('(Header Top)'); $sql->db_Mark_Time('(Header Top)');
// //
@ -214,23 +218,30 @@ else
define("e_WYSIWYG",FALSE); define("e_WYSIWYG",FALSE);
} }
// Load Javascript Libraries // [JSManager] Load JS Includes - Zone 1 - Before Library
$hash = md5(serialize(varset($pref['e_jslib'])).serialize(varset($THEME_JSLIB)).THEME.e_LANGUAGE.ADMIN).'_admin'; e107::getJs()->renderJs('header', 1);
//echo "<script type='text/javascript' src='".e_FILE_ABS."e_js.php'></script>\n"; e107::getJs()->renderJs('header_inline', 1);
// Load Javascript Library consolidation script
// TODO - option to call libraries external (admin preferences)
$hash = md5(serialize(varset($pref['e_jslib'])).THEME.e_LANGUAGE.ADMIN).'_admin'; //FIXME - hash is wrong, move this to e_jsmanager?
echo "<script type='text/javascript' src='".e_FILE_ABS."e_jslib.php?{$hash}'></script>\n"; echo "<script type='text/javascript' src='".e_FILE_ABS."e_jslib.php?{$hash}'></script>\n";
//if (strpos(e_SELF.'?'.e_QUERY, 'menus.php?configure') === FALSE) {
//echo "<script type='text/javascript' src='".e_FILE_ABS."e_ajax.php'></script>\n"; // [JSManager] Load JS Includes - Zone 2 - After Library, before CSS
//} e107::getJs()->renderJs('header', 2);
if (file_exists(THEME.'theme.js')) { echo "<script type='text/javascript' src='".THEME_ABS."theme.js'></script>\n"; } e107::getJs()->renderJs('header_inline', 2);
if (is_readable(e_FILE.'user.js') && filesize(e_FILE.'user.js')) { echo "<script type='text/javascript' src='".e_FILE_ABS."user.js'></script>\n"; }
//DEPRECATED - use e107::getJs()->headerFile('{e_PLUGIN}myplug/js/my.js', $zone = 2)
if (isset($eplug_js) && $eplug_js) { if (isset($eplug_js) && $eplug_js) {
echo "\n<!-- eplug_js -->\n"; echo "\n<!-- eplug_js -->\n";
echo "<script type='text/javascript' src='{$eplug_js}'></script>\n"; echo "<script type='text/javascript' src='{$eplug_js}'></script>\n";
} }
//FIXME - theme.js/user.js should be registered/rendered through e_jsmanager
if (file_exists(THEME.'theme.js')) { echo "<script type='text/javascript' src='".THEME_ABS."theme.js'></script>\n"; }
if (is_readable(e_FILE.'user.js') && filesize(e_FILE.'user.js')) { echo "<script type='text/javascript' src='".e_FILE_ABS."user.js'></script>\n"; }
if ((strpos(e_SELF, 'fileinspector.php') === FALSE) && getperms("0")) if ((strpos(e_SELF, 'fileinspector.php') === FALSE) && getperms("0"))
{ {
@ -264,8 +275,6 @@ if((isset($pref['enable_png_image_fix']) && $pref['enable_png_image_fix'] == tru
echo "<![endif]-->\n"; echo "<![endif]-->\n";
} }
if (function_exists('headerjs')){echo headerjs(); }
// //
// E: Send CSS // E: Send CSS
// //
@ -279,6 +288,10 @@ if (isset($eplug_css) && $eplug_css) {
} }
echo "<!-- Theme css -->\n"; echo "<!-- Theme css -->\n";
if (!isset($no_core_css) || !$no_core_css)
{
echo "<link rel='stylesheet' href='".e_FILE_ABS."e107.css' type='text/css' />\n";
}
//NEW - Iframe mod //NEW - Iframe mod
if (!defsettrue('e_IFRAME') && isset($pref['admincss']) && $pref['admincss'] && file_exists(THEME.$pref['admincss'])) if (!defsettrue('e_IFRAME') && isset($pref['admincss']) && $pref['admincss'] && file_exists(THEME.$pref['admincss']))
{ {
@ -296,12 +309,16 @@ else
$css_file = file_exists(THEME.'admin_style.css') ? THEME_ABS.'admin_style.css' : THEME_ABS.'style.css'; $css_file = file_exists(THEME.'admin_style.css') ? THEME_ABS.'admin_style.css' : THEME_ABS.'style.css';
echo "<link rel='stylesheet' href='".$css_file."' type='text/css' />\n"; echo "<link rel='stylesheet' href='".$css_file."' type='text/css' />\n";
} }
if (!isset($no_core_css) || !$no_core_css)
{
echo "<link rel='stylesheet' href='".e_FILE_ABS."e107.css' type='text/css' />\n";
}
// [JSManager] Load JS Includes - Zone 3 - After Theme CSS, before e_meta and headerjs()
e107::getJs()->renderJs('header', 3);
e107::getJs()->renderJs('header_inline', 3);
//XXX - do we still need it?
if (function_exists('headerjs')){echo headerjs(); }
// //
// F: Send Meta Tags and Icon links // F: Send Meta Tags and Icon links
// //
@ -320,6 +337,10 @@ if (vartrue($pref['e_meta_list']))
} }
} }
// [JSManager] Load JS Includes - Zone 4 - After e_meta
e107::getJs()->renderJs('header', 4);
e107::getJs()->renderJs('header_inline', 4);
// ---------- Favicon --------- // ---------- Favicon ---------
if (file_exists(THEME."favicon.ico")) { if (file_exists(THEME."favicon.ico")) {
@ -357,6 +378,7 @@ $body_onload = "";
/* /*
* Admin LAN * Admin LAN
* TODO - remove it from here
*/ */
require_once(e_HANDLER.'js_helper.php'); require_once(e_HANDLER.'js_helper.php');
echo " echo "
@ -367,8 +389,14 @@ echo "
"; ";
// [JSManager] Load JS Includes - Zone 5 - After theme_head, before e107:loaded trigger
e107::getJs()->renderJs('header', 5);
e107::getJs()->renderJs('header_inline', 5);
/* /*
* Fire Event e107:loaded * Fire Event e107:loaded
* TODO - remove it from here, should be registered to e_jsmanager
* or better - moved to core init.js(.php)
*/ */
echo "<script type='text/javascript'>\n"; echo "<script type='text/javascript'>\n";
echo "<!--\n"; echo "<!--\n";

View File

@ -55,6 +55,15 @@
<core name='displaysql'>0</core> <core name='displaysql'>0</core>
<core name='displaythemeinfo'>0</core> <core name='displaythemeinfo'>0</core>
<core name='download_email'>0</core> <core name='download_email'>0</core>
<core name='e_jslib_browser_cache'>0</core>
<core name='e_jslib_core'><![CDATA[array (
'prototype/prototype.js' => 'all',
'scriptaculous/scriptaculous.js' => 'all',
'scriptaculous/effects.js' => 'all',
'e107.js.php' => 'all',
)]]></core>
<core name='e_jslib_plugin'><![CDATA[array ()]]></core>
<core name='e_jslib_theme'><![CDATA[array ()]]></core>
<core name='email_notify'>0</core> <core name='email_notify'>0</core>
<core name='email_text'></core> <core name='email_text'></core>
<core name='emotepack'>default</core> <core name='emotepack'>default</core>
@ -214,7 +223,6 @@ City, State, Country
<core name='xup_enabled'>1</core> <core name='xup_enabled'>1</core>
<core name='xmlfeed_languagepacks'>http://www.e107.org/themeupdate.php</core> <core name='xmlfeed_languagepacks'>http://www.e107.org/themeupdate.php</core>
<core name='xmlfeed_security'>http://www.e107.org/themeupdate.php</core> <core name='xmlfeed_security'>http://www.e107.org/themeupdate.php</core>
<core name='email_item_class'>253</core>
<emote name='alien!png'>!alien</emote> <emote name='alien!png'>!alien</emote>
<emote name='amazed!png'>!amazed</emote> <emote name='amazed!png'>!amazed</emote>
<emote name='angry!png'>!grr !angry</emote> <emote name='angry!png'>!grr !angry</emote>

View File

@ -6,35 +6,42 @@
* 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).
* *
* e107 Javascript API * Javascript files consolidation script (gzip compression)
* *
* $Source: /cvs_backup/e107_0.8/e107_files/e_jslib.php,v $ * $Source: /cvs_backup/e107_0.8/e107_files/e_jslib.php,v $
* $Revision: 1.3 $ * $Revision: 1.4 $
* $Date: 2008-11-21 16:24:49 $ * $Date: 2009-09-29 17:40:56 $
* $Author: secretr $ * $Author: secretr $
* *
*/ */
/* // prevent notices/warnings to break JS source
called from header_default.php - just after e_header processing
*/
error_reporting(0); error_reporting(0);
//output cache if available before calling the api //output cache if available before calling the api
e_jslib_cache_out(); e_jslib_cache_out();
//v0.8 - we need THEME defines here (do we?) //v0.8 - we need THEME defines here (do we?) - WE DON'T
$_E107 = array('no_forceuserupdate' => 1, 'no_online' => 1,'no_menus' => 1,'no_prunetmp' => 1); //$_E107 = array('no_forceuserupdate' => 1, 'no_online' => 1, 'no_menus' => 1, 'no_prunetmp' => 1);
$_E107['minimal'] = true;
//admin or front-end call //admin or front-end call
if(strpos($_SERVER['QUERY_STRING'], '_admin') !== FALSE) if(strpos($_SERVER['QUERY_STRING'], '_admin') !== FALSE)
$eplug_admin = TRUE; {
define('ADMIN_AREA', true); //force admin area
}
else
{
define('USER_AREA', true); //force user area
}
//call jslib handler, render content
require_once("../class2.php"); require_once("../class2.php");
require_once(e_HANDLER.'jslib_handler.php'); require_once(e_HANDLER.'jslib_handler.php');
$jslib = new e_jslib(); $jslib = new e_jslib();
$jslib->core_run(); $jslib->core_run();
exit;
/** /**
* FUNCTIONS required for retrieveing cache without e107 API * FUNCTIONS required for retrieveing cache without e107 API

View File

@ -9,8 +9,8 @@
* Text processing and parsing functions * Text processing and parsing functions
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/e_parse_class.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/e_parse_class.php,v $
* $Revision: 1.64 $ * $Revision: 1.65 $
* $Date: 2009-09-29 11:32:09 $ * $Date: 2009-09-29 17:40:55 $
* $Author: secretr $ * $Author: secretr $
* *
*/ */
@ -1191,7 +1191,7 @@ class e_parse
* "" (default) = URL's get relative path e.g. ../e107_plugins/etc * "" (default) = URL's get relative path e.g. ../e107_plugins/etc
* @param mixed $all [optional] if TRUE, then when $mode is "full" or TRUE, USERID is also replaced... * @param mixed $all [optional] if TRUE, then when $mode is "full" or TRUE, USERID is also replaced...
* when $mode is "" (default), ALL other e107 constants are replaced * when $mode is "" (default), ALL other e107 constants are replaced
* @return * @return string
*/ */
function replaceConstants($text, $mode = '', $all = false) function replaceConstants($text, $mode = '', $all = false)
{ {

View File

@ -7,14 +7,14 @@
* GNU General Public License (http://gnu.org). * GNU General Public License (http://gnu.org).
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/js_manager.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/js_manager.php,v $
* $Revision: 1.1 $ * $Revision: 1.2 $
* $Date: 2009-09-28 19:17:59 $ * $Date: 2009-09-29 17:40:55 $
* $Author: secretr $ * $Author: secretr $
* *
*/ */
global $pref, $eplug_admin, $THEME_JSLIB, $THEME_CORE_JSLIB; global $pref, $eplug_admin, $THEME_JSLIB, $THEME_CORE_JSLIB;
class e_js_manager class e_jsmanager
{ {
/** /**
* Core JS library files, loaded via e_jslib.php * Core JS library files, loaded via e_jslib.php
@ -30,6 +30,13 @@ class e_js_manager
*/ */
protected $_e_jslib_plugin = array(); protected $_e_jslib_plugin = array();
/**
* Theme JS library files, loaded via e_jslib.php
*
* @var array
*/
protected $_e_jslib_theme = array();
/** /**
* JS files array - loaded in page header * JS files array - loaded in page header
* *
@ -73,11 +80,18 @@ class e_js_manager
*/ */
protected $_in_admin = false; protected $_in_admin = false;
/**
* Browser cache id
*
* @var integer
*/
protected $_cache_id = 0;
/** /**
* Singleton instance * Singleton instance
* Allow class extends - override {@link getInstance()} * Allow class extends - override {@link getInstance()}
* *
* @var e_js_manager * @var e_jsmanager
*/ */
protected static $_instance = null; protected static $_instance = null;
@ -104,54 +118,152 @@ class e_js_manager
/** /**
* Get singleton instance * Get singleton instance
* *
* @return e_js_manager * @return e_jsmanager
*/ */
public static function getInstance() public static function getInstance()
{ {
if(null == self::$_instance) if(null === self::$_instance)
{ {
self::$_instance = new self(); self::$_instance = new self();
self::$_instance->_init();
} }
return self::$_instance; return self::$_instance;
} }
/** /**
* Get and parse core preference values * Get and parse core preference values (if available)
*
* @return void * @return void
*/ */
protected function _init() protected function _init()
{ {
$core_list = e107::getPref('e_jslib_core'); // Try to auto-detect runtime location
if(!$core_list) $this->setInAdmin(defset('e_ADMIN_AREA', false));
// Try to load browser cache id from core preferences
$this->setCacheId(e107::getPref('e_jslib_browser_cache', 0));
// Load stored in preferences core lib paths ASAP
$core_libs = e107::getPref('e_jslib_core');
if(!$core_libs)
{ {
$core_list = array(); $core_libs = array();
} }
$this->coreLib($core_libs);
// Load stored in preferences plugin lib paths ASAP
$plug_libs = e107::getPref('e_jslib_plugin');
if(!$plug_libs)
{
$plug_libs = array();
}
foreach ($plug_libs as $plugname => $lib_paths)
{
$this->pluginLib($plugname, $lib_paths);
}
// Load stored in preferences theme lib paths ASAP
// TODO - decide if THEME should directly use themeLib() or
// we store paths in 'e_jslib_theme' on theme installation only (theme.xml)!
$theme_libs = e107::getPref('e_jslib_theme');
if(!$theme_libs)
{
$theme_libs = array();
}
$this->themeLib($lib_paths);
} }
/** /**
* Add Core JS library file(s) for inclusion from e_jslib routine * Add Core JS library file(s) for inclusion from e_jslib routine
* *
* @param string|array $file_path relative to e107_files/jslib/ folder or array in format path - runtime location * @param string|array $file_path relative to e107_files/jslib/ folder or array in format 'path - runtime location'
* @param string $runtime_location where should be JS used * @param string $runtime_location admin|front|all - where should be JS used
* @return e_js_manager * @return e_jsmanager
*/ */
public function coreLib($file_path, $runtime_location = 'front') protected function coreLib($file_path, $runtime_location = 'front')
{ {
$this->addJs('core', $file_path, $runtime_location); $this->addJs('core', $file_path, $runtime_location);
return $this; return $this;
} }
/** /**
* Add Core JS library file(s) for inclusion from e_jslib routine * Add Plugin JS library file(s) for inclusion from e_jslib routine
* *
* @param string $plugname * @param string $plugname
* @param string|array $file_path relative to e107_plugins/myplug/jslib/ folder or array in format path - runtime location * @param string|array $file_path relative to e107_plugins/myplug/ folder or array in format 'path - runtime location'
* @param string $runtime_location admin|front|all - where should be JS used * @param string $runtime_location admin|front|all - where should be JS used
* @return e_js_manager * @return e_jsmanager
*/ */
public function pluginLib($plugname, $file_path, $runtime_location = 'front') protected function pluginLib($plugname, $file_path, $runtime_location = 'front')
{ {
$this->addJs('plugin', array($plugname, $file_path), $runtime_location); if(is_array($file_path))
{
foreach ($file_path as $fpath => $rlocation)
{
$this->addJs('plugin', $plugname.':'.$fpath, $rlocation);
}
return $this;
}
$this->addJs('plugin', $plugname.':'.$file_path, $runtime_location);
return $this;
}
/**
* Add Theme JS library file(s) for inclusion from e_jslib routine
*
* @param string|array $file_path relative to e107_themes/current_theme/ folder or array in format 'path - runtime location'
* @param string $runtime_location admin|front|all - where should be JS used
* @return e_jsmanager
*/
protected function themeLib($file_path, $runtime_location = 'front')
{
$this->addJs('theme', $file_path, $runtime_location);
return $this;
}
/**
* Add Core JS library file(s) for inclusion in site header or site footer (in this order) if not
* already loaded by e_jslib routine. This should avoid dependency problems.
* Extremely useful for shortcodes and menus.
*
* @param string $file_path relative to e107_files/jslib/ folder
* @param integer $zone 1-5 (see header.php)
* @return e_jsmanager
*/
public function requireCoreLib($file_path, $zone = 2)
{
if(is_array($file_path))
{
foreach ($file_path as $fpath => $z)
{
$this->tryHeaderFile('{e_FILE}jslib/'.trim($fpath, '/'), $z);
}
return $this;
}
$this->tryHeaderFile('{e_FILE}jslib/'.trim($file_path, '/'), $zone);
return $this;
}
/**
* Add Plugin JS library file(s) for inclusion in site header if not
* already loaded by e_jslib routine. This should avoid dependency problems.
*
* @param string $plugname
* @param string $file_path relative to e107_plugins/myplug/ folder
* @param integer $zone 1-5 (see header.php)
* @return e_jsmanager
*/
public function requirePluginLib($plugname, $file_path, $zone = 5)
{
if(is_array($file_path))
{
foreach ($file_path as $fpath => $z)
{
$this->tryHeaderFile('{e_PLUGIN}'.$plugname.'/'.trim($fpath, '/'), $z);
}
return $this;
}
$this->tryHeaderFile('{e_PLUGIN}'.$plugname.'/'.trim($file_path, '/'), $zone);
return $this; return $this;
} }
@ -160,7 +272,7 @@ class e_js_manager
* *
* @param string|array $file_path path shortcodes usage is prefered * @param string|array $file_path path shortcodes usage is prefered
* @param integer $zone 1-5 (see header.php) * @param integer $zone 1-5 (see header.php)
* @return e_js_manager * @return e_jsmanager
*/ */
public function headerFile($file_path, $zone = 5) public function headerFile($file_path, $zone = 5)
{ {
@ -168,25 +280,45 @@ class e_js_manager
return $this; return $this;
} }
/**
* Add JS file(s) for inclusion in site header if possible, else
* use {@link footerFile()}
*
* @param string|array $file_path path shortcodes usage is prefered
* @param integer $zone 1-5 (see header.php and footer.php)
* @return e_jsmanager
*/
public function tryHeaderFile($file_path, $zone = 5)
{
if(!defined('HEADER_INIT'))
{
$this->headerFile($file_path, $zone);
return $this;
}
$this->footerFile($file_path, $zone);
return $this;
}
/** /**
* Add JS file(s) for inclusion in site footer * Add JS file(s) for inclusion in site footer
* *
* @param string|array $file_path path shortcodes usage is prefered * @param string|array $file_path path shortcodes usage is prefered
* @return e_js_manager * @param integer $priority 1-5 (see footer.php)
* @return e_jsmanager
*/ */
public function footerFile($file_path) public function footerFile($file_path, $priority = 5)
{ {
$this->addJs('footer', $file_path); $this->addJs('footer', $file_path, $priority);
return $this; return $this;
} }
/** /**
* Add JS file(s) for inclusion in site header * Add JS file(s) for inclusion in site header
* *
* @param string|array $js_content path shortcodes usage is prefered * @param string|array $js_content
* @param integer $zone 1-5 (see header.php) * @param integer $zone 1-5 (see header.php)
* @return e_js_manager * @return e_jsmanager
*/ */
public function headerInline($js_content, $zone = 5) public function headerInline($js_content, $zone = 5)
{ {
@ -194,37 +326,65 @@ class e_js_manager
return $this; return $this;
} }
/**
* Add JS file(s) for inclusion in site header if possible, else
* use {@link footerFile()}
*
* @param string $js_content
* @param integer $zone 1-5 (see header.php and footer.php)
* @return e_jsmanager
*/
public function tryHeaderInline($js_content, $zone = 5)
{
if(!defined('HEADER_INIT'))
{
$this->headerInline($js_content, $zone);
return $this;
}
$this->footerInline($js_content, $zone);
return $this;
}
/** /**
* Add JS file(s) for inclusion in site footer * Add JS file(s) for inclusion in site footer
* *
* @param string|array $js_content path shortcodes usage is prefered * @param string|array $js_content path shortcodes usage is prefered
* @return e_js_manager * @param integer $priority 1-5 (see footer.php)
* @return e_jsmanager
*/ */
public function footerInline($js_content) public function footerInline($js_content, $priority = 5)
{ {
$this->addJs('footer_inline', $js_content); $this->addJs('footer_inline', $js_content, $priority);
return $this; return $this;
} }
/** /**
* Require JS file(s). Access could be changed to private soon so don't use this * Require JS file(s). Used by corresponding public proxy methods.
* directly. Use corresponding proxy methods instead
* *
* @see requirePluginLib() * @see themeLib()
* @see requireCoreLib() * @see pluginLib()
* @see coreLib()
* @see headerFile()
* @see footerFile()
* @see headerInline()
* @see footerInline()
* @param string $type core|plugin - jslib.php, header|footer|header_inline|footer_inline - runtime * @param string $type core|plugin - jslib.php, header|footer|header_inline|footer_inline - runtime
* @param string|array $file_path * @param string|array $file_path
* @param string|integer $runtime_location admin|front|all (jslib), 0-5 (runtime inclusion) * @param string|integer $runtime_location admin|front|all (jslib), 0-5 (runtime inclusion)
* @return * @return
*/ */
public function addJs($type, $file_path, $runtime_location = '') protected function addJs($type, $file_path, $runtime_location = '')
{ {
if(empty($file_path))
{
return $this;
}
if(is_array($file_path)) if(is_array($file_path))
{ {
foreach ($file_path as $fp => $loc) foreach ($file_path as $fp => $loc)
{ {
$this->requireLib($type, $fp, $loc); $this->addJs($type, $fp, $loc);
} }
return $this; return $this;
} }
@ -239,10 +399,16 @@ class e_js_manager
break; break;
case 'plugin': case 'plugin':
$file_path = '{e_PLUGIN}jslib/'.$file_path[0].'/'.trim($file_path[1], '/'); $file_path = explode(':', $file_path);
$file_path = '{e_PLUGIN}'.$file_path[0].'/'.trim($file_path[1], '/');
$registry = &$this->_e_jslib_plugin; $registry = &$this->_e_jslib_plugin;
break; break;
case 'theme':
$file_path = '{e_THEME}'.$this->getCurrentTheme().'/'.trim($file_path, '/');
$registry = &$this->_e_jslib_theme;
break;
case 'header': case 'header':
$file_path = $tp->createConstants($file_path, 4); $file_path = $tp->createConstants($file_path, 4);
$zone = intval($runtime_location); $zone = intval($runtime_location);
@ -259,30 +425,41 @@ class e_js_manager
break; break;
case 'footer': case 'footer':
$file_path = $tp->createConstants($file_path, 4);
$registry = &$this->_runtime_footer_src;
$runtime = true;
break;
case 'header_inline':
$file_path = $tp->createConstants($file_path, 4); $file_path = $tp->createConstants($file_path, 4);
$zone = intval($runtime_location); $zone = intval($runtime_location);
if($zone > 5 || $zone < 1) if($zone > 5 || $zone < 1)
{ {
$zone = 5; $zone = 5;
} }
if(!isset($this->_runtime_header_src[$zone])) if(!isset($this->_runtime_footer[$zone]))
{ {
$this->_runtime_header_src[$zone] = array(); $this->_runtime_footer[$zone] = array();
} }
$registry = &$this->_runtime_header_src[$zone]; $registry = &$this->_runtime_footer[$zone];
$runtime = true; $runtime = true;
break; break;
case 'header_inline':
$zone = intval($runtime_location);
if($zone > 5 || $zone < 1)
{
$zone = 5;
}
//$this->_js_all[] = $file_path;
$this->_runtime_header_src[$zone][] = $file_path;
return $this;
break;
break;
case 'footer_inline': case 'footer_inline':
$file_path = $tp->createConstants($file_path, 4); $zone = intval($runtime_location);
$registry = &$this->_runtime_footer; if($zone > 5 || $zone < 1)
$runtime = true; {
$zone = 5;
}
//$this->_js_all[] = $file_path;
$this->_runtime_footer_src[$zone][] = $file_path;
return $this;
break; break;
default: default:
@ -294,6 +471,7 @@ class e_js_manager
{ {
return $this; return $this;
} }
$this->_js_all[] = $file_path; $this->_js_all[] = $file_path;
$registry[] = $file_path; $registry[] = $file_path;
@ -303,44 +481,90 @@ class e_js_manager
/** /**
* Render registered JS * Render registered JS
* *
* @param string $what core|plugin|header|footer|header_inline|footer_inline * @param string $mod core|plugin|theme|header|footer|header_inline|footer_inline
* @param integer $zone 1-5 - only needed when in 'header' and 'header_inline' render mode * @param integer $zone 1-5 - only used when in 'header','footer','header_inline' and 'footer_inline' render mod
* @return * @param boolean $external exrernal file calls, only used when NOT in 'header_inline' and 'footer_inline' render mod
* @param boolean $return
* @return string JS content - only if $return is true
*/ */
public function renderJs($what, $zone = 5) public function renderJs($mod, $zone, $external = true, $return = false)
{ {
switch($what) if($return)
{
ob_start();
}
switch($mod)
{ {
case 'core': case 'core':
$this->renderFile($this->_e_jslib_core); $this->renderFile($this->_e_jslib_core, $external, 'Core libraries');
$this->_e_jslib_core = array(); $this->_e_jslib_core = array();
break; break;
case 'plugin': case 'plugin':
$this->renderFile($this->_e_jslib_plugin); foreach($this->_e_jslib_plugin as $plugname => $paths)
{
$this->renderFile($paths, $external, $plugname.' libraries');
}
$this->_e_jslib_plugin = array(); $this->_e_jslib_plugin = array();
break; break;
case 'theme':
$this->renderFile($this->_e_jslib_theme, $external, 'Theme libraries');
$this->_e_jslib_theme = array();
break;
case 'header': case 'header':
$this->renderFile(varsettrue($this->_runtime_header[$zone], array())); $this->renderFile(varsettrue($this->_runtime_header[$zone], array()), $external, 'Header JS include - zone #'.$zone);
unset($this->_runtime_header[$zone]); unset($this->_runtime_header[$zone]);
break; break;
case 'footer': case 'footer':
$this->renderInline($this->_runtime_footer); if(true === $zone)
{
ksort($this->_runtime_footer, SORT_NUMERIC);
foreach ($this->_runtime_footer as $priority => $path_array)
{
$this->renderFile($path_array, $external, 'Footer JS include - priority #'.$priority);
}
$this->_runtime_footer = array(); $this->_runtime_footer = array();
}
else
{
$this->renderFile(varsettrue($this->_runtime_footer[$zone], array()), $external, 'Footer JS include - priority #'.$zone);
unset($this->_runtime_footer[$zone]);
}
break; break;
case 'header_inline': case 'header_inline':
$this->renderInline(varsettrue($this->_runtime_header_src[$zone], array())); $this->renderInline(varsettrue($this->_runtime_header_src[$zone], array()), 'Header JS - zone #'.$zone);
unset($this->_runtime_header_src[$zone]); unset($this->_runtime_header_src[$zone]);
break; break;
case 'footer_inline': case 'footer_inline':
$this->renderInline($this->_runtime_footer_src); if(true === $zone)
{
ksort($this->_runtime_footer_src, SORT_NUMERIC);
foreach ($this->_runtime_footer_src as $priority => $src_array)
{
$this->renderInline($src_array, 'Footer JS - priority #'.$priority);
}
$this->_runtime_footer_src = array(); $this->_runtime_footer_src = array();
}
else
{
$this->renderInline(varsettrue($this->_runtime_footer_src[$zone], array()), 'Footer JS - priority #'.$zone);
unset($this->_runtime_footer_src[$zone]);
}
break; break;
} }
if($return)
{
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
} }
/** /**
@ -348,47 +572,73 @@ class e_js_manager
* TODO - option to output <script src='$path'> * TODO - option to output <script src='$path'>
* *
* @param array $file_path_array * @param array $file_path_array
* @return * @param boolean $external if true - external file calls, else get file contents
* @param string $label added as comment if non-empty
* @return void
*/ */
public function renderFile($file_path_array) public function renderFile($file_path_array, $external = false, $label = '')
{ {
if(empty($file_path_array))
{
return '';
}
$tp = e107::getParser(); $tp = e107::getParser();
echo "\n\n"; echo "\n";
if($external && $label) //TODO - print comments only if site debug is on
{
echo "<!-- [JSManager] ".$label." -->\n";
}
foreach ($file_path_array as $path) foreach ($file_path_array as $path)
{ {
if (substr($path, - 4) == '.php') if (substr($path, - 4) == '.php')
{ {
include_once($tp->replaceConstants($text, '')); if($external)
echo "\n\n"; {
echo '<script type="text/javascript" src="'.$tp->replaceConstants($path, 'abs').'?external=1&amp;cacheid='.$this->getCacheId().'"></script>';
echo "\n";
continue;
}
include_once($tp->replaceConstants($path, ''));
echo "\n";
} }
else else
{ {
echo file_get_contents($tp->replaceConstants($text, '')); if($external)
echo "\n\n"; {
echo '<script type="text/javascript" src="'.$tp->replaceConstants($path, 'abs').'?'.$this->getCacheId().'"></script>';
echo "\n";
continue;
}
echo file_get_contents($tp->replaceConstants($path, ''));
echo "\n";
} }
} }
} }
/** /**
* Render JS source array * Render JS source array
* @param object $js_content_array *
* @return * @param array $js_content_array
* @param string $label added as comment if non-empty
* @return void
*/ */
public function renderInline($js_content_array) public function renderInline($js_content_array, $label = '')
{ {
if(empty($js_content_array)) if(empty($js_content_array))
{ {
return ''; return '';
} }
echo "\n\n"; echo "\n";
echo '<script type="text/javascript">'; if($label) //TODO - print comments only if site debug is on
foreach ($file_path_array as $js_content)
{ {
echo $js_content; echo "<!-- [JSManager] ".$label." -->\n";
echo "\n\n";
} }
echo '<script type="text/javascript">';
echo "\n//<![CDATA[\n";
echo implode("\n\n", $js_content_array);
echo "\n//]]>\n";
echo '</script>'; echo '</script>';
echo "\n\n"; echo "\n";
} }
/** /**
@ -406,7 +656,7 @@ class e_js_manager
* Set current script location * Set current script location
* *
* @param object $is true - back-end, false - front-end * @param object $is true - back-end, false - front-end
* @return e_js_manager * @return e_jsmanager
*/ */
public function setInAdmin($is) public function setInAdmin($is)
{ {
@ -424,5 +674,34 @@ class e_js_manager
return ($this->isInAdmin() ? 'admin' : 'front'); return ($this->isInAdmin() ? 'admin' : 'front');
} }
/**
* Get current theme name
*
* @return string
*/
public function getCurrentTheme()
{
return ($this->isInAdmin() ? e107::getPref('admintheme') : e107::getPref('sitetheme'));
}
/**
* Get browser cache id
*
* @return integer
*/
public function getCacheId()
{
return $this->_cache_id;
}
/**
* Set browser cache id
*
* @return e_jsmanager
*/
public function setCacheId($cacheid)
{
$this->_cache_id = $cacheid;
return $this;
}
} }

View File

@ -7,8 +7,8 @@
* GNU General Public License (http://gnu.org). * GNU General Public License (http://gnu.org).
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/jslib_handler.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/jslib_handler.php,v $
* $Revision: 1.5 $ * $Revision: 1.6 $
* $Date: 2009-09-28 19:17:58 $ * $Date: 2009-09-29 17:40:55 $
* $Author: secretr $ * $Author: secretr $
* *
*/ */
@ -17,7 +17,7 @@ global $pref, $eplug_admin, $THEME_JSLIB, $THEME_CORE_JSLIB;
class e_jslib class e_jslib
{ {
function e_jslib() function __construct()
{ {
} }
@ -36,7 +36,7 @@ class e_jslib
*/ */
function core_run() function core_run()
{ {
global $pref, $eplug_admin, $THEME_JSLIB, $THEME_CORE_JSLIB; //global $pref, $eplug_admin, $THEME_JSLIB, $THEME_CORE_JSLIB;
ob_start(); ob_start();
ob_implicit_flush(0); ob_implicit_flush(0);
@ -44,6 +44,15 @@ class e_jslib
header("Last-modified: " . gmdate("D, d M Y H:i:s",mktime(0,0,0,15,2,2004)) . " GMT"); header("Last-modified: " . gmdate("D, d M Y H:i:s",mktime(0,0,0,15,2,2004)) . " GMT");
header('Content-type: text/javascript', TRUE); header('Content-type: text/javascript', TRUE);
$e_jsmanager = e107::getJs();
$e_jsmanager->renderJs('core', null, false);
$e_jsmanager->renderJs('plugin', null, false);
$e_jsmanager->renderJs('theme', null, false);
//Output
$this->content_out();
/*
//array - uses the same format as $core_jslib //array - uses the same format as $core_jslib
if (!isset($THEME_CORE_JSLIB) || ! is_array($THEME_CORE_JSLIB)) if (!isset($THEME_CORE_JSLIB) || ! is_array($THEME_CORE_JSLIB))
$THEME_CORE_JSLIB = array(); $THEME_CORE_JSLIB = array();
@ -65,7 +74,7 @@ class e_jslib
$where_now = $eplug_admin ? 'admin' : 'front'; $where_now = $eplug_admin ? 'admin' : 'front';
//1. Core libs - prototype + scriptaculous effects //1. Core libs - prototype + scriptaculous effects
echo "/* Prototype/Scriptaculous/Core libraries */\n"; echo "// Prototype/Scriptaculous/Core libraries \n";
foreach ($core_jslib as $core_path => $where) foreach ($core_jslib as $core_path => $where)
{ {
if ($where != 'all' && $where != $where_now) if ($where != 'all' && $where != $where_now)
@ -84,9 +93,9 @@ class e_jslib
} }
//2. Plugins output - all 3-rd party libs //2. Plugins output - all 3-rd party libs
if (varset($pref['e_jslib'])) if (varsettrue($pref['e_jslib_plugin']))
{ {
foreach ($pref['e_jslib']['plugins'] as $plugin_name => $plugin_libs) foreach ($pref['e_jslib_plugin'] as $plugin_name => $plugin_libs)
{ {
if ($plugin_libs) if ($plugin_libs)
{ {
@ -98,7 +107,7 @@ class e_jslib
$lib_path = $plugin_name . '/' . trim($plugin_lib, '/'); $lib_path = $plugin_name . '/' . trim($plugin_lib, '/');
echo "/* $plugin_name libraries */\n\n"; echo "// $plugin_name libraries \n\n";
if (substr($plugin_lib, - 4) == '.php') if (substr($plugin_lib, - 4) == '.php')
{ {
@ -118,7 +127,7 @@ class e_jslib
//3. Theme libs //3. Theme libs
if (varset($THEME_JSLIB) && is_array($THEME_JSLIB)) if (varset($THEME_JSLIB) && is_array($THEME_JSLIB))
{ {
echo "/* Theme libraries */\n\n"; echo "// Theme libraries \n\n";
foreach ($THEME_JSLIB as $lib_path => $where) foreach ($THEME_JSLIB as $lib_path => $where)
{ {
if ($where != 'all' && $where != $where_now) if ($where != 'all' && $where != $where_now)
@ -136,9 +145,7 @@ class e_jslib
} }
} }
} }
*/
//Output
$this->content_out();
} }
/** /**