$toplevel_item_id = intval($_REQUEST['parent'] ?? 0);
$thr_parent_uri = trim($_REQUEST['parent_uri'] ?? '');
- $thread_parent_id = 0;
+ $thread_parent_uriid = 0;
$thread_parent_contact = null;
$toplevel_item = null;
// if this isn't the top-level parent of the conversation, find it
if (DBA::isResult($toplevel_item)) {
// The URI and the contact is taken from the direct parent which needn't to be the top parent
- $thread_parent_id = $toplevel_item['id'];
+ $thread_parent_uriid = $toplevel_item['uri-id'];
$thr_parent_uri = $toplevel_item['uri'];
$thread_parent_contact = Contact::getDetailsByURL($toplevel_item["author-link"]);
$tags = BBCode::getTags($body);
- if ($thread_parent_id && !\Friendica\Content\Feature::isEnabled($uid, 'explicit_mentions')) {
- $tags = item_add_implicit_mentions($tags, $thread_parent_contact, $thread_parent_id);
+ if ($thread_parent_uriid && !\Friendica\Content\Feature::isEnabled($uid, 'explicit_mentions')) {
+ $tags = item_add_implicit_mentions($tags, $thread_parent_contact, $thread_parent_uriid);
}
$tagged = [];
return ['replaced' => $replaced, 'contact' => $contact];
}
-function item_add_implicit_mentions(array $tags, array $thread_parent_contact, $thread_parent_id)
+function item_add_implicit_mentions(array $tags, array $thread_parent_contact, $thread_parent_uriid)
{
if (DI::config()->get('system', 'disable_implicit_mentions')) {
// Add a tag if the parent contact is from ActivityPub or OStatus (This will notify them)
$thread_parent_contact['url'] => $thread_parent_contact['nick']
];
- $parent_terms = Term::tagArrayFromItemId($thread_parent_id, [Tag::MENTION, Tag::IMPLICIT_MENTION]);
+ $parent_terms = Tag::getByURIId($thread_parent_uriid, [Tag::MENTION, Tag::IMPLICIT_MENTION]);
foreach ($parent_terms as $parent_term) {
$implicit_mentions[$parent_term['url']] = $parent_term['term'];
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\Tag;
-use Friendica\Model\Term;
/**
* Trending tags aside widget for the community pages, handles both local and global scopes
public static function getHTML($content = 'global', int $period = 24)
{
if ($content == 'local') {
- $tags = Term::getLocalTrendingHashtags($period, 20);
+ $tags = Tag::getLocalTrendingHashtags($period, 20);
} else {
- $tags = Term::getGlobalTrendingHashtags($period, 20);
+ $tags = Tag::getGlobalTrendingHashtags($period, 20);
}
$tpl = Renderer::getMarkupTemplate('widget/trending_tags.tpl');
namespace Friendica\Model;
use Friendica\Content\Text\BBCode;
+use Friendica\Core\Cache\Duration;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Database\DBA;
return $uriids;
}
+
+ /**
+ * Returns a list of the most frequent global hashtags over the given period
+ *
+ * @param int $period Period in hours to consider posts
+ * @return array
+ * @throws \Exception
+ */
+ public static function getGlobalTrendingHashtags(int $period, $limit = 10)
+ {
+ $tags = DI::cache()->get('global_trending_tags');
+
+ if (empty($tags)) {
+ $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`
+ FROM `tag-search-view`
+ WHERE `private` = ? AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR)
+ GROUP BY `term` ORDER BY `score` DESC LIMIT ?",
+ Item::PUBLIC, $period, $limit);
+
+ if (DBA::isResult($tagsStmt)) {
+ $tags = DBA::toArray($tagsStmt);
+ DI::cache()->set('global_trending_tags', $tags, Duration::HOUR);
+ }
+ }
+
+ return $tags ?: [];
+ }
+
+ /**
+ * Returns a list of the most frequent local hashtags over the given period
+ *
+ * @param int $period Period in hours to consider posts
+ * @return array
+ * @throws \Exception
+ */
+ public static function getLocalTrendingHashtags(int $period, $limit = 10)
+ {
+ $tags = DI::cache()->get('local_trending_tags');
+
+ if (empty($tags)) {
+ $tagsStmt = DBA::p("SELECT `name` AS `term`, COUNT(*) AS `score`
+ FROM `tag-search-view`
+ WHERE `private` = ? AND `wall` AND `origin` AND `received` > DATE_SUB(NOW(), INTERVAL ? HOUR)
+ GROUP BY `term` ORDER BY `score` DESC LIMIT ?",
+ Item::PUBLIC, $period, $limit);
+
+ if (DBA::isResult($tagsStmt)) {
+ $tags = DBA::toArray($tagsStmt);
+ DI::cache()->set('local_trending_tags', $tags, Duration::HOUR);
+ }
+ }
+
+ return $tags ?: [];
+ }
}
const OBJECT_TYPE_POST = 1;
const OBJECT_TYPE_PHOTO = 2;
- /**
- * Returns a list of the most frequent global hashtags over the given period
- *
- * @param int $period Period in hours to consider posts
- * @return array
- * @throws \Exception
- */
- public static function getGlobalTrendingHashtags(int $period, $limit = 10)
- {
- $tags = DI::cache()->get('global_trending_tags');
-
- if (!$tags) {
- $tagsStmt = DBA::p("SELECT t.`term`, COUNT(*) AS `score`
- FROM `term` t
- JOIN `item` i ON i.`id` = t.`oid` AND i.`uid` = t.`uid`
- JOIN `thread` ON `thread`.`iid` = i.`id`
- WHERE `thread`.`visible`
- AND NOT `thread`.`deleted`
- AND NOT `thread`.`moderated`
- AND `thread`.`private` = ?
- AND t.`uid` = 0
- AND t.`otype` = ?
- AND t.`type` = ?
- AND t.`term` != ''
- AND i.`received` > DATE_SUB(NOW(), INTERVAL ? HOUR)
- GROUP BY `term`
- ORDER BY `score` DESC
- LIMIT ?",
- Item::PUBLIC,
- self::OBJECT_TYPE_POST,
- self::HASHTAG,
- $period,
- $limit
- );
-
- if (DBA::isResult($tagsStmt)) {
- $tags = DBA::toArray($tagsStmt);
- DI::cache()->set('global_trending_tags', $tags, Duration::HOUR);
- }
- }
-
- return $tags ?: [];
- }
-
- /**
- * Returns a list of the most frequent local hashtags over the given period
- *
- * @param int $period Period in hours to consider posts
- * @return array
- * @throws \Exception
- */
- public static function getLocalTrendingHashtags(int $period, $limit = 10)
- {
- $tags = DI::cache()->get('local_trending_tags');
-
- if (!$tags) {
- $tagsStmt = DBA::p("SELECT t.`term`, COUNT(*) AS `score`
- FROM `term` t
- JOIN `item` i ON i.`id` = t.`oid` AND i.`uid` = t.`uid`
- JOIN `thread` ON `thread`.`iid` = i.`id`
- WHERE `thread`.`visible`
- AND NOT `thread`.`deleted`
- AND NOT `thread`.`moderated`
- AND `thread`.`private` = ?
- AND `thread`.`wall`
- AND `thread`.`origin`
- AND t.`otype` = ?
- AND t.`type` = ?
- AND t.`term` != ''
- AND i.`received` > DATE_SUB(NOW(), INTERVAL ? HOUR)
- GROUP BY `term`
- ORDER BY `score` DESC
- LIMIT ?",
- Item::PUBLIC,
- self::OBJECT_TYPE_POST,
- self::HASHTAG,
- $period,
- $limit
- );
-
- if (DBA::isResult($tagsStmt)) {
- $tags = DBA::toArray($tagsStmt);
- DI::cache()->set('local_trending_tags', $tags, Duration::HOUR);
- }
- }
-
- return $tags ?: [];
- }
-
/**
* Generates the legacy item.tag field comma-separated BBCode string from an item ID.
* Includes only hashtags, implicit and explicit mentions.
* @return array
* @throws \Exception
*/
- public static function tagArrayFromItemId($item_id, $type = [self::HASHTAG, self::MENTION])
+ private static function tagArrayFromItemId($item_id, $type = [self::HASHTAG, self::MENTION])
{
$condition = ['otype' => self::OBJECT_TYPE_POST, 'oid' => $item_id, 'type' => $type];
$tags = DBA::select('term', ['type', 'term', 'url'], $condition);
$item_id = '';
$terms = [];
if (!empty($guid)) {
- $item = Model\Item::selectFirst(['id', 'guid', 'uri'], ['guid' => $guid]);
+ $item = Model\Item::selectFirst(['id', 'uri-id', 'guid', 'uri'], ['guid' => $guid]);
$conversation = Model\Conversation::getByItemUri($item['uri']);
$item_id = $item['id'];
$item_uri = $item['uri'];
$source = $conversation['source'];
- $terms = Model\Term::tagArrayFromItemId($item['id'], [Model\Term::HASHTAG, Model\Term::MENTION, Model\Term::IMPLICIT_MENTION]);
+ $terms = Model\Tag::getByURIId($item['uri-id'], [Model\Tag::HASHTAG, Model\Tag::MENTION, Model\Tag::IMPLICIT_MENTION]);
}
$tpl = Renderer::getMarkupTemplate('admin/item/source.tpl');
"guid" => ["item", "guid"],
"uid" => ["item", "uid"],
"private" => ["item", "private"],
+ "wall" => ["item", "wall"],
+ "origin" => ["item", "origin"],
+ "gravity" => ["item", "gravity"],
+ "received" => ["item", "received"],
"name" => ["tag", "name"],
],
"query" => "FROM `post-tag`