PHP 4 compatible plugin engine

master
pecesama 2008-11-08 03:11:11 +00:00
parent fa676b0fa4
commit eb69c37903
5 changed files with 30 additions and 45 deletions

View File

@ -233,7 +233,7 @@ if ($user->isAdmin()) {
<option value="0" <?php if(!$conf->check_version) echo "selected=\"selected\""; ?>><?php echo __("Deactive")?></option>
</select>
</li>
<?php print_r($trigger);echo "<br>";die("Antes de trigger->call add options panel");
<?php
$trigger->call('add_options_panel');
?>
</ul>

View File

@ -23,17 +23,12 @@ if(!defined('entry') || !entry) die('Not a valid page');
return false;
}
/*echo "<br />==========<br />";
echo $name;
echo "<br />";*/
$index = 0;
//foreach (plugins::$instances as $plugin) {
foreach ($GLOBALS['plugins::$instances'] as $plugin) {
if(array_key_exists($index,$this->actions[$name])){
$action = $this->actions[$name][$index][1];
if (is_callable(array($plugin, $action))) {
//echo "ejecutar: ".$action."()<br/>";
$plugin->$action();
$index++;
}
@ -46,16 +41,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
return $this->exists[$name];
}
//foreach (plugins::$instances as $plugin) {
foreach ($GLOBALS['plugins::$instances'] as $plugin) {
/*print_r(plugins::$instances);
echo "<br />";
print_r($plugin);
echo "<br />";
print_r($this->actions[$name]);
echo "<br />";
echo $this->actions[$name][0][1];
echo "<br />";*/
if(array_key_exists($name,$this->actions)){
if (is_callable(array($plugin, $this->actions[$name][0][1]))) {
return $this->exists[$name] = true;
@ -66,14 +52,13 @@ if(!defined('entry') || !entry) die('Not a valid page');
return $this->exists[$name] = false;
}
function instance(){
//$instance;
if( !isset($GLOBALS['$instance']) ) {
$GLOBALS['$instance'] = new plugin();
//I really hate you PHP4's OOP implementation
function &instance() {
static $instance;
if (!isset($instance)) {
$instance = new plugin();
}
//print_r($GLOBALS['$instance']);
//die();
return $GLOBALS['$instance'];
return $instance;
}
}

View File

@ -12,11 +12,13 @@ if(!defined('entry') || !entry) die('Not a valid page');
=========================== */
?>
<?php
$GLOBALS['plugins::$instances'] = array(); /* class static property */
/* Simulating a class static property */
$GLOBALS['plugins::$instances'] = array();
class plugins {
function addAction($name, $function) {
$plugEngine = plugin::instance();
$plugEngine =& plugin::instance(); //DO NOT remove the & after the =
$plugEngine->actions[$name][] = array($this, $function);
}

View File

@ -654,6 +654,7 @@ class util {
$actives = json_decode($conf->active_plugins,1);
$actives = $actives[1];
foreach ($actives as $index => $plugin) {
if (!file_exists(Absolute_Path."plugins/".$plugin)) {
unset($actives[$index]);
@ -664,7 +665,6 @@ class util {
if (!class_exists($index)) {
continue;
}
//plugins::$instances[$index] = new $index;
$GLOBALS['plugins::$instances'][$index] = new $index;
}
}

View File

@ -2,13 +2,12 @@
ob_start();
if(!defined('entry') || !entry) die('Not a valid page');
error_reporting (E_ALL);
ini_set('display_errors', '1');
// PHP settings specific to Gelato
ini_set('pcre.backtrack_limit', '10000');
// Globals to be used throughout the application
define('Absolute_Path', dirname(__FILE__).DIRECTORY_SEPARATOR);
$installed = true;
$configFile = Absolute_Path.'config.php';
@ -48,7 +47,6 @@ if (!extension_loaded('json')) {
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'configuration.class.php');
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'util.class.php');
//require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'functions.php');
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'gelato.class.php');
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'templates.class.php');
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'themes.class.php');
@ -74,7 +72,7 @@ if($installed){
session_start();
util::init_plugins();
$trigger = plugin::instance();
$trigger =& plugin::instance(); //DO NOT remove the & after the =
$trigger->call('gelato_init');