]> git.mxchange.org Git - friendica.git/blob - mod/fbrowser.php
Merge pull request #331 from mexon/upstream
[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 $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                                 return array( 
59                                         $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['hiq'] . '.' .$ext, 
60                                         template_escape($rr['filename']), 
61                                         $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['loq'] . '.'. $ext
62                                 );
63                         }
64                         $files = array_map("files1", $r);
65                         
66                         $tpl = get_markup_template("filebrowser.tpl");
67                         echo replace_macros($tpl, array(
68                                 '$type' => 'image',
69                                 '$baseurl' => $a->get_baseurl(),
70                                 '$path' => $path,
71                                 '$folders' => $albums,
72                                 '$files' =>$files,
73                         ));
74                                 
75                                 
76                         break;
77                 case "file":
78                         if ($a->argc==2){
79                                 $files = q("SELECT id, filename, filetype FROM `attach` WHERE `uid` = %d ",
80                                         intval(local_user())
81                                 );
82                                 
83                                 function files2($rr){ global $a; 
84                                         list($m1,$m2) = explode("/",$rr['filetype']);
85                                         $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
86                                         return array( $a->get_baseurl() . '/attach/' . $rr['id'], template_escape($rr['filename']), $a->get_baseurl() . '/images/icons/16/' . $filetype . '.png'); 
87                                 }
88                                 $files = array_map("files2", $files);
89                                 //echo "<pre>"; var_dump($files); killme();
90                         
91                                                         
92                                 $tpl = get_markup_template("filebrowser.tpl");
93                                 echo replace_macros($tpl, array(
94                                         '$type' => 'file',
95                                         '$baseurl' => $a->get_baseurl(),
96                                         '$path' => array( array($a->get_baseurl()."/fbrowser/image/", t("Files")) ),
97                                         '$folders' => false,
98                                         '$files' =>$files,
99                                 ));
100                                 
101                         }
102                 
103                         break;
104         }
105         
106
107         killme();
108         
109 }