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);
43 * Is this a reply to something?
46 $parent = ((x($_POST,'parent')) ? intval($_POST['parent']) : 0);
47 $parent_uri = ((x($_POST,'parent_uri')) ? trim($_POST['parent_uri']) : '');
50 $parent_contact = null;
55 if($parent || $parent_uri) {
57 if(! x($_POST,'type'))
58 $_POST['type'] = 'net-comment';
61 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
65 elseif($parent_uri && local_user()) {
66 // This is coming from an API source, and we are logged in
67 $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
72 // if this isn't the real parent of the conversation, find it
73 if($r !== false && count($r)) {
74 $parid = $r[0]['parent'];
75 if($r[0]['id'] != $r[0]['parent']) {
76 $r = q("SELECT * FROM `item` WHERE `id` = `parent` AND `parent` = %d LIMIT 1",
82 if(($r === false) || (! count($r))) {
83 notice( t('Unable to locate original post.') . EOL);
84 if(x($_POST,'return'))
85 goaway($a->get_baseurl() . "/" . $_POST['return'] );
89 $parent = $r[0]['id'];
91 // multi-level threading - preserve the info but re-parent to our single level threading
92 if(($parid) && ($parid != $parent))
93 $thr_parent = $parent_uri;
95 if($parent_item['contact-id'] && $uid) {
96 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
97 intval($parent_item['contact-id']),
101 $parent_contact = $r[0];
105 if($parent) logger('mod_post: parent=' . $parent);
107 $profile_uid = ((x($_POST,'profile_uid')) ? intval($_POST['profile_uid']) : 0);
108 $post_id = ((x($_POST['post_id'])) ? intval($_POST['post_id']) : 0);
109 $app = ((x($_POST['source'])) ? strip_tags($_POST['source']) : '');
111 if(! can_write_wall($a,$profile_uid)) {
112 notice( t('Permission denied.') . EOL) ;
113 if(x($_POST,'return'))
114 goaway($a->get_baseurl() . "/" . $_POST['return'] );
119 // is this an edited post?
124 $i = q("SELECT * FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
125 intval($profile_uid),
135 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
142 $str_group_allow = $orig_post['allow_gid'];
143 $str_contact_allow = $orig_post['allow_cid'];
144 $str_group_deny = $orig_post['deny_gid'];
145 $str_contact_deny = $orig_post['deny_cid'];
146 $title = $orig_post['title'];
147 $location = $orig_post['location'];
148 $coord = $orig_post['coord'];
149 $verb = $orig_post['verb'];
150 $emailcc = $orig_post['emailcc'];
151 $app = $orig_post['app'];
153 $body = escape_tags(trim($_POST['body']));
154 $private = $orig_post['private'];
155 $pubmail_enable = $orig_post['pubmail'];
158 $str_group_allow = perms2str($_POST['group_allow']);
159 $str_contact_allow = perms2str($_POST['contact_allow']);
160 $str_group_deny = perms2str($_POST['group_deny']);
161 $str_contact_deny = perms2str($_POST['contact_deny']);
162 $title = notags(trim($_POST['title']));
163 $location = notags(trim($_POST['location']));
164 $coord = notags(trim($_POST['coord']));
165 $verb = notags(trim($_POST['verb']));
166 $emailcc = notags(trim($_POST['emailcc']));
168 $body = escape_tags(trim($_POST['body']));
169 $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);
172 (($parent_item['private'])
173 || strlen($parent_item['allow_cid'])
174 || strlen($parent_item['allow_gid'])
175 || strlen($parent_item['deny_cid'])
176 || strlen($parent_item['deny_gid'])
181 $pubmail_enable = ((x($_POST,'pubmail_enable') && intval($_POST['pubmail_enable']) && (! $private)) ? 1 : 0);
183 // if using the API, we won't see pubmail_enable - figure out if it should be set
185 if($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) {
186 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
187 if(! $mail_disabled) {
188 $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
191 if(count($r) && intval($r[0]['pubmail']))
192 $pubmail_enabled = true;
197 if(! strlen($body)) {
198 info( t('Empty post discarded.') . EOL );
199 if(x($_POST,'return'))
200 goaway($a->get_baseurl() . "/" . $_POST['return'] );
205 // get contact info for poster
210 if(($_SESSION['uid']) && ($_SESSION['uid'] == $profile_uid)) {
212 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
213 intval($_SESSION['uid'])
217 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
218 $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
219 intval($_SESSION['visitor_id'])
226 $contact_id = $author['id'];
229 // get contact info for owner
231 if($profile_uid == $_SESSION['uid']) {
232 $contact_record = $author;
235 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
239 $contact_record = $r[0];
244 $post_type = notags(trim($_POST['type']));
246 if($post_type === 'net-comment') {
247 if($parent_item !== null) {
248 if($parent_item['wall'] == 1)
249 $post_type = 'wall-comment';
251 $post_type = 'remote-comment';
257 * When a photo was uploaded into the message using the (profile wall) ajax
258 * uploader, The permissions are initially set to disallow anybody but the
259 * owner from seeing it. This is because the permissions may not yet have been
260 * set for the post. If it's private, the photo permissions should be set
261 * appropriately. But we didn't know the final permissions on the post until
262 * now. So now we'll look for links of uploaded messages that are in the
263 * post and set them to the same permissions as the post itself.
269 if(preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) {
272 foreach($images as $image) {
273 if(! stristr($image,$a->get_baseurl() . '/photo/'))
275 $image_uri = substr($image,strrpos($image,'/') + 1);
276 $image_uri = substr($image_uri,0, strpos($image_uri,'-'));
277 if(! strlen($image_uri))
279 $srch = '<' . intval($profile_uid) . '>';
280 $r = q("SELECT `id` FROM `photo` WHERE `allow_cid` = '%s' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = ''
281 AND `resource-id` = '%s' AND `uid` = %d LIMIT 1",
290 $r = q("UPDATE `photo` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
291 WHERE `resource-id` = '%s' AND `uid` = %d AND `album` = '%s' ",
292 dbesc($str_contact_allow),
293 dbesc($str_group_allow),
294 dbesc($str_contact_deny),
295 dbesc($str_group_deny),
297 intval($profile_uid),
298 dbesc( t('Wall Photos'))
307 * Next link in any attachment references we find in the post.
312 if(preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",$body,$match)) {
313 $attaches = $match[1];
314 if(count($attaches)) {
315 foreach($attaches as $attach) {
316 $r = q("SELECT * FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
317 intval($profile_uid),
321 $r = q("UPDATE `attach` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
322 WHERE `uid` = %d AND `id` = %d LIMIT 1",
323 dbesc($str_contact_allow),
324 dbesc($str_group_allow),
325 dbesc($str_contact_deny),
326 dbesc($str_group_deny),
327 intval($profile_uid),
336 * Fold multi-line [code] sequences
339 $body = preg_replace('/\[\/code\]\s*\[code\]/m',"\n",$body);
342 * Look for any tags and linkify them
349 $tags = get_tags($body);
352 * add a statusnet style reply tag if the original post was from there
353 * and we are replying, and there isn't one already
356 if(($parent_contact) && ($parent_contact['network'] === NETWORK_OSTATUS)
357 && ($parent_contact['nick']) && (! in_array('@' . $parent_contact['nick'],$tags))) {
358 $body = '@' . $parent_contact['nick'] . ' ' . $body;
359 $tags[] = '@' . $parent_contact['nick'];
363 foreach($tags as $tag) {
366 if(strpos($tag,'#') === 0) {
367 if(strpos($tag,'[url='))
369 $basetag = str_replace('_',' ',substr($tag,1));
370 $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
371 if(strlen($str_tags))
373 $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
376 if(strpos($tag,'@') === 0) {
377 if(strpos($tag,'[url='))
380 $name = substr($tag,1);
381 if((strpos($name,'@')) || (strpos($name,'http://'))) {
383 $links = @lrdd($name);
385 foreach($links as $link) {
386 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
387 $profile = $link['@attributes']['href'];
388 if($link['@attributes']['rel'] === 'salmon') {
391 $inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']);
399 if(strstr($name,'_') || strstr($name,' ')) {
400 $newname = str_replace('_',' ',$name);
401 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
407 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
414 $profile = $r[0]['url'];
415 if($r[0]['network'] === 'stat') {
416 $newname = $r[0]['nick'];
419 $alias = $r[0]['alias'];
422 $newname = $r[0]['name'];
425 $inform .= 'cid:' . $r[0]['id'];
429 $body = str_replace('@' . $name, '@' . '[url=' . $profile . ']' . $newname . '[/url]', $body);
430 $profile = str_replace(',','%2c',$profile);
431 if(strlen($str_tags))
433 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
435 // Status.Net seems to require the numeric ID URL in a mention if the person isn't
436 // subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
439 if(strlen($str_tags))
441 $str_tags .= '@[url=' . $alias . ']' . $newname . '[/url]';
451 if(preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) {
452 foreach($match[2] as $mtch) {
453 $r = q("SELECT `id`,`filename`,`filesize`,`filetype` FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
454 intval($profile_uid),
458 if(strlen($attachments))
460 $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]';
462 $body = str_replace($match[1],'',$body);
468 if($post_type === 'wall' || $post_type === 'wall-comment')
472 $verb = ACTIVITY_POST ;
474 $gravity = (($parent) ? 6 : 0 );
476 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
478 $uri = item_new_uri($a->get_hostname(),$profile_uid);
481 $datarray['uid'] = $profile_uid;
482 $datarray['type'] = $post_type;
483 $datarray['wall'] = $wall;
484 $datarray['gravity'] = $gravity;
485 $datarray['contact-id'] = $contact_id;
486 $datarray['owner-name'] = $contact_record['name'];
487 $datarray['owner-link'] = $contact_record['url'];
488 $datarray['owner-avatar'] = $contact_record['thumb'];
489 $datarray['author-name'] = $author['name'];
490 $datarray['author-link'] = $author['url'];
491 $datarray['author-avatar'] = $author['thumb'];
492 $datarray['created'] = datetime_convert();
493 $datarray['edited'] = 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['thr-parent'] = $thr_parent;
515 * These fields are for the convenience of plugins...
516 * 'self' if true indicates the owner is posting on their own wall
517 * If parent is 0 it is a top-level post.
520 $datarray['parent'] = $parent;
521 $datarray['self'] = $self;
522 $datarray['prvnets'] = $user['prvnets'];
525 $datarray['edit'] = true;
527 $datarray['guid'] = get_guid();
530 call_hooks('post_local',$datarray);
534 $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
536 dbesc(datetime_convert()),
541 proc_run('php', "include/notifier.php", 'edit_post', "$post_id");
542 if((x($_POST,'return')) && strlen($_POST['return'])) {
543 logger('return: ' . $_POST['return']);
544 goaway($a->get_baseurl() . "/" . $_POST['return'] );
552 $r = q("INSERT INTO `item` (`guid`, `uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
553 `author-name`, `author-link`, `author-avatar`, `created`, `edited`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`,
554 `tag`, `inform`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach` )
555 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' )",
556 dbesc($datarray['guid']),
557 intval($datarray['uid']),
558 dbesc($datarray['type']),
559 intval($datarray['wall']),
560 intval($datarray['gravity']),
561 intval($datarray['contact-id']),
562 dbesc($datarray['owner-name']),
563 dbesc($datarray['owner-link']),
564 dbesc($datarray['owner-avatar']),
565 dbesc($datarray['author-name']),
566 dbesc($datarray['author-link']),
567 dbesc($datarray['author-avatar']),
568 dbesc($datarray['created']),
569 dbesc($datarray['edited']),
570 dbesc($datarray['received']),
571 dbesc($datarray['changed']),
572 dbesc($datarray['uri']),
573 dbesc($datarray['thr-parent']),
574 dbesc($datarray['title']),
575 dbesc($datarray['body']),
576 dbesc($datarray['app']),
577 dbesc($datarray['location']),
578 dbesc($datarray['coord']),
579 dbesc($datarray['tag']),
580 dbesc($datarray['inform']),
581 dbesc($datarray['verb']),
582 dbesc($datarray['allow_cid']),
583 dbesc($datarray['allow_gid']),
584 dbesc($datarray['deny_cid']),
585 dbesc($datarray['deny_gid']),
586 intval($datarray['private']),
587 intval($datarray['pubmail']),
588 dbesc($datarray['attach'])
591 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
592 dbesc($datarray['uri']));
594 $post_id = $r[0]['id'];
595 logger('mod_item: saved item ' . $post_id);
599 // This item is the last leaf and gets the comment box, clear any ancestors
600 $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d ",
601 dbesc(datetime_convert()),
605 // Inherit ACL's from the parent item.
607 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d
608 WHERE `id` = %d LIMIT 1",
609 dbesc($parent_item['allow_cid']),
610 dbesc($parent_item['allow_gid']),
611 dbesc($parent_item['deny_cid']),
612 dbesc($parent_item['deny_gid']),
613 intval($parent_item['private']),
617 // Send a notification email to the conversation owner, unless the owner is me and I wrote this item
618 if(($user['notify-flags'] & NOTIFY_COMMENT) && ($contact_record != $author)) {
619 push_lang($user['language']);
620 require_once('bbcode.php');
621 $from = $author['name'];
623 // name of the automated email sender
624 $msg['notificationfromname'] = stripslashes($datarray['author-name']);;
625 // noreply address to send from
626 $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
629 // process the message body to display properly in text mode
631 = html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8');
634 // process the message body to display properly in text mode
636 = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$datarray['body']))));
638 // load the template for private message notifications
639 $tpl = get_intltext_template('cmnt_received_html_body_eml.tpl');
640 $email_html_body_tpl = replace_macros($tpl,array(
641 '$username' => $user['username'],
642 '$sitename' => $a->config['sitename'], // name of this site
643 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
644 '$thumb' => $author['thumb'], // thumbnail url for sender icon
645 '$email' => $importer['email'], // email address to send to
646 '$url' => $author['url'], // full url for the site
647 '$from' => $from, // name of the person sending the message
648 '$body' => $msg['htmlversion'], // html version of the message
649 '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
652 // load the template for private message notifications
653 $tpl = get_intltext_template('cmnt_received_text_body_eml.tpl');
654 $email_text_body_tpl = replace_macros($tpl,array(
655 '$username' => $user['username'],
656 '$sitename' => $a->config['sitename'], // name of this site
657 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
658 '$thumb' => $author['thumb'], // thumbnail url for sender icon
659 '$email' => $importer['email'], // email address to send to
660 '$url' => $author['url'], // profile url for the author
661 '$from' => $from, // name of the person sending the message
662 '$body' => $msg['textversion'], // text version of the message
663 '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
666 // use the EmailNotification library to send the message
667 require_once("include/EmailNotification.php");
668 EmailNotification::sendTextHtmlEmail(
669 $msg['notificationfromname'],
670 t("Administrator@") . $a->get_hostname(),
671 t("noreply") . '@' . $a->get_hostname(),
673 sprintf( t('%s commented on an item at %s'), $from , $a->config['sitename']),
674 $email_html_body_tpl,
681 // We won't be able to sign Diaspora comments for authenticated visitors - we don't have their private key
684 require_once('include/bb2diaspora.php');
685 $signed_body = html_entity_decode(bb2diaspora($datarray['body']));
686 $myaddr = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
687 if($datarray['verb'] === ACTIVITY_LIKE)
688 $signed_text = $datarray['guid'] . ';' . 'Post' . ';' . $parent_item['guid'] . ';' . 'true' . ';' . $myaddr;
690 $signed_text = $datarray['guid'] . ';' . $parent_item['guid'] . ';' . $signed_body . ';' . $myaddr;
692 $authorsig = base64_encode(rsa_sign($signed_text,$a->user['prvkey'],'sha'));
694 q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
697 dbesc(base64_encode($authorsig)),
705 // let me know if somebody did a wall-to-wall post on my profile
707 if(($user['notify-flags'] & NOTIFY_WALL) && ($contact_record != $author)) {
708 push_lang($user['language']);
709 require_once('bbcode.php');
710 $from = $author['name'];
712 // name of the automated email sender
713 $msg['notificationfromname'] = $from;
714 // noreply address to send from
715 $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
718 // process the message body to display properly in text mode
720 = html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8');
723 // process the message body to display properly in text mode
725 = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$datarray['body']))));
727 // load the template for private message notifications
728 $tpl = load_view_file('view/wall_received_html_body_eml.tpl');
729 $email_html_body_tpl = replace_macros($tpl,array(
730 '$username' => $user['username'],
731 '$sitename' => $a->config['sitename'], // name of this site
732 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
733 '$thumb' => $author['thumb'], // thumbnail url for sender icon
734 '$url' => $author['url'], // full url for the site
735 '$from' => $from, // name of the person sending the message
736 '$body' => $msg['htmlversion'], // html version of the message
737 '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
740 // load the template for private message notifications
741 $tpl = load_view_file('view/wall_received_text_body_eml.tpl');
742 $email_text_body_tpl = replace_macros($tpl,array(
743 '$username' => $user['username'],
744 '$sitename' => $a->config['sitename'], // name of this site
745 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
746 '$thumb' => $author['thumb'], // thumbnail url for sender icon
747 '$url' => $author['url'], // full url for the site
748 '$from' => $from, // name of the person sending the message
749 '$body' => $msg['textversion'], // text version of the message
750 '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
753 // use the EmailNotification library to send the message
754 require_once("include/EmailNotification.php");
755 EmailNotification::sendTextHtmlEmail(
756 $msg['notificationfromname'],
757 t("Administrator@") . $a->get_hostname(),
758 t("noreply") . '@' . $a->get_hostname(),
760 sprintf( t('%s posted to your profile wall at %s') , $from , $a->config['sitename']),
761 $email_html_body_tpl,
768 $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `plink` = '%s', `changed` = '%s', `last-child` = 1, `visible` = 1
769 WHERE `id` = %d LIMIT 1",
771 dbesc(($parent == $post_id) ? $uri : $parent_item['uri']),
772 dbesc($a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id),
773 dbesc(datetime_convert()),
777 // photo comments turn the corresponding item visible to the profile wall
778 // This way we don't see every picture in your new photo album posted to your wall at once.
779 // They will show up as people comment on them.
781 if(! $parent_item['visible']) {
782 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d LIMIT 1",
783 intval($parent_item['id'])
788 logger('mod_item: unable to retrieve post that was just stored.');
789 notify( t('System error. Post not saved.'));
790 goaway($a->get_baseurl() . "/" . $_POST['return'] );
794 proc_run('php', "include/notifier.php", $notify_type, "$post_id");
796 $datarray['id'] = $post_id;
797 $datarray['plink'] = $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id;
799 call_hooks('post_local_end', $datarray);
801 if(strlen($emailcc) && $profile_uid == local_user()) {
802 $erecips = explode(',', $emailcc);
803 if(count($erecips)) {
804 foreach($erecips as $recip) {
805 $addr = trim($recip);
808 $disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendika social network.'),$a->user['username'])
810 $disclaimer .= sprintf( t('You may visit them online at %s'), $a->get_baseurl() . '/profile/' . $a->user['nickname']) . EOL;
811 $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
813 $subject = '[Friendika]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']);
814 $headers = 'From: ' . $a->user['username'] . ' <' . $a->user['email'] . '>' . "\n";
815 $headers .= 'MIME-Version: 1.0' . "\n";
816 $headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
817 $headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n";
818 $link = '<a href="' . $a->get_baseurl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
819 $html = prepare_body($datarray);
820 $message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
821 @mail($addr, $subject, $message, $headers);
832 logger('post_complete');
834 // figure out how to return, depending on from whence we came
839 if((x($_POST,'return')) && strlen($_POST['return'])) {
840 logger('return: ' . $_POST['return']);
841 goaway($a->get_baseurl() . "/" . $_POST['return'] );
843 $json = array('success' => 1);
844 if(x($_POST,'jsreload') && strlen($_POST['jsreload']))
845 $json['reload'] = $a->get_baseurl() . '/' . $_POST['jsreload'];
847 logger('post_json: ' . print_r($json,true), LOGGER_DEBUG);
849 echo json_encode($json);
858 function item_content(&$a) {
860 if((! local_user()) && (! remote_user()))
863 require_once('include/security.php');
865 if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
866 require_once('include/items.php');
867 drop_item($a->argv[2]);