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 ) ",
38 // reload all updated plugins
40 if(! function_exists('reload_plugins')) {
41 function reload_plugins() {
42 $plugins = get_config('system','addon');
43 if(strlen($plugins)) {
45 $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
51 $parr = explode(',',$plugins);
53 foreach($parr as $pl) {
56 $t = filemtime('addon/' . $pl . '/' . $pl . '.php');
57 foreach($installed as $i) {
58 if(($i['name'] == $pl) && ($i['timestamp'] != $t)) {
59 logger('Reloading plugin: ' . $i['name']);
60 @include_once('addon/' . $pl . '/' . $pl . '.php');
62 if(function_exists($pl . '_uninstall')) {
63 $func = $pl . '_uninstall';
66 if(function_exists($pl . '_install')) {
67 $func = $pl . '_install';
70 q("UPDATE `addon` SET `timestamp` = %d WHERE `id` = %d LIMIT 1",
85 if(! function_exists('register_hook')) {
86 function register_hook($hook,$file,$function) {
88 $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
96 $r = q("INSERT INTO `hook` (`hook`, `file`, `function`) VALUES ( '%s', '%s', '%s' ) ",
104 if(! function_exists('unregister_hook')) {
105 function unregister_hook($hook,$file,$function) {
107 $r = q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
116 if(! function_exists('load_hooks')) {
117 function load_hooks() {
120 $r = q("SELECT * FROM `hook` WHERE 1");
123 $a->hooks[] = array($rr['hook'], $rr['file'], $rr['function']);
129 if(! function_exists('call_hooks')) {
130 function call_hooks($name, &$data = null) {
133 if(count($a->hooks)) {
134 foreach($a->hooks as $hook) {
135 if($hook[HOOK_HOOK] === $name) {
136 @include_once($hook[HOOK_FILE]);
137 if(function_exists($hook[HOOK_FUNCTION])) {
138 $func = $hook[HOOK_FUNCTION];
148 * parse plugin comment in search of plugin infos.
152 * * Description: A plugin which plugs in
154 * * Author: John <profile url>
155 * * Author: Jane <email>
159 if (! function_exists('get_plugin_info')){
160 function get_plugin_info($plugin){
161 if (!is_file("addon/$plugin/$plugin.php")) return false;
163 $f = file_get_contents("addon/$plugin/$plugin.php");
164 $r = preg_match("|/\*.*\*/|msU", $f, $m);
174 $ll = explode("\n", $m[0]);
175 foreach( $ll as $l ) {
176 $l = trim($l,"\t\n\r */");
178 list($k,$v) = array_map("trim", explode(":",$l,2));
181 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
183 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
185 $info['author'][] = array('name'=>$v);
188 if (array_key_exists($k,$info)){