]> git.mxchange.org Git - friendica.git/blob - mod/wall_attach.php
Some Bugfixes, and variable checks
[friendica.git] / mod / wall_attach.php
1 <?php
2
3 require_once('include/attach.php');
4 require_once('include/datetime.php');
5
6 function wall_attach_post(&$a) {
7
8         if($a->argc > 1) {
9                 $nick = $a->argv[1];
10                 $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT JOIN `contact` on `user`.`uid` = `contact`.`uid`  WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1",
11                         dbesc($nick)
12                 );
13                 if(! count($r))
14                         return;
15
16         }
17         else
18                 return;
19
20         $can_post  = false;
21         $visitor   = 0;
22
23         $page_owner_uid   = $r[0]['uid'];
24         $page_owner_cid   = $r[0]['id'];
25         $page_owner_nick  = $r[0]['nickname'];
26         $community_page   = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
27
28         if((local_user()) && (local_user() == $page_owner_uid))
29                 $can_post = true;
30         else {
31                 if($community_page && remote_user()) {
32                         $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
33                                 intval(remote_user()),
34                                 intval($page_owner_uid)
35                         );
36                         if(count($r)) {
37                                 $can_post = true;
38                                 $visitor = remote_user();
39                         }
40                 }
41         }
42
43         if(! $can_post) {
44                 notice( t('Permission denied.') . EOL );
45                 killme();
46         }
47
48         if(! x($_FILES,'userfile'))
49                 killme();
50
51         $src      = $_FILES['userfile']['tmp_name'];
52         $filename = basename($_FILES['userfile']['name']);
53         $filesize = intval($_FILES['userfile']['size']);
54
55         $maxfilesize = get_config('system','maxfilesize');
56
57         if(($maxfilesize) && ($filesize > $maxfilesize)) {
58                 notice( sprintf(t('File exceeds size limit of %d'), $maxfilesize) . EOL);
59                 @unlink($src);
60                 return;
61         }
62
63         $filedata = @file_get_contents($src);
64         $mimetype = z_mime_content_type($filename);
65         $hash = random_string();
66         $created = datetime_convert();
67         $r = q("INSERT INTO `attach` ( `uid`, `hash`, `filename`, `filetype`, `filesize`, `data`, `created`, `edited`, `allow_cid`, `allow_gid`,`deny_cid`, `deny_gid` )
68                 VALUES ( %d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
69                 intval($page_owner_uid),
70                 dbesc($hash),
71                 dbesc($filename),
72                 dbesc($mimetype),
73                 intval($filesize),
74                 dbesc($filedata),
75                 dbesc($created),
76                 dbesc($created),
77                 dbesc('<' . $page_owner_cid . '>'),
78                 dbesc(''),
79                 dbesc(''),
80                 dbesc('')
81         );              
82
83         @unlink($src);
84
85         if(! $r) {
86                 echo ( t('File upload failed.') . EOL);
87                 killme();
88         }
89
90         $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `created` = '%s' AND `hash` = '%s' LIMIT 1",
91                 intval($page_owner_uid),
92                 dbesc($created),
93                 dbesc($hash)
94         );
95
96         if(! count($r)) {
97                 echo ( t('File upload failed.') . EOL);
98                 killme();
99         }
100
101         echo  '<br /><br />[attachment]' . $r[0]['id'] . '[/attachment]' . '<br />';
102
103         killme();
104         // NOTREACHED
105 }