From: Michael Date: Sat, 18 Apr 2020 10:05:30 +0000 (+0000) Subject: Improved body scanning, increased length X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3ce9386cb1c80476e021467edd76803d004c1d91;p=friendica.git Improved body scanning, increased length --- diff --git a/src/Model/Tag.php b/src/Model/Tag.php index 9c9ac033f0..61a1575a1c 100644 --- a/src/Model/Tag.php +++ b/src/Model/Tag.php @@ -69,7 +69,7 @@ class Tag return; } - $fields = ['name' => substr($name, 0, 64), 'type' => $type]; + $fields = ['name' => substr($name, 0, 96), 'type' => $type]; if (!empty($url) && ($url != $name)) { $fields['url'] = strtolower($url); @@ -119,25 +119,20 @@ class Tag } /** - * Store tags from the body - * - * @param integer $uriid - * @param string $body + * Store tags and mentions from the body + * + * @param integer $uriid URI-Id + * @param string $body Body of the post + * @param string $tags Accepted tags */ - public static function storeFromBody(int $uriid, string $body) + public static function storeFromBody(int $uriid, string $body, string $tags = '#@!') { - $tags = BBCode::getTags($body); - if (empty($tags)) { + if (!preg_match_all("/([" . $tags . "])\[url\=(.*?)\](.*?)\[\/url\]/ism", $body, $result, PREG_SET_ORDER)) { return; } - foreach ($tags as $tag) { - if ((substr($tag, 0, 1) != self::TAG_CHARACTER[self::HASHTAG]) || (strlen($tag) <= 1)) { - Logger::info('Skip tag', ['uriid' => $uriid, 'tag' => $tag]); - continue; - } - - self::storeByHash($uriid, '#', $tag); + foreach ($result as $tag) { + self::storeByHash($uriid, $tag[1], $tag[3], $tag[2]); } } } diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 8033ffb701..653e5c242b 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -2410,7 +2410,7 @@ class DFRN $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]); - Tag::storeFromBody($item['uri-id'], $item["body"]); + Tag::storeFromBody($item['uri-id'], $item["body"], '#'); // We store the data from "dfrn:diaspora_signature" in a different table, this is done in "Item::insert" $dsprsig = XML::unescape(XML::getFirstNodeValue($xpath, "dfrn:diaspora_signature/text()", $entry)); diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 20a2be4cc1..a8ffcbcfe5 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -1938,7 +1938,7 @@ class Diaspora $datarray["body"] = self::replacePeopleGuid($body, $person["url"]); self::storeMentions($datarray['uri-id'], $text); - Tag::storeFromBody($datarray['uri-id'], $datarray["body"]); + Tag::storeFromBody($datarray['uri-id'], $datarray["body"], '#'); self::fetchGuid($datarray); @@ -3013,7 +3013,7 @@ class Diaspora $datarray["body"] = self::replacePeopleGuid($body, $contact["url"]); self::storeMentions($datarray['uri-id'], $text); - Tag::storeFromBody($datarray['uri-id'], $datarray["body"]); + Tag::storeFromBody($datarray['uri-id'], $datarray["body"], '#'); if ($provider_display_name != "") { $datarray["app"] = $provider_display_name; diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 204fca9bfe..a1d72322a8 100755 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -1297,7 +1297,7 @@ return [ "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""], "type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""], - "name" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => ""], + "name" => ["type" => "varchar(96)", "not null" => "1", "default" => "", "comment" => ""], "url" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => ""] ], "indexes" => [