Ejemplo n.º 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;
}
Ejemplo n.º 2
0
/**
 * Add a follower
 * @param  integer  		$current_user_id   	Current user_id
 * @param  integer  		$user_to_follow 	user to follow
 * @return bollean|integer
 */
function ap_add_follower($current_user_id, $user_to_follow)
{
    $row = ap_add_meta($current_user_id, 'follower', $user_to_follow);
    if ($row !== false) {
        do_action('ap_added_follower', $user_to_follow, $current_user_id);
    }
    return $row;
}
Ejemplo n.º 3
0
/**
 * Add vote meta.
 *
 * @param int    $current_userid    User ID of user casting the vote
 * @param string $type              Type of vote, "vote_up" or "vote_down"
 * @param int    $actionid          Post ID
 * @param int    $receiveing_userid User ID of user receiving the vote. @since 2.3
 *
 * @return int|bool
 */
function ap_add_vote($current_userid, $type, $actionid, $receiving_userid)
{
    $row = ap_add_meta($current_userid, $type, $actionid, $receiving_userid);
    if ($row !== false) {
        do_action('ap_vote_casted', $current_userid, $type, $actionid, $receiving_userid);
    }
    return $row;
}
Ejemplo n.º 4
0
function ap_add_parti($post_id, $user_id, $action, $param = false)
{
    $rows = ap_add_meta($user_id, 'parti', $post_id, $action, $param);
    /* Update the meta only if successfully created */
    if ($rows !== false) {
        $current_parti = ap_get_parti($post_id, true);
        update_post_meta($post_id, ANSPRESS_PARTI_META, $current_parti);
    }
}
Ejemplo n.º 5
0
function ap_insert_views($data_id, $type)
{
    if ($type == 'question') {
        $userid = get_current_user_id();
        $row = ap_add_meta($userid, 'post_view', $data_id, $_SERVER['REMOTE_ADDR']);
        $view = ap_get_views_db($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);
    }
}
Ejemplo n.º 6
0
/**
 * Insert subscriber for question or term
 * @param  integer  		$user_id   	WP user ID
 * @param  integer  		$action_id 	Question ID or Term ID
 * @param  boolean|integer 	$sub_id    	Any sub ID
 * @param  boolean|integer 	$type      	Type of subscriber, empty string for question
 * @return bollean|integer
 */
function ap_add_subscriber($user_id, $action_id, $type = false, $sub_id = false)
{
    if ($type === 'category') {
        $subscribe_type = 'category';
    } elseif ($type === 'tag') {
        $subscribe_type = 'tag';
    } else {
        $subscribe_type = $type;
    }
    $row = ap_add_meta($user_id, 'subscriber', $action_id, $sub_id, $subscribe_type);
    if ($row !== false) {
        do_action('ap_added_subscriber', $action_id, $subscribe_type, $sub_id);
    }
    return $row;
}
Ejemplo n.º 7
0
function ap_add_history($userid = false, $actionid, $parent_id, $param = NULL)
{
    if (!$userid) {
        $userid = get_current_user_id();
    }
    $opts = array('userid' => $userid, 'actionid' => $actionid, 'parent_id' => $parent_id, 'param' => $param);
    $opts = apply_filters('ap_add_history_parms', $opts);
    extract($opts);
    $last_history = ap_get_latest_history($parent_id);
    if ($last_history && $last_history['user_id'] == $userid && $last_history['type'] == $param && $last_history['parent_id'] == $parent_id && $last_history['action_id'] == $actionid) {
        $row = ap_update_meta(array('apmeta_userid' => $userid, 'apmeta_actionid' => $actionid, 'apmeta_value' => $parent_id, 'apmeta_param' => $param), array('apmeta_userid' => $last_history['user_id'], 'apmeta_actionid' => $last_history['action_id'], 'apmeta_value' => $last_history['parent_id'], 'apmeta_param' => $last_history['type']));
    } else {
        $row = ap_add_meta($userid, 'history', $actionid, $parent_id, $param);
    }
    do_action('ap_after_history_' . $parent_id, $userid, $actionid, $param);
    do_action('ap_after_inserting_history', $userid, $actionid, $parent_id, $param);
    return $row;
}
Ejemplo n.º 8
0
/**
 * Insert notification in ap_meta table
 *
 * @param  integer  		$current_user_id   	User id of user triggering this hook
 * @param  integer  		$affected_user_id  	User id of user who is being affected
 * @param  string 			$notification_type 	Type of notification
 * @param  boolean|array 	$args              	arguments for the notification
 * @return integer|boolean
 */
