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