From d9e9cbe7534ec05a131ac250ef9912cdaf7078ee Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Sun, 19 Nov 2017 14:15:25 -0500 Subject: [PATCH] Coding Standards A few updates for coding standards --- include/conversation.php | 4 +- index.php | 106 +++++++++---------- mod/smilies.php | 4 +- src/Content/Smilies.php | 24 +++-- src/Core/BaseObject.php | 8 +- src/Core/Cache.php | 4 + src/Core/Config.php | 53 +++++----- src/Core/Conversation.php | 77 +++++++++----- src/Core/Item.php | 163 ++++++++++++++++++++++-------- src/Core/NotificationsManager.php | 72 +++++++------ src/Core/PConfig.php | 67 ++++++------ src/Core/System.php | 24 +++-- 12 files changed, 357 insertions(+), 249 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 9f6cfa0f5..218d7405b 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -905,11 +905,11 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { if ($item['id'] == $item['parent']) { $item_object = new Item($item); - $conv->add_thread($item_object); + $conv->addThread($item_object); } } - $threads = $conv->get_template_data($conv_responses); + $threads = $conv->getTemplateData($conv_responses); if (!$threads) { logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG); diff --git a/index.php b/index.php index c31b1adc0..5e8860afd 100644 --- a/index.php +++ b/index.php @@ -20,7 +20,7 @@ require_once 'boot.php'; if (empty($a)) { $a = new App(__DIR__); } -BaseObject::set_app($a); +BaseObject::setApp($a); // We assume that the index.php is called by a frontend process // The value is set to "true" by default in boot.php @@ -40,9 +40,7 @@ if (!$install) { } /** - * * Try to open the database; - * */ require_once "include/dba.php"; @@ -64,9 +62,10 @@ if (!$install) { die("System is currently unavailable. Please try again later"); } - if (Config::get('system', 'force_ssl') && ($a->get_scheme() == "http") && - (intval(Config::get('system', 'ssl_policy')) == SSL_POLICY_FULL) && - (substr(System::baseUrl(), 0, 8) == "https://")) { + if (Config::get('system', 'force_ssl') && ($a->get_scheme() == "http") + && (intval(Config::get('system', 'ssl_policy')) == SSL_POLICY_FULL) + && (substr(System::baseUrl(), 0, 8) == "https://") + ) { header("HTTP/1.1 302 Moved Temporarily"); header("Location: " . System::baseUrl() . "/" . $a->query_string); exit(); @@ -84,14 +83,12 @@ $lang = get_browser_language(); load_translation_table($lang); /** - * * Important stuff we always need to do. * * The order of these may be important so use caution if you think they're all * intertwingled with no logical order and decide to sort it out. Some of the * dependencies have changed, but at least at one time in the recent past - the * order was critical to everything working properly - * */ // Exclude the backend processes from the session management @@ -107,7 +104,7 @@ if (!$a->is_backend()) { * Language was set earlier, but we can over-ride it in the session. * We have to do it here because the session was just now opened. */ -if (x($_SESSION,'authenticated') && !x($_SESSION,'language')) { +if (x($_SESSION, 'authenticated') && !x($_SESSION, 'language')) { // we didn't loaded user data yet, but we need user language $r = dba::select('user', array('language'), array('uid' => $_SESSION['uid']), array('limit' => 1)); $_SESSION['language'] = $lang; @@ -116,18 +113,19 @@ if (x($_SESSION,'authenticated') && !x($_SESSION,'language')) { } } -if ((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) { +if ((x($_SESSION, 'language')) && ($_SESSION['language'] !== $lang)) { $lang = $_SESSION['language']; load_translation_table($lang); } -if ((x($_GET,'zrl')) && (!$install && !$maintenance)) { +if ((x($_GET, 'zrl')) && (!$install && !$maintenance)) { // Only continue when the given profile link seems valid // Valid profile links contain a path with "/profile/" and no query parameters - if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "") && - strstr(parse_url($_GET['zrl'], PHP_URL_PATH), "/profile/")) { + if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "") + && strstr(parse_url($_GET['zrl'], PHP_URL_PATH), "/profile/") + ) { $_SESSION['my_url'] = $_GET['zrl']; - $a->query_string = preg_replace('/[\?&]zrl=(.*?)([\?&]|$)/is','',$a->query_string); + $a->query_string = preg_replace('/[\?&]zrl=(.*?)([\?&]|$)/is', '', $a->query_string); zrl_init($a); } else { // Someone came with an invalid parameter, maybe as a DDoS attempt @@ -140,23 +138,21 @@ if ((x($_GET,'zrl')) && (!$install && !$maintenance)) { } /** - * * For Mozilla auth manager - still needs sorting, and this might conflict with LRDD header. * Apache/PHP lumps the Link: headers into one - and other services might not be able to parse it * this way. There's a PHP flag to link the headers because by default this will over-write any other * link header. * * What we really need to do is output the raw headers ourselves so we can keep them separate. - * */ // header('Link: <' . System::baseUrl() . '/amcd>; rel="acct-mgmt";'); -if (x($_COOKIE["Friendica"]) || (x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login')) { - require("include/auth.php"); +if (x($_COOKIE["Friendica"]) || (x($_SESSION, 'authenticated')) || (x($_POST, 'auth-params')) || ($a->module === 'login')) { + require "include/auth.php"; } -if (! x($_SESSION,'authenticated')) { +if (! x($_SESSION, 'authenticated')) { header('X-Account-Management-Status: none'); } @@ -165,16 +161,16 @@ $a->page['htmlhead'] = ''; $a->page['end'] = ''; -if (! x($_SESSION,'sysmsg')) { +if (! x($_SESSION, 'sysmsg')) { $_SESSION['sysmsg'] = array(); } -if (! x($_SESSION,'sysmsg_info')) { +if (! x($_SESSION, 'sysmsg_info')) { $_SESSION['sysmsg_info'] = array(); } // Array for informations about last received items -if (! x($_SESSION,'last_updated')) { +if (! x($_SESSION, 'last_updated')) { $_SESSION['last_updated'] = array(); } /* @@ -198,7 +194,7 @@ if ($install && $a->module!="view") { nav_set_selected('nothing'); //Don't populate apps_menu if apps are private -$privateapps = Config::get('config','private_addons'); +$privateapps = Config::get('config', 'private_addons'); if ((local_user()) || (! $privateapps === "1")) { $arr = array('app_menu' => $a->apps); @@ -208,7 +204,6 @@ if ((local_user()) || (! $privateapps === "1")) { } /** - * * We have already parsed the server path into $a->argc and $a->argv * * $a->argv[0] is our module name. We will load the file mod/{$a->argv[0]}.php @@ -229,10 +224,8 @@ if ((local_user()) || (! $privateapps === "1")) { if (strlen($a->module)) { /** - * * We will always have a module name. * First see if we have a plugin which is masquerading as a module. - * */ // Compatibility with the Android Diaspora client @@ -245,14 +238,14 @@ if (strlen($a->module)) { $a->module = "login"; } - $privateapps = Config::get('config','private_addons'); + $privateapps = Config::get('config', 'private_addons'); - if (is_array($a->plugins) && in_array($a->module,$a->plugins) && file_exists("addon/{$a->module}/{$a->module}.php")) { + if (is_array($a->plugins) && in_array($a->module, $a->plugins) && file_exists("addon/{$a->module}/{$a->module}.php")) { //Check if module is an app and if public access to apps is allowed or not if ((!local_user()) && plugin_is_app($a->module) && $privateapps === "1") { - info( t("You must be logged in to use addons. ")); + info(t("You must be logged in to use addons. ")); } else { - include_once("addon/{$a->module}/{$a->module}.php"); + include_once "addon/{$a->module}/{$a->module}.php"; if (function_exists($a->module . '_module')) { $a->module_loaded = true; } @@ -264,12 +257,11 @@ if (strlen($a->module)) { */ if ((! $a->module_loaded) && (file_exists("mod/{$a->module}.php"))) { - include_once("mod/{$a->module}.php"); + include_once "mod/{$a->module}.php"; $a->module_loaded = true; } /** - * * The URL provided does not resolve to a valid module. * * On Dreamhost sites, quite often things go wrong for no apparent reason and they send us to '/internal_error.html'. @@ -278,17 +270,15 @@ if (strlen($a->module)) { * this will often succeed and eventually do the right thing. * * Otherwise we are going to emit a 404 not found. - * */ if (! $a->module_loaded) { - // 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) { + if ((x($_SERVER, 'QUERY_STRING')) && preg_match('/{[0-9]}/', $_SERVER['QUERY_STRING']) !== 0) { killme(); } - if ((x($_SERVER,'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) { + if ((x($_SERVER, 'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) { logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI']); goaway(System::baseUrl() . $_SERVER['REQUEST_URI']); } @@ -296,29 +286,31 @@ if (strlen($a->module)) { logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG); header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . t('Not Found')); $tpl = get_markup_template("404.tpl"); - $a->page['content'] = replace_macros($tpl, array( - '$message' => t('Page not found.' ) - )); + $a->page['content'] = replace_macros( + $tpl, + array( + '$message' => t('Page not found.')) + ); } } /** - * load current theme info + * Load current theme info */ $theme_info_file = "view/theme/".current_theme()."/theme.php"; -if (file_exists($theme_info_file)){ - require_once($theme_info_file); +if (file_exists($theme_info_file)) { + require_once $theme_info_file; } /* initialise content region */ -if (! x($a->page,'content')) { +if (! x($a->page, 'content')) { $a->page['content'] = ''; } if (!$install && !$maintenance) { - call_hooks('page_content_top',$a->page['content']); + call_hooks('page_content_top', $a->page['content']); } /** @@ -335,21 +327,22 @@ if ($a->module_loaded) { $func($a); } - if (function_exists(str_replace('-','_',current_theme()) . '_init')) { - $func = str_replace('-','_',current_theme()) . '_init'; + if (function_exists(str_replace('-', '_', current_theme()) . '_init')) { + $func = str_replace('-', '_', current_theme()) . '_init'; $func($a); } if (($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error) && (function_exists($a->module . '_post')) - && (! x($_POST,'auth-params'))) { + && (! x($_POST, 'auth-params')) + ) { call_hooks($a->module . '_mod_post', $_POST); $func = $a->module . '_post'; $func($a); } if ((! $a->error) && (function_exists($a->module . '_afterpost'))) { - call_hooks($a->module . '_mod_afterpost',$placeholder); + call_hooks($a->module . '_mod_afterpost', $placeholder); $func = $a->module . '_afterpost'; $func($a); } @@ -364,8 +357,8 @@ if ($a->module_loaded) { $a->page['content'] .= $arr['content']; } - if (function_exists(str_replace('-','_',current_theme()) . '_content_loaded')) { - $func = str_replace('-','_',current_theme()) . '_content_loaded'; + if (function_exists(str_replace('-', '_', current_theme()) . '_content_loaded')) { + $func = str_replace('-', '_', current_theme()) . '_content_loaded'; $func($a); } } @@ -427,10 +420,12 @@ if ($a->is_mobile || $a->is_tablet) { } else { $link = 'toggle_mobile?off=1&address=' . curPageURL(); } - $a->page['footer'] = replace_macros(get_markup_template("toggle_mobile_footer.tpl"), array( - '$toggle_link' => $link, - '$toggle_text' => t('toggle mobile') - )); + $a->page['footer'] = replace_macros( + get_markup_template("toggle_mobile_footer.tpl"), + array( + '$toggle_link' => $link, + '$toggle_text' => t('toggle mobile')) + ); } /** @@ -443,7 +438,7 @@ if (!$a->theme['stylesheet']) { $stylesheet = $a->theme['stylesheet']; } -$a->page['htmlhead'] = str_replace('{{$stylesheet}}',$stylesheet,$a->page['htmlhead']); +$a->page['htmlhead'] = str_replace('{{$stylesheet}}', $stylesheet, $a->page['htmlhead']); //$a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => $stylesheet)); if (isset($_GET["mode"]) && (($_GET["mode"] == "raw") || ($_GET["mode"] == "minimal"))) { @@ -470,7 +465,6 @@ if (isset($_GET["mode"]) && (($_GET["mode"] == "raw") || ($_GET["mode"] == "mini } if (isset($_GET["mode"]) && ($_GET["mode"] == "raw")) { - header("Content-type: text/html; charset=utf-8"); echo substr($target->saveHTML(), 6, -8); diff --git a/mod/smilies.php b/mod/smilies.php index 04bdbe88e..50d6836f7 100644 --- a/mod/smilies.php +++ b/mod/smilies.php @@ -6,10 +6,10 @@ use Friendica\App; use Friendica\Content\Smilies; -function smilies_content(App $a) +function smiliesContent(App $a) { if ($a->argv[1] === "json") { - $tmp = Smilies::get_list(); + $tmp = Smilies::getList(); $results = array(); for ($i = 0; $i < count($tmp['texts']); $i++) { $results[] = array('text' => $tmp['texts'][$i], 'icon' => $tmp['icons'][$i]); diff --git a/src/Content/Smilies.php b/src/Content/Smilies.php index 464b5ee83..ce785d66f 100644 --- a/src/Content/Smilies.php +++ b/src/Content/Smilies.php @@ -33,6 +33,8 @@ class Smilies * @param array $b Array of emoticons * @param string $smiley The text smilie * @param string $representation The replacement + * + * @return void */ public static function add(&$b, $smiley, $representation) { @@ -57,7 +59,7 @@ class Smilies * * @hook smilie ('texts' => smilies texts array, 'icons' => smilies html array) */ - public static function get_list() + public static function getList() { $texts = array( '<3', @@ -154,7 +156,7 @@ class Smilies * bbcode source for HTML display * * @param string $s Text that should be replaced - * @param boolean $sample + * @param boolean $sample optional, default false * @param boolean $no_images Only replace emoticons without images * * @return string HML Output of the Smilie @@ -170,7 +172,7 @@ class Smilies $s = preg_replace_callback('/
(.*?)<\/pre>/ism', 'self::encode', $s);
 		$s = preg_replace_callback('/(.*?)<\/code>/ism', 'self::encode', $s);
 
-		$params = self::get_list();
+		$params = self::getList();
 
 		if ($no_images) {
 			$cleaned = array('texts' => array(), 'icons' => array());
@@ -192,7 +194,7 @@ class Smilies
 				$s .= '
' . $params['texts'][$x] . '
' . $params['icons'][$x] . '
'; } } else { - $params['string'] = preg_replace_callback('/<(3+)/', 'self::preg_heart', $params['string']); + $params['string'] = preg_replace_callback('/<(3+)/', 'self::pregHeart', $params['string']); $s = str_replace($params['texts'], $params['icons'], $params['string']); } @@ -202,11 +204,21 @@ class Smilies return $s; } + /** + * @param string $m string + * + * @return string base64 encoded string + */ private static function encode($m) { return(str_replace($m[1], base64url_encode($m[1]), $m[0])); } + /** + * @param string $m string + * + * @return string base64 decoded string + */ private static function decode($m) { return(str_replace($m[1], base64url_decode($m[1]), $m[0])); @@ -216,13 +228,13 @@ class Smilies /** * @brief expand <3333 to the correct number of hearts * - * @param string $x + * @param string $x string * * @return string HTML Output * * @todo: Rework because it doesn't work correctly */ - private static function preg_heart($x) + private static function pregHeart($x) { if (strlen($x[1]) == 1) { return $x[0]; diff --git a/src/Core/BaseObject.php b/src/Core/BaseObject.php index ade8d9219..d6ea17f70 100644 --- a/src/Core/BaseObject.php +++ b/src/Core/BaseObject.php @@ -19,8 +19,10 @@ class BaseObject * Get the app * * Same as get_app from boot.php + * + * @return object */ - public function get_app() + public function getApp() { if (self::$app) { return self::$app; @@ -35,8 +37,10 @@ class BaseObject * Set the app * * @param object $app App + * + * @return void */ - public static function set_app($app) + public static function setApp($app) { self::$app = $app; } diff --git a/src/Core/Cache.php b/src/Core/Cache.php index ab87bc375..39f5d12fa 100644 --- a/src/Core/Cache.php +++ b/src/Core/Cache.php @@ -134,6 +134,8 @@ class Cache * @param string $key The key to the cached data * @param mixed $value The value that is about to be stored * @param integer $duration The cache lifespan + * + * @return void */ public static function set($key, $value, $duration = CACHE_MONTH) { @@ -159,6 +161,8 @@ class Cache * @brief Remove outdated data from the cache * * @param integer $max_level The maximum cache level that is to be cleared + * + * @return void */ public static function clear($max_level = CACHE_MONTH) { diff --git a/src/Core/Config.php b/src/Core/Config.php index 56b85dba4..219831ad9 100644 --- a/src/Core/Config.php +++ b/src/Core/Config.php @@ -21,8 +21,8 @@ use dba; * There are a few places in the code (such as the admin panel) where boolean * configurations need to be fixed as of 10/08/2011. */ -class Config { - +class Config +{ private static $cache; private static $in_db; @@ -32,12 +32,12 @@ class Config { * All configuration values of the system are stored in global cache * which is available under the global variable $a->config * - * @param string $family - * The category of the configuration value + * @param string $family The category of the configuration value + * * @return void */ - public static function load($family = "config") { - + public static function load($family = "config") + { // We don't preload "system" anymore. // This reduces the number of database reads a lot. if ($family === 'system') { @@ -72,18 +72,15 @@ class Config { * local config cache, pull it into the cache so we don't have * to hit the DB again for this item. * - * @param string $family - * The category of the configuration value - * @param string $key - * The configuration key to query - * @param mixed $default_value optional - * The value to return if key is not set (default: null) - * @param boolean $refresh optional - * If true the config is loaded from the db and not from the cache (default: false) + * @param string $family The category of the configuration value + * @param string $key The configuration key to query + * @param mixed $default_value optional, The value to return if key is not set (default: null) + * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false) + * * @return mixed Stored value or null if it does not exist */ - public static function get($family, $key, $default_value = null, $refresh = false) { - + public static function get($family, $key, $default_value = null, $refresh = false) + { $a = get_app(); if (!$refresh) { @@ -128,15 +125,14 @@ class Config { * * Note: Please do not store booleans - convert to 0/1 integer values! * - * @param string $family - * The category of the configuration value - * @param string $key - * The configuration key to set - * @param string $value - * The value to store + * @param string $family The category of the configuration value + * @param string $key The configuration key to set + * @param string $value The value to store + * * @return mixed Stored $value or false if the database update failed */ - public static function set($family, $key, $value) { + public static function set($family, $key, $value) + { $a = get_app(); // We store our setting values in a string variable. @@ -177,14 +173,13 @@ class Config { * Removes the configured value from the stored cache in $a->config * and removes it from the database. * - * @param string $family - * The category of the configuration value - * @param string $key - * The configuration key to delete + * @param string $family The category of the configuration value + * @param string $key The configuration key to delete + * * @return mixed */ - public static function delete($family, $key) { - + public static function delete($family, $key) + { if (isset(self::$cache[$family][$key])) { unset(self::$cache[$family][$key]); unset(self::$in_db[$family][$key]); diff --git a/src/Core/Conversation.php b/src/Core/Conversation.php index 4cb11d9ae..10d0e46f1 100644 --- a/src/Core/Conversation.php +++ b/src/Core/Conversation.php @@ -23,22 +23,32 @@ class Conversation extends BaseObject private $profile_owner = 0; private $preview = false; + /** + * Constructor + * + * @param string $mode The mode + * @param boolean $preview boolean value + */ public function __construct($mode, $preview) { - $this->set_mode($mode); + $this->setMode($mode); $this->preview = $preview; } /** * Set the mode we'll be displayed on + * + * @param string $mode The mode to set + * + * @return void */ - private function set_mode($mode) + private function setMode($mode) { - if ($this->get_mode() == $mode) { + if ($this->getMode() == $mode) { return; } - $a = $this->get_app(); + $a = $this->getApp(); switch ($mode) { case 'network': @@ -55,7 +65,7 @@ class Conversation extends BaseObject $this->writable = can_write_wall($a, $this->profile_owner); break; default: - logger('[ERROR] Conversation::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG); + logger('[ERROR] Conversation::setMode : Unhandled mode ('. $mode .').', LOGGER_DEBUG); return false; break; } @@ -64,32 +74,40 @@ class Conversation extends BaseObject /** * Get mode + * + * @return string */ - public function get_mode() + public function getMode() { return $this->mode; } /** * Check if page is writable + * + * @return boolean */ - public function is_writable() + public function isWritable() { return $this->writable; } /** * Check if page is a preview + * + * @return boolean */ - public function is_preview() + public function isPreview() { return $this->preview; } /** * Get profile owner + * + * @return integer */ - public function get_profile_owner() + public function getProfileOwner() { return $this->profile_owner; } @@ -97,21 +115,22 @@ class Conversation extends BaseObject /** * Add a thread to the conversation * - * Returns: - * _ The inserted item on success - * _ false on failure + * @param object $item The item to insert + * + * @return mixed The inserted item on success + * false on failure */ - public function add_thread($item) + public function addThread($item) { $item_id = $item->getId(); if (!$item_id) { - logger('[ERROR] Conversation::add_thread : Item has no ID!!', LOGGER_DEBUG); + logger('[ERROR] Conversation::addThread : Item has no ID!!', LOGGER_DEBUG); return false; } - if ($this->get_thread($item->getId())) { - logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->getId() .').', LOGGER_DEBUG); + if ($this->getThread($item->getId())) { + logger('[WARN] Conversation::addThread : Thread already exists ('. $item->getId() .').', LOGGER_DEBUG); return false; } @@ -119,12 +138,12 @@ class Conversation extends BaseObject * Only add will be displayed */ if ($item->getDataValue('network') === NETWORK_MAIL && local_user() != $item->getDataValue('uid')) { - logger('[WARN] Conversation::add_thread : Thread is a mail ('. $item->getId() .').', LOGGER_DEBUG); + logger('[WARN] Conversation::addThread : Thread is a mail ('. $item->getId() .').', LOGGER_DEBUG); return false; } if ($item->getDataValue('verb') === ACTIVITY_LIKE || $item->getDataValue('verb') === ACTIVITY_DISLIKE) { - logger('[WARN] Conversation::add_thread : Thread is a (dis)like ('. $item->getId() .').', LOGGER_DEBUG); + logger('[WARN] Conversation::addThread : Thread is a (dis)like ('. $item->getId() .').', LOGGER_DEBUG); return false; } @@ -139,13 +158,14 @@ class Conversation extends BaseObject * * We should find a way to avoid using those arguments (at least most of them) * - * Returns: - * _ The data requested on success - * _ false on failure + * @param object $conv_responses data + * + * @return mixed The data requested on success + * false on failure */ - public function get_template_data($conv_responses) + public function getTemplateData($conv_responses) { - $a = get_app(); + $a = getApp(); $result = array(); $i = 0; @@ -157,7 +177,7 @@ class Conversation extends BaseObject $item_data = $item->getTemplateData($conv_responses); if (!$item_data) { - logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->getId() .').', LOGGER_DEBUG); + logger('[ERROR] Conversation::getTemplateData : Failed to get item template data ('. $item->getId() .').', LOGGER_DEBUG); return false; } $result[] = $item_data; @@ -169,11 +189,12 @@ class Conversation extends BaseObject /** * Get a thread based on its item id * - * Returns: - * _ The found item on success - * _ false on failure + * @param integer $id Item id + * + * @return mixed The found item on success + * false on failure */ - private function get_thread($id) + private function getThread($id) { foreach ($this->threads as $item) { if ($item->getId() == $id) { diff --git a/src/Core/Item.php b/src/Core/Item.php index 49f060338..24e524d2e 100644 --- a/src/Core/Item.php +++ b/src/Core/Item.php @@ -39,9 +39,14 @@ class Item extends BaseObject private $threaded = false; private $visiting = false; + /** + * Constructor + * + * @param array $data data array + */ public function __construct($data) { - $a = $this->get_app(); + $a = $this->getApp(); $this->data = $data; $this->setTemplate('wall'); @@ -92,9 +97,11 @@ class Item extends BaseObject /** * Get data in a form usable by a conversation template * - * Returns: - * _ The data requested on success - * _ false on failure + * @param object $conv_responses conversation responses + * @param integer $thread_level default = 1 + * + * @return mixed The data requested on success + * false on failure */ public function getTemplateData($conv_responses, $thread_level = 1) { @@ -102,7 +109,7 @@ class Item extends BaseObject $result = array(); - $a = $this->get_app(); + $a = $this->getApp(); $item = $this->getData(); $edited = false; @@ -136,7 +143,7 @@ class Item extends BaseObject || strlen($item['deny_cid']) || strlen($item['deny_gid'])))) ? t('Private Message') : false); - $shareable = ((($conv->get_profile_owner() == local_user()) && ($item['private'] != 1)) ? true : false); + $shareable = ((($conv->getProfileOwner() == local_user()) && ($item['private'] != 1)) ? true : false); if (local_user() && link_compare($a->contact['url'], $item['author-link'])) { if ($item["event-id"] != 0) { $edpost = array("events/event/".$item['event-id'], t("Edit")); @@ -153,12 +160,12 @@ class Item extends BaseObject $drop = array( 'dropping' => $dropping, - 'pagedrop' => ((feature_enabled($conv->get_profile_owner(), 'multi_delete')) ? $item['pagedrop'] : ''), + 'pagedrop' => ((feature_enabled($conv->getProfileOwner(), 'multi_delete')) ? $item['pagedrop'] : ''), 'select' => t('Select'), 'delete' => t('Delete'), ); - $filer = (($conv->get_profile_owner() == local_user()) ? t("save to folder") : false); + $filer = (($conv->getProfileOwner() == local_user()) ? t("save to folder") : false); $diff_author = ((link_compare($item['url'], $item['author-link'])) ? false : true); $profile_name = htmlentities(((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']); @@ -179,7 +186,7 @@ class Item extends BaseObject } if (!isset($item['author-thumb']) || ($item['author-thumb'] == "")) { - $author_contact = get_contact_details_by_url($item['author-link'], $conv->get_profile_owner()); + $author_contact = get_contact_details_by_url($item['author-link'], $conv->getProfileOwner()); if ($author_contact["thumb"]) { $item['author-thumb'] = $author_contact["thumb"]; } else { @@ -188,7 +195,7 @@ class Item extends BaseObject } if (!isset($item['owner-thumb']) || ($item['owner-thumb'] == "")) { - $owner_contact = get_contact_details_by_url($item['owner-link'], $conv->get_profile_owner()); + $owner_contact = get_contact_details_by_url($item['owner-link'], $conv->getProfileOwner()); if ($owner_contact["thumb"]) { $item['owner-thumb'] = $owner_contact["thumb"]; } else { @@ -223,7 +230,7 @@ class Item extends BaseObject $response_verbs[] = 'attendyes'; $response_verbs[] = 'attendno'; $response_verbs[] = 'attendmaybe'; - if ($conv->is_writable()) { + if ($conv->isWritable()) { $isevent = true; $attend = array( t('I will attend'), t('I will not attend'), t('I might attend')); } @@ -247,7 +254,7 @@ class Item extends BaseObject } if ($this->isToplevel()) { - if ($conv->get_profile_owner() == local_user()) { + if ($conv->getProfileOwner() == local_user()) { $isstarred = (($item['starred']) ? "starred" : "unstarred"); $star = array( @@ -271,7 +278,7 @@ class Item extends BaseObject } $tagger = ''; - if (feature_enabled($conv->get_profile_owner(), 'commtag')) { + if (feature_enabled($conv->getProfileOwner(), 'commtag')) { $tagger = array( 'add' => t("add tag"), 'class' => "", @@ -282,10 +289,10 @@ class Item extends BaseObject $indent = 'comment'; } - if ($conv->is_writable()) { + if ($conv->isWritable()) { $buttons = array( 'like' => array( t("I like this \x28toggle\x29"), t("like")), - 'dislike' => ((feature_enabled($conv->get_profile_owner(), 'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''), + 'dislike' => ((feature_enabled($conv->getProfileOwner(), 'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''), ); if ($shareable) { $buttons['share'] = array( t('Share this'), t('share')); @@ -379,12 +386,12 @@ class Item extends BaseObject 'owner_photo' => $a->remove_baseurl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)), 'owner_name' => htmlentities($owner_name_e), 'plink' => get_plink($item), - 'edpost' => ((feature_enabled($conv->get_profile_owner(), 'edit_posts')) ? $edpost : ''), + 'edpost' => ((feature_enabled($conv->getProfileOwner(), 'edit_posts')) ? $edpost : ''), 'isstarred' => $isstarred, - 'star' => ((feature_enabled($conv->get_profile_owner(), 'star_posts')) ? $star : ''), - 'ignore' => ((feature_enabled($conv->get_profile_owner(), 'ignore_posts')) ? $ignore : ''), + 'star' => ((feature_enabled($conv->getProfileOwner(), 'star_posts')) ? $star : ''), + 'ignore' => ((feature_enabled($conv->getProfileOwner(), 'ignore_posts')) ? $ignore : ''), 'tagger' => $tagger, - 'filer' => ((feature_enabled($conv->get_profile_owner(), 'filing')) ? $filer : ''), + 'filer' => ((feature_enabled($conv->getProfileOwner(), 'filing')) ? $filer : ''), 'drop' => $drop, 'vote' => $buttons, 'like' => $responses['like']['output'], @@ -392,7 +399,7 @@ class Item extends BaseObject 'responses' => $responses, 'switchcomment' => t('Comment'), 'comment' => $comment, - 'previewing' => ($conv->is_preview() ? ' preview ' : ''), + 'previewing' => ($conv->isPreview() ? ' preview ' : ''), 'wait' => t('Please wait'), 'thread_level' => $thread_level, 'edited' => $edited, @@ -449,11 +456,17 @@ class Item extends BaseObject return $result; } + /** + * @return integer + */ public function getId() { return $this->getDataValue('id'); } + /** + * @return boolean + */ public function isThreaded() { return $this->threaded; @@ -461,6 +474,10 @@ class Item extends BaseObject /** * Add a child item + * + * @param object $item The child item to add + * + * @return mixed */ public function addChild(Item $item) { @@ -489,6 +506,10 @@ class Item extends BaseObject /** * Get a child by its ID + * + * @param integer $id The child id + * + * @return mixed */ public function getChild($id) { @@ -502,7 +523,9 @@ class Item extends BaseObject } /** - * Get all ou children + * Get all our children + * + * @return object */ public function getChildren() { @@ -511,6 +534,10 @@ class Item extends BaseObject /** * Set our parent + * + * @param object $item The item to set as parent + * + * @return void */ protected function setParent($item) { @@ -525,6 +552,8 @@ class Item extends BaseObject /** * Remove our parent + * + * @return void */ protected function removeParent() { @@ -534,6 +563,10 @@ class Item extends BaseObject /** * Remove a child + * + * @param object $item The child to be removed + * + * @return boolean Success or failure */ public function removeChild($item) { @@ -553,6 +586,8 @@ class Item extends BaseObject /** * Get parent item + * + * @return object */ protected function getParent() { @@ -560,11 +595,15 @@ class Item extends BaseObject } /** - * set conversation + * Set conversation + * + * @param object $conv The conversation + * + * @return void */ public function setConversation($conv) { - $previous_mode = ($this->conversation ? $this->conversation->get_mode() : ''); + $previous_mode = ($this->conversation ? $this->conversation->getMode() : ''); $this->conversation = $conv; @@ -575,7 +614,9 @@ class Item extends BaseObject } /** - * get conversation + * Get conversation + * + * @return object */ public function getConversation() { @@ -586,6 +627,8 @@ class Item extends BaseObject * Get raw data * * We shouldn't need this + * + * @return array */ public function getData() { @@ -595,9 +638,10 @@ class Item extends BaseObject /** * Get a data value * - * Returns: - * _ value on success - * _ false on failure + * @param object $name key + * + * @return mixed value on success + * false on failure */ public function getDataValue($name) { @@ -611,6 +655,10 @@ class Item extends BaseObject /** * Set template + * + * @param object $name template name + * + * @return void */ private function setTemplate($name) { @@ -624,6 +672,8 @@ class Item extends BaseObject /** * Get template + * + * @return object */ private function getTemplate() { @@ -632,6 +682,8 @@ class Item extends BaseObject /** * Check if this is a toplevel post + * + * @return boolean */ private function isToplevel() { @@ -640,6 +692,8 @@ class Item extends BaseObject /** * Check if this is writable + * + * @return boolean */ private function isWritable() { @@ -650,18 +704,20 @@ class Item extends BaseObject // and community forums even if somebody else wrote the post. // bug #517 - this fixes for conversation owner - if ($conv->get_mode() == 'profile' && $conv->get_profile_owner() == local_user()) { + if ($conv->getMode() == 'profile' && $conv->getProfileOwner() == local_user()) { return true; } // this fixes for visitors - return ($this->writable || ($this->isVisiting() && $conv->get_mode() == 'profile')); + return ($this->writable || ($this->isVisiting() && $conv->getMode() == 'profile')); } return $this->writable; } /** * Count the total of our descendants + * + * @return integer */ private function countDescendants() { @@ -678,6 +734,8 @@ class Item extends BaseObject /** * Get the template for the comment box + * + * @return string */ private function getCommentBoxTemplate() { @@ -687,13 +745,14 @@ class Item extends BaseObject /** * Get the comment box * - * Returns: - * _ The comment box string (empty if no comment box) - * _ false on failure + * @param string $indent Indent value + * + * @return mixed The comment box string (empty if no comment box) + * false on failure */ private function getCommentBox($indent) { - $a = $this->get_app(); + $a = $this->getApp(); if (!$this->isToplevel() && !(Config::get('system', 'thread_allow') && $a->theme_thread_allow)) { return ''; } @@ -702,11 +761,11 @@ class Item extends BaseObject $conv = $this->getConversation(); $template = get_markup_template($this->getCommentBoxTemplate()); $ww = ''; - if (($conv->get_mode() === 'network') && $this->isWallToWall()) { + if (($conv->getMode() === 'network') && $this->isWallToWall()) { $ww = 'ww'; } - if ($conv->is_writable() && $this->isWritable()) { + if ($conv->isWritable() && $this->isWritable()) { $qc = $qcomment = null; /* @@ -723,13 +782,13 @@ class Item extends BaseObject array( '$return_path' => $a->query_string, '$threaded' => $this->isThreaded(), - // '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''), + // '$jsreload' => (($conv->getMode() === 'display') ? $_SESSION['return_url'] : ''), '$jsreload' => '', - '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'), + '$type' => (($conv->getMode() === 'profile') ? 'wall-comment' : 'net-comment'), '$id' => $this->getId(), '$parent' => $this->getId(), '$qcomment' => $qcomment, - '$profile_uid' => $conv->get_profile_owner(), + '$profile_uid' => $conv->getProfileOwner(), '$mylink' => $a->remove_baseurl($a->contact['url']), '$mytitle' => t('This is you'), '$myphoto' => $a->remove_baseurl($a->contact['thumb']), @@ -743,10 +802,10 @@ class Item extends BaseObject '$edimg' => t('Image'), '$edurl' => t('Link'), '$edvideo' => t('Video'), - '$preview' => ((feature_enabled($conv->get_profile_owner(), 'preview')) ? t('Preview') : ''), + '$preview' => ((feature_enabled($conv->getProfileOwner(), 'preview')) ? t('Preview') : ''), '$indent' => $indent, '$sourceapp' => t($a->sourcename), - '$ww' => (($conv->get_mode() === 'network') ? $ww : ''), + '$ww' => (($conv->getMode() === 'network') ? $ww : ''), '$rand_num' => random_digits(12)) ); } @@ -754,6 +813,9 @@ class Item extends BaseObject return $comment_box; } + /** + * @return string + */ private function getRedirectUrl() { return $this->redirect_url; @@ -761,15 +823,17 @@ class Item extends BaseObject /** * Check if we are a wall to wall item and set the relevant properties + * + * @return void */ protected function checkWallToWall() { - $a = $this->get_app(); + $a = $this->getApp(); $conv = $this->getConversation(); $this->wall_to_wall = false; if ($this->isToplevel()) { - if ($conv->get_mode() !== 'profile') { + if ($conv->getMode() !== 'profile') { if ($this->getDataValue('wall') && !$this->getDataValue('self')) { // On the network page, I am the owner. On the display page it will be the profile owner. // This will have been stored in $a->page_contact by our calling page. @@ -819,26 +883,41 @@ class Item extends BaseObject } } + /** + * @return boolean + */ private function isWallToWall() { return $this->wall_to_wall; } + /** + * @return string + */ private function getOwnerUrl() { return $this->owner_url; } + /** + * @return string + */ private function getOwnerPhoto() { return $this->owner_photo; } + /** + * @return string + */ private function getOwnerName() { return $this->owner_name; } + /** + * @return boolean + */ private function isVisiting() { return $this->visiting; diff --git a/src/Core/NotificationsManager.php b/src/Core/NotificationsManager.php index ea3d4c0cc..318d5a8e8 100644 --- a/src/Core/NotificationsManager.php +++ b/src/Core/NotificationsManager.php @@ -322,7 +322,7 @@ class NotificationsManager 'link' => System::baseUrl(true).'/display/'.$it['pguid'], 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), 'url' => $it['author-link'], - 'text' => sprintf( t("%s is not attending %s's event"), $it['author-name'], $it['pname']), + 'text' => sprintf(t("%s is not attending %s's event"), $it['author-name'], $it['pname']), 'when' => $default_item_when, 'ago' => $default_item_ago, 'seen' => $it['seen'] @@ -381,9 +381,9 @@ class NotificationsManager /** * @brief Total number of network notifications - * @param int|string $seen - * If 0 only include notifications into the query - * which aren't marked as "seen" + * @param int|string $seen If 0 only include notifications into the query + * which aren't marked as "seen" + * * @return int Number of network notifications */ private function networkTotal($seen = 0) @@ -413,9 +413,8 @@ class NotificationsManager /** * @brief Get network notifications * - * @param int|string $seen - * If 0 only include notifications into the query - * which aren't marked as "seen" + * @param int|string $seen If 0 only include notifications into the query + * which aren't marked as "seen" * @param int $start Start the query at this point * @param int $limit Maximum number of query results * @@ -465,9 +464,9 @@ class NotificationsManager /** * @brief Total number of system notifications - * @param int|string $seen - * If 0 only include notifications into the query - * which aren't marked as "seen" + * @param int|string $seen If 0 only include notifications into the query + * which aren't marked as "seen" + * * @return int Number of system notifications */ private function systemTotal($seen = 0) @@ -493,9 +492,8 @@ class NotificationsManager /** * @brief Get system notifications * - * @param int|string $seen - * If 0 only include notifications into the query - * which aren't marked as "seen" + * @param int|string $seen If 0 only include notifications into the query + * which aren't marked as "seen" * @param int $start Start the query at this point * @param int $limit Maximum number of query results * @@ -541,7 +539,7 @@ class NotificationsManager * * @return string The additional sql query */ - private function _personal_sql_extra() + private function personalSqlExtra() { $myurl = System::baseUrl(true) . '/profile/'. $this->a->user['nickname']; $myurl = substr($myurl, strpos($myurl, '://') + 3); @@ -559,15 +557,15 @@ class NotificationsManager /** * @brief Total number of personal notifications - * @param int|string $seen - * If 0 only include notifications into the query - * which aren't marked as "seen" + * @param int|string $seen If 0 only include notifications into the query + * which aren't marked as "seen" + * * @return int Number of personal notifications */ private function personalTotal($seen = 0) { $sql_seen = ""; - $sql_extra = $this->_personal_sql_extra(); + $sql_extra = $this->personalSqlExtra(); if ($seen === 0) { $sql_seen = " AND `item`.`unseen` = 1 "; @@ -579,7 +577,7 @@ class NotificationsManager WHERE `item`.`visible` = 1 $sql_extra $sql_seen - AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 " , + AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ", intval(local_user()) ); @@ -593,9 +591,8 @@ class NotificationsManager /** * @brief Get personal notifications * - * @param int|string $seen - * If 0 only include notifications into the query - * which aren't marked as "seen" + * @param int|string $seen If 0 only include notifications into the query + * which aren't marked as "seen" * @param int $start Start the query at this point * @param int $limit Maximum number of query results * @@ -608,7 +605,7 @@ class NotificationsManager { $ident = 'personal'; $total = $this->personalTotal($seen); - $sql_extra = $this->_personal_sql_extra(); + $sql_extra = $this->personalSqlExtra(); $notifs = array(); $sql_seen = ""; @@ -646,9 +643,9 @@ class NotificationsManager /** * @brief Total number of home notifications - * @param int|string $seen - * If 0 only include notifications into the query - * which aren't marked as "seen" + * @param int|string $seen If 0 only include notifications into the query + * which aren't marked as "seen" + * * @return int Number of home notifications */ private function homeTotal($seen = 0) @@ -677,9 +674,8 @@ class NotificationsManager /** * @brief Get home notifications * - * @param int|string $seen - * If 0 only include notifications into the query - * which aren't marked as "seen" + * @param int|string $seen If 0 only include notifications into the query + * which aren't marked as "seen" * @param int $start Start the query at this point * @param int $limit Maximum number of query results * @@ -728,9 +724,9 @@ class NotificationsManager /** * @brief Total number of introductions - * @param bool $all - * If false only include introductions into the query - * which aren't marked as ignored + * @param bool $all If false only include introductions into the query + * which aren't marked as ignored + * * @return int Number of introductions */ private function introTotal($all = false) @@ -757,18 +753,18 @@ class NotificationsManager /** * @brief Get introductions * - * @param bool $all - * If false only include introductions into the query - * which aren't marked as ignored - * @param int $start Start the query at this point - * @param int $limit Maximum number of query results + * @param bool $all If false only include introductions into the query + * which aren't marked as ignored + * @param int $start Start the query at this point + * @param int $limit Maximum number of query results * * @return array with * string 'ident' => Notification identifier * int 'total' => Total number of available introductions * array 'notifications' => Introductions */ - public function introNotifs($all = false, $start = 0, $limit = 80) { + public function introNotifs($all = false, $start = 0, $limit = 80) + { $ident = 'introductions'; $total = $this->introTotal($seen); $notifs = array(); diff --git a/src/Core/PConfig.php b/src/Core/PConfig.php index b60dcd1b3..3467032fa 100644 --- a/src/Core/PConfig.php +++ b/src/Core/PConfig.php @@ -1,4 +1,7 @@ config[$uid]. * - * @param string $uid - * The user_id - * @param string $family - * The category of the configuration value + * @param string $uid The user_id + * @param string $family The category of the configuration value + * * @return void */ - public static function load($uid, $family) { + public static function load($uid, $family) + { $a = get_app(); $r = dba::select('pconfig', array('v', 'k'), array('cat' => $family, 'uid' => $uid)); @@ -57,20 +60,16 @@ class PConfig { * Get a particular user's config value from the given category ($family) * and the $key from a cached storage in $a->config[$uid]. * - * @param string $uid - * The user_id - * @param string $family - * The category of the configuration value - * @param string $key - * The configuration key to query - * @param mixed $default_value optional - * The value to return if key is not set (default: null) - * @param boolean $refresh optional - * If true the config is loaded from the db and not from the cache (default: false) + * @param string $uid The user_id + * @param string $family The category of the configuration value + * @param string $key The configuration key to query + * @param mixed $default_value optional, The value to return if key is not set (default: null) + * @param boolean $refresh optional, If true the config is loaded from the db and not from the cache (default: false) + * * @return mixed Stored value or null if it does not exist */ - public static function get($uid, $family, $key, $default_value = null, $refresh = false) { - + public static function get($uid, $family, $key, $default_value = null, $refresh = false) + { $a = get_app(); if (!$refresh) { @@ -112,18 +111,15 @@ class PConfig { * * @note Please do not store booleans - convert to 0/1 integer values! * - * @param string $uid - * The user_id - * @param string $family - * The category of the configuration value - * @param string $key - * The configuration key to set - * @param string $value - * The value to store + * @param string $uid The user_id + * @param string $family The category of the configuration value + * @param string $key The configuration key to set + * @param string $value The value to store + * * @return mixed Stored $value or false */ - public static function set($uid, $family, $key, $value) { - + public static function set($uid, $family, $key, $value) + { $a = get_app(); // We store our setting values in a string variable. @@ -157,15 +153,14 @@ class PConfig { * Removes the configured value from the stored cache in $a->config[$uid] * and removes it from the database. * - * @param string $uid The user_id - * @param string $family - * The category of the configuration value - * @param string $key - * The configuration key to delete + * @param string $uid The user_id + * @param string $family The category of the configuration value + * @param string $key The configuration key to delete + * * @return mixed */ - public static function delete($uid,$family,$key) { - + public static function delete($uid, $family, $key) + { $a = get_app(); if (x($a->config[$uid][$family], $key)) { diff --git a/src/Core/System.php b/src/Core/System.php index a2c6f6509..45e4f652a 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -1,4 +1,7 @@ get_baseurl($ssl); } @@ -42,21 +48,23 @@ class System { /** * @brief Removes the baseurl from an url. This avoids some mixed content problems. * - * @param string $orig_url + * @param string $orig_url The url to be cleaned * * @return string The cleaned url */ - public static function removedBaseUrl($orig_url) { + public static function removedBaseUrl($orig_url) + { self::init(); return self::$a->remove_baseurl($orig_url); } /** * @brief Returns a string with a callstack. Can be used for logging. - * + * @param integer $depth optional, default 4 * @return string */ - public static function callstack($depth = 4) { + public static function callstack($depth = 4) + { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); // We remove the first two items from the list since they contain data that we don't need.