From 4afa2853ccf54240080a2c2a6fc73076de7d99d5 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Mon, 30 Jun 2014 23:43:05 +0200 Subject: Documented include/plugin.php a bit and removed an annoying default logging. Changed it to LOGGER_DEBUG. --- include/plugin.php | 221 +++++++++++++++++++++++++++-------------------------- 1 file changed, 114 insertions(+), 107 deletions(-) (limited to 'include/plugin.php') 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 @@ -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 * * Author: Jane * * 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 * * Maintainer: Jane * * 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 + * + * @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 '' . "\r\n"; - + return '' . "\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 '' . "\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; } - -- cgit v1.2.3