diff --git a/database.sql b/database.sql index 987a2d7e20..c9017fd2ef 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2021.03-dev (Red Hot Poker) --- DB_UPDATE_VERSION 1393 +-- DB_UPDATE_VERSION 1394 -- ------------------------------------------ @@ -1494,11 +1494,9 @@ CREATE VIEW `post-view` AS SELECT `item`.`id` AS `id`, `item`.`id` AS `item_id`, `item`.`uid` AS `uid`, - `item`.`uid` AS `internal-uid`, `item`.`parent` AS `parent`, `item`.`uri` AS `uri`, `item`.`uri-id` AS `uri-id`, - `item`.`uri-id` AS `internal-uri-id`, `item`.`parent-uri` AS `parent-uri`, `item`.`parent-uri-id` AS `parent-uri-id`, `item`.`thr-parent` AS `thr-parent`, @@ -1530,9 +1528,6 @@ CREATE VIEW `post-view` AS SELECT `item`.`network` AS `network`, `item`.`vid` AS `vid`, `item`.`psid` AS `psid`, - `item`.`attach` AS `attach`, - (SELECT COUNT(*) FROM `post-category` WHERE `post-category`.`uri-id` = `item`.`uri-id`) AS `internal-file-count`, - NULL AS `file`, IF (`item`.`vid` IS NULL, '', `verb`.`name`) AS `verb`, `item-content`.`title` AS `title`, `item-content`.`content-warning` AS `content-warning`, @@ -1653,11 +1648,9 @@ CREATE VIEW `post-thread-view` AS SELECT `thread`.`iid` AS `iid`, `item`.`id` AS `item_id`, `thread`.`uid` AS `uid`, - `item`.`uid` AS `internal-uid`, `item`.`parent` AS `parent`, `item`.`uri` AS `uri`, `item`.`uri-id` AS `uri-id`, - `item`.`uri-id` AS `internal-uri-id`, `item`.`parent-uri` AS `parent-uri`, `item`.`parent-uri-id` AS `parent-uri-id`, `item`.`thr-parent` AS `thr-parent`, @@ -1690,9 +1683,6 @@ CREATE VIEW `post-thread-view` AS SELECT `thread`.`network` AS `network`, `item`.`vid` AS `vid`, `item`.`psid` AS `psid`, - `item`.`attach` AS `attach`, - (SELECT COUNT(*) FROM `post-category` WHERE `post-category`.`uri-id` = `item`.`uri-id`) AS `internal-file-count`, - NULL AS `file`, IF (`item`.`vid` IS NULL, '', `verb`.`name`) AS `verb`, `item-content`.`title` AS `title`, `item-content`.`content-warning` AS `content-warning`, diff --git a/mod/editpost.php b/mod/editpost.php index 4bfb63ada5..31f121bd54 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -26,8 +26,6 @@ use Friendica\Core\Renderer; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; -use Friendica\Model\FileTag; -use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Util\Crypto; @@ -48,7 +46,7 @@ function editpost_content(App $a) } $fields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', - 'type', 'body', 'title', 'file', 'wall', 'post-type', 'guid']; + 'type', 'body', 'title', 'uri-id', 'wall', 'post-type', 'guid']; $item = Post::selectFirstForUser(local_user(), $fields, ['id' => $post_id, 'uid' => local_user()]); @@ -117,7 +115,7 @@ function editpost_content(App $a) '$jotnets' => $jotnets, '$title' => $item['title'], '$placeholdertitle' => DI::l10n()->t('Set title'), - '$category' => FileTag::fileToList($item['file'], 'category'), + '$category' => Post\Category::getCSVByURIId($item['uri-id'], local_user(), Post\Category::CATEGORY), '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? DI::l10n()->t("Categories \x28comma-separated list\x29") : ''), '$emtitle' => DI::l10n()->t('Example: bob@example.com, mary@example.com'), '$lockstate' => $lockstate, diff --git a/mod/item.php b/mod/item.php index 68904d9ecb..68fa6fbf6d 100644 --- a/mod/item.php +++ b/mod/item.php @@ -252,7 +252,7 @@ function item_post(App $a) { $verb = $orig_post['verb']; $objecttype = $orig_post['object-type']; $app = $orig_post['app']; - $categories = $orig_post['file'] ?? ''; + $categories = Post\Category::getTextByURIId($orig_post['uri-id'], $orig_post['uid']); $title = trim($_REQUEST['title'] ?? ''); $body = trim($body); $private = $orig_post['private']; @@ -344,10 +344,7 @@ function item_post(App $a) { $filedas = FileTag::fileToArray($categories); } - // save old and new categories, so we can determine what needs to be deleted from pconfig - $categories_old = $categories; $categories = FileTag::listToFile(trim($_REQUEST['category'] ?? ''), 'category'); - $categories_new = $categories; if (!empty($filedas) && is_array($filedas)) { // append the fileas stuff to the new categories list @@ -696,9 +693,6 @@ function item_post(App $a) { Item::update($fields, ['id' => $post_id]); - // update filetags in pconfig - FileTag::updatePconfig($uid, $categories_old, $categories_new, 'category'); - if ($return_path) { DI::baseUrl()->redirect($return_path); } @@ -745,9 +739,6 @@ function item_post(App $a) { Tag::createImplicitMentions($datarray['uri-id'], $datarray['thr-parent-id']); } - // update filetags in pconfig - FileTag::updatePconfig($uid, $categories_old, $categories_new, 'category'); - // These notifications are sent if someone else is commenting other your wall if ($contact_record != $author) { if ($toplevel_item_id) { diff --git a/src/Content/Item.php b/src/Content/Item.php index c0b1d3b49a..06190dc88f 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -23,8 +23,8 @@ namespace Friendica\Content; use Friendica\Database\DBA; use Friendica\Model\Contact; -use Friendica\Model\FileTag; use Friendica\Model\Tag; +use Friendica\Model\Post; /** * A content helper class for displaying items @@ -64,7 +64,7 @@ class Item $folders = []; $first = true; - foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) { + foreach (Post\Category::getArrayByURIId($item['uri-id'], $item['uid'], Post\Category::CATEGORY) as $savedFolderName) { if (!empty($item['author-link'])) { $url = $item['author-link'] . "?category=" . rawurlencode($savedFolderName); } else { @@ -85,7 +85,7 @@ class Item } if (local_user() == $item['uid']) { - foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) { + foreach (Post\Category::getArrayByURIId($item['uri-id'], $item['uid'], Post\Category::FILE) as $savedFolderName) { $folders[] = [ 'name' => $savedFolderName, 'url' => "#", diff --git a/src/Content/Widget.php b/src/Content/Widget.php index f4a9fbe1f1..8f3edada2c 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -27,9 +27,9 @@ use Friendica\Core\Renderer; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; -use Friendica\Model\FileTag; use Friendica\Model\Group; use Friendica\Model\Item; +use Friendica\Model\Post; use Friendica\Util\DateTimeFormat; use Friendica\Util\Temporal; @@ -305,19 +305,10 @@ class Widget return ''; } - $saved = DI::pConfig()->get(local_user(), 'system', 'filetags'); - if (!strlen($saved)) { - return; - } - $terms = []; - foreach (FileTag::fileToArray($saved) as $savedFolderName) { + foreach (Post\Category::getArray(local_user(), Post\Category::FILE) as $savedFolderName) { $terms[] = ['ref' => $savedFolderName, 'name' => $savedFolderName]; } - - usort($terms, function ($a, $b) { - return strcmp($a['name'], $b['name']); - }); return self::filter( 'file', @@ -348,13 +339,8 @@ class Widget return ''; } - $saved = DI::pConfig()->get($uid, 'system', 'filetags'); - if (!strlen($saved)) { - return; - } - $terms = array(); - foreach (FileTag::fileToArray($saved, 'category') as $savedFolderName) { + foreach (Post\Category::getArray(local_user(), Post\Category::CATEGORY) as $savedFolderName) { $terms[] = ['ref' => $savedFolderName, 'name' => $savedFolderName]; } diff --git a/src/Model/FileTag.php b/src/Model/FileTag.php index 2f5e82ba40..15dadb44fd 100644 --- a/src/Model/FileTag.php +++ b/src/Model/FileTag.php @@ -21,10 +21,6 @@ namespace Friendica\Model; -use Friendica\Database\DBA; -use Friendica\DI; -use Friendica\Model\Post\Category; - /** * This class handles FileTag related functions * @@ -42,7 +38,7 @@ class FileTag * * @return string The URL encoded string. */ - public static function encode($s) + private static function encode($s) { return str_replace(['<', '>', '[', ']'], ['%3c', '%3e', '%5b', '%5d'], $s); } @@ -54,31 +50,11 @@ class FileTag * * @return string The decoded string. */ - public static function decode($s) + private static function decode($s) { return str_replace(['%3c', '%3e', '%5b', '%5d'], ['<', '>', '[', ']'], $s); } - /** - * 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') - { - if ($type == 'file') { - $str = preg_quote('[' . str_replace('%', '%%', self::encode($s)) . ']'); - } else { - $str = preg_quote('<' . str_replace('%', '%%', self::encode($s)) . '>'); - } - - return " AND " . (($table) ? DBA::escape($table) . '.' : '') . "file regexp '" . DBA::escape($str) . "' "; - } - /** * Get file tags from array * @@ -155,167 +131,4 @@ class FileTag return self::arrayToFile($list_array, $type); } - - /** - * Get list from file tags - * - * ex. given