3 function sanitise_acl(&$item) {
4 $item = '<' . intval(notags(trim($item))) . '>';
7 function item_post(&$a) {
9 if((! local_user()) && (! remote_user()))
12 require_once('include/security.php');
14 $uid = $_SESSION['uid'];
16 if(($a->argc == 3) && ($a->argv[1] == 'drop') && intval($a->argv[2])) {
17 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
21 notice("Permission denied." . EOL);
22 goway($a->get_baseurl() . $_SESSION['return_url']);
25 if(($_SESSION['visitor_id'] == $item['contact-id']) || ($_SESSION['uid'] == $item['uid'])) {
26 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s' WHERE `id` = %d LIMIT 1",
27 dbesc(datetime_convert()),
30 if($item['uri'] == $item['parent-uri']) {
31 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s' WHERE `parent-uri` = '%s',
32 dbesc(datetime_convert()),
33 dbesc($item['parent-uri'])
37 $url = $a->get_baseurl();
38 $drop_id = intval($item['id'])l
40 proc_close(proc_open("php include/notifier.php \"$url\" \"$drop" \"$drop_id\" > notify.log &",
43 goway($a->get_baseurl() . $_SESSION['return_url']);
47 $parent = ((x($_POST,'parent')) ? intval($_POST['parent']) : 0);
52 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
56 notice("Unable to locate original post." . EOL);
57 goaway($a->get_baseurl() . "/" . $_POST['return'] );
62 $profile_uid = ((x($_POST,'profile_uid')) ? intval($_POST['profile_uid']) : 0);
64 if(! can_write_wall($a,$profile_uid)) {
65 notice("Permission denied." . EOL) ;
69 $str_group_allow = '';
70 $group_allow = $_POST['group_allow'];
71 if(is_array($group_allow)) {
72 array_walk($group_allow,'sanitise_acl');
73 $str_group_allow = implode('',$group_allow);
76 $str_contact_allow = '';
77 $contact_allow = $_POST['contact_allow'];
78 if(is_array($contact_allow)) {
79 array_walk($contact_allow,'sanitise_acl');
80 $str_contact_allow = implode('',$contact_allow);
84 $group_deny = $_POST['group_deny'];
85 if(is_array($group_deny)) {
86 array_walk($group_deny,'sanitise_acl');
87 $str_group_deny = implode('',$group_deny);
90 $str_contact_deny = '';
91 $contact_deny = $_POST['contact_deny'];
92 if(is_array($contact_deny)) {
93 array_walk($contact_deny,'sanitise_acl');
94 $str_contact_deny = implode('',$contact_deny);
98 $body = escape_tags(trim($_POST['body']));
100 if(! strlen($body)) {
101 notice("Empty post discarded." . EOL );
102 goaway($a->get_baseurl() . "/" . $_POST['return'] );
106 // get contact info for poster
108 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
109 $contact_id = $_SESSION['visitor_id'];
112 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
113 intval($_SESSION['uid']));
115 $contact_id = $r[0]['id'];
118 // get contact info for owner
120 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
124 $contact_record = $r[0];
126 $post_type == notags(trim($_POST['type']));
128 if($post_type == 'net-comment') {
129 if($parent_item !== null && $parent_item['type'] != 'remote')
130 $post_type = 'wall-comment';
133 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
135 if(($_POST['type'] == 'wall') || ($_POST['type'] == 'wall-comment') || ($_POST['type'] == 'net-comment')) {
139 $hash = random_string();
141 $uri = "urn:X-dfrn:" . $a->get_hostname() . ':' . $profile_uid . ':' . $hash;
143 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
147 } while($dups == true);
150 $r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`, `created`,
151 `edited`, `uri`, `body`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
152 VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
153 intval($profile_uid),
154 dbesc($_POST['type']),
156 dbesc($contact_record['name']),
157 dbesc($contact_record['url']),
158 dbesc($contact_record['thumb']),
162 dbesc(escape_tags(trim($_POST['body']))),
163 dbesc($str_contact_allow),
164 dbesc($str_group_allow),
165 dbesc($str_contact_deny),
166 dbesc($str_group_deny)
169 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
172 $post_id = $r[0]['id'];
176 // This item is the last leaf and gets the comment box, clear any ancestors
177 $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent` = %d ",
181 // Inherit ACL's from the parent item.
182 // TODO merge with subsequent UPDATE operation and save a db write
184 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
185 WHERE `id` = %d LIMIT 1",
186 dbesc($parent_item['allow_cid']),
187 dbesc($parent_item['allow_gid']),
188 dbesc($parent_item['deny_cid']),
189 dbesc($parent_item['deny_gid']),
197 $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `last-child` = 1, `visible` = 1
198 WHERE `id` = %d LIMIT 1",
200 dbesc(($parent == $post_id) ? $uri : $parent_item['uri']),
205 $url = $a->get_baseurl();
207 proc_close(proc_open("php include/notifier.php \"$url\" \"$notify_type\" \"$post_id\" > notify.log &",
211 goaway($a->get_baseurl() . "/" . $_POST['return'] );
212 return; // NOTREACHED