3 * @package Friendica\modules
4 * @subpackage FileBrowser
5 * @author Fabio Comuni <fabrixxm@kirgroup.com>
9 use Friendica\Core\System;
10 use Friendica\Object\Image;
15 function fbrowser_content(App $a) {
25 $template_file = "filebrowser.tpl";
27 if (x($_GET,'mode')) {
28 $mode = "?mode=".$_GET['mode'];
31 switch ($a->argv[1]) {
33 $path = array(array("", t("Photos")));
36 $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
39 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
41 dbesc('Contact Photos'),
42 dbesc( t('Contact Photos'))
45 function _map_folder1($el){return array(bin2hex($el['album']),$el['album']);};
46 $albums = array_map( "_map_folder1" , $albums);
52 $album = hex2bin($a->argv[2]);
53 $sql_extra = sprintf("AND `album` = '%s' ",dbesc($album));
55 $path[]=array($a->argv[2], $album);
58 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`,
59 min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created`
60 FROM `photo` WHERE `uid` = %d $sql_extra AND `album` != '%s' AND `album` != '%s'
61 GROUP BY `resource-id` $sql_extra2",
63 dbesc('Contact Photos'),
64 dbesc( t('Contact Photos'))
67 function _map_files1($rr){
69 $types = Image::supportedTypes();
70 $ext = $types[$rr['type']];
71 $filename_e = $rr['filename'];
73 // Take the largest picture that is smaller or equal 640 pixels
74 $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
75 dbesc($rr['resource-id']));
77 $scale = $p[0]["scale"];
82 System::baseUrl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
84 System::baseUrl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
87 $files = array_map("_map_files1", $r);
89 $tpl = get_markup_template($template_file);
91 $o = replace_macros($tpl, array(
93 '$baseurl' => System::baseUrl(),
95 '$folders' => $albums,
97 '$cancel' => t('Cancel'),
98 '$nickname' => $a->user['nickname'],
105 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
109 function _map_files2($rr){
111 list($m1,$m2) = explode("/",$rr['filetype']);
112 $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
113 $filename_e = $rr['filename'];
115 return array(System::baseUrl() . '/attach/' . $rr['id'], $filename_e, System::baseUrl() . '/images/icons/16/' . $filetype . '.png');
117 $files = array_map("_map_files2", $files);
120 $tpl = get_markup_template($template_file);
121 $o = replace_macros($tpl, array(
123 '$baseurl' => System::baseUrl(),
124 '$path' => array( array( "", t("Files")) ),
127 '$cancel' => t('Cancel'),
128 '$nickname' => $a->user['nickname'],
136 if (x($_GET,'mode')) {