예제 #1
0
/**
 * Insert view data in ap_meta table and update post meta ANSPRESS_VIEW_META
 * @param  integer $data_id
 * @param  string $type
 * @return boolean
 */
function ap_insert_views($data_id, $type)
{
    if ($type == 'question') {
        $userid = get_current_user_id();
        // log in DB only if not viewed before and not anonymous
        if (!ap_is_already_viewed(get_current_user_id(), $data_id) && $userid != 0) {
            /**
             * FILTER: ap_log_ip_view
             * Toggle ip logging for view count
             * @var boolean
             */
            $log_ip = apply_filters('ap_log_ip_view', true);
            $ip = $log_ip ? $_SERVER['REMOTE_ADDR'] : '';
            ap_add_meta($userid, 'post_view', $data_id, $ip);
        }
        $view = ap_get_qa_views($data_id);
        $view = $view + 1;
        update_post_meta($data_id, ANSPRESS_VIEW_META, apply_filters('ap_insert_views', $view));
        do_action('after_insert_views', $data_id, $view);
        return true;
    } elseif ($type == 'profile') {
        $userid = get_current_user_id();
        // log in DB only if not viewed before and not anonymous
        if (!ap_is_already_viewed(get_current_user_id(), $data_id, 'profile_view') && $userid != 0) {
            ap_add_meta($userid, 'profile_view', $data_id, $_SERVER['REMOTE_ADDR']);
        }
        $view = ap_get_profile_views($data_id);
        $view = $view + 1;
        update_user_meta($data_id, '__profile_views', apply_filters('ap_insert_views', $view));
        do_action('after_insert_views', $data_id, $view);
        return true;
    }
    return false;
}
예제 #2
0
 public function insert_views($post)
 {
     if (is_question() && $post->post_type == 'question') {
         if (!ap_is_already_viewed(get_current_user_id(), $post->ID)) {
             ap_insert_views($post->ID, $post->post_type);
         }
     }
 }