]> git.mxchange.org Git - friendica.git/blob - mod/wall_attach.php
Merge branch 'pull'
[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 * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 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_nick  = $r[0]['nickname'];
25         $community_page   = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
26
27         if((local_user()) && (local_user() == $page_owner_uid))
28                 $can_post = true;
29         else {
30                 if($community_page && remote_user()) {
31                         $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
32                                 intval(remote_user()),
33                                 intval($page_owner_uid)
34                         );
35                         if(count($r)) {
36                                 $can_post = true;
37                                 $visitor = remote_user();
38                         }
39                 }
40         }
41
42         if(! $can_post) {
43                 notice( t('Permission denied.') . EOL );
44                 killme();
45         }
46
47         if(! x($_FILES,'userfile'))
48                 killme();
49
50         $src      = $_FILES['userfile']['tmp_name'];
51         $filename = basename($_FILES['userfile']['name']);
52         $filesize = intval($_FILES['userfile']['size']);
53
54         $maxfilesize = get_config('system','maxfilesize');
55
56         if(($maxfilesize) && ($filesize > $maxfilesize)) {
57                 notice( sprintf(t('File exceeds size limit of %d'), $maxfilesize) . EOL);
58                 @unlink($src);
59                 return;
60         }
61
62         $filedata = @file_get_contents($src);
63         $mimetype = z_mime_content_type($filename);
64         $hash = random_string();
65         $created = datetime_convert();
66         $r = q("INSERT INTO `attach` ( `uid`, `hash`, `filename`, `filetype`, `filesize`, `data`, `created`, `edited`, `allow_cid`, `allow_gid`,`deny_cid`, `deny_gid` )
67                 VALUES ( %d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
68                 intval($page_owner_uid),
69                 dbesc($hash),
70                 dbesc($filename),
71                 dbesc($mimetype),
72                 intval($filesize),
73                 dbesc($filedata),
74                 dbesc($created),
75                 dbesc($created),
76                 dbesc('<' . $page_owner_uid . '>'),
77                 dbesc(''),
78                 dbesc(''),
79                 dbesc('')
80         );              
81
82         @unlink($src);
83
84         if(! $r) {
85                 echo ( t('File upload failed.') . EOL);
86                 killme();
87         }
88
89         $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `created` = '%s' AND `hash` = '%s' LIMIT 1",
90                 intval($page_owner_uid),
91                 dbesc($created),
92                 dbesc($hash)
93         );
94
95         if(! count($r)) {
96                 echo ( t('File upload failed.') . EOL);
97                 killme();
98         }
99
100         echo  '<br /><br />[attachment]' . $r[0]['id'] . '[/attachment]' . '<br />';
101
102         killme();
103         // NOTREACHED
104 }