]> git.mxchange.org Git - friendica.git/commitdiff
Improved body scanning, increased length
authorMichael <heluecht@pirati.ca>
Sat, 18 Apr 2020 10:05:30 +0000 (10:05 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 18 Apr 2020 10:05:30 +0000 (10:05 +0000)
src/Model/Tag.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
static/dbstructure.config.php

index 9c9ac033f0bb7188a670143a084968071256d9d0..61a1575a1ce76b78ceff9d759a44bbcf9d318f31 100644 (file)
@@ -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]);
                }
        }
 }
index 8033ffb701622b89b9c5cbed49e63837616974cd..653e5c242beed68d2a8189c9ee1b9b34499272d1 100644 (file)
@@ -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));
index 20a2be4cc123230e38f0e57fa8895c60d3101a97..a8ffcbcfe5456f62f379df99bc7fa9ad67ebab64 100644 (file)
@@ -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;
index 204fca9bfe00b10f6fa229a456c2fee58bc32bb9..a1d72322a89a6d8bfec3ca312128aca4600fddc0 100755 (executable)
@@ -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" => [