3 require_once('include/attach.php');
4 require_once('include/datetime.php');
6 function wall_attach_post(&$a) {
10 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
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);
27 if((local_user()) && (local_user() == $page_owner_uid))
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)
37 $visitor = remote_user();
43 notice( t('Permission denied.') . EOL );
47 if(! x($_FILES,'userfile'))
50 $src = $_FILES['userfile']['tmp_name'];
51 $filename = basename($_FILES['userfile']['name']);
52 $filesize = intval($_FILES['userfile']['size']);
54 $maxfilesize = get_config('system','maxfilesize');
56 if(($maxfilesize) && ($filesize > $maxfilesize)) {
57 notice( sprintf(t('File exceeds size limit of %d'), $maxfilesize) . EOL);
62 $filedata = @file_get_contents($src);
64 $mimetype = mime_content_type($src);
65 $hash = random_string();
66 $created = datetime_convert();
68 $r = q("INSERT INTO `attach` ( `uid`, `hash`, `filename`, `filetype`, `filesize`, `data`, `created`, `edited`, `allow_cid`, `allow_gid`,`deny_cid`, `deny_gid` )
69 VALUES ( %d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
70 intval($page_owner_uid),
78 dbesc('<' . $page_owner_uid . '>'),
87 echo ( t('File upload failed.') . EOL);
91 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `created` = '%s' AND `hash` = '%s' LIMIT 1",
92 intval($page_owner_uid),
98 echo ( t('File upload failed.') . EOL);
102 echo '<br /><br />[attachment]' . $r[0]['id'] . '[/attachment]' . '<br />';