コード例 #1
0
function bp_checkins_handle_places_checkin()
{
    global $bp;
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Check the nonce
    check_admin_referer('place_post_checkin', '_wpnonce_place_post_checkin');
    if (!is_user_logged_in()) {
        echo '-1';
        return false;
    }
    if (empty($_POST['bpci-lat']) || empty($_POST['bpci-lng']) || empty($_POST['bpci-address']) || empty($_POST['place_id'])) {
        echo __('Oops something went wrong, please try again.', 'bp-checkins');
        return false;
    }
    $place_id = intval($_POST['place_id']);
    $group_id = get_post_meta($place_id, '_bpci_group_id', true);
    $place_name = esc_attr($_POST['bpci-address']);
    if (!empty($_POST['place'])) {
        $place_name = esc_attr($_POST['place']);
    }
    $activity_id = 0;
    if (empty($group_id) && bp_is_active('checkins')) {
        $activity_id = bp_checkins_post_update(array('type' => 'place_checkin', 'place_id' => $place_id, 'place_name' => $place_name));
    } else {
        $activity_id = bp_checkins_groups_post_update(array('group_id' => $group_id, 'type' => 'place_checkin', 'place_id' => $place_id, 'place_name' => $place_name));
    }
    if (empty($activity_id)) {
        echo __('There was a problem posting your checkin, please try again.', 'bp-checkins') . '</p></div>';
        return false;
    } else {
        // update checkins count and list of users for this place
        bp_checkins_places_update_checkins_meta($bp->loggedin_user->id, $place_id);
        // update user meta for user & cookie ?
        bp_checkins_places_user_checkins_transcient($bp->loggedin_user->id, $place_id);
        // insert user in group if not a member ?
        echo 'checkedin';
    }
    exit;
}
コード例 #2
0
function bp_checkins_add_checkins_meta_to_comment($comment_id, $is_approved = true)
{
    /**
     * inspired by BuddyPress bp_blogs_record_comment function
     */
    // is it a place comment !
    if (!empty($_POST['_bpci_place_id'])) {
        $checkin = !empty($_POST['_checkin_comment']) ? $_POST['_checkin_comment'] : false;
        $place_id = intval($_POST['_bpci_place_id']);
        $place_name = esc_attr($_POST['_bpci_place_name']);
        $image_data = $_POST['_bpci_comment_image_url'];
        $group_id = get_post_meta($place_id, '_bpci_group_id', true);
        $html_meta = false;
        if (empty($is_approved)) {
            return false;
        }
        $recorded_comment = get_comment($comment_id);
        // Don't record activity if no email address has been included
        if (empty($recorded_comment->comment_author_email)) {
            return false;
        }
        // Don't record activity if no content has been included
        if (empty($recorded_comment->comment_content)) {
            return false;
        }
        // Get the user_id from the comment author email.
        $user = get_user_by('email', $recorded_comment->comment_author_email);
        $user_id = (int) $user->ID;
        $recorded_comment->post = get_post($recorded_comment->comment_post_ID);
        if (empty($recorded_comment->post) || is_wp_error($recorded_comment->post)) {
            return false;
        }
        // Stop if the comment's associated post isn't a Place Post
        if (!in_array($recorded_comment->post->post_type, array('places'))) {
            return false;
        }
        // preparing activity content
        $activity_content = wp_kses($recorded_comment->comment_content, array());
        $activity_content = bp_create_excerpt($activity_content, 180, array('filter_shortcodes' => true));
        //Now let's first record comment meta data (image) !
        if (!empty($image_data)) {
            $is_metas = explode('|', $image_data);
            if (count($is_metas) > 1) {
                $html_meta = '<a href="' . $is_metas[0] . '" class="bp-ci-zoompic align-left"><img src="' . $is_metas[1] . '" width="100px" alt="Photo" class="align-left thumbnail" /></a>';
            } else {
                $html_meta = '<a href="' . $image_data . '" class="bp-ci-zoompic align-left"><img src="' . $image_data . '" width="100px" alt="Photo" class="align-left thumbnail" /></a>';
            }
            if (!empty($html_meta)) {
                update_comment_meta($comment_id, '_bpci_comment_image', $html_meta);
            }
        }
        //do we have a checkin or is it a regular comment ?
        if (!empty($checkin)) {
            $args = array('content' => $html_meta . $activity_content, 'user_id' => $user_id, 'type' => 'place_checkin_comment', 'place_id' => $place_id, 'place_name' => $place_name, 'comment_id' => $comment_id);
            // update checkins count and list of users for this place
            bp_checkins_places_update_checkins_meta($user_id, $place_id);
            // update user meta for user & cookie ?
            bp_checkins_places_user_checkins_transcient($user_id, $place_id);
        } else {
            // empty lat lng address posted values...
            unset($_POST['bpci-lat']);
            unset($_POST['bpci-lng']);
            unset($_POST['bpci-address']);
            $args = array('content' => $html_meta . $activity_content, 'user_id' => $user_id, 'type' => 'place_comment', 'place_id' => $place_id, 'place_name' => $place_name, 'comment_id' => $comment_id);
        }
        if (empty($group_id)) {
            $activity_id = bp_checkins_post_update($args);
        } else {
            $args['group_id'] = $group_id;
            $activity_id = bp_checkins_groups_post_update($args);
        }
        do_action('bp_chekins_places_recorded_comment', $recorded_comment->post->post_author, $place_id, $user_id, $comment_id);
        return true;
    }
}