]> git.mxchange.org Git - friendica.git/blob - mod/fbrowser.php
Merge pull request #2166 from rabuzarus/1012_vier-forum
[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($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                                 global $a;
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                                 return array(
78                                         $a->get_baseurl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
79                                         $filename_e,
80                                         $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['loq'] . '.'. $ext
81                                 );
82                         }
83                         $files = array_map("_map_files1", $r);
84
85                         $tpl = get_markup_template($template_file);
86
87                         $o =  replace_macros($tpl, array(
88                                 '$type' => 'image',
89                                 '$baseurl' => $a->get_baseurl(),
90                                 '$path' => $path,
91                                 '$folders' => $albums,
92                                 '$files' =>$files,
93                                 '$cancel' => t('Cancel'),
94                                 '$nickname' => $a->user['nickname'],
95                         ));
96
97
98                         break;
99                 case "file":
100                         if ($a->argc==2){
101                                 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
102                                         intval(local_user())
103                                 );
104
105                                 function _map_files2($rr){ global $a;
106                                         list($m1,$m2) = explode("/",$rr['filetype']);
107                                         $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
108
109                                         if($a->theme['template_engine'] === 'internal') {
110                                                 $filename_e = template_escape($rr['filename']);
111                                         }
112                                         else {
113                                                 $filename_e = $rr['filename'];
114                                         }
115
116                                         return array( $a->get_baseurl() . '/attach/' . $rr['id'], $filename_e, $a->get_baseurl() . '/images/icons/16/' . $filetype . '.png');
117                                 }
118                                 $files = array_map("_map_files2", $files);
119
120
121                                 $tpl = get_markup_template($template_file);
122                                 $o = replace_macros($tpl, array(
123                                         '$type' => 'file',
124                                         '$baseurl' => $a->get_baseurl(),
125                                         '$path' => array( array( "", t("Files")) ),
126                                         '$folders' => false,
127                                         '$files' =>$files,
128                                         '$cancel' => t('Cancel'),
129                                         '$nickname' => $a->user['nickname'],
130                                 ));
131
132                         }
133
134                         break;
135         }
136
137         if (x($_GET,'mode')) {
138                 return $o;
139         } else {
140                 echo $o;
141                 killme();
142         }
143
144
145 }