3 function item_post(&$a) {
5 if((! local_user()) && (! remote_user()))
8 require_once('include/security.php');
10 $uid = $_SESSION['uid'];
13 $parent = ((x($_POST,'parent')) ? intval($_POST['parent']) : 0);
18 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
22 notice( t('Unable to locate original post.') . EOL);
23 goaway($a->get_baseurl() . "/" . $_POST['return'] );
28 $profile_uid = ((x($_POST,'profile_uid')) ? intval($_POST['profile_uid']) : 0);
30 if(! can_write_wall($a,$profile_uid)) {
31 notice("Permission denied." . EOL) ;
35 $str_group_allow = '';
36 $group_allow = $_POST['group_allow'];
37 if(is_array($group_allow)) {
38 array_walk($group_allow,'sanitise_acl');
39 $str_group_allow = implode('',$group_allow);
42 $str_contact_allow = '';
43 $contact_allow = $_POST['contact_allow'];
44 if(is_array($contact_allow)) {
45 array_walk($contact_allow,'sanitise_acl');
46 $str_contact_allow = implode('',$contact_allow);
50 $group_deny = $_POST['group_deny'];
51 if(is_array($group_deny)) {
52 array_walk($group_deny,'sanitise_acl');
53 $str_group_deny = implode('',$group_deny);
56 $str_contact_deny = '';
57 $contact_deny = $_POST['contact_deny'];
58 if(is_array($contact_deny)) {
59 array_walk($contact_deny,'sanitise_acl');
60 $str_contact_deny = implode('',$contact_deny);
63 $title = notags(trim($_POST['title']));
64 $body = escape_tags(trim($_POST['body']));
67 notice( t('Empty post discarded.') . EOL );
68 goaway($a->get_baseurl() . "/" . $_POST['return'] );
72 // get contact info for poster
74 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
75 $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];
92 $post_type == notags(trim($_POST['type']));
94 if($post_type == 'net-comment') {
95 if($parent_item !== null) {
96 if($parent_item['type'] == 'remote')
97 $post_type = 'remote-comment';
99 $post_type = 'wall-comment';
103 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
107 $hash = random_string();
109 $uri = "urn:X-dfrn:" . $a->get_hostname() . ':' . $profile_uid . ':' . $hash;
111 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
115 } while($dups == true);
118 $r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`, `created`,
119 `edited`, `uri`, `title`, `body`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
120 VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
121 intval($profile_uid),
124 dbesc($contact_record['name']),
125 dbesc($contact_record['url']),
126 dbesc($contact_record['thumb']),
132 dbesc($str_contact_allow),
133 dbesc($str_group_allow),
134 dbesc($str_contact_deny),
135 dbesc($str_group_deny)
137 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
140 $post_id = $r[0]['id'];
144 // This item is the last leaf and gets the comment box, clear any ancestors
145 $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent` = %d ",
149 // Inherit ACL's from the parent item.
150 // TODO merge with subsequent UPDATE operation and save a db write
152 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
153 WHERE `id` = %d LIMIT 1",
154 dbesc($parent_item['allow_cid']),
155 dbesc($parent_item['allow_gid']),
156 dbesc($parent_item['deny_cid']),
157 dbesc($parent_item['deny_gid']),
165 $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `last-child` = 1, `visible` = 1
166 WHERE `id` = %d LIMIT 1",
168 dbesc(($parent == $post_id) ? $uri : $parent_item['uri']),
171 // photo comments turn the corresponding item visible to the profile wall
172 if(! $parent_item['visible']) {
173 $r = q("UPDATE `item` SET `visible = 1 WHERE `id` = %d LIMIT 1",
174 intval($parent_item['id'])
178 $url = $a->get_baseurl();
180 proc_close(proc_open("php include/notifier.php \"$url\" \"$notify_type\" \"$post_id\" > notify.log &",
183 goaway($a->get_baseurl() . "/" . $_POST['return'] );
184 return; // NOTREACHED
187 function item_content(&$a) {
189 if((! local_user()) && (! remote_user()))
192 require_once('include/security.php');
194 $uid = $_SESSION['uid'];
196 if(($a->argc == 3) && ($a->argv[1] == 'drop') && intval($a->argv[2])) {
198 // locate item to be deleted
200 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
205 notice("Item not found." . EOL);
206 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
210 // check if logged in user is either the author or owner of this item
212 if(($_SESSION['visitor_id'] == $item['contact-id']) || ($_SESSION['uid'] == $item['uid'])) {
216 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s' WHERE `id` = %d LIMIT 1",
217 dbesc(datetime_convert()),
221 // If item is a link to a photo resource, nuke all the associated photos
222 // (visitors will not have photo resources)
223 // This only applies to photos uploaded from the photos page. Photos inserted into a post do not
224 // generate a resource-id and therefore aren't intimately linked to the item.
226 if(strlen($item['resource-id'])) {
227 $q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ",
228 dbesc($item['resource-id']),
234 // If it's the parent of a comment thread, kill all the kids
236 if($item['uri'] == $item['parent-uri']) {
237 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s'
238 WHERE `parent-uri` = '%s' AND `uid` = %d ",
239 dbesc(datetime_convert()),
240 dbesc($item['parent-uri']),
246 $url = $a->get_baseurl();
247 $drop_id = intval($item['id']);
249 // send the notification upstream/downstream as the case may be
251 proc_close(proc_open("php include/notifier.php \"$url\" \"drop\" \"$drop_id\" > notify.log &",
254 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
258 notice("Permission denied." . EOL);
259 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);