From 7f5f68a9048644ffbc3ce4fb94e56c0dae480d0c Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Apr 2020 16:15:39 +0000 Subject: [PATCH] More preparations for term to tag transition --- include/api.php | 3 ++- mod/item.php | 15 +++++++-------- mod/network.php | 3 ++- mod/tagger.php | 4 ++-- src/Content/Widget/TagCloud.php | 5 +++-- src/Content/Widget/TrendingTags.php | 1 + src/Model/Item.php | 11 ++++++++--- src/Model/UserItem.php | 3 ++- src/Module/Hashtag.php | 3 ++- src/Module/Profile/Status.php | 3 ++- src/Module/Search/Index.php | 3 ++- 11 files changed, 33 insertions(+), 21 deletions(-) diff --git a/include/api.php b/include/api.php index 36b08f08f8..77dc020da3 100644 --- a/include/api.php +++ b/include/api.php @@ -41,6 +41,7 @@ use Friendica\Model\Item; use Friendica\Model\Mail; use Friendica\Model\Notify; use Friendica\Model\Photo; +use Friendica\Model\Tag; use Friendica\Model\Term; use Friendica\Model\User; use Friendica\Model\UserItem; @@ -1542,7 +1543,7 @@ function api_search($type) $condition = ["`oid` > ? AND (`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `otype` = ? AND `type` = ? AND `term` = ?", - $since_id, local_user(), Term::OBJECT_TYPE_POST, Term::HASHTAG, $searchTerm]; + $since_id, local_user(), Term::OBJECT_TYPE_POST, Tag::HASHTAG, $searchTerm]; if ($max_id > 0) { $condition[0] .= ' AND `oid` <= ?'; $condition[] = $max_id; diff --git a/mod/item.php b/mod/item.php index 5785954bce..bd28d33899 100644 --- a/mod/item.php +++ b/mod/item.php @@ -29,7 +29,6 @@ */ use Friendica\App; -use Friendica\Content\Pager; use Friendica\Content\Text\BBCode; use Friendica\Core\Hook; use Friendica\Core\Logger; @@ -396,7 +395,7 @@ function item_post(App $a) { foreach ($tags as $tag) { $tag_type = substr($tag, 0, 1); - if ($tag_type == Term::TAG_CHARACTER[Term::HASHTAG]) { + if ($tag_type == Tag::TAG_CHARACTER[Tag::HASHTAG]) { continue; } @@ -421,9 +420,9 @@ function item_post(App $a) { $tagged[] = $tag; } // When the forum is private or the forum is addressed with a "!" make the post private - if (is_array($success['contact']) && (!empty($success['contact']['prv']) || ($tag_type == Term::TAG_CHARACTER[Term::EXCLUSIVE_MENTION]))) { + if (is_array($success['contact']) && (!empty($success['contact']['prv']) || ($tag_type == Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION]))) { $private_forum = $success['contact']['prv']; - $only_to_forum = ($tag_type == Term::TAG_CHARACTER[Term::EXCLUSIVE_MENTION]); + $only_to_forum = ($tag_type == Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION]); $private_id = $success['contact']['id']; $forum_contact = $success['contact']; } elseif (is_array($success['contact']) && !empty($success['contact']['forum']) && @@ -907,7 +906,7 @@ function handle_tag(&$body, &$inform, &$str_tags, $profile_uid, $tag, $network = $r = null; //is it a person tag? - if (Term::isType($tag, Term::MENTION, Term::IMPLICIT_MENTION, Term::EXCLUSIVE_MENTION)) { + if (Term::isType($tag, Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION)) { $tag_type = substr($tag, 0, 1); //is it already replaced? if (strpos($tag, '[url=')) { @@ -1050,7 +1049,7 @@ function item_add_implicit_mentions(array $tags, array $thread_parent_contact, $ if (DI::config()->get('system', 'disable_implicit_mentions')) { // Add a tag if the parent contact is from ActivityPub or OStatus (This will notify them) if (in_array($thread_parent_contact['network'], [Protocol::OSTATUS, Protocol::ACTIVITYPUB])) { - $contact = Term::TAG_CHARACTER[Term::MENTION] . '[url=' . $thread_parent_contact['url'] . ']' . $thread_parent_contact['nick'] . '[/url]'; + $contact = Tag::TAG_CHARACTER[Tag::MENTION] . '[url=' . $thread_parent_contact['url'] . ']' . $thread_parent_contact['nick'] . '[/url]'; if (!stripos(implode($tags), '[url=' . $thread_parent_contact['url'] . ']')) { $tags[] = $contact; } @@ -1060,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, [Term::MENTION, Term::IMPLICIT_MENTION]); + $parent_terms = Term::tagArrayFromItemId($thread_parent_id, [Tag::MENTION, Tag::IMPLICIT_MENTION]); foreach ($parent_terms as $parent_term) { $implicit_mentions[$parent_term['url']] = $parent_term['term']; @@ -1068,7 +1067,7 @@ function item_add_implicit_mentions(array $tags, array $thread_parent_contact, $ foreach ($implicit_mentions as $url => $label) { if ($url != \Friendica\Model\Profile::getMyURL() && !stripos(implode($tags), '[url=' . $url . ']')) { - $tags[] = Term::TAG_CHARACTER[Term::IMPLICIT_MENTION] . '[url=' . $url . ']' . $label . '[/url]'; + $tags[] = Tag::TAG_CHARACTER[Tag::IMPLICIT_MENTION] . '[url=' . $url . ']' . $label . '[/url]'; } } } diff --git a/mod/network.php b/mod/network.php index 6c02c4f843..0c2cbccf55 100644 --- a/mod/network.php +++ b/mod/network.php @@ -38,6 +38,7 @@ use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\Profile; +use Friendica\Model\Tag; use Friendica\Model\Term; use Friendica\Module\Security\Login; use Friendica\Util\DateTimeFormat; @@ -793,7 +794,7 @@ function networkThreadedView(App $a, $update, $parent) STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `item`.`author-id` WHERE `item`.`uid` = 0 AND `item`.$ordering < ? AND `item`.$ordering > ? AND `item`.`gravity` = ? AND NOT `author`.`hidden` AND NOT `author`.`blocked`" . $sql_tag_nets, - local_user(), Term::OBJECT_TYPE_POST, Term::HASHTAG, + local_user(), Term::OBJECT_TYPE_POST, Tag::HASHTAG, $top_limit, $bottom_limit, GRAVITY_PARENT); $data = DBA::toArray($items); diff --git a/mod/tagger.php b/mod/tagger.php index b3ba472eab..f39c37103a 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -183,7 +183,7 @@ EOT; q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)", intval($item['id']), $term_objtype, - Term::HASHTAG, + Tag::HASHTAG, DBA::escape($term), '', intval($owner_uid) @@ -205,7 +205,7 @@ EOT; q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)", intval($original_item['id']), $term_objtype, - Term::HASHTAG, + Tag::HASHTAG, DBA::escape($term), '', intval($owner_uid) diff --git a/src/Content/Widget/TagCloud.php b/src/Content/Widget/TagCloud.php index 5bdf7d8346..63df5a0bd5 100644 --- a/src/Content/Widget/TagCloud.php +++ b/src/Content/Widget/TagCloud.php @@ -25,6 +25,7 @@ use Friendica\Core\Renderer; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Item; +use Friendica\Model\Tag; use Friendica\Model\Term; /** @@ -46,7 +47,7 @@ class TagCloud * @return string HTML formatted output. * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function getHTML($uid, $count = 0, $owner_id = 0, $flags = '', $type = Term::HASHTAG) + public static function getHTML($uid, $count = 0, $owner_id = 0, $flags = '', $type = Tag::HASHTAG) { $o = ''; $r = self::tagadelic($uid, $count, $owner_id, $flags, $type); @@ -85,7 +86,7 @@ class TagCloud * @return array Alphabetical sorted array of used tags of an user. * @throws \Exception */ - private static function tagadelic($uid, $count = 0, $owner_id = 0, $flags = '', $type = Term::HASHTAG) + private static function tagadelic($uid, $count = 0, $owner_id = 0, $flags = '', $type = Tag::HASHTAG) { $sql_options = Item::getPermissionsSQLByUserId($uid); $limit = $count ? sprintf('LIMIT %d', intval($count)) : ''; diff --git a/src/Content/Widget/TrendingTags.php b/src/Content/Widget/TrendingTags.php index 9f935e6de6..053cba09d3 100644 --- a/src/Content/Widget/TrendingTags.php +++ b/src/Content/Widget/TrendingTags.php @@ -23,6 +23,7 @@ namespace Friendica\Content\Widget; use Friendica\Core\Renderer; use Friendica\DI; +use Friendica\Model\Tag; use Friendica\Model\Term; /** diff --git a/src/Model/Item.php b/src/Model/Item.php index bd8d03359e..6a80765cdb 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -61,7 +61,7 @@ class Item // Field list that is used to display the items const DISPLAY_FIELDLIST = [ - 'uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid', 'network', 'gravity', + 'uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid', 'network', 'gravity', 'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink', 'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'attach', 'language', 'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object', @@ -77,7 +77,7 @@ class Item ]; // Field list that is used to deliver items via the protocols - const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid', + const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid', 'parent-guid', 'created', 'edited', 'verb', 'object-type', 'object', 'target', 'private', 'title', 'body', 'location', 'coord', 'app', 'attach', 'tag', 'deleted', 'extid', 'post-type', @@ -1674,6 +1674,11 @@ class Item // Check for hashtags in the body and repair or add hashtag links self::setHashtags($item); + // Store tags from the body if this hadn't been handled previously in the protocol classes + if (!Tag::existsForPost($item['uri-id'])) { + Tag::storeFromBody($item['uri-id'], $item['body']); + } + $item['thr-parent'] = $item['parent-uri']; $notify_type = Delivery::POST; @@ -3558,7 +3563,7 @@ class Item return $ev; } - $tags = Term::populateTagsFromItem($item); + $tags = Tag::populateTagsFromItem($item); $item['tags'] = $tags['tags']; $item['hashtags'] = $tags['hashtags']; diff --git a/src/Model/UserItem.php b/src/Model/UserItem.php index 6a228c098a..f68b5aac82 100644 --- a/src/Model/UserItem.php +++ b/src/Model/UserItem.php @@ -26,6 +26,7 @@ use Friendica\Core\Hook; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Util\Strings; +use Friendica\Model\Tag; use Friendica\Model\Term; class UserItem @@ -207,7 +208,7 @@ class UserItem } // Or the contact is a mentioned forum - $tags = DBA::select('term', ['url'], ['otype' => Term::OBJECT_TYPE_POST, 'oid' => $item['id'], 'type' => Term::MENTION, 'uid' => $uid]); + $tags = DBA::select('term', ['url'], ['otype' => Term::OBJECT_TYPE_POST, 'oid' => $item['id'], 'type' => Tag::MENTION, 'uid' => $uid]); while ($tag = DBA::fetch($tags)) { $condition = ['nurl' => Strings::normaliseLink($tag['url']), 'uid' => $uid, 'notify_new_posts' => true, 'contact-type' => Contact::TYPE_COMMUNITY]; if (DBA::exists('contact', $condition)) { diff --git a/src/Module/Hashtag.php b/src/Module/Hashtag.php index 06c6374e34..8c1dad4afd 100644 --- a/src/Module/Hashtag.php +++ b/src/Module/Hashtag.php @@ -25,6 +25,7 @@ use Friendica\BaseModule; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Util\Strings; +use Friendica\Model\Tag; use Friendica\Model\Term; /** @@ -44,7 +45,7 @@ class Hashtag extends BaseModule $taglist = DBA::p("SELECT DISTINCT(`term`) FROM `term` WHERE `term` LIKE ? AND `type` = ? ORDER BY `term`", $t . '%', - intval(Term::HASHTAG) + intval(Tag::HASHTAG) ); while ($tag = DBA::fetch($taglist)) { $result[] = ['text' => $tag['term']]; diff --git a/src/Module/Profile/Status.php b/src/Module/Profile/Status.php index 8b6734e5cd..d7ed5ca7f4 100644 --- a/src/Module/Profile/Status.php +++ b/src/Module/Profile/Status.php @@ -31,6 +31,7 @@ use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\Profile as ProfileModel; use Friendica\Model\User; +use Friendica\Model\Tag; use Friendica\Model\Term; use Friendica\Module\BaseProfile; use Friendica\Module\Security\Login; @@ -148,7 +149,7 @@ class Status extends BaseProfile if (!empty($hashtags)) { $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", - DBA::escape(Strings::protectSprintf($hashtags)), intval(Term::OBJECT_TYPE_POST), intval(Term::HASHTAG), intval($a->profile['uid'])); + DBA::escape(Strings::protectSprintf($hashtags)), intval(Term::OBJECT_TYPE_POST), intval(Tag::HASHTAG), intval($a->profile['uid'])); } if (!empty($datequery)) { diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index 44407623e9..e5ad5091d9 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -33,6 +33,7 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Item; +use Friendica\Model\Tag; use Friendica\Model\Term; use Friendica\Module\BaseSearch; use Friendica\Network\HTTPException; @@ -153,7 +154,7 @@ class Index extends BaseSearch $condition = [ "(`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `otype` = ? AND `type` = ? AND `term` = ?", - local_user(), Term::OBJECT_TYPE_POST, Term::HASHTAG, $search + local_user(), Term::OBJECT_TYPE_POST, Tag::HASHTAG, $search ]; $params = [ 'order' => ['received' => true],