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'];
17 $parent = ((x($_POST,'parent')) ? intval($_POST['parent']) : 0);
22 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
26 notice("Unable to locate original post." . EOL);
27 goaway($a->get_baseurl() . "/" . $_POST['return'] );
32 $profile_uid = ((x($_POST,'profile_uid')) ? intval($_POST['profile_uid']) : 0);
34 if(! can_write_wall($a,$profile_uid)) {
35 notice("Permission denied." . EOL) ;
39 $str_group_allow = '';
40 $group_allow = $_POST['group_allow'];
41 if(is_array($group_allow)) {
42 array_walk($group_allow,'sanitise_acl');
43 $str_group_allow = implode('',$group_allow);
46 $str_contact_allow = '';
47 $contact_allow = $_POST['contact_allow'];
48 if(is_array($contact_allow)) {
49 array_walk($contact_allow,'sanitise_acl');
50 $str_contact_allow = implode('',$contact_allow);
54 $group_deny = $_POST['group_deny'];
55 if(is_array($group_deny)) {
56 array_walk($group_deny,'sanitise_acl');
57 $str_group_deny = implode('',$group_deny);
60 $str_contact_deny = '';
61 $contact_deny = $_POST['contact_deny'];
62 if(is_array($contact_deny)) {
63 array_walk($contact_deny,'sanitise_acl');
64 $str_contact_deny = implode('',$contact_deny);
68 $body = escape_tags(trim($_POST['body']));
71 notice("Empty post discarded." . EOL );
72 goaway($a->get_baseurl() . "/" . $_POST['return'] );
76 // get contact info for poster
78 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
79 $contact_id = $_SESSION['visitor_id'];
82 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
83 intval($_SESSION['uid']));
85 $contact_id = $r[0]['id'];
88 // get contact info for owner
90 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
94 $contact_record = $r[0];
96 $post_type == notags(trim($_POST['type']));
98 if($post_type == 'net-comment') {
99 if($parent_item !== null && $parent_item['type'] != 'remote')
100 $post_type = 'wall-comment';
103 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
105 if(($_POST['type'] == 'wall') || ($_POST['type'] == 'wall-comment') || ($_POST['type'] == 'net-comment')) {
109 $hash = random_string();
111 $uri = "urn:X-dfrn:" . $a->get_hostname() . ':' . $profile_uid . ':' . $hash;
113 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
117 } while($dups == true);
120 $r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`, `created`,
121 `edited`, `uri`, `body`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
122 VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
123 intval($profile_uid),
124 dbesc($_POST['type']),
126 dbesc($contact_record['name']),
127 dbesc($contact_record['url']),
128 dbesc($contact_record['thumb']),
132 dbesc(escape_tags(trim($_POST['body']))),
133 dbesc($str_contact_allow),
134 dbesc($str_group_allow),
135 dbesc($str_contact_deny),
136 dbesc($str_group_deny)
139 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
142 $post_id = $r[0]['id'];
146 // This item is the last leaf and gets the comment box, clear any ancestors
147 $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent` = %d ",
151 // Inherit ACL's from the parent item.
152 // TODO merge with subsequent UPDATE operation and save a db write
154 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
155 WHERE `id` = %d LIMIT 1",
156 dbesc($parent_item['allow_cid']),
157 dbesc($parent_item['allow_gid']),
158 dbesc($parent_item['deny_cid']),
159 dbesc($parent_item['deny_gid']),
167 $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `last-child` = 1, `visible` = 1
168 WHERE `id` = %d LIMIT 1",
170 dbesc(($parent == $post_id) ? $uri : $parent_item['uri']),
175 $url = $a->get_baseurl();
177 proc_close(proc_open("php include/notifier.php \"$url\" \"$notify_type\" \"$post_id\" > notify.log &",
181 goaway($a->get_baseurl() . "/" . $_POST['return'] );
182 return; // NOTREACHED
185 function item_content(&$a) {
187 if((! local_user()) && (! remote_user()))
190 require_once('include/security.php');
192 $uid = $_SESSION['uid'];
194 if(($a->argc == 3) && ($a->argv[1] == 'drop') && intval($a->argv[2])) {
196 // locate item to be deleted
198 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
203 notice("Item not found." . EOL);
204 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
208 // check if logged in user is either the author or owner of this item
210 if(($_SESSION['visitor_id'] == $item['contact-id']) || ($_SESSION['uid'] == $item['uid'])) {
214 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s' WHERE `id` = %d LIMIT 1",
215 dbesc(datetime_convert()),
219 // If it's the parent of a comment thread, kill all the kids
221 if($item['uri'] == $item['parent-uri']) {
222 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s'
223 WHERE `parent-uri` = '%s' AND `uid` = %d ",
224 dbesc(datetime_convert()),
225 dbesc($item['parent-uri']),
230 $url = $a->get_baseurl();
231 $drop_id = intval($item['id']);
233 // send the notification upstream/downstream as the case may be
235 proc_close(proc_open("php include/notifier.php \"$url\" \"drop\" \"$drop_id\" > notify.log &",
238 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
242 notice("Permission denied." . EOL);
243 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);