From: Michael Date: Fri, 1 May 2020 10:57:32 +0000 (+0000) Subject: Some more "term" to "tag" conversion X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ac2957c4dda0ec3421f9d47a7d601bdcdd1d9579;p=friendica.git Some more "term" to "tag" conversion --- diff --git a/mod/item.php b/mod/item.php index bd28d33899..b97f8bbe31 100644 --- a/mod/item.php +++ b/mod/item.php @@ -101,7 +101,7 @@ function item_post(App $a) { $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; @@ -123,7 +123,7 @@ function item_post(App $a) { // 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"]); @@ -381,8 +381,8 @@ function item_post(App $a) { $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 = []; @@ -1044,7 +1044,7 @@ function handle_tag(&$body, &$inform, &$str_tags, $profile_uid, $tag, $network = 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) @@ -1059,7 +1059,7 @@ function item_add_implicit_mentions(array $tags, array $thread_parent_contact, $ $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']; diff --git a/src/Content/Widget/TrendingTags.php b/src/Content/Widget/TrendingTags.php index 053cba09d3..9c24d1549c 100644 --- a/src/Content/Widget/TrendingTags.php +++ b/src/Content/Widget/TrendingTags.php @@ -24,7 +24,6 @@ namespace Friendica\Content\Widget; 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 @@ -42,9 +41,9 @@ class TrendingTags 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'); diff --git a/src/Model/Tag.php b/src/Model/Tag.php index ef962b582c..0a3e0e8533 100644 --- a/src/Model/Tag.php +++ b/src/Model/Tag.php @@ -22,6 +22,7 @@ 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; @@ -416,4 +417,58 @@ class Tag 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 ?: []; + } } diff --git a/src/Model/Term.php b/src/Model/Term.php index a6858d8415..6f241015f8 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -60,95 +60,6 @@ class Term 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. @@ -176,7 +87,7 @@ class Term * @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); diff --git a/src/Module/Admin/Item/Source.php b/src/Module/Admin/Item/Source.php index b8aaff99b8..e35eafd2f2 100644 --- a/src/Module/Admin/Item/Source.php +++ b/src/Module/Admin/Item/Source.php @@ -48,14 +48,14 @@ class Source extends BaseAdmin $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'); diff --git a/static/dbview.config.php b/static/dbview.config.php index 3be78bf694..0f0d691085 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -228,6 +228,10 @@ return [ "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`