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);
74 foreach($parr as $pl) {
77 $fname = 'addon/' . $pl . '/' . $pl . '.php';
79 if(file_exists($fname)) {
80 $t = @filemtime($fname);
81 foreach($installed as $i) {
82 if(($i['name'] == $pl) && ($i['timestamp'] != $t)) {
83 logger('Reloading plugin: ' . $i['name']);
84 @include_once($fname);
86 if(function_exists($pl . '_uninstall')) {
87 $func = $pl . '_uninstall';
90 if(function_exists($pl . '_install')) {
91 $func = $pl . '_install';
94 q("UPDATE `addon` SET `timestamp` = %d WHERE `id` = %d LIMIT 1",
110 if(! function_exists('register_hook')) {
111 function register_hook($hook,$file,$function) {
113 $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
121 $r = q("INSERT INTO `hook` (`hook`, `file`, `function`) VALUES ( '%s', '%s', '%s' ) ",
129 if(! function_exists('unregister_hook')) {
130 function unregister_hook($hook,$file,$function) {
132 $r = q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
141 if(! function_exists('load_hooks')) {
142 function load_hooks() {
145 $r = q("SELECT * FROM `hook` WHERE 1");
148 $a->hooks[] = array($rr['hook'], $rr['file'], $rr['function']);
154 if(! function_exists('call_hooks')) {
155 function call_hooks($name, &$data = null) {
158 if(count($a->hooks)) {
159 foreach($a->hooks as $hook) {
160 if($hook[HOOK_HOOK] === $name) {
161 @include_once($hook[HOOK_FILE]);
162 if(function_exists($hook[HOOK_FUNCTION])) {
163 $func = $hook[HOOK_FUNCTION];
173 * parse plugin comment in search of plugin infos.
177 * * Description: A plugin which plugs in
179 * * Author: John <profile url>
180 * * Author: Jane <email>
184 if (! function_exists('get_plugin_info')){
185 function get_plugin_info($plugin){
193 if (!is_file("addon/$plugin/$plugin.php")) return $info;
195 $f = file_get_contents("addon/$plugin/$plugin.php");
196 $r = preg_match("|/\*.*\*/|msU", $f, $m);
199 $ll = explode("\n", $m[0]);
200 foreach( $ll as $l ) {
201 $l = trim($l,"\t\n\r */");
203 list($k,$v) = array_map("trim", explode(":",$l,2));
206 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
208 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
210 $info['author'][] = array('name'=>$v);
213 if (array_key_exists($k,$info)){
227 * parse theme comment in search of theme infos.
231 * * Description: My Cool Theme
233 * * Author: John <profile url>
234 * * Maintainer: Jane <profile url>
238 if (! function_exists('get_theme_info')){
239 function get_theme_info($theme){
244 'maintainer' => array(),
246 'experimental' => false,
247 'unsupported' => false
250 if(file_exists("view/theme/$theme/experimental"))
251 $info['experimental'] = true;
252 if(file_exists("view/theme/$theme/unsupported"))
253 $info['unsupported'] = true;
255 if (!is_file("view/theme/$theme/theme.php")) return $info;
257 $f = file_get_contents("view/theme/$theme/theme.php");
258 $r = preg_match("|/\*.*\*/|msU", $f, $m);
262 $ll = explode("\n", $m[0]);
263 foreach( $ll as $l ) {
264 $l = trim($l,"\t\n\r */");
266 list($k,$v) = array_map("trim", explode(":",$l,2));
270 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
272 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
274 $info['author'][] = array('name'=>$v);
277 elseif ($k=="maintainer"){
278 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
280 $info['maintainer'][] = array('name'=>$m[1], 'link'=>$m[2]);
282 $info['maintainer'][] = array('name'=>$v);
285 if (array_key_exists($k,$info)){
298 function get_theme_screenshot($theme) {
300 $exts = array('.png','.jpg');
301 foreach($exts as $ext) {
302 if(file_exists('view/theme/' . $theme . '/screenshot' . $ext))
303 return($a->get_baseurl() . '/view/theme/' . $theme . '/screenshot' . $ext);
305 return($a->get_baseurl() . '/images/blank.png');