]> git.mxchange.org Git - friendica.git/commitdiff
Fixed max value check, improved request value fetching
authorMichael <heluecht@pirati.ca>
Sun, 16 Jan 2022 15:22:35 +0000 (15:22 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 16 Jan 2022 15:22:35 +0000 (15:22 +0000)
12 files changed:
src/BaseModule.php
src/Module/Api/Friendica/Notification/Seen.php
src/Module/Api/GNUSocial/Statusnet/Conversation.php
src/Module/Api/Twitter/Lists/Statuses.php
src/Module/Api/Twitter/Search/Tweets.php
src/Module/Api/Twitter/Statuses/Destroy.php
src/Module/Api/Twitter/Statuses/HomeTimeline.php
src/Module/Api/Twitter/Statuses/Mentions.php
src/Module/Api/Twitter/Statuses/NetworkPublicTimeline.php
src/Module/Api/Twitter/Statuses/PublicTimeline.php
src/Module/Api/Twitter/Statuses/Show.php
src/Module/Api/Twitter/Statuses/UserTimeline.php

index d85e895a17c6252d461e769b3d5aa7d5e7efc000..c03a77e29e2e3cc935e7b43e2907d280efc89a23 100644 (file)
@@ -296,7 +296,7 @@ abstract class BaseModule implements ICanHandleRequests
                                $value = max(filter_var($minimal_value, FILTER_VALIDATE_INT), $value);
                        }
                        if (!is_null($maximum_value)) {
-                               $value = min(filter_var($minimal_value, FILTER_VALIDATE_INT), $value);
+                               $value = min(filter_var($maximum_value, FILTER_VALIDATE_INT), $value);
                        }
                } elseif (is_float($default)) {
                        $value = filter_var($input[$parameter] ?? $default, FILTER_VALIDATE_FLOAT);
@@ -304,7 +304,7 @@ abstract class BaseModule implements ICanHandleRequests
                                $value = max(filter_var($minimal_value, FILTER_VALIDATE_FLOAT), $value);
                        }
                        if (!is_null($maximum_value)) {
-                               $value = min(filter_var($minimal_value, FILTER_VALIDATE_FLOAT), $value);
+                               $value = min(filter_var($maximum_value, FILTER_VALIDATE_FLOAT), $value);
                        }
                } elseif (is_array($default)) {
                        $value = filter_var($input[$parameter] ?? $default, FILTER_DEFAULT, ['flags' => FILTER_FORCE_ARRAY]);
index 7b37b7615faeb081c3accd029f3361a858670a38..7a52a124df97cabbf6b96da082e15b94843f1991 100644 (file)
@@ -49,6 +49,8 @@ class Seen extends BaseApi
 
                $id = intval($request['id'] ?? 0);
 
+               $include_entities = $this->getRequestValue($request, 'include_entities', false);
+
                try {
                        $Notify = DI::notify()->selectOneById($id);
                        if ($Notify->uid !== $uid) {
@@ -65,8 +67,6 @@ class Seen extends BaseApi
                        if ($Notify->otype === Notification\ObjectType::ITEM) {
                                $item = Post::selectFirstForUser($uid, [], ['id' => $Notify->iid, 'uid' => $uid]);
                                if (DBA::isResult($item)) {
-                                       $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
-
                                        // we found the item, return it to the user
                                        $ret  = [DI::twitterStatus()->createFromUriId($item['uri-id'], $item['uid'], $include_entities)->toArray()];
                                        $data = ['status' => $ret];
index 5edcc4099dbf4d4bb93bbfe6de7f4aa6f28638a9..f21f4c3117ab2762215f82cf4771d76027ae4bc5 100644 (file)
@@ -40,11 +40,12 @@ class Conversation extends BaseApi
                $uid = BaseApi::getCurrentUserID();
 
                // params
-               $id       = $this->parameters['id'] ?? 0;
-               $since_id = $this->getRequestValue($request, 'since_id', 0, 0);
-               $max_id   = $this->getRequestValue($request, 'max_id', 0, 0);
-               $count    = $this->getRequestValue($request, 'count', 20, 1, 100);
-               $page     = $this->getRequestValue($request, 'page', 1, 1);
+               $id               = $this->parameters['id'] ?? 0;
+               $since_id         = $this->getRequestValue($request, 'since_id', 0, 0);
+               $max_id           = $this->getRequestValue($request, 'max_id', 0, 0);
+               $count            = $this->getRequestValue($request, 'count', 20, 1, 100);
+               $page             = $this->getRequestValue($request, 'page', 1, 1);
+               $include_entities = $this->getRequestValue($request, 'include_entities', false);
 
                $start = max(0, ($page - 1) * $count);
 
@@ -82,8 +83,6 @@ class Conversation extends BaseApi
                        throw new BadRequestException("There is no status with id $id.");
                }
 
-               $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
-
                $ret = [];
                while ($status = DBA::fetch($statuses)) {
                        $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
index 87cb1b4ebd38bac92c67a417dc15e4a7152bd987..2bf27697b4fd981106b0053c42c0613c19b446d1 100644 (file)
@@ -65,12 +65,13 @@ class Statuses extends BaseApi
                }
 
                // params
-               $count           = $this->getRequestValue($request, 'count', 20, 1, 100);
-               $page            = $this->getRequestValue($request, 'page', 1, 1);
-               $since_id        = $this->getRequestValue($request, 'since_id', 0, 0);
-               $max_id          = $this->getRequestValue($request, 'max_id', 0, 0);
-               $exclude_replies = $this->getRequestValue($request, 'exclude_replies', false);
-               $conversation_id = $this->getRequestValue($request, 'conversation_id', 0, 0);
+               $count            = $this->getRequestValue($request, 'count', 20, 1, 100);
+               $page             = $this->getRequestValue($request, 'page', 1, 1);
+               $since_id         = $this->getRequestValue($request, 'since_id', 0, 0);
+               $max_id           = $this->getRequestValue($request, 'max_id', 0, 0);
+               $exclude_replies  = $this->getRequestValue($request, 'exclude_replies', false);
+               $conversation_id  = $this->getRequestValue($request, 'conversation_id', 0, 0);
+               $include_entities = $this->getRequestValue($request, 'include_entities', false);
 
                $start = max(0, ($page - 1) * $count);
 
@@ -95,8 +96,6 @@ class Statuses extends BaseApi
                $params   = ['order' => ['id' => true], 'limit' => [$start, $count]];
                $statuses = Post::selectForUser($uid, [], $condition, $params);
 
-               $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
-
                $items = [];
                while ($status = $this->dba->fetch($statuses)) {
                        $items[] = $this->twitterStatus->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
index c8ebd21db4345f3cdc880f1b5ceaf69d15c7177a..0d6b5c230834b022aaf15d88cfe4dec242a0d9bc 100644 (file)
@@ -62,6 +62,8 @@ class Tweets extends BaseApi
                $max_id   = $_REQUEST['max_id']   ?? 0;
                $page     = $_REQUEST['page']     ?? 1;
 
+               $include_entities = $this->getRequestValue($request, 'include_entities', false);
+
                $start = max(0, ($page - 1) * $count);
 
                $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
@@ -115,8 +117,6 @@ class Tweets extends BaseApi
 
                $statuses = $statuses ?: Post::selectForUser($uid, [], $condition, $params);
 
-               $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
-
                $ret = [];
                while ($status = DBA::fetch($statuses)) {
                        $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
index aabf6f98db71d0231a029bc068ca70cdf161bcc9..7f4a6c6dc7e4ca9ea98680aeff0a9d725a4c0aa1 100644 (file)
@@ -21,7 +21,6 @@
 
 namespace Friendica\Module\Api\Twitter\Statuses;
 
-use Friendica\Core\Logger;
 use Friendica\Module\BaseApi;
 use Friendica\DI;
 use Friendica\Model\Contact;
@@ -50,7 +49,7 @@ class Destroy extends BaseApi
 
                $this->logger->notice('API: api_statuses_destroy: ' . $id);
 
-               $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
+               $include_entities = $this->getRequestValue($request, 'include_entities', false);
 
                $ret = DI::twitterStatus()->createFromItemId($id, $uid, $include_entities)->toArray();
 
index 41ce9b37e114a72b6922232afbda4326e3923454..41314bb1b7ab614f62b67ba9532fdb7edc3425b6 100644 (file)
@@ -43,12 +43,13 @@ class HomeTimeline extends BaseApi
                // get last network messages
 
                // params
-               $count           = $this->getRequestValue($request, 'count', 20, 1, 100);
-               $page            = $this->getRequestValue($request, 'page', 1, 1);
-               $since_id        = $this->getRequestValue($request, 'since_id', 0, 0);
-               $max_id          = $this->getRequestValue($request, 'max_id', 0, 0);
-               $exclude_replies = $this->getRequestValue($request, 'exclude_replies', false);
-               $conversation_id = $this->getRequestValue($request, 'conversation_id', 0, 0);
+               $count            = $this->getRequestValue($request, 'count', 20, 1, 100);
+               $page             = $this->getRequestValue($request, 'page', 1, 1);
+               $since_id         = $this->getRequestValue($request, 'since_id', 0, 0);
+               $max_id           = $this->getRequestValue($request, 'max_id', 0, 0);
+               $exclude_replies  = $this->getRequestValue($request, 'exclude_replies', false);
+               $include_entities = $this->getRequestValue($request, 'include_entities', false);
+               $conversation_id  = $this->getRequestValue($request, 'conversation_id', 0, 0);
 
                $start = max(0, ($page - 1) * $count);
 
@@ -71,8 +72,6 @@ class HomeTimeline extends BaseApi
                $params   = ['order' => ['id' => true], 'limit' => [$start, $count]];
                $statuses = Post::selectForUser($uid, [], $condition, $params);
 
-               $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
-
                $ret     = [];
                $idarray = [];
                while ($status = DBA::fetch($statuses)) {
index 0ddabd9a4a7fc9b0909e852a0a32b05f865094b1..e9bbb93bdf413f00acc12e4bb0591f5780af053e 100644 (file)
@@ -42,10 +42,11 @@ class Mentions extends BaseApi
                // get last network messages
 
                // params
-               $count    = $this->getRequestValue($request, 'count', 20, 1, 100);
-               $page     = $this->getRequestValue($request, 'page', 1, 1);
-               $since_id = $this->getRequestValue($request, 'since_id', 0, 0);
-               $max_id   = $this->getRequestValue($request, 'max_id', 0, 0);
+               $count            = $this->getRequestValue($request, 'count', 20, 1, 100);
+               $page             = $this->getRequestValue($request, 'page', 1, 1);
+               $since_id         = $this->getRequestValue($request, 'since_id', 0, 0);
+               $max_id           = $this->getRequestValue($request, 'max_id', 0, 0);
+               $include_entities = $this->getRequestValue($request, 'include_entities', false);
 
                $start = max(0, ($page - 1) * $count);
 
@@ -72,8 +73,6 @@ class Mentions extends BaseApi
                $params   = ['order' => ['id' => true], 'limit' => [$start, $count]];
                $statuses = Post::selectForUser($uid, [], $condition, $params);
 
-               $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
-
                $ret = [];
                while ($status = DBA::fetch($statuses)) {
                        $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
index d7612d193a42e34fa88c06b1355b6fe55ed47154..af0436b4a29afa6ae502ccd88ae1edb65c8f327e 100644 (file)
@@ -38,12 +38,11 @@ class NetworkPublicTimeline extends BaseApi
                BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
                $uid = BaseApi::getCurrentUserID();
 
-               $since_id = $_REQUEST['since_id'] ?? 0;
-               $max_id   = $_REQUEST['max_id']   ?? 0;
-
-               // pagination
-               $count = $_REQUEST['count'] ?? 20;
-               $page  = $_REQUEST['page']  ?? 1;
+               $count            = $this->getRequestValue($request, 'count', 20, 1, 100);
+               $page             = $this->getRequestValue($request, 'page', 1, 1);
+               $since_id         = $this->getRequestValue($request, 'since_id', 0, 0);
+               $max_id           = $this->getRequestValue($request, 'max_id', 0, 0);
+               $include_entities = $this->getRequestValue($request, 'include_entities', false);
 
                $start = max(0, ($page - 1) * $count);
 
@@ -58,8 +57,6 @@ class NetworkPublicTimeline extends BaseApi
                $params   = ['order' => ['id' => true], 'limit' => [$start, $count]];
                $statuses = Post::selectForUser($uid, Item::DISPLAY_FIELDLIST, $condition, $params);
 
-               $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
-
                $ret = [];
                while ($status = DBA::fetch($statuses)) {
                        $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
index 2a71bfe965aa68bca4ca8144ee2cbcc54b65dab2..aba330a658bbc047a2d7991cdd46ffcc1af81e9d 100644 (file)
@@ -41,12 +41,13 @@ class PublicTimeline extends BaseApi
                // get last network messages
 
                // params
-               $count           = $this->getRequestValue($request, 'count', 20, 1, 100);
-               $page            = $this->getRequestValue($request, 'page', 1, 1);
-               $since_id        = $this->getRequestValue($request, 'since_id', 0, 0);
-               $max_id          = $this->getRequestValue($request, 'max_id', 0, 0);
-               $exclude_replies = $this->getRequestValue($request, 'exclude_replies', false);
-               $conversation_id = $this->getRequestValue($request, 'conversation_id', 0, 0);
+               $count            = $this->getRequestValue($request, 'count', 20, 1, 100);
+               $page             = $this->getRequestValue($request, 'page', 1, 1);
+               $since_id         = $this->getRequestValue($request, 'since_id', 0, 0);
+               $max_id           = $this->getRequestValue($request, 'max_id', 0, 0);
+               $exclude_replies  = $this->getRequestValue($request, 'exclude_replies', false);
+               $conversation_id  = $this->getRequestValue($request, 'conversation_id', 0, 0);
+               $include_entities = $this->getRequestValue($request, 'include_entities', false);
 
                $start = max(0, ($page - 1) * $count);
 
@@ -78,8 +79,6 @@ class PublicTimeline extends BaseApi
                        $statuses = Post::selectForUser($uid, [], $condition, $params);
                }
 
-               $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
-
                $ret = [];
                while ($status = DBA::fetch($statuses)) {
                        $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
index f698997094b9d4085c63f5ee48a28cb458edee3f..a85483790576498056fba24ba22a98a944fac169 100644 (file)
@@ -79,7 +79,7 @@ class Show extends BaseApi
                        throw new BadRequestException(sprintf("There is no status or conversation with the id %d.", $id));
                }
 
-               $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
+               $include_entities = $this->getRequestValue($request, 'include_entities', false);
 
                $ret = [];
                while ($status = DBA::fetch($statuses)) {
index 2255287c77ed17d73a7766f5f71fe2a8d84ab4af..b6dcd86c9199041d3fb741ccd20f82056b3d401d 100644 (file)
@@ -42,15 +42,14 @@ class UserTimeline extends BaseApi
 
                Logger::info('api_statuses_user_timeline', ['api_user' => $uid, '_REQUEST' => $request]);
 
-               $cid             = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, $uid);
-               $since_id        = $request['since_id'] ?? 0;
-               $max_id          = $request['max_id']   ?? 0;
-               $exclude_replies = !empty($request['exclude_replies']);
-               $conversation_id = $request['conversation_id'] ?? 0;
-
-               // pagination
-               $count = $request['count'] ?? 20;
-               $page  = $request['page']  ?? 1;
+               $cid              = BaseApi::getContactIDForSearchterm($request['screen_name'] ?? '', $request['profileurl'] ?? '', $request['user_id'] ?? 0, $uid);
+               $count            = $this->getRequestValue($request, 'count', 20, 1, 100);
+               $page             = $this->getRequestValue($request, 'page', 1, 1);
+               $since_id         = $this->getRequestValue($request, 'since_id', 0, 0);
+               $max_id           = $this->getRequestValue($request, 'max_id', 0, 0);
+               $exclude_replies  = $this->getRequestValue($request, 'exclude_replies', false);
+               $conversation_id  = $this->getRequestValue($request, 'conversation_id', 0, 0);
+               $include_entities = $this->getRequestValue($request, 'include_entities', false);
 
                $start = max(0, ($page - 1) * $count);
 
@@ -74,8 +73,6 @@ class UserTimeline extends BaseApi
                $params   = ['order' => ['id' => true], 'limit' => [$start, $count]];
                $statuses = Post::selectForUser($uid, [], $condition, $params);
 
-               $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
-
                $ret = [];
                while ($status = DBA::fetch($statuses)) {
                        $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();