3 require_once('include/attach.php');
4 require_once('include/datetime.php');
6 function wall_attach_post(&$a) {
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",
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);
28 if((local_user()) && (local_user() == $page_owner_uid))
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)
38 $visitor = remote_user();
44 notice( t('Permission denied.') . EOL );
48 if(! x($_FILES,'userfile'))
51 $src = $_FILES['userfile']['tmp_name'];
52 $filename = basename($_FILES['userfile']['name']);
53 $filesize = intval($_FILES['userfile']['size']);
55 $maxfilesize = get_config('system','maxfilesize');
57 if(($maxfilesize) && ($filesize > $maxfilesize)) {
58 notice( sprintf(t('File exceeds size limit of %d'), $maxfilesize) . EOL);
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),
77 dbesc('<' . $page_owner_cid . '>'),
86 echo ( t('File upload failed.') . EOL);
90 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `created` = '%s' AND `hash` = '%s' LIMIT 1",
91 intval($page_owner_uid),
97 echo ( t('File upload failed.') . EOL);
103 if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
106 echo $lf . $lf . '[attachment]' . $r[0]['id'] . '[/attachment]' . $lf;