friendica/src/Content/Widget/TrendingTags.php

59 lines
1.8 KiB
PHP
Raw Normal View History

2019-08-06 03:00:27 +02:00
<?php
2020-02-09 15:45:36 +01:00
/**
* @copyright Copyright (C) 2020, Friendica
*
* @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/>.
*
*/
2019-08-06 03:00:27 +02:00
namespace Friendica\Content\Widget;
use Friendica\Core\Renderer;
2020-01-18 22:07:07 +01:00
use Friendica\DI;
2019-08-06 03:00:27 +02:00
use Friendica\Model\Term;
/**
* Trending tags aside widget for the community pages, handles both local and global scopes
*
* @package Friendica\Content\Widget
*/
2019-08-06 03:00:27 +02:00
class TrendingTags
{
/**
* @param string $content 'global' (all posts) or 'local' (this node's posts only)
* @param int $period Period in hours to consider posts
* @return string
* @throws \Exception
*/
public static function getHTML($content = 'global', int $period = 24)
{
if ($content == 'local') {
$tags = Term::getLocalTrendingHashtags($period, 20);
2019-08-06 03:00:27 +02:00
} else {
$tags = Term::getGlobalTrendingHashtags($period, 20);
2019-08-06 03:00:27 +02:00
}
$tpl = Renderer::getMarkupTemplate('widget/trending_tags.tpl');
$o = Renderer::replaceMacros($tpl, [
'$title' => DI::l10n()->tt('Trending Tags (last %d hour)', 'Trending Tags (last %d hours)', $period),
'$more' => DI::l10n()->t('More Trending Tags'),
2019-08-06 03:00:27 +02:00
'$tags' => $tags,
]);
return $o;
}
}