]> git.mxchange.org Git - friendica.git/blob - mod/fbrowser.php
Merge branch 'master', remote-tracking branch 'remotes/upstream/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 /**
9  * @param App $a
10  */
11 function fbrowser_content($a){
12         
13         if (!local_user())
14                 killme();
15
16         if ($a->argc==1)
17                 killme();
18         
19         //echo "<pre>"; var_dump($a->argv); killme();   
20         
21         switch($a->argv[1]){
22                 case "image":
23                         $path = array( array($a->get_baseurl()."/fbrowser/image/", t("Photos")));
24                         $albums = false;
25                         $sql_extra = "";
26                         $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
27                         
28                         if ($a->argc==2){
29                                 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d ",
30                                         intval(local_user())
31                                 );
32                                 // anon functions only from 5.3.0... meglio tardi che mai..
33                                 function folder1($el){return array(bin2hex($el['album']),$el['album']);}        
34                                 $albums = array_map( "folder1" , $albums);
35                                 
36                         }
37                         
38                         $album = "";
39                         if ($a->argc==3){
40                                 $album = hex2bin($a->argv[2]);
41                                 $sql_extra = sprintf("AND `album` = '%s' ",dbesc($album));
42                                 $sql_extra2 = "";
43                                 $path[]=array($a->get_baseurl()."/fbrowser/image/".$a->argv[2]."/", $album);
44                         }
45                                 
46                         $r = q("SELECT `resource-id`, `id`, `filename`, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc`  
47                                         FROM `photo` WHERE `uid` = %d $sql_extra
48                                         GROUP BY `resource-id` $sql_extra2",
49                                 intval(local_user())                                    
50                         );
51                         
52                         
53                         function files1($rr){ global $a; return array( $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['hiq'] . '.jpg', template_escape($rr['filename']), $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['loq'] . '.jpg');  }
54                         $files = array_map("files1", $r);
55                         
56                         $tpl = get_markup_template("filebrowser.tpl");
57                         echo replace_macros($tpl, array(
58                                 '$type' => 'image',
59                                 '$baseurl' => $a->get_baseurl(),
60                                 '$path' => $path,
61                                 '$folders' => $albums,
62                                 '$files' =>$files,
63                         ));
64                                 
65                                 
66                         break;
67                 case "file":
68                         if ($a->argc==2){
69                                 $files = q("SELECT id, filename, filetype FROM `attach` WHERE `uid` = %d ",
70                                         intval(local_user())
71                                 );
72                                 
73                                 function files2($rr){ global $a; 
74                                         list($m1,$m2) = explode("/",$rr['filetype']);
75                                         $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
76                                         return array( $a->get_baseurl() . '/attach/' . $rr['id'], template_escape($rr['filename']), $a->get_baseurl() . '/images/icons/16/' . $filetype . '.png'); 
77                                 }
78                                 $files = array_map("files2", $files);
79                                 //echo "<pre>"; var_dump($files); killme();
80                         
81                                                         
82                                 $tpl = get_markup_template("filebrowser.tpl");
83                                 echo replace_macros($tpl, array(
84                                         '$type' => 'file',
85                                         '$baseurl' => $a->get_baseurl(),
86                                         '$path' => array( array($a->get_baseurl()."/fbrowser/image/", t("Files")) ),
87                                         '$folders' => false,
88                                         '$files' =>$files,
89                                 ));
90                                 
91                         }
92                 
93                         break;
94         }
95         
96
97         killme();
98         
99 }