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 require_once('include/crypto.php');
20 function item_post(&$a) {
22 if((! local_user()) && (! remote_user()))
25 require_once('include/security.php');
29 if(x($_POST,'dropitems')) {
30 require_once('include/items.php');
31 $arr_drop = explode(',',$_POST['dropitems']);
32 drop_items($arr_drop);
33 $json = array('success' => 1);
34 echo json_encode($json);
38 call_hooks('post_local_start', $_POST);
40 $api_source = ((x($_POST,'api_source') && $_POST['api_source']) ? true : false);
41 $return_path = ((x($_POST,'return')) ? $_POST['return'] : '');
44 * Is this a reply to something?
47 $parent = ((x($_POST,'parent')) ? intval($_POST['parent']) : 0);
48 $parent_uri = ((x($_POST,'parent_uri')) ? trim($_POST['parent_uri']) : '');
51 $parent_contact = null;
56 if($parent || $parent_uri) {
58 if(! x($_POST,'type'))
59 $_POST['type'] = 'net-comment';
62 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
66 elseif($parent_uri && local_user()) {
67 // This is coming from an API source, and we are logged in
68 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
73 // if this isn't the real parent of the conversation, find it
74 if($r !== false && count($r)) {
75 $parid = $r[0]['parent'];
76 if($r[0]['id'] != $r[0]['parent']) {
77 $r = q("SELECT * FROM `item` WHERE `id` = `parent` AND `parent` = %d LIMIT 1",
83 if(($r === false) || (! count($r))) {
84 notice( t('Unable to locate original post.') . EOL);
85 if(x($_POST,'return'))
86 goaway($a->get_baseurl() . "/" . $return_path );
90 $parent = $r[0]['id'];
92 // multi-level threading - preserve the info but re-parent to our single level threading
93 if(($parid) && ($parid != $parent))
94 $thr_parent = $parent_uri;
96 if($parent_item['contact-id'] && $uid) {
97 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
98 intval($parent_item['contact-id']),
102 $parent_contact = $r[0];
106 if($parent) logger('mod_post: parent=' . $parent);
108 $profile_uid = ((x($_POST,'profile_uid')) ? intval($_POST['profile_uid']) : 0);
109 $post_id = ((x($_POST['post_id'])) ? intval($_POST['post_id']) : 0);
110 $app = ((x($_POST['source'])) ? strip_tags($_POST['source']) : '');
112 if(! can_write_wall($a,$profile_uid)) {
113 notice( t('Permission denied.') . EOL) ;
114 if(x($_POST,'return'))
115 goaway($a->get_baseurl() . "/" . $return_path );
120 // is this an edited post?
125 $i = q("SELECT * FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
126 intval($profile_uid),
136 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
143 $str_group_allow = $orig_post['allow_gid'];
144 $str_contact_allow = $orig_post['allow_cid'];
145 $str_group_deny = $orig_post['deny_gid'];
146 $str_contact_deny = $orig_post['deny_cid'];
147 $title = $orig_post['title'];
148 $location = $orig_post['location'];
149 $coord = $orig_post['coord'];
150 $verb = $orig_post['verb'];
151 $emailcc = $orig_post['emailcc'];
152 $app = $orig_post['app'];
154 $body = escape_tags(trim($_POST['body']));
155 $private = $orig_post['private'];
156 $pubmail_enable = $orig_post['pubmail'];
159 $str_group_allow = perms2str($_POST['group_allow']);
160 $str_contact_allow = perms2str($_POST['contact_allow']);
161 $str_group_deny = perms2str($_POST['group_deny']);
162 $str_contact_deny = perms2str($_POST['contact_deny']);
163 $title = notags(trim($_POST['title']));
164 $location = notags(trim($_POST['location']));
165 $coord = notags(trim($_POST['coord']));
166 $verb = notags(trim($_POST['verb']));
167 $emailcc = notags(trim($_POST['emailcc']));
169 $body = escape_tags(trim($_POST['body']));
170 $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);
173 (($parent_item['private'])
174 || strlen($parent_item['allow_cid'])
175 || strlen($parent_item['allow_gid'])
176 || strlen($parent_item['deny_cid'])
177 || strlen($parent_item['deny_gid'])
182 $pubmail_enable = ((x($_POST,'pubmail_enable') && intval($_POST['pubmail_enable']) && (! $private)) ? 1 : 0);
184 // if using the API, we won't see pubmail_enable - figure out if it should be set
186 if($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) {
187 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
188 if(! $mail_disabled) {
189 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
192 if(count($r) && intval($r[0]['pubmail']))
193 $pubmail_enabled = true;
198 if(! strlen($body)) {
199 info( t('Empty post discarded.') . EOL );
200 if(x($_POST,'return'))
201 goaway($a->get_baseurl() . "/" . $return_path );
206 // get contact info for poster
211 if(($_SESSION['uid']) && ($_SESSION['uid'] == $profile_uid)) {
213 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
214 intval($_SESSION['uid'])
218 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
219 $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
220 intval($_SESSION['visitor_id'])
227 $contact_id = $author['id'];
230 // get contact info for owner
232 if($profile_uid == $_SESSION['uid']) {
233 $contact_record = $author;
236 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
240 $contact_record = $r[0];
245 $post_type = notags(trim($_POST['type']));
247 if($post_type === 'net-comment') {
248 if($parent_item !== null) {
249 if($parent_item['wall'] == 1)
250 $post_type = 'wall-comment';
252 $post_type = 'remote-comment';
258 * When a photo was uploaded into the message using the (profile wall) ajax
259 * uploader, The permissions are initially set to disallow anybody but the
260 * owner from seeing it. This is because the permissions may not yet have been
261 * set for the post. If it's private, the photo permissions should be set
262 * appropriately. But we didn't know the final permissions on the post until
263 * now. So now we'll look for links of uploaded messages that are in the
264 * post and set them to the same permissions as the post itself.
270 if(preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) {
273 foreach($images as $image) {
274 if(! stristr($image,$a->get_baseurl() . '/photo/'))
276 $image_uri = substr($image,strrpos($image,'/') + 1);
277 $image_uri = substr($image_uri,0, strpos($image_uri,'-'));
278 if(! strlen($image_uri))
280 $srch = '<' . intval($profile_uid) . '>';
281 $r = q("SELECT `id` FROM `photo` WHERE `allow_cid` = '%s' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = ''
282 AND `resource-id` = '%s' AND `uid` = %d LIMIT 1",
291 $r = q("UPDATE `photo` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
292 WHERE `resource-id` = '%s' AND `uid` = %d AND `album` = '%s' ",
293 dbesc($str_contact_allow),
294 dbesc($str_group_allow),
295 dbesc($str_contact_deny),
296 dbesc($str_group_deny),
298 intval($profile_uid),
299 dbesc( t('Wall Photos'))
308 * Next link in any attachment references we find in the post.
313 if(preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",$body,$match)) {
314 $attaches = $match[1];
315 if(count($attaches)) {
316 foreach($attaches as $attach) {
317 $r = q("SELECT * FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
318 intval($profile_uid),
322 $r = q("UPDATE `attach` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
323 WHERE `uid` = %d AND `id` = %d LIMIT 1",
324 dbesc($str_contact_allow),
325 dbesc($str_group_allow),
326 dbesc($str_contact_deny),
327 dbesc($str_group_deny),
328 intval($profile_uid),
336 // embedded bookmark in post? convert to regular url and set bookmark flag
339 if(preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/m",$body,$match)) {
341 $body = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/m",'[url=$1]$2[/url]',$body);
346 * Fold multi-line [code] sequences
349 $body = preg_replace('/\[\/code\]\s*\[code\]/m',"\n",$body);
352 * Look for any tags and linkify them
359 $tags = get_tags($body);
362 * add a statusnet style reply tag if the original post was from there
363 * and we are replying, and there isn't one already
366 if(($parent_contact) && ($parent_contact['network'] === NETWORK_OSTATUS)
367 && ($parent_contact['nick']) && (! in_array('@' . $parent_contact['nick'],$tags))) {
368 $body = '@' . $parent_contact['nick'] . ' ' . $body;
369 $tags[] = '@' . $parent_contact['nick'];
373 foreach($tags as $tag) {
376 if(strpos($tag,'#') === 0) {
377 if(strpos($tag,'[url='))
379 $basetag = str_replace('_',' ',substr($tag,1));
380 $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
381 if(strlen($str_tags))
383 $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
386 if(strpos($tag,'@') === 0) {
387 if(strpos($tag,'[url='))
390 $name = substr($tag,1);
391 if((strpos($name,'@')) || (strpos($name,'http://'))) {
393 $links = @lrdd($name);
395 foreach($links as $link) {
396 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
397 $profile = $link['@attributes']['href'];
398 if($link['@attributes']['rel'] === 'salmon') {
401 $inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']);
409 if(strstr($name,'_') || strstr($name,' ')) {
410 $newname = str_replace('_',' ',$name);
411 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
417 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
424 $profile = $r[0]['url'];
425 if($r[0]['network'] === 'stat') {
426 $newname = $r[0]['nick'];
429 $alias = $r[0]['alias'];
432 $newname = $r[0]['name'];
435 $inform .= 'cid:' . $r[0]['id'];
439 $body = str_replace('@' . $name, '@' . '[url=' . $profile . ']' . $newname . '[/url]', $body);
440 $profile = str_replace(',','%2c',$profile);
441 if(strlen($str_tags))
443 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
445 // Status.Net seems to require the numeric ID URL in a mention if the person isn't
446 // subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
449 if(strlen($str_tags))
451 $str_tags .= '@[url=' . $alias . ']' . $newname . '[/url]';
461 if(preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) {
462 foreach($match[2] as $mtch) {
463 $r = q("SELECT `id`,`filename`,`filesize`,`filetype` FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
464 intval($profile_uid),
468 if(strlen($attachments))
470 $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]';
472 $body = str_replace($match[1],'',$body);
478 if($post_type === 'wall' || $post_type === 'wall-comment')
482 $verb = ACTIVITY_POST ;
484 $gravity = (($parent) ? 6 : 0 );
486 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
488 $uri = item_new_uri($a->get_hostname(),$profile_uid);
491 $datarray['uid'] = $profile_uid;
492 $datarray['type'] = $post_type;
493 $datarray['wall'] = $wall;
494 $datarray['gravity'] = $gravity;
495 $datarray['contact-id'] = $contact_id;
496 $datarray['owner-name'] = $contact_record['name'];
497 $datarray['owner-link'] = $contact_record['url'];
498 $datarray['owner-avatar'] = $contact_record['thumb'];
499 $datarray['author-name'] = $author['name'];
500 $datarray['author-link'] = $author['url'];
501 $datarray['author-avatar'] = $author['thumb'];
502 $datarray['created'] = datetime_convert();
503 $datarray['edited'] = datetime_convert();
504 $datarray['received'] = datetime_convert();
505 $datarray['changed'] = datetime_convert();
506 $datarray['uri'] = $uri;
507 $datarray['title'] = $title;
508 $datarray['body'] = $body;
509 $datarray['app'] = $app;
510 $datarray['location'] = $location;
511 $datarray['coord'] = $coord;
512 $datarray['tag'] = $str_tags;
513 $datarray['inform'] = $inform;
514 $datarray['verb'] = $verb;
515 $datarray['allow_cid'] = $str_contact_allow;
516 $datarray['allow_gid'] = $str_group_allow;
517 $datarray['deny_cid'] = $str_contact_deny;
518 $datarray['deny_gid'] = $str_group_deny;
519 $datarray['private'] = $private;
520 $datarray['pubmail'] = $pubmail_enable;
521 $datarray['attach'] = $attachments;
522 $datarray['bookmark'] = intval($bookmark);
523 $datarray['thr-parent'] = $thr_parent;
526 * These fields are for the convenience of plugins...
527 * 'self' if true indicates the owner is posting on their own wall
528 * If parent is 0 it is a top-level post.
531 $datarray['parent'] = $parent;
532 $datarray['self'] = $self;
533 $datarray['prvnets'] = $user['prvnets'];
536 $datarray['edit'] = true;
538 $datarray['guid'] = get_guid();
541 call_hooks('post_local',$datarray);
545 $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
547 dbesc(datetime_convert()),
552 proc_run('php', "include/notifier.php", 'edit_post', "$post_id");
553 if((x($_POST,'return')) && strlen($return_path)) {
554 logger('return: ' . $return_path);
555 goaway($a->get_baseurl() . "/" . $return_path );
563 $r = q("INSERT INTO `item` (`guid`, `uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
564 `author-name`, `author-link`, `author-avatar`, `created`, `edited`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`,
565 `tag`, `inform`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`, `bookmark` )
566 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', %d )",
567 dbesc($datarray['guid']),
568 intval($datarray['uid']),
569 dbesc($datarray['type']),
570 intval($datarray['wall']),
571 intval($datarray['gravity']),
572 intval($datarray['contact-id']),
573 dbesc($datarray['owner-name']),
574 dbesc($datarray['owner-link']),
575 dbesc($datarray['owner-avatar']),
576 dbesc($datarray['author-name']),
577 dbesc($datarray['author-link']),
578 dbesc($datarray['author-avatar']),
579 dbesc($datarray['created']),
580 dbesc($datarray['edited']),
581 dbesc($datarray['received']),
582 dbesc($datarray['changed']),
583 dbesc($datarray['uri']),
584 dbesc($datarray['thr-parent']),
585 dbesc($datarray['title']),
586 dbesc($datarray['body']),
587 dbesc($datarray['app']),
588 dbesc($datarray['location']),
589 dbesc($datarray['coord']),
590 dbesc($datarray['tag']),
591 dbesc($datarray['inform']),
592 dbesc($datarray['verb']),
593 dbesc($datarray['allow_cid']),
594 dbesc($datarray['allow_gid']),
595 dbesc($datarray['deny_cid']),
596 dbesc($datarray['deny_gid']),
597 intval($datarray['private']),
598 intval($datarray['pubmail']),
599 dbesc($datarray['attach']),
600 intval($datarray['bookmark'])
603 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
604 dbesc($datarray['uri']));
606 $post_id = $r[0]['id'];
607 logger('mod_item: saved item ' . $post_id);
611 // This item is the last leaf and gets the comment box, clear any ancestors
612 $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d ",
613 dbesc(datetime_convert()),
617 // Inherit ACL's from the parent item.
619 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d
620 WHERE `id` = %d LIMIT 1",
621 dbesc($parent_item['allow_cid']),
622 dbesc($parent_item['allow_gid']),
623 dbesc($parent_item['deny_cid']),
624 dbesc($parent_item['deny_gid']),
625 intval($parent_item['private']),
629 // Send a notification email to the conversation owner, unless the owner is me and I wrote this item
630 if(($user['notify-flags'] & NOTIFY_COMMENT) && ($contact_record != $author)) {
631 push_lang($user['language']);
632 require_once('bbcode.php');
633 $from = $author['name'];
635 // name of the automated email sender
636 $msg['notificationfromname'] = stripslashes($datarray['author-name']);;
637 // noreply address to send from
638 $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
641 // process the message body to display properly in text mode
643 = html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8');
646 // process the message body to display properly in text mode
648 = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$datarray['body']))));
650 // load the template for private message notifications
651 $tpl = get_intltext_template('cmnt_received_html_body_eml.tpl');
652 $email_html_body_tpl = replace_macros($tpl,array(
653 '$username' => $user['username'],
654 '$sitename' => $a->config['sitename'], // name of this site
655 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
656 '$thumb' => $author['thumb'], // thumbnail url for sender icon
657 '$email' => $importer['email'], // email address to send to
658 '$url' => $author['url'], // full url for the site
659 '$from' => $from, // name of the person sending the message
660 '$body' => $msg['htmlversion'], // html version of the message
661 '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
664 // load the template for private message notifications
665 $tpl = get_intltext_template('cmnt_received_text_body_eml.tpl');
666 $email_text_body_tpl = replace_macros($tpl,array(
667 '$username' => $user['username'],
668 '$sitename' => $a->config['sitename'], // name of this site
669 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
670 '$thumb' => $author['thumb'], // thumbnail url for sender icon
671 '$email' => $importer['email'], // email address to send to
672 '$url' => $author['url'], // profile url for the author
673 '$from' => $from, // name of the person sending the message
674 '$body' => $msg['textversion'], // text version of the message
675 '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
678 // use the EmailNotification library to send the message
679 require_once("include/EmailNotification.php");
680 EmailNotification::sendTextHtmlEmail(
681 $msg['notificationfromname'],
682 t("Administrator@") . $a->get_hostname(),
683 t("noreply") . '@' . $a->get_hostname(),
685 sprintf( t('%s commented on an item at %s'), $from , $a->config['sitename']),
686 $email_html_body_tpl,
693 // We won't be able to sign Diaspora comments for authenticated visitors - we don't have their private key
696 require_once('include/bb2diaspora.php');
697 $signed_body = html_entity_decode(bb2diaspora($datarray['body']));
698 $myaddr = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
699 if($datarray['verb'] === ACTIVITY_LIKE)
700 $signed_text = $datarray['guid'] . ';' . 'Post' . ';' . $parent_item['guid'] . ';' . 'true' . ';' . $myaddr;
702 $signed_text = $datarray['guid'] . ';' . $parent_item['guid'] . ';' . $signed_body . ';' . $myaddr;
704 $authorsig = base64_encode(rsa_sign($signed_text,$a->user['prvkey'],'sha'));
706 q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
709 dbesc(base64_encode($authorsig)),
717 // let me know if somebody did a wall-to-wall post on my profile
719 if(($user['notify-flags'] & NOTIFY_WALL) && ($contact_record != $author)) {
720 push_lang($user['language']);
721 require_once('bbcode.php');
722 $from = $author['name'];
724 // name of the automated email sender
725 $msg['notificationfromname'] = $from;
726 // noreply address to send from
727 $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
730 // process the message body to display properly in text mode
732 = html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8');
735 // process the message body to display properly in text mode
737 = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$datarray['body']))));
739 // load the template for private message notifications
740 $tpl = load_view_file('view/wall_received_html_body_eml.tpl');
741 $email_html_body_tpl = replace_macros($tpl,array(
742 '$username' => $user['username'],
743 '$sitename' => $a->config['sitename'], // name of this site
744 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
745 '$thumb' => $author['thumb'], // thumbnail url for sender icon
746 '$url' => $author['url'], // full url for the site
747 '$from' => $from, // name of the person sending the message
748 '$body' => $msg['htmlversion'], // html version of the message
749 '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
752 // load the template for private message notifications
753 $tpl = load_view_file('view/wall_received_text_body_eml.tpl');
754 $email_text_body_tpl = replace_macros($tpl,array(
755 '$username' => $user['username'],
756 '$sitename' => $a->config['sitename'], // name of this site
757 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
758 '$thumb' => $author['thumb'], // thumbnail url for sender icon
759 '$url' => $author['url'], // full url for the site
760 '$from' => $from, // name of the person sending the message
761 '$body' => $msg['textversion'], // text version of the message
762 '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
765 // use the EmailNotification library to send the message
766 require_once("include/EmailNotification.php");
767 EmailNotification::sendTextHtmlEmail(
768 $msg['notificationfromname'],
769 t("Administrator@") . $a->get_hostname(),
770 t("noreply") . '@' . $a->get_hostname(),
772 sprintf( t('%s posted to your profile wall at %s') , $from , $a->config['sitename']),
773 $email_html_body_tpl,
780 $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `plink` = '%s', `changed` = '%s', `last-child` = 1, `visible` = 1
781 WHERE `id` = %d LIMIT 1",
783 dbesc(($parent == $post_id) ? $uri : $parent_item['uri']),
784 dbesc($a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id),
785 dbesc(datetime_convert()),
789 // photo comments turn the corresponding item visible to the profile wall
790 // This way we don't see every picture in your new photo album posted to your wall at once.
791 // They will show up as people comment on them.
793 if(! $parent_item['visible']) {
794 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d LIMIT 1",
795 intval($parent_item['id'])
800 logger('mod_item: unable to retrieve post that was just stored.');
801 notify( t('System error. Post not saved.'));
802 goaway($a->get_baseurl() . "/" . $return_path );
807 $datarray['id'] = $post_id;
808 $datarray['plink'] = $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id;
810 call_hooks('post_local_end', $datarray);
812 if(strlen($emailcc) && $profile_uid == local_user()) {
813 $erecips = explode(',', $emailcc);
814 if(count($erecips)) {
815 foreach($erecips as $recip) {
816 $addr = trim($recip);
819 $disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendika social network.'),$a->user['username'])
821 $disclaimer .= sprintf( t('You may visit them online at %s'), $a->get_baseurl() . '/profile/' . $a->user['nickname']) . EOL;
822 $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
824 $subject = '[Friendika]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']);
825 $headers = 'From: ' . $a->user['username'] . ' <' . $a->user['email'] . '>' . "\n";
826 $headers .= 'MIME-Version: 1.0' . "\n";
827 $headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
828 $headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n";
829 $link = '<a href="' . $a->get_baseurl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
830 $html = prepare_body($datarray);
831 $message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
832 @mail($addr, $subject, $message, $headers);
837 // This is a real juggling act on shared hosting services which kill your processes
838 // e.g. dreamhost. We used to start delivery to our native delivery agents in the background
839 // and then run our plugin delivery from the foreground. We're now doing plugin delivery first,
840 // because as soon as you start loading up a bunch of remote delivey processes, *this* page is
841 // likely to get killed off. If you end up looking at an /item URL and a blank page,
842 // it's very likely the delivery got killed before all your friends could be notified.
843 // Currently the only realistic fixes are to use a reliable server - which precludes shared hosting,
844 // or cut back on plugins which do remote deliveries.
846 proc_run('php', "include/notifier.php", $notify_type, "$post_id");
848 logger('post_complete');
850 // figure out how to return, depending on from whence we came
856 goaway($a->get_baseurl() . "/" . $return_path);
859 $json = array('success' => 1);
860 if(x($_POST,'jsreload') && strlen($_POST['jsreload']))
861 $json['reload'] = $a->get_baseurl() . '/' . $_POST['jsreload'];
863 logger('post_json: ' . print_r($json,true), LOGGER_DEBUG);
865 echo json_encode($json);
874 function item_content(&$a) {
876 if((! local_user()) && (! remote_user()))
879 require_once('include/security.php');
881 if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
882 require_once('include/items.php');
883 drop_item($a->argv[2]);