From 1a737be2b408135177a9e94dcffd0f68c0aca90b Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Tue, 5 Sep 2017 00:23:42 +0200 Subject: :bulb: Improving Doxygen documentation. Fix some Doxygen parsing errors. Improve hooks documentation. --- Zotlabs/Access/PermissionRoles.php | 128 ++++++++++++++------------ Zotlabs/Access/Permissions.php | 33 ++++--- Zotlabs/Extend/Hook.php | 18 ++-- Zotlabs/Lib/ActivityStreams.php | 124 +++++++++++++++++++------ Zotlabs/Lib/Chatroom.php | 40 +++++---- Zotlabs/Lib/Config.php | 29 +++--- Zotlabs/Lib/PConfig.php | 46 +++++----- Zotlabs/Lib/SConfig.php | 7 +- Zotlabs/Lib/XConfig.php | 33 +++++-- Zotlabs/Render/Comanche.php | 179 ++++++++++++++++++++++++------------- Zotlabs/Web/Router.php | 40 +++++---- Zotlabs/Zot/Verify.php | 13 ++- 12 files changed, 451 insertions(+), 239 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Access/PermissionRoles.php b/Zotlabs/Access/PermissionRoles.php index 49d478c5c..b335bf825 100644 --- a/Zotlabs/Access/PermissionRoles.php +++ b/Zotlabs/Access/PermissionRoles.php @@ -1,12 +1,21 @@ [ - 'social' => t('Social - Mostly Public'), - 'social_restricted' => t('Social - Restricted'), + 'social' => t('Social - Mostly Public'), + 'social_restricted' => t('Social - Restricted'), 'social_private' => t('Social - Private') ], t('Community Forum') => [ - 'forum' => t('Forum - Mostly Public'), - 'forum_restricted' => t('Forum - Restricted'), + 'forum' => t('Forum - Mostly Public'), + 'forum_restricted' => t('Forum - Restricted'), 'forum_private' => t('Forum - Private') ], t('Feed Republish') => [ - 'feed' => t('Feed - Mostly Public'), + 'feed' => t('Feed - Mostly Public'), 'feed_restricted' => t('Feed - Restricted') ], t('Special Purpose') => [ - 'soapbox' => t('Special - Celebrity/Soapbox'), + 'soapbox' => t('Special - Celebrity/Soapbox'), 'repository' => t('Special - Group Repository') ], t('Other') => [ 'custom' => t('Custom/Expert Mode') ] - ]; - return $roles; + return $roles; } } \ No newline at end of file diff --git a/Zotlabs/Access/Permissions.php b/Zotlabs/Access/Permissions.php index 62c4af0ff..20ce21238 100644 --- a/Zotlabs/Access/Permissions.php +++ b/Zotlabs/Access/Permissions.php @@ -33,19 +33,22 @@ use Zotlabs\Lib as Zlib; */ class Permissions { + /** + * @brief Permissions version. + * + * This must match the version in PermissionRoles.php before permission updates can run. + * + * @return number + */ static public function version() { - // This must match the version in PermissionRoles.php before permission updates can run. return 2; } /** * @brief Return an array with Permissions. * - * @hooks permissions_list - * * \e array \b permissions - * * \e string \b filter - * @param string $filter (optional) only passed to hook permission_list - * @return Associative array with permissions and short description. + * @param string $filter (optional) only passed to hook permissions_list + * @return array Associative array with permissions and short description. */ static public function Perms($filter = '') { @@ -74,6 +77,11 @@ class Permissions { 'permissions' => $perms, 'filter' => $filter ]; + /** + * @hooks permissions_list + * * \e array \b permissions + * * \e string \b filter + */ call_hooks('permissions_list', $x); return($x['permissions']); @@ -84,9 +92,7 @@ class Permissions { * * e.g. you must be authenticated. * - * @hooks write_perms - * * \e array \b permissions - * @return Associative array with permissions and short description. + * @return array Associative array with permissions and short description. */ static public function BlockedAnonPerms() { @@ -99,6 +105,10 @@ class Permissions { } $x = ['permissions' => $res]; + /** + * @hooks write_perms + * * \e array \b permissions + */ call_hooks('write_perms', $x); return($x['permissions']); @@ -138,7 +148,7 @@ class Permissions { * to [ 0 => ['name' => 'view_stream', 'value' => 1], ... ] * * @param array $arr associative perms array 'view_stream' => 1 - * @return Indexed array with elements that look like + * @return array Indexed array with elements that look like * * \e string \b name the perm name (e.g. view_stream) * * \e int \b value the value of the perm (e.g. 1) */ @@ -197,11 +207,10 @@ class Permissions { * @brief * * @param int $channel_id A channel id - * @return associative array + * @return array Associative array with * * \e array \b perms Permission array * * \e int \b automatic 0 or 1 */ - static public function connect_perms($channel_id) { $my_perms = []; diff --git a/Zotlabs/Extend/Hook.php b/Zotlabs/Extend/Hook.php index c6f9ea850..81260ead6 100644 --- a/Zotlabs/Extend/Hook.php +++ b/Zotlabs/Extend/Hook.php @@ -2,7 +2,12 @@ namespace Zotlabs\Extend; +use App; +/** + * @brief Hook class. + * + */ class Hook { static public function register($hook,$file,$function,$version = 1,$priority = 0) { @@ -64,11 +69,14 @@ class Hook { return $r; } - // unregister all hooks with this file component. - // Useful for addon upgrades where you want to clean out old interfaces. - + /** + * @brief Unregister all hooks with this file component. + * + * Useful for addon upgrades where you want to clean out old interfaces. + * + * @param string $file + */ static public function unregister_by_file($file) { - $r = q("DELETE FROM hook WHERE file = '%s' ", dbesc($file) ); @@ -76,7 +84,6 @@ class Hook { return $r; } - /** * @brief Inserts a hook into a page request. * @@ -98,7 +105,6 @@ class Hook { * @param int $priority * currently not implemented in this function, would require the hook array to be resorted */ - static public function insert($hook, $fn, $version = 0, $priority = 0) { if(is_array($fn)) { $fn = serialize($fn); diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index 379e78a59..2e9bb0703 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -2,6 +2,11 @@ namespace Zotlabs\Lib; +/** + * @brief ActivityStreams class. + * + * Parses an ActivityStream JSON string. + */ class ActivityStreams { public $data; @@ -19,9 +24,16 @@ class ActivityStreams { public $recips = null; public $raw_recips = null; + /** + * @brief Constructor for ActivityStreams. + * + * Takes a JSON string as parameter, decodes it and sets up this object. + * + * @param string $string + */ function __construct($string) { - $this->data = json_decode($string,true); + $this->data = json_decode($string, true); if($this->data) { $this->valid = true; } @@ -50,6 +62,11 @@ class ActivityStreams { } } + /** + * @brief Return if instantiated ActivityStream is valid. + * + * @return boolean Return true if the JSON string could be decoded. + */ function is_valid() { return $this->valid; } @@ -58,18 +75,26 @@ class ActivityStreams { $this->saved_recips = $arr; } - function collect_recips($base = '',$namespace = '') { + /** + * @brief Collects all recipients. + * + * @param string $base + * @param string $namespace (optional) default empty + * @return array + */ + function collect_recips($base = '', $namespace = '') { $x = []; - $fields = [ 'to','cc','bto','bcc','audience']; + $fields = [ 'to', 'cc', 'bto', 'bcc', 'audience']; foreach($fields as $f) { - $y = $this->get_compound_property($f,$base,$namespace); + $y = $this->get_compound_property($f, $base, $namespace); if($y) { - $x = array_merge($x,$y); + $x = array_merge($x, $y); if(! is_array($this->raw_recips)) $this->raw_recips = []; + $this->raw_recips[$f] = $x; } - } + } // not yet ready for prime time // $x = $this->expand($x,$base,$namespace); return $x; @@ -96,23 +121,30 @@ class ActivityStreams { } } - // @fixme de-duplicate + /// @fixme de-duplicate return $ret; } - function get_namespace($base,$namespace) { + /** + * @brief + * + * @param array $base + * @param string $namespace if not set return empty string + * @return string|NULL + */ + function get_namespace($base, $namespace) { if(! $namespace) return ''; $key = null; - foreach( [ $this->data, $base ] as $b ) { if(! $b) continue; - if(array_key_exists('@context',$b)) { + + if(array_key_exists('@context', $b)) { if(is_array($b['@context'])) { foreach($b['@context'] as $ns) { if(is_array($ns)) { @@ -135,19 +167,35 @@ class ActivityStreams { } } } + return $key; } - - function get_property_obj($property,$base = '',$namespace = '' ) { - $prefix = $this->get_namespace($base,$namespace); + /** + * @brief + * + * @param string $property + * @param array $base (optional) + * @param string $namespace (optional) default empty + * @return NULL|mixed + */ + function get_property_obj($property, $base = '', $namespace = '') { + $prefix = $this->get_namespace($base, $namespace); if($prefix === null) - return null; + return null; + $base = (($base) ? $base : $this->data); $propname = (($prefix) ? $prefix . ':' : '') . $property; - return ((array_key_exists($propname,$base)) ? $base[$propname] : null); + + return ((array_key_exists($propname, $base)) ? $base[$propname] : null); } + /** + * @brief Fetches a property from an URL. + * + * @param string $url + * @return NULL|mixed + */ function fetch_property($url) { $redirects = 0; if(! check_siteallowed($url)) { @@ -155,44 +203,70 @@ class ActivityStreams { return null; } - $x = z_fetch_url($url,true,$redirects, + $x = z_fetch_url($url, true, $redirects, ['headers' => [ 'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams", application/activity+json' ]]); if($x['success']) - return json_decode($x['body'],true); + return json_decode($x['body'], true); + return null; } - function get_compound_property($property,$base = '',$namespace = '') { - $x = $this->get_property_obj($property,$base,$namespace); + /** + * @brief + * + * @param string $property + * @param array $base + * @param string $namespace (optional) default empty + * @return NULL|mixed + */ + function get_compound_property($property, $base = '', $namespace = '') { + $x = $this->get_property_obj($property, $base, $namespace); if($this->is_url($x)) { - $x = $this->fetch_property($x); + $x = $this->fetch_property($x); } + return $x; } + /** + * @brief Check if string starts with http. + * + * @param string $url + * @return boolean + */ function is_url($url) { - if(($url) && (! is_array($url)) && (strpos($url,'http') === 0)) { + if(($url) && (! is_array($url)) && (strpos($url, 'http') === 0)) { return true; } + return false; } - function get_primary_type($base = '',$namespace = '') { + /** + * @brief Gets the type property. + * + * @param array $base + * @param string $namespace (optional) default empty + * @return NULL|mixed + */ + function get_primary_type($base = '', $namespace = '') { if(! $base) $base = $this->data; - $x = $this->get_property_obj('type',$base,$namespace); + + $x = $this->get_property_obj('type', $base, $namespace); if(is_array($x)) { foreach($x as $y) { - if(strpos($y,':') === false) { + if(strpos($y, ':') === false) { return $y; } } } + return $x; } function debug() { - $x = var_export($this,true); + $x = var_export($this, true); return $x; } diff --git a/Zotlabs/Lib/Chatroom.php b/Zotlabs/Lib/Chatroom.php index e1a9a10b3..e762620ae 100644 --- a/Zotlabs/Lib/Chatroom.php +++ b/Zotlabs/Lib/Chatroom.php @@ -2,22 +2,18 @@ namespace Zotlabs\Lib; /** - * @brief Chat related functions. + * @brief A class with chatroom related static methods. */ - - - class Chatroom { /** * @brief Creates a chatroom. * * @param array $channel * @param array $arr - * @return An associative array containing: - * - success: A boolean - * - message: (optional) A string + * @return array An associative array containing: + * * \e boolean \b success - A boolean success status + * * \e string \b message - (optional) A string */ - static public function create($channel, $arr) { $ret = array('success' => false); @@ -150,8 +146,8 @@ class Chatroom { } if(intval($x[0]['cr_expire'])) { - $r = q("delete from chat where created < %s - INTERVAL %s and chat_room = %d", - db_utcnow(), + $r = q("delete from chat where created < %s - INTERVAL %s and chat_room = %d", + db_utcnow(), db_quoteinterval( intval($x[0]['cr_expire']) . ' MINUTE' ), intval($x[0]['cr_id']) ); @@ -225,10 +221,16 @@ class Chatroom { } /** - * create a chat message via API. + * @brief Create a chat message via API. + * * It is the caller's responsibility to enter the room. - */ - + * + * @param int $uid + * @param int $room_id + * @param string $xchan + * @param string $text + * @return array + */ static public function message($uid, $room_id, $xchan, $text) { $ret = array('success' => false); @@ -245,12 +247,18 @@ class Chatroom { if(! $r) return $ret; - $arr = array( + $arr = [ 'chat_room' => $room_id, 'chat_xchan' => $xchan, 'chat_text' => $text - ); - + ]; + /** + * @hooks chat_message + * Called to create a chat message. + * * \e int \b chat_room + * * \e string \b chat_xchan + * * \e string \b chat_text + */ call_hooks('chat_message', $arr); $x = q("insert into chat ( chat_room, chat_xchan, created, chat_text ) diff --git a/Zotlabs/Lib/Config.php b/Zotlabs/Lib/Config.php index 6e042feba..f9f22ba3a 100644 --- a/Zotlabs/Lib/Config.php +++ b/Zotlabs/Lib/Config.php @@ -1,4 +1,4 @@ -PConfig is used for channel specific configurations and takes a + * channel_id as identifier. It stores for example which features are + * enabled per channel. The storage is of size MEDIUMTEXT. + * + * @code{.php}$var = Zotlabs\Lib\PConfig::Get('uid', 'category', 'key'); + * // with default value for non existent key + * $var = Zotlabs\Lib\PConfig::Get('uid', 'category', 'unsetkey', 'defaultvalue');@endcode + * + * The old (deprecated?) way to access a PConfig value is: + * @code{.php}$var = get_pconfig(local_channel(), 'category', 'key');@endcode + */ class PConfig { /** @@ -13,9 +26,8 @@ class PConfig { * * @param string $uid * The channel_id - * @return void|false Nothing or false if $uid is false + * @return void|false Nothing or false if $uid is null or false */ - static public function Load($uid) { if(is_null($uid) || $uid === false) return false; @@ -64,11 +76,11 @@ class PConfig { * The category of the configuration value * @param string $key * The configuration key to query - * @param boolean $instore (deprecated, without function) + * @param mixed $default (optional, default false) + * Default value to return if key does not exist * @return mixed Stored value or false if it does not exist */ - - static public function Get($uid,$family,$key,$default = false) { + static public function Get($uid, $family, $key, $default = false) { if(is_null($uid) || $uid === false) return $default; @@ -79,11 +91,10 @@ class PConfig { if((! array_key_exists($family, \App::$config[$uid])) || (! array_key_exists($key, \App::$config[$uid][$family]))) return $default; - return ((! is_array(\App::$config[$uid][$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', \App::$config[$uid][$family][$key])) + return ((! is_array(\App::$config[$uid][$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', \App::$config[$uid][$family][$key])) ? unserialize(\App::$config[$uid][$family][$key]) : \App::$config[$uid][$family][$key] ); - } /** @@ -102,12 +113,11 @@ class PConfig { * The value to store * @return mixed Stored $value or false */ - static public function Set($uid, $family, $key, $value) { - // this catches subtle errors where this function has been called + // this catches subtle errors where this function has been called // with local_channel() when not logged in (which returns false) - // and throws an error in array_key_exists below. + // and throws an error in array_key_exists below. // we provide a function backtrace in the logs so that we can find // and fix the calling function. @@ -132,7 +142,6 @@ class PConfig { dbesc($key), dbesc($dbvalue) ); - } else { @@ -142,7 +151,6 @@ class PConfig { dbesc($family), dbesc($key) ); - } // keep a separate copy for all variables which were @@ -178,7 +186,6 @@ class PConfig { * The configuration key to delete * @return mixed */ - static public function Delete($uid, $family, $key) { if(is_null($uid) || $uid === false) @@ -186,12 +193,12 @@ class PConfig { $ret = false; - if(array_key_exists($uid,\App::$config) - && is_array(\App::$config['uid']) - && array_key_exists($family,\App::$config['uid']) + if(array_key_exists($uid,\App::$config) + && is_array(\App::$config['uid']) + && array_key_exists($family,\App::$config['uid']) && array_key_exists($key, \App::$config[$uid][$family])) unset(\App::$config[$uid][$family][$key]); - + $ret = q("DELETE FROM pconfig WHERE uid = %d AND cat = '%s' AND k = '%s'", intval($uid), dbesc($family), @@ -202,4 +209,3 @@ class PConfig { } } - \ No newline at end of file diff --git a/Zotlabs/Lib/SConfig.php b/Zotlabs/Lib/SConfig.php index ca0d133b2..ab6f49025 100644 --- a/Zotlabs/Lib/SConfig.php +++ b/Zotlabs/Lib/SConfig.php @@ -2,8 +2,11 @@ namespace Zotlabs\Lib; -// account configuration storage is built on top of the under-utilised xconfig - +/** + * @brief Account configuration storage is built on top of the under-utilised xconfig. + * + * @see XConfig + */ class SConfig { static public function Load($server_id) { diff --git a/Zotlabs/Lib/XConfig.php b/Zotlabs/Lib/XConfig.php index bf78c360f..c5a108ac9 100644 --- a/Zotlabs/Lib/XConfig.php +++ b/Zotlabs/Lib/XConfig.php @@ -2,7 +2,26 @@ namespace Zotlabs\Lib; - +/** + * @brief Class for handling observer's config. + * + * XConfig is comparable to PConfig, except that it uses xchan + * (an observer hash) as an identifier. + * + * XConfig is used for observer specific configurations and takes a + * xchan as identifier. + * The storage is of size MEDIUMTEXT. + * + * @code{.php}$var = Zotlabs\Lib\XConfig::Get('xchan', 'category', 'key'); + * // with default value for non existent key + * $var = Zotlabs\Lib\XConfig::Get('xchan', 'category', 'unsetkey', 'defaultvalue');@endcode + * + * The old (deprecated?) way to access a XConfig value is: + * @code{.php}$observer = App::get_observer_hash(); + * if ($observer) { + * $var = get_xconfig($observer, 'category', 'key'); + * }@endcode + */ class XConfig { /** @@ -15,7 +34,6 @@ class XConfig { * The observer's hash * @return void|false Returns false if xchan is not set */ - static public function Load($xchan) { if(! $xchan) @@ -56,9 +74,9 @@ class XConfig { * The category of the configuration value * @param string $key * The configuration key to query + * @param boolean $default (optional) default false * @return mixed Stored $value or false if it does not exist */ - static public function Get($xchan, $family, $key, $default = false) { if(! $xchan) @@ -70,7 +88,7 @@ class XConfig { if((! array_key_exists($family, \App::$config[$xchan])) || (! array_key_exists($key, \App::$config[$xchan][$family]))) return $default; - return ((! is_array(\App::$config[$xchan][$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', \App::$config[$xchan][$family][$key])) + return ((! is_array(\App::$config[$xchan][$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', \App::$config[$xchan][$family][$key])) ? unserialize(\App::$config[$xchan][$family][$key]) : \App::$config[$xchan][$family][$key] ); @@ -82,7 +100,6 @@ class XConfig { * Stores a config value ($value) in the category ($family) under the key ($key) * for the observer's $xchan hash. * - * * @param string $xchan * The observer's hash * @param string $family @@ -93,7 +110,6 @@ class XConfig { * The value to store * @return mixed Stored $value or false */ - static public function Set($xchan, $family, $key, $value) { // manage array value @@ -106,7 +122,7 @@ class XConfig { if(! array_key_exists($family, \App::$config[$xchan])) \App::$config[$xchan][$family] = array(); - $ret = q("INSERT INTO xconfig ( xchan, cat, k, v ) VALUES ( '%s', '%s', '%s', '%s' ) ", + $ret = q("INSERT INTO xconfig ( xchan, cat, k, v ) VALUES ( '%s', '%s', '%s', '%s' )", dbesc($xchan), dbesc($family), dbesc($key), @@ -126,6 +142,7 @@ class XConfig { if($ret) return $value; + return $ret; } @@ -143,11 +160,11 @@ class XConfig { * The configuration key to delete * @return mixed */ - static public function Delete($xchan, $family, $key) { if(x(\App::$config[$xchan][$family], $key)) unset(\App::$config[$xchan][$family][$key]); + $ret = q("DELETE FROM xconfig WHERE xchan = '%s' AND cat = '%s' AND k = '%s'", dbesc($xchan), dbesc($family), diff --git a/Zotlabs/Render/Comanche.php b/Zotlabs/Render/Comanche.php index 78ca870a7..cd06e11a8 100644 --- a/Zotlabs/Render/Comanche.php +++ b/Zotlabs/Render/Comanche.php @@ -5,10 +5,20 @@ namespace Zotlabs\Render; require_once('include/security.php'); require_once('include/menu.php'); - +/** + * @brief Comanche Page Description Language. + * + * Comanche is a markup language similar to bbcode with which to create elaborate + * and complex web pages by assembling them from a series of components - some of + * which are pre-built and others which can be defined on the fly. Comanche uses + * a Page Decription Language to create these pages. + * + * Comanche primarily chooses what content will appear in various regions of the + * page. The various regions have names and these names can change depending on + * what layout template you choose. + */ class Comanche { - function parse($s, $pass = 0) { $matches = array(); @@ -18,13 +28,13 @@ class Comanche { $s = str_replace($mtch[0], '', $s); } } - + /* - * This section supports the "switch" statement of the form given by the following - * example. The [default][/default] block must be the last in the arbitrary + * This section supports the "switch" statement of the form given by the following + * example. The [default][/default] block must be the last in the arbitrary * list of cases. The first case that matches the switch variable is used * and the rest are not evaluated. - * + * * [switch observer.language] * [case de] * [block]german-content[/block] @@ -37,7 +47,7 @@ class Comanche { * [/default] * [/switch] */ - + $cnt = preg_match_all("/\[switch (.*?)\](.*?)\[default\](.*?)\[\/default\]\s*\[\/switch\]/ism", $s, $matches, PREG_SET_ORDER); if($cnt) { foreach($matches as $mtch) { @@ -60,7 +70,7 @@ class Comanche { } } } - + $cnt = preg_match_all("/\[if (.*?)\](.*?)\[else\](.*?)\[\/if\]/ism", $s, $matches, PREG_SET_ORDER); if($cnt) { foreach($matches as $mtch) { @@ -89,7 +99,6 @@ class Comanche { $this->parse_pass0($s); else $this->parse_pass1($s); - } function parse_pass0($s) { @@ -103,7 +112,7 @@ class Comanche { $cnt = preg_match("/\[template=(.*?)\](.*?)\[\/template\]/ism", $s, $matches); if($cnt) { \App::$page['template'] = trim($matches[2]); - \App::$page['template_style'] = trim($matches[2]) . '_' . $matches[1]; + \App::$page['template_style'] = trim($matches[2]) . '_' . $matches[1]; } $cnt = preg_match("/\[template\](.*?)\[\/template\]/ism", $s, $matches); @@ -145,20 +154,23 @@ class Comanche { } /** + * @brief Replace conditional variables with real values. + * * Currently supported condition variables: + * * $config.xxx.yyy - get_config with cat = xxx and k = yyy + * * $request - request uri for this page + * * $observer.language - viewer's preferred language (closest match) + * * $observer.address - xchan_addr or false + * * $observer.name - xchan_name or false + * * $observer - xchan_hash of observer or empty string + * * $local_channel - logged in channel_id or false * - * $config.xxx.yyy - get_config with cat = xxx and k = yyy - * $request - request uri for this page - * $observer.language - viewer's preferred language (closest match) - * $observer.address - xchan_addr or false - * $observer.name - xchan_name or false - * $observer - xchan_hash of observer or empty string - * $local_channel - logged in channel_id or false + * @param string $v The conditional variable name + * @return string|boolean */ - function get_condition_var($v) { if($v) { - $x = explode('.',$v); + $x = explode('.', $v); if($x[0] == 'config') return get_config($x[1],$x[2]); elseif($x[0] === 'request') @@ -179,6 +191,7 @@ class Comanche { return $y['xchan_name']; elseif($x[1] == 'webname') return substr($y['xchan_addr'],0,strpos($y['xchan_addr'],'@')); + return false; } return get_observer_hash(); @@ -186,30 +199,39 @@ class Comanche { else return false; } + return false; } + /** + * @brief Test for Conditional Execution conditions. + * + * This is extensible. The first version of variable testing supports tests of the forms: + * + * - [if $config.system.foo ~= baz] which will check if get_config('system','foo') contains the string 'baz'; + * - [if $config.system.foo == baz] which will check if get_config('system','foo') is the string 'baz'; + * - [if $config.system.foo != baz] which will check if get_config('system','foo') is not the string 'baz'; + * - [if $config.system.foo >= 3] which will check if get_config('system','foo') is greater than or equal to 3; + * - [if $config.system.foo > 3] which will check if get_config('system','foo') is greater than 3; + * - [if $config.system.foo <= 3] which will check if get_config('system','foo') is less than or equal to 3; + * - [if $config.system.foo < 3] which will check if get_config('system','foo') is less than 3; + * + * - [if $config.system.foo {} baz] which will check if 'baz' is an array element in get_config('system','foo') + * - [if $config.system.foo {*} baz] which will check if 'baz' is an array key in get_config('system','foo') + * - [if $config.system.foo] which will check for a return of a true condition for get_config('system','foo'); + * + * The values 0, '', an empty array, and an unset value will all evaluate to false. + * + * @param int|string $s + * @return boolean + */ function test_condition($s) { - // This is extensible. The first version of variable testing supports tests of the forms: - - // [if $config.system.foo ~= baz] which will check if get_config('system','foo') contains the string 'baz'; - // [if $config.system.foo == baz] which will check if get_config('system','foo') is the string 'baz'; - // [if $config.system.foo != baz] which will check if get_config('system','foo') is not the string 'baz'; - // [if $config.system.foo >= 3] which will check if get_config('system','foo') is greater than or equal to 3; - // [if $config.system.foo > 3] which will check if get_config('system','foo') is greater than 3; - - // [if $config.system.foo <= 3] which will check if get_config('system','foo') is less than or equal to 3; - // [if $config.system.foo < 3] which will check if get_config('system','foo') is less than 3; - - // [if $config.system.foo {} baz] which will check if 'baz' is an array element in get_config('system','foo') - // [if $config.system.foo {*} baz] which will check if 'baz' is an array key in get_config('system','foo') - // [if $config.system.foo] which will check for a return of a true condition for get_config('system','foo'); - // The values 0, '', an empty array, and an unset value will all evaluate to false. if(preg_match('/[\$](.*?)\s\~\=\s(.*?)$/',$s,$matches)) { $x = $this->get_condition_var($matches[1]); if(stripos($x,trim($matches[2])) !== false) return true; + return false; } @@ -217,6 +239,7 @@ class Comanche { $x = $this->get_condition_var($matches[1]); if($x == trim($matches[2])) return true; + return false; } @@ -224,6 +247,7 @@ class Comanche { $x = $this->get_condition_var($matches[1]); if($x != trim($matches[2])) return true; + return false; } @@ -231,24 +255,31 @@ class Comanche { $x = $this->get_condition_var($matches[1]); if($x >= trim($matches[2])) return true; + return false; } + if(preg_match('/[\$](.*?)\s\<\=\s(.*?)$/',$s,$matches)) { $x = $this->get_condition_var($matches[1]); if($x <= trim($matches[2])) return true; + return false; } + if(preg_match('/[\$](.*?)\s\>\s(.*?)$/',$s,$matches)) { $x = $this->get_condition_var($matches[1]); if($x > trim($matches[2])) return true; + return false; } + if(preg_match('/[\$](.*?)\s\>\s(.*?)$/',$s,$matches)) { $x = $this->get_condition_var($matches[1]); if($x < trim($matches[2])) return true; + return false; } @@ -256,6 +287,7 @@ class Comanche { $x = $this->get_condition_var($matches[1]); if(is_array($x) && in_array(trim($matches[2]),$x)) return true; + return false; } @@ -263,6 +295,7 @@ class Comanche { $x = $this->get_condition_var($matches[1]); if(is_array($x) && array_key_exists(trim($matches[2]),$x)) return true; + return false; } @@ -270,13 +303,21 @@ class Comanche { $x = $this->get_condition_var($matches[1]); if($x) return true; + return false; } - return false; + return false; } - + /** + * @brief Return rendered menu for current channel_id. + * + * @see menu_render() + * @param string $s + * @param string $class (optional) default empty + * @return string + */ function menu($s, $class = '') { $channel_id = $this->get_channel_id(); @@ -291,7 +332,7 @@ class Comanche { } if($channel_id) { - $m = menu_fetch($name,$channel_id, get_observer_hash()); + $m = menu_fetch($name, $channel_id, get_observer_hash()); return menu_render($m, $class, $edit = false, $var); } } @@ -309,9 +350,8 @@ class Comanche { * Returns the channel_id of the profile owner of the page, or the local_channel * if there is no profile owner. Otherwise returns 0. * - * @return channel_id + * @return int channel_id */ - function get_channel_id() { $channel_id = ((is_array(\App::$profile)) ? \App::$profile['profile_uid'] : 0); @@ -321,6 +361,13 @@ class Comanche { return $channel_id; } + /** + * @brief Returns a parsed block. + * + * @param string $s + * @param string $class (optional) default empty + * @return string parsed HTML of block + */ function block($s, $class = '') { $var = array(); $matches = array(); @@ -339,7 +386,7 @@ class Comanche { $channel_id = $this->get_channel_id(); if($channel_id) { - $r = q("select * from item inner join iconfig on iconfig.iid = item.id and item.uid = %d + $r = q("select * from item inner join iconfig on iconfig.iid = item.id and item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'BUILDBLOCK' and iconfig.v = '%s' limit 1", intval($channel_id), dbesc($name) @@ -381,6 +428,12 @@ class Comanche { return $o; } + /** + * @brief Include JS depending on framework. + * + * @param string $s + * @return string + */ function js($s) { switch($s) { @@ -401,9 +454,14 @@ class Comanche { $ret .= $init; return $ret; - } + /** + * @brief Include CSS depending on framework. + * + * @param string $s + * @return string + */ function css($s) { switch($s) { @@ -418,17 +476,22 @@ class Comanche { $ret = ''; return $ret; - } - // This doesn't really belong in Comanche, but it could also be argued that it is the perfect place. - // We need to be able to select what kind of template and decoration to use for the webpage at the heart of our content. - // For now we'll allow an '[authored]' element which defaults to name and date, or 'none' to remove these, and perhaps - // 'full' to provide a social network style profile photo. - // But leave it open to have richer templating options and perhaps ultimately discard this one, once we have a better idea - // of what template and webpage options we might desire. - - function webpage(&$a,$s) { + /** + * This doesn't really belong in Comanche, but it could also be argued that it is the perfect place. + * We need to be able to select what kind of template and decoration to use for the webpage at the heart of our content. + * For now we'll allow an '[authored]' element which defaults to name and date, or 'none' to remove these, and perhaps + * 'full' to provide a social network style profile photo. + * + * But leave it open to have richer templating options and perhaps ultimately discard this one, once we have a better idea + * of what template and webpage options we might desire. + * + * @param[in,out] array $a + * @param string $s + * @return array + */ + function webpage(&$a, $s) { $ret = array(); $matches = array(); @@ -438,22 +501,20 @@ class Comanche { $ret['authored'] = $mtch[1]; } } + return $ret; } - /** - * Render a widget + * @brief Render a widget. * * @param string $name * @param string $text */ - function widget($name, $text) { $vars = array(); $matches = array(); - $cnt = preg_match_all("/\[var=(.*?)\](.*?)\[\/var\]/ism", $text, $matches, PREG_SET_ORDER); if ($cnt) { foreach ($matches as $mtch) { @@ -480,7 +541,7 @@ class Comanche { if(method_exists($x,$f)) { return $x->$f($vars); } - } + } $func = 'widget_' . trim($name); @@ -563,9 +624,9 @@ class Comanche { } - /* - * @function register_page_template($arr) - * Registers a page template/variant for use by Comanche selectors + /** + * @brief Registers a page template/variant for use by Comanche selectors. + * * @param array $arr * 'template' => template name * 'variant' => array( @@ -577,8 +638,6 @@ class Comanche { * ) * ) */ - - function register_page_template($arr) { \App::$page_layouts[$arr['template']] = array($arr['variant']); return; diff --git a/Zotlabs/Web/Router.php b/Zotlabs/Web/Router.php index 9486130cb..12ef315d4 100644 --- a/Zotlabs/Web/Router.php +++ b/Zotlabs/Web/Router.php @@ -2,6 +2,8 @@ namespace Zotlabs\Web; +use Exception; + /** * * We have already parsed the server path into App::$argc and App::$argv @@ -34,7 +36,7 @@ class Router { private $controller = null; /** - * @brief Router constructor + * @brief Router constructor. * * @param[in,out] App &$a * @throws Exception module not found @@ -98,15 +100,23 @@ class Router { } } - /* - * This provides a place for plugins to register module handlers which don't otherwise exist - * on the system, or to completely over-ride an existing module. - * If the plugin sets 'installed' to true we won't throw a 404 error for the specified module even if - * there is no specific module file or matching plugin name. - * The plugin should catch at least one of the module hooks for this URL. + $x = [ + 'module' => $module, + 'installed' => \App::$module_loaded, + 'controller' => $this->controller + ]; + /** + * @hooks module_loaded + * Called when a module has been successfully locate to server a URL request. + * This provides a place for plugins to register module handlers which don't otherwise exist + * on the system, or to completely over-ride an existing module. + * If the plugin sets 'installed' to true we won't throw a 404 error for the specified module even if + * there is no specific module file or matching plugin name. + * The plugin should catch at least one of the module hooks for this URL. + * * \e string \b module + * * \e boolean \b installed + * * \e mixed \b controller - The initialized module object */ - - $x = array('module' => $module, 'installed' => \App::$module_loaded, 'controller' => $this->controller); call_hooks('module_loaded', $x); if($x['installed']) { \App::$module_loaded = true; @@ -131,14 +141,14 @@ class Router { } } - $x = [ - 'module' => $module, - 'installed' => \App::$module_loaded, + $x = [ + 'module' => $module, + 'installed' => \App::$module_loaded, 'controller' => $this->controller ]; call_hooks('page_not_found',$x); - // Stupid browser tried to pre-fetch our Javascript img template. + // Stupid browser tried to pre-fetch our Javascript img template. // Don't log the event or return anything - just quietly exit. if((x($_SERVER, 'QUERY_STRING')) && preg_match('/{[0-9]}/', $_SERVER['QUERY_STRING']) !== 0) { @@ -147,8 +157,8 @@ class Router { if(get_config('system','log_404',true)) { logger("Module {$module} not found.", LOGGER_DEBUG, LOG_WARNING); - logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] - . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' + logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] + . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG); } diff --git a/Zotlabs/Zot/Verify.php b/Zotlabs/Zot/Verify.php index 1d9e6de3f..7abe38d17 100644 --- a/Zotlabs/Zot/Verify.php +++ b/Zotlabs/Zot/Verify.php @@ -26,12 +26,11 @@ class Verify { q("delete from verify where id = %d", intval($r[0]['id']) ); - return true; + return true; } return false; } - function get_meta($type,$channel_id,$token) { $r = q("select id, meta from verify where vtype = '%s' and channel = %d and token = '%s' limit 1", dbesc($type), @@ -42,12 +41,18 @@ class Verify { q("delete from verify where id = %d", intval($r[0]['id']) ); - return $r[0]['meta']; + return $r[0]['meta']; } return false; } - function purge($type,$interval) { + /** + * @brief Purge entries of a verify-type older than interval. + * + * @param string $type Verify type + * @param string $interval SQL compatible time interval + */ + function purge($type, $interval) { q("delete from verify where vtype = '%s' and created < %s - INTERVAL %s", dbesc($type), db_utcnow(), -- cgit v1.2.3