1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 03:40:37 +02:00

__autoload - plugin and core batch auto-detection added, still no support for plugins e_shortcode.php (see comments)

This commit is contained in:
secretr
2010-02-03 11:08:36 +00:00
parent 9a8e027287
commit a4c80b99e2
2 changed files with 53 additions and 17 deletions

View File

@@ -9,9 +9,9 @@
* General purpose file * General purpose file
* *
* $Source: /cvs_backup/e107_0.8/class2.php,v $ * $Source: /cvs_backup/e107_0.8/class2.php,v $
* $Revision: 1.175 $ * $Revision: 1.176 $
* $Date: 2010-01-09 20:32:51 $ * $Date: 2010-02-03 11:08:36 $
* $Author: e107steved $ * $Author: secretr $
* *
*/ */
// //
@@ -2107,10 +2107,20 @@ function plugInstalled($plugname)
* { * {
* *
* } * }
*
* // __autoload() will look in e_PLUGIN.'myplug/shortcodes/my_shortcodes.php for this class
* // e_admin_ui is core handler, so it'll be autoloaded as well
* class plugin_myplug_my_shortcodes extends e_admin_ui
* {
*
* }
* </code> * </code>
* TODO - use spl_autoload[_*] for core autoloading some day (PHP5 > 5.1.2) * TODO - use spl_autoload[_*] for core autoloading some day (PHP5 > 5.1.2)
* TODO - at this time we could create e107 version of spl_autoload_register - e_event->register/trigger('autoload') * TODO - at this time we could create e107 version of spl_autoload_register - e_event->register/trigger('autoload')
* *
* @todo plugname/e_shortcode.php auto-detection (hard, near impossible at this time) - we need 'plugin_' prefix to
* distinguish them from the core batches
*
* @param string $className * @param string $className
* @return void * @return void
*/ */
@@ -2122,27 +2132,53 @@ function __autoload($className)
return; return;
} }
$tmp = explode('_', $className); $tmp = explode('_', $className);
$filename = '';
switch($tmp[0]) switch($tmp[0])
{ {
case 'plugin': case 'plugin': // plugin handlers/shortcode batches
array_shift($tmp); array_shift($tmp); // remove 'plugin'
// folder 'includes' is not part of the class name $end = array_pop($tmp); // check for 'shortcodes' end phrase
if (!isset($tmp[0]) || !$tmp[0]) return; // In case we get an empty class part
$tmp[0] = $tmp[0].'/includes'; if (!isset($tmp[0]) || !$tmp[0]) return; // In case we get an empty class part
// Currently only batches inside shortcodes/ folder are auto-detected,
// read the todo for e_shortcode.php related problems
if('shortcodes' == $end)
{
$filename = e_PLUGIN.$tmp[0].'/shortcodes/'; // plugname/shortcodes/
unset($tmp[0]);
$filename .= implode('_', $tmp).'_shortcodes.php'; // my_shortcodes.php
break;
}
if($end)
{
$tmp[] = $end; // not a shortcode batch - append the end phrase again
}
// Handler check
$tmp[0] .= '/includes'; //folder 'includes' is not part of the class name
$filename = e_PLUGIN.implode('/', $tmp).'.php'; $filename = e_PLUGIN.implode('/', $tmp).'.php';
//TODO add debug screen Auto-loaded classes - ['plugin: '.$filename.' - '.$className]; //TODO add debug screen Auto-loaded classes - ['plugin: '.$filename.' - '.$className];
break; break;
default: //core libraries default: //core libraries, core shortcode batches
// core SC batch check
$end = array_pop($tmp);
if('shortcodes' == $end)
{
$filename = e_FILE.'shortcode/batch/'.$className.'.php'; // core shortcode batch
break;
}
$filename = e107::getHandlerPath($className, true); $filename = e107::getHandlerPath($className, true);
//TODO add debug screen Auto-loaded classes - ['core: '.$filename.' - '.$className]; //TODO add debug screen Auto-loaded classes - ['core: '.$filename.' - '.$className];
break; break;
} }
if($filename) if($filename)
{ {
// auto load doesn't REQUIRE files, because this will break things like call_user_func() // autoload doesn't REQUIRE files, because this will break things like call_user_func()
include($filename); include($filename);
} }
} }

View File

@@ -9,9 +9,9 @@
* e107 Shortcode handler * e107 Shortcode handler
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/shortcode_handler.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/shortcode_handler.php,v $
* $Revision: 1.41 $ * $Revision: 1.42 $
* $Date: 2010-01-23 16:41:56 $ * $Date: 2010-02-03 11:08:36 $
* $Author: mcfly_e107 $ * $Author: secretr $
*/ */
if (!defined('e107_INIT')) { exit; } if (!defined('e107_INIT')) { exit; }
@@ -133,7 +133,7 @@ function callScFunc($className, $scFuncName, $param= '')
function initShortcodeClass($class, $force = false) function initShortcodeClass($class, $force = false)
{ {
$sc = e107::getScParser(); $sc = e107::getScParser();
if(class_exists($class, false) && ($force || !isset($sc->scClasses[$class]))) if(class_exists($class) && ($force || !isset($sc->scClasses[$class])))
{ {
$sc->scClasses[$class] = new $class(); $sc->scClasses[$class] = new $class();
} }
@@ -437,7 +437,7 @@ class e_shortcode
$_method = 'sc_'.strtolower($code); $_method = 'sc_'.strtolower($code);
if(!isset($this->scClasses[$_class])) if(!isset($this->scClasses[$_class]))
{ {
if(!class_exists($_class, false) && $this->registered_codes[$code]['path']) if(!class_exists($_class) && $this->registered_codes[$code]['path'])
{ {
include_once($this->registered_codes[$code]['path']); include_once($this->registered_codes[$code]['path']);
} }
@@ -494,7 +494,7 @@ class e_shortcode
include_once(e_FILE.'shortcode/'.strtolower($code).'.php'); include_once(e_FILE.'shortcode/'.strtolower($code).'.php');
if(class_exists($_class)) if(class_exists($_class, false)) // prevent __autoload - performance
{ {
$ret = call_user_func(array($_class,$_function), $parm); $ret = call_user_func(array($_class,$_function), $parm);
} }