3 * @package Friendica\modules
4 * @subpackage FileBrowser
5 * @author Fabio Comuni <fabrixxm@kirgroup.com>
8 require_once('include/Photo.php');
13 function fbrowser_content(App $a) {
23 $template_file = "filebrowser.tpl";
25 if (x($_GET,'mode')) {
26 $mode = "?mode=".$_GET['mode'];
29 switch ($a->argv[1]) {
31 $path = array(array("", t("Photos")));
34 $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
37 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
39 dbesc('Contact Photos'),
40 dbesc( t('Contact Photos'))
43 function _map_folder1($el){return array(bin2hex($el['album']),$el['album']);};
44 $albums = array_map( "_map_folder1" , $albums);
50 $album = hex2bin($a->argv[2]);
51 $sql_extra = sprintf("AND `album` = '%s' ",dbesc($album));
53 $path[]=array($a->argv[2], $album);
56 $r = q("SELECT `resource-id`, `id`, `filename`, type, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc`
57 FROM `photo` WHERE `uid` = %d $sql_extra AND `album` != '%s' AND `album` != '%s'
58 GROUP BY `resource-id` $sql_extra2",
60 dbesc('Contact Photos'),
61 dbesc( t('Contact Photos'))
64 function _map_files1($rr){
66 $types = Photo::supportedTypes();
67 $ext = $types[$rr['type']];
69 if ($a->theme['template_engine'] === 'internal') {
70 $filename_e = template_escape($rr['filename']);
72 $filename_e = $rr['filename'];
75 // Take the largest picture that is smaller or equal 640 pixels
76 $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
77 dbesc($rr['resource-id']));
79 $scale = $p[0]["scale"];
84 App::get_baseurl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
86 App::get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
89 $files = array_map("_map_files1", $r);
91 $tpl = get_markup_template($template_file);
93 $o = replace_macros($tpl, array(
95 '$baseurl' => App::get_baseurl(),
97 '$folders' => $albums,
99 '$cancel' => t('Cancel'),
100 '$nickname' => $a->user['nickname'],
107 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
111 function _map_files2($rr){
113 list($m1,$m2) = explode("/",$rr['filetype']);
114 $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
116 if ($a->theme['template_engine'] === 'internal') {
117 $filename_e = template_escape($rr['filename']);
119 $filename_e = $rr['filename'];
122 return array( App::get_baseurl() . '/attach/' . $rr['id'], $filename_e, App::get_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, array(
130 '$baseurl' => App::get_baseurl(),
131 '$path' => array( array( "", t("Files")) ),
134 '$cancel' => t('Cancel'),
135 '$nickname' => $a->user['nickname'],
143 if (x($_GET,'mode')) {