Quellcode durchsuchen

PHP 4 compatible plugin engine

pecesama vor 15 Jahren
Ursprung
Commit
eb69c37903
5 geänderte Dateien mit 30 neuen und 45 gelöschten Zeilen
  1. 2 2
      admin/options.php
  2. 17 32
      classes/plugin.class.php
  3. 7 5
      classes/plugins.class.php
  4. 2 2
      classes/util.class.php
  5. 2 4
      entry.php

+ 2 - 2
admin/options.php Datei anzeigen

233
 											<option value="0" <?php if(!$conf->check_version) echo "selected=\"selected\""; ?>><?php echo __("Deactive")?></option>
233
 											<option value="0" <?php if(!$conf->check_version) echo "selected=\"selected\""; ?>><?php echo __("Deactive")?></option>
234
 										</select>
234
 										</select>
235
 									</li>
235
 									</li>
236
-<?php	print_r($trigger);echo "<br>";die("Antes de trigger->call add options panel");
237
-									$trigger->call('add_options_panel');	
236
+<?php
237
+									$trigger->call('add_options_panel');									
238
 ?>									
238
 ?>									
239
 								</ul>
239
 								</ul>
240
 							</fieldset>
240
 							</fieldset>

+ 17 - 32
classes/plugin.class.php Datei anzeigen

12
   =========================== */
12
   =========================== */
13
 ?>
13
 ?>
14
 <?php
14
 <?php
