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) {
21 // silently fail if plugin was removed
23 if(! file_exists('addon/' . $plugin . '/' . $plugin . '.php'))
25 logger("Addons: installing " . $plugin);
26 $t = @filemtime('addon/' . $plugin . '/' . $plugin . '.php');
27 @include_once('addon/' . $plugin . '/' . $plugin . '.php');
28 if(function_exists($plugin . '_install')) {
29 $func = $plugin . '_install';
32 $plugin_admin = (function_exists($plugin."_plugin_admin")?1:0);
34 $r = q("INSERT INTO `addon` (`name`, `installed`, `timestamp`, `plugin_admin`) VALUES ( '%s', 1, %d , %d ) ",
40 // we can add the following with the previous SQL
41 // once most site tables have been updated.
42 // This way the system won't fall over dead during the update.
44 if(file_exists('addon/' . $plugin . '/.hidden')) {
45 q("update addon set hidden = 1 where name = '%s'",
52 logger("Addons: FAILED installing " . $plugin);
58 // reload all updated plugins
60 if(! function_exists('reload_plugins')) {
61 function reload_plugins() {
62 $plugins = get_config('system','addon');
63 if(strlen($plugins)) {
65 $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
71 $parr = explode(',',$plugins);
74 foreach($parr as $pl) {
78 $fname = 'addon/' . $pl . '/' . $pl . '.php';
80 if(file_exists($fname)) {
81 $t = @filemtime($fname);
82 foreach($installed as $i) {
83 if(($i['name'] == $pl) && ($i['timestamp'] != $t)) {
84 logger('Reloading plugin: ' . $i['name']);
85 @include_once($fname);
87 if(function_exists($pl . '_uninstall')) {
88 $func = $pl . '_uninstall';
91 if(function_exists($pl . '_install')) {
92 $func = $pl . '_install';
95 q("UPDATE `addon` SET `timestamp` = %d WHERE `id` = %d",
112 if(! function_exists('register_hook')) {
113 function register_hook($hook,$file,$function,$priority=0) {
115 $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
123 $r = q("INSERT INTO `hook` (`hook`, `file`, `function`, `priority`) VALUES ( '%s', '%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'",
144 if(! function_exists('load_hooks')) {
145 function load_hooks() {
148 $r = q("SELECT * FROM `hook` WHERE 1 ORDER BY `priority` DESC");
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) {
161 $stamp1 = microtime(true);
165 if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) {
166 foreach($a->hooks[$name] as $hook) {
167 // Don't run a theme's hook if the user isn't using the theme
168 if(strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/'.current_theme()) === false)
171 @include_once($hook[0]);
172 if(function_exists($hook[1])) {
177 // remove orphan hooks
178 q("delete from hook where hook = '%s' and file = '%s' and function = '%s'",
188 //check if an app_menu hook exist for plugin $name.
189 //Return true if the plugin is an app
190 if(! function_exists('plugin_is_app')) {
191 function plugin_is_app($name) {
194 if(is_array($a->hooks) && (array_key_exists('app_menu',$a->hooks))) {
195 foreach($a->hooks['app_menu'] as $hook) {
196 if($hook[0] == 'addon/'.$name.'/'.$name.'.php')
205 * parse plugin comment in search of plugin infos.
209 * * Description: A plugin which plugs in
211 * * Author: John <profile url>
212 * * Author: Jane <email>
216 if (! function_exists('get_plugin_info')){
217 function get_plugin_info($plugin){
228 if (!is_file("addon/$plugin/$plugin.php")) return $info;
230 $stamp1 = microtime(true);
231 $f = file_get_contents("addon/$plugin/$plugin.php");
232 $a->save_timestamp($stamp1, "file");
234 $r = preg_match("|/\*.*\*/|msU", $f, $m);
237 $ll = explode("\n", $m[0]);
238 foreach( $ll as $l ) {
239 $l = trim($l,"\t\n\r */");
241 list($k,$v) = array_map("trim", explode(":",$l,2));
244 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
246 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
248 $info['author'][] = array('name'=>$v);
251 if (array_key_exists($k,$info)){
265 * parse theme comment in search of theme infos.
269 * * Description: My Cool Theme
271 * * Author: John <profile url>
272 * * Maintainer: Jane <profile url>
276 if (! function_exists('get_theme_info')){
277 function get_theme_info($theme){
282 'maintainer' => array(),
285 'experimental' => false,
286 'unsupported' => false
289 if(file_exists("view/theme/$theme/experimental"))
290 $info['experimental'] = true;
291 if(file_exists("view/theme/$theme/unsupported"))
292 $info['unsupported'] = true;
294 if (!is_file("view/theme/$theme/theme.php")) return $info;
297 $stamp1 = microtime(true);
298 $f = file_get_contents("view/theme/$theme/theme.php");
299 $a->save_timestamp($stamp1, "file");
301 $r = preg_match("|/\*.*\*/|msU", $f, $m);
304 $ll = explode("\n", $m[0]);
305 foreach( $ll as $l ) {
306 $l = trim($l,"\t\n\r */");
308 list($k,$v) = array_map("trim", explode(":",$l,2));
312 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
314 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
316 $info['author'][] = array('name'=>$v);
319 elseif ($k=="maintainer"){
320 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
322 $info['maintainer'][] = array('name'=>$m[1], 'link'=>$m[2]);
324 $info['maintainer'][] = array('name'=>$v);
327 if (array_key_exists($k,$info)){
340 function get_theme_screenshot($theme) {
342 $exts = array('.png','.jpg');
343 foreach($exts as $ext) {
344 if(file_exists('view/theme/' . $theme . '/screenshot' . $ext))
345 return($a->get_baseurl() . '/view/theme/' . $theme . '/screenshot' . $ext);
347 return($a->get_baseurl() . '/images/blank.png');
350 // install and uninstall theme
351 if (! function_exists('uninstall_theme')){
352 function uninstall_theme($theme){
353 logger("Addons: uninstalling theme " . $theme);
355 @include_once("view/theme/$theme/theme.php");
356 if(function_exists("{$theme}_uninstall")) {
357 $func = "{$theme}_uninstall";
362 if (! function_exists('install_theme')){
363 function install_theme($theme) {
364 // silently fail if theme was removed
366 if(! file_exists("view/theme/$theme/theme.php"))
369 logger("Addons: installing theme $theme");
371 @include_once("view/theme/$theme/theme.php");
373 if(function_exists("{$theme}_install")) {
374 $func = "{$theme}_install";
379 logger("Addons: FAILED installing theme $theme");
387 // check service_class restrictions. If there are no service_classes defined, everything is allowed.
388 // if $usage is supplied, we check against a maximum count and return true if the current usage is
389 // less than the subscriber plan allows. Otherwise we return boolean true or false if the property
390 // is allowed (or not) in this subscriber plan. An unset property for this service plan means
391 // the property is allowed, so it is only necessary to provide negative properties for each plan,
392 // or what the subscriber is not allowed to do.
395 function service_class_allows($uid,$property,$usage = false) {
397 if($uid == local_user()) {
398 $service_class = $a->user['service_class'];
401 $r = q("select service_class from user where uid = %d limit 1",
404 if($r !== false and count($r)) {
405 $service_class = $r[0]['service_class'];
408 if(! x($service_class))
409 return true; // everything is allowed
411 $arr = get_config('service_class',$service_class);
412 if(! is_array($arr) || (! count($arr)))
416 return ((x($arr[$property])) ? (bool) $arr['property'] : true);
418 if(! array_key_exists($property,$arr))
420 return (((intval($usage)) < intval($arr[$property])) ? true : false);
425 function service_class_fetch($uid,$property) {
427 if($uid == local_user()) {
428 $service_class = $a->user['service_class'];
431 $r = q("select service_class from user where uid = %d limit 1",
434 if($r !== false and count($r)) {
435 $service_class = $r[0]['service_class'];
438 if(! x($service_class))
439 return false; // everything is allowed
441 $arr = get_config('service_class',$service_class);
442 if(! is_array($arr) || (! count($arr)))
445 return((array_key_exists($property,$arr)) ? $arr[$property] : false);
449 function upgrade_link($bbcode = false) {
450 $l = get_config('service_class','upgrade_link');
454 $t = sprintf('[url=%s]' . t('Click here to upgrade.') . '[/url]', $l);
456 $t = sprintf('<a href="%s">' . t('Click here to upgrade.') . '</div>', $l);
460 function upgrade_message($bbcode = false) {
461 $x = upgrade_link($bbcode);
462 return t('This action exceeds the limits set by your subscription plan.') . (($x) ? ' ' . $x : '') ;
465 function upgrade_bool_message($bbcode = false) {
466 $x = upgrade_link($bbcode);
467 return t('This action is not available under your subscription plan.') . (($x) ? ' ' . $x : '') ;