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()) {
33 if(is_array($_SESSION['remote'])) {
34 foreach($_SESSION['remote'] as $v) {
35 if($v['uid'] == $page_owner_uid) {
43 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
45 intval($page_owner_uid)
55 notice( t('Permission denied.') . EOL );
59 if(! x($_FILES,'userfile'))
62 $src = $_FILES['userfile']['tmp_name'];
63 $filename = basename($_FILES['userfile']['name']);
64 $filesize = intval($_FILES['userfile']['size']);
66 $maxfilesize = get_config('system','maxfilesize');
68 if(($maxfilesize) && ($filesize > $maxfilesize)) {
69 notice( sprintf(t('File exceeds size limit of %d'), $maxfilesize) . EOL);
74 $r = q("select sum(octet_length(data)) as total from attach where uid = %d ",
75 intval($page_owner_uid)
78 $limit = service_class_fetch($page_owner_uid,'attach_upload_limit');
80 if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
81 echo upgrade_message(true) . EOL ;
87 $filedata = @file_get_contents($src);
88 $mimetype = z_mime_content_type($filename);
89 $hash = random_string();
90 $created = datetime_convert();
91 $r = q("INSERT INTO `attach` ( `uid`, `hash`, `filename`, `filetype`, `filesize`, `data`, `created`, `edited`, `allow_cid`, `allow_gid`,`deny_cid`, `deny_gid` )
92 VALUES ( %d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
93 intval($page_owner_uid),
101 dbesc('<' . $page_owner_cid . '>'),
110 echo ( t('File upload failed.') . EOL);
114 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `created` = '%s' AND `hash` = '%s' LIMIT 1",
115 intval($page_owner_uid),
121 echo ( t('File upload failed.') . EOL);
127 echo $lf . $lf . '[attachment]' . $r[0]['id'] . '[/attachment]' . $lf;