PHP 4 compatible plugin engine
parent
fa676b0fa4
commit
eb69c37903
|
|
@ -233,8 +233,8 @@ 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");
|
||||
$trigger->call('add_options_panel');
|
||||
<?php
|
||||
$trigger->call('add_options_panel');
|
||||
?>
|
||||
</ul>
|
||||
</fieldset>
|
||||
|
|
|
|||
|
|
@ -12,28 +12,23 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
|||
=========================== */
|
||||
?>
|
||||
<?php
|
||||
class plugin {
|
||||
class plugin {
|
||||
|
||||
var $actions = array();
|
||||
var $exists = array();
|
||||
|
||||
function call($name) {
|
||||
|
||||
function call($name) {
|
||||
|
||||
if (!$this->exists($name)) {
|
||||
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/>";
|
||||
if (is_callable(array($plugin, $action))) {
|
||||
$plugin->$action();
|
||||
$index++;
|
||||
}
|
||||
|
|
@ -44,18 +39,9 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
|||
function exists($name) {
|
||||
if (isset($this->exists[$name])) {
|
||||
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 />";*/
|
||||
}
|
||||
|
||||
foreach ($GLOBALS['plugins::$instances'] as $plugin) {
|
||||
if(array_key_exists($name,$this->actions)){
|
||||
if (is_callable(array($plugin, $this->actions[$name][0][1]))) {
|
||||
return $this->exists[$name] = true;
|
||||
|
|
@ -65,16 +51,15 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -12,12 +12,14 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
|||
=========================== */
|
||||
?>
|
||||
<?php
|
||||
$GLOBALS['plugins::$instances'] = array(); /* class static property */
|
||||
class plugins {
|
||||
/* Simulating a class static property */
|
||||
$GLOBALS['plugins::$instances'] = array();
|
||||
|
||||
class plugins {
|
||||
|
||||
function addAction($name, $function) {
|
||||
$plugEngine = plugin::instance();
|
||||
$plugEngine->actions[$name][] = array($this, $function);
|
||||
function addAction($name, $function) {
|
||||
$plugEngine =& plugin::instance(); //DO NOT remove the & after the =
|
||||
$plugEngine->actions[$name][] = array($this, $function);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -654,17 +654,17 @@ 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]);
|
||||
continue;
|
||||
}else{
|
||||
} else {
|
||||
require_once(Absolute_Path.'plugins/'.$plugin);
|
||||
}
|
||||
if (!class_exists($index)) {
|
||||
continue;
|
||||
}
|
||||
//plugins::$instances[$index] = new $index;
|
||||
$GLOBALS['plugins::$instances'][$index] = new $index;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue