3 * @package Friendica\modules
4 * @subpackage FileBrowser
5 * @author Fabio Comuni <fabrixxm@kirgroup.com>
8 require_once('include/Photo.php');
13 /// @TODO & is missing or App ?
14 function fbrowser_content($a){
22 $template_file = "filebrowser.tpl";
24 if (x($_GET,'mode')) {
25 $template_file = "filebrowser_plain.tpl";
26 $mode = "?mode=".$_GET['mode'];
29 //echo "<pre>"; var_dump($a->argv); killme();
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`, `id`, `filename`, type, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc`
59 FROM `photo` WHERE `uid` = %d $sql_extra AND `album` != '%s' AND `album` != '%s'
60 GROUP BY `resource-id` $sql_extra2",
62 dbesc('Contact Photos'),
63 dbesc( t('Contact Photos'))
66 function _map_files1($rr){
68 $types = Photo::supportedTypes();
69 $ext = $types[$rr['type']];
71 if($a->theme['template_engine'] === 'internal') {
72 $filename_e = template_escape($rr['filename']);
75 $filename_e = $rr['filename'];
78 // Take the largest picture that is smaller or equal 640 pixels
79 $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
80 dbesc($rr['resource-id']));
82 $scale = $p[0]["scale"];
87 App::get_baseurl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
89 App::get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
92 $files = array_map("_map_files1", $r);
94 $tpl = get_markup_template($template_file);
96 $o = replace_macros($tpl, array(
98 '$baseurl' => App::get_baseurl(),
100 '$folders' => $albums,
102 '$cancel' => t('Cancel'),
103 '$nickname' => $a->user['nickname'],
110 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
114 function _map_files2($rr){
116 list($m1,$m2) = explode("/",$rr['filetype']);
117 $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
119 if($a->theme['template_engine'] === 'internal') {
120 $filename_e = template_escape($rr['filename']);
123 $filename_e = $rr['filename'];
126 return array( App::get_baseurl() . '/attach/' . $rr['id'], $filename_e, App::get_baseurl() . '/images/icons/16/' . $filetype . '.png');
128 $files = array_map("_map_files2", $files);
131 $tpl = get_markup_template($template_file);
132 $o = replace_macros($tpl, array(
134 '$baseurl' => App::get_baseurl(),
135 '$path' => array( array( "", t("Files")) ),
138 '$cancel' => t('Cancel'),
139 '$nickname' => $a->user['nickname'],
147 if (x($_GET,'mode')) {