3 * @package Friendica\modules
4 * @subpackage FileBrowser
5 * @author Fabio Comuni <fabrixxm@kirgroup.com>
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;
18 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
20 function fbrowser_content(App $a)
30 $template_file = "filebrowser.tpl";
34 switch ($a->argv[1]) {
36 $path = [["", L10n::t("Photos")]];
39 $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
42 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
44 DBA::escape('Contact Photos'),
45 DBA::escape(L10n::t('Contact Photos'))
48 function _map_folder1($el)
50 return [bin2hex($el['album']),$el['album']];
53 $albums = array_map("_map_folder1", $albums);
57 $album = hex2bin($a->argv[2]);
58 $sql_extra = sprintf("AND `album` = '%s' ", DBA::escape($album));
60 $path[] = [$a->argv[2], $album];
63 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`,
64 min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created`
65 FROM `photo` WHERE `uid` = %d $sql_extra AND `album` != '%s' AND `album` != '%s'
66 GROUP BY `resource-id` $sql_extra2",
68 DBA::escape('Contact Photos'),
69 DBA::escape(L10n::t('Contact Photos'))
72 function _map_files1($rr)
75 $types = Image::supportedTypes();
76 $ext = $types[$rr['type']];
77 $filename_e = $rr['filename'];
79 // Take the largest picture that is smaller or equal 640 pixels
80 $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
81 DBA::escape($rr['resource-id']));
83 $scale = $p[0]["scale"];
89 System::baseUrl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
91 System::baseUrl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
94 $files = array_map("_map_files1", $r);
96 $tpl = Renderer::getMarkupTemplate($template_file);
98 $o = Renderer::replaceMacros($tpl, [
100 '$baseurl' => System::baseUrl(),
102 '$folders' => $albums,
104 '$cancel' => L10n::t('Cancel'),
105 '$nickname' => $a->user['nickname'],
106 '$upload' => L10n::t('Upload')
112 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
116 function _map_files2($rr)
118 list($m1, $m2) = explode("/", $rr['filetype']);
119 $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
120 $filename_e = $rr['filename'];
122 return [System::baseUrl() . '/attach/' . $rr['id'], $filename_e, System::baseUrl() . '/images/icons/16/' . $filetype . '.png'];
124 $files = array_map("_map_files2", $files);
127 $tpl = Renderer::getMarkupTemplate($template_file);
128 $o = Renderer::replaceMacros($tpl, [
130 '$baseurl' => System::baseUrl(),
131 '$path' => [ [ "", L10n::t("Files")] ],
134 '$cancel' => L10n::t('Cancel'),
135 '$nickname' => $a->user['nickname'],
136 '$upload' => L10n::t('Upload')
143 if (!empty($_GET['mode'])) {