5 * This is the POST destination for most all locally posted
6 * text stuff. This function handles status, wall-to-wall status,
7 * local comments, and remote coments - that are posted on this site
8 * (as opposed to being delivered in a feed).
9 * Also processed here are posts and comments coming through the
10 * statusnet/twitter API.
11 * All of these become an "item" which is our basic unit of
13 * Posts that originate externally or do not fall into the above
14 * posting categories go through item_store() instead of this function.
18 function item_post(&$a) {
20 if((! local_user()) && (! remote_user()))
23 require_once('include/security.php');
27 if(x($_POST,'dropitems')) {
28 require_once('include/items.php');
29 $arr_drop = explode(',',$_POST['dropitems']);
30 drop_items($arr_drop);
31 $json = array('success' => 1);
32 echo json_encode($json);
36 call_hooks('post_local_start', $_POST);
38 $api_source = ((x($_POST,'api_source') && $_POST['api_source']) ? true : false);
41 * Is this a reply to something?
44 $parent = ((x($_POST,'parent')) ? intval($_POST['parent']) : 0);
45 $parent_uri = ((x($_POST,'parent_uri')) ? trim($_POST['parent_uri']) : '');
48 $parent_contact = null;
53 if($parent || $parent_uri) {
55 if(! x($_POST,'type'))
56 $_POST['type'] = 'net-comment';
59 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
63 elseif($parent_uri && local_user()) {
64 // This is coming from an API source, and we are logged in
65 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
70 // if this isn't the real parent of the conversation, find it
71 if($r !== false && count($r)) {
72 $parid = $r[0]['parent'];
73 if($r[0]['id'] != $r[0]['parent']) {
74 $r = q("SELECT * FROM `item` WHERE `id` = `parent` AND `parent` = %d LIMIT 1",
80 if(($r === false) || (! count($r))) {
81 notice( t('Unable to locate original post.') . EOL);
82 if(x($_POST,'return'))
83 goaway($a->get_baseurl() . "/" . $_POST['return'] );
87 $parent = $r[0]['id'];
89 // multi-level threading - preserve the info but re-parent to our single level threading
90 if(($parid) && ($parid != $parent))
91 $thr_parent = $parent_uri;
93 if($parent_item['contact-id'] && $uid) {
94 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
95 intval($parent_item['contact-id']),
99 $parent_contact = $r[0];
103 if($parent) logger('mod_post: parent=' . $parent);
105 $profile_uid = ((x($_POST,'profile_uid')) ? intval($_POST['profile_uid']) : 0);
106 $post_id = ((x($_POST['post_id'])) ? intval($_POST['post_id']) : 0);
107 $app = ((x($_POST['source'])) ? strip_tags($_POST['source']) : '');
109 if(! can_write_wall($a,$profile_uid)) {
110 notice( t('Permission denied.') . EOL) ;
111 if(x($_POST,'return'))
112 goaway($a->get_baseurl() . "/" . $_POST['return'] );
117 // is this an edited post?
122 $i = q("SELECT * FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
123 intval($profile_uid),
133 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
140 $str_group_allow = $orig_post['allow_gid'];
141 $str_contact_allow = $orig_post['allow_cid'];
142 $str_group_deny = $orig_post['deny_gid'];
143 $str_contact_deny = $orig_post['deny_cid'];
144 $title = $orig_post['title'];
145 $location = $orig_post['location'];
146 $coord = $orig_post['coord'];
147 $verb = $orig_post['verb'];
148 $emailcc = $orig_post['emailcc'];
149 $app = $orig_post['app'];
151 $body = escape_tags(trim($_POST['body']));
152 $private = $orig_post['private'];
153 $pubmail_enable = $orig_post['pubmail'];
156 $str_group_allow = perms2str($_POST['group_allow']);
157 $str_contact_allow = perms2str($_POST['contact_allow']);
158 $str_group_deny = perms2str($_POST['group_deny']);
159 $str_contact_deny = perms2str($_POST['contact_deny']);
160 $title = notags(trim($_POST['title']));
161 $location = notags(trim($_POST['location']));
162 $coord = notags(trim($_POST['coord']));
163 $verb = notags(trim($_POST['verb']));
164 $emailcc = notags(trim($_POST['emailcc']));
166 $body = escape_tags(trim($_POST['body']));
167 $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);
170 (($parent_item['private'])
171 || strlen($parent_item['allow_cid'])
172 || strlen($parent_item['allow_gid'])
173 || strlen($parent_item['deny_cid'])
174 || strlen($parent_item['deny_gid'])
179 $pubmail_enable = ((x($_POST,'pubmail_enable') && intval($_POST['pubmail_enable']) && (! $private)) ? 1 : 0);
181 // if using the API, we won't see pubmail_enable - figure out if it should be set
183 if($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) {
184 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
185 if(! $mail_disabled) {
186 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
189 if(count($r) && intval($r[0]['pubmail']))
190 $pubmail_enabled = true;
195 if(! strlen($body)) {
196 info( t('Empty post discarded.') . EOL );
197 if(x($_POST,'return'))
198 goaway($a->get_baseurl() . "/" . $_POST['return'] );
203 // get contact info for poster
208 if(($_SESSION['uid']) && ($_SESSION['uid'] == $profile_uid)) {
210 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
211 intval($_SESSION['uid'])
215 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
216 $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
217 intval($_SESSION['visitor_id'])
224 $contact_id = $author['id'];
227 // get contact info for owner
229 if($profile_uid == $_SESSION['uid']) {
230 $contact_record = $author;
233 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
237 $contact_record = $r[0];
242 $post_type = notags(trim($_POST['type']));
244 if($post_type === 'net-comment') {
245 if($parent_item !== null) {
246 if($parent_item['wall'] == 1)
247 $post_type = 'wall-comment';
249 $post_type = 'remote-comment';
255 * When a photo was uploaded into the message using the (profile wall) ajax
256 * uploader, The permissions are initially set to disallow anybody but the
257 * owner from seeing it. This is because the permissions may not yet have been
258 * set for the post. If it's private, the photo permissions should be set
259 * appropriately. But we didn't know the final permissions on the post until
260 * now. So now we'll look for links of uploaded messages that are in the
261 * post and set them to the same permissions as the post itself.
267 if(preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) {
270 foreach($images as $image) {
271 if(! stristr($image,$a->get_baseurl() . '/photo/'))
273 $image_uri = substr($image,strrpos($image,'/') + 1);
274 $image_uri = substr($image_uri,0, strpos($image_uri,'-'));
275 if(! strlen($image_uri))
277 $srch = '<' . intval($profile_uid) . '>';
278 $r = q("SELECT `id` FROM `photo` WHERE `allow_cid` = '%s' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = ''
279 AND `resource-id` = '%s' AND `uid` = %d LIMIT 1",
288 $r = q("UPDATE `photo` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
289 WHERE `resource-id` = '%s' AND `uid` = %d AND `album` = '%s' ",
290 dbesc($str_contact_allow),
291 dbesc($str_group_allow),
292 dbesc($str_contact_deny),
293 dbesc($str_group_deny),
295 intval($profile_uid),
296 dbesc( t('Wall Photos'))
305 * Next link in any attachment references we find in the post.
310 if(preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",$body,$match)) {
311 $attaches = $match[1];
312 if(count($attaches)) {
313 foreach($attaches as $attach) {
314 $r = q("SELECT * FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
315 intval($profile_uid),
319 $r = q("UPDATE `attach` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
320 WHERE `uid` = %d AND `id` = %d LIMIT 1",
321 dbesc($str_contact_allow),
322 dbesc($str_group_allow),
323 dbesc($str_contact_deny),
324 dbesc($str_group_deny),
325 intval($profile_uid),
334 * Fold multi-line [code] sequences
337 $body = preg_replace('/\[\/code\]\s*\[code\]/m',"\n",$body);
340 * Look for any tags and linkify them
347 $tags = get_tags($body);
350 * add a statusnet style reply tag if the original post was from there
351 * and we are replying, and there isn't one already
354 if(($parent_contact) && ($parent_contact['network'] === 'stat')
355 && ($parent_contact['nick']) && (! in_array('@' . $parent_contact['nick'],$tags))) {
356 $body = '@' . $parent_contact['nick'] . ' ' . $body;
357 $tags[] = '@' . $parent_contact['nick'];
361 foreach($tags as $tag) {
364 if(strpos($tag,'#') === 0) {
365 if(strpos($tag,'[url='))
367 $basetag = str_replace('_',' ',substr($tag,1));
368 $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
369 if(strlen($str_tags))
371 $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
374 if(strpos($tag,'@') === 0) {
375 if(strpos($tag,'[url='))
378 $name = substr($tag,1);
379 if((strpos($name,'@')) || (strpos($name,'http://'))) {
381 $links = @lrdd($name);
383 foreach($links as $link) {
384 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
385 $profile = $link['@attributes']['href'];
386 if($link['@attributes']['rel'] === 'salmon') {
389 $inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']);
397 if(strstr($name,'_') || strstr($name,' ')) {
398 $newname = str_replace('_',' ',$name);
399 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
405 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
411 $profile = $r[0]['url'];
412 if($r[0]['network'] === 'stat') {
413 $newname = $r[0]['nick'];
416 $alias = $r[0]['alias'];
419 $newname = $r[0]['name'];
422 $inform .= 'cid:' . $r[0]['id'];
426 $body = str_replace('@' . $name, '@' . '[url=' . $profile . ']' . $newname . '[/url]', $body);
427 $profile = str_replace(',','%2c',$profile);
428 if(strlen($str_tags))
430 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
432 // Status.Net seems to require the numeric ID URL in a mention if the person isn't
433 // subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
436 if(strlen($str_tags))
438 $str_tags .= '@[url=' . $alias . ']' . $newname . '[/url]';
448 if(preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) {
449 foreach($match[2] as $mtch) {
450 $r = q("SELECT `id`,`filename`,`filesize`,`filetype` FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
451 intval($profile_uid),
455 if(strlen($attachments))
457 $attachments .= '[attach]href="' . $a->get_baseurl() . '/attach/' . $r[0]['id'] . '" length="' . $r[0]['filesize'] . '" type="' . $r[0]['filetype'] . '" title="' . (($r[0]['filename']) ? $r[0]['filename'] : '') . '"[/attach]';
459 $body = str_replace($match[1],'',$body);
465 if($post_type === 'wall' || $post_type === 'wall-comment')
469 $verb = ACTIVITY_POST ;
471 $gravity = (($parent) ? 6 : 0 );
473 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
475 $uri = item_new_uri($a->get_hostname(),$profile_uid);
478 $datarray['uid'] = $profile_uid;
479 $datarray['type'] = $post_type;
480 $datarray['wall'] = $wall;
481 $datarray['gravity'] = $gravity;
482 $datarray['contact-id'] = $contact_id;
483 $datarray['owner-name'] = $contact_record['name'];
484 $datarray['owner-link'] = $contact_record['url'];
485 $datarray['owner-avatar'] = $contact_record['thumb'];
486 $datarray['author-name'] = $author['name'];
487 $datarray['author-link'] = $author['url'];
488 $datarray['author-avatar'] = $author['thumb'];
489 $datarray['created'] = datetime_convert();
490 $datarray['edited'] = datetime_convert();
491 $datarray['received'] = datetime_convert();
492 $datarray['changed'] = datetime_convert();
493 $datarray['uri'] = $uri;
494 $datarray['title'] = $title;
495 $datarray['body'] = $body;
496 $datarray['app'] = $app;
497 $datarray['location'] = $location;
498 $datarray['coord'] = $coord;
499 $datarray['tag'] = $str_tags;
500 $datarray['inform'] = $inform;
501 $datarray['verb'] = $verb;
502 $datarray['allow_cid'] = $str_contact_allow;
503 $datarray['allow_gid'] = $str_group_allow;
504 $datarray['deny_cid'] = $str_contact_deny;
505 $datarray['deny_gid'] = $str_group_deny;
506 $datarray['private'] = $private;
507 $datarray['pubmail'] = $pubmail_enable;
508 $datarray['attach'] = $attachments;
509 $datarray['thr-parent'] = $thr_parent;
512 * These fields are for the convenience of plugins...
513 * 'self' if true indicates the owner is posting on their own wall
514 * If parent is 0 it is a top-level post.
517 $datarray['parent'] = $parent;
518 $datarray['self'] = $self;
519 $datarray['prvnets'] = $user['prvnets'];
522 $datarray['edit'] = true;
524 $datarray['guid'] = get_guid();
527 call_hooks('post_local',$datarray);
531 $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
533 dbesc(datetime_convert()),
538 proc_run('php', "include/notifier.php", 'edit_post', "$post_id");
539 if((x($_POST,'return')) && strlen($_POST['return'])) {
540 logger('return: ' . $_POST['return']);
541 goaway($a->get_baseurl() . "/" . $_POST['return'] );
549 $r = q("INSERT INTO `item` (`guid`, `uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
550 `author-name`, `author-link`, `author-avatar`, `created`, `edited`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`,
551 `tag`, `inform`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach` )
552 VALUES( '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s' )",
553 dbesc($datarray['guid']),
554 intval($datarray['uid']),
555 dbesc($datarray['type']),
556 intval($datarray['wall']),
557 intval($datarray['gravity']),
558 intval($datarray['contact-id']),
559 dbesc($datarray['owner-name']),
560 dbesc($datarray['owner-link']),
561 dbesc($datarray['owner-avatar']),
562 dbesc($datarray['author-name']),
563 dbesc($datarray['author-link']),
564 dbesc($datarray['author-avatar']),
565 dbesc($datarray['created']),
566 dbesc($datarray['edited']),
567 dbesc($datarray['received']),
568 dbesc($datarray['changed']),
569 dbesc($datarray['uri']),
570 dbesc($datarray['thr-parent']),
571 dbesc($datarray['title']),
572 dbesc($datarray['body']),
573 dbesc($datarray['app']),
574 dbesc($datarray['location']),
575 dbesc($datarray['coord']),
576 dbesc($datarray['tag']),
577 dbesc($datarray['inform']),
578 dbesc($datarray['verb']),
579 dbesc($datarray['allow_cid']),
580 dbesc($datarray['allow_gid']),
581 dbesc($datarray['deny_cid']),
582 dbesc($datarray['deny_gid']),
583 intval($datarray['private']),
584 intval($datarray['pubmail']),
585 dbesc($datarray['attach'])
588 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
589 dbesc($datarray['uri']));
591 $post_id = $r[0]['id'];
592 logger('mod_item: saved item ' . $post_id);
596 // This item is the last leaf and gets the comment box, clear any ancestors
597 $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d ",
598 dbesc(datetime_convert()),
602 // Inherit ACL's from the parent item.
604 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d
605 WHERE `id` = %d LIMIT 1",
606 dbesc($parent_item['allow_cid']),
607 dbesc($parent_item['allow_gid']),
608 dbesc($parent_item['deny_cid']),
609 dbesc($parent_item['deny_gid']),
610 intval($parent_item['private']),
614 // Send a notification email to the conversation owner, unless the owner is me and I wrote this item
615 if(($user['notify-flags'] & NOTIFY_COMMENT) && ($contact_record != $author)) {
616 push_lang($user['language']);
617 require_once('bbcode.php');
618 $from = $author['name'];
620 // name of the automated email sender
621 $msg['notificationfromname'] = stripslashes($datarray['author-name']);;
622 // noreply address to send from
623 $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
626 // process the message body to display properly in text mode
628 = html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8');
631 // process the message body to display properly in text mode
633 = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$datarray['body']))));
635 // load the template for private message notifications
636 $tpl = get_intltext_template('cmnt_received_html_body_eml.tpl');
637 $email_html_body_tpl = replace_macros($tpl,array(
638 '$username' => $user['username'],
639 '$sitename' => $a->config['sitename'], // name of this site
640 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
641 '$thumb' => $author['thumb'], // thumbnail url for sender icon
642 '$email' => $importer['email'], // email address to send to
643 '$url' => $author['url'], // full url for the site
644 '$from' => $from, // name of the person sending the message
645 '$body' => $msg['htmlversion'], // html version of the message
646 '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
649 // load the template for private message notifications
650 $tpl = get_intltext_template('cmnt_received_text_body_eml.tpl');
651 $email_text_body_tpl = replace_macros($tpl,array(
652 '$username' => $user['username'],
653 '$sitename' => $a->config['sitename'], // name of this site
654 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
655 '$thumb' => $author['thumb'], // thumbnail url for sender icon
656 '$email' => $importer['email'], // email address to send to
657 '$url' => $author['url'], // profile url for the author
658 '$from' => $from, // name of the person sending the message
659 '$body' => $msg['textversion'], // text version of the message
660 '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
663 // use the EmailNotification library to send the message
664 require_once("include/EmailNotification.php");
665 EmailNotification::sendTextHtmlEmail(
666 $msg['notificationfromname'],
667 t("Administrator@") . $a->get_hostname(),
668 t("noreply") . '@' . $a->get_hostname(),
670 sprintf( t('%s commented on an item at %s'), $from , $a->config['sitename']),
671 $email_html_body_tpl,
681 // let me know if somebody did a wall-to-wall post on my profile
683 if(($user['notify-flags'] & NOTIFY_WALL) && ($contact_record != $author)) {
684 push_lang($user['language']);
685 require_once('bbcode.php');
686 $from = $author['name'];
688 // name of the automated email sender
689 $msg['notificationfromname'] = $from;
690 // noreply address to send from
691 $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
694 // process the message body to display properly in text mode
696 = html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8');
699 // process the message body to display properly in text mode
701 = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$datarray['body']))));
703 // load the template for private message notifications
704 $tpl = load_view_file('view/wall_received_html_body_eml.tpl');
705 $email_html_body_tpl = replace_macros($tpl,array(
706 '$username' => $user['username'],
707 '$sitename' => $a->config['sitename'], // name of this site
708 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
709 '$thumb' => $author['thumb'], // thumbnail url for sender icon
710 '$url' => $author['url'], // full url for the site
711 '$from' => $from, // name of the person sending the message
712 '$body' => $msg['htmlversion'], // html version of the message
713 '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
716 // load the template for private message notifications
717 $tpl = load_view_file('view/wall_received_text_body_eml.tpl');
718 $email_text_body_tpl = replace_macros($tpl,array(
719 '$username' => $user['username'],
720 '$sitename' => $a->config['sitename'], // name of this site
721 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
722 '$thumb' => $author['thumb'], // thumbnail url for sender icon
723 '$url' => $author['url'], // full url for the site
724 '$from' => $from, // name of the person sending the message
725 '$body' => $msg['textversion'], // text version of the message
726 '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
729 // use the EmailNotification library to send the message
730 require_once("include/EmailNotification.php");
731 EmailNotification::sendTextHtmlEmail(
732 $msg['notificationfromname'],
733 t("Administrator@") . $a->get_hostname(),
734 t("noreply") . '@' . $a->get_hostname(),
736 sprintf( t('%s posted to your profile wall at %s') , $from , $a->config['sitename']),
737 $email_html_body_tpl,
744 $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `plink` = '%s', `changed` = '%s', `last-child` = 1, `visible` = 1
745 WHERE `id` = %d LIMIT 1",
747 dbesc(($parent == $post_id) ? $uri : $parent_item['uri']),
748 dbesc($a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id),
749 dbesc(datetime_convert()),
753 // photo comments turn the corresponding item visible to the profile wall
754 // This way we don't see every picture in your new photo album posted to your wall at once.
755 // They will show up as people comment on them.
757 if(! $parent_item['visible']) {
758 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d LIMIT 1",
759 intval($parent_item['id'])
764 logger('mod_item: unable to retrieve post that was just stored.');
765 notify( t('System error. Post not saved.'));
766 goaway($a->get_baseurl() . "/" . $_POST['return'] );
770 proc_run('php', "include/notifier.php", $notify_type, "$post_id");
772 $datarray['id'] = $post_id;
773 $datarray['plink'] = $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id;
775 call_hooks('post_local_end', $datarray);
777 if(strlen($emailcc) && $profile_uid == local_user()) {
778 $erecips = explode(',', $emailcc);
779 if(count($erecips)) {
780 foreach($erecips as $recip) {
781 $addr = trim($recip);
784 $disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendika social network.'),$a->user['username'])
786 $disclaimer .= sprintf( t('You may visit them online at %s'), $a->get_baseurl() . '/profile/' . $a->user['nickname']) . EOL;
787 $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
789 $subject = '[Friendika]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']);
790 $headers = 'From: ' . $a->user['username'] . ' <' . $a->user['email'] . '>' . "\n";
791 $headers .= 'MIME-Version: 1.0' . "\n";
792 $headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
793 $headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n";
794 $link = '<a href="' . $a->get_baseurl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
795 $html = prepare_body($datarray);
796 $message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
797 @mail($addr, $subject, $message, $headers);
802 logger('post_complete');
804 // figure out how to return, depending on from whence we came
809 if((x($_POST,'return')) && strlen($_POST['return'])) {
810 logger('return: ' . $_POST['return']);
811 goaway($a->get_baseurl() . "/" . $_POST['return'] );
813 $json = array('success' => 1);
814 if(x($_POST,'jsreload') && strlen($_POST['jsreload']))
815 $json['reload'] = $a->get_baseurl() . '/' . $_POST['jsreload'];
817 logger('post_json: ' . print_r($json,true), LOGGER_DEBUG);
819 echo json_encode($json);
828 function item_content(&$a) {
830 if((! local_user()) && (! remote_user()))
833 require_once('include/security.php');
835 if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
836 require_once('include/items.php');
837 drop_item($a->argv[2]);