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 function fbrowser_content(App $a)
28 $template_file = "filebrowser.tpl";
30 if (!empty($_GET['mode'])) {
31 $mode = "?mode=".$_GET['mode'];
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);
58 $album = hex2bin($a->argv[2]);
59 $sql_extra = sprintf("AND `album` = '%s' ", DBA::escape($album));
61 $path[]=[$a->argv[2], $album];
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",
69 DBA::escape('Contact Photos'),
70 DBA::escape(L10n::t('Contact Photos'))
73 function _map_files1($rr)
76 $types = Image::supportedTypes();
77 $ext = $types[$rr['type']];
78 $filename_e = $rr['filename'];
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']));
84 $scale = $p[0]["scale"];
90 System::baseUrl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
92 System::baseUrl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
95 $files = array_map("_map_files1", $r);
97 $tpl = Renderer::getMarkupTemplate($template_file);
99 $o = Renderer::replaceMacros($tpl, [
101 '$baseurl' => System::baseUrl(),
103 '$folders' => $albums,
105 '$cancel' => L10n::t('Cancel'),
106 '$nickname' => $a->user['nickname'],
107 '$upload' => L10n::t('Upload')
113 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
117 function _map_files2($rr)
120 list($m1,$m2) = explode("/", $rr['filetype']);
121 $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
122 $filename_e = $rr['filename'];
124 return [System::baseUrl() . '/attach/' . $rr['id'], $filename_e, System::baseUrl() . '/images/icons/16/' . $filetype . '.png'];
126 $files = array_map("_map_files2", $files);
129 $tpl = Renderer::getMarkupTemplate($template_file);
130 $o = Renderer::replaceMacros($tpl, [
132 '$baseurl' => System::baseUrl(),
133 '$path' => [ [ "", L10n::t("Files")] ],
136 '$cancel' => L10n::t('Cancel'),
137 '$nickname' => $a->user['nickname'],
138 '$upload' => L10n::t('Upload')
145 if (!empty($_GET['mode'])) {