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