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