friendica/src/Module/Api/Mastodon/Trends/Statuses.php

63 lines
2 KiB
PHP
Raw Normal View History

2020-10-31 23:32:26 +01:00
<?php
/**
2023-01-01 15:36:24 +01:00
* @copyright Copyright (C) 2010-2023, the Friendica project
2020-10-31 23:32:26 +01:00
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
2022-11-28 10:30:41 +01:00
namespace Friendica\Module\Api\Mastodon\Trends;
2020-10-31 23:32:26 +01:00
2022-11-28 10:30:41 +01:00
use Friendica\Core\Protocol;
2020-10-31 23:32:26 +01:00
use Friendica\Core\System;
2022-11-28 10:30:41 +01:00
use Friendica\Database\DBA;
2020-10-31 23:32:26 +01:00
use Friendica\DI;
2022-11-28 10:30:41 +01:00
use Friendica\Model\Post;
2020-10-31 23:32:26 +01:00
use Friendica\Module\BaseApi;
2022-11-28 10:30:41 +01:00
use Friendica\Util\DateTimeFormat;
2020-10-31 23:32:26 +01:00
/**
2022-11-28 10:30:41 +01:00
* @see https://docs.joinmastodon.org/methods/trends/#statuses
2020-10-31 23:32:26 +01:00
*/
2022-11-28 10:30:41 +01:00
class Statuses extends BaseApi
2020-10-31 23:32:26 +01:00
{
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
protected function rawContent(array $request = [])
2020-10-31 23:32:26 +01:00
{
2022-11-28 21:19:57 +01:00
$uid = self::getCurrentUserID();
$request = $this->getRequest([
2022-11-28 10:30:41 +01:00
'limit' => 10, // Maximum number of results to return. Defaults to 10.
], $request);
2020-10-31 23:32:26 +01:00
$condition = ["NOT `private` AND `commented` > ? AND `created` > ?", DateTimeFormat::utc('now -1 day'), DateTimeFormat::utc('now -1 week')];
2022-11-28 10:30:41 +01:00
$condition = DBA::mergeConditions($condition, ['network' => Protocol::FEDERATED]);
2022-11-28 11:54:26 +01:00
$display_quotes = self::appSupportsQuotes();
2022-11-28 11:54:26 +01:00
$trending = [];
2022-11-28 21:19:57 +01:00
$statuses = Post::selectPostThread(['uri-id'], $condition, ['limit' => $request['limit'], 'order' => ['total-actors' => true]]);
2022-11-28 10:30:41 +01:00
while ($status = Post::fetch($statuses)) {
2023-01-25 21:14:33 +01:00
$trending[] = DI::mstdnStatus()->createFromUriId($status['uri-id'], $uid, $display_quotes);
2020-10-31 23:32:26 +01:00
}
2022-11-28 10:30:41 +01:00
DBA::close($statuses);
2020-10-31 23:32:26 +01:00
2022-11-28 10:30:41 +01:00
System::jsonExit($trending);
2020-10-31 23:32:26 +01:00
}
}