]> git.mxchange.org Git - friendica.git/blob - mod/fbrowser.php
Merge pull request #3036 from Quix0r/rewrites/app_get_baseurl_static
[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 /// @TODO & is missing or App ?
14 function fbrowser_content($a){
15
16         if (!local_user())
17                 killme();
18
19         if ($a->argc==1)
20                 killme();
21
22         $template_file = "filebrowser.tpl";
23         $mode = "";
24         if (x($_GET,'mode')) {
25                 $template_file = "filebrowser_plain.tpl";
26                 $mode  = "?mode=".$_GET['mode'];
27         }
28
29         //echo "<pre>"; var_dump($a->argv); killme();
30
31         switch($a->argv[1]){
32                 case "image":
33                         $path = array( array("", t("Photos")));
34                         $albums = false;
35                         $sql_extra = "";
36                         $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
37
38                         if ($a->argc==2){
39                                 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
40                                         intval(local_user()),
41                                         dbesc('Contact Photos'),
42                                         dbesc( t('Contact Photos'))
43                                 );
44
45                                 function _map_folder1($el){return array(bin2hex($el['album']),$el['album']);};
46                                 $albums = array_map( "_map_folder1" , $albums);
47
48                         }
49
50                         $album = "";
51                         if ($a->argc==3){
52                                 $album = hex2bin($a->argv[2]);
53                                 $sql_extra = sprintf("AND `album` = '%s' ",dbesc($album));
54                                 $sql_extra2 = "";
55                                 $path[]=array($a->argv[2], $album);
56                         }
57
58                         $r = q("SELECT `resource-id`, `id`, `filename`, type, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc`
59                                         FROM `photo` WHERE `uid` = %d $sql_extra AND `album` != '%s' AND `album` != '%s'
60                                         GROUP BY `resource-id` $sql_extra2",
61                                 intval(local_user()),
62                                 dbesc('Contact Photos'),
63                                 dbesc( t('Contact Photos'))
64                         );
65
66                         function _map_files1($rr){
67                                 $a = get_app();
68                                 $types = Photo::supportedTypes();
69                                 $ext = $types[$rr['type']];
70
71                                 if($a->theme['template_engine'] === 'internal') {
72                                         $filename_e = template_escape($rr['filename']);
73                                 }
74                                 else {
75                                         $filename_e = $rr['filename'];
76                                 }
77
78                                 // Take the largest picture that is smaller or equal 640 pixels
79                                 $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
80                                         dbesc($rr['resource-id']));
81                                 if ($p)
82                                         $scale = $p[0]["scale"];
83                                 else
84                                         $scale = $rr['loq'];
85
86                                 return array(
87                                         App::get_baseurl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
88                                         $filename_e,
89                                         App::get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
90                                 );
91                         }
92                         $files = array_map("_map_files1", $r);
93
94                         $tpl = get_markup_template($template_file);
95
96                         $o =  replace_macros($tpl, array(
97                                 '$type'     => 'image',
98                                 '$baseurl'  => App::get_baseurl(),
99                                 '$path'     => $path,
100                                 '$folders'  => $albums,
101                                 '$files'    => $files,
102                                 '$cancel'   => t('Cancel'),
103                                 '$nickname' => $a->user['nickname'],
104                         ));
105
106
107                         break;
108                 case "file":
109                         if ($a->argc==2) {
110                                 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
111                                         intval(local_user())
112                                 );
113
114                                 function _map_files2($rr){
115                                         $a = get_app();
116                                         list($m1,$m2) = explode("/",$rr['filetype']);
117                                         $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
118
119                                         if ($a->theme['template_engine'] === 'internal') {
120                                                 $filename_e = template_escape($rr['filename']);
121                                         } else {
122                                                 $filename_e = $rr['filename'];
123                                         }
124
125                                         return array( App::get_baseurl() . '/attach/' . $rr['id'], $filename_e, App::get_baseurl() . '/images/icons/16/' . $filetype . '.png');
126                                 }
127                                 $files = array_map("_map_files2", $files);
128
129
130                                 $tpl = get_markup_template($template_file);
131                                 $o = replace_macros($tpl, array(
132                                         '$type'     => 'file',
133                                         '$baseurl'  => App::get_baseurl(),
134                                         '$path'     => array( array( "", t("Files")) ),
135                                         '$folders'  => false,
136                                         '$files'    =>$files,
137                                         '$cancel'   => t('Cancel'),
138                                         '$nickname' => $a->user['nickname'],
139                                 ));
140
141                         }
142
143                         break;
144         }
145
146         if (x($_GET,'mode')) {
147                 return $o;
148         } else {
149                 echo $o;
150                 killme();
151         }
152
153
154 }