]> git.mxchange.org Git - friendica.git/blob - src/Content/Item.php
Merge pull request #7765 from nupplaphil/task/move_text
[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                 foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) {
46                         $categories[] = [
47                                 'name' => $savedFolderName,
48                                 'url' => "#",
49                                 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""),
50                                 'first' => $first,
51                                 'last' => false
52                         ];
53                         $first = false;
54                 }
55
56                 if (count($categories)) {
57                         $categories[count($categories) - 1]['last'] = true;
58                 }
59
60                 if (local_user() == $item['uid']) {
61                         foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) {
62                                 $folders[] = [
63                                         'name' => $savedFolderName,
64                                         'url' => "#",
65                                         'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . rawurlencode($savedFolderName) : ""),
66                                         'first' => $first,
67                                         'last' => false
68                                 ];
69                                 $first = false;
70                         }
71                 }
72
73                 if (count($folders)) {
74                         $folders[count($folders) - 1]['last'] = true;
75                 }
76
77                 return [$categories, $folders];
78         }
79 }