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\Model\Photo;
13 use Friendica\Util\Images;
14 use Friendica\Util\Strings;
19 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
21 function fbrowser_content(App $a)
31 // Needed to match the correct template in a module that uses a different theme than the user/site/default
32 $theme = Strings::sanitizeFilePathItem($_GET['theme'] ?? null);
33 if ($theme && is_file("view/theme/$theme/config.php")) {
34 $a->setCurrentTheme($theme);
37 $template_file = "filebrowser.tpl";
41 switch ($a->argv[1]) {
43 $path = ['' => DI::l10n()->t('Photos')];
46 $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
49 $photos = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
51 DBA::escape(Photo::CONTACT_PHOTOS),
52 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS))
55 $albums = array_column($photos, 'album');
60 $sql_extra = sprintf("AND `album` = '%s' ", DBA::escape($album));
62 $path[$album] = $album;
65 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`,
66 min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created`
67 FROM `photo` WHERE `uid` = %d $sql_extra AND `album` != '%s' AND `album` != '%s'
68 GROUP BY `resource-id` $sql_extra2",
70 DBA::escape(Photo::CONTACT_PHOTOS),
71 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS))
74 function _map_files1($rr)
77 $types = Images::supportedTypes();
78 $ext = $types[$rr['type']];
79 $filename_e = $rr['filename'];
81 // Take the largest picture that is smaller or equal 640 pixels
82 $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
83 DBA::escape($rr['resource-id']));
85 $scale = $p[0]["scale"];
91 DI::baseUrl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
93 DI::baseUrl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
96 $files = array_map("_map_files1", $r);
98 $tpl = Renderer::getMarkupTemplate($template_file);
100 $o = Renderer::replaceMacros($tpl, [
103 '$folders' => $albums,
105 '$cancel' => DI::l10n()->t('Cancel'),
106 '$nickname' => $a->user['nickname'],
107 '$upload' => DI::l10n()->t('Upload')
113 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
117 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 [DI::baseUrl() . '/attach/' . $rr['id'], $filename_e, DI::baseUrl() . '/images/icons/16/' . $filetype . '.png'];
125 $files = array_map("_map_files2", $files);
128 $tpl = Renderer::getMarkupTemplate($template_file);
129 $o = Renderer::replaceMacros($tpl, [
131 '$path' => [ [ "", DI::l10n()->t("Files")] ],
134 '$cancel' => DI::l10n()->t('Cancel'),
135 '$nickname' => $a->user['nickname'],
136 '$upload' => DI::l10n()->t('Upload')
143 if (!empty($_GET['mode'])) {