]> git.mxchange.org Git - friendica.git/blob - mod/fbrowser.php
filebrowser: more style, load min and max scale photos
[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                         if ($a->argc==2){
26                                 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d ",
27                                         intval(local_user())
28                                 );
29                                 // anon functions only from 5.3.0... meglio tardi che mai..
30                                 function folder1($el){return array(bin2hex($el['album']),$el['album']);}        
31                                 $albums = array_map( "folder1" , $albums);
32                                 
33                         }
34                         
35                         $album = "";
36                         if ($a->argc==3){
37                                 $album = hex2bin($a->argv[2]);
38                                 $sql_extra = sprintf("AND `album` = '%s' ",dbesc($album));
39                                 $path[]=array($a->get_baseurl()."/fbrowser/image/".$a->argv[2]."/", $album);
40                         }
41                                 
42                         $r = q("SELECT `resource-id`, `id`, `filename`, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc`  FROM `photo` WHERE `uid` = %d $sql_extra
43                                 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
44                                 intval(local_user())                                    
45                         );
46                         
47                         
48                         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');  }
49                         $files = array_map("files1", $r);
50                         
51                         $tpl = get_markup_template("filebrowser.tpl");
52                         echo replace_macros($tpl, array(
53                                 '$type' => 'image',
54                                 '$baseurl' => $a->get_baseurl(),
55                                 '$path' => $path,
56                                 '$folders' => $albums,
57                                 '$files' =>$files,
58                         ));
59                                 
60                                 
61                         break;
62                 case "file":
63                         if ($a->argc==2){
64                                 $files = q("SELECT id, filename, filetype FROM `attach` WHERE `uid` = %d ",
65                                         intval(local_user())
66                                 );
67                                 
68                                 function files2($rr){ global $a; 
69                                         list($m1,$m2) = explode("/",$rr['filetype']);
70                                         $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
71                                         return array( $a->get_baseurl() . '/attach/' . $rr['id'], template_escape($rr['filename']), $a->get_baseurl() . '/images/icons/16/' . $filetype . '.png'); 
72                                 }
73                                 $files = array_map("files2", $files);
74                                 //echo "<pre>"; var_dump($files); killme();
75                         
76                                                         
77                                 $tpl = get_markup_template("filebrowser.tpl");
78                                 echo replace_macros($tpl, array(
79                                         '$type' => 'file',
80                                         '$baseurl' => $a->get_baseurl(),
81                                         '$path' => array( array($a->get_baseurl()."/fbrowser/image/", t("Files")) ),
82                                         '$folders' => false,
83                                         '$files' =>$files,
84                                 ));
85                                 
86                         }
87                 
88                         break;
89         }
90         
91
92         killme();
93         
94 }