public function parse_body()
{
// Parse the body and remove signatures, and reformat
$parts = array();
$fragments = EmailReplyParser::read($this->body);
foreach ($fragments as $fragment) {
// We don't care about hidden parts (signatures, eg)
if ($fragment->isHidden()) {
continue;
} elseif ($fragment->isQuoted()) {
// Remove leading quote symbols
$quoted = preg_replace('/^> */m', '', $fragment->getContent());
// Reparse to ensure that we strip signatures from here too
$subfragments = EmailReplyParser::read($quoted);
$subparts = array();
foreach ($subfragments as $subfrag) {
if ($subfrag->isHidden()) {
continue;
}
$subparts[] = $subfrag->getContent();
}
$parts[] = '<blockquote>' . implode("\n", $subparts) . '</blockquote>';
} else {
$parts[] = $fragment->getContent();
}
}
$content = implode("\n", $parts);
return $content;
}
public function handle_insert($value, Falcon_Reply $reply) { if (!empty($value)) { return $value; } $post = get_post($reply->post); if (!$this->is_allowed_type($post->post_type)) { return $value; } $user = $reply->get_user(); if ($reply->is_valid()) { Falcon::notify_invalid($user, bbp_get_topic_title($reply->post)); return false; } $new_reply = array('post_parent' => $reply->post, 'post_author' => $user->ID, 'post_content' => $reply->parse_body(), 'post_title' => $reply->subject); $meta = array('author_ip' => '127.0.0.1', 'forum_id' => bbp_get_topic_forum_id($reply->post), 'topic_id' => $reply->post); $reply_id = bbp_insert_reply($new_reply, $meta); do_action('bbp_new_reply', $reply_id, $meta['topic_id'], $meta['forum_id'], false, $new_reply['post_author']); // bbPress removes the user's subscription because bbp_update_reply() is hooked to 'bbp_new_reply' and it checks for $_POST['bbp_topic_subscription'] bbp_add_user_subscription($new_reply['post_author'], $meta['topic_id']); return $reply_id; }