]> git.mxchange.org Git - friendica.git/blob - mod/fbrowser.php
Merge branch 'develop' into rewrites/dbm_is_result
[friendica.git] / mod / fbrowser.php
1 <?php
2 /**
3  * @package             Friendica\modules
4  * @subpackage  FileBrowser
5  * @author              Fabio Comuni <fabrixxm@kirgroup.com>
6  */
7
8 require_once('include/Photo.php');
9
10 /**
11  * @param App $a
12  */
13 function fbrowser_content(App &$a){
14
15         if (!local_user())
16                 killme();
17
18         if ($a->argc==1)
19                 killme();
20
21         $template_file = "filebrowser.tpl";
22         $mode = "";
23         if (x($_GET,'mode')) {
24                 $template_file = "filebrowser_plain.tpl";
25                 $mode  = "?mode=".$_GET['mode'];
26         }
27
28         //echo "<pre>"; var_dump($a->argv); killme();
29
30         switch($a->argv[1]){
31                 case "image":
32                         $path = array( array("", t("Photos")));
33                         $albums = false;
34                         $sql_extra = "";
35                         $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
36
37                         if ($a->argc==2){
38                                 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
39                                         intval(local_user()),
40                                         dbesc('Contact Photos'),
41                                         dbesc( t('Contact Photos'))
42                                 );
43
44                                 function _map_folder1($el){return array(bin2hex($el['album']),$el['album']);};
45                                 $albums = array_map( "_map_folder1" , $albums);
46
47                         }
48
49                         $album = "";
50                         if ($a->argc==3){
51                                 $album = hex2bin($a->argv[2]);
52                                 $sql_extra = sprintf("AND `album` = '%s' ",dbesc($album));
53                                 $sql_extra2 = "";
54                                 $path[]=array($a->argv[2], $album);
55                         }
56
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",
60                                 intval(local_user()),
61                                 dbesc('Contact Photos'),
62                                 dbesc( t('Contact Photos'))
63                         );
64
65                         function _map_files1($rr){
66                                 $a = get_app();
67                                 $types = Photo::supportedTypes();
68                                 $ext = $types[$rr['type']];
69
70                                 if($a->theme['template_engine'] === 'internal') {
71                                         $filename_e = template_escape($rr['filename']);
72                                 }
73                                 else {
74                                         $filename_e = $rr['filename'];
75                                 }
76
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']));
80                                 if ($p)
81                                         $scale = $p[0]["scale"];
82                                 else
83                                         $scale = $rr['loq'];
84
85                                 return array(
86                                         App::get_baseurl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
87                                         $filename_e,
88                                         App::get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
89                                 );
90                         }
91                         $files = array_map("_map_files1", $r);
92
93                         $tpl = get_markup_template($template_file);
94
95                         $o =  replace_macros($tpl, array(
96                                 '$type' => 'image',
97                                 '$baseurl' => App::get_baseurl(),
98                                 '$path' => $path,
99                                 '$folders' => $albums,
100                                 '$files' =>$files,
101                                 '$cancel' => t('Cancel'),
102                                 '$nickname' => $a->user['nickname'],
103                         ));
104
105
106                         break;
107                 case "file":
108                         if ($a->argc==2){
109                                 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
110                                         intval(local_user())
111                                 );
112
113                                 function _map_files2($rr){
114                                         $a = get_app();
115                                         list($m1,$m2) = explode("/",$rr['filetype']);
116                                         $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
117
118                                         if($a->theme['template_engine'] === 'internal') {
119                                                 $filename_e = template_escape($rr['filename']);
120                                         }
121                                         else {
122                                                 $filename_e = $rr['filename'];
123                                         }
124
125                                         return array( App::get_baseurl() . '/attach/' . $rr['id'], $filename_e, App::get_baseurl() . '/images/icons/16/' . $filetype . '.png');
126                                 }
127                                 $files = array_map("_map_files2", $files);
128
129
130                                 $tpl = get_markup_template($template_file);
131                                 $o = replace_macros($tpl, array(
132                                         '$type' => 'file',
133                                         '$baseurl' => App::get_baseurl(),
134                                         '$path' => array( array( "", t("Files")) ),
135                                         '$folders' => false,
136                                         '$files' =>$files,
137                                         '$cancel' => t('Cancel'),
138                                         '$nickname' => $a->user['nickname'],
139                                 ));
140
141                         }
142
143                         break;
144         }
145
146         if (x($_GET,'mode')) {
147                 return $o;
148         } else {
149                 echo $o;
150                 killme();
151         }
152
153
154 }