Move (last) get_cats_and_terms to Content\Item::determineCategoriesTerms()
- Added incomplete test
This commit is contained in:
parent
ad67fd3aa8
commit
edf006905b
|
@ -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']);
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @file include/text.php
|
||||
*/
|
||||
|
||||
use Friendica\Model\FileTag;
|
||||
|
||||
/**
|
||||
* return array with details for categories and folders for an item
|
||||
*
|
||||
* @param array $item
|
||||
* @return array
|
||||
*
|
||||
* [
|
||||
* [ // categories array
|
||||
* {
|
||||
* 'name': 'category name',
|
||||
* 'removeurl': 'url to remove this category',
|
||||
* 'first': 'is the first in this array? true/false',
|
||||
* 'last': 'is the last in this array? true/false',
|
||||
* } ,
|
||||
* ....
|
||||
* ],
|
||||
* [ //folders array
|
||||
* {
|
||||
* 'name': 'folder name',
|
||||
* 'removeurl': 'url to remove this folder',
|
||||
* 'first': 'is the first in this array? true/false',
|
||||
* 'last': 'is the last in this array? true/false',
|
||||
* } ,
|
||||
* ....
|
||||
* ]
|
||||
* ]
|
||||
*/
|
||||
function get_cats_and_terms($item)
|
||||
{
|
||||
$categories = [];
|
||||
$folders = [];
|
||||
$first = true;
|
||||
|
||||
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)) {
|
||||
$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];
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Content;
|
||||
|
||||
use Friendica\Model\FileTag;
|
||||
|
||||
/**
|
||||
* A content helper class for displaying items
|
||||
*/
|
||||
final class Item
|
||||
{
|
||||
/**
|
||||
* Return array with details for categories and folders for an item
|
||||
*
|
||||
* @param array $item
|
||||
* @return [array, array]
|
||||
*
|
||||
* [
|
||||
* [ // categories array
|
||||
* {
|
||||
* 'name': 'category name',
|
||||
* 'removeurl': 'url to remove this category',
|
||||
* 'first': 'is the first in this array? true/false',
|
||||
* 'last': 'is the last in this array? true/false',
|
||||
* } ,
|
||||
* ....
|
||||
* ],
|
||||
* [ //folders array
|
||||
* {
|
||||
* 'name': 'folder name',
|
||||
* 'removeurl': 'url to remove this folder',
|
||||
* 'first': 'is the first in this array? true/false',
|
||||
* 'last': 'is the last in this array? true/false',
|
||||
* } ,
|
||||
* ....
|
||||
* ]
|
||||
* ]
|
||||
*/
|
||||
public function determineCategoriesTerms(array $item)
|
||||
{
|
||||
$categories = [];
|
||||
$folders = [];
|
||||
$first = true;
|
||||
|
||||
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)) {
|
||||
$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];
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\src\Content;
|
||||
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class ItemTest extends MockedTest
|
||||
{
|
||||
public function testDetermineCategoriesTerms()
|
||||
{
|
||||
$this->markTestIncomplete('Test data needed.');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user