]> git.mxchange.org Git - friendica.git/blob - src/Content/Item.php
f086fbe19cc1b6e50706d052c948af35faa5150d
[friendica.git] / src / Content / Item.php
1 <?php
2
3 namespace Friendica\Content;
4
5 use Friendica\Model\FileTag;
6
7 /**
8  * A content helper class for displaying items
9  */
10 final class Item
11 {
12         /**
13          * Return array with details for categories and folders for an item
14          *
15          * @param array $item
16          * @return [array, array]
17          *
18          * [
19          *      [ // categories array
20          *          {
21          *               'name': 'category name',
22          *               'removeurl': 'url to remove this category',
23          *               'first': 'is the first in this array? true/false',
24          *               'last': 'is the last in this array? true/false',
25          *           } ,
26          *           ....
27          *       ],
28          *       [ //folders array
29          *                      {
30          *               'name': 'folder name',
31          *               'removeurl': 'url to remove this folder',
32          *               'first': 'is the first in this array? true/false',
33          *               'last': 'is the last in this array? true/false',
34          *           } ,
35          *           ....
36          *       ]
37          *  ]
38          */
39         public function determineCategoriesTerms(array $item)
40         {
41                 $categories = [];
42                 $folders = [];
43                 $first = true;
44
45                 if (!empty($item['author-link'])) {
46                         $url = $item['author-link'] . "?category=" . rawurlencode($savedFolderName);
47                 } else {
48                         $url = '#';
49                 }
50
51                 foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) {
52                         $categories[] = [
53                                 'name' => $savedFolderName,
54                                 'url' => $url,
55                                 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""),
56                                 'first' => $first,
57                                 'last' => false
58                         ];
59                         $first = false;
60                 }
61
62                 if (count($categories)) {
63                         $categories[count($categories) - 1]['last'] = true;
64                 }
65
66                 if (local_user() == $item['uid']) {
67                         foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) {
68                                 $folders[] = [
69                                         'name' => $savedFolderName,
70                                         'url' => "#",
71                                         'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . rawurlencode($savedFolderName) : ""),
72                                         'first' => $first,
73                                         'last' => false
74                                 ];
75                                 $first = false;
76                         }
77                 }
78
79                 if (count($folders)) {
80                         $folders[count($folders) - 1]['last'] = true;
81                 }
82
83                 return [$categories, $folders];
84         }
85 }