15
-	class plugin {	
15
+	class plugin {
16
 		
16
 		
17
 		var $actions = array();
17
 		var $actions = array();
18
 		var $exists = array();
18
 		var $exists = array();
19
 	
19
 	
20
-		function call($name) {            
21
-
20
+		function call($name) {			
21
+			
22
 			if (!$this->exists($name)) {
22
 			if (!$this->exists($name)) {
23
 				return false;
23
 				return false;
24
-			}            
25
-
26
- 			/*echo "<br />==========<br />";
27
-			echo $name;
28
-			echo "<br />";*/
24
+			} 			
29
 			
25
 			
30
 			$index = 0;
26
 			$index = 0;
31
-			//foreach (plugins::$instances as $plugin) {
27
+			
32
 			foreach ($GLOBALS['plugins::$instances'] as $plugin) {
28
 			foreach ($GLOBALS['plugins::$instances'] as $plugin) {
33
 				if(array_key_exists($index,$this->actions[$name])){
29
 				if(array_key_exists($index,$this->actions[$name])){
34
 					$action = $this->actions[$name][$index][1]; 
30
 					$action = $this->actions[$name][$index][1]; 
35
-					if (is_callable(array($plugin, $action))) {
36
-						//echo "ejecutar: ".$action."()<br/>";					
31
+					if (is_callable(array($plugin, $action))) {						
37
 						$plugin->$action();
32
 						$plugin->$action();
38
 						$index++;
33
 						$index++;
39
 					}
34
 					}
44
 		function exists($name) {
39
 		function exists($name) {
45
             if (isset($this->exists[$name])) {
40
             if (isset($this->exists[$name])) {
46
                 return $this->exists[$name];
41
                 return $this->exists[$name];
47
-			}
48
-
49
-            //foreach (plugins::$instances as $plugin) {
50
-			foreach ($GLOBALS['plugins::$instances'] as $plugin) {
51
-				/*print_r(plugins::$instances);
52
-				echo "<br />";
53
-				print_r($plugin);
54
-				echo "<br />";
55
-				print_r($this->actions[$name]);
56
-				echo "<br />";
57
-				echo $this->actions[$name][0][1];
58
-				echo "<br />";*/
42
+			}			
43
+            
44
+			foreach ($GLOBALS['plugins::$instances'] as $plugin) {				
59
 				if(array_key_exists($name,$this->actions)){
45
 				if(array_key_exists($name,$this->actions)){
60
 					if (is_callable(array($plugin, $this->actions[$name][0][1]))) {
46
 					if (is_callable(array($plugin, $this->actions[$name][0][1]))) {
61
 						return $this->exists[$name] = true;
47
 						return $this->exists[$name] = true;
65
 
51
 
66
             return $this->exists[$name] = false;
52
             return $this->exists[$name] = false;
67
         }		
53
         }		
68
-        
69
-		function instance(){
70
-			//$instance;			
71
-			if( !isset($GLOBALS['$instance']) ) {
72
-				$GLOBALS['$instance'] = new plugin();
54
+		
55
+		//I really hate you PHP4's OOP implementation
56
+		function &instance() {
57
+			static $instance;
58
+			if (!isset($instance)) {
59
+				$instance = new plugin();
73
 			}
60
 			}
74
-			//print_r($GLOBALS['$instance']);
75
-			//die();
76
-			return $GLOBALS['$instance'];
77
-        }
61
+			return $instance;   
62
+		}
78
 		
63
 		
79
 	}
64
 	}
80
 ?>
65
 ?>

+ 7 - 5
classes/plugins.class.php Datei anzeigen

12
   =========================== */
12
   =========================== */
13
 ?>
13
 ?>
14
 <?php
14
 <?php
15
-	$GLOBALS['plugins::$instances'] = array(); /* class static property */
16
-	class plugins {		
15
+	/* Simulating a class static property */
16
+	$GLOBALS['plugins::$instances'] = array();
17
+	
18
+	class plugins {
17
 		
19
 		
18
-		function addAction($name, $function) {
19
-	    	$plugEngine = plugin::instance();
20
-	    	$plugEngine->actions[$name][] = array($this, $function);	    	
20
+		function addAction($name, $function) {	    	
21
+			$plugEngine =& plugin::instance(); //DO NOT remove the & after the =
22
+	    	$plugEngine->actions[$name][] = array($this, $function);
21
 	    }
23
 	    }
22
 		
24
 		
23
 	}
25
 	}

+ 2 - 2
classes/util.class.php Datei anzeigen

654
         
654
         
655
 		$actives = json_decode($conf->active_plugins,1);
655
 		$actives = json_decode($conf->active_plugins,1);
656
 		$actives = $actives[1];
656
 		$actives = $actives[1];
657
+		
657
         foreach ($actives as $index => $plugin) {
658
         foreach ($actives as $index => $plugin) {
658
             if (!file_exists(Absolute_Path."plugins/".$plugin)) {
659
             if (!file_exists(Absolute_Path."plugins/".$plugin)) {
659
                 unset($actives[$index]);
660
                 unset($actives[$index]);
660
                 continue;
661
                 continue;
661
-            }else{
662
+            } else {
662
 				require_once(Absolute_Path.'plugins/'.$plugin);
663
 				require_once(Absolute_Path.'plugins/'.$plugin);
663
 			}            
664
 			}            
664
 			if (!class_exists($index)) {
665
 			if (!class_exists($index)) {
665
                 continue;
666
                 continue;
666
 			}
667
 			}
667
-			//plugins::$instances[$index] = new $index;
668
 			$GLOBALS['plugins::$instances'][$index] = new $index;
668
 			$GLOBALS['plugins::$instances'][$index] = new $index;
669
         }
669
         }
670
 	}
670
 	}

+ 2 - 4
entry.php Datei anzeigen

2
 ob_start();
2
 ob_start();
3
 if(!defined('entry') || !entry) die('Not a valid page');
3
 if(!defined('entry') || !entry) die('Not a valid page');
4
 
4
 
5
-
6
 error_reporting (E_ALL);
5
 error_reporting (E_ALL);
7
 ini_set('display_errors', '1');
6
 ini_set('display_errors', '1');
8
 
7
 
9
 // PHP settings specific to Gelato
8
 // PHP settings specific to Gelato
10
 ini_set('pcre.backtrack_limit', '10000');
9
 ini_set('pcre.backtrack_limit', '10000');
11
-// Globals to be used throughout the application
10
+
12
 define('Absolute_Path', dirname(__FILE__).DIRECTORY_SEPARATOR);
11
 define('Absolute_Path', dirname(__FILE__).DIRECTORY_SEPARATOR);
13
 $installed = true;
12
 $installed = true;
14
 $configFile = Absolute_Path.'config.php';
13
 $configFile = Absolute_Path.'config.php';
48
 
47
 
49
 require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'configuration.class.php');
48
 require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'configuration.class.php');
50
 require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'util.class.php');
49
 require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'util.class.php');
51
-//require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'functions.php');
52
 require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'gelato.class.php');
50
 require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'gelato.class.php');
53
 require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'templates.class.php');
51
 require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'templates.class.php');
54
 require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'themes.class.php');
52
 require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'themes.class.php');
74
 	session_start();
72
 	session_start();
75
 	
73
 	
76
 	util::init_plugins();
74
 	util::init_plugins();
77
-	$trigger = plugin::instance();
75
+	$trigger =& plugin::instance(); //DO NOT remove the & after the =	
78
 	
76
 	
79
 	$trigger->call('gelato_init');	
77
 	$trigger->call('gelato_init');	
80
 
78