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);
31 if(! can_write_wall($a,$profile_uid)) {
32 notice("Permission denied." . EOL) ;
38 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
45 $str_group_allow = '';
46 $group_allow = $_POST['group_allow'];
47 if(is_array($group_allow)) {
48 array_walk($group_allow,'sanitise_acl');
49 $str_group_allow = implode('',$group_allow);
52 $str_contact_allow = '';
53 $contact_allow = $_POST['contact_allow'];
54 if(is_array($contact_allow)) {
55 array_walk($contact_allow,'sanitise_acl');
56 $str_contact_allow = implode('',$contact_allow);
60 $group_deny = $_POST['group_deny'];
61 if(is_array($group_deny)) {
62 array_walk($group_deny,'sanitise_acl');
63 $str_group_deny = implode('',$group_deny);
66 $str_contact_deny = '';
67 $contact_deny = $_POST['contact_deny'];
68 if(is_array($contact_deny)) {
69 array_walk($contact_deny,'sanitise_acl');
70 $str_contact_deny = implode('',$contact_deny);
73 $title = notags(trim($_POST['title']));
74 $body = escape_tags(trim($_POST['body']));
75 $location = notags(trim($_POST['location']));
78 notice( t('Empty post discarded.') . EOL );
79 goaway($a->get_baseurl() . "/" . $_POST['return'] );
83 // get contact info for poster
87 if(($_SESSION['uid']) && ($_SESSION['uid'] == $profile_uid)) {
88 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
89 intval($_SESSION['uid'])
93 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
94 $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
95 intval($_SESSION['visitor_id'])
102 $contact_id = $author['id'];
105 // get contact info for owner
107 if($profile_uid == $_SESSION['uid']) {
108 $contact_record = $author;
111 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
115 $contact_record = $r[0];
118 $post_type = notags(trim($_POST['type']));
120 if($post_type == 'net-comment') {
121 if($parent_item !== null) {
122 if($parent_item['type'] == 'remote')
123 $post_type = 'remote-comment';
125 $post_type = 'wall-comment';
129 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
133 $hash = random_string();
135 $uri = "urn:X-dfrn:" . $a->get_hostname() . ':' . $profile_uid . ':' . $hash;
137 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
141 } while($dups == true);
144 $r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
145 `author-name`, `author-link`, `author-avatar`, `created`,
146 `edited`, `uri`, `title`, `body`, `location`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
147 VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
148 intval($profile_uid),
151 dbesc($contact_record['name']),
152 dbesc($contact_record['url']),
153 dbesc($contact_record['thumb']),
154 dbesc($author['name']),
155 dbesc($author['url']),
156 dbesc($author['thumb']),
163 dbesc($str_contact_allow),
164 dbesc($str_group_allow),
165 dbesc($str_contact_deny),
166 dbesc($str_group_deny)
168 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
171 $post_id = $r[0]['id'];
175 // This item is the last leaf and gets the comment box, clear any ancestors
176 $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent` = %d ",
180 // Inherit ACL's from the parent item.
181 // TODO merge with subsequent UPDATE operation and save a db write
183 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
184 WHERE `id` = %d LIMIT 1",
185 dbesc($parent_item['allow_cid']),
186 dbesc($parent_item['allow_gid']),
187 dbesc($parent_item['deny_cid']),
188 dbesc($parent_item['deny_gid']),
192 if(($user['notify-flags'] & NOTIFY_COMMENT) && ($contact_record != $author)) {
193 require_once('bbcode.php');
194 $from = $author['name'];
195 $tpl = file_get_contents('view/cmnt_received_eml.tpl');
196 $email_tpl = replace_macros($tpl, array(
197 '$sitename' => $a->config['sitename'],
198 '$siteurl' => $a->get_baseurl(),
199 '$username' => $user['username'],
200 '$email' => $user['email'],
202 '$body' => strip_tags(bbcode($body))
205 $res = mail($user['email'], $from . t(" commented on your item at ") . $a->config['sitename'],
206 $email_tpl,t("From: Administrator@") . $a->get_hostname() );
212 if(($user['notify-flags'] & NOTIFY_WALL) && ($contact_record != $author)) {
213 require_once('bbcode.php');
214 $from = $author['name'];
215 $tpl = file_get_contents('view/wall_received_eml.tpl');
216 $email_tpl = replace_macros($tpl, array(
217 '$sitename' => $a->config['sitename'],
218 '$siteurl' => $a->get_baseurl(),
219 '$username' => $user['username'],
220 '$email' => $user['email'],
222 '$body' => strip_tags(bbcode($body))
225 $res = mail($user['email'], $from . t(" posted on your profile wall at ") . $a->config['sitename'],
226 $email_tpl,t("From: Administrator@") . $a->get_hostname() );
230 $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `last-child` = 1, `visible` = 1
231 WHERE `id` = %d LIMIT 1",
233 dbesc(($parent == $post_id) ? $uri : $parent_item['uri']),
236 // photo comments turn the corresponding item visible to the profile wall
237 if(! $parent_item['visible']) {
238 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d LIMIT 1",
239 intval($parent_item['id'])
244 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
246 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"$notify_type\" \"$post_id\" &",
249 goaway($a->get_baseurl() . "/" . $_POST['return'] );
250 return; // NOTREACHED
253 function item_content(&$a) {
255 if((! local_user()) && (! remote_user()))
258 require_once('include/security.php');
260 $uid = $_SESSION['uid'];
262 if(($a->argc == 3) && ($a->argv[1] == 'drop') && intval($a->argv[2])) {
264 // locate item to be deleted
266 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
271 notice( t('Item not found.') . EOL);
272 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
276 // check if logged in user is either the author or owner of this item
278 if(($_SESSION['visitor_id'] == $item['contact-id']) || ($_SESSION['uid'] == $item['uid'])) {
282 $r = q("UPDATE `item` SET `deleted` = 1, `body` = '', `edited` = '%s' WHERE `id` = %d LIMIT 1",
283 dbesc(datetime_convert()),
287 // If item is a link to a photo resource, nuke all the associated photos
288 // (visitors will not have photo resources)
289 // This only applies to photos uploaded from the photos page. Photos inserted into a post do not
290 // generate a resource-id and therefore aren't intimately linked to the item.
292 if(strlen($item['resource-id'])) {
293 $q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ",
294 dbesc($item['resource-id']),
300 // If it's the parent of a comment thread, kill all the kids
302 if($item['uri'] == $item['parent-uri']) {
303 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `body` = ''
304 WHERE `parent-uri` = '%s' AND `uid` = %d ",
305 dbesc(datetime_convert()),
306 dbesc($item['parent-uri']),
312 $drop_id = intval($item['id']);
313 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
315 // send the notification upstream/downstream as the case may be
317 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" &",
320 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
324 notice( t('Permission denied.') . EOL);
325 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);