From ce177f22c867d4b9dc904914d6f80a5c7b988453 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 11:36:01 -0500 Subject: [PATCH 1/7] Fix doc blocks and return value type --- include/api.php | 2 +- include/conversation.php | 2 +- include/enotify.php | 21 ++++++++++----------- include/text.php | 2 +- src/Object/Thread.php | 2 +- src/Util/Emailer.php | 2 +- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/include/api.php b/include/api.php index d1d54f144c..3c11ea4640 100644 --- a/include/api.php +++ b/include/api.php @@ -528,7 +528,7 @@ function api_unique_id_to_nurl($id) * * @param App $a App * @param int|string $contact_id Contact ID or URL - * @return array + * @return array|bool * @throws BadRequestException * @throws ImagickException * @throws InternalServerErrorException diff --git a/include/conversation.php b/include/conversation.php index 6ee7309ad1..e6c787915f 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1447,7 +1447,7 @@ function sort_thr_created_rev(array $a, array $b) * * @param array $a * @param array $b - * @return int|lt + * @return int */ function sort_thr_commented(array $a, array $b) { diff --git a/include/enotify.php b/include/enotify.php index 800158d9ae..f725511f5e 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -25,7 +25,7 @@ use Friendica\Util\Strings; * link, subject, body, to_name, to_email, source_name, * source_link, activity, preamble, notify_flags, * language, show_in_notification_page - * @return bool|object + * @return bool * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ function notification($params) @@ -43,7 +43,7 @@ function notification($params) if (!DBA::isResult($user)) { Logger::log('Unknown user ' . $params['uid']); - return; + return false; } $params['notify_flags'] = defaults($params, 'notify_flags', $user['notify-flags']); @@ -79,7 +79,7 @@ function notification($params) // There is no need to create notifications for forum accounts if (!DBA::isResult($user) || in_array($user["page-flags"], [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP])) { - return; + return false; } $nickname = $user["nickname"]; } else { @@ -146,7 +146,7 @@ function notification($params) if (DBA::isResult($thread) && $thread['ignored']) { Logger::log('Thread ' . $parent_id . ' will be ignored', Logger::DEBUG); L10n::popLang(); - return; + return false; } // Check to see if there was already a tag notify or comment notify for this post. @@ -155,7 +155,7 @@ function notification($params) 'link' => $params['link'], 'uid' => $params['uid']]; if (DBA::exists('notify', $condition)) { L10n::popLang(); - return; + return false; } // if it's a post figure out who's post it is. @@ -522,7 +522,7 @@ function notification($params) if ($datarray['abort']) { L10n::popLang(); - return False; + return false; } // create notification entry in DB @@ -671,8 +671,7 @@ function notification($params) L10n::popLang(); // use the Emailer class to send the message - return Emailer::send( - [ + return Emailer::send([ 'uid' => $params['uid'], 'fromName' => $sender_name, 'fromEmail' => $sender_email, @@ -681,8 +680,8 @@ function notification($params) 'messageSubject' => $datarray['subject'], 'htmlVersion' => $email_html_body, 'textVersion' => $email_text_body, - 'additionalMailHeader' => $datarray['headers']] - ); + 'additionalMailHeader' => $datarray['headers'] + ]); } L10n::popLang(); @@ -778,7 +777,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { $condition = ['id' => $itemid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]]; $item = Item::selectFirst($fields, $condition); if (!DBA::isResult($item) || in_array($item['author-id'], $contacts)) { - return; + return false; } // Generate the notification array diff --git a/include/text.php b/include/text.php index 0b8bcacba5..a96a3a1e58 100644 --- a/include/text.php +++ b/include/text.php @@ -235,7 +235,7 @@ function get_cats_and_terms($item) /** * return number of bytes in size (K, M, G) * @param string $size_str - * @return number + * @return int */ function return_bytes($size_str) { switch (substr ($size_str, -1)) { diff --git a/src/Object/Thread.php b/src/Object/Thread.php index c5795819a4..89ed5a9408 100644 --- a/src/Object/Thread.php +++ b/src/Object/Thread.php @@ -170,7 +170,7 @@ class Thread extends BaseObject * * We should find a way to avoid using those arguments (at least most of them) * - * @param object $conv_responses data + * @param array $conv_responses data * * @return mixed The data requested on success * false on failure diff --git a/src/Util/Emailer.php b/src/Util/Emailer.php index cccf8c2fab..6a19e8e458 100644 --- a/src/Util/Emailer.php +++ b/src/Util/Emailer.php @@ -29,7 +29,7 @@ class Emailer * additionalMailHeader additions to the SMTP mail header * optional uid user id of the destination user * - * @return object + * @return bool * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ public static function send($params) From b161bd1dfa8522c742b2f8d1d34cbad2d27466bc Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 11:37:05 -0500 Subject: [PATCH 2/7] Improve get_responses() prototype --- include/conversation.php | 2 +- mod/photos.php | 2 +- src/Object/Post.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index e6c787915f..682bc14555 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1464,7 +1464,7 @@ function render_location_dummy(array $item) { } } -function get_responses(array $conv_responses, array $response_verbs, $ob, array $item) { +function get_responses(array $conv_responses, array $response_verbs, array $item, Post $ob = null) { $ret = []; foreach ($response_verbs as $v) { $ret[$v] = []; diff --git a/mod/photos.php b/mod/photos.php index 710a3873ee..137e0adb56 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1564,7 +1564,7 @@ function photos_content(App $a) } $response_verbs = ['like']; $response_verbs[] = 'dislike'; - $responses = get_responses($conv_responses, $response_verbs, '', $link_item); + $responses = get_responses($conv_responses, $response_verbs, $link_item); $paginate = $pager->renderFull($total); } diff --git a/src/Object/Post.php b/src/Object/Post.php index 2d52f4244a..c9e5cddb69 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -250,7 +250,7 @@ class Post extends BaseObject } } - $responses = get_responses($conv_responses, $response_verbs, $this, $item); + $responses = get_responses($conv_responses, $response_verbs, $item, $this); foreach ($response_verbs as $value => $verbs) { $responses[$verbs]['output'] = !empty($conv_responses[$verbs][$item['uri']]) ? format_like($conv_responses[$verbs][$item['uri']], $conv_responses[$verbs][$item['uri'] . '-l'], $verbs, $item['uri']) : ''; From 6f7ec1dc0c7aa9ce313c9e00eaec5711e5839541 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 11:37:43 -0500 Subject: [PATCH 3/7] Remove unused consume_feed() parameters --- include/items.php | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/include/items.php b/include/items.php index 52d37d621c..88eec1dc48 100644 --- a/include/items.php +++ b/include/items.php @@ -247,30 +247,21 @@ function add_page_info_to_body($body, $texturl = false, $no_photos = false) * @param array $importer * @param array $contact * @param $hub - * @param int $datedir - * @param int $pass * @throws ImagickException * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ -function consume_feed($xml, array $importer, array $contact, &$hub, $datedir = 0, $pass = 0) +function consume_feed($xml, array $importer, array $contact, &$hub) { if ($contact['network'] === Protocol::OSTATUS) { - if ($pass < 2) { - // Test - remove before flight - //$tempfile = tempnam(get_temppath(), "ostatus2"); - //file_put_contents($tempfile, $xml); - Logger::log("Consume OStatus messages ", Logger::DEBUG); - OStatus::import($xml, $importer, $contact, $hub); - } + Logger::log("Consume OStatus messages ", Logger::DEBUG); + OStatus::import($xml, $importer, $contact, $hub); return; } if ($contact['network'] === Protocol::FEED) { - if ($pass < 2) { - Logger::log("Consume feeds", Logger::DEBUG); - Feed::import($xml, $importer, $contact, $hub); - } + Logger::log("Consume feeds", Logger::DEBUG); + Feed::import($xml, $importer, $contact, $hub); return; } From 1467a02576cd636f121f3e1ae73db7812d511d10 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 11:38:01 -0500 Subject: [PATCH 4/7] Fix namespace usage in include/enotify --- include/enotify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/enotify.php b/include/enotify.php index f725511f5e..58e1a75f00 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -11,8 +11,8 @@ use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; -use Friendica\Model\Contact; use Friendica\Model\Item; +use Friendica\Model\User; use Friendica\Util\DateTimeFormat; use Friendica\Util\Emailer; use Friendica\Util\Strings; From 04b742a97da4803c6448db2a6a74d55f3cb9df86 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 11:38:12 -0500 Subject: [PATCH 5/7] Fix variable type in include/text --- include/text.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/text.php b/include/text.php index a96a3a1e58..c4249f86c4 100644 --- a/include/text.php +++ b/include/text.php @@ -122,7 +122,7 @@ function qp($s) { */ function redir_private_images($a, &$item) { - $matches = false; + $matches = []; $cnt = preg_match_all('|\[img\](http[^\[]*?/photo/[a-fA-F0-9]+?(-[0-9]\.[\w]+?)?)\[\/img\]|', $item['body'], $matches, PREG_SET_ORDER); if ($cnt) { foreach ($matches as $mtch) { @@ -187,7 +187,7 @@ function get_cats_and_terms($item) $categories = []; $folders = []; - $matches = false; + $matches = []; $first = true; $cnt = preg_match_all('/<(.*?)>/', $item['file'], $matches, PREG_SET_ORDER); if ($cnt) { @@ -208,7 +208,7 @@ function get_cats_and_terms($item) } if (local_user() == $item['uid']) { - $matches = false; + $matches = []; $first = true; $cnt = preg_match_all('/\[(.*?)\]/', $item['file'], $matches, PREG_SET_ORDER); if ($cnt) { From 9b27d049dcef53a021d3750bb86f18441310cb38 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 11:38:54 -0500 Subject: [PATCH 6/7] Add missing break statements in include/conversation - Remove bad variable initialization in format_like() --- include/conversation.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 682bc14555..d7e3d54808 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -210,8 +210,8 @@ function localize_item(&$item) foreach ($links->link as $l) { $atts = $l->attributes(); switch ($atts['rel']) { - case "alternate": $Blink = $atts['href']; - case "photo": $Bphoto = $atts['href']; + case "alternate": $Blink = $atts['href']; break; + case "photo": $Bphoto = $atts['href']; break; } } @@ -1044,7 +1044,6 @@ function format_like($cnt, array $arr, $type, $id) { } } - $phrase = ''; if ($cnt > 1) { $total = count($arr); if ($total < MAX_LIKERS) { From 592592525b564200c621304ef73c926b90664c34 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 11:40:14 -0500 Subject: [PATCH 7/7] Various fixes in include/api - Fix unused condition in api_status_show() - Fix wrong operator orders in api_get_entitites() - Fix wrong variable usage in api_account_update_profile_image() --- include/api.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/include/api.php b/include/api.php index 3c11ea4640..4452ebfb92 100644 --- a/include/api.php +++ b/include/api.php @@ -1320,12 +1320,6 @@ function api_status_show($type, $item_id = 0) Logger::log('api_status_show: user_info: '.print_r($user_info, true), Logger::DEBUG); - if ($type == "raw") { - $privacy_sql = "AND NOT `private`"; - } else { - $privacy_sql = ""; - } - if (!empty($item_id)) { // Get the item with the given id $condition = ['id' => $item_id]; @@ -1334,6 +1328,11 @@ function api_status_show($type, $item_id = 0) $condition = ['owner-id' => $user_info['pid'], 'uid' => api_user(), 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]]; } + + if ($type == "raw") { + $condition['private'] = false; + } + $lastwall = Item::selectFirst(Item::ITEM_FIELDLIST, $condition, ['order' => ['id' => true]]); if (DBA::isResult($lastwall)) { @@ -2834,7 +2833,7 @@ function api_get_entitities(&$text, $bbcode) $entities["media"][] = [ "id" => $start+1, - "id_str" => (string)$start+1, + "id_str" => (string) ($start + 1), "indices" => [$start, $start+strlen($url)], "media_url" => Strings::normaliseLink($media_url), "media_url_https" => $media_url, @@ -4597,8 +4596,8 @@ function api_account_update_profile_image($type) $condition = ["`profile` AND `resource-id` != ? AND `uid` = ?", $data['photo']['id'], api_user()]; Photo::update(['profile' => false], $condition); } else { - $fields = ['photo' => System::baseUrl() . '/photo/' . $data['photo']['id'] . '-4.' . $filetype, - 'thumb' => System::baseUrl() . '/photo/' . $data['photo']['id'] . '-5.' . $filetype]; + $fields = ['photo' => System::baseUrl() . '/photo/' . $data['photo']['id'] . '-4.' . $fileext, + 'thumb' => System::baseUrl() . '/photo/' . $data['photo']['id'] . '-5.' . $fileext]; DBA::update('profile', $fields, ['id' => $_REQUEST['profile'], 'uid' => api_user()]); }