author | Dan |
Tue, 12 Feb 2008 00:37:46 -0500 | |
changeset 413 | 6607cd646d6d |
parent 411 | d1a95497b68f |
child 464 | 8063eace5b67 |
permissions | -rw-r--r-- |
1 | 1 |
<?php |
2 |
||
3 |
/* |
|
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
411 | 5 |
* Version 1.1.2 (Caoineag alpha 2) |
1 | 6 |
* Copyright (C) 2006-2007 Dan Fuhry |
7 |
* |
|
8 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
12 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
13 |
*/ |
|
14 |
||
15 |
class pluginLoader { |
|
16 |
var $hook_list; |
|
17 |
var $load_list; |
|
18 |
var $loaded_plugins; |
|
403 | 19 |
var $system_plugins = Array('SpecialUserFuncs.php','SpecialUserPrefs.php','SpecialPageFuncs.php','SpecialAdmin.php','SpecialCSS.php','SpecialUpdownload.php','SpecialSearch.php','PrivateMessages.php','SpecialGroups.php', 'SpecialRecentChanges.php'); |
1 | 20 |
function loadAll() |
21 |
{ |
|
22 |
$dir = ENANO_ROOT.'/plugins/'; |
|
23 |
||
24 |
$this->load_list = Array(); |
|
25 |
||
26 |
$plugins = Array(); |
|
27 |
||
28 |
// Open a known directory, and proceed to read its contents |
|
29 |
||
30 |
if (is_dir($dir)) |
|
31 |
{ |
|
32 |
if ($dh = opendir($dir)) |
|
33 |
{ |
|
34 |
while (($file = readdir($dh)) !== false) |
|
35 |
{ |
|
36 |
if(preg_match('#^(.*?)\.php$#is', $file)) |
|
37 |
{ |
|
38 |
if(getConfig('plugin_'.$file) == '1' || in_array($file, $this->system_plugins)) |
|
39 |
{ |
|
40 |
$this->load_list[] = $dir . $file; |
|
41 |
$plugid = substr($file, 0, strlen($file)-4); |
|
378
c1c7fa6b329f
Got Enano to load even if there are no plugins; added caching for decrypted session keys to significantly improve performance (in theory at least)
Dan
parents:
322
diff
changeset
|
42 |
$f = @file_get_contents($dir . $file); |
c1c7fa6b329f
Got Enano to load even if there are no plugins; added caching for decrypted session keys to significantly improve performance (in theory at least)
Dan
parents:
322
diff
changeset
|
43 |
if ( empty($f) ) |
c1c7fa6b329f
Got Enano to load even if there are no plugins; added caching for decrypted session keys to significantly improve performance (in theory at least)
Dan
parents:
322
diff
changeset
|
44 |
continue; |
1 | 45 |
$f = explode("\n", $f); |
46 |
$f = array_slice($f, 2, 7); |
|
47 |
$f[0] = substr($f[0], 13); |
|
48 |
$f[1] = substr($f[1], 12); |
|
49 |
$f[2] = substr($f[2], 13); |
|
50 |
$f[3] = substr($f[3], 8 ); |
|
51 |
$f[4] = substr($f[4], 9 ); |
|
52 |
$f[5] = substr($f[5], 12); |
|
53 |
$plugins[$plugid] = Array(); |
|
54 |
$plugins[$plugid]['name'] = $f[0]; |
|
55 |
$plugins[$plugid]['uri'] = $f[1]; |
|
56 |
$plugins[$plugid]['desc'] = $f[2]; |
|
57 |
$plugins[$plugid]['auth'] = $f[3]; |
|
58 |
$plugins[$plugid]['vers'] = $f[4]; |
|
59 |
$plugins[$plugid]['aweb'] = $f[5]; |
|
60 |
} |
|
61 |
} |
|
62 |
} |
|
63 |
closedir($dh); |
|
64 |
} |
|
65 |
} |
|
66 |
$this->loaded_plugins = $plugins; |
|
67 |
//die('<pre>'.htmlspecialchars(print_r($plugins, true)).'</pre>'); |
|
68 |
} |
|
69 |
function setHook($name, $opts = Array()) { |
|
70 |
/* |
|
71 |
$r = Array(); |
|
72 |
if(isset($this->hook_list[$name])) { |
|
73 |
for($i=0;$i<sizeof($this->hook_list[$name]);$i++) { |
|
74 |
$ret = eval($this->hook_list[$name][$i]); |
|
75 |
if($ret !== null) $r[] = $ret; |
|
76 |
} |
|
77 |
} |
|
78 |
if(sizeof($r) > 0) return $r; |
|
79 |
else return false; |
|
80 |
*/ |
|
81 |
if(isset($this->hook_list[$name]) && is_array($this->hook_list[$name])) |
|
82 |
{ |
|
379
82b991bee797
Minor and hopefully non-breaking change to plugin loader to possibly double performance at hook points
Dan
parents:
378
diff
changeset
|
83 |
return array(implode("\n", $this->hook_list[$name])); |
1 | 84 |
} |
85 |
else |
|
86 |
{ |
|
87 |
return Array(); |
|
88 |
} |
|
89 |
} |
|
90 |
function attachHook($name, $code) { |
|
91 |
if(!isset($this->hook_list[$name])) |
|
92 |
{ |
|
93 |
$this->hook_list[$name] = Array(); |
|
94 |
} |
|
95 |
$this->hook_list[$name][] = $code; |
|
96 |
} |
|
97 |
function loaded($plugid) |
|
98 |
{ |
|
99 |
return isset( $this->loaded_plugins[$plugid] ); |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
?> |