More preparations for term to tag transition

This commit is contained in:
Michael 2020-04-26 16:15:39 +00:00
parent 5df5e9521b
commit 7f5f68a904
11 changed files with 33 additions and 21 deletions

View File

@ -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;

View File

@ -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]';
}
}
}

View File

@ -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);

View File

@ -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)

View File

@ -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)) : '';

View File

@ -23,6 +23,7 @@ namespace Friendica\Content\Widget;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\Tag;
use Friendica\Model\Term;
/**

View File

@ -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'];

View File

@ -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)) {

View File

@ -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']];

View File

@ -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)) {

View File

@ -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],