3 * @package Friendica\modules
4 * @subpackage FileBrowser
5 * @author Fabio Comuni <fabrixxm@kirgroup.com>
9 use Friendica\Core\System;
11 require_once('include/Photo.php');
16 function fbrowser_content(App $a) {
26 $template_file = "filebrowser.tpl";
28 if (x($_GET,'mode')) {
29 $mode = "?mode=".$_GET['mode'];
32 switch ($a->argv[1]) {
34 $path = array(array("", t("Photos")));
37 $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
40 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
42 dbesc('Contact Photos'),
43 dbesc( t('Contact Photos'))
46 function _map_folder1($el){return array(bin2hex($el['album']),$el['album']);};
47 $albums = array_map( "_map_folder1" , $albums);
53 $album = hex2bin($a->argv[2]);
54 $sql_extra = sprintf("AND `album` = '%s' ",dbesc($album));
56 $path[]=array($a->argv[2], $album);
59 $r = q("SELECT `resource-id`, `id`, `filename`, type, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc`
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 = Photo::supportedTypes();
70 $ext = $types[$rr['type']];
72 if($a->theme['template_engine'] === 'internal') {
73 $filename_e = template_escape($rr['filename']);
76 $filename_e = $rr['filename'];
79 // Take the largest picture that is smaller or equal 640 pixels
80 $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
81 dbesc($rr['resource-id']));
83 $scale = $p[0]["scale"];
88 System::baseUrl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
90 System::baseUrl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
93 $files = array_map("_map_files1", $r);
95 $tpl = get_markup_template($template_file);
97 $o = replace_macros($tpl, array(
99 '$baseurl' => System::baseUrl(),
101 '$folders' => $albums,
103 '$cancel' => t('Cancel'),
104 '$nickname' => $a->user['nickname'],
111 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
115 function _map_files2($rr){
117 list($m1,$m2) = explode("/",$rr['filetype']);
118 $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
120 if ($a->theme['template_engine'] === 'internal') {
121 $filename_e = template_escape($rr['filename']);
123 $filename_e = $rr['filename'];
126 return array( System::baseUrl() . '/attach/' . $rr['id'], $filename_e, System::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' => System::baseUrl(),
135 '$path' => array( array( "", t("Files")) ),
138 '$cancel' => t('Cancel'),
139 '$nickname' => $a->user['nickname'],
147 if (x($_GET,'mode')) {