From 0fadc7730cb0d03d3a7319f6481790cbb1317bc3 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 27 May 2019 17:17:53 -0400 Subject: [PATCH] Replace deprecated string-bases Model\FileTag calls with array-based ones --- include/text.php | 49 ++++++++++++++---------------------- mod/item.php | 10 +++----- src/Content/Widget.php | 24 +++++------------- src/Module/Filer/SaveTag.php | 3 +-- 4 files changed, 30 insertions(+), 56 deletions(-) diff --git a/include/text.php b/include/text.php index c4249f86c4..eb65334fd9 100644 --- a/include/text.php +++ b/include/text.php @@ -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; } } diff --git a/mod/item.php b/mod/item.php index b126c4825b..7af5c712f6 100644 --- a/mod/item.php +++ b/mod/item.php @@ -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 diff --git a/src/Content/Widget.php b/src/Content/Widget.php index 066c17413a..dcfc1d0e3d 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -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( diff --git a/src/Module/Filer/SaveTag.php b/src/Module/Filer/SaveTag.php index f5d6115199..aeafdbeb59 100644 --- a/src/Module/Filer/SaveTag.php +++ b/src/Module/Filer/SaveTag.php @@ -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, [ -- 2.39.5