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 $a->hooks[] = array($rr['hook'], $rr['file'], $rr['function']);
157 if(! function_exists('call_hooks')) {
158 function call_hooks($name, &$data = null) {
161 if(count($a->hooks)) {
162 foreach($a->hooks as $hook) {
163 if($hook[HOOK_HOOK] === $name) {
164 @include_once($hook[HOOK_FILE]);
165 if(function_exists($hook[HOOK_FUNCTION])) {
166 $func = $hook[HOOK_FUNCTION];
170 // remove orphan hooks
171 q("delete from hook where hook = '%s' and file = '$s' and function = '%s' limit 1",
172 dbesc($hook[HOOK_HOOK]),
173 dbesc($hook[HOOK_FILE]),
174 dbesc($hook[HOOK_FUNCTION])
184 * parse plugin comment in search of plugin infos.
188 * * Description: A plugin which plugs in
190 * * Author: John <profile url>
191 * * Author: Jane <email>
195 if (! function_exists('get_plugin_info')){
196 function get_plugin_info($plugin){
204 if (!is_file("addon/$plugin/$plugin.php")) return $info;
206 $f = file_get_contents("addon/$plugin/$plugin.php");
207 $r = preg_match("|/\*.*\*/|msU", $f, $m);
210 $ll = explode("\n", $m[0]);
211 foreach( $ll as $l ) {
212 $l = trim($l,"\t\n\r */");
214 list($k,$v) = array_map("trim", explode(":",$l,2));
217 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
219 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
221 $info['author'][] = array('name'=>$v);
224 if (array_key_exists($k,$info)){
238 * parse theme comment in search of theme infos.
242 * * Description: My Cool Theme
244 * * Author: John <profile url>
245 * * Maintainer: Jane <profile url>
249 if (! function_exists('get_theme_info')){
250 function get_theme_info($theme){
255 'maintainer' => array(),
257 'experimental' => false,
258 'unsupported' => false
261 if(file_exists("view/theme/$theme/experimental"))
262 $info['experimental'] = true;
263 if(file_exists("view/theme/$theme/unsupported"))
264 $info['unsupported'] = true;
266 if (!is_file("view/theme/$theme/theme.php")) return $info;
268 $f = file_get_contents("view/theme/$theme/theme.php");
269 $r = preg_match("|/\*.*\*/|msU", $f, $m);
273 $ll = explode("\n", $m[0]);
274 foreach( $ll as $l ) {
275 $l = trim($l,"\t\n\r */");
277 list($k,$v) = array_map("trim", explode(":",$l,2));
281 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
283 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
285 $info['author'][] = array('name'=>$v);
288 elseif ($k=="maintainer"){
289 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
291 $info['maintainer'][] = array('name'=>$m[1], 'link'=>$m[2]);
293 $info['maintainer'][] = array('name'=>$v);
296 if (array_key_exists($k,$info)){
309 function get_theme_screenshot($theme) {
311 $exts = array('.png','.jpg');
312 foreach($exts as $ext) {
313 if(file_exists('view/theme/' . $theme . '/screenshot' . $ext))
314 return($a->get_baseurl() . '/view/theme/' . $theme . '/screenshot' . $ext);
316 return($a->get_baseurl() . '/images/blank.png');