]> git.mxchange.org Git - friendica.git/commitdiff
Replace deprecated string-bases Model\FileTag calls with array-based ones
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 27 May 2019 21:17:53 +0000 (17:17 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 27 May 2019 21:40:08 +0000 (17:40 -0400)
include/text.php
mod/item.php
src/Content/Widget.php
src/Module/Filer/SaveTag.php

index c4249f86c49acc47d245163f3eed9bd3787ff866..eb65334fd94e72469c33ee7a2b31ca36a8e15c7c 100644 (file)
@@ -8,10 +8,8 @@ use Friendica\Content\Smilies;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Protocol;
 use Friendica\Model\Contact;
-
 use Friendica\Model\FileTag;
 use Friendica\Util\Strings;
-use Friendica\Util\XML;
 
 /**
  * Turn user/group ACLs stored as angle bracketed text into arrays
@@ -186,21 +184,17 @@ function get_cats_and_terms($item)
 {
        $categories = [];
        $folders = [];
-
-       $matches = [];
        $first = true;
-       $cnt = preg_match_all('/<(.*?)>/', $item['file'], $matches, PREG_SET_ORDER);
-       if ($cnt) {
-               foreach ($matches as $mtch) {
-                       $categories[] = [
-                               'name' => XML::escape(FileTag::decode($mtch[1])),
-                               'url' =>  "#",
-                               'removeurl' => ((local_user() == $item['uid'])?'filerm/' . $item['id'] . '?f=&cat=' . XML::escape(FileTag::decode($mtch[1])):""),
-                               'first' => $first,
-                               'last' => false
-                       ];
-                       $first = false;
-               }
+
+       foreach (FileTag::fileToArray($item['file'], 'category') as $savedFolderName) {
+               $categories[] = [
+                       'name' => $savedFolderName,
+                       'url' => "#",
+                       'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""),
+                       'first' => $first,
+                       'last' => false
+               ];
+               $first = false;
        }
 
        if (count($categories)) {
@@ -208,20 +202,15 @@ function get_cats_and_terms($item)
        }
 
        if (local_user() == $item['uid']) {
-               $matches = [];
-               $first = true;
-               $cnt = preg_match_all('/\[(.*?)\]/', $item['file'], $matches, PREG_SET_ORDER);
-               if ($cnt) {
-                       foreach ($matches as $mtch) {
-                               $folders[] = [
-                                       'name' => XML::escape(FileTag::decode($mtch[1])),
-                                       'url' =>  "#",
-                                       'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . XML::escape(FileTag::decode($mtch[1])) : ""),
-                                       'first' => $first,
-                                       'last' => false
-                               ];
-                               $first = false;
-                       }
+               foreach (FileTag::fileToArray($item['file']) as $savedFolderName) {
+                       $folders[] = [
+                               'name' => $savedFolderName,
+                               'url' => "#",
+                               'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . rawurlencode($savedFolderName) : ""),
+                               'first' => $first,
+                               'last' => false
+                       ];
+                       $first = false;
                }
        }
 
index b126c4825b6ef7a8ca83f517a9edc52f08352e9c..7af5c712f6b3bbf59fdf4705fa5f9516344ade4a 100644 (file)
@@ -327,10 +327,9 @@ function item_post(App $a) {
                }
        }
 
-       if (!empty($categories))
-       {
+       if (!empty($categories)) {
                // get the "fileas" tags for this post
-               $filedas = FileTag::fileToList($categories, 'file');
+               $filedas = FileTag::fileToArray($categories);
        }
 
        // save old and new categories, so we can determine what needs to be deleted from pconfig
@@ -338,10 +337,9 @@ function item_post(App $a) {
        $categories = FileTag::listToFile(trim(defaults($_REQUEST, 'category', '')), 'category');
        $categories_new = $categories;
 
-       if (!empty($filedas))
-       {
+       if (!empty($filedas)) {
                // append the fileas stuff to the new categories list
-               $categories .= FileTag::listToFile($filedas, 'file');
+               $categories .= FileTag::arrayToFile($filedas);
        }
 
        // get contact info for poster
index 066c17413a3a8db9b56da401f1b5e481a339cb08..dcfc1d0e3d95da631db6899dc781c10eff9f017c 100644 (file)
@@ -256,7 +256,7 @@ class Widget
         * @param string $baseurl  baseurl
         * @param string $selected optional, default empty
         * @return string|void
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \Exception
         */
        public static function fileAs($baseurl, $selected = '')
        {
@@ -269,15 +269,9 @@ class Widget
                        return;
                }
 
-               $matches = [];
-               $terms = array();
-               $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
-               if ($cnt) {
-                       foreach ($matches as $mtch)
-                       {
-                               $unescaped = XML::escape(FileTag::decode($mtch[1]));
-                               $terms[] = ['ref' => $unescaped, 'name' => $unescaped];
-                       }
+               $terms = [];
+               foreach (FileTag::fileToArray($saved) as $savedFolderName) {
+                       $terms[] = ['ref' => $savedFolderName, 'name' => $savedFolderName];
                }
 
                return self::filter(
@@ -312,15 +306,9 @@ class Widget
                        return;
                }
 
-               $matches = [];
                $terms = array();
-               $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
-
-               if ($cnt) {
-                       foreach ($matches as $mtch) {
-                               $unescaped = XML::escape(FileTag::decode($mtch[1]));
-                               $terms[] = ['ref' => $unescaped, 'name' => $unescaped];
-                       }
+               foreach (FileTag::fileToArray($saved, 'category') as $savedFolderName) {
+                       $terms[] = ['ref' => $savedFolderName, 'name' => $savedFolderName];
                }
 
                return self::filter(
index f5d6115199a2ca007333212cab6da91ed21e0225..aeafdbeb5905a379f8e5482805549930b5e37a3a 100644 (file)
@@ -41,8 +41,7 @@ class SaveTag extends BaseModule
 
                // return filer dialog
                $filetags = PConfig::get(local_user(), 'system', 'filetags');
-               $filetags = Model\FileTag::fileToList($filetags, 'file');
-               $filetags = explode(",", $filetags);
+               $filetags = Model\FileTag::fileToArray($filetags);
 
                $tpl = Renderer::getMarkupTemplate("filer_dialog.tpl");
                echo Renderer::replaceMacros($tpl, [