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 $photos = 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 $albums = array_column($photos, 'album');
59 $sql_extra = sprintf("AND `album` = '%s' ", DBA::escape($album));
61 $path[$album] = $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(DI::l10n()->t('Contact Photos'))
73 function _map_files1($rr)
76 $types = Images::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 DI::baseUrl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
92 DI::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, [
102 '$folders' => $albums,
104 '$cancel' => DI::l10n()->t('Cancel'),
105 '$nickname' => $a->user['nickname'],
106 '$upload' => DI::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 [DI::baseUrl() . '/attach/' . $rr['id'], $filename_e, DI::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 '$path' => [ [ "", DI::l10n()->t("Files")] ],
133 '$cancel' => DI::l10n()->t('Cancel'),
134 '$nickname' => $a->user['nickname'],
135 '$upload' => DI::l10n()->t('Upload')
142 if (!empty($_GET['mode'])) {