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');
19 require_once('include/enotify.php');
21 function item_post(&$a) {
23 if((! local_user()) && (! remote_user()))
26 require_once('include/security.php');
30 if(x($_POST,'dropitems')) {
31 require_once('include/items.php');
32 $arr_drop = explode(',',$_POST['dropitems']);
33 drop_items($arr_drop);
34 $json = array('success' => 1);
35 echo json_encode($json);
39 call_hooks('post_local_start', $_POST);
41 $api_source = ((x($_POST,'api_source') && $_POST['api_source']) ? true : false);
42 $return_path = ((x($_POST,'return')) ? $_POST['return'] : '');
45 * Is this a reply to something?
48 $parent = ((x($_POST,'parent')) ? intval($_POST['parent']) : 0);
49 $parent_uri = ((x($_POST,'parent_uri')) ? trim($_POST['parent_uri']) : '');
52 $parent_contact = null;
57 $preview = ((x($_POST,'preview')) ? intval($_POST['preview']) : 0);
59 if($parent || $parent_uri) {
61 if(! x($_POST,'type'))
62 $_POST['type'] = 'net-comment';
65 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
69 elseif($parent_uri && local_user()) {
70 // This is coming from an API source, and we are logged in
71 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
76 // if this isn't the real parent of the conversation, find it
77 if($r !== false && count($r)) {
78 $parid = $r[0]['parent'];
79 if($r[0]['id'] != $r[0]['parent']) {
80 $r = q("SELECT * FROM `item` WHERE `id` = `parent` AND `parent` = %d LIMIT 1",
86 if(($r === false) || (! count($r))) {
87 notice( t('Unable to locate original post.') . EOL);
88 if(x($_POST,'return'))
89 goaway($a->get_baseurl() . "/" . $return_path );
93 $parent = $r[0]['id'];
95 // multi-level threading - preserve the info but re-parent to our single level threading
96 if(($parid) && ($parid != $parent))
97 $thr_parent = $parent_uri;
99 if($parent_item['contact-id'] && $uid) {
100 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
101 intval($parent_item['contact-id']),
105 $parent_contact = $r[0];
109 if($parent) logger('mod_post: parent=' . $parent);
111 $profile_uid = ((x($_POST,'profile_uid')) ? intval($_POST['profile_uid']) : 0);
112 $post_id = ((x($_POST['post_id'])) ? intval($_POST['post_id']) : 0);
113 $app = ((x($_POST['source'])) ? strip_tags($_POST['source']) : '');
115 if(! can_write_wall($a,$profile_uid)) {
116 notice( t('Permission denied.') . EOL) ;
117 if(x($_POST,'return'))
118 goaway($a->get_baseurl() . "/" . $return_path );
123 // is this an edited post?
128 $i = q("SELECT * FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
129 intval($profile_uid),
139 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
146 $str_group_allow = $orig_post['allow_gid'];
147 $str_contact_allow = $orig_post['allow_cid'];
148 $str_group_deny = $orig_post['deny_gid'];
149 $str_contact_deny = $orig_post['deny_cid'];
150 $title = $orig_post['title'];
151 $location = $orig_post['location'];
152 $coord = $orig_post['coord'];
153 $verb = $orig_post['verb'];
154 $emailcc = $orig_post['emailcc'];
155 $app = $orig_post['app'];
157 $body = escape_tags(trim($_POST['body']));
158 $private = $orig_post['private'];
159 $pubmail_enable = $orig_post['pubmail'];
162 $str_group_allow = perms2str($_POST['group_allow']);
163 $str_contact_allow = perms2str($_POST['contact_allow']);
164 $str_group_deny = perms2str($_POST['group_deny']);
165 $str_contact_deny = perms2str($_POST['contact_deny']);
166 $title = notags(trim($_POST['title']));
167 $location = notags(trim($_POST['location']));
168 $coord = notags(trim($_POST['coord']));
169 $verb = notags(trim($_POST['verb']));
170 $emailcc = notags(trim($_POST['emailcc']));
172 $body = escape_tags(trim($_POST['body']));
173 $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);
176 (($parent_item['private'])
177 || strlen($parent_item['allow_cid'])
178 || strlen($parent_item['allow_gid'])
179 || strlen($parent_item['deny_cid'])
180 || strlen($parent_item['deny_gid'])
185 $pubmail_enable = ((x($_POST,'pubmail_enable') && intval($_POST['pubmail_enable']) && (! $private)) ? 1 : 0);
187 // if using the API, we won't see pubmail_enable - figure out if it should be set
189 if($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) {
190 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
191 if(! $mail_disabled) {
192 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
195 if(count($r) && intval($r[0]['pubmail']))
196 $pubmail_enabled = true;
201 if(! strlen($body)) {
202 info( t('Empty post discarded.') . EOL );
203 if(x($_POST,'return'))
204 goaway($a->get_baseurl() . "/" . $return_path );
210 && (! array_key_exists('allow_cid',$_REQUEST))
211 && (! array_key_exists('allow_gid',$_REQUEST))
212 && (! array_key_exists('deny_cid',$_REQUEST))
213 && (! array_key_exists('deny_gid',$_REQUEST))) {
214 $str_group_allow = $user['allow_gid'];
215 $str_contact_allow = $user['allow_cid'];
216 $str_group_deny = $user['deny_gid'];
217 $str_contact_deny = $user['deny_cid'];
221 // get contact info for poster
226 if(($_SESSION['uid']) && ($_SESSION['uid'] == $profile_uid)) {
228 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
229 intval($_SESSION['uid'])
233 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
234 $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
235 intval($_SESSION['visitor_id'])
242 $contact_id = $author['id'];
245 // get contact info for owner
247 if($profile_uid == $_SESSION['uid']) {
248 $contact_record = $author;
251 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
255 $contact_record = $r[0];
260 $post_type = notags(trim($_POST['type']));
262 if($post_type === 'net-comment') {
263 if($parent_item !== null) {
264 if($parent_item['wall'] == 1)
265 $post_type = 'wall-comment';
267 $post_type = 'remote-comment';
273 * When a photo was uploaded into the message using the (profile wall) ajax
274 * uploader, The permissions are initially set to disallow anybody but the
275 * owner from seeing it. This is because the permissions may not yet have been
276 * set for the post. If it's private, the photo permissions should be set
277 * appropriately. But we didn't know the final permissions on the post until
278 * now. So now we'll look for links of uploaded messages that are in the
279 * post and set them to the same permissions as the post itself.
285 if((! $preview) && preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) {
288 foreach($images as $image) {
289 if(! stristr($image,$a->get_baseurl() . '/photo/'))
291 $image_uri = substr($image,strrpos($image,'/') + 1);
292 $image_uri = substr($image_uri,0, strpos($image_uri,'-'));
293 if(! strlen($image_uri))
295 $srch = '<' . intval($profile_uid) . '>';
296 $r = q("SELECT `id` FROM `photo` WHERE `allow_cid` = '%s' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = ''
297 AND `resource-id` = '%s' AND `uid` = %d LIMIT 1",
306 $r = q("UPDATE `photo` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
307 WHERE `resource-id` = '%s' AND `uid` = %d AND `album` = '%s' ",
308 dbesc($str_contact_allow),
309 dbesc($str_group_allow),
310 dbesc($str_contact_deny),
311 dbesc($str_group_deny),
313 intval($profile_uid),
314 dbesc( t('Wall Photos'))
323 * Next link in any attachment references we find in the post.
328 if((! $preview) && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",$body,$match)) {
329 $attaches = $match[1];
330 if(count($attaches)) {
331 foreach($attaches as $attach) {
332 $r = q("SELECT * FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
333 intval($profile_uid),
337 $r = q("UPDATE `attach` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
338 WHERE `uid` = %d AND `id` = %d LIMIT 1",
339 dbesc($str_contact_allow),
340 dbesc($str_group_allow),
341 dbesc($str_contact_deny),
342 dbesc($str_group_deny),
343 intval($profile_uid),
351 // embedded bookmark in post? set bookmark flag
354 if(preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",$body,$match,PREG_SET_ORDER)) {
358 $body = bb_translate_video($body);
361 * Fold multi-line [code] sequences
364 $body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body);
367 * Look for any tags and linkify them
374 $tags = get_tags($body);
377 * add a statusnet style reply tag if the original post was from there
378 * and we are replying, and there isn't one already
381 if(($parent_contact) && ($parent_contact['network'] === NETWORK_OSTATUS)
382 && ($parent_contact['nick']) && (! in_array('@' . $parent_contact['nick'],$tags))) {
383 $body = '@' . $parent_contact['nick'] . ' ' . $body;
384 $tags[] = '@' . $parent_contact['nick'];
388 foreach($tags as $tag) {
392 if(strpos($tag,'#') === 0) {
393 if(strpos($tag,'[url='))
395 $basetag = str_replace('_',' ',substr($tag,1));
396 $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
398 $newtag = '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
399 if(! stristr($str_tags,$newtag)) {
400 if(strlen($str_tags))
402 $str_tags .= $newtag;
406 if(strpos($tag,'@') === 0) {
407 if(strpos($tag,'[url='))
410 $name = substr($tag,1);
411 if((strpos($name,'@')) || (strpos($name,'http://'))) {
413 $links = @lrdd($name);
415 foreach($links as $link) {
416 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
417 $profile = $link['@attributes']['href'];
418 if($link['@attributes']['rel'] === 'salmon') {
421 $inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']);
430 if(strrpos($newname,'+')) {
431 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
432 if(strpos($name,' '))
433 $name = substr($name,0,strpos($name,' '));
436 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
441 elseif(strstr($name,'_') || strstr($name,' ')) {
442 $newname = str_replace('_',' ',$name);
443 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
449 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
456 $profile = $r[0]['url'];
457 if($r[0]['network'] === 'stat') {
458 $newname = $r[0]['nick'];
461 $alias = $r[0]['alias'];
464 $newname = $r[0]['name'];
467 $inform .= 'cid:' . $r[0]['id'];
471 $body = str_replace('@' . $name, '@' . '[url=' . $profile . ']' . $newname . '[/url]', $body);
472 $profile = str_replace(',','%2c',$profile);
473 $newtag = '@[url=' . $profile . ']' . $newname . '[/url]';
474 if(! stristr($str_tags,$newtag)) {
475 if(strlen($str_tags))
477 $str_tags .= $newtag;
480 // Status.Net seems to require the numeric ID URL in a mention if the person isn't
481 // subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
484 $newtag = '@[url=' . $alias . ']' . $newname . '[/url]';
485 if(! stristr($str_tags,$newtag)) {
486 if(strlen($str_tags))
488 $str_tags .= $newtag;
499 if(preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) {
500 foreach($match[2] as $mtch) {
501 $r = q("SELECT `id`,`filename`,`filesize`,`filetype` FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
502 intval($profile_uid),
506 if(strlen($attachments))
508 $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]';
510 $body = str_replace($match[1],'',$body);
516 if($post_type === 'wall' || $post_type === 'wall-comment')
520 $verb = ACTIVITY_POST ;
522 $gravity = (($parent) ? 6 : 0 );
524 // even if the post arrived via API we are considering that it
525 // originated on this site by default for determining relayability.
527 $origin = ((x($_REQUEST,'origin')) ? intval($_REQUEST['origin']) : 1);
529 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
531 $uri = item_new_uri($a->get_hostname(),$profile_uid);
534 $datarray['uid'] = $profile_uid;
535 $datarray['type'] = $post_type;
536 $datarray['wall'] = $wall;
537 $datarray['gravity'] = $gravity;
538 $datarray['contact-id'] = $contact_id;
539 $datarray['owner-name'] = $contact_record['name'];
540 $datarray['owner-link'] = $contact_record['url'];
541 $datarray['owner-avatar'] = $contact_record['thumb'];
542 $datarray['author-name'] = $author['name'];
543 $datarray['author-link'] = $author['url'];
544 $datarray['author-avatar'] = $author['thumb'];
545 $datarray['created'] = datetime_convert();
546 $datarray['edited'] = datetime_convert();
547 $datarray['commented'] = datetime_convert();
548 $datarray['received'] = datetime_convert();
549 $datarray['changed'] = datetime_convert();
550 $datarray['uri'] = $uri;
551 $datarray['title'] = $title;
552 $datarray['body'] = $body;
553 $datarray['app'] = $app;
554 $datarray['location'] = $location;
555 $datarray['coord'] = $coord;
556 $datarray['tag'] = $str_tags;
557 $datarray['inform'] = $inform;
558 $datarray['verb'] = $verb;
559 $datarray['allow_cid'] = $str_contact_allow;
560 $datarray['allow_gid'] = $str_group_allow;
561 $datarray['deny_cid'] = $str_contact_deny;
562 $datarray['deny_gid'] = $str_group_deny;
563 $datarray['private'] = $private;
564 $datarray['pubmail'] = $pubmail_enable;
565 $datarray['attach'] = $attachments;
566 $datarray['bookmark'] = intval($bookmark);
567 $datarray['thr-parent'] = $thr_parent;
568 $datarray['postopts'] = '';
569 $datarray['origin'] = $origin;
572 * These fields are for the convenience of plugins...
573 * 'self' if true indicates the owner is posting on their own wall
574 * If parent is 0 it is a top-level post.
577 $datarray['parent'] = $parent;
578 $datarray['self'] = $self;
579 // $datarray['prvnets'] = $user['prvnets'];
582 $datarray['edit'] = true;
584 $datarray['guid'] = get_guid();
586 // preview mode - prepare the body for display and send it via json
589 require_once('include/conversation.php');
590 $o = conversation(&$a,array(array_merge($contact_record,$datarray)),'search',false,true);
591 echo json_encode(array('preview' => $o));
596 call_hooks('post_local',$datarray);
600 $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
602 dbesc(datetime_convert()),
607 proc_run('php', "include/notifier.php", 'edit_post', "$post_id");
608 if((x($_POST,'return')) && strlen($return_path)) {
609 logger('return: ' . $return_path);
610 goaway($a->get_baseurl() . "/" . $return_path );
618 $r = q("INSERT INTO `item` (`guid`, `uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
619 `author-name`, `author-link`, `author-avatar`, `created`, `edited`, `commented`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`,
620 `tag`, `inform`, `verb`, `postopts`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`, `bookmark`,`origin` )
621 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', '%s', '%s', %d, %d, '%s', %d, %d )",
622 dbesc($datarray['guid']),
623 intval($datarray['uid']),
624 dbesc($datarray['type']),
625 intval($datarray['wall']),
626 intval($datarray['gravity']),
627 intval($datarray['contact-id']),
628 dbesc($datarray['owner-name']),
629 dbesc($datarray['owner-link']),
630 dbesc($datarray['owner-avatar']),
631 dbesc($datarray['author-name']),
632 dbesc($datarray['author-link']),
633 dbesc($datarray['author-avatar']),
634 dbesc($datarray['created']),
635 dbesc($datarray['edited']),
636 dbesc($datarray['commented']),
637 dbesc($datarray['received']),
638 dbesc($datarray['changed']),
639 dbesc($datarray['uri']),
640 dbesc($datarray['thr-parent']),
641 dbesc($datarray['title']),
642 dbesc($datarray['body']),
643 dbesc($datarray['app']),
644 dbesc($datarray['location']),
645 dbesc($datarray['coord']),
646 dbesc($datarray['tag']),
647 dbesc($datarray['inform']),
648 dbesc($datarray['verb']),
649 dbesc($datarray['postopts']),
650 dbesc($datarray['allow_cid']),
651 dbesc($datarray['allow_gid']),
652 dbesc($datarray['deny_cid']),
653 dbesc($datarray['deny_gid']),
654 intval($datarray['private']),
655 intval($datarray['pubmail']),
656 dbesc($datarray['attach']),
657 intval($datarray['bookmark']),
658 intval($datarray['origin'])
661 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
662 dbesc($datarray['uri']));
664 $post_id = $r[0]['id'];
665 logger('mod_item: saved item ' . $post_id);
669 // This item is the last leaf and gets the comment box, clear any ancestors
670 $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d ",
671 dbesc(datetime_convert()),
675 // Inherit ACL's from the parent item.
677 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d
678 WHERE `id` = %d LIMIT 1",
679 dbesc($parent_item['allow_cid']),
680 dbesc($parent_item['allow_gid']),
681 dbesc($parent_item['deny_cid']),
682 dbesc($parent_item['deny_gid']),
683 intval($parent_item['private']),
687 if($contact_record != $author) {
689 'type' => NOTIFY_COMMENT,
690 'notify_flags' => $user['notify-flags'],
691 'language' => $user['language'],
692 'to_name' => $user['username'],
693 'to_email' => $user['email'],
695 'link' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
696 'source_name' => $datarray['author-name'],
697 'source_link' => $datarray['author-link'],
698 'source_photo' => $datarray['author-avatar'],
699 'verb' => ACTIVITY_POST,
705 // We won't be able to sign Diaspora comments for authenticated visitors - we don't have their private key
708 require_once('include/bb2diaspora.php');
709 $signed_body = html_entity_decode(bb2diaspora($datarray['body']));
710 $myaddr = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
711 if($datarray['verb'] === ACTIVITY_LIKE)
712 $signed_text = $datarray['guid'] . ';' . 'Post' . ';' . $parent_item['guid'] . ';' . 'true' . ';' . $myaddr;
714 $signed_text = $datarray['guid'] . ';' . $parent_item['guid'] . ';' . $signed_body . ';' . $myaddr;
716 $authorsig = base64_encode(rsa_sign($signed_text,$a->user['prvkey'],'sha256'));
718 q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
721 dbesc(base64_encode($authorsig)),
729 if($contact_record != $author) {
731 'type' => NOTIFY_WALL,
732 'notify_flags' => $user['notify-flags'],
733 'language' => $user['language'],
734 'to_name' => $user['username'],
735 'to_email' => $user['email'],
737 'link' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
738 'source_name' => $datarray['author-name'],
739 'source_link' => $datarray['author-link'],
740 'source_photo' => $datarray['author-avatar'],
741 'verb' => ACTIVITY_POST,
747 // fallback so that parent always gets set to non-zero.
752 $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `plink` = '%s', `changed` = '%s', `last-child` = 1, `visible` = 1
753 WHERE `id` = %d LIMIT 1",
755 dbesc(($parent == $post_id) ? $uri : $parent_item['uri']),
756 dbesc($a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id),
757 dbesc(datetime_convert()),
761 // photo comments turn the corresponding item visible to the profile wall
762 // This way we don't see every picture in your new photo album posted to your wall at once.
763 // They will show up as people comment on them.
765 if(! $parent_item['visible']) {
766 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d LIMIT 1",
767 intval($parent_item['id'])
772 logger('mod_item: unable to retrieve post that was just stored.');
773 notify( t('System error. Post not saved.'));
774 goaway($a->get_baseurl() . "/" . $return_path );
778 // update the commented timestamp on the parent
780 q("UPDATE `item` set `commented` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
781 dbesc(datetime_convert()),
782 dbesc(datetime_convert()),
786 $datarray['id'] = $post_id;
787 $datarray['plink'] = $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id;
789 call_hooks('post_local_end', $datarray);
791 if(strlen($emailcc) && $profile_uid == local_user()) {
792 $erecips = explode(',', $emailcc);
793 if(count($erecips)) {
794 foreach($erecips as $recip) {
795 $addr = trim($recip);
798 $disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendica social network.'),$a->user['username'])
800 $disclaimer .= sprintf( t('You may visit them online at %s'), $a->get_baseurl() . '/profile/' . $a->user['nickname']) . EOL;
801 $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
803 $subject = '[Friendica]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']);
804 $headers = 'From: ' . $a->user['username'] . ' <' . $a->user['email'] . '>' . "\n";
805 $headers .= 'MIME-Version: 1.0' . "\n";
806 $headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
807 $headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n";
808 $link = '<a href="' . $a->get_baseurl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
809 $html = prepare_body($datarray);
810 $message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
811 @mail($addr, $subject, $message, $headers);
816 // This is a real juggling act on shared hosting services which kill your processes
817 // e.g. dreamhost. We used to start delivery to our native delivery agents in the background
818 // and then run our plugin delivery from the foreground. We're now doing plugin delivery first,
819 // because as soon as you start loading up a bunch of remote delivey processes, *this* page is
820 // likely to get killed off. If you end up looking at an /item URL and a blank page,
821 // it's very likely the delivery got killed before all your friends could be notified.
822 // Currently the only realistic fixes are to use a reliable server - which precludes shared hosting,
823 // or cut back on plugins which do remote deliveries.
825 proc_run('php', "include/notifier.php", $notify_type, "$post_id");
827 logger('post_complete');
829 // figure out how to return, depending on from whence we came
835 goaway($a->get_baseurl() . "/" . $return_path);
838 $json = array('success' => 1);
839 if(x($_POST,'jsreload') && strlen($_POST['jsreload']))
840 $json['reload'] = $a->get_baseurl() . '/' . $_POST['jsreload'];
842 logger('post_json: ' . print_r($json,true), LOGGER_DEBUG);
844 echo json_encode($json);
853 function item_content(&$a) {
855 if((! local_user()) && (! remote_user()))
858 require_once('include/security.php');
860 if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
861 require_once('include/items.php');
862 drop_item($a->argv[2]);