4 // install and uninstall plugin
5 if (! function_exists('uninstall_plugin')){
6 function uninstall_plugin($plugin){
7 logger("Addons: uninstalling " . $plugin);
8 q("DELETE FROM `addon` WHERE `name` = '%s' LIMIT 1",
12 @include_once('addon/' . $plugin . '/' . $plugin . '.php');
13 if(function_exists($plugin . '_uninstall')) {
14 $func = $plugin . '_uninstall';
19 if (! function_exists('install_plugin')){
20 function install_plugin($plugin){
21 logger("Addons: installing " . $plugin);
22 $t = @filemtime('addon/' . $plugin . '/' . $plugin . '.php');
23 @include_once('addon/' . $plugin . '/' . $plugin . '.php');
24 if(function_exists($plugin . '_install')) {
25 $func = $plugin . '_install';
28 $plugin_admin = (function_exists($plugin."_plugin_admin")?1:0);
30 $r = q("INSERT INTO `addon` (`name`, `installed`, `timestamp`, `plugin_admin`) VALUES ( '%s', 1, %d , %d ) ",
37 logger("Addons: FAILED installing " . $plugin);
42 // reload all updated plugins
44 if(! function_exists('reload_plugins')) {
45 function reload_plugins() {
46 $plugins = get_config('system','addon');
47 if(strlen($plugins)) {
49 $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
55 $parr = explode(',',$plugins);
57 foreach($parr as $pl) {
60 $fname = 'addon/' . $pl . '/' . $pl . '.php';
62 if(file_exists($fname)) {
63 $t = @filemtime($fname);
64 foreach($installed as $i) {
65 if(($i['name'] == $pl) && ($i['timestamp'] != $t)) {
66 logger('Reloading plugin: ' . $i['name']);
67 @include_once($fname);
69 if(function_exists($pl . '_uninstall')) {
70 $func = $pl . '_uninstall';
73 if(function_exists($pl . '_install')) {
74 $func = $pl . '_install';
77 q("UPDATE `addon` SET `timestamp` = %d WHERE `id` = %d LIMIT 1",
93 if(! function_exists('register_hook')) {
94 function register_hook($hook,$file,$function) {
96 $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
104 $r = q("INSERT INTO `hook` (`hook`, `file`, `function`) VALUES ( '%s', '%s', '%s' ) ",
112 if(! function_exists('unregister_hook')) {
113 function unregister_hook($hook,$file,$function) {
115 $r = q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
124 if(! function_exists('load_hooks')) {
125 function load_hooks() {
128 $r = q("SELECT * FROM `hook` WHERE 1");
131 $a->hooks[] = array($rr['hook'], $rr['file'], $rr['function']);
137 if(! function_exists('call_hooks')) {
138 function call_hooks($name, &$data = null) {
141 if(count($a->hooks)) {
142 foreach($a->hooks as $hook) {
143 if($hook[HOOK_HOOK] === $name) {
144 @include_once($hook[HOOK_FILE]);
145 if(function_exists($hook[HOOK_FUNCTION])) {
146 $func = $hook[HOOK_FUNCTION];
156 * parse plugin comment in search of plugin infos.
160 * * Description: A plugin which plugs in
162 * * Author: John <profile url>
163 * * Author: Jane <email>
167 if (! function_exists('get_plugin_info')){
168 function get_plugin_info($plugin){
169 if (!is_file("addon/$plugin/$plugin.php")) return false;
171 $f = file_get_contents("addon/$plugin/$plugin.php");
172 $r = preg_match("|/\*.*\*/|msU", $f, $m);
182 $ll = explode("\n", $m[0]);
183 foreach( $ll as $l ) {
184 $l = trim($l,"\t\n\r */");
186 list($k,$v) = array_map("trim", explode(":",$l,2));
189 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
191 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
193 $info['author'][] = array('name'=>$v);
196 if (array_key_exists($k,$info)){