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' ",
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) {
22 // silently fail if plugin was removed
24 if(! file_exists('addon/' . $plugin . '/' . $plugin . '.php'))
26 logger("Addons: installing " . $plugin);
27 $t = @filemtime('addon/' . $plugin . '/' . $plugin . '.php');
28 @include_once('addon/' . $plugin . '/' . $plugin . '.php');
29 if(function_exists($plugin . '_install')) {
30 $func = $plugin . '_install';
33 $plugin_admin = (function_exists($plugin."_plugin_admin")?1:0);
35 $r = q("INSERT INTO `addon` (`name`, `installed`, `timestamp`, `plugin_admin`) VALUES ( '%s', 1, %d , %d ) ",
41 // we can add the following with the previous SQL
42 // once most site tables have been updated.
43 // This way the system won't fall over dead during the update.
45 if(file_exists('addon/' . $plugin . '/.hidden')) {
46 q("update addon set hidden = 1 where name = '%s' limit 1",
53 logger("Addons: FAILED installing " . $plugin);
59 // reload all updated plugins
61 if(! function_exists('reload_plugins')) {
62 function reload_plugins() {
63 $plugins = get_config('system','addon');
64 if(strlen($plugins)) {
66 $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
72 $parr = explode(',',$plugins);
75 foreach($parr as $pl) {
79 $fname = 'addon/' . $pl . '/' . $pl . '.php';
81 if(file_exists($fname)) {
82 $t = @filemtime($fname);
83 foreach($installed as $i) {
84 if(($i['name'] == $pl) && ($i['timestamp'] != $t)) {
85 logger('Reloading plugin: ' . $i['name']);
86 @include_once($fname);
88 if(function_exists($pl . '_uninstall')) {
89 $func = $pl . '_uninstall';
92 if(function_exists($pl . '_install')) {
93 $func = $pl . '_install';
96 q("UPDATE `addon` SET `timestamp` = %d WHERE `id` = %d LIMIT 1",
113 if(! function_exists('register_hook')) {
114 function register_hook($hook,$file,$function) {
116 $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
124 $r = q("INSERT INTO `hook` (`hook`, `file`, `function`) VALUES ( '%s', '%s', '%s' ) ",
132 if(! function_exists('unregister_hook')) {
133 function unregister_hook($hook,$file,$function) {
135 $r = q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
144 if(! function_exists('load_hooks')) {
145 function load_hooks() {
148 $r = q("SELECT * FROM `hook` WHERE 1");
151 if(! array_key_exists($rr['hook'],$a->hooks))
152 $a->hooks[$rr['hook']] = array();
153 $a->hooks[$rr['hook']][] = array($rr['file'],$rr['function']);
159 if(! function_exists('call_hooks')) {
160 function call_hooks($name, &$data = null) {
163 if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) {
164 foreach($a->hooks[$name] as $hook) {
165 @include_once($hook[0]);
166 if(function_exists($hook[1])) {
171 // remove orphan hooks
172 q("delete from hook where hook = '%s' and file = '$s' and function = '%s' limit 1",
185 * parse plugin comment in search of plugin infos.
189 * * Description: A plugin which plugs in
191 * * Author: John <profile url>
192 * * Author: Jane <email>
196 if (! function_exists('get_plugin_info')){
197 function get_plugin_info($plugin){
205 if (!is_file("addon/$plugin/$plugin.php")) return $info;
207 $f = file_get_contents("addon/$plugin/$plugin.php");
208 $r = preg_match("|/\*.*\*/|msU", $f, $m);
211 $ll = explode("\n", $m[0]);
212 foreach( $ll as $l ) {
213 $l = trim($l,"\t\n\r */");
215 list($k,$v) = array_map("trim", explode(":",$l,2));
218 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
220 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
222 $info['author'][] = array('name'=>$v);
225 if (array_key_exists($k,$info)){
239 * parse theme comment in search of theme infos.
243 * * Description: My Cool Theme
245 * * Author: John <profile url>
246 * * Maintainer: Jane <profile url>
250 if (! function_exists('get_theme_info')){
251 function get_theme_info($theme){
256 'maintainer' => array(),
258 'experimental' => false,
259 'unsupported' => false
262 if(file_exists("view/theme/$theme/experimental"))
263 $info['experimental'] = true;
264 if(file_exists("view/theme/$theme/unsupported"))
265 $info['unsupported'] = true;
267 if (!is_file("view/theme/$theme/theme.php")) return $info;
269 $f = file_get_contents("view/theme/$theme/theme.php");
270 $r = preg_match("|/\*.*\*/|msU", $f, $m);
274 $ll = explode("\n", $m[0]);
275 foreach( $ll as $l ) {
276 $l = trim($l,"\t\n\r */");
278 list($k,$v) = array_map("trim", explode(":",$l,2));
282 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
284 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
286 $info['author'][] = array('name'=>$v);
289 elseif ($k=="maintainer"){
290 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
292 $info['maintainer'][] = array('name'=>$m[1], 'link'=>$m[2]);
294 $info['maintainer'][] = array('name'=>$v);
297 if (array_key_exists($k,$info)){
310 function get_theme_screenshot($theme) {
312 $exts = array('.png','.jpg');
313 foreach($exts as $ext) {
314 if(file_exists('view/theme/' . $theme . '/screenshot' . $ext))
315 return($a->get_baseurl() . '/view/theme/' . $theme . '/screenshot' . $ext);
317 return($a->get_baseurl() . '/images/blank.png');