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) {
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 ) ",
43 logger("Addons: FAILED installing " . $plugin);
49 // reload all updated plugins
51 if(! function_exists('reload_plugins')) {
52 function reload_plugins() {
53 $plugins = get_config('system','addon');
54 if(strlen($plugins)) {
56 $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
62 $parr = explode(',',$plugins);
64 foreach($parr as $pl) {
67 $fname = 'addon/' . $pl . '/' . $pl . '.php';
69 if(file_exists($fname)) {
70 $t = @filemtime($fname);
71 foreach($installed as $i) {
72 if(($i['name'] == $pl) && ($i['timestamp'] != $t)) {
73 logger('Reloading plugin: ' . $i['name']);
74 @include_once($fname);
76 if(function_exists($pl . '_uninstall')) {
77 $func = $pl . '_uninstall';
80 if(function_exists($pl . '_install')) {
81 $func = $pl . '_install';
84 q("UPDATE `addon` SET `timestamp` = %d WHERE `id` = %d LIMIT 1",
100 if(! function_exists('register_hook')) {
101 function register_hook($hook,$file,$function) {
103 $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
111 $r = q("INSERT INTO `hook` (`hook`, `file`, `function`) VALUES ( '%s', '%s', '%s' ) ",
119 if(! function_exists('unregister_hook')) {
120 function unregister_hook($hook,$file,$function) {
122 $r = q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
131 if(! function_exists('load_hooks')) {
132 function load_hooks() {
135 $r = q("SELECT * FROM `hook` WHERE 1");
138 $a->hooks[] = array($rr['hook'], $rr['file'], $rr['function']);
144 if(! function_exists('call_hooks')) {
145 function call_hooks($name, &$data = null) {
148 if(count($a->hooks)) {
149 foreach($a->hooks as $hook) {
150 if($hook[HOOK_HOOK] === $name) {
151 @include_once($hook[HOOK_FILE]);
152 if(function_exists($hook[HOOK_FUNCTION])) {
153 $func = $hook[HOOK_FUNCTION];
163 * parse plugin comment in search of plugin infos.
167 * * Description: A plugin which plugs in
169 * * Author: John <profile url>
170 * * Author: Jane <email>
174 if (! function_exists('get_plugin_info')){
175 function get_plugin_info($plugin){
183 if (!is_file("addon/$plugin/$plugin.php")) return $info;
185 $f = file_get_contents("addon/$plugin/$plugin.php");
186 $r = preg_match("|/\*.*\*/|msU", $f, $m);
189 $ll = explode("\n", $m[0]);
190 foreach( $ll as $l ) {
191 $l = trim($l,"\t\n\r */");
193 list($k,$v) = array_map("trim", explode(":",$l,2));
196 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
198 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
200 $info['author'][] = array('name'=>$v);
203 if (array_key_exists($k,$info)){
217 * parse theme comment in search of theme infos.
221 * * Description: My Cool Theme
223 * * Author: John <profile url>
224 * * Maintainer: Jane <profile url>
228 if (! function_exists('get_theme_info')){
229 function get_theme_info($theme){
234 'maintainer' => array(),
236 'experimental' => false,
237 'unsupported' => false
240 if(file_exists("view/theme/$theme/experimental"))
241 $info['experimental'] = true;
242 if(file_exists("view/theme/$theme/unsupported"))
243 $info['unsupported'] = true;
245 if (!is_file("view/theme/$theme/theme.php")) return $info;
247 $f = file_get_contents("view/theme/$theme/theme.php");
248 $r = preg_match("|/\*.*\*/|msU", $f, $m);
252 $ll = explode("\n", $m[0]);
253 foreach( $ll as $l ) {
254 $l = trim($l,"\t\n\r */");
256 list($k,$v) = array_map("trim", explode(":",$l,2));
260 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
262 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
264 $info['author'][] = array('name'=>$v);
267 elseif ($k=="maintainer"){
268 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
270 $info['maintainer'][] = array('name'=>$m[1], 'link'=>$m[2]);
272 $info['maintainer'][] = array('name'=>$v);
275 if (array_key_exists($k,$info)){
288 function get_theme_screenshot($theme) {
290 $exts = array('.png','.jpg');
291 foreach($exts as $ext) {
292 if(file_exists('view/theme/' . $theme . '/screenshot' . $ext))
293 return($a->get_baseurl() . '/view/theme/' . $theme . '/screenshot' . $ext);
295 return($a->get_baseurl() . '/images/blank.png');