diff options
author | RedMatrix <info@friendica.com> | 2014-07-01 09:18:49 +1000 |
---|---|---|
committer | RedMatrix <info@friendica.com> | 2014-07-01 09:18:49 +1000 |
commit | e8d7bd64eb5e475ccb9b986144ed4e9390e8236b (patch) | |
tree | 8f0f2a0da5ed27fb47078cabf16e36055fe72cf1 | |
parent | 2f56472f0c8c6d709b21d6734590bb88da891643 (diff) | |
parent | 4afa2853ccf54240080a2c2a6fc73076de7d99d5 (diff) | |
download | volse-hubzilla-e8d7bd64eb5e475ccb9b986144ed4e9390e8236b.tar.gz volse-hubzilla-e8d7bd64eb5e475ccb9b986144ed4e9390e8236b.tar.bz2 volse-hubzilla-e8d7bd64eb5e475ccb9b986144ed4e9390e8236b.zip |
Merge pull request #522 from dawnbreak/master
Some documentation, less default debugging, bit styleguide
-rwxr-xr-x | include/plugin.php | 221 | ||||
-rw-r--r-- | mod/ping.php | 80 |
2 files changed, 147 insertions, 154 deletions
diff --git a/include/plugin.php b/include/plugin.php index 5c425ac58..cf058ddeb 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -1,12 +1,21 @@ -<?php /** @file */ +<?php +/** + * @file include/plugin.php + * + * @brief Some functions to handle addons and themes. + */ require_once("include/friendica_smarty.php"); -// install and uninstall plugin - +/** + * @brief unloads an addon. + * + * @param string $plugin name of the addon + * @return void + */ function unload_plugin($plugin){ logger("Addons: unloading " . $plugin, LOGGER_DEBUG); - + @include_once('addon/' . $plugin . '/' . $plugin . '.php'); if(function_exists($plugin . '_unload')) { $func = $plugin . '_unload'; @@ -14,10 +23,13 @@ function unload_plugin($plugin){ } } - - +/** + * @brief uninstalls an addon. + * + * @param string $plugin name of the addon + * @return bool + */ function uninstall_plugin($plugin) { - unload_plugin($plugin); if(! file_exists('addon/' . $plugin . '/' . $plugin . '.php')) @@ -34,9 +46,14 @@ function uninstall_plugin($plugin) { q("DELETE FROM `addon` WHERE `name` = '%s' ", dbesc($plugin) ); - } +/** + * @brief installs an addon. + * + * @param string $plugin name of the addon + * @return bool + */ function install_plugin($plugin) { if(! file_exists('addon/' . $plugin . '/' . $plugin . '.php')) return false; @@ -50,7 +67,7 @@ function install_plugin($plugin) { } $plugin_admin = (function_exists($plugin . "_plugin_admin") ? 1 : 0); - + $r = q("INSERT INTO `addon` (`name`, `installed`, `timestamp`, `plugin_admin`) VALUES ( '%s', 1, %d , %d ) ", dbesc($plugin), intval($t), @@ -58,23 +75,25 @@ function install_plugin($plugin) { ); load_plugin($plugin); - } - +/** + * @brief loads an addon by it's name. + * + * @param string $plugin name of the addon + * @return bool + */ function load_plugin($plugin) { // silently fail if plugin was removed - if(! file_exists('addon/' . $plugin . '/' . $plugin . '.php')) return false; - logger("Addons: loading " . $plugin); + logger("Addons: loading " . $plugin, LOGGER_DEBUG); $t = @filemtime('addon/' . $plugin . '/' . $plugin . '.php'); @include_once('addon/' . $plugin . '/' . $plugin . '.php'); if(function_exists($plugin . '_load')) { $func = $plugin . '_load'; $func(); - // we can add the following with the previous SQL // once most site tables have been updated. @@ -91,7 +110,6 @@ function load_plugin($plugin) { logger("Addons: FAILED loading " . $plugin); return false; } - } function plugin_is_installed($name) { @@ -104,24 +122,21 @@ function plugin_is_installed($name) { } - // reload all updated plugins function reload_plugins() { - $plugins = get_config('system','addon'); + $plugins = get_config('system', 'addon'); if(strlen($plugins)) { - $r = q("SELECT * FROM `addon` WHERE `installed` = 1"); if(count($r)) $installed = $r; else $installed = array(); - $parr = explode(',',$plugins); + $parr = explode(',', $plugins); if(count($parr)) { foreach($parr as $pl) { - $pl = trim($pl); $fname = 'addon/' . $pl . '/' . $pl . '.php'; @@ -152,14 +167,18 @@ function reload_plugins() { } } } - - - - - -function register_hook($hook,$file,$function,$priority=0) { +/** + * @brief registers a hook. + * + * @param string $hook the name of the hook + * @param string $file the name of the file that hooks into + * @param string $function the name of the function that the hook will call + * @param int $priority A priority (defaults to 0) + * @return mixed|bool + */ +function register_hook($hook, $file, $function, $priority = 0) { $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1", dbesc($hook), dbesc($file), @@ -178,8 +197,15 @@ function register_hook($hook,$file,$function,$priority=0) { } -function unregister_hook($hook,$file,$function) { - +/** + * @brief unregisters a hook. + * + * @param string $hook the name of the hook + * @param string $file the name of the file that hooks into + * @param string $function the name of the function that the hook called + * @return mixed + */ +function unregister_hook($hook, $file, $function) { $r = q("DELETE FROM hook WHERE hook = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1", dbesc($hook), dbesc($file), @@ -209,7 +235,6 @@ function load_hooks() { } } //logger('hooks: ' . print_r($a->hooks,true)); - } /** @@ -231,7 +256,6 @@ function load_hooks() { * function name of callback handler * */ - function insert_hook($hook,$fn) { $a = get_app(); if(! is_array($a->hooks)) @@ -240,8 +264,6 @@ function insert_hook($hook,$fn) { $a->hooks[$hook] = array(); $a->hooks[$hook][] = array('',$fn); } - - function call_hooks($name, &$data = null) { @@ -265,80 +287,79 @@ function call_hooks($name, &$data = null) { } } } - } -/* - * parse plugin comment in search of plugin infos. +/** + * @brief parse plugin comment in search of plugin infos. + * * like - * - * * Name: Plugin + * * Name: Plugin * * Description: A plugin which plugs in - * * Version: 1.2.3 + * * Version: 1.2.3 * * Author: John <profile url> * * Author: Jane <email> * * Compat: Red [(version)], Friendica [(version)] * * + * + * @param string $plugin the name of the plugin + * @return array with the plugin information */ - - function get_plugin_info($plugin){ - $info=Array( + $info = Array( 'name' => $plugin, 'description' => "", 'author' => array(), 'version' => "", 'compat' => "" ); - + if (!is_file("addon/$plugin/$plugin.php")) return $info; $f = file_get_contents("addon/$plugin/$plugin.php"); $r = preg_match("|/\*.*\*/|msU", $f, $m); - + if ($r){ $ll = explode("\n", $m[0]); foreach( $ll as $l ) { - $l = trim($l,"\t\n\r */"); - if ($l!=""){ - list($k,$v) = array_map("trim", explode(":",$l,2)); - $k= strtolower($k); - if ($k=="author"){ - $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m); + $l = trim($l, "\t\n\r */"); + if ($l != ""){ + list($k, $v) = array_map("trim", explode(":", $l, 2)); + $k = strtolower($k); + if ($k == "author"){ + $r = preg_match("|([^<]+)<([^>]+)>|", $v, $m); if ($r) { - $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]); + $info['author'][] = array('name' => $m[1], 'link' => $m[2]); } else { - $info['author'][] = array('name'=>$v); + $info['author'][] = array('name' => $v); } } else { - if (array_key_exists($k,$info)){ - $info[$k]=$v; + if (array_key_exists($k, $info)){ + $info[$k] = $v; } } - } } - } return $info; } -/* - * parse theme comment in search of theme infos. +/** + * @brief parse theme comment in search of theme infos. + * * like - * - * * Name: My Theme + * * Name: My Theme * * Description: My Cool Theme - * * Version: 1.2.3 + * * Version: 1.2.3 * * Author: John <profile url> * * Maintainer: Jane <profile url> * * Compat: Friendica [(version)], Red [(version)] * * + * + * @param string $theme the name of the theme + * @return array */ - - function get_theme_info($theme){ $info=Array( 'name' => $theme, @@ -358,43 +379,39 @@ function get_theme_info($theme){ $info['unsupported'] = true; if (!is_file("view/theme/$theme/php/theme.php")) return $info; - + $f = file_get_contents("view/theme/$theme/php/theme.php"); $r = preg_match("|/\*.*\*/|msU", $f, $m); - - + if ($r){ $ll = explode("\n", $m[0]); foreach( $ll as $l ) { - $l = trim($l,"\t\n\r */"); - if ($l!=""){ - list($k,$v) = array_map("trim", explode(":",$l,2)); - $k= strtolower($k); - if ($k=="author"){ - - $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m); + $l = trim($l, "\t\n\r */"); + if ($l != ""){ + list($k, $v) = array_map("trim", explode(":", $l, 2)); + $k = strtolower($k); + if ($k == "author"){ + $r = preg_match("|([^<]+)<([^>]+)>|", $v, $m); if ($r) { - $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]); + $info['author'][] = array('name' => $m[1], 'link' => $m[2]); } else { - $info['author'][] = array('name'=>$v); + $info['author'][] = array('name' => $v); } } - elseif ($k=="maintainer"){ - $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m); + elseif ($k == "maintainer"){ + $r = preg_match("|([^<]+)<([^>]+)>|", $v, $m); if ($r) { - $info['maintainer'][] = array('name'=>$m[1], 'link'=>$m[2]); + $info['maintainer'][] = array('name' => $m[1], 'link' => $m[2]); } else { - $info['maintainer'][] = array('name'=>$v); + $info['maintainer'][] = array('name' => $v); } } else { - if (array_key_exists($k,$info)){ - $info[$k]=$v; + if (array_key_exists($k, $info)){ + $info[$k] = $v; } } - } } - } return $info; } @@ -402,7 +419,7 @@ function get_theme_info($theme){ function get_theme_screenshot($theme) { $a = get_app(); - $exts = array('.png','.jpg'); + $exts = array('.png', '.jpg'); foreach($exts as $ext) { if(file_exists('view/theme/' . $theme . '/img/screenshot' . $ext)) return($a->get_baseurl() . '/view/theme/' . $theme . '/img/screenshot' . $ext); @@ -475,7 +492,6 @@ function service_class_fetch($uid,$property) { return false; return((array_key_exists($property,$arr)) ? $arr[$property] : false); - } function upgrade_link($bbcode = false) { @@ -499,19 +515,22 @@ function upgrade_bool_message($bbcode = false) { return t('This action is not available under your subscription plan.') . (($x) ? ' ' . $x : '') ; } - - -function head_add_css($src,$media = 'screen') { - get_app()->css_sources[] = array($src,$media); +/** + * @brief add CSS to <head> + * + * @param string $src + * @param string $media change media attribute (default to 'screen') + * @return void + */ +function head_add_css($src, $media = 'screen') { + get_app()->css_sources[] = array($src, $media); } - -function head_remove_css($src,$media = 'screen') { +function head_remove_css($src, $media = 'screen') { $a = get_app(); - $index = array_search(array($src,$media),$a->css_sources); + $index = array_search(array($src, $media), $a->css_sources); if($index !== false) unset($a->css_sources[$index]); - } function head_get_css() { @@ -524,15 +543,13 @@ function head_get_css() { } function format_css_if_exists($source) { - if(strpos($source[0],'/') !== false) $path = $source[0]; else $path = theme_include($source[0]); if($path) - return '<link rel="stylesheet" href="' . script_path() . '/' . $path . '" type="text/css" media="' . $source[1] . '" />' . "\r\n"; - + return '<link rel="stylesheet" href="' . script_path() . '/' . $path . '" type="text/css" media="' . $source[1] . '">' . "\r\n"; } function script_path() { @@ -544,7 +561,7 @@ function script_path() { $scheme = 'http'; if(x($_SERVER,'SERVER_NAME')) { - $hostname = $_SERVER['SERVER_NAME']; + $hostname = $_SERVER['SERVER_NAME']; } else { return z_root(); @@ -563,10 +580,9 @@ function head_add_js($src) { function head_remove_js($src) { $a = get_app(); - $index = array_search($src,$a->js_sources); + $index = array_search($src, $a->js_sources); if($index !== false) unset($a->js_sources[$index]); - } function head_get_js() { @@ -590,22 +606,17 @@ function head_get_main_js() { return $str; } - - function format_js_if_exists($source) { - if(strpos($source,'/') !== false) $path = $source; else $path = theme_include($source); if($path) return '<script src="' . script_path() . '/' . $path . '" ></script>' . "\r\n" ; - } function theme_include($file, $root = '') { - $a = get_app(); // Make sure $root ends with a slash / if it's not blank @@ -640,15 +651,12 @@ function theme_include($file, $root = '') { } - - function get_intltext_template($s, $root = '') { $a = get_app(); $t = $a->template_engine(); $template = $t->get_intltext_template($s, $root); return $template; - } @@ -658,4 +666,3 @@ function get_markup_template($s, $root = '') { $template = $t->get_markup_template($s, $root); return $template; } - diff --git a/mod/ping.php b/mod/ping.php index ac12e2fc0..7e7ccaa15 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -1,9 +1,21 @@ <?php - +/** + * @file mod/ping.php + * + */ require_once('include/bbcode.php'); require_once('include/notify.php'); +/** + * @brief do several updates when pinged. + * + * This function does several tasks. Whenever called it checks for new messages, + * introductions, notifications, etc. and returns a json with the results. + * + * @param App &$a + * @result JSON + */ function ping_init(&$a) { $result = array(); @@ -30,13 +42,13 @@ function ping_init(&$a) { $result['invalid'] = ((intval($_GET['uid'])) && (intval($_GET['uid']) != local_user()) ? 1 : 0); - if(x($_SESSION,'sysmsg')){ + if(x($_SESSION, 'sysmsg')){ foreach ($_SESSION['sysmsg'] as $m){ $result['notice'][] = array('message' => $m); } unset($_SESSION['sysmsg']); } - if(x($_SESSION,'sysmsg_info')){ + if(x($_SESSION, 'sysmsg_info')){ foreach ($_SESSION['sysmsg_info'] as $m){ $result['info'][] = array('message' => $m); } @@ -48,7 +60,6 @@ function ping_init(&$a) { killme(); } - if(get_observer_hash() && (! $result['invalid'])) { $r = q("select cp_id, cp_room from chatpresence where cp_xchan = '%s' and cp_client = '%s' and cp_room = 0 limit 1", dbesc(get_observer_hash()), @@ -80,8 +91,8 @@ function ping_init(&$a) { killme(); } - if(x($_REQUEST,'markRead') && local_user()) { - + // mark all items read + if(x($_REQUEST, 'markRead') && local_user()) { switch($_REQUEST['markRead']) { case 'network': $r = q("update item set item_flags = ( item_flags ^ %d ) where (item_flags & %d) and uid = %d", @@ -90,7 +101,6 @@ function ping_init(&$a) { intval(local_user()) ); break; - case 'home': $r = q("update item set item_flags = ( item_flags ^ %d ) where (item_flags & %d) and (item_flags & %d) and uid = %d", intval(ITEM_UNSEEN), @@ -111,19 +121,16 @@ function ping_init(&$a) { intval(local_user()) ); break; - case 'notify': $r = q("update notify set seen = 1 where uid = %d", intval(local_user()) ); break; - default: break; } } - if(argc() > 1 && argv(1) === 'notify') { $t = q("select count(*) as total from notify where uid = %d and seen = 0", intval(local_user()) @@ -163,12 +170,9 @@ function ping_init(&$a) { echo json_encode(array('notify' => $notifs)); killme(); - } - if(argc() > 1 && argv(1) === 'messages') { - $channel = $a->get_channel(); $t = q("select mail.*, xchan.* from mail left join xchan on xchan_hash = from_xchan where channel_id = %d and not ( mail_flags & %d ) and not (mail_flags & %d ) @@ -196,14 +200,9 @@ function ping_init(&$a) { echo json_encode(array('notify' => $notifs)); killme(); - } - - - if(argc() > 1 && (argv(1) === 'network' || argv(1) === 'home')) { - $result = array(); $r = q("SELECT * FROM item @@ -220,15 +219,13 @@ function ping_init(&$a) { continue; $result[] = format_notification($item); } - } - logger('ping: ' . print_r($result,true)); + } + logger('ping (network||home): ' . print_r($result, true), LOGGER_DATA); echo json_encode(array('notify' => $result)); killme(); - } if(argc() > 1 && (argv(1) === 'intros')) { - $result = array(); $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash @@ -250,15 +247,13 @@ function ping_init(&$a) { 'message' => t('added your channel') ); } - } - logger('ping: ' . print_r($result,true)); + } + logger('ping (intros): ' . print_r($result, true), LOGGER_DATA); echo json_encode(array('notify' => $result)); killme(); - } if(argc() > 1 && (argv(1) === 'all_events')) { - $bd_format = t('g A l F d') ; // 8 AM Friday January 18 $result = array(); @@ -267,23 +262,22 @@ function ping_init(&$a) { WHERE `event`.`uid` = %d AND start < '%s' AND start > '%s' and `ignore` = 0 ORDER BY `start` DESC ", intval(local_user()), - dbesc(datetime_convert('UTC',date_default_timezone_get(),'now + 7 days')), - dbesc(datetime_convert('UTC',date_default_timezone_get(),'now - 1 days')) + dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + 7 days')), + dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')) ); if($r) { foreach($r as $rr) { if($rr['adjust']) - $md = datetime_convert('UTC',date_default_timezone_get(),$rr['start'],'Y/m'); + $md = datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'Y/m'); else - $md = datetime_convert('UTC','UTC',$rr['start'],'Y/m'); + $md = datetime_convert('UTC', 'UTC', $rr['start'], 'Y/m'); - $strt = datetime_convert('UTC',$rr['convert'] ? date_default_timezone_get() : 'UTC',$rr['start']); - $today = ((substr($strt,0,10) === datetime_convert('UTC',date_default_timezone_get(),'now','Y-m-d')) ? true : false); + $strt = datetime_convert('UTC', $rr['convert'] ? date_default_timezone_get() : 'UTC', $rr['start']); + $today = ((substr($strt, 0, 10) === datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d')) ? true : false); $when = day_translate(datetime_convert('UTC', $rr['adjust'] ? date_default_timezone_get() : 'UTC', $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : ''); - $result[] = array( 'notify_link' => $a->get_baseurl() . '/events', // FIXME this takes you to an edit page and it may not be yours, we really want to just view the single event --> '/events/event/' . $rr['event_hash'], 'name' => $rr['xchan_name'], @@ -294,23 +288,19 @@ function ping_init(&$a) { 'message' => t('posted an event') ); } - } - logger('ping: ' . print_r($result,true)); + } + logger('ping (all_events): ' . print_r($result, true), LOGGER_DATA); echo json_encode(array('notify' => $result)); killme(); - } - // Normal ping - just the counts - $t = q("select count(*) as total from notify where uid = %d and seen = 0", intval(local_user()) ); if($t) $result['notify'] = intval($t[0]['total']); - $t1 = dba_timer(); $r = q("SELECT id, item_restrict, item_flags FROM item @@ -321,7 +311,6 @@ function ping_init(&$a) { ); if(count($r)) { - $arr = array('items' => $r); call_hooks('network_ping', $arr); @@ -333,7 +322,6 @@ function ping_init(&$a) { } } - $t2 = dba_timer(); $intr = q("select count(abook_id) as total from abook where (abook_flags & %d) and abook_channel = %d", @@ -372,15 +360,15 @@ function ping_init(&$a) { WHERE `event`.`uid` = %d AND start < '%s' AND start > '%s' and `ignore` = 0 ORDER BY `start` ASC ", intval(local_user()), - dbesc(datetime_convert('UTC',date_default_timezone_get(),'now + 7 days')), - dbesc(datetime_convert('UTC',date_default_timezone_get(),'now - 1 days')) + dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + 7 days')), + dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')) ); if($events) { $result['all_events'] = count($events); if($result['all_events']) { - $str_now = datetime_convert('UTC',$a->timezone,'now','Y-m-d'); + $str_now = datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d'); foreach($events as $x) { $bd = false; if($x['type'] === 'birthday') { @@ -390,7 +378,7 @@ function ping_init(&$a) { else { $result['events'] ++; } - if(datetime_convert('UTC',((intval($x['adjust'])) ? $a->timezone : 'UTC'), $x['start'],'Y-m-d') === $str_now) { + if(datetime_convert('UTC', ((intval($x['adjust'])) ? $a->timezone : 'UTC'), $x['start'], 'Y-m-d') === $str_now) { $result['all_events_today'] ++; if($bd) $result['birthdays_today'] ++; @@ -409,6 +397,4 @@ function ping_init(&$a) { echo $x; killme(); - } - |