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; }
/** * Handles Mandrill inbound web hook * * @return void */ public function handle_post() { if (isset($_POST['mandrill_events'])) { $parsed = reset(json_decode(wp_unslash($_POST['mandrill_events']))); if (!$parsed) { return; } $reply = new Falcon_Reply(); $reply->subject = $parsed->msg->subject; $reply->body = $parsed->msg->text; list($reply->post, $reply->site, $reply->user, $reply->nonce) = Falcon_Reply::parse_to($parsed->msg->email); $reply_id = $reply->insert(); if ($reply_id === false) { header('X-Fail: No reply ID', true, 400); echo 'Reply could not be added?'; // intentionally not translated // Log this? } } }
public function handle_insert($value, Falcon_Reply $reply) { if (!empty($value)) { return $value; } $comment_parent = null; list($type, $parent_id) = explode('_', $reply->post, 2); switch ($type) { case 'post': $post = get_post($parent_id); break; case 'comment': $comment_parent = get_comment($parent_id); if (empty($comment_parent)) { return $value; } $post = get_post($comment_parent->comment_post_ID); break; default: return $value; } if (!$this->is_allowed_type($post->post_type)) { return $value; } $user = $reply->get_user(); if (!$reply->is_valid()) { Falcon::notify_invalid($user, $post->post_title); return new WP_Error('falcon.connector.wordpress.invalid_reply'); } $data = array('comment_post_ID' => $post->ID, 'user_id' => $user->ID, 'comment_author' => $user->display_name, 'comment_author_email' => $user->user_email, 'comment_author_url' => $user->user_url, 'comment_content' => $reply->parse_body()); if (!empty($comment_parent)) { $data['comment_parent'] = $comment_parent->comment_ID; } return wp_insert_comment($data); }
public function handle_post() { $input = file_get_contents('php://input'); if (empty($input)) { header('X-Fail: No input', true, 400); echo 'No input found.'; // intentionally not translated return; } file_put_contents('/tmp/postmark', $input); try { $inbound = new \Postmark\Inbound($input); } catch (\Postmark\InboundException $e) { header('X-Fail: Postmark problem', true, 400); echo $e->getMessage(); return; } // The "Test" button sends an email from support@postmarkapp.com if ($inbound->FromEmail() === '*****@*****.**') { echo 'Hello tester!'; // intentionally not translated return; } $reply = new Falcon_Reply(); $reply->subject = $inbound->Subject(); $reply->body = $inbound->TextBody(); $to = $inbound->Recipients(); list($reply->post, $reply->site, $reply->user, $reply->nonce) = Falcon_Reply::parse_to($to[0]->Email); $reply_id = $reply->insert(); if ($reply_id === false) { header('X-Fail: No reply ID', true, 400); echo 'Reply could not be added?'; // intentionally not translated // Log this? } }