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

55 lines
1.7 KiB
PHP
Raw Normal View History

2020-10-31 22:32:26 +00:00
<?php
/**
2021-03-29 06:40:20 +00:00
* @copyright Copyright (C) 2010-2021, the Friendica project
2020-10-31 22:32:26 +00: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/>.
*
*/
namespace Friendica\Module\Api\Mastodon;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Tag;
use Friendica\Module\BaseApi;
/**
* @see https://docs.joinmastodon.org/methods/instance/trends/
*/
class Trends extends BaseApi
{
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
2021-11-14 22:13:47 +00:00
public function rawContent()
2020-10-31 22:32:26 +00:00
{
2021-05-19 06:18:42 +00:00
$request = self::getRequest([
'limit' => 20, // Maximum number of results to return. Defaults to 10.
]);
2020-10-31 22:32:26 +00:00
$trending = [];
$tags = Tag::getGlobalTrendingHashtags(24, 20);
foreach ($tags as $tag) {
$tag['name'] = $tag['term'];
2021-06-24 22:15:25 +00:00
$history = [['day' => (string)time(), 'uses' => (string)$tag['score'], 'accounts' => (string)$tag['authors']]];
$hashtag = new \Friendica\Object\Api\Mastodon\Tag(DI::baseUrl(), $tag, $history);
2020-10-31 22:32:26 +00:00
$trending[] = $hashtag->toArray();
}
2021-05-19 06:18:42 +00:00
System::jsonExit(array_slice($trending, 0, $request['limit']));
2020-10-31 22:32:26 +00:00
}
}