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']];
73 if($a->theme['template_engine'] === 'internal') {
74 $filename_e = template_escape($rr['filename']);
77 $filename_e = $rr['filename'];
80 // Take the largest picture that is smaller or equal 640 pixels
81 $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
82 dbesc($rr['resource-id']));
84 $scale = $p[0]["scale"];
89 System::baseUrl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
91 System::baseUrl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
94 $files = array_map("_map_files1", $r);
96 $tpl = get_markup_template($template_file);
98 $o = replace_macros($tpl, array(
100 '$baseurl' => System::baseUrl(),
102 '$folders' => $albums,
104 '$cancel' => t('Cancel'),
105 '$nickname' => $a->user['nickname'],
112 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
116 function _map_files2($rr){
118 list($m1,$m2) = explode("/",$rr['filetype']);
119 $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
121 if ($a->theme['template_engine'] === 'internal') {
122 $filename_e = template_escape($rr['filename']);
124 $filename_e = $rr['filename'];
127 return array( System::baseUrl() . '/attach/' . $rr['id'], $filename_e, System::baseUrl() . '/images/icons/16/' . $filetype . '.png');
129 $files = array_map("_map_files2", $files);
132 $tpl = get_markup_template($template_file);
133 $o = replace_macros($tpl, array(
135 '$baseurl' => System::baseUrl(),
136 '$path' => array( array( "", t("Files")) ),
139 '$cancel' => t('Cancel'),
140 '$nickname' => $a->user['nickname'],
148 if (x($_GET,'mode')) {