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

58 lines
1.9 KiB
PHP
Raw Normal View History

2020-10-31 23:32:26 +01:00
<?php
/**
2022-01-02 08:27:47 +01:00
* @copyright Copyright (C) 2010-2022, 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
{
$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
$trending = [];
2022-11-28 10:30:41 +01:00
$condition = ["NOT `private` AND `commented` > ?", DateTimeFormat::utc('now -1 day')];
$condition = DBA::mergeConditions($condition, ['network' => Protocol::FEDERATED]);
$statuses = Post::selectPostThread(['uri-id'], $condition, ['limit' => $request['limit'], 'order' => ['total-comments' => true]]);
while ($status = Post::fetch($statuses)) {
$trending[] = DI::mstdnStatus()->createFromUriId($status['uri-id']);
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
}
}