]> git.mxchange.org Git - friendica.git/commitdiff
Some more "term" to "tag" conversion
authorMichael <heluecht@pirati.ca>
Fri, 1 May 2020 10:57:32 +0000 (10:57 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 1 May 2020 10:57:32 +0000 (10:57 +0000)
mod/item.php
src/Content/Widget/TrendingTags.php
src/Model/Tag.php
src/Model/Term.php
src/Module/Admin/Item/Source.php
static/dbview.config.php

index bd28d33899eda072bf3b3da20038d5f70cf466ee..b97f8bbe31739757f9cbc069859307b66decbb97 100644 (file)
@@ -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'];
index 053cba09d3d58f9fc1180bb19bbc1998d05d6415..9c24d1549cf8871abd7034f0e676705c420a222f 100644 (file)
@@ -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');
index ef962b582cc8be70e6d0396e3387d22bffe6a525..0a3e0e85337f6def2a7535e0fd301681390f406a 100644 (file)
@@ -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 ?: [];
+       }
 }
index a6858d8415a403e86b411fee2848e6f730fb5ab6..6f241015f8f0273737e209a881ea2c07ec07dcdc 100644 (file)
@@ -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);
index b8aaff99b8f0952621a9a3ec9684c7d6d0398ecd..e35eafd2f27376b04cd36edc89d9dbbfb95e8041 100644 (file)
@@ -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');
index 3be78bf6943fa4f29cc5f946ebe61ad8d9045748..0f0d691085a186193c119b69274d1849d9257ee0 100755 (executable)
@@ -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`