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 $location = $orig_post['location'];
175 $coord = $orig_post['coord'];
176 $verb = $orig_post['verb'];
177 $emailcc = $orig_post['emailcc'];
178 $app = $orig_post['app'];
179 $categories = $orig_post['file'];
180 $title = notags(trim($_REQUEST['title']));
181 $body = escape_tags(trim($_REQUEST['body']));
182 $private = $orig_post['private'];
183 $pubmail_enable = $orig_post['pubmail'];
188 // if coming from the API and no privacy settings are set,
189 // use the user default permissions - as they won't have
190 // been supplied via a form.
193 && (! array_key_exists('contact_allow',$_REQUEST))
194 && (! array_key_exists('group_allow',$_REQUEST))
195 && (! array_key_exists('contact_deny',$_REQUEST))
196 && (! array_key_exists('group_deny',$_REQUEST))) {
197 $str_group_allow = $user['allow_gid'];
198 $str_contact_allow = $user['allow_cid'];
199 $str_group_deny = $user['deny_gid'];
200 $str_contact_deny = $user['deny_cid'];
204 // use the posted permissions
206 $str_group_allow = perms2str($_REQUEST['group_allow']);
207 $str_contact_allow = perms2str($_REQUEST['contact_allow']);
208 $str_group_deny = perms2str($_REQUEST['group_deny']);
209 $str_contact_deny = perms2str($_REQUEST['contact_deny']);
212 $title = notags(trim($_REQUEST['title']));
213 $location = notags(trim($_REQUEST['location']));
214 $coord = notags(trim($_REQUEST['coord']));
215 $verb = notags(trim($_REQUEST['verb']));
216 $emailcc = notags(trim($_REQUEST['emailcc']));
217 $body = escape_tags(trim($_REQUEST['body']));
219 $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);
222 (($parent_item['private'])
223 || strlen($parent_item['allow_cid'])
224 || strlen($parent_item['allow_gid'])
225 || strlen($parent_item['deny_cid'])
226 || strlen($parent_item['deny_gid'])
231 $pubmail_enable = ((x($_REQUEST,'pubmail_enable') && intval($_REQUEST['pubmail_enable']) && (! $private)) ? 1 : 0);
233 // if using the API, we won't see pubmail_enable - figure out if it should be set
235 if($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) {
236 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
237 if(! $mail_disabled) {
238 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
241 if(count($r) && intval($r[0]['pubmail']))
242 $pubmail_enabled = true;
246 if(! strlen($body)) {
249 info( t('Empty post discarded.') . EOL );
250 if(x($_REQUEST,'return'))
251 goaway($a->get_baseurl() . "/" . $return_path );
256 if(strlen($categories)) {
257 // get the "fileas" tags for this post
258 $filedas = file_tag_file_to_list($categories, 'file');
260 // save old and new categories, so we can determine what needs to be deleted from pconfig
261 $categories_old = $categories;
262 $categories = file_tag_list_to_file(trim($_REQUEST['category']), 'category');
263 $categories_new = $categories;
264 if(strlen($filedas)) {
265 // append the fileas stuff to the new categories list
266 $categories .= file_tag_list_to_file($filedas, 'file');
269 // Work around doubled linefeeds in Tinymce 3.5b2
270 // First figure out if it's a status post that would've been
271 // created using tinymce. Otherwise leave it alone.
273 $plaintext = (local_user() ? intval(get_pconfig(local_user(),'system','plaintext')) : 0);
274 if((! $parent) && (! $api_source) && (! $plaintext)) {
275 $body = fix_mce_lf($body);
279 // get contact info for poster
284 if(($_SESSION['uid']) && ($_SESSION['uid'] == $profile_uid)) {
286 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
287 intval($_SESSION['uid'])
291 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
292 $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
293 intval($_SESSION['visitor_id'])
300 $contact_id = $author['id'];
303 // get contact info for owner
305 if($profile_uid == $_SESSION['uid']) {
306 $contact_record = $author;
309 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
313 $contact_record = $r[0];
318 $post_type = notags(trim($_REQUEST['type']));
320 if($post_type === 'net-comment') {
321 if($parent_item !== null) {
322 if($parent_item['wall'] == 1)
323 $post_type = 'wall-comment';
325 $post_type = 'remote-comment';
331 * When a photo was uploaded into the message using the (profile wall) ajax
332 * uploader, The permissions are initially set to disallow anybody but the
333 * owner from seeing it. This is because the permissions may not yet have been
334 * set for the post. If it's private, the photo permissions should be set
335 * appropriately. But we didn't know the final permissions on the post until
336 * now. So now we'll look for links of uploaded messages that are in the
337 * post and set them to the same permissions as the post itself.
343 if((! $preview) && preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) {
346 foreach($images as $image) {
347 if(! stristr($image,$a->get_baseurl() . '/photo/'))
349 $image_uri = substr($image,strrpos($image,'/') + 1);
350 $image_uri = substr($image_uri,0, strpos($image_uri,'-'));
351 if(! strlen($image_uri))
353 $srch = '<' . intval($contact_record['id']) . '>';
354 $r = q("SELECT `id` FROM `photo` WHERE `allow_cid` = '%s' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = ''
355 AND `resource-id` = '%s' AND `uid` = %d LIMIT 1",
364 $r = q("UPDATE `photo` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
365 WHERE `resource-id` = '%s' AND `uid` = %d AND `album` = '%s' ",
366 dbesc($str_contact_allow),
367 dbesc($str_group_allow),
368 dbesc($str_contact_deny),
369 dbesc($str_group_deny),
371 intval($profile_uid),
372 dbesc( t('Wall Photos'))
381 * Next link in any attachment references we find in the post.
386 if((! $preview) && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",$body,$match)) {
387 $attaches = $match[1];
388 if(count($attaches)) {
389 foreach($attaches as $attach) {
390 $r = q("SELECT * FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
391 intval($profile_uid),
395 $r = q("UPDATE `attach` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
396 WHERE `uid` = %d AND `id` = %d LIMIT 1",
397 dbesc($str_contact_allow),
398 dbesc($str_group_allow),
399 dbesc($str_contact_deny),
400 dbesc($str_group_deny),
401 intval($profile_uid),
409 // embedded bookmark in post? set bookmark flag
412 if(preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",$body,$match,PREG_SET_ORDER)) {
416 $body = bb_translate_video($body);
419 * Fold multi-line [code] sequences
422 $body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body);
424 $body = scale_external_images($body,false);
427 * Look for any tags and linkify them
434 $tags = get_tags($body);
437 * add a statusnet style reply tag if the original post was from there
438 * and we are replying, and there isn't one already
441 if(($parent_contact) && ($parent_contact['network'] === NETWORK_OSTATUS)
442 && ($parent_contact['nick']) && (! in_array('@' . $parent_contact['nick'],$tags))) {
443 $body = '@' . $parent_contact['nick'] . ' ' . $body;
444 $tags[] = '@' . $parent_contact['nick'];
451 foreach($tags as $tag) {
453 // If we already tagged 'Robert Johnson', don't try and tag 'Robert'.
454 // Robert Johnson should be first in the $tags array
456 $fullnametagged = false;
457 for($x = 0; $x < count($tagged); $x ++) {
458 if(stristr($tagged[$x],$tag . ' ')) {
459 $fullnametagged = true;
466 $success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag);
475 if(preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) {
476 foreach($match[2] as $mtch) {
477 $r = q("SELECT `id`,`filename`,`filesize`,`filetype` FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
478 intval($profile_uid),
482 if(strlen($attachments))
484 $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]';
486 $body = str_replace($match[1],'',$body);
492 if($post_type === 'wall' || $post_type === 'wall-comment')
496 $verb = ACTIVITY_POST ;
498 $gravity = (($parent) ? 6 : 0 );
500 // even if the post arrived via API we are considering that it
501 // originated on this site by default for determining relayability.
503 $origin = ((x($_REQUEST,'origin')) ? intval($_REQUEST['origin']) : 1);
505 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
507 $uri = item_new_uri($a->get_hostname(),$profile_uid);
510 $datarray['uid'] = $profile_uid;
511 $datarray['type'] = $post_type;
512 $datarray['wall'] = $wall;
513 $datarray['gravity'] = $gravity;
514 $datarray['contact-id'] = $contact_id;
515 $datarray['owner-name'] = $contact_record['name'];
516 $datarray['owner-link'] = $contact_record['url'];
517 $datarray['owner-avatar'] = $contact_record['thumb'];
518 $datarray['author-name'] = $author['name'];
519 $datarray['author-link'] = $author['url'];
520 $datarray['author-avatar'] = $author['thumb'];
521 $datarray['created'] = datetime_convert();
522 $datarray['edited'] = datetime_convert();
523 $datarray['commented'] = datetime_convert();
524 $datarray['received'] = datetime_convert();
525 $datarray['changed'] = datetime_convert();
526 $datarray['uri'] = $uri;
527 $datarray['title'] = $title;
528 $datarray['body'] = $body;
529 $datarray['app'] = $app;
530 $datarray['location'] = $location;
531 $datarray['coord'] = $coord;
532 $datarray['tag'] = $str_tags;
533 $datarray['file'] = $categories;
534 $datarray['inform'] = $inform;
535 $datarray['verb'] = $verb;
536 $datarray['allow_cid'] = $str_contact_allow;
537 $datarray['allow_gid'] = $str_group_allow;
538 $datarray['deny_cid'] = $str_contact_deny;
539 $datarray['deny_gid'] = $str_group_deny;
540 $datarray['private'] = $private;
541 $datarray['pubmail'] = $pubmail_enable;
542 $datarray['attach'] = $attachments;
543 $datarray['bookmark'] = intval($bookmark);
544 $datarray['thr-parent'] = $thr_parent;
545 $datarray['postopts'] = '';
546 $datarray['origin'] = $origin;
547 $datarray['moderated'] = $allow_moderated;
550 * These fields are for the convenience of plugins...
551 * 'self' if true indicates the owner is posting on their own wall
552 * If parent is 0 it is a top-level post.
555 $datarray['parent'] = $parent;
556 $datarray['self'] = $self;
557 // $datarray['prvnets'] = $user['prvnets'];
560 $datarray['edit'] = true;
562 $datarray['guid'] = get_guid();
564 // preview mode - prepare the body for display and send it via json
567 require_once('include/conversation.php');
568 $o = conversation($a,array(array_merge($contact_record,$datarray)),'search',false,true);
569 logger('preview: ' . $o);
570 echo json_encode(array('preview' => $o));
575 call_hooks('post_local',$datarray);
577 if(x($datarray,'cancel')) {
578 logger('mod_item: post cancelled by plugin.');
580 goaway($a->get_baseurl() . "/" . $return_path);
583 $json = array('cancel' => 1);
584 if(x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload']))
585 $json['reload'] = $a->get_baseurl() . '/' . $_REQUEST['jsreload'];
587 echo json_encode($json);
593 $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `attach` = '%s', `file` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
594 dbesc($datarray['title']),
595 dbesc($datarray['body']),
596 dbesc($datarray['tag']),
597 dbesc($datarray['attach']),
598 dbesc($datarray['file']),
599 dbesc(datetime_convert()),
604 // update filetags in pconfig
605 file_tag_update_pconfig($uid,$categories_old,$categories_new,'category');
607 proc_run('php', "include/notifier.php", 'edit_post', "$post_id");
608 if((x($_REQUEST,'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`, `moderated`, `file` )
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, %d, '%s' )",
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']),
659 intval($datarray['moderated']),
660 dbesc($datarray['file'])
663 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
664 dbesc($datarray['uri']));
666 $post_id = $r[0]['id'];
667 logger('mod_item: saved item ' . $post_id);
669 // update filetags in pconfig
670 file_tag_update_pconfig($uid,$categories_old,$categories_new,'category');
674 // This item is the last leaf and gets the comment box, clear any ancestors
675 $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d ",
676 dbesc(datetime_convert()),
680 // Inherit ACL's from the parent item.
682 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d
683 WHERE `id` = %d LIMIT 1",
684 dbesc($parent_item['allow_cid']),
685 dbesc($parent_item['allow_gid']),
686 dbesc($parent_item['deny_cid']),
687 dbesc($parent_item['deny_gid']),
688 intval($parent_item['private']),
692 if($contact_record != $author) {
694 'type' => NOTIFY_COMMENT,
695 'notify_flags' => $user['notify-flags'],
696 'language' => $user['language'],
697 'to_name' => $user['username'],
698 'to_email' => $user['email'],
699 'uid' => $user['uid'],
701 'link' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
702 'source_name' => $datarray['author-name'],
703 'source_link' => $datarray['author-link'],
704 'source_photo' => $datarray['author-avatar'],
705 'verb' => ACTIVITY_POST,
712 // We won't be able to sign Diaspora comments for authenticated visitors - we don't have their private key
715 require_once('include/bb2diaspora.php');
716 $signed_body = html_entity_decode(bb2diaspora($datarray['body']));
717 $myaddr = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
718 if($datarray['verb'] === ACTIVITY_LIKE)
719 $signed_text = $datarray['guid'] . ';' . 'Post' . ';' . $parent_item['guid'] . ';' . 'true' . ';' . $myaddr;
721 $signed_text = $datarray['guid'] . ';' . $parent_item['guid'] . ';' . $signed_body . ';' . $myaddr;
723 $authorsig = base64_encode(rsa_sign($signed_text,$a->user['prvkey'],'sha256'));
725 q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
728 dbesc(base64_encode($authorsig)),
736 if($contact_record != $author) {
738 'type' => NOTIFY_WALL,
739 'notify_flags' => $user['notify-flags'],
740 'language' => $user['language'],
741 'to_name' => $user['username'],
742 'to_email' => $user['email'],
743 'uid' => $user['uid'],
745 'link' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
746 'source_name' => $datarray['author-name'],
747 'source_link' => $datarray['author-link'],
748 'source_photo' => $datarray['author-avatar'],
749 'verb' => ACTIVITY_POST,
755 // fallback so that parent always gets set to non-zero.
760 $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `plink` = '%s', `changed` = '%s', `last-child` = 1, `visible` = 1
761 WHERE `id` = %d LIMIT 1",
763 dbesc(($parent == $post_id) ? $uri : $parent_item['uri']),
764 dbesc($a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id),
765 dbesc(datetime_convert()),
769 // photo comments turn the corresponding item visible to the profile wall
770 // This way we don't see every picture in your new photo album posted to your wall at once.
771 // They will show up as people comment on them.
773 if(! $parent_item['visible']) {
774 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d LIMIT 1",
775 intval($parent_item['id'])
780 logger('mod_item: unable to retrieve post that was just stored.');
781 notice( t('System error. Post not saved.') . EOL);
782 goaway($a->get_baseurl() . "/" . $return_path );
786 // update the commented timestamp on the parent
788 q("UPDATE `item` set `commented` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
789 dbesc(datetime_convert()),
790 dbesc(datetime_convert()),
794 $datarray['id'] = $post_id;
795 $datarray['plink'] = $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id;
797 call_hooks('post_local_end', $datarray);
799 if(strlen($emailcc) && $profile_uid == local_user()) {
800 $erecips = explode(',', $emailcc);
801 if(count($erecips)) {
802 foreach($erecips as $recip) {
803 $addr = trim($recip);
806 $disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendica social network.'),$a->user['username'])
808 $disclaimer .= sprintf( t('You may visit them online at %s'), $a->get_baseurl() . '/profile/' . $a->user['nickname']) . EOL;
809 $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
811 $subject = email_header_encode('[Friendica]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']),'UTF-8');
812 $headers = 'From: ' . email_header_encode($a->user['username'],'UTF-8') . ' <' . $a->user['email'] . '>' . "\n";
813 $headers .= 'MIME-Version: 1.0' . "\n";
814 $headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
815 $headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n";
816 $link = '<a href="' . $a->get_baseurl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
817 $html = prepare_body($datarray);
818 $message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
819 @mail($addr, $subject, $message, $headers);
824 // This is a real juggling act on shared hosting services which kill your processes
825 // e.g. dreamhost. We used to start delivery to our native delivery agents in the background
826 // and then run our plugin delivery from the foreground. We're now doing plugin delivery first,
827 // because as soon as you start loading up a bunch of remote delivey processes, *this* page is
828 // likely to get killed off. If you end up looking at an /item URL and a blank page,
829 // it's very likely the delivery got killed before all your friends could be notified.
830 // Currently the only realistic fixes are to use a reliable server - which precludes shared hosting,
831 // or cut back on plugins which do remote deliveries.
833 proc_run('php', "include/notifier.php", $notify_type, "$post_id");
835 logger('post_complete');
837 // figure out how to return, depending on from whence we came
843 goaway($a->get_baseurl() . "/" . $return_path);
846 $json = array('success' => 1);
847 if(x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload']))
848 $json['reload'] = $a->get_baseurl() . '/' . $_REQUEST['jsreload'];
850 logger('post_json: ' . print_r($json,true), LOGGER_DEBUG);
852 echo json_encode($json);
861 function item_content(&$a) {
863 if((! local_user()) && (! remote_user()))
866 require_once('include/security.php');
868 if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
869 require_once('include/items.php');
870 drop_item($a->argv[2]);
875 * This function removes the tag $tag from the text $body and replaces it with
876 * the appropiate link.
878 * @param unknown_type $body the text to replace the tag in
879 * @param unknown_type $inform a comma-seperated string containing everybody to inform
880 * @param unknown_type $str_tags string to add the tag to
881 * @param unknown_type $profile_uid
882 * @param unknown_type $tag the tag to replace
884 * @return boolean true if replaced, false if not replaced
886 function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) {
891 if(strpos($tag,'#') === 0) {
892 //if the tag is replaced...
893 if(strpos($tag,'[url='))
896 //base tag has the tags name only
897 $basetag = str_replace('_',' ',substr($tag,1));
898 //create text for link
899 $newtag = '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
900 //replace tag by the link
901 $body = str_replace($tag, $newtag, $body);
904 //is the link already in str_tags?
905 if(! stristr($str_tags,$newtag)) {
906 //append or set str_tags
907 if(strlen($str_tags))
909 $str_tags .= $newtag;
913 //is it a person tag?
914 if(strpos($tag,'@') === 0) {
915 //is it already replaced?
916 if(strpos($tag,'[url='))
919 //get the person's name
920 $name = substr($tag,1);
921 //is it a link or a full dfrn address?
922 if((strpos($name,'@')) || (strpos($name,'http://'))) {
924 //get the profile links
925 $links = @lrdd($name);
927 //for all links, collect how is to inform and how's profile is to link
928 foreach($links as $link) {
929 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
930 $profile = $link['@attributes']['href'];
931 if($link['@attributes']['rel'] === 'salmon') {
934 $inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']);
938 } else { //if it is a name rather than an address
942 //is it some generated name?
943 if(strrpos($newname,'+')) {
945 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
946 //remove the next word from tag's name
947 if(strpos($name,' ')) {
948 $name = substr($name,0,strpos($name,' '));
951 if($tagcid) { //if there was an id
952 //select contact with that id from the logged in user's contact list
953 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
957 } elseif(strstr($name,'_') || strstr($name,' ')) { //no id
959 $newname = str_replace('_',' ',$name);
960 //select someone from this user's contacts by name
961 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
966 //select someone by attag or nick and the name passed in
967 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
973 //$r is set, if someone could be selected
975 $profile = $r[0]['url'];
976 //set newname to nick, find alias
977 if($r[0]['network'] === 'stat') {
978 $newname = $r[0]['nick'];
981 $alias = $r[0]['alias'];
984 $newname = $r[0]['name'];
985 //add person's id to $inform
988 $inform .= 'cid:' . $r[0]['id'];
991 //if there is an url for this persons profile
992 if(isset($profile)) {
994 //create profile link
995 $profile = str_replace(',','%2c',$profile);
996 $newtag = '@[url=' . $profile . ']' . $newname . '[/url]';
997 $body = str_replace('@' . $name, $newtag, $body);
998 //append tag to str_tags
999 if(! stristr($str_tags,$newtag)) {
1000 if(strlen($str_tags))
1002 $str_tags .= $newtag;
1005 // Status.Net seems to require the numeric ID URL in a mention if the person isn't
1006 // subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
1008 if(strlen($alias)) {
1009 $newtag = '@[url=' . $alias . ']' . $newname . '[/url]';
1010 if(! stristr($str_tags,$newtag)) {
1011 if(strlen($str_tags))
1013 $str_tags .= $newtag;