3 * @package Friendica\modules
4 * @subpackage FileBrowser
5 * @author Fabio Comuni <fabrixxm@kirgroup.com>
9 use Friendica\Core\Renderer;
10 use Friendica\Database\DBA;
12 use Friendica\Util\Images;
13 use Friendica\Util\Strings;
18 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
20 function fbrowser_content(App $a)
30 // Needed to match the correct template in a module that uses a different theme than the user/site/default
31 $theme = Strings::sanitizeFilePathItem($_GET['theme'] ?? null);
32 if ($theme && is_file("view/theme/$theme/config.php")) {
33 $a->setCurrentTheme($theme);
36 $template_file = "filebrowser.tpl";
40 switch ($a->argv[1]) {
42 $path = [["", DI::l10n()->t("Photos")]];
45 $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
48 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
50 DBA::escape('Contact Photos'),
51 DBA::escape(DI::l10n()->t('Contact Photos'))
54 function _map_folder1($el)
56 return [bin2hex($el['album']),$el['album']];
59 $albums = array_map("_map_folder1", $albums);
63 $album = hex2bin($a->argv[2]);
64 $sql_extra = sprintf("AND `album` = '%s' ", DBA::escape($album));
66 $path[] = [$a->argv[2], $album];
69 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`,
70 min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created`
71 FROM `photo` WHERE `uid` = %d $sql_extra AND `album` != '%s' AND `album` != '%s'
72 GROUP BY `resource-id` $sql_extra2",
74 DBA::escape('Contact Photos'),
75 DBA::escape(DI::l10n()->t('Contact Photos'))
78 function _map_files1($rr)
81 $types = Images::supportedTypes();
82 $ext = $types[$rr['type']];
83 $filename_e = $rr['filename'];
85 // Take the largest picture that is smaller or equal 640 pixels
86 $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
87 DBA::escape($rr['resource-id']));
89 $scale = $p[0]["scale"];
95 DI::baseUrl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
97 DI::baseUrl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
100 $files = array_map("_map_files1", $r);
102 $tpl = Renderer::getMarkupTemplate($template_file);
104 $o = Renderer::replaceMacros($tpl, [
107 '$folders' => $albums,
109 '$cancel' => DI::l10n()->t('Cancel'),
110 '$nickname' => $a->user['nickname'],
111 '$upload' => DI::l10n()->t('Upload')
117 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
121 function _map_files2($rr)
123 list($m1, $m2) = explode("/", $rr['filetype']);
124 $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
125 $filename_e = $rr['filename'];
127 return [DI::baseUrl() . '/attach/' . $rr['id'], $filename_e, DI::baseUrl() . '/images/icons/16/' . $filetype . '.png'];
129 $files = array_map("_map_files2", $files);
132 $tpl = Renderer::getMarkupTemplate($template_file);
133 $o = Renderer::replaceMacros($tpl, [
135 '$path' => [ [ "", DI::l10n()->t("Files")] ],
138 '$cancel' => DI::l10n()->t('Cancel'),
139 '$nickname' => $a->user['nickname'],
140 '$upload' => DI::l10n()->t('Upload')
147 if (!empty($_GET['mode'])) {