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'];
15 $parent = ((x($_POST,'parent')) ? intval($_POST['parent']) : 0);
20 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
24 notice("Unable to locate original post." . EOL);
25 goaway($a->get_baseurl() . "/" . $_POST['return'] );
30 $profile_uid = ((x($_POST,'profile_uid')) ? intval($_POST['profile_uid']) : 0);
32 if(! can_write_wall($a,$profile_uid)) {
33 notice("Permission denied." . EOL) ;
37 $str_group_allow = '';
38 $group_allow = $_POST['group_allow'];
39 if(is_array($group_allow)) {
40 array_walk($group_allow,'sanitise_acl');
41 $str_group_allow = implode('',$group_allow);
44 $str_contact_allow = '';
45 $contact_allow = $_POST['contact_allow'];
46 if(is_array($contact_allow)) {
47 array_walk($contact_allow,'sanitise_acl');
48 $str_contact_allow = implode('',$contact_allow);
52 $group_deny = $_POST['group_deny'];
53 if(is_array($group_deny)) {
54 array_walk($group_deny,'sanitise_acl');
55 $str_group_deny = implode('',$group_deny);
58 $str_contact_deny = '';
59 $contact_deny = $_POST['contact_deny'];
60 if(is_array($contact_deny)) {
61 array_walk($contact_deny,'sanitise_acl');
62 $str_contact_deny = implode('',$contact_deny);
66 $body = escape_tags(trim($_POST['body']));
69 notice("Empty post discarded." . EOL );
70 goaway($a->get_baseurl() . "/" . $_POST['return'] );
74 // get contact info for poster
75 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id'])))
76 $contact_id = $_SESSION['visitor_id'];
78 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
79 intval($_SESSION['uid']));
81 $contact_id = $r[0]['id'];
84 // get contact info for owner
86 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
90 $contact_record = $r[0];
93 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
95 if(($_POST['type'] == 'wall') || ($_POST['type'] == 'wall-comment')) {
99 $hash = random_string();
100 $r = q("SELECT `id` FROM `item` WHERE `hash` = '%s' LIMIT 1",
104 } while($dups == true);
107 $r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`, `created`,`edited`,`hash`,`body`,
108 `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
109 VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
110 intval($profile_uid),
111 dbesc($_POST['type']),
113 dbesc($contact_record['name']),
114 dbesc($contact_record['url']),
115 dbesc($contact_record['thumb']),
119 dbesc(escape_tags(trim($_POST['body']))),
120 dbesc($str_contact_allow),
121 dbesc($str_group_allow),
122 dbesc($str_contact_deny),
123 dbesc($str_group_deny)
126 $r = q("SELECT `id` FROM `item` WHERE `hash` = '%s' LIMIT 1",
129 $post_id = $r[0]['id'];
133 // This item is the last leaf and gets the comment box, clear any ancestors
134 $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent` = %d ",
138 // Inherit ACL's from the parent item.
139 // TODO merge with subsequent UPDATE operation and save a db write
141 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
142 WHERE `id` = %d LIMIT 1",
143 dbesc($parent_item['allow_cid']),
144 dbesc($parent_item['allow_gid']),
145 dbesc($parent_item['deny_cid']),
146 dbesc($parent_item['deny_gid']),
154 $r = q("UPDATE `item` SET `parent` = %d, `last-child` = 1, `visible` = 1
155 WHERE `id` = %d LIMIT 1",
160 $url = bin2hex($a->get_baseurl());
162 proc_close(proc_open("php include/notifier.php $url $notify_type $post_id > notify.log &",
166 goaway($a->get_baseurl() . "/" . $_POST['return'] );
167 return; // NOTREACHED