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 // define THISPLUGIN, make life easy to plugin devs :-)
13 define("THISPLUGIN", 'addon/' . $plugin . '/' . $plugin . '.php');
15 @include_once('addon/' . $plugin . '/' . $plugin . '.php');
16 if(function_exists($plugin . '_uninstall')) {
17 $func = $plugin . '_uninstall';
22 if (! function_exists('install_plugin')){
23 function install_plugin($plugin) {
24 // silently fail if plugin was removed
26 // define THISPLUGIN, make life easy to plugin devs :-)
27 define("THISPLUGIN", 'addon/' . $plugin . '/' . $plugin . '.php');
29 if(! file_exists('addon/' . $plugin . '/' . $plugin . '.php'))
31 logger("Addons: installing " . $plugin);
32 $t = @filemtime('addon/' . $plugin . '/' . $plugin . '.php');
33 @include_once('addon/' . $plugin . '/' . $plugin . '.php');
34 if(function_exists($plugin . '_install')) {
35 $func = $plugin . '_install';
38 $plugin_admin = (function_exists($plugin."_plugin_admin")?1:0);
40 $r = q("INSERT INTO `addon` (`name`, `installed`, `timestamp`, `plugin_admin`) VALUES ( '%s', 1, %d , %d ) ",
46 // we can add the following with the previous SQL
47 // once most site tables have been updated.
48 // This way the system won't fall over dead during the update.
50 if(file_exists('addon/' . $plugin . '/.hidden')) {
51 q("update addon set hidden = 1 where name = '%s' limit 1",
58 logger("Addons: FAILED installing " . $plugin);
64 // reload all updated plugins
66 if(! function_exists('reload_plugins')) {
67 function reload_plugins() {
68 $plugins = get_config('system','addon');
69 if(strlen($plugins)) {
71 $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
77 $parr = explode(',',$plugins);
80 foreach($parr as $pl) {
84 $fname = 'addon/' . $pl . '/' . $pl . '.php';
86 // define THISPLUGIN, make life easy to plugin devs :-)
87 define("THISPLUGIN", $fname);
89 if(file_exists($fname)) {
90 $t = @filemtime($fname);
91 foreach($installed as $i) {
92 if(($i['name'] == $pl) && ($i['timestamp'] != $t)) {
93 logger('Reloading plugin: ' . $i['name']);
94 @include_once($fname);
96 if(function_exists($pl . '_uninstall')) {
97 $func = $pl . '_uninstall';
100 if(function_exists($pl . '_install')) {
101 $func = $pl . '_install';
104 q("UPDATE `addon` SET `timestamp` = %d WHERE `id` = %d LIMIT 1",
121 if(! function_exists('register_hook')) {
122 function register_hook($hook,$file,$function,$priority=0) {
124 $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
132 $r = q("INSERT INTO `hook` (`hook`, `file`, `function`, `priority`) VALUES ( '%s', '%s', '%s', '%s' ) ",
141 if(! function_exists('unregister_hook')) {
142 function unregister_hook($hook,$file,$function) {
144 $r = q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
153 if(! function_exists('load_hooks')) {
154 function load_hooks() {
157 $r = q("SELECT * FROM `hook` WHERE 1 ORDER BY `priority` DESC");
160 if(! array_key_exists($rr['hook'],$a->hooks))
161 $a->hooks[$rr['hook']] = array();
162 $a->hooks[$rr['hook']][] = array($rr['file'],$rr['function']);
168 if(! function_exists('call_hooks')) {
169 function call_hooks($name, &$data = null) {
172 if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) {
173 foreach($a->hooks[$name] as $hook) {
174 // define THISPLUGIN, make life easy to plugin devs :-)
175 define("THISPLUGIN", $hook[0]);
176 @include_once($hook[0]);
177 if(function_exists($hook[1])) {
182 // remove orphan hooks
183 q("delete from hook where hook = '%s' and file = '$s' and function = '%s' limit 1",
196 * parse plugin comment in search of plugin infos.
200 * * Description: A plugin which plugs in
202 * * Author: John <profile url>
203 * * Author: Jane <email>
207 if (! function_exists('get_plugin_info')){
208 function get_plugin_info($plugin){
216 if (!is_file("addon/$plugin/$plugin.php")) return $info;
218 $f = file_get_contents("addon/$plugin/$plugin.php");
219 $r = preg_match("|/\*.*\*/|msU", $f, $m);
222 $ll = explode("\n", $m[0]);
223 foreach( $ll as $l ) {
224 $l = trim($l,"\t\n\r */");
226 list($k,$v) = array_map("trim", explode(":",$l,2));
229 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
231 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
233 $info['author'][] = array('name'=>$v);
236 if (array_key_exists($k,$info)){
250 * parse theme comment in search of theme infos.
254 * * Description: My Cool Theme
256 * * Author: John <profile url>
257 * * Maintainer: Jane <profile url>
261 if (! function_exists('get_theme_info')){
262 function get_theme_info($theme){
267 'maintainer' => array(),
270 'experimental' => false,
271 'unsupported' => false
274 if(file_exists("view/theme/$theme/experimental"))
275 $info['experimental'] = true;
276 if(file_exists("view/theme/$theme/unsupported"))
277 $info['unsupported'] = true;
279 if (!is_file("view/theme/$theme/theme.php")) return $info;
281 $f = file_get_contents("view/theme/$theme/theme.php");
282 $r = preg_match("|/\*.*\*/|msU", $f, $m);
286 $ll = explode("\n", $m[0]);
287 foreach( $ll as $l ) {
288 $l = trim($l,"\t\n\r */");
290 list($k,$v) = array_map("trim", explode(":",$l,2));
294 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
296 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
298 $info['author'][] = array('name'=>$v);
301 elseif ($k=="maintainer"){
302 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
304 $info['maintainer'][] = array('name'=>$m[1], 'link'=>$m[2]);
306 $info['maintainer'][] = array('name'=>$v);
309 if (array_key_exists($k,$info)){
322 function get_theme_screenshot($theme) {
324 $exts = array('.png','.jpg');
325 foreach($exts as $ext) {
326 if(file_exists('view/theme/' . $theme . '/screenshot' . $ext))
327 return($a->get_baseurl() . '/view/theme/' . $theme . '/screenshot' . $ext);
329 return($a->get_baseurl() . '/images/blank.png');
333 // check service_class restrictions. If there are no service_classes defined, everything is allowed.
334 // if $usage is supplied, we check against a maximum count and return true if the current usage is
335 // less than the subscriber plan allows. Otherwise we return boolean true or false if the property
336 // is allowed (or not) in this subscriber plan. An unset property for this service plan means
337 // the property is allowed, so it is only necessary to provide negative properties for each plan,
338 // or what the subscriber is not allowed to do.
341 function service_class_allows($uid,$property,$usage = false) {
343 if($uid == local_user()) {
344 $service_class = $a->user['service_class'];
347 $r = q("select service_class from user where uid = %d limit 1",
350 if($r !== false and count($r)) {
351 $service_class = $r[0]['service_class'];
354 if(! x($service_class))
355 return true; // everything is allowed
357 $arr = get_config('service_class',$service_class);
358 if(! is_array($arr) || (! count($arr)))
362 return ((x($arr[$property])) ? (bool) $arr['property'] : true);
364 if(! array_key_exists($property,$arr))
366 return (((intval($usage)) < intval($arr[$property])) ? true : false);
371 function service_class_fetch($uid,$property) {
373 if($uid == local_user()) {
374 $service_class = $a->user['service_class'];
377 $r = q("select service_class from user where uid = %d limit 1",
380 if($r !== false and count($r)) {
381 $service_class = $r[0]['service_class'];
384 if(! x($service_class))
385 return false; // everything is allowed
387 $arr = get_config('service_class',$service_class);
388 if(! is_array($arr) || (! count($arr)))
391 return((array_key_exists($property,$arr)) ? $arr[$property] : false);
395 function upgrade_link($bbcode = false) {
396 $l = get_config('service_class','upgrade_link');
400 $t = sprintf('[url=%s]' . t('Click here to upgrade.') . '[/url]', $l);
402 $t = sprintf('<a href="%s">' . t('Click here to upgrade.') . '</div>', $l);
406 function upgrade_message($bbcode = false) {
407 $x = upgrade_link($bbcode);
408 return t('This action exceeds the limits set by your subscription plan.') . (($x) ? ' ' . $x : '') ;
411 function upgrade_bool_message($bbcode = false) {
412 $x = upgrade_link($bbcode);
413 return t('This action is not available under your subscription plan.') . (($x) ? ' ' . $x : '') ;