From 3a604029eb741519cb4f79b850900e8cb70f10ec Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Tue, 30 Oct 2018 14:51:21 -0400 Subject: [PATCH 1/3] Create FileTag class create class and move functions --- include/text.php | 202 +------------------------------- src/Model/FileTag.php | 266 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 271 insertions(+), 197 deletions(-) create mode 100644 src/Model/FileTag.php diff --git a/include/text.php b/include/text.php index aae739312..aa4b2c8db 100644 --- a/include/text.php +++ b/include/text.php @@ -24,6 +24,7 @@ use Friendica\Util\Map; use Friendica\Util\Proxy as ProxyUtils; use Friendica\Core\Logger; +use Friendica\Model\FileTag; require_once "include/conversation.php"; @@ -1099,9 +1100,9 @@ function get_cats_and_terms($item) if ($cnt) { foreach ($matches as $mtch) { $categories[] = [ - 'name' => xmlify(file_tag_decode($mtch[1])), + 'name' => xmlify(FileTag::decode($mtch[1])), 'url' => "#", - 'removeurl' => ((local_user() == $item['uid'])?'filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])):""), + 'removeurl' => ((local_user() == $item['uid'])?'filerm/' . $item['id'] . '?f=&cat=' . xmlify(FileTag::decode($mtch[1])):""), 'first' => $first, 'last' => false ]; @@ -1120,9 +1121,9 @@ function get_cats_and_terms($item) if ($cnt) { foreach ($matches as $mtch) { $folders[] = [ - 'name' => xmlify(file_tag_decode($mtch[1])), + 'name' => xmlify(FileTag::decode($mtch[1])), 'url' => "#", - 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])) : ""), + 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . xmlify(FileTag::decode($mtch[1])) : ""), 'first' => $first, 'last' => false ]; @@ -1360,199 +1361,6 @@ function item_post_type($item) { return L10n::t('post'); } -// 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 -// and save to file categories in square brackets. -// To do this we need to escape these characters if they appear in our tag. - -function file_tag_encode($s) { - return str_replace(['<','>','[',']'],['%3c','%3e','%5b','%5d'],$s); -} - -function file_tag_decode($s) { - return str_replace(['%3c', '%3e', '%5b', '%5d'], ['<', '>', '[', ']'], $s); -} - -function file_tag_file_query($table,$s,$type = 'file') { - - if ($type == 'file') { - $str = preg_quote('[' . str_replace('%', '%%', file_tag_encode($s)) . ']'); - } else { - $str = preg_quote('<' . str_replace('%', '%%', file_tag_encode($s)) . '>'); - } - return " AND " . (($table) ? DBA::escape($table) . '.' : '') . "file regexp '" . DBA::escape($str) . "' "; -} - -// ex. given music,video return