author | Dan |
Mon, 29 Oct 2007 20:01:48 -0400 | |
changeset 216 | feaffad3e07b |
parent 166 | d53cc29308f4 |
child 311 | a007145a0ff6 |
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 |
|
166
d53cc29308f4
Rebrand as 1.1.1; everything should now be bumped to "unstable" status
Dan
parents:
142
diff
changeset
|
5 |
* Version 1.1.1 |
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; |
|
19 |
var $system_plugins = Array('SpecialUserFuncs.php','SpecialUserPrefs.php','SpecialPageFuncs.php','SpecialAdmin.php','SpecialCSS.php','SpecialUpdownload.php','SpecialSearch.php','PrivateMessages.php','SpecialGroups.php'); |
|
20 |
function loadAll() |
|
21 |
{ |
|
22 |
dc_here('plugins: building file list'); |
|
23 |
||
24 |
$dir = ENANO_ROOT.'/plugins/'; |
|
25 |
||
26 |
$this->load_list = Array(); |
|
27 |
||
28 |
$plugins = Array(); |
|
29 |
||
30 |
// Open a known directory, and proceed to read its contents |
|
31 |
||
32 |
if (is_dir($dir)) |
|
33 |
{ |
|
34 |
if ($dh = opendir($dir)) |
|
35 |
{ |
|
36 |
while (($file = readdir($dh)) !== false) |
|
37 |
{ |
|
38 |
if(preg_match('#^(.*?)\.php$#is', $file)) |
|
39 |
{ |
|
40 |
if(getConfig('plugin_'.$file) == '1' || in_array($file, $this->system_plugins)) |
|
41 |
{ |
|
42 |
$this->load_list[] = $dir . $file; |
|
43 |
$plugid = substr($file, 0, strlen($file)-4); |
|
44 |
$f = file_get_contents($dir . $file); |
|
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 |
dc_dump($name, 'plugins: hook added: '); |
|
71 |
/* |
|
72 |
$r = Array(); |
|
73 |
if(isset($this->hook_list[$name])) { |
|
74 |
for($i=0;$i<sizeof($this->hook_list[$name]);$i++) { |
|
75 |
$ret = eval($this->hook_list[$name][$i]); |
|
76 |
if($ret !== null) $r[] = $ret; |
|
77 |
} |
|
78 |
} |
|
79 |
if(sizeof($r) > 0) return $r; |
|
80 |
else return false; |
|
81 |
*/ |
|
82 |
if(isset($this->hook_list[$name]) && is_array($this->hook_list[$name])) |
|
83 |
{ |
|
84 |
return $this->hook_list[$name]; |
|
85 |
} |
|
86 |
else |
|
87 |
{ |
|
88 |
return Array(); |
|
89 |
} |
|
90 |
} |
|
91 |
function attachHook($name, $code) { |
|
92 |
dc_dump($code, 'plugins: hook attached: '.$name.'<br />code:'); |
|
93 |
if(!isset($this->hook_list[$name])) |
|
94 |
{ |
|
95 |
$this->hook_list[$name] = Array(); |
|
96 |
} |
|
97 |
$this->hook_list[$name][] = $code; |
|
98 |
} |
|
99 |
function loaded($plugid) |
|
100 |
{ |
|
101 |
return isset( $this->loaded_plugins[$plugid] ); |
|
102 |
} |
|
103 |
} |
|
104 |
||
105 |
?> |