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
|
|
|
|
*/
|
2021-11-20 15:38:03 +01:00
|
|
|
protected function rawContent(array $request = [])
|
2020-10-31 23:32:26 +01:00
|
|
|
{
|
2021-11-28 13:22:27 +01:00
|
|
|
$request = $this->getRequest([
|
2022-11-28 10:30:41 +01:00
|
|
|
'limit' => 10, // Maximum number of results to return. Defaults to 10.
|
2021-11-28 00:30:41 +01:00
|
|
|
], $request);
|
2020-10-31 23:32:26 +01:00
|
|
|
|
2022-11-28 15:51:37 +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
|
|
|
|
|
|
|
$trending = [];
|
2022-11-28 10:30:41 +01:00
|
|
|
$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
|
|
|
}
|
|
|
|
}
|