]> git.mxchange.org Git - friendica.git/blob - src/Content/Item.php
Merge pull request #8269 from MrPetovan/bug/frio-more-actions
[friendica.git] / src / Content / Item.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Content;
23
24 use Friendica\Model\FileTag;
25
26 /**
27  * A content helper class for displaying items
28  */
29 class Item
30 {
31         /**
32          * Return array with details for categories and folders for an item
33          *
34          * @param array $item
35          * @return [array, array]
36          *
37          * [
38          *      [ // categories array
39          *          {
40          *               'name': 'category name',
41          *               'removeurl': 'url to remove this category',
42          *               'first': 'is the first in this array? true/false',
43          *               'last': 'is the last in this array? true/false',
44          *           } ,
45          *           ....
46          *       ],
47          *       [ //folders array
48          *                      {
49          *               'name': 'folder name',
50          *               'removeurl': 'url to remove this folder',
51          *               'first': 'is the first in this array? true/false',
52          *               'last': 'is the last in this array? true/false',
53          *           } ,
54          *           ....
55          *       ]
56          *  ]
57          */
58         public function determineCategoriesTerms(array $item)
59         {
60                 $categories = [];
61                 $folders = [];
62                 $first = true;
63
64                 foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) {
65                         if (!empty($item['author-link'])) {
66                                 $url = $item['author-link'] . "?category=" . rawurlencode($savedFolderName);
67                         } else {
68                                 $url = '#';
69                         }
70                         $categories[] = [
71                                 'name' => $savedFolderName,
72                                 'url' => $url,
73                                 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?cat=' . rawurlencode($savedFolderName) : ""),
74                                 'first' => $first,
75                                 'last' => false
76                         ];
77                         $first = false;
78                 }
79
80                 if (count($categories)) {
81                         $categories[count($categories) - 1]['last'] = true;
82                 }
83
84                 if (local_user() == $item['uid']) {
85                         foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) {
86                                 $folders[] = [
87                                         'name' => $savedFolderName,
88                                         'url' => "#",
89                                         'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?term=' . rawurlencode($savedFolderName) : ""),
90                                         'first' => $first,
91                                         'last' => false
92                                 ];
93                                 $first = false;
94                         }
95                 }
96
97                 if (count($folders)) {
98                         $folders[count($folders) - 1]['last'] = true;
99                 }
100
101                 return [$categories, $folders];
102         }
103 }