]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/FileTag.php
Fill "last-item" with an empty date when bo date had been provided
[friendica.git] / src / Model / FileTag.php
index ffcea7e281dc34b83665dde33fbd463c4ed3a522..a2c8bb43972a426e9647d7a5866915a2acd5d247 100644 (file)
@@ -1,16 +1,32 @@
 <?php
 /**
- * @file src/Model/FileTag.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
 
 namespace Friendica\Model;
 
-use Friendica\Core\L10n;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Model\Post\Category;
 
 /**
- * @brief This class handles FileTag related functions
+ * This class handles FileTag related functions
  *
  * post categories and "save to file" use the same item.file table for storage.
  * We will differentiate the different uses by wrapping categories in angle brackets
@@ -20,7 +36,7 @@ use Friendica\DI;
 class FileTag
 {
        /**
-        * @brief URL encode <, >, left and right brackets
+        * URL encode <, >, left and right brackets
         *
         * @param string $s String to be URL encoded.
         *
@@ -32,7 +48,7 @@ class FileTag
        }
 
        /**
-        * @brief URL decode <, >, left and right brackets
+        * URL decode <, >, left and right brackets
         *
         * @param string $s The URL encoded string to be decoded
         *
@@ -44,7 +60,7 @@ class FileTag
        }
 
        /**
-        * @brief Query files for tag
+        * Query files for tag
         *
         * @param string $table The table to be queired.
         * @param string $s     The search term
@@ -124,7 +140,7 @@ class FileTag
        }
 
        /**
-        * @brief      Get file tags from list
+        * Get file tags from list
         *
         * ex. given music,video return <music><video> or [music][video]
         * @param string $list A comma delimited list of tags.
@@ -141,7 +157,7 @@ class FileTag
        }
 
        /**
-        * @brief      Get list from file tags
+        * Get list from file tags
         *
         * ex. given <music><video>[friends], return music,video or friends
         * @param string $file File tags
@@ -156,7 +172,7 @@ class FileTag
        }
 
        /**
-        * @brief Update file tags in PConfig
+        * Update file tags in PConfig
         *
         * @param int    $uid      Unique Identity.
         * @param string $file_old Categories previously associated with an item
@@ -180,11 +196,11 @@ class FileTag
                        if ($type == 'file') {
                                $lbracket = '[';
                                $rbracket = ']';
-                               $termtype = TERM_FILE;
+                               $termtype = Category::FILE;
                        } else {
                                $lbracket = '<';
                                $rbracket = '>';
-                               $termtype = TERM_CATEGORY;
+                               $termtype = Category::CATEGORY;
                        }
 
                        $filetags_updated = $saved;
@@ -208,13 +224,7 @@ class FileTag
                        }
 
                        foreach ($deleted_tags as $key => $tag) {
-                               $r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d",
-                                       DBA::escape($tag),
-                                       intval(Term::OBJECT_TYPE_POST),
-                                       intval($termtype),
-                                       intval($uid));
-
-                               if (DBA::isResult($r)) {
+                               if (DBA::exists('category-view', ['name' => $tag, 'type' => $termtype, 'uid' => $uid])) {
                                        unset($deleted_tags[$key]);
                                } else {
                                        $filetags_updated = str_replace($lbracket . self::encode($tag) . $rbracket, '', $filetags_updated);
@@ -234,7 +244,7 @@ class FileTag
        }
 
        /**
-        * @brief Add tag to file
+        * Add tag to file
         *
         * @param int    $uid     Unique identity.
         * @param int    $item_id Item identity.
@@ -261,15 +271,13 @@ class FileTag
                        if (!strlen($saved) || !stristr($saved, '[' . self::encode($file) . ']')) {
                                DI::pConfig()->set($uid, 'system', 'filetags', $saved . '[' . self::encode($file) . ']');
                        }
-
-                       info(L10n::t('Item filed'));
                }
 
                return true;
        }
 
        /**
-        * @brief Remove tag from file
+        * Remove tag from file
         *
         * @param int     $uid     Unique identity.
         * @param int     $item_id Item identity.
@@ -287,10 +295,10 @@ class FileTag
 
                if ($cat == true) {
                        $pattern = '<' . self::encode($file) . '>';
-                       $termtype = Term::CATEGORY;
+                       $termtype = Category::CATEGORY;
                } else {
                        $pattern = '[' . self::encode($file) . ']';
-                       $termtype = Term::FILE;
+                       $termtype = Category::FILE;
                }
 
                $item = Item::selectFirst(['file'], ['id' => $item_id, 'uid' => $uid]);
@@ -303,14 +311,7 @@ class FileTag
 
                Item::update($fields, ['id' => $item_id]);
 
-               $r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d",
-                       DBA::escape($file),
-                       intval(Term::OBJECT_TYPE_POST),
-                       intval($termtype),
-                       intval($uid)
-               );
-
-               if (!DBA::isResult($r)) {
+               if (!DBA::exists('category-view', ['name' => $file, 'type' => $termtype, 'uid' => $uid])) {
                        $saved = DI::pConfig()->get($uid, 'system', 'filetags');
                        DI::pConfig()->set($uid, 'system', 'filetags', str_replace($pattern, '', $saved));
                }