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');
20 require_once('include/email.php');
22 function item_post(&$a) {
24 if((! local_user()) && (! remote_user()) && (! x($_REQUEST,'commenter')))
27 require_once('include/security.php');
31 if(x($_REQUEST,'dropitems')) {
32 require_once('include/items.php');
33 $arr_drop = explode(',',$_REQUEST['dropitems']);
34 drop_items($arr_drop);
35 $json = array('success' => 1);
36 echo json_encode($json);
40 call_hooks('post_local_start', $_REQUEST);
41 // logger('postinput ' . file_get_contents('php://input'));
42 logger('postvars ' . print_r($_REQUEST,true), LOGGER_DATA);
44 $api_source = ((x($_REQUEST,'api_source') && $_REQUEST['api_source']) ? true : false);
45 $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
46 $preview = ((x($_REQUEST,'preview')) ? intval($_REQUEST['preview']) : 0);
49 * Is this a reply to something?
52 $parent = ((x($_REQUEST,'parent')) ? intval($_REQUEST['parent']) : 0);
53 $parent_uri = ((x($_REQUEST,'parent_uri')) ? trim($_REQUEST['parent_uri']) : '');
56 $parent_contact = null;
61 if($parent || $parent_uri) {
63 if(! x($_REQUEST,'type'))
64 $_REQUEST['type'] = 'net-comment';
67 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
71 elseif($parent_uri && local_user()) {
72 // This is coming from an API source, and we are logged in
73 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
78 // if this isn't the real parent of the conversation, find it
79 if($r !== false && count($r)) {
80 $parid = $r[0]['parent'];
81 if($r[0]['id'] != $r[0]['parent']) {
82 $r = q("SELECT * FROM `item` WHERE `id` = `parent` AND `parent` = %d LIMIT 1",
88 if(($r === false) || (! count($r))) {
89 notice( t('Unable to locate original post.') . EOL);
90 if(x($_REQUEST,'return'))
91 goaway($a->get_baseurl() . "/" . $return_path );
95 $parent = $r[0]['id'];
97 // multi-level threading - preserve the info but re-parent to our single level threading
98 if(($parid) && ($parid != $parent))
99 $thr_parent = $parent_uri;
101 if($parent_item['contact-id'] && $uid) {
102 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
103 intval($parent_item['contact-id']),
107 $parent_contact = $r[0];
111 if($parent) logger('mod_post: parent=' . $parent);
113 $profile_uid = ((x($_REQUEST,'profile_uid')) ? intval($_REQUEST['profile_uid']) : 0);
114 $post_id = ((x($_REQUEST,'post_id')) ? intval($_REQUEST['post_id']) : 0);
115 $app = ((x($_REQUEST,'source')) ? strip_tags($_REQUEST['source']) : '');
117 $allow_moderated = false;
119 // here is where we are going to check for permission to post a moderated comment.
121 // First check that the parent exists and it is a wall item.
123 if((x($_REQUEST,'commenter')) && ((! $parent) || (! $parent_item['wall']))) {
124 notice( t('Permission denied.') . EOL) ;
125 if(x($_REQUEST,'return'))
126 goaway($a->get_baseurl() . "/" . $return_path );
130 // Now check that it is a page_type of PAGE_BLOG, and that valid personal details
131 // have been provided, and run any anti-spam plugins
139 if((! can_write_wall($a,$profile_uid)) && (! $allow_moderated)) {
140 notice( t('Permission denied.') . EOL) ;
141 if(x($_REQUEST,'return'))
142 goaway($a->get_baseurl() . "/" . $return_path );
147 // is this an edited post?
152 $i = q("SELECT * FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
153 intval($profile_uid),
163 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
170 $str_group_allow = $orig_post['allow_gid'];
171 $str_contact_allow = $orig_post['allow_cid'];
172 $str_group_deny = $orig_post['deny_gid'];
173 $str_contact_deny = $orig_post['deny_cid'];
174 $title = $orig_post['title'];
175 $location = $orig_post['location'];
176 $coord = $orig_post['coord'];
177 $verb = $orig_post['verb'];
178 $emailcc = $orig_post['emailcc'];
179 $app = $orig_post['app'];
181 $body = escape_tags(trim($_REQUEST['body']));
182 $private = $orig_post['private'];
183 $pubmail_enable = $orig_post['pubmail'];
187 // if coming from the API and no privacy settings are set,
188 // use the user default permissions - as they won't have
189 // been supplied via a form.
192 && (! array_key_exists('contact_allow',$_REQUEST))
193 && (! array_key_exists('group_allow',$_REQUEST))
194 && (! array_key_exists('contact_deny',$_REQUEST))
195 && (! array_key_exists('group_deny',$_REQUEST))) {
196 $str_group_allow = $user['allow_gid'];
197 $str_contact_allow = $user['allow_cid'];
198 $str_group_deny = $user['deny_gid'];
199 $str_contact_deny = $user['deny_cid'];
203 // use the posted permissions
205 $str_group_allow = perms2str($_REQUEST['group_allow']);
206 $str_contact_allow = perms2str($_REQUEST['contact_allow']);
207 $str_group_deny = perms2str($_REQUEST['group_deny']);
208 $str_contact_deny = perms2str($_REQUEST['contact_deny']);
211 $title = notags(trim($_REQUEST['title']));
212 $location = notags(trim($_REQUEST['location']));
213 $coord = notags(trim($_REQUEST['coord']));
214 $verb = notags(trim($_REQUEST['verb']));
215 $emailcc = notags(trim($_REQUEST['emailcc']));
217 $body = escape_tags(trim($_REQUEST['body']));
218 $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);
221 (($parent_item['private'])
222 || strlen($parent_item['allow_cid'])
223 || strlen($parent_item['allow_gid'])
224 || strlen($parent_item['deny_cid'])
225 || strlen($parent_item['deny_gid'])
230 $pubmail_enable = ((x($_REQUEST,'pubmail_enable') && intval($_REQUEST['pubmail_enable']) && (! $private)) ? 1 : 0);
232 // if using the API, we won't see pubmail_enable - figure out if it should be set
234 if($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) {
235 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
236 if(! $mail_disabled) {
237 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
240 if(count($r) && intval($r[0]['pubmail']))
241 $pubmail_enabled = true;
247 if(! strlen($body)) {
250 info( t('Empty post discarded.') . EOL );
251 if(x($_REQUEST,'return'))
252 goaway($a->get_baseurl() . "/" . $return_path );
257 // Work around doubled linefeeds in Tinymce 3.5b2
258 // First figure out if it's a status post that would've been
259 // created using tinymce. Otherwise leave it alone.
261 $plaintext = (local_user() ? intval(get_pconfig(local_user(),'system','plaintext')) : 0);
262 if((! $parent) && (! $api_source) && (! $plaintext)) {
263 $body = str_replace("\r\n","\n",$body);
264 $body = str_replace("\n\n","\n",$body);
268 // get contact info for poster
273 if(($_SESSION['uid']) && ($_SESSION['uid'] == $profile_uid)) {
275 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
276 intval($_SESSION['uid'])
280 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
281 $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
282 intval($_SESSION['visitor_id'])
289 $contact_id = $author['id'];
292 // get contact info for owner
294 if($profile_uid == $_SESSION['uid']) {
295 $contact_record = $author;
298 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
302 $contact_record = $r[0];
307 $post_type = notags(trim($_REQUEST['type']));
309 if($post_type === 'net-comment') {
310 if($parent_item !== null) {
311 if($parent_item['wall'] == 1)
312 $post_type = 'wall-comment';
314 $post_type = 'remote-comment';
320 * When a photo was uploaded into the message using the (profile wall) ajax
321 * uploader, The permissions are initially set to disallow anybody but the
322 * owner from seeing it. This is because the permissions may not yet have been
323 * set for the post. If it's private, the photo permissions should be set
324 * appropriately. But we didn't know the final permissions on the post until
325 * now. So now we'll look for links of uploaded messages that are in the
326 * post and set them to the same permissions as the post itself.
332 if((! $preview) && preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) {
335 foreach($images as $image) {
336 if(! stristr($image,$a->get_baseurl() . '/photo/'))
338 $image_uri = substr($image,strrpos($image,'/') + 1);
339 $image_uri = substr($image_uri,0, strpos($image_uri,'-'));
340 if(! strlen($image_uri))
342 $srch = '<' . intval($profile_uid) . '>';
343 $r = q("SELECT `id` FROM `photo` WHERE `allow_cid` = '%s' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = ''
344 AND `resource-id` = '%s' AND `uid` = %d LIMIT 1",
353 $r = q("UPDATE `photo` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
354 WHERE `resource-id` = '%s' AND `uid` = %d AND `album` = '%s' ",
355 dbesc($str_contact_allow),
356 dbesc($str_group_allow),
357 dbesc($str_contact_deny),
358 dbesc($str_group_deny),
360 intval($profile_uid),
361 dbesc( t('Wall Photos'))
370 * Next link in any attachment references we find in the post.
375 if((! $preview) && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",$body,$match)) {
376 $attaches = $match[1];
377 if(count($attaches)) {
378 foreach($attaches as $attach) {
379 $r = q("SELECT * FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
380 intval($profile_uid),
384 $r = q("UPDATE `attach` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
385 WHERE `uid` = %d AND `id` = %d LIMIT 1",
386 dbesc($str_contact_allow),
387 dbesc($str_group_allow),
388 dbesc($str_contact_deny),
389 dbesc($str_group_deny),
390 intval($profile_uid),
398 // embedded bookmark in post? set bookmark flag
401 if(preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",$body,$match,PREG_SET_ORDER)) {
405 $body = bb_translate_video($body);
408 * Fold multi-line [code] sequences
411 $body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body);
413 $body = scale_external_images($body,false);
416 * Look for any tags and linkify them
423 $tags = get_tags($body);
426 * add a statusnet style reply tag if the original post was from there
427 * and we are replying, and there isn't one already
430 if(($parent_contact) && ($parent_contact['network'] === NETWORK_OSTATUS)
431 && ($parent_contact['nick']) && (! in_array('@' . $parent_contact['nick'],$tags))) {
432 $body = '@' . $parent_contact['nick'] . ' ' . $body;
433 $tags[] = '@' . $parent_contact['nick'];
437 foreach($tags as $tag) {
438 handle_tag($a, $body, $inform, $str_tags, $profile_uid, $tag);
445 if(preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) {
446 foreach($match[2] as $mtch) {
447 $r = q("SELECT `id`,`filename`,`filesize`,`filetype` FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
448 intval($profile_uid),
452 if(strlen($attachments))
454 $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]';
456 $body = str_replace($match[1],'',$body);
462 if($post_type === 'wall' || $post_type === 'wall-comment')
466 $verb = ACTIVITY_POST ;
468 $gravity = (($parent) ? 6 : 0 );
470 // even if the post arrived via API we are considering that it
471 // originated on this site by default for determining relayability.
473 $origin = ((x($_REQUEST,'origin')) ? intval($_REQUEST['origin']) : 1);
475 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
477 $uri = item_new_uri($a->get_hostname(),$profile_uid);
480 $datarray['uid'] = $profile_uid;
481 $datarray['type'] = $post_type;
482 $datarray['wall'] = $wall;
483 $datarray['gravity'] = $gravity;
484 $datarray['contact-id'] = $contact_id;
485 $datarray['owner-name'] = $contact_record['name'];
486 $datarray['owner-link'] = $contact_record['url'];
487 $datarray['owner-avatar'] = $contact_record['thumb'];
488 $datarray['author-name'] = $author['name'];
489 $datarray['author-link'] = $author['url'];
490 $datarray['author-avatar'] = $author['thumb'];
491 $datarray['created'] = datetime_convert();
492 $datarray['edited'] = datetime_convert();
493 $datarray['commented'] = datetime_convert();
494 $datarray['received'] = datetime_convert();
495 $datarray['changed'] = datetime_convert();
496 $datarray['uri'] = $uri;
497 $datarray['title'] = $title;
498 $datarray['body'] = $body;
499 $datarray['app'] = $app;
500 $datarray['location'] = $location;
501 $datarray['coord'] = $coord;
502 $datarray['tag'] = $str_tags;
503 $datarray['inform'] = $inform;
504 $datarray['verb'] = $verb;
505 $datarray['allow_cid'] = $str_contact_allow;
506 $datarray['allow_gid'] = $str_group_allow;
507 $datarray['deny_cid'] = $str_contact_deny;
508 $datarray['deny_gid'] = $str_group_deny;
509 $datarray['private'] = $private;
510 $datarray['pubmail'] = $pubmail_enable;
511 $datarray['attach'] = $attachments;
512 $datarray['bookmark'] = intval($bookmark);
513 $datarray['thr-parent'] = $thr_parent;
514 $datarray['postopts'] = '';
515 $datarray['origin'] = $origin;
516 $datarray['moderated'] = $allow_moderated;
519 * These fields are for the convenience of plugins...
520 * 'self' if true indicates the owner is posting on their own wall
521 * If parent is 0 it is a top-level post.
524 $datarray['parent'] = $parent;
525 $datarray['self'] = $self;
526 // $datarray['prvnets'] = $user['prvnets'];
529 $datarray['edit'] = true;
531 $datarray['guid'] = get_guid();
533 // preview mode - prepare the body for display and send it via json
536 require_once('include/conversation.php');
537 $o = conversation($a,array(array_merge($contact_record,$datarray)),'search',false,true);
538 logger('preview: ' . $o);
539 echo json_encode(array('preview' => $o));
544 call_hooks('post_local',$datarray);
546 if(x($datarray,'cancel')) {
547 logger('mod_item: post cancelled by plugin.');
549 goaway($a->get_baseurl() . "/" . $return_path);
552 $json = array('cancel' => 1);
553 if(x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload']))
554 $json['reload'] = $a->get_baseurl() . '/' . $_REQUEST['jsreload'];
556 echo json_encode($json);
562 $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
565 dbesc(datetime_convert()),
570 proc_run('php', "include/notifier.php", 'edit_post', "$post_id");
571 if((x($_REQUEST,'return')) && strlen($return_path)) {
572 logger('return: ' . $return_path);
573 goaway($a->get_baseurl() . "/" . $return_path );
581 $r = q("INSERT INTO `item` (`guid`, `uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
582 `author-name`, `author-link`, `author-avatar`, `created`, `edited`, `commented`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`,
583 `tag`, `inform`, `verb`, `postopts`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`, `bookmark`,`origin`, `moderated` )
584 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, %d )",
585 dbesc($datarray['guid']),
586 intval($datarray['uid']),
587 dbesc($datarray['type']),
588 intval($datarray['wall']),
589 intval($datarray['gravity']),
590 intval($datarray['contact-id']),
591 dbesc($datarray['owner-name']),
592 dbesc($datarray['owner-link']),
593 dbesc($datarray['owner-avatar']),
594 dbesc($datarray['author-name']),
595 dbesc($datarray['author-link']),
596 dbesc($datarray['author-avatar']),
597 dbesc($datarray['created']),
598 dbesc($datarray['edited']),
599 dbesc($datarray['commented']),
600 dbesc($datarray['received']),
601 dbesc($datarray['changed']),
602 dbesc($datarray['uri']),
603 dbesc($datarray['thr-parent']),
604 dbesc($datarray['title']),
605 dbesc($datarray['body']),
606 dbesc($datarray['app']),
607 dbesc($datarray['location']),
608 dbesc($datarray['coord']),
609 dbesc($datarray['tag']),
610 dbesc($datarray['inform']),
611 dbesc($datarray['verb']),
612 dbesc($datarray['postopts']),
613 dbesc($datarray['allow_cid']),
614 dbesc($datarray['allow_gid']),
615 dbesc($datarray['deny_cid']),
616 dbesc($datarray['deny_gid']),
617 intval($datarray['private']),
618 intval($datarray['pubmail']),
619 dbesc($datarray['attach']),
620 intval($datarray['bookmark']),
621 intval($datarray['origin']),
622 intval($datarry['moderated'])
625 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
626 dbesc($datarray['uri']));
628 $post_id = $r[0]['id'];
629 logger('mod_item: saved item ' . $post_id);
633 // This item is the last leaf and gets the comment box, clear any ancestors
634 $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d ",
635 dbesc(datetime_convert()),
639 // Inherit ACL's from the parent item.
641 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d
642 WHERE `id` = %d LIMIT 1",
643 dbesc($parent_item['allow_cid']),
644 dbesc($parent_item['allow_gid']),
645 dbesc($parent_item['deny_cid']),
646 dbesc($parent_item['deny_gid']),
647 intval($parent_item['private']),
651 if($contact_record != $author) {
653 'type' => NOTIFY_COMMENT,
654 'notify_flags' => $user['notify-flags'],
655 'language' => $user['language'],
656 'to_name' => $user['username'],
657 'to_email' => $user['email'],
658 'uid' => $user['uid'],
660 'link' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
661 'source_name' => $datarray['author-name'],
662 'source_link' => $datarray['author-link'],
663 'source_photo' => $datarray['author-avatar'],
664 'verb' => ACTIVITY_POST,
671 // We won't be able to sign Diaspora comments for authenticated visitors - we don't have their private key
674 require_once('include/bb2diaspora.php');
675 $signed_body = html_entity_decode(bb2diaspora($datarray['body']));
676 $myaddr = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
677 if($datarray['verb'] === ACTIVITY_LIKE)
678 $signed_text = $datarray['guid'] . ';' . 'Post' . ';' . $parent_item['guid'] . ';' . 'true' . ';' . $myaddr;
680 $signed_text = $datarray['guid'] . ';' . $parent_item['guid'] . ';' . $signed_body . ';' . $myaddr;
682 $authorsig = base64_encode(rsa_sign($signed_text,$a->user['prvkey'],'sha256'));
684 q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
687 dbesc(base64_encode($authorsig)),
695 if($contact_record != $author) {
697 'type' => NOTIFY_WALL,
698 'notify_flags' => $user['notify-flags'],
699 'language' => $user['language'],
700 'to_name' => $user['username'],
701 'to_email' => $user['email'],
702 'uid' => $user['uid'],
704 'link' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
705 'source_name' => $datarray['author-name'],
706 'source_link' => $datarray['author-link'],
707 'source_photo' => $datarray['author-avatar'],
708 'verb' => ACTIVITY_POST,
714 // fallback so that parent always gets set to non-zero.
719 $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `plink` = '%s', `changed` = '%s', `last-child` = 1, `visible` = 1
720 WHERE `id` = %d LIMIT 1",
722 dbesc(($parent == $post_id) ? $uri : $parent_item['uri']),
723 dbesc($a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id),
724 dbesc(datetime_convert()),
728 // photo comments turn the corresponding item visible to the profile wall
729 // This way we don't see every picture in your new photo album posted to your wall at once.
730 // They will show up as people comment on them.
732 if(! $parent_item['visible']) {
733 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d LIMIT 1",
734 intval($parent_item['id'])
739 logger('mod_item: unable to retrieve post that was just stored.');
740 notify( t('System error. Post not saved.'));
741 goaway($a->get_baseurl() . "/" . $return_path );
745 // update the commented timestamp on the parent
747 q("UPDATE `item` set `commented` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
748 dbesc(datetime_convert()),
749 dbesc(datetime_convert()),
753 $datarray['id'] = $post_id;
754 $datarray['plink'] = $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id;
756 call_hooks('post_local_end', $datarray);
758 if(strlen($emailcc) && $profile_uid == local_user()) {
759 $erecips = explode(',', $emailcc);
760 if(count($erecips)) {
761 foreach($erecips as $recip) {
762 $addr = trim($recip);
765 $disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendica social network.'),$a->user['username'])
767 $disclaimer .= sprintf( t('You may visit them online at %s'), $a->get_baseurl() . '/profile/' . $a->user['nickname']) . EOL;
768 $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
770 $subject = email_header_encode('[Friendica]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']),'UTF-8');
771 $headers = 'From: ' . email_header_encode($a->user['username'],'UTF-8') . ' <' . $a->user['email'] . '>' . "\n";
772 $headers .= 'MIME-Version: 1.0' . "\n";
773 $headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
774 $headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n";
775 $link = '<a href="' . $a->get_baseurl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
776 $html = prepare_body($datarray);
777 $message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
778 @mail($addr, $subject, $message, $headers);
783 // This is a real juggling act on shared hosting services which kill your processes
784 // e.g. dreamhost. We used to start delivery to our native delivery agents in the background
785 // and then run our plugin delivery from the foreground. We're now doing plugin delivery first,
786 // because as soon as you start loading up a bunch of remote delivey processes, *this* page is
787 // likely to get killed off. If you end up looking at an /item URL and a blank page,
788 // it's very likely the delivery got killed before all your friends could be notified.
789 // Currently the only realistic fixes are to use a reliable server - which precludes shared hosting,
790 // or cut back on plugins which do remote deliveries.
792 proc_run('php', "include/notifier.php", $notify_type, "$post_id");
794 logger('post_complete');
796 // figure out how to return, depending on from whence we came
802 goaway($a->get_baseurl() . "/" . $return_path);
805 $json = array('success' => 1);
806 if(x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload']))
807 $json['reload'] = $a->get_baseurl() . '/' . $_REQUEST['jsreload'];
809 logger('post_json: ' . print_r($json,true), LOGGER_DEBUG);
811 echo json_encode($json);
820 function item_content(&$a) {
822 if((! local_user()) && (! remote_user()))
825 require_once('include/security.php');
827 if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
828 require_once('include/items.php');
829 drop_item($a->argv[2]);
834 * This function removes the tag $tag from the text $body and replaces it with
835 * the appropiate link.
837 * @param unknown_type $body the text to replace the tag in
838 * @param unknown_type $inform a comma-seperated string containing everybody to inform
839 * @param unknown_type $str_tags string to add the tag to
840 * @param unknown_type $profile_uid
841 * @param unknown_type $tag the tag to replace
843 function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) {
845 if(strpos($tag,'#') === 0) {
846 //if the tag is replaced...
847 if(strpos($tag,'[url='))
850 //base tag has the tags name only
851 $basetag = str_replace('_',' ',substr($tag,1));
852 //create text for link
853 $newtag = '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
854 //replace tag by the link
855 $body = str_replace($tag, $newtag, $body);
857 //is the link already in str_tags?
858 if(! stristr($str_tags,$newtag)) {
859 //append or set str_tags
860 if(strlen($str_tags))
862 $str_tags .= $newtag;
866 //is it a person tag?
867 if(strpos($tag,'@') === 0) {
868 //is it already replaced?
869 if(strpos($tag,'[url='))
872 //get the person's name
873 $name = substr($tag,1);
874 //is it a link or a full dfrn address?
875 if((strpos($name,'@')) || (strpos($name,'http://'))) {
877 //get the profile links
878 $links = @lrdd($name);
880 //for all links, collect how is to inform and how's profile is to link
881 foreach($links as $link) {
882 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
883 $profile = $link['@attributes']['href'];
884 if($link['@attributes']['rel'] === 'salmon') {
887 $inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']);
891 } else { //if it is a name rather than an address
895 //is it some generated name?
896 if(strrpos($newname,'+')) {
898 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
899 //remove the next word from tag's name
900 if(strpos($name,' ')) {
901 $name = substr($name,0,strpos($name,' '));
904 if($tagcid) { //if there was an id
905 //select contact with that id from the logged in user's contact list
906 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
910 } elseif(strstr($name,'_') || strstr($name,' ')) { //no id
912 $newname = str_replace('_',' ',$name);
913 //select someone from this user's contacts by name
914 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
919 //select someone by attag or nick and the name passed in
920 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
926 //$r is set, if someone could be selected
928 $profile = $r[0]['url'];
929 //set newname to nick, find alias
930 if($r[0]['network'] === 'stat') {
931 $newname = $r[0]['nick'];
934 $alias = $r[0]['alias'];
937 $newname = $r[0]['name'];
938 //add person's id to $inform
941 $inform .= 'cid:' . $r[0]['id'];
944 //if there is an url for this persons profile
945 if(isset($profile)) {
946 //create profile link
947 $profile = str_replace(',','%2c',$profile);
948 $newtag = '@[url=' . $profile . ']' . $newname . '[/url]';
949 $body = str_replace('@' . $name, $newtag, $body);
950 //append tag to str_tags
951 if(! stristr($str_tags,$newtag)) {
952 if(strlen($str_tags))
954 $str_tags .= $newtag;
957 // Status.Net seems to require the numeric ID URL in a mention if the person isn't
958 // subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
961 $newtag = '@[url=' . $alias . ']' . $newname . '[/url]';
962 if(! stristr($str_tags,$newtag)) {
963 if(strlen($str_tags))
965 $str_tags .= $newtag;