2019-10-23 02:48:46 +02:00
|
|
|
<?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) {
|
2019-11-03 19:57:32 +01:00
|
|
|
if (!empty($item['author-link'])) {
|
|
|
|
$url = $item['author-link'] . "?category=" . rawurlencode($savedFolderName);
|
|
|
|
} else {
|
|
|
|
$url = '#';
|
|
|
|
}
|
2019-10-23 02:48:46 +02:00
|
|
|
$categories[] = [
|
|
|
|
'name' => $savedFolderName,
|
2019-11-03 16:34:58 +01:00
|
|
|
'url' => $url,
|
2020-01-13 21:10:13 +01:00
|
|
|
'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?cat=' . rawurlencode($savedFolderName) : ""),
|
2019-10-23 02:48:46 +02:00
|
|
|
'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' => "#",
|
2020-01-13 21:10:13 +01:00
|
|
|
'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?term=' . rawurlencode($savedFolderName) : ""),
|
2019-10-23 02:48:46 +02:00
|
|
|
'first' => $first,
|
|
|
|
'last' => false
|
|
|
|
];
|
|
|
|
$first = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($folders)) {
|
|
|
|
$folders[count($folders) - 1]['last'] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [$categories, $folders];
|
|
|
|
}
|
|
|
|
}
|