]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/FileTag.php
Merge pull request #6989 from nupplaphil/task/basePath_baseUrl_fix
[friendica.git] / src / Model / FileTag.php
index d2937a731289bdc4cba7cb9ed953aaa6a13d965d..2ad864c9c4d1fe4cce6db1fa3fa6919a2b9ff48c 100644 (file)
@@ -8,7 +8,6 @@ namespace Friendica\Model;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Database\DBA;
-use Friendica\Model\Item;
 
 /**
  * @brief This class handles FileTag related functions
@@ -22,6 +21,10 @@ class FileTag
 
     /**
      * @brief URL encode &lt, &gt, left and right brackets
+     * 
+     * @param string $s String to be URL encoded.
+     * 
+     * @return string   The URL encoded string.
      */
     public static function encode($s)
     {
@@ -30,6 +33,10 @@ class FileTag
 
     /**
      * @brief URL decode &lt, &gt, left and right brackets
+     * 
+     * @param string $s The URL encoded string to be decoded
+     * 
+     * @return string   The decoded string.
      */
     public static function decode($s)
     {
@@ -38,6 +45,12 @@ class FileTag
 
     /**
      * @brief Query files for tag
+     * 
+     * @param string $table The table to be queired.
+     * @param string $s     The search term
+     * @param string $type  Optional file type.
+     * 
+     * @return string       Query string.
      */
     public static function fileQuery($table, $s, $type = 'file')
     {
@@ -54,6 +67,10 @@ class FileTag
      * @brief Get file tags from list
      * 
      * ex. given music,video return <music><video> or [music][video]
+     * @param string $list  A comma delimited list of tags.
+     * @param string $type  Optional file type.
+     * 
+     * @return string       A list of file tags.
      */
     public static function listToFile($list, $type = 'file')
     {
@@ -84,21 +101,31 @@ class FileTag
      * @brief Get list from file tags
      * 
      * ex. given <music><video>[friends], return music,video or friends
+     * @param string $file  File tags
+     * @param string $type  Optional file type.
+     * 
+     * @return string       Comma delimited list of tag names.
      */
     public static function fileToList($file, $type = 'file')
     {
         $matches = false;
         $list = '';
+
         if ($type == 'file') {
             $cnt = preg_match_all('/\[(.*?)\]/', $file, $matches, PREG_SET_ORDER);
         } else {
             $cnt = preg_match_all('/<(.*?)>/', $file, $matches, PREG_SET_ORDER);
         }
-        if ($cnt) {
-            foreach ($matches as $mtch) {
-                if (strlen($list)) {
+
+        if ($cnt)
+        {
+            foreach ($matches as $mtch)
+            {
+                if (strlen($list))
+                {
                     $list .= ',';
                 }
+
                 $list .= self::decode($mtch[1]);
             }
         }
@@ -106,14 +133,19 @@ class FileTag
         return $list;
     }
 
-    /**
-     * @brief Update file tags in PConfig
-     */
+       /**
+        * @brief Update file tags in PConfig
+        *
+        * @param int    $uid      Unique Identity.
+        * @param string $file_old Categories previously associated with an item
+        * @param string $file_new New list of categories for an item
+        * @param string $type     Optional file type.
+        *
+        * @return boolean          A value indicating success or failure.
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        */
     public static function updatePconfig($uid, $file_old, $file_new, $type = 'file')
     {
-        // $file_old - categories previously associated with an item
-        // $file_new - new list of categories for an item
-
         if (!intval($uid)) {
             return false;
         } elseif ($file_old == $file_new) {
@@ -188,9 +220,16 @@ class FileTag
         return true;
     }
 
-    /**
-     * @brief Add tag to file
-     */
+       /**
+        * @brief Add tag to file
+        *
+        * @param int    $uid     Unique identity.
+        * @param int    $item_id Item identity.
+        * @param string $file    File tag.
+        *
+        * @return boolean      A value indicating success or failure.
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        */
     public static function saveFile($uid, $item_id, $file)
     {
         if (!intval($uid))
@@ -220,9 +259,17 @@ class FileTag
         return true;
     }
 
-    /**
-     * @brief Remove tag from file
-     */
+       /**
+        * @brief Remove tag from file
+        *
+        * @param int     $uid     Unique identity.
+        * @param int     $item_id Item identity.
+        * @param string  $file    File tag.
+        * @param boolean $cat     Optional value indicating the term type (i.e. Category or File)
+        *
+        * @return boolean      A value indicating success or failure.
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        */
     public static function unsaveFile($uid, $item_id, $file, $cat = false)
     {
         if (!intval($uid))
@@ -231,10 +278,10 @@ class FileTag
         }
 
         if ($cat == true) {
-            $pattern = '<' . self::encode($file) . '>' ;
+            $pattern = '<' . self::encode($file) . '>';
             $termtype = TERM_CATEGORY;
         } else {
-            $pattern = '[' . self::encode($file) . ']' ;
+            $pattern = '[' . self::encode($file) . ']';
             $termtype = TERM_FILE;
         }
 
@@ -246,6 +293,7 @@ class FileTag
         }
 
         $fields = ['file' => str_replace($pattern, '', $item['file'])];
+
         Item::update($fields, ['id' => $item_id]);
 
         $r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d",