function recipient_box_save($post_id)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (!wp_verify_nonce($_POST['recipient_box_content_nonce'], plugin_basename(__FILE__))) {
        return;
    }
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return;
        }
    } else {
        if (!current_user_can('edit_post', $post_id)) {
            return;
        }
    }
    $recipient = $_POST['recipient'];
    update_post_meta($post_id, 'recipient', $recipient);
    $notified = get_post_meta($post_id, 'notified');
    if (empty($notified)) {
        update_post_meta($post_id, 'notified', "1");
        $pushMessage = get_the_title($post_id);
        $reg_ids = users_gcm_ids($recipient);
        $message = array("chat" => $pushMessage, "user" => "admin");
        send_push_notification($reg_ids, $message);
    }
}
示例#2
0
function send_message($user_id, $message, $recipient)
{
    $post_id = wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $user_id, 'post_title' => $message, 'post_status' => 'draft', 'post_type' => 'message'));
    update_post_meta($post_id, 'recipient', $recipient);
    update_post_meta($post_id, 'author', $user_id);
    //send gcm notification
    $user = get_user_by('id', $user_id);
    $gcm = array("chat" => $message, "user" => $user->user_login);
    $reg_id = users_gcm_ids($recipient);
    send_push_notification($reg_id, $gcm);
}
function send_feedback_after_comment($comment_id)
{
    $comment = get_comment($comment_id);
    $author_uname = $comment->comment_author;
    $raw_message = $comment->comment_content;
    //get author of original post
    $post_id = $comment->comment_post_ID;
    $post = get_post($post_id);
    $author_id = $post->post_author;
    //get comment author gravatar
    $author = get_user_by('login', $author_uname);
    $author_email = $author->user_email;
    $gravatar = get_gravatar_url($author_email);
    $message = array("feedback" => $raw_message, "author" => $author_uname, "icon_url" => $gravatar);
    send_push_notification(users_gcm_ids($author_id), $message);
}
function assignment_type_box_save($post_id)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (!wp_verify_nonce($_POST['assignment_type_box_content_nonce'], plugin_basename(__FILE__))) {
        return;
    }
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return;
        }
    } else {
        if (!current_user_can('edit_post', $post_id)) {
            return;
        }
    }
    $assignment_type = $_POST['assignment_type'];
    update_post_meta($post_id, 'assignment_type', $assignment_type);
    //send push notification if new assignment
    // if ( !wp_is_post_revision( $post_id ) ){
    $notified = get_post_meta($post_id, 'notified');
    if (empty($notified)) {
        $pushMessage = get_the_title($post_id);
        $reg_ids = users_gcm_ids();
        $deadline = get_post_meta($post_id, 'assignment_date', true);
        $firebase = new FirebasePush($pushMessage);
        $firebase->sendPushNotification();
        assignment_send_push($pushMessage, $post_id, $deadline, $reg_ids);
    }
}
    update_post_meta($post_id, 'assignment_address', $_POST['address']);
    update_post_meta($post_id, 'assignment_location', $_POST['lat_lon']);
    update_post_meta($post_id, 'assignment_target', $_POST['target']);
    if ($_POST['target'] == "specific") {
        update_post_meta($post_id, 'assignment_target_person', $_POST['target_person']);
    }
    update_post_meta($post_id, 'assignment_date', $_POST['deadline']);
    update_post_meta($post_id, 'assignment_bounty', $_POST['bounty']);
    //return success message!
    print 1;
    //send message to targets if any
    /**
     * if target is specific, send only to target_person
     * if target is everyone, send to everyone
     * if target is nearby, look for nearest users(or users in same town)
     */
    $reg_ids = users_gcm_ids();
    if ($_POST['target'] == "specific") {
        //send to specific person
        $user = get_user_by('login', $_POST['target_person']);
        $reg_ids = users_gcm_ids($user->ID);
    } else {
        if ($_POST['target'] == "nearby") {
            //send to people nearby
            $reg_ids = get_nearby_users($_POST['lat_lon']);
        }
    }
    assignment_send_push($_POST['title'], $post_id, $_POST['deadline'], $reg_ids);
} else {
    print 0;
}