Improved handling of boolean input values

This commit is contained in:
Michael 2022-01-16 09:24:35 +00:00
parent e6108668e3
commit 7b68a5956e
13 changed files with 18 additions and 18 deletions

View File

@ -65,7 +65,7 @@ class Seen extends BaseApi
if ($Notify->otype === Notification\ObjectType::ITEM) { if ($Notify->otype === Notification\ObjectType::ITEM) {
$item = Post::selectFirstForUser($uid, [], ['id' => $Notify->iid, 'uid' => $uid]); $item = Post::selectFirstForUser($uid, [], ['id' => $Notify->iid, 'uid' => $uid]);
if (DBA::isResult($item)) { if (DBA::isResult($item)) {
$include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true'); $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
// we found the item, return it to the user // we found the item, return it to the user
$ret = [DI::twitterStatus()->createFromUriId($item['uri-id'], $item['uid'], $include_entities)->toArray()]; $ret = [DI::twitterStatus()->createFromUriId($item['uri-id'], $item['uid'], $include_entities)->toArray()];

View File

@ -41,15 +41,15 @@ class Conversation extends BaseApi
// params // params
$id = $this->parameters['id'] ?? 0; $id = $this->parameters['id'] ?? 0;
$since_id = $_REQUEST['since_id'] ?? 0; $since_id = $request['since_id'] ?? 0;
$max_id = $_REQUEST['max_id'] ?? 0; $max_id = $request['max_id'] ?? 0;
$count = $_REQUEST['count'] ?? 20; $count = $request['count'] ?? 20;
$page = $_REQUEST['page'] ?? 1; $page = $request['page'] ?? 1;
$start = max(0, ($page - 1) * $count); $start = max(0, ($page - 1) * $count);
if ($id == 0) { if ($id == 0) {
$id = $_REQUEST['id'] ?? 0; $id = $request['id'] ?? 0;
} }
Logger::info(BaseApi::LOG_PREFIX . '{subaction}', ['module' => 'api', 'action' => 'conversation', 'subaction' => 'show', 'id' => $id]); Logger::info(BaseApi::LOG_PREFIX . '{subaction}', ['module' => 'api', 'action' => 'conversation', 'subaction' => 'show', 'id' => $id]);
@ -82,7 +82,7 @@ class Conversation extends BaseApi
throw new BadRequestException("There is no status with id $id."); throw new BadRequestException("There is no status with id $id.");
} }
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true'); $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
$ret = []; $ret = [];
while ($status = DBA::fetch($statuses)) { while ($status = DBA::fetch($statuses)) {

View File

@ -56,7 +56,7 @@ class UpdateProfile extends BaseApi
Profile::publishUpdate($uid); Profile::publishUpdate($uid);
$skip_status = $request['skip_status'] ?? false; $skip_status = filter_var($request['skip_status'] ?? false, FILTER_VALIDATE_BOOLEAN);
$user_info = DI::twitterUser()->createFromUserId($uid, $skip_status)->toArray(); $user_info = DI::twitterUser()->createFromUserId($uid, $skip_status)->toArray();

View File

@ -37,7 +37,7 @@ class VerifyCredentials extends BaseApi
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID(); $uid = BaseApi::getCurrentUserID();
$skip_status = $_REQUEST['skip_status'] ?? false; $skip_status = filter_var($request['skip_status'] ?? false, FILTER_VALIDATE_BOOLEAN);
$user_info = DI::twitterUser()->createFromUserId($uid, $skip_status)->toArray(); $user_info = DI::twitterUser()->createFromUserId($uid, $skip_status)->toArray();

View File

@ -95,7 +95,7 @@ class Statuses extends BaseApi
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, [], $condition, $params); $statuses = Post::selectForUser($uid, [], $condition, $params);
$include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true'); $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
$items = []; $items = [];
while ($status = $this->dba->fetch($statuses)) { while ($status = $this->dba->fetch($statuses)) {

View File

@ -115,7 +115,7 @@ class Tweets extends BaseApi
$statuses = $statuses ?: Post::selectForUser($uid, [], $condition, $params); $statuses = $statuses ?: Post::selectForUser($uid, [], $condition, $params);
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true'); $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
$ret = []; $ret = [];
while ($status = DBA::fetch($statuses)) { while ($status = DBA::fetch($statuses)) {

View File

@ -50,7 +50,7 @@ class Destroy extends BaseApi
$this->logger->notice('API: api_statuses_destroy: ' . $id); $this->logger->notice('API: api_statuses_destroy: ' . $id);
$include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true'); $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
$ret = DI::twitterStatus()->createFromItemId($id, $uid, $include_entities)->toArray(); $ret = DI::twitterStatus()->createFromItemId($id, $uid, $include_entities)->toArray();

View File

@ -71,7 +71,7 @@ class HomeTimeline extends BaseApi
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, [], $condition, $params); $statuses = Post::selectForUser($uid, [], $condition, $params);
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true'); $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
$ret = []; $ret = [];
$idarray = []; $idarray = [];

View File

@ -72,7 +72,7 @@ class Mentions extends BaseApi
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, [], $condition, $params); $statuses = Post::selectForUser($uid, [], $condition, $params);
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true'); $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
$ret = []; $ret = [];
while ($status = DBA::fetch($statuses)) { while ($status = DBA::fetch($statuses)) {

View File

@ -58,7 +58,7 @@ class NetworkPublicTimeline extends BaseApi
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, Item::DISPLAY_FIELDLIST, $condition, $params); $statuses = Post::selectForUser($uid, Item::DISPLAY_FIELDLIST, $condition, $params);
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true'); $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
$ret = []; $ret = [];
while ($status = DBA::fetch($statuses)) { while ($status = DBA::fetch($statuses)) {

View File

@ -78,7 +78,7 @@ class PublicTimeline extends BaseApi
$statuses = Post::selectForUser($uid, [], $condition, $params); $statuses = Post::selectForUser($uid, [], $condition, $params);
} }
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true'); $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
$ret = []; $ret = [];
while ($status = DBA::fetch($statuses)) { while ($status = DBA::fetch($statuses)) {

View File

@ -79,7 +79,7 @@ class Show extends BaseApi
throw new BadRequestException(sprintf("There is no status or conversation with the id %d.", $id)); throw new BadRequestException(sprintf("There is no status or conversation with the id %d.", $id));
} }
$include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true'); $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
$ret = []; $ret = [];
while ($status = DBA::fetch($statuses)) { while ($status = DBA::fetch($statuses)) {

View File

@ -74,7 +74,7 @@ class UserTimeline extends BaseApi
$params = ['order' => ['id' => true], 'limit' => [$start, $count]]; $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Post::selectForUser($uid, [], $condition, $params); $statuses = Post::selectForUser($uid, [], $condition, $params);
$include_entities = strtolower(($request['include_entities'] ?? 'false') == 'true'); $include_entities = filter_var($request['include_entities'] ?? false, FILTER_VALIDATE_BOOLEAN);
$ret = []; $ret = [];
while ($status = DBA::fetch($statuses)) { while ($status = DBA::fetch($statuses)) {