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