]> git.mxchange.org Git - friendica.git/commitdiff
Move "isType" to Tag.php
authorMichael <heluecht@pirati.ca>
Fri, 1 May 2020 12:39:41 +0000 (12:39 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 1 May 2020 12:39:41 +0000 (12:39 +0000)
mod/item.php
src/Model/Tag.php
src/Model/Term.php

index b97f8bbe31739757f9cbc069859307b66decbb97..b044078ae237b9d8f99552bfb7e8f7da1f1ddb7d 100644 (file)
@@ -906,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, Tag::MENTION, Tag::IMPLICIT_MENTION, Tag::EXCLUSIVE_MENTION)) {
+       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=')) {
index 0a3e0e85337f6def2a7535e0fd301681390f406a..2c5295924aa267f970ff96c2594667daf3a926fe 100644 (file)
@@ -471,4 +471,23 @@ class Tag
 
                return $tags ?: [];
        }
+
+       /**
+        * Check if the provided tag is of one of the provided term types.
+        *
+        * @param string $tag
+        * @param int    ...$types
+        * @return bool
+        */
+       public static function isType($tag, ...$types)
+       {
+               $tag_chars = [];
+               foreach ($types as $type) {
+                       if (array_key_exists($type, self::TAG_CHARACTER)) {
+                               $tag_chars[] = self::TAG_CHARACTER[$type];
+                       }
+               }
+
+               return Strings::startsWith($tag, $tag_chars);
+       }       
 }
index 6f241015f8f0273737e209a881ea2c07ec07dcdc..05314dd601002a8b5fb8b8d2e0aa0e3cb30e2226 100644 (file)
@@ -21,7 +21,6 @@
 
 namespace Friendica\Model;
 
-use Friendica\Core\Cache\Duration;
 use Friendica\Core\Logger;
 use Friendica\Database\DBA;
 use Friendica\DI;
@@ -202,7 +201,7 @@ class Term
                }
 
                foreach ($tags as $link => $tag) {
-                       if (self::isType($tag, self::HASHTAG)) {
+                       if (Tag::isType($tag, self::HASHTAG)) {
                                // try to ignore #039 or #1 or anything like that
                                if (ctype_digit(substr(trim($tag), 1))) {
                                        continue;
@@ -216,8 +215,8 @@ class Term
                                $type = self::HASHTAG;
                                $term = substr($tag, 1);
                                $link = '';
-                       } elseif (self::isType($tag, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION)) {
-                               if (self::isType($tag, self::MENTION, self::EXCLUSIVE_MENTION)) {
+                       } elseif (Tag::isType($tag, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION)) {
+                               if (Tag::isType($tag, self::MENTION, self::EXCLUSIVE_MENTION)) {
                                        $type = self::MENTION;
                                } else {
                                        $type = self::IMPLICIT_MENTION;
@@ -266,7 +265,7 @@ class Term
                        ]);
 
                        // Search for mentions
-                       if (self::isType($tag, self::MENTION, self::EXCLUSIVE_MENTION)
+                       if (Tag::isType($tag, self::MENTION, self::EXCLUSIVE_MENTION)
                                && (
                                        strpos($link, $profile_base_friendica) !== false
                                        || strpos($link, $profile_base_diaspora) !== false
@@ -351,23 +350,4 @@ class Term
                // Clean up all tags
                DBA::delete('term', ['otype' => self::OBJECT_TYPE_POST, 'oid' => $item_id, 'type' => $type]);
        }
-
-       /**
-        * Check if the provided tag is of one of the provided term types.
-        *
-        * @param string $tag
-        * @param int    ...$types
-        * @return bool
-        */
-       public static function isType($tag, ...$types)
-       {
-               $tag_chars = [];
-               foreach ($types as $type) {
-                       if (array_key_exists($type, self::TAG_CHARACTER)) {
-                               $tag_chars[] = self::TAG_CHARACTER[$type];
-                       }
-               }
-
-               return Strings::startsWith($tag, $tag_chars);
-       }
 }