3 * @package Friendica\modules
4 * @subpackage FileBrowser
5 * @author Fabio Comuni <fabrixxm@kirgroup.com>
9 use Friendica\Core\L10n;
10 use Friendica\Core\System;
11 use Friendica\Database\DBA;
12 use Friendica\Object\Image;
17 function fbrowser_content(App $a)
27 $template_file = "filebrowser.tpl";
29 if (x($_GET, 'mode')) {
30 $mode = "?mode=".$_GET['mode'];
33 switch ($a->argv[1]) {
35 $path = [["", L10n::t("Photos")]];
38 $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
41 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
43 DBA::escape('Contact Photos'),
44 DBA::escape(L10n::t('Contact Photos'))
47 function _map_folder1($el)
49 return [bin2hex($el['album']),$el['album']];
52 $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 = get_markup_template($template_file);
98 $o = replace_macros($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)
119 list($m1,$m2) = explode("/", $rr['filetype']);
120 $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
121 $filename_e = $rr['filename'];
123 return [System::baseUrl() . '/attach/' . $rr['id'], $filename_e, System::baseUrl() . '/images/icons/16/' . $filetype . '.png'];
125 $files = array_map("_map_files2", $files);
128 $tpl = get_markup_template($template_file);
129 $o = replace_macros($tpl, [
131 '$baseurl' => System::baseUrl(),
132 '$path' => [ [ "", L10n::t("Files")] ],
135 '$cancel' => L10n::t('Cancel'),
136 '$nickname' => $a->user['nickname'],
137 '$upload' => L10n::t('Upload')
144 if (x($_GET, 'mode')) {