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){
21 $template_file = "filebrowser.tpl";
23 if (x($_GET,'mode')) {
24 $template_file = "filebrowser_plain.tpl";
25 $mode = "?mode=".$_GET['mode'];
28 //echo "<pre>"; var_dump($a->argv); killme();
32 $path = array( array("", t("Photos")));
35 $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
38 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
40 dbesc('Contact Photos'),
41 dbesc( t('Contact Photos'))
44 function _map_folder1($el){return array(bin2hex($el['album']),$el['album']);};
45 $albums = array_map( "_map_folder1" , $albums);
51 $album = hex2bin($a->argv[2]);
52 $sql_extra = sprintf("AND `album` = '%s' ",dbesc($album));
54 $path[]=array($a->argv[2], $album);
57 $r = q("SELECT `resource-id`, `id`, `filename`, type, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc`
58 FROM `photo` WHERE `uid` = %d $sql_extra AND `album` != '%s' AND `album` != '%s'
59 GROUP BY `resource-id` $sql_extra2",
61 dbesc('Contact Photos'),
62 dbesc( t('Contact Photos'))
65 function _map_files1($rr){
67 $types = Photo::supportedTypes();
68 $ext = $types[$rr['type']];
70 if($a->theme['template_engine'] === 'internal') {
71 $filename_e = template_escape($rr['filename']);
74 $filename_e = $rr['filename'];
77 // Take the largest picture that is smaller or equal 640 pixels
78 $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
79 dbesc($rr['resource-id']));
81 $scale = $p[0]["scale"];
86 App::get_baseurl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
88 App::get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
91 $files = array_map("_map_files1", $r);
93 $tpl = get_markup_template($template_file);
95 $o = replace_macros($tpl, array(
97 '$baseurl' => App::get_baseurl(),
99 '$folders' => $albums,
101 '$cancel' => t('Cancel'),
102 '$nickname' => $a->user['nickname'],
109 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
113 function _map_files2($rr){
115 list($m1,$m2) = explode("/",$rr['filetype']);
116 $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
118 if($a->theme['template_engine'] === 'internal') {
119 $filename_e = template_escape($rr['filename']);
122 $filename_e = $rr['filename'];
125 return array( App::get_baseurl() . '/attach/' . $rr['id'], $filename_e, App::get_baseurl() . '/images/icons/16/' . $filetype . '.png');
127 $files = array_map("_map_files2", $files);
130 $tpl = get_markup_template($template_file);
131 $o = replace_macros($tpl, array(
133 '$baseurl' => App::get_baseurl(),
134 '$path' => array( array( "", t("Files")) ),
137 '$cancel' => t('Cancel'),
138 '$nickname' => $a->user['nickname'],
146 if (x($_GET,'mode')) {