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( t('Permission denied.') . EOL) ;
38 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
45 $str_group_allow = perms2str($_POST['group_allow']);
46 $str_contact_allow = perms2str($_POST['contact_allow']);
47 $str_group_deny = perms2str($_POST['group_deny']);
48 $str_contact_deny = perms2str($_POST['contact_deny']);
50 $title = notags(trim($_POST['title']));
51 $body = escape_tags(trim($_POST['body']));
52 $location = notags(trim($_POST['location']));
53 $verb = notags(trim($_POST['verb']));
56 notice( t('Empty post discarded.') . EOL );
57 goaway($a->get_baseurl() . "/" . $_POST['return'] );
61 // get contact info for poster
65 if(($_SESSION['uid']) && ($_SESSION['uid'] == $profile_uid)) {
66 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
67 intval($_SESSION['uid'])
71 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
72 $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
73 intval($_SESSION['visitor_id'])
80 $contact_id = $author['id'];
83 // get contact info for owner
85 if($profile_uid == $_SESSION['uid']) {
86 $contact_record = $author;
89 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
93 $contact_record = $r[0];
96 $post_type = notags(trim($_POST['type']));
98 if($post_type == 'net-comment') {
99 if($parent_item !== null) {
100 if($parent_item['type'] == 'remote') {
101 $post_type = 'remote-comment';
104 $post_type = 'wall-comment';
110 if($post_type == 'wall' || $post_type == 'wall-comment')
114 $verb = ACTIVITY_POST ;
116 $gravity = (($parent) ? 6 : 0 );
118 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
120 $uri = item_new_uri($a->get_hostname(),$profile_uid);
122 $r = q("INSERT INTO `item` (`uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
123 `author-name`, `author-link`, `author-avatar`, `created`,
124 `edited`, `changed`, `uri`, `title`, `body`, `location`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
125 VALUES( %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
126 intval($profile_uid),
131 dbesc($contact_record['name']),
132 dbesc($contact_record['url']),
133 dbesc($contact_record['thumb']),
134 dbesc($author['name']),
135 dbesc($author['url']),
136 dbesc($author['thumb']),
137 dbesc(datetime_convert()),
138 dbesc(datetime_convert()),
139 dbesc(datetime_convert()),
145 dbesc($str_contact_allow),
146 dbesc($str_group_allow),
147 dbesc($str_contact_deny),
148 dbesc($str_group_deny)
150 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
153 $post_id = $r[0]['id'];
157 // This item is the last leaf and gets the comment box, clear any ancestors
158 $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d ",
159 dbesc(datetime_convert()),
163 // Inherit ACL's from the parent item.
164 // TODO merge with subsequent UPDATE operation and save a db write
166 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
167 WHERE `id` = %d LIMIT 1",
168 dbesc($parent_item['allow_cid']),
169 dbesc($parent_item['allow_gid']),
170 dbesc($parent_item['deny_cid']),
171 dbesc($parent_item['deny_gid']),
175 if(($user['notify-flags'] & NOTIFY_COMMENT) && ($contact_record != $author)) {
176 require_once('bbcode.php');
177 $from = $author['name'];
178 $tpl = load_view_file('view/cmnt_received_eml.tpl');
179 $email_tpl = replace_macros($tpl, array(
180 '$sitename' => $a->config['sitename'],
181 '$siteurl' => $a->get_baseurl(),
182 '$username' => $user['username'],
183 '$email' => $user['email'],
185 '$body' => strip_tags(bbcode($body))
188 $res = mail($user['email'], $from . t(" commented on your item at ") . $a->config['sitename'],
189 $email_tpl,t("From: Administrator@") . $a->get_hostname() );
195 if(($user['notify-flags'] & NOTIFY_WALL) && ($contact_record != $author)) {
196 require_once('bbcode.php');
197 $from = $author['name'];
198 $tpl = load_view_file('view/wall_received_eml.tpl');
199 $email_tpl = replace_macros($tpl, array(
200 '$sitename' => $a->config['sitename'],
201 '$siteurl' => $a->get_baseurl(),
202 '$username' => $user['username'],
203 '$email' => $user['email'],
205 '$body' => strip_tags(bbcode($body))
208 $res = mail($user['email'], $from . t(" posted on your profile wall at ") . $a->config['sitename'],
209 $email_tpl,t("From: Administrator@") . $a->get_hostname() );
213 $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `changed` = '%s', `last-child` = 1, `visible` = 1
214 WHERE `id` = %d LIMIT 1",
216 dbesc(($parent == $post_id) ? $uri : $parent_item['uri']),
217 dbesc(datetime_convert()),
220 // photo comments turn the corresponding item visible to the profile wall
221 if(! $parent_item['visible']) {
222 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d LIMIT 1",
223 intval($parent_item['id'])
228 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
230 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"$notify_type\" \"$post_id\" &",
233 goaway($a->get_baseurl() . "/" . $_POST['return'] );
234 return; // NOTREACHED
237 function item_content(&$a) {
239 if((! local_user()) && (! remote_user()))
242 require_once('include/security.php');
244 $uid = $_SESSION['uid'];
246 if(($a->argc == 3) && ($a->argv[1] == 'drop') && intval($a->argv[2])) {
248 // locate item to be deleted
250 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
255 notice( t('Item not found.') . EOL);
256 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
260 // check if logged in user is either the author or owner of this item
262 if(($_SESSION['visitor_id'] == $item['contact-id']) || ($_SESSION['uid'] == $item['uid'])) {
266 $r = q("UPDATE `item` SET `deleted` = 1, `body` = '', `edited` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
267 dbesc(datetime_convert()),
268 dbesc(datetime_convert()),
272 // If item is a link to a photo resource, nuke all the associated photos
273 // (visitors will not have photo resources)
274 // This only applies to photos uploaded from the photos page. Photos inserted into a post do not
275 // generate a resource-id and therefore aren't intimately linked to the item.
277 if(strlen($item['resource-id'])) {
278 $q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ",
279 dbesc($item['resource-id']),
285 // If it's the parent of a comment thread, kill all the kids
287 if($item['uri'] == $item['parent-uri']) {
288 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = ''
289 WHERE `parent-uri` = '%s' AND `uid` = %d ",
290 dbesc(datetime_convert()),
291 dbesc(datetime_convert()),
292 dbesc($item['parent-uri']),
298 // ensure that last-child is set in case the comment that had it just got wiped.
299 q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
300 dbesc(datetime_convert()),
301 dbesc($item['parent-uri']),
304 // who is the last child now?
305 $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d ORDER BY `edited` DESC LIMIT 1",
306 dbesc($item['parent-uri']),
310 q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
315 $drop_id = intval($item['id']);
316 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
318 // send the notification upstream/downstream as the case may be
320 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" &",
323 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
327 notice( t('Permission denied.') . EOL);
328 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);