]> git.mxchange.org Git - friendica.git/blob - mod/fbrowser.php
Merge develop into 0602_contact_profile
[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 if(! function_exists('fbrowser_content')) {
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                                 global $a;
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                                 return array(
79                                         $a->get_baseurl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
80                                         $filename_e,
81                                         $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['loq'] . '.'. $ext
82                                 );
83                         }
84                         $files = array_map("_map_files1", $r);
85
86                         $tpl = get_markup_template($template_file);
87
88                         $o =  replace_macros($tpl, array(
89                                 '$type' => 'image',
90                                 '$baseurl' => $a->get_baseurl(),
91                                 '$path' => $path,
92                                 '$folders' => $albums,
93                                 '$files' =>$files,
94                                 '$cancel' => t('Cancel'),
95                                 '$nickname' => $a->user['nickname'],
96                         ));
97
98
99                         break;
100                 case "file":
101                         if ($a->argc==2){
102                                 $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
103                                         intval(local_user())
104                                 );
105
106                                 function _map_files2($rr){ global $a;
107                                         list($m1,$m2) = explode("/",$rr['filetype']);
108                                         $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
109
110                                         if($a->theme['template_engine'] === 'internal') {
111                                                 $filename_e = template_escape($rr['filename']);
112                                         }
113                                         else {
114                                                 $filename_e = $rr['filename'];
115                                         }
116
117                                         return array( $a->get_baseurl() . '/attach/' . $rr['id'], $filename_e, $a->get_baseurl() . '/images/icons/16/' . $filetype . '.png');
118                                 }
119                                 $files = array_map("_map_files2", $files);
120
121
122                                 $tpl = get_markup_template($template_file);
123                                 $o = replace_macros($tpl, array(
124                                         '$type' => 'file',
125                                         '$baseurl' => $a->get_baseurl(),
126                                         '$path' => array( array( "", t("Files")) ),
127                                         '$folders' => false,
128                                         '$files' =>$files,
129                                         '$cancel' => t('Cancel'),
130                                         '$nickname' => $a->user['nickname'],
131                                 ));
132
133                         }
134
135                         break;
136         }
137
138         if (x($_GET,'mode')) {
139                 return $o;
140         } else {
141                 echo $o;
142                 killme();
143         }
144
145 }
146 }