]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Tag.php
Don't cache local avatars
[friendica.git] / src / Model / Tag.php
index fb301d1436299e828913503dcbd55537c7dd4cc6..17a68f120f4b5ab643277ac387571410b6d93944 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -29,6 +29,7 @@ use Friendica\Core\System;
 use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
 
 /**
@@ -206,22 +207,40 @@ class Tag
        }
 
        /**
-        * Store tags and mentions from the body
+        * Get tags and mentions from the body
         * 
-        * @param integer $uriid   URI-Id
         * @param string  $body    Body of the post
         * @param string  $tags    Accepted tags
-        * @param boolean $probing Perform a probing for contacts, adding them if needed
+        *
+        * @return array Tag list
         */
-       public static function storeFromBody(int $uriid, string $body, string $tags = null, $probing = true)
+       public static function getFromBody(string $body, string $tags = null)
        {
                if (is_null($tags)) {
                        $tags =  self::TAG_CHARACTER[self::HASHTAG] . self::TAG_CHARACTER[self::MENTION] . self::TAG_CHARACTER[self::EXCLUSIVE_MENTION];
                }
 
+               if (!preg_match_all("/([" . $tags . "])\[url\=([^\[\]]*)\]([^\[\]]*)\[\/url\]/ism", $body, $result, PREG_SET_ORDER)) {
+                       return [];
+               }
+
+               return $result;
+       }
+
+       /**
+        * Store tags and mentions from the body
+        * 
+        * @param integer $uriid   URI-Id
+        * @param string  $body    Body of the post
+        * @param string  $tags    Accepted tags
+        * @param boolean $probing Perform a probing for contacts, adding them if needed
+        */
+       public static function storeFromBody(int $uriid, string $body, string $tags = null, $probing = true)
+       {
                Logger::info('Check for tags', ['uri-id' => $uriid, 'hash' => $tags, 'callstack' => System::callstack()]);
 
-               if (!preg_match_all("/([" . $tags . "])\[url\=([^\[\]]*)\]([^\[\]]*)\[\/url\]/ism", $body, $result, PREG_SET_ORDER)) {
+               $result = self::getFromBody($body, $tags);
+               if (empty($result)) {
                        return;
                }
 
@@ -547,7 +566,7 @@ class Tag
        {
                // Get a uri-id that is at least X hours old.
                // We use the uri-id in the query for the hash tags since this is much faster
-               $post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? HOUR", 0, $period],
+               $post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < ?", 0, DateTimeFormat::utc('now - ' . $period . ' hour')],
                        ['order' => ['received' => true]]);
                if (empty($post['uri-id'])) {
                        return [];
@@ -600,7 +619,7 @@ class Tag
        {
                // Get a uri-id that is at least X hours old.
                // We use the uri-id in the query for the hash tags since this is much faster
-               $post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < UTC_TIMESTAMP() - INTERVAL ? HOUR", 0, $period],
+               $post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < ?", 0, DateTimeFormat::utc('now - ' . $period . ' hour')],
                        ['order' => ['received' => true]]);
                if (empty($post['uri-id'])) {
                        return [];