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,$priority=0) {
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`, `priority`) VALUES ( '%s', '%s', '%s', '%s' ) ",
133 if(! function_exists('unregister_hook')) {
134 function unregister_hook($hook,$file,$function) {
136 $r = q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1",
145 if(! function_exists('load_hooks')) {
146 function load_hooks() {
149 $r = q("SELECT * FROM `hook` WHERE 1 ORDER BY `priority` DESC");
152 if(! array_key_exists($rr['hook'],$a->hooks))
153 $a->hooks[$rr['hook']] = array();
154 $a->hooks[$rr['hook']][] = array($rr['file'],$rr['function']);
160 if(! function_exists('call_hooks')) {
161 function call_hooks($name, &$data = null) {
164 if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) {
165 foreach($a->hooks[$name] as $hook) {
166 @include_once($hook[0]);
167 if(function_exists($hook[1])) {
172 // remove orphan hooks
173 q("delete from hook where hook = '%s' and file = '$s' and function = '%s' limit 1",
186 * parse plugin comment in search of plugin infos.
190 * * Description: A plugin which plugs in
192 * * Author: John <profile url>
193 * * Author: Jane <email>
197 if (! function_exists('get_plugin_info')){
198 function get_plugin_info($plugin){
206 if (!is_file("addon/$plugin/$plugin.php")) return $info;
208 $f = file_get_contents("addon/$plugin/$plugin.php");
209 $r = preg_match("|/\*.*\*/|msU", $f, $m);
212 $ll = explode("\n", $m[0]);
213 foreach( $ll as $l ) {
214 $l = trim($l,"\t\n\r */");
216 list($k,$v) = array_map("trim", explode(":",$l,2));
219 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
221 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
223 $info['author'][] = array('name'=>$v);
226 if (array_key_exists($k,$info)){
240 * parse theme comment in search of theme infos.
244 * * Description: My Cool Theme
246 * * Author: John <profile url>
247 * * Maintainer: Jane <profile url>
251 if (! function_exists('get_theme_info')){
252 function get_theme_info($theme){
257 'maintainer' => array(),
260 'experimental' => false,
261 'unsupported' => false
264 if(file_exists("view/theme/$theme/experimental"))
265 $info['experimental'] = true;
266 if(file_exists("view/theme/$theme/unsupported"))
267 $info['unsupported'] = true;
269 if (!is_file("view/theme/$theme/theme.php")) return $info;
271 $f = file_get_contents("view/theme/$theme/theme.php");
272 $r = preg_match("|/\*.*\*/|msU", $f, $m);
276 $ll = explode("\n", $m[0]);
277 foreach( $ll as $l ) {
278 $l = trim($l,"\t\n\r */");
280 list($k,$v) = array_map("trim", explode(":",$l,2));
284 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
286 $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]);
288 $info['author'][] = array('name'=>$v);
291 elseif ($k=="maintainer"){
292 $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
294 $info['maintainer'][] = array('name'=>$m[1], 'link'=>$m[2]);
296 $info['maintainer'][] = array('name'=>$v);
299 if (array_key_exists($k,$info)){
312 function get_theme_screenshot($theme) {
314 $exts = array('.png','.jpg');
315 foreach($exts as $ext) {
316 if(file_exists('view/theme/' . $theme . '/screenshot' . $ext))
317 return($a->get_baseurl() . '/view/theme/' . $theme . '/screenshot' . $ext);
319 return($a->get_baseurl() . '/images/blank.png');
323 // check service_class restrictions. If there are no service_classes defined, everything is allowed.
324 // if $usage is supplied, we check against a maximum count and return true if the current usage is
325 // less than the subscriber plan allows. Otherwise we return boolean true or false if the property
326 // is allowed (or not) in this subscriber plan. An unset property for this service plan means
327 // the property is allowed, so it is only necessary to provide negative properties for each plan,
328 // or what the subscriber is not allowed to do.
331 function service_class_allows($uid,$property,$usage = false) {
333 if($uid == local_user()) {
334 $service_class = $a->user['service_class'];
337 $r = q("select service_class from user where uid = %d limit 1",
340 if($r !== false and count($r)) {
341 $service_class = $r[0]['service_class'];
344 if(! x($service_class))
345 return true; // everything is allowed
347 $arr = get_config('service_class',$service_class);
348 if(! is_array($arr) || (! count($arr)))
352 return ((x($arr[$property])) ? (bool) $arr['property'] : true);
354 if(! array_key_exists($property,$arr))
356 return (((intval($usage)) < intval($arr[$property])) ? true : false);
361 function service_class_fetch($uid,$property) {
363 if($uid == local_user()) {
364 $service_class = $a->user['service_class'];
367 $r = q("select service_class from user where uid = %d limit 1",
370 if($r !== false and count($r)) {
371 $service_class = $r[0]['service_class'];
374 if(! x($service_class))
375 return false; // everything is allowed
377 $arr = get_config('service_class',$service_class);
378 if(! is_array($arr) || (! count($arr)))
381 return((array_key_exists($property,$arr)) ? $arr[$property] : false);
385 function upgrade_link($bbcode = false) {
386 $l = get_config('service_class','upgrade_link');
390 $t = sprintf('[url=%s]' . t('Click here to upgrade.') . '[/url]', $l);
392 $t = sprintf('<a href="%s">' . t('Click here to upgrade.') . '</div>', $l);
396 function upgrade_message($bbcode = false) {
397 $x = upgrade_link($bbcode);
398 return t('This action exceeds the limits set by your subscription plan.') . (($x) ? ' ' . $x : '') ;
401 function upgrade_bool_message($bbcode = false) {
402 $x = upgrade_link($bbcode);
403 return t('This action is not available under your subscription plan.') . (($x) ? ' ' . $x : '') ;