1
0
Fork 0

The old tag handling is removed

This commit is contained in:
Michael 2020-05-02 05:08:05 +00:00
commit b0cb6536dd
14 changed files with 40 additions and 543 deletions

View file

@ -375,7 +375,6 @@ function item_post(App $a) {
}
// Look for any tags and linkify them
$str_tags = '';
$inform = '';
$tags = BBCode::getTags($body);
@ -414,7 +413,7 @@ function item_post(App $a) {
continue;
}
$success = handle_tag($body, $inform, $str_tags, local_user() ? local_user() : $profile_uid, $tag, $network);
$success = handle_tag($body, $inform, local_user() ? local_user() : $profile_uid, $tag, $network);
if ($success['replaced']) {
$tagged[] = $tag;
}
@ -598,7 +597,6 @@ function item_post(App $a) {
$datarray['app'] = $app;
$datarray['location'] = $location;
$datarray['coord'] = $coord;
$datarray['tag'] = $str_tags;
$datarray['file'] = $categories;
$datarray['inform'] = $inform;
$datarray['verb'] = $verb;
@ -695,7 +693,6 @@ function item_post(App $a) {
$fields = [
'title' => $datarray['title'],
'body' => $datarray['body'],
'tag' => $datarray['tag'],
'attach' => $datarray['attach'],
'file' => $datarray['file'],
'rendered-html' => $datarray['rendered-html'],
@ -890,7 +887,6 @@ function item_content(App $a)
* @param App $a
* @param string $body the text to replace the tag in
* @param string $inform a comma-seperated string containing everybody to inform
* @param string $str_tags string to add the tag to
* @param integer $profile_uid
* @param string $tag the tag to replace
* @param string $network The network of the post
@ -899,24 +895,15 @@ function item_content(App $a)
* @throws ImagickException
* @throws HTTPException\InternalServerErrorException
*/
function handle_tag(&$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "")
function handle_tag(&$body, &$inform, $profile_uid, $tag, $network = "")
{
$replaced = false;
$r = null;
//is it a person tag?
if (Tag::isType($tag, Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION)) {
$tag_type = substr($tag, 0, 1);
//is it already replaced?
if (strpos($tag, '[url=')) {
//append tag to str_tags
if (!stristr($str_tags, $tag)) {
if (strlen($str_tags)) {
$str_tags .= ',';
}
$str_tags .= $tag;
}
// Checking for the alias that is used for OStatus
$pattern = "/[@!]\[url\=(.*?)\](.*?)\[\/url\]/ism";
if (preg_match($pattern, $tag, $matches)) {
@ -924,14 +911,6 @@ function handle_tag(&$body, &$inform, &$str_tags, $profile_uid, $tag, $network =
if ($data["alias"] != "") {
$newtag = '@[url=' . $data["alias"] . ']' . $data["nick"] . '[/url]';
if (!stripos($str_tags, '[url=' . $data["alias"] . ']')) {
if (strlen($str_tags)) {
$str_tags .= ',';
}
$str_tags .= $newtag;
}
}
}
@ -1005,7 +984,6 @@ function handle_tag(&$body, &$inform, &$str_tags, $profile_uid, $tag, $network =
}
$profile = $contact["url"];
$alias = $contact["alias"];
$newname = ($contact["name"] ?? '') ?: $contact["nick"];
}
@ -1016,27 +994,6 @@ function handle_tag(&$body, &$inform, &$str_tags, $profile_uid, $tag, $network =
$profile = str_replace(',', '%2c', $profile);
$newtag = $tag_type.'[url=' . $profile . ']' . $newname . '[/url]';
$body = str_replace($tag_type . $name, $newtag, $body);
// append tag to str_tags
if (!stristr($str_tags, $newtag)) {
if (strlen($str_tags)) {
$str_tags .= ',';
}
$str_tags .= $newtag;
}
/*
* Status.Net seems to require the numeric ID URL in a mention if the person isn't
* subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
*/
if (!empty($alias)) {
$newtag = '@[url=' . $alias . ']' . $newname . '[/url]';
if (!stripos($str_tags, '[url=' . $alias . ']')) {
if (strlen($str_tags)) {
$str_tags .= ',';
}
$str_tags .= $newtag;
}
}
}
}

View file

@ -29,7 +29,6 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Tag;
use Friendica\Model\Term;
use Friendica\Protocol\Activity;
use Friendica\Util\Strings;
use Friendica\Util\XML;
@ -170,50 +169,8 @@ EOT;
Item::update(['visible' => true], ['id' => $item['id']]);
}
$term_objtype = ($item['resource-id'] ? Term::OBJECT_TYPE_PHOTO : Term::OBJECT_TYPE_POST);
Tag::store($item['uri-id'], Tag::HASHTAG, $term);
$t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
intval($item['id']),
DBA::escape($term)
);
if (!$blocktags && $t[0]['tcount'] == 0) {
q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
intval($item['id']),
$term_objtype,
Tag::HASHTAG,
DBA::escape($term),
'',
intval($owner_uid)
);
}
// if the original post is on this site, update it.
$original_item = Item::selectFirst(['tag', 'id', 'uid'], ['origin' => true, 'uri' => $item['uri']]);
if (DBA::isResult($original_item)) {
$x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
intval($original_item['uid'])
);
$t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
intval($original_item['id']),
DBA::escape($term)
);
if (DBA::isResult($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
intval($original_item['id']),
$term_objtype,
Tag::HASHTAG,
DBA::escape($term),
'',
intval($owner_uid)
);
}
}
$arr['id'] = $post_id;
Hook::callAll('post_local_end', $arr);

View file

@ -25,7 +25,6 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Tag;
use Friendica\Model\Term;
use Friendica\Util\Strings;
function tagrm_post(App $a)
@ -58,35 +57,24 @@ function tagrm_post(App $a)
* @param $tags array
* @throws Exception
*/
function update_tags($item_id, $tags){
if (empty($item_id) || empty($tags)){
function update_tags($item_id, $tags)
{
if (empty($item_id) || empty($tags)) {
return;
}
$item = Item::selectFirst(['tag', 'uri-id'], ['id' => $item_id, 'uid' => local_user()]);
$item = Item::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => local_user()]);
if (!DBA::isResult($item)) {
return;
}
$old_tags = explode(',', $item['tag']);
foreach ($tags as $new_tag) {
if (preg_match_all('/([#@!])\[url\=([^\[\]]*)\]([^\[\]]*)\[\/url\]/ism', $new_tag, $results, PREG_SET_ORDER)) {
foreach ($results as $tag) {
Tag::removeByHash($item['uri-id'], $tag[1], $tag[3], $tag[2]);
}
}
foreach ($old_tags as $index => $old_tag) {
if (strcmp($old_tag, $new_tag) == 0) {
unset($old_tags[$index]);
break;
}
}
}
$tag_str = implode(',', $old_tags);
Term::insertFromTagFieldByItemId($item_id, $tag_str);
}
function tagrm_content(App $a)