]> git.mxchange.org Git - friendica.git/blob - mod/fbrowser.php
Merge pull request #1795 from fabrixxm/upload_or_browse_dialog
[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 ",
39                                         intval(local_user())
40                                 );
41                                 // anon functions only from 5.3.0... meglio tardi che mai..
42                                 $folder1 = function($el) use ($mode) {return array(bin2hex($el['album']),$el['album']);};
43                                 $albums = array_map( $folder1 , $albums);
44                                 
45                         }
46                         
47                         $album = "";
48                         if ($a->argc==3){
49                                 $album = hex2bin($a->argv[2]);
50                                 $sql_extra = sprintf("AND `album` = '%s' ",dbesc($album));
51                                 $sql_extra2 = "";
52                                 $path[]=array($a->argv[2], $album);
53                         }
54                                 
55                         $r = q("SELECT `resource-id`, `id`, `filename`, type, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc`  
56                                         FROM `photo` WHERE `uid` = %d AND (height <= 320 AND width <= 320) $sql_extra
57                                         GROUP BY `resource-id` $sql_extra2",
58                                 intval(local_user())                                    
59                         );
60                         
61                         function files1($rr){ 
62                                 global $a;
63                                 $types = Photo::supportedTypes();
64                                 $ext = $types[$rr['type']];
65
66                                 if($a->theme['template_engine'] === 'internal') {
67                                         $filename_e = template_escape($rr['filename']);
68                                 }
69                                 else {
70                                         $filename_e = $rr['filename'];
71                                 }
72
73                                 return array( 
74                                         $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['hiq'] . '.' .$ext, 
75                                         $filename_e, 
76                                         $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['loq'] . '.'. $ext
77                                 );
78                         }
79                         $files = array_map("files1", $r);
80                         
81                         $tpl = get_markup_template($template_file);
82                         
83                         $o =  replace_macros($tpl, array(
84                                 '$type' => 'image',
85                                 '$baseurl' => $a->get_baseurl(),
86                                 '$path' => $path,
87                                 '$folders' => $albums,
88                                 '$files' =>$files,
89                                 '$cancel' => t('Cancel'),
90                                 '$nickname' => $a->user['nickname'],
91                         ));
92                                 
93                                 
94                         break;
95                 case "file":
96                         if ($a->argc==2){
97                                 $files = q("SELECT id, filename, filetype FROM `attach` WHERE `uid` = %d ",
98                                         intval(local_user())
99                                 );
100                                 
101                                 function files2($rr){ global $a; 
102                                         list($m1,$m2) = explode("/",$rr['filetype']);
103                                         $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
104
105                                         if($a->theme['template_engine'] === 'internal') {
106                                                 $filename_e = template_escape($rr['filename']);
107                                         }
108                                         else {
109                                                 $filename_e = $rr['filename'];
110                                         }
111
112                                         return array( $a->get_baseurl() . '/attach/' . $rr['id'], $filename_e, $a->get_baseurl() . '/images/icons/16/' . $filetype . '.png'); 
113                                 }
114                                 $files = array_map("files2", $files);
115                                 //echo "<pre>"; var_dump($files); killme();
116                         
117                                                         
118                                 $tpl = get_markup_template($template_file);
119                                 $o = replace_macros($tpl, array(
120                                         '$type' => 'file',
121                                         '$baseurl' => $a->get_baseurl(),
122                                         '$path' => array( array( "", t("Files")) ),
123                                         '$folders' => false,
124                                         '$files' =>$files,
125                                         '$cancel' => t('Cancel'),
126                                         '$nickname' => $a->user['nickname'],
127                                 ));
128                                 
129                         }
130                 
131                         break;
132         }
133         
134         if (x($_GET,'mode')) {
135                 return $o;
136         } else {
137                 echo $o;
138                 killme();
139         }
140         
141         
142 }