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']);
73 $filename_e = $rr['filename'];
76 // Take the largest picture that is smaller or equal 640 pixels
77 $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
78 dbesc($rr['resource-id']));
80 $scale = $p[0]["scale"];
85 App::get_baseurl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
87 App::get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
90 $files = array_map("_map_files1", $r);
92 $tpl = get_markup_template($template_file);
94 $o = replace_macros($tpl, array(
96 '$baseurl' => App::get_baseurl(),
98 '$folders' => $albums,
100 '$cancel' => t('Cancel'),
101 '$nickname' => $a->user['nickname'],
108 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
112 function _map_files2($rr){
114 list($m1,$m2) = explode("/",$rr['filetype']);
115 $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
117 if ($a->theme['template_engine'] === 'internal') {
118 $filename_e = template_escape($rr['filename']);
120 $filename_e = $rr['filename'];
123 return array( App::get_baseurl() . '/attach/' . $rr['id'], $filename_e, App::get_baseurl() . '/images/icons/16/' . $filetype . '.png');
125 $files = array_map("_map_files2", $files);
128 $tpl = get_markup_template($template_file);
129 $o = replace_macros($tpl, array(
131 '$baseurl' => App::get_baseurl(),
132 '$path' => array( array( "", t("Files")) ),
135 '$cancel' => t('Cancel'),
136 '$nickname' => $a->user['nickname'],
144 if (x($_GET,'mode')) {