]> git.mxchange.org Git - friendica.git/blob - mod/fbrowser.php
Bugfix: The user id wasn't fetched correctly.
[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         //echo "<pre>"; var_dump($a->argv); killme();   
22         
23         switch($a->argv[1]){
24                 case "image":
25                         $path = array( array($a->get_baseurl()."/fbrowser/image/", t("Photos")));
26                         $albums = false;
27                         $sql_extra = "";
28                         $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
29                         
30                         if ($a->argc==2){
31                                 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d ",
32                                         intval(local_user())
33                                 );
34                                 // anon functions only from 5.3.0... meglio tardi che mai..
35                                 function folder1($el){return array(bin2hex($el['album']),$el['album']);}        
36                                 $albums = array_map( "folder1" , $albums);
37                                 
38                         }
39                         
40                         $album = "";
41                         if ($a->argc==3){
42                                 $album = hex2bin($a->argv[2]);
43                                 $sql_extra = sprintf("AND `album` = '%s' ",dbesc($album));
44                                 $sql_extra2 = "";
45                                 $path[]=array($a->get_baseurl()."/fbrowser/image/".$a->argv[2]."/", $album);
46                         }
47                                 
48                         $r = q("SELECT `resource-id`, `id`, `filename`, type, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc`  
49                                         FROM `photo` WHERE `uid` = %d AND (height <= 320 AND width <= 320) $sql_extra
50                                         GROUP BY `resource-id` $sql_extra2",
51                                 intval(local_user())                                    
52                         );
53                         
54                         function files1($rr){ 
55                                 global $a;
56                                 $types = Photo::supportedTypes();
57                                 $ext = $types[$rr['type']];
58
59                                 if($a->theme['template_engine'] === 'internal') {
60                                         $filename_e = template_escape($rr['filename']);
61                                 }
62                                 else {
63                                         $filename_e = $rr['filename'];
64                                 }
65
66                                 return array( 
67                                         $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['hiq'] . '.' .$ext, 
68                                         $filename_e, 
69                                         $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['loq'] . '.'. $ext
70                                 );
71                         }
72                         $files = array_map("files1", $r);
73                         
74                         $tpl = get_markup_template("filebrowser.tpl");
75                         echo replace_macros($tpl, array(
76                                 '$type' => 'image',
77                                 '$baseurl' => $a->get_baseurl(),
78                                 '$path' => $path,
79                                 '$folders' => $albums,
80                                 '$files' =>$files,
81                                 '$cancel' => t('Cancel'),
82                         ));
83                                 
84                                 
85                         break;
86                 case "file":
87                         if ($a->argc==2){
88                                 $files = q("SELECT id, filename, filetype FROM `attach` WHERE `uid` = %d ",
89                                         intval(local_user())
90                                 );
91                                 
92                                 function files2($rr){ global $a; 
93                                         list($m1,$m2) = explode("/",$rr['filetype']);
94                                         $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
95
96                                         if($a->theme['template_engine'] === 'internal') {
97                                                 $filename_e = template_escape($rr['filename']);
98                                         }
99                                         else {
100                                                 $filename_e = $rr['filename'];
101                                         }
102
103                                         return array( $a->get_baseurl() . '/attach/' . $rr['id'], $filename_e, $a->get_baseurl() . '/images/icons/16/' . $filetype . '.png'); 
104                                 }
105                                 $files = array_map("files2", $files);
106                                 //echo "<pre>"; var_dump($files); killme();
107                         
108                                                         
109                                 $tpl = get_markup_template("filebrowser.tpl");
110                                 echo replace_macros($tpl, array(
111                                         '$type' => 'file',
112                                         '$baseurl' => $a->get_baseurl(),
113                                         '$path' => array( array($a->get_baseurl()."/fbrowser/image/", t("Files")) ),
114                                         '$folders' => false,
115                                         '$files' =>$files,
116                                         '$cancel' => t('Cancel'),
117                                 ));
118                                 
119                         }
120                 
121                         break;
122         }
123         
124
125         killme();
126         
127 }