From edf006905b5108d16eb5d4a5974198e0a93e41e7 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Wed, 23 Oct 2019 02:48:46 +0200 Subject: [PATCH] Move (last) get_cats_and_terms to Content\Item::determineCategoriesTerms() - Added incomplete test --- include/conversation.php | 6 ++- include/text.php | 74 ------------------------------- src/Content/Item.php | 79 ++++++++++++++++++++++++++++++++++ src/Object/Post.php | 6 ++- tests/src/Content/ItemTest.php | 13 ++++++ 5 files changed, 102 insertions(+), 76 deletions(-) delete mode 100644 include/text.php create mode 100644 src/Content/Item.php create mode 100644 tests/src/Content/ItemTest.php diff --git a/include/conversation.php b/include/conversation.php index c857336e34..8bcd1b338f 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -7,6 +7,7 @@ use Friendica\App; use Friendica\BaseObject; use Friendica\Content\ContactSelector; use Friendica\Content\Feature; +use Friendica\Content\Item as ContentItem; use Friendica\Content\Pager; use Friendica\Content\Text\BBCode; use Friendica\Core\Config; @@ -671,7 +672,10 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ $body = Item::prepareBody($item, true, $preview); - list($categories, $folders) = get_cats_and_terms($item); + /** @var ContentItem $contItem */ + $contItem = BaseObject::getClass(ContentItem::class); + + list($categories, $folders) = $contItem->determineCategoriesTerms($item); if (!empty($item['content-warning']) && PConfig::get(local_user(), 'system', 'disable_cw', false)) { $title = ucfirst($item['content-warning']); diff --git a/include/text.php b/include/text.php deleted file mode 100644 index 89c07000f7..0000000000 --- a/include/text.php +++ /dev/null @@ -1,74 +0,0 @@ - $savedFolderName, - 'url' => "#", - 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""), - 'first' => $first, - 'last' => false - ]; - $first = false; - } - - if (count($categories)) { - $categories[count($categories) - 1]['last'] = true; - } - - if (local_user() == $item['uid']) { - 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; - } - } - - if (count($folders)) { - $folders[count($folders) - 1]['last'] = true; - } - - return [$categories, $folders]; -} diff --git a/src/Content/Item.php b/src/Content/Item.php new file mode 100644 index 0000000000..ed6ec9c877 --- /dev/null +++ b/src/Content/Item.php @@ -0,0 +1,79 @@ + $savedFolderName, + 'url' => "#", + 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""), + 'first' => $first, + 'last' => false + ]; + $first = false; + } + + if (count($categories)) { + $categories[count($categories) - 1]['last'] = true; + } + + if (local_user() == $item['uid']) { + 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; + } + } + + if (count($folders)) { + $folders[count($folders) - 1]['last'] = true; + } + + return [$categories, $folders]; + } +} diff --git a/src/Object/Post.php b/src/Object/Post.php index 12de457a51..7dd5308017 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -7,6 +7,7 @@ namespace Friendica\Object; use Friendica\BaseObject; use Friendica\Content\ContactSelector; use Friendica\Content\Feature; +use Friendica\Content\Item as ContentItem; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\Hook; @@ -324,7 +325,10 @@ class Post extends BaseObject $body = Item::prepareBody($item, true); - list($categories, $folders) = get_cats_and_terms($item); + /** @var ContentItem $contItem */ + $contItem = self::getClass(ContentItem::class); + + list($categories, $folders) = $contItem->determineCategoriesTerms($item); $body_e = $body; $text_e = strip_tags($body); diff --git a/tests/src/Content/ItemTest.php b/tests/src/Content/ItemTest.php new file mode 100644 index 0000000000..5cdfa978bd --- /dev/null +++ b/tests/src/Content/ItemTest.php @@ -0,0 +1,13 @@ +markTestIncomplete('Test data needed.'); + } +} -- 2.39.5