1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-09 09:13:25 +02:00

introducing JS Manager handler - work in progress

This commit is contained in:
secretr
2009-09-28 19:17:59 +00:00
parent 812dbfe9a9
commit 3a67014d65
5 changed files with 585 additions and 116 deletions

View File

@ -55,6 +55,13 @@
<core name='displaysql'>0</core>
<core name='displaythemeinfo'>0</core>
<core name='download_email'>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='email_notify'>0</core>
<core name='email_text'></core>
<core name='emotepack'>default</core>

View File

@ -9,8 +9,8 @@
* Text processing and parsing functions
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/e_parse_class.php,v $
* $Revision: 1.62 $
* $Date: 2009-09-12 18:20:23 $
* $Revision: 1.63 $
* $Date: 2009-09-28 19:17:58 $
* $Author: secretr $
*
*/
@ -1293,34 +1293,79 @@ class e_parse
return $matches[1];
}
/**
* Create and substitute e107 constants in passed URL
*
* @param string $url
* @param string $mode 0-folders, 1-relative, 2-absolute, 3-full (with domain), 4-absolute & relative (combination of 1,2,3)
* @return
*/
function createConstants($url, $mode=0)
{
//FIXME - create constants for absolute paths and site URL's
if($mode == 0) // folder name only.
$e107 = e107::getInstance();
switch($mode)
{
$e107 = e107::getInstance();
$tmp = array(
'{e_IMAGE}' => $e107->getFolder('images'),
'{e_PLUGIN}' => $e107->getFolder('plugins'),
'{e_FILE}' => $e107->getFolder('files'),
'{e_THEME}' => $e107->getFolder('themes'),
'{e_DOWNLOAD}' => $e107->getFolder('downloads'),
'{e_ADMIN}' => $e107->getFolder('admin'),
'{e_HANDLER}' => $e107->getFolder('handlers')
);
}
elseif($mode == 1) // relative path
{
$tmp = array(
'{e_IMAGE}' => e_IMAGE,
'{e_PLUGIN}' => e_PLUGIN,
'{e_FILE}' => e_FILE,
'{e_THEME}' => e_THEME,
'{e_DOWNLOAD}' => e_DOWNLOAD,
'{e_ADMIN}' => e_ADMIN,
'{e_HANDLER}' => e_HANDLER
);
case 0: // folder name only.
$tmp = array(
'{e_IMAGE}' => $e107->getFolder('images'),
'{e_PLUGIN}' => $e107->getFolder('plugins'),
'{e_FILE}' => $e107->getFolder('files'),
'{e_THEME}' => $e107->getFolder('themes'),
'{e_DOWNLOAD}' => $e107->getFolder('downloads'),
'{e_ADMIN}' => $e107->getFolder('admin'),
'{e_HANDLER}' => $e107->getFolder('handlers')
);
break;
case 1: // relative path only
$tmp = array(
'{e_IMAGE}' => e_IMAGE,
'{e_PLUGIN}' => e_PLUGIN,
'{e_FILE}' => e_FILE,
'{e_THEME}' => e_THEME,
'{e_DOWNLOAD}' => e_DOWNLOAD,
'{e_ADMIN}' => e_ADMIN,
'{e_HANDLER}' => e_HANDLER
);
break;
case 2: // absolute path only
$tmp = array(
'{e_IMAGE}' => e_IMAGE_ABS,
'{e_PLUGIN}' => e_PLUGIN_ABS,
'{e_FILE}' => e_FILE_ABS,
'{e_THEME}' => e_THEME_ABS,
'{e_DOWNLOAD}' => e_DOWNLOAD_ABS,
'{e_ADMIN}' => e_ADMIN_ABS,
'{e_HANDLER}' => e_HANDLER_ABS
);
break;
case 3: // full path (e.g http://domain.com/e107_images/)
$tmp = array(
'{e_IMAGE}' => SITEURL.$e107->getFolder('images'),
'{e_PLUGIN}' => SITEURL.$e107->getFolder('plugins'),
'{e_FILE}' => SITEURL.$e107->getFolder('files'),
'{e_THEME}' => SITEURL.$e107->getFolder('themes'),
'{e_DOWNLOAD}' => SITEURL.$e107->getFolder('downloads'),
'{e_ADMIN}' => SITEURL.$e107->getFolder('admin'),
'{e_HANDLER}' => SITEURL.$e107->getFolder('handlers')
);
break;
case 4: // absolute & relative paths
$url = $this->replaceConstants($url, 3);
$url = $this->replaceConstants($url, 2);
$url = $this->replaceConstants($url, 1);
return $url;
break;
default:
$tmp = array();
break;
}
foreach($tmp as $key=>$val)
{
$len = strlen($val);

View File

@ -0,0 +1,428 @@
<?php
/*
* e107 website system
*
* Copyright (c) 2001-2008 e107 Inc. (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://gnu.org).
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/js_manager.php,v $
* $Revision: 1.1 $
* $Date: 2009-09-28 19:17:59 $
* $Author: secretr $
*
*/
global $pref, $eplug_admin, $THEME_JSLIB, $THEME_CORE_JSLIB;
class e_js_manager
{
/**
* Core JS library files, loaded via e_jslib.php
*
* @var array
*/
protected $_e_jslib_core = array();
/**
* Plugin JS library files, loaded via e_jslib.php
*
* @var array
*/
protected $_e_jslib_plugin = array();
/**
* JS files array - loaded in page header
*
* @var array
*/
protected $_runtime_header = array();
/**
* JS code array - loaded in page header
* after all registered JS header files
*
* @var array
*/
protected $_runtime_header_src = array();
/**
* JS files array - loaded in page footer
*
* @var array
*/
protected $_runtime_footer = array();
/**
* JS code array - loaded in page footer
*
* @var array
*/
protected $_runtime_footer_src = array();
/**
* All registered JS files
*
* @var array
*/
protected $_js_all = array();
/**
* Runtime location
*
* @var boolean
*/
protected $_in_admin = false;
/**
* Singleton instance
* Allow class extends - override {@link getInstance()}
*
* @var e_js_manager
*/
protected static $_instance = null;
/**
* Constructor
*
* Use {@link getInstance()}, direct instantiating
* is not possible for signleton objects
*
* @return void
*/
protected function __construct()
{
}
/**
* Cloning is not allowed
*
*/
private function __clone()
{
}
/**
* Get singleton instance
*
* @return e_js_manager
*/
public static function getInstance()
{
if(null == self::$_instance)
{
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Get and parse core preference values
* @return void
*/
protected function _init()
{
$core_list = e107::getPref('e_jslib_core');
if(!$core_list)
{
$core_list = array();
}
}
/**
* 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 $runtime_location where should be JS used
* @return e_js_manager
*/
public function coreLib($file_path, $runtime_location = 'front')
{
$this->addJs('core', $file_path, $runtime_location);
return $this;
}
/**
* Add Core JS library file(s) for inclusion from e_jslib routine
*
* @param string $plugname
* @param string|array $file_path relative to e107_plugins/myplug/jslib/ folder or array in format path - runtime location
* @param string $runtime_location admin|front|all - where should be JS used
* @return e_js_manager
*/
public function pluginLib($plugname, $file_path, $runtime_location = 'front')
{
$this->addJs('plugin', array($plugname, $file_path), $runtime_location);
return $this;
}
/**
* Add JS file(s) for inclusion in site header
*
* @param string|array $file_path path shortcodes usage is prefered
* @param integer $zone 1-5 (see header.php)
* @return e_js_manager
*/
public function headerFile($file_path, $zone = 5)
{
$this->addJs('header', $file_path, $zone);
return $this;
}
/**
* Add JS file(s) for inclusion in site footer
*
* @param string|array $file_path path shortcodes usage is prefered
* @return e_js_manager
*/
public function footerFile($file_path)
{
$this->addJs('footer', $file_path);
return $this;
}
/**
* Add JS file(s) for inclusion in site header
*
* @param string|array $js_content path shortcodes usage is prefered
* @param integer $zone 1-5 (see header.php)
* @return e_js_manager
*/
public function headerInline($js_content, $zone = 5)
{
$this->addJs('header_inline', $js_content, $zone);
return $this;
}
/**
* Add JS file(s) for inclusion in site footer
*
* @param string|array $js_content path shortcodes usage is prefered
* @return e_js_manager
*/
public function footerInline($js_content)
{
$this->addJs('footer_inline', $js_content);
return $this;
}
/**
* Require JS file(s). Access could be changed to private soon so don't use this
* directly. Use corresponding proxy methods instead
*
* @see requirePluginLib()
* @see requireCoreLib()
* @param string $type core|plugin - jslib.php, header|footer|header_inline|footer_inline - runtime
* @param string|array $file_path
* @param string|integer $runtime_location admin|front|all (jslib), 0-5 (runtime inclusion)
* @return
*/
public function addJs($type, $file_path, $runtime_location = '')
{
if(is_array($file_path))
{
foreach ($file_path as $fp => $loc)
{
$this->requireLib($type, $fp, $loc);
}
return $this;
}
$tp = e107::getParser();
$runtime = false;
switch($type)
{
case 'core':
$file_path = '{e_FILE}jslib/'.trim($file_path, '/');
$registry = &$this->_e_jslib_core;
break;
case 'plugin':
$file_path = '{e_PLUGIN}jslib/'.$file_path[0].'/'.trim($file_path[1], '/');
$registry = &$this->_e_jslib_plugin;
break;
case 'header':
$file_path = $tp->createConstants($file_path, 4);
$zone = intval($runtime_location);
if($zone > 5 || $zone < 1)
{
$zone = 5;
}
if(!isset($this->_runtime_header[$zone]))
{
$this->_runtime_header[$zone] = array();
}
$registry = &$this->_runtime_header[$zone];
$runtime = true;
break;
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);
$zone = intval($runtime_location);
if($zone > 5 || $zone < 1)
{
$zone = 5;
}
if(!isset($this->_runtime_header_src[$zone]))
{
$this->_runtime_header_src[$zone] = array();
}
$registry = &$this->_runtime_header_src[$zone];
$runtime = true;
break;
case 'footer_inline':
$file_path = $tp->createConstants($file_path, 4);
$registry = &$this->_runtime_footer;
$runtime = true;
break;
default:
return $this;
break;
}
if(in_array($file_path, $this->_js_all) || (!$runtime && $runtime_location != 'all' && $runtime_location != $this->getCurrentLocation()))
{
return $this;
}
$this->_js_all[] = $file_path;
$registry[] = $file_path;
return $this;
}
/**
* Render registered JS
*
* @param string $what core|plugin|header|footer|header_inline|footer_inline
* @param integer $zone 1-5 - only needed when in 'header' and 'header_inline' render mode
* @return
*/
public function renderJs($what, $zone = 5)
{
switch($what)
{
case 'core':
$this->renderFile($this->_e_jslib_core);
$this->_e_jslib_core = array();
break;
case 'plugin':
$this->renderFile($this->_e_jslib_plugin);
$this->_e_jslib_plugin = array();
break;
case 'header':
$this->renderFile(varsettrue($this->_runtime_header[$zone], array()));
unset($this->_runtime_header[$zone]);
break;
case 'footer':
$this->renderInline($this->_runtime_footer);
$this->_runtime_footer = array();
break;
case 'header_inline':
$this->renderInline(varsettrue($this->_runtime_header_src[$zone], array()));
unset($this->_runtime_header_src[$zone]);
break;
case 'footer_inline':
$this->renderInline($this->_runtime_footer_src);
$this->_runtime_footer_src = array();
break;
}
}
/**
* Render JS file array
* TODO - option to output <script src='$path'>
*
* @param array $file_path_array
* @return
*/
public function renderFile($file_path_array)
{
$tp = e107::getParser();
echo "\n\n";
foreach ($file_path_array as $path)
{
if (substr($path, - 4) == '.php')
{
include_once($tp->replaceConstants($text, ''));
echo "\n\n";
}
else
{
echo file_get_contents($tp->replaceConstants($text, ''));
echo "\n\n";
}
}
}
/**
* Render JS source array
* @param object $js_content_array
* @return
*/
public function renderInline($js_content_array)
{
if(empty($js_content_array))
{
return '';
}
echo "\n\n";
echo '<script type="text/javascript">';
foreach ($file_path_array as $js_content)
{
echo $js_content;
echo "\n\n";
}
echo '</script>';
echo "\n\n";
}
/**
* Returns true if currently running in
* administration area.
*
* @return boolean
*/
public function isInAdmin()
{
return $this->_in_admin;
}
/**
* Set current script location
*
* @param object $is true - back-end, false - front-end
* @return e_js_manager
*/
public function setInAdmin($is)
{
$this->_in_admin = (boolean) $is;
return $this;
}
/**
* Get current location as a string (admin|front)
*
* @return string
*/
public function getCurrentLocation()
{
return ($this->isInAdmin() ? 'admin' : 'front');
}
}

View File

@ -7,8 +7,8 @@
* GNU General Public License (http://gnu.org).
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/jslib_handler.php,v $
* $Revision: 1.4 $
* $Date: 2008-11-21 16:24:48 $
* $Revision: 1.5 $
* $Date: 2009-09-28 19:17:58 $
* $Author: secretr $
*
*/
@ -45,11 +45,11 @@ class e_jslib
header('Content-type: text/javascript', TRUE);
//array - uses the same format as $core_jslib
if (! varset($THEME_CORE_JSLIB) || ! is_array($THEME_CORE_JSLIB))
if (!isset($THEME_CORE_JSLIB) || ! is_array($THEME_CORE_JSLIB))
$THEME_CORE_JSLIB = array();
//array - uses the same format as $core_jslib
if (! varset($THEME_JSLIB) || ! is_array($THEME_JSLIB))
if (!isset($THEME_JSLIB) || ! is_array($THEME_JSLIB))
$THEME_JSLIB = array();
//available values - admin,front,all,none
@ -61,7 +61,7 @@ class e_jslib
//'jslib/core/decorate.js' => 'all'
);
$core_jslib = array_merge($core_jslib, $THEME_CORE_JSLIB, varsettrue($pref['e_jslib']['core'], array()));
$core_jslib = array_merge($core_jslib, $THEME_CORE_JSLIB, varsettrue($pref['e_jslib_core'], array()));
$where_now = $eplug_admin ? 'admin' : 'front';
//1. Core libs - prototype + scriptaculous effects

147
index.php
View File

@ -1,113 +1,102 @@
<?php
/*
+ ----------------------------------------------------------------------------+
| e107 website system
|
| Copyright (C) 2001-2009 e107 Inc
| http://e107.org
|
|
| Released under the terms and conditions of the
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/index.php,v $
| $Revision: 1.6 $
| $Date: 2009-07-14 05:31:57 $
| $Author: e107coders $
* e107 website system
*
* Copyright (C) 2001-2008 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* News frontend
*
* $Source: /cvs_backup/e107_0.8/index.php,v $
* $Revision: 1.7 $
* $Date: 2009-09-28 19:17:59 $
* $Author: secretr $
*/
Mods for prioritised system
+----------------------------------------------------------------------------+
*/
require_once('class2.php');
require_once ('class2.php');
if (file_exists('index_include.php'))
{
include('index_include.php');
include ('index_include.php');
}
$query = (e_QUERY && e_QUERY != '' && !$_GET['elan']) ? '?'.e_QUERY : '';
$location = '';
if ($pref['membersonly_enabled'] && !USER)
{
header('location: '.e_LOGIN);
exit;
header('location: '.e_LOGIN);
exit;
}
$class_list = explode(',',USERCLASS_LIST);
$class_list = explode(',', USERCLASS_LIST);
if (isset($pref['frontpage']['all']) && $pref['frontpage']['all'])
{ // 0.7 method
$location = ((strpos($pref['frontpage']['all'], 'http') === FALSE) ? e_BASE : '').$pref['frontpage']['all'].$query;
{ // 0.7 method
$location = ((strpos($pref['frontpage']['all'], 'http') === FALSE) ? e_BASE : '').$pref['frontpage']['all'].$query;
}
else
{ // This is the 'new' method - assumes $pref['frontpage'] is an ordered list of rules
foreach ($pref['frontpage'] as $fk=>$fp)
{
if (in_array($fk,$class_list))
{ // This is the 'new' method - assumes $pref['frontpage'] is an ordered list of rules
foreach ($pref['frontpage'] as $fk=>$fp)
{
// Debateable whether we should append $query - we may be redirecting to a custom page, for example
if (strpos($fp,'{') !== FALSE)
if (in_array($fk, $class_list))
{
$location = $tp->replaceConstants($fp).$query;
// Debateable whether we should append $query - we may be redirecting to a custom page, for example
if (strpos($fp, '{') !== FALSE)
{
$location = $tp->replaceConstants($fp).$query;
}
else
{
$location = ((strpos($fp, 'http') === FALSE) ? e_BASE : '').$fp.$query;
}
break;
}
else
{
$location = ((strpos($fp, 'http') === FALSE) ? e_BASE : '').$fp.$query;
}
break;
}
}
}
if (!$location)
{ // Try and use the 'old' method (this bit can go later)
if (ADMIN)
{
$location = ((strpos($pref['frontpage'][e_UC_ADMIN], 'http') === FALSE) ? e_BASE : '').$pref['frontpage'][e_UC_ADMIN].$query;
}
elseif (USER)
{ // This is the key bit - what to do for a 'normal' logged in user
// We have USERCLASS_LIST - comma separated. Also e_CLASS_REGEXP
foreach ($class_list as $fp_class)
{ // Try and use the 'old' method (this bit can go later)
if (ADMIN)
{
$inclass = false;
if (!$inclass && check_class($fp_class['userclass_id']))
{
$location = ((strpos($pref['frontpage'][$fp_class['userclass_id']], 'http') === FALSE) ? e_BASE : '').$pref['frontpage'][$fp_class['userclass_id']].$query;
$inclass = true;
}
}
$location = $location ? $location : ((strpos($pref['frontpage'][e_UC_MEMBER], 'http') === FALSE) ? e_BASE : '').$pref['frontpage'][e_UC_MEMBER].$query;
}
else
{
$location = ((strpos($pref['frontpage'][e_UC_GUEST], 'http') === FALSE) ? e_BASE : '').$pref['frontpage'][e_UC_GUEST].$query;
}
$location = ((strpos($pref['frontpage'][e_UC_ADMIN], 'http') === FALSE) ? e_BASE : '').$pref['frontpage'][e_UC_ADMIN].$query;
}
elseif (USER)
{ // This is the key bit - what to do for a 'normal' logged in user
// We have USERCLASS_LIST - comma separated. Also e_CLASS_REGEXP
foreach ($class_list as $fp_class)
{
$inclass = false;
if (!$inclass && check_class($fp_class['userclass_id']))
{
$location = ((strpos($pref['frontpage'][$fp_class['userclass_id']], 'http') === FALSE) ? e_BASE : '').$pref['frontpage'][$fp_class['userclass_id']].$query;
$inclass = true;
}
}
$location = $location ? $location : ((strpos($pref['frontpage'][e_UC_MEMBER], 'http') === FALSE) ? e_BASE : '').$pref['frontpage'][e_UC_MEMBER].$query;
}
else
{
$location = ((strpos($pref['frontpage'][e_UC_GUEST], 'http') === FALSE) ? e_BASE : '').$pref['frontpage'][e_UC_GUEST].$query;
}
}
if (!trim($location)) $location = 'news.php';
if (!trim($location))
$location = 'news.php';
list($page,$str) = explode("?",$location."?"); // required to prevent infinite looping when queries are used on index.php.
if($page == "index.php") // Welcome Message is the front-page.
{
require_once(HEADERF);
require_once(FOOTERF);
exit;
}
else
{ // redirect to different frontpage.
list($page, $str) = explode("?", $location."?"); // required to prevent infinite looping when queries are used on index.php.
if ($page == "index.php") // Welcome Message is the front-page.
{
require_once (HEADERF);
require_once (FOOTERF);
exit;
}
else
{ // redirect to different frontpage.
header("Location: {$location}");
}
exit();
}
exit();
?>