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\Object\Image;
16 function fbrowser_content(App $a)
26 $template_file = "filebrowser.tpl";
28 if (x($_GET, 'mode')) {
29 $mode = "?mode=".$_GET['mode'];
32 switch ($a->argv[1]) {
34 $path = [["", L10n::t("Photos")]];
37 $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
40 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
42 dbesc('Contact Photos'),
43 dbesc(L10n::t('Contact Photos'))
46 function _map_folder1($el)
48 return [bin2hex($el['album']),$el['album']];
51 $albums = array_map("_map_folder1", $albums);
56 $album = hex2bin($a->argv[2]);
57 $sql_extra = sprintf("AND `album` = '%s' ", dbesc($album));
59 $path[]=[$a->argv[2], $album];
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",
67 dbesc('Contact Photos'),
68 dbesc(L10n::t('Contact Photos'))
71 function _map_files1($rr)
74 $types = Image::supportedTypes();
75 $ext = $types[$rr['type']];
76 $filename_e = $rr['filename'];
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']));
82 $scale = $p[0]["scale"];
88 System::baseUrl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
90 System::baseUrl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
93 $files = array_map("_map_files1", $r);
95 $tpl = get_markup_template($template_file);
97 $o = replace_macros($tpl, [
99 '$baseurl' => System::baseUrl(),
101 '$folders' => $albums,
103 '$cancel' => L10n::t('Cancel'),
104 '$nickname' => $a->user['nickname'],
105 '$upload' => L10n::t('Upload')
111 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
115 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 = get_markup_template($template_file);
128 $o = replace_macros($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 (x($_GET, 'mode')) {