]> git.mxchange.org Git - friendica.git/blob - mod/fbrowser.php
Remove unused global cache constants
[friendica.git] / mod / fbrowser.php
1 <?php
2 /**
3  * @package             Friendica\modules
4  * @subpackage  FileBrowser
5  * @author              Fabio Comuni <fabrixxm@kirgroup.com>
6  */
7
8 use Friendica\App;
9 use Friendica\Core\L10n;
10 use Friendica\Core\System;
11 use Friendica\Object\Image;
12
13 /**
14  * @param App $a
15  */
16 function fbrowser_content(App $a)
17 {
18         if (!local_user()) {
19                 killme();
20         }
21
22         if ($a->argc == 1) {
23                 killme();
24         }
25
26         $template_file = "filebrowser.tpl";
27         $mode = "";
28         if (x($_GET, 'mode')) {
29                 $mode  = "?mode=".$_GET['mode'];
30         }
31
32         switch ($a->argv[1]) {
33                 case "image":
34                         $path = [["", L10n::t("Photos")]];
35                         $albums = false;
36                         $sql_extra = "";
37                         $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
38
39                         if ($a->argc==2) {
40                                 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
41                                         intval(local_user()),
42                                         dbesc('Contact Photos'),
43                                         dbesc(L10n::t('Contact Photos'))
44                                 );
45
46                                 function _map_folder1($el)
47                                 {
48                                         return [bin2hex($el['album']),$el['album']];
49                                 };
50
51                                 $albums = array_map("_map_folder1", $albums);
52                         }
53
54                         $album = "";
55                         if ($a->argc==3) {
56                                 $album = hex2bin($a->argv[2]);
57                                 $sql_extra = sprintf("AND `album` = '%s' ", dbesc($album));
58                                 $sql_extra2 = "";
59                                 $path[]=[$a->argv[2], $album];
60                         }
61
62                         $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`,
63                                         min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created`
64                                         FROM `photo` WHERE `uid` = %d $sql_extra AND `album` != '%s' AND `album` != '%s'
65                                         GROUP BY `resource-id` $sql_extra2",
66                                 intval(local_user()),
67                                 dbesc('Contact Photos'),
68                                 dbesc(L10n::t('Contact Photos'))
69                         );
70
71                         function _map_files1($rr)
72                         {
73                                 $a = get_app();
74                                 $types = Image::supportedTypes();
75                                 $ext = $types[$rr['type']];
76                                 $filename_e = $rr['filename'];
77
78                                 // Take the largest picture that is smaller or equal 640 pixels
79                                 $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
80                                         dbesc($rr['resource-id']));
81                                 if ($p) {
82                                         $scale = $p[0]["scale"];
83                                 } else {
84                                         $scale = $rr['loq'];
85                                 }
86
87                                 return [
88                                         System::baseUrl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
89                                         $filename_e,
90                                         System::baseUrl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
91                                 ];
92                         }
93                         $files = array_map("_map_files1", $r);
94
95                         $tpl = get_markup_template($template_file);
96
97                         $o =  replace_macros($tpl, [
98                                 '$type'     => 'image',
99                                 '$baseurl'  => System::baseUrl(),
100                                 '$path'     => $path,
101                                 '$folders'  => $albums,
102                                 '$files'    => $files,
103                                 '$cancel'   => L10n::t('Cancel'),
104                                 '$nickname' => $a->user['nickname'],
105                                 '$upload'   => L10n::t('Upload')
106                         ]);
107
108                         break;
109                 case "file":
110                         if ($a->argc==2) {
111                                 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
112                                         intval(local_user())
113                                 );
114
115                                 function _map_files2($rr)
116                                 {
117                                         $a = get_app();
118                                         list($m1,$m2) = explode("/", $rr['filetype']);
119                                         $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
120                                         $filename_e = $rr['filename'];
121
122                                         return [System::baseUrl() . '/attach/' . $rr['id'], $filename_e, System::baseUrl() . '/images/icons/16/' . $filetype . '.png'];
123                                 }
124                                 $files = array_map("_map_files2", $files);
125
126
127                                 $tpl = get_markup_template($template_file);
128                                 $o = replace_macros($tpl, [
129                                         '$type'     => 'file',
130                                         '$baseurl'  => System::baseUrl(),
131                                         '$path'     => [ [ "", L10n::t("Files")] ],
132                                         '$folders'  => false,
133                                         '$files'    => $files,
134                                         '$cancel'   => L10n::t('Cancel'),
135                                         '$nickname' => $a->user['nickname'],
136                                         '$upload'   => L10n::t('Upload')
137                                 ]);
138                         }
139
140                         break;
141         }
142
143         if (x($_GET, 'mode')) {
144                 return $o;
145         } else {
146                 echo $o;
147                 killme();
148         }
149 }