]> git.mxchange.org Git - friendica.git/blob - mod/fbrowser.php
Merge pull request #555 from annando/master
[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                         ));
82                                 
83                                 
84                         break;
85                 case "file":
86                         if ($a->argc==2){
87                                 $files = q("SELECT id, filename, filetype FROM `attach` WHERE `uid` = %d ",
88                                         intval(local_user())
89                                 );
90                                 
91                                 function files2($rr){ global $a; 
92                                         list($m1,$m2) = explode("/",$rr['filetype']);
93                                         $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
94
95                                         if($a->theme['template_engine'] === 'internal') {
96                                                 $filename_e = template_escape($rr['filename']);
97                                         }
98                                         else {
99                                                 $filename_e = $rr['filename'];
100                                         }
101
102                                         return array( $a->get_baseurl() . '/attach/' . $rr['id'], $filename_e, $a->get_baseurl() . '/images/icons/16/' . $filetype . '.png'); 
103                                 }
104                                 $files = array_map("files2", $files);
105                                 //echo "<pre>"; var_dump($files); killme();
106                         
107                                                         
108                                 $tpl = get_markup_template("filebrowser.tpl");
109                                 echo replace_macros($tpl, array(
110                                         '$type' => 'file',
111                                         '$baseurl' => $a->get_baseurl(),
112                                         '$path' => array( array($a->get_baseurl()."/fbrowser/image/", t("Files")) ),
113                                         '$folders' => false,
114                                         '$files' =>$files,
115                                 ));
116                                 
117                         }
118                 
119                         break;
120         }
121         
122
123         killme();
124         
125 }