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`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`,
60 min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created`
61 FROM `photo` WHERE `uid` = %d $sql_extra AND `album` != '%s' AND `album` != '%s'
62 GROUP BY `resource-id` $sql_extra2",
64 dbesc('Contact Photos'),
65 dbesc( t('Contact Photos'))
68 function _map_files1($rr){
70 $types = Photo::supportedTypes();
71 $ext = $types[$rr['type']];
72 $filename_e = $rr['filename'];
74 // Take the largest picture that is smaller or equal 640 pixels
75 $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
76 dbesc($rr['resource-id']));
78 $scale = $p[0]["scale"];
83 System::baseUrl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
85 System::baseUrl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
88 $files = array_map("_map_files1", $r);
90 $tpl = get_markup_template($template_file);
92 $o = replace_macros($tpl, array(
94 '$baseurl' => System::baseUrl(),
96 '$folders' => $albums,
98 '$cancel' => t('Cancel'),
99 '$nickname' => $a->user['nickname'],
106 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
110 function _map_files2($rr){
112 list($m1,$m2) = explode("/",$rr['filetype']);
113 $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
114 $filename_e = $rr['filename'];
116 return array(System::baseUrl() . '/attach/' . $rr['id'], $filename_e, System::baseUrl() . '/images/icons/16/' . $filetype . '.png');
118 $files = array_map("_map_files2", $files);
121 $tpl = get_markup_template($template_file);
122 $o = replace_macros($tpl, array(
124 '$baseurl' => System::baseUrl(),
125 '$path' => array( array( "", t("Files")) ),
128 '$cancel' => t('Cancel'),
129 '$nickname' => $a->user['nickname'],
137 if (x($_GET,'mode')) {