friendica/include/text.php

75 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/**
* @file include/text.php
*/
use Friendica\Model\FileTag;
/**
2013-03-27 10:11:40 +01:00
* return array with details for categories and folders for an item
*
2013-03-27 10:11:40 +01:00
* @param array $item
* @return array
*
2013-03-27 10:11:40 +01:00
* [
* [ // categories array
* {
* 'name': 'category name',
2013-03-27 10:11:40 +01:00
* 'removeurl': 'url to remove this category',
* 'first': 'is the first in this array? true/false',
* 'last': 'is the last in this array? true/false',
* } ,
* ....
* ],
2013-03-27 10:11:40 +01:00
* [ //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',
* } ,
* ....
* ]
2013-03-27 10:11:40 +01:00
* ]
*/
function get_cats_and_terms($item)
{
$categories = [];
$folders = [];
$first = true;
2019-05-30 13:54:17 +02:00
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']) {
2019-05-30 13:54:17 +02:00
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];
}