function ap_insert_notification($current_user_id, $affected_user_id, $notification_type, $args = false)
{
    //if effected user id and current user id are same or is anonymous then return
    if ($affected_user_id <= 0 || $affected_user_id == $current_user_id) {
        return;
    }
    //Convert array to query string
    if ($args === false) {
        $args = array();
    }
    switch ($notification_type) {
        case 'new_answer':
        case 'question_update':
        case 'answer_update':
            $post = get_post($args['post_id']);
            $args['permalink'] = get_permalink($post->ID);
            $args['post_title'] = ap_truncate_chars($post->post_title, 50);
            break;
        case 'comment_on_question':
        case 'comment_on_answer':
            $post = get_post($args['post_id']);
            $args['permalink'] = get_comment_link($args['comment_id']);
            $args['post_title'] = ap_truncate_chars($post->post_title, 50);
            break;
        case 'vote_up':
            $post = get_post($args['post_id']);
            $args['user_id'] = $current_user_id;
            $args['permalink'] = get_permalink($post->ID);
            $args['post_title'] = ap_truncate_chars($post->post_title, 50);
            break;
        case 'new_follower':
            $args['permalink'] = ap_user_link($current_user_id);
            $args['user_id'] = $current_user_id;
            break;
        case 'answer_selected':
            $post = get_post($args['post_id']);
            $args['permalink'] = get_permalink($post->ID);
            $args['post_title'] = ap_truncate_chars($post->post_title, 50);
            break;
        case 'received_reputation':
            $args['reputation'] = $args['reputation'];
            $args['permalink'] = ap_user_link($affected_user_id, 'reputation');
            break;
        default:
            $args = apply_filters('ap_notification_args', $args, func_get_args());
            break;
    }
    $args = urlencode(strip_tags(build_query($args)));
    $row = ap_add_meta($current_user_id, 'unread_notification', $affected_user_id, $args, $notification_type);
    if ($row !== false) {
        do_action('ap_insert_notification', $current_user_id, $affected_user_id, $notification_type, $args);
    }
    return $row;
}
Ejemplo n.º 9
0
                    if ($old_vote->vote == -1) {
                        ap_add_meta($userids[$a->contact_id], 'reputation', $answer_id, -3, 'vote_down', $old_vote->datetime);
                        ap_add_meta($userids[$old_vote->contact_id], 'reputation', $answer_id, -1, 'voted_down', $old_vote->datetime);
                    }
                }
            }
            // Anspress will fill it with current datetime otherwise.
            update_post_meta($answer_id, '_ap_updated', $a->datetime);
            update_post_meta($answer_id, '__ap_activity', array('type' => 'new_answer', 'user_id' => $userids[$a->contact_id], 'date' => $a->datetime));
            ap_add_meta($userids[$a->contact_id], 'reputation', $answer_id, 1, 'answer', $a->datetime);
            if ($a->solution) {
                // Select answer for question too.
                update_post_meta($question_id, '_ap_selected', $answer_id);
                // Add reputation log for best answer.
                ap_add_meta($userids[$a->contact_id], 'reputation', $answer_id, 100, 'best_answer', $a->datetime);
                ap_add_meta($userids[$q->contact_id], 'reputation', $answer_id, 15, 'selecting_answer', $a->datetime);
            }
        }
    }
    // Anspress will fill it with current datetime otherwise.
    update_post_meta($question_id, '_ap_updated', $q->create_datetime);
    update_post_meta($question_id, '__ap_activity', array('type' => 'new_question', 'user_id' => $userids[$q->contact_id], 'date' => $q->create_datetime));
    $questions_counter++;
    p('Added question ' . $questions_counter . '/' . count($questions) . ' with ' . count($answers[$q->id]) . ' answers');
}
// Fill users counters.
$users = get_users();
$users_counter = 0;
foreach ($users as $user) {
    $total_questions = $wpdb->get_var("SELECT COUNT(*) FROM wp_posts WHERE post_author={$user->ID} AND post_type='question'");
    update_user_meta($user->ID, '__total_questions', $total_questions);
Ejemplo n.º 10
0
/**
 * @param string $type
 */
function ap_reputation_log($type, $uid, $reputation, $action_id, $current_user_id)
{
    $userinfo = get_userdata($uid);
    if ($userinfo->user_login == '') {
        return false;
    }
    if ($reputation == 0) {
        return false;
    }
    $row = ap_add_meta($uid, 'reputation', $action_id, $reputation, $type);
    if ($row !== false) {
        do_action('ap_added_reputation', $uid, $action_id, $reputation, $type, $current_user_id);
    }
    return $row;
}
Ejemplo n.º 11
0
/**
 * Insert flag vote for comment.
 *
 * @param int   $user_id
 * @param int   $action_id
 * @param mixed $value
 * @param mixed $param
 *
 * @return integer
 */
function ap_insert_comment_flag($user_id, $action_id, $value = null, $param = null)
{
    return ap_add_meta($user_id, 'comment_flag', $action_id, $value, $param);
}
Ejemplo n.º 12
0
function ap_add_recipients($recipient, $sender, $conversation_id)
{
    $recipient = sanitize_comma_delimited($recipient);
    $sender = filter_var($sender, FILTER_SANITIZE_NUMBER_INT);
    $users = array_unique(explode(',', str_replace(' ', '', $recipient . ',' . $sender)));
    if (!empty($users)) {
        foreach ($users as $user) {
            ap_add_meta($user, 'recipient', $conversation_id);
        }
    }
}
Ejemplo n.º 13
0
/**
 * @param integer $actionid
 */
function ap_add_flag($userid, $actionid, $value = NULL, $param = NULL)
{
    return ap_add_meta($userid, 'flag', $actionid, $value, $param);
}
Ejemplo n.º 14
0
function ap_point_log($type, $uid, $points, $data)
{
    $userinfo = get_userdata($uid);
    if ($userinfo->user_login == '') {
        return false;
    }
    if ($points == 0 && $type != 'reset') {
        return false;
    }
    return ap_add_meta($uid, 'point', $data, $points, $type);
}
Ejemplo n.º 15
0
function ap_set_badge($user_id, $badge_id, $badge_type, $action_id = 0)
{
    return ap_add_meta($user_id, 'badge', $action_id, $badge_id, $badge_type);
}