function wppa_add_credit_points($amount, $reason = '', $id = '', $value = '')
{
    global $user_ID;
    // Initialize
    if (!$user_ID) {
        get_currentuserinfo();
    }
    $bret = false;
    // Must be logged in
    if (!is_user_logged_in()) {
        return $bret;
    }
    // Cube points
    if (function_exists('cp_alterPoints')) {
        cp_alterPoints(cp_currentUser(), $amount);
        $bret = true;
    }
    // myCred
    if (function_exists('mycred_add')) {
        $entry = $reason . ($id ? ', ' . __('Photo id =', 'wppa') . ' ' . $id : '') . ($value ? ', ' . __('Value =', 'wppa') . ' ' . $value : '');
        $bret = mycred_add(str_replace(' ', '_', $reason), $user_ID, $amount, $entry, '', '', '');
        // $ref_id, $data, $type );
    }
    return $bret;
}
Пример #2
0
function cp_api_do()
{
    if (get_option('cp_auth_key') != $_REQUEST['cp_api_key']) {
        $r['error'] = 'Invalid API key';
        return $r;
    }
    $s = $_REQUEST['cp_api'];
    $q = explode('/', $s);
    switch ($q[0]) {
        case 'user':
            switch ($q[1]) {
                case 'login':
                    $user = get_userdatabylogin($q[2]);
                    break;
                case 'id':
                    $user = get_userdata($q[2]);
                    break;
                default:
                    $r['error'] = 'Method not implemented';
                    return $r;
            }
            if ($user->ID == '') {
                $r['error'] = 'Invalid user';
                return $r;
            }
            switch ($q[3]) {
                case '':
                    $r = $user;
                    return $r;
                    break;
                case 'points':
                    switch ($q[4]) {
                        case '':
                            $r['points'] = cp_getPoints($user->ID);
                            return $r;
                            break;
                        case 'get':
                            $r['points'] = cp_getPoints($user->ID);
                            return $r;
                            break;
                        case 'set':
                            if (!is_numeric($q[5])) {
                                $r['error'] = 'Points must be integers';
                                return $r;
                            } else {
                                cp_updatePoints($user->ID, (int) $q[5]);
                                $r['points'] = cp_getPoints($user->ID);
                                $r['message'] = 'Points updated';
                                return $r;
                            }
                            break;
                        case 'add':
                            if (!is_numeric($q[5])) {
                                $r['error'] = 'Points must be integers';
                                return $r;
                            } else {
                                switch ($q[6]) {
                                    case '':
                                        cp_alterPoints($user->ID, $q[5]);
                                        $r['points'] = cp_getPoints($user->ID);
                                        $r['message'] = 'Points updated';
                                        return $r;
                                        break;
                                    case 'log':
                                        if ($q[7] == '') {
                                            $r['error'] = 'Log item type must not be empty';
                                            return $r;
                                        }
                                        $data = explode('/', $s, 9);
                                        cp_points($q[7], $user->ID, $q[5], $data[8]);
                                        $r['points'] = cp_getPoints($user->ID);
                                        $r['message'] = 'Points updated';
                                        return $r;
                                        break;
                                    default:
                                        $r['error'] = 'Method not implemented';
                                        return $r;
                                }
                            }
                            break;
                        default:
                            $r['error'] = 'Method not implemented';
                            return $r;
                    }
                    break;
                default:
                    $r['error'] = 'Method not implemented';
                    return $r;
            }
            break;
        default:
            $r['error'] = 'Method not implemented';
            return $r;
    }
}
function wppa_add_credit_points($amount, $reason = '', $id = '', $value = '', $user = '')
{
    // Anything to do?
    if (!$amount) {
        return;
    }
    // Initialize
    $bret = false;
    if ($user) {
        $usr = get_user_by('login', $user);
    } else {
        $usr = wp_get_current_user();
    }
    if (!$usr) {
        wppa_log('err', 'Could not add points to user ' . $user);
        return false;
    }
    // Cube points
    if (function_exists('cp_alterPoints')) {
        cp_alterPoints($usr->ID, $amount);
        $bret = true;
    }
    // myCred
    if (function_exists('mycred_add')) {
        $entry = $reason . ($id ? ', ' . __('Photo id =', 'wp-photo-album-plus') . ' ' . $id : '') . ($value ? ', ' . __('Value =', 'wp-photo-album-plus') . ' ' . $value : '');
        $bret = mycred_add(str_replace(' ', '_', $reason), $usr->ID, $amount, $entry, '', '', '');
    }
    return $bret;
}
Пример #4
0
/**
* Function called when a comment has been deleted or marked as SPAM
*
* @param int id Comment id
* @access public
*/
function sk_actionDelete($id)
{
    global $wpdb;
    //Getcomment data
    $table_name = $wpdb->prefix . "schreikasten";
    $sql = "SELECT * FROM {$table_name} WHERE id={$id}";
    $comments = $wpdb->get_results($sql);
    if (count($comments) > 0) {
        foreach ($comments as $comment) {
            if (function_exists('cp_alterPoints') && $comment->user_id >= 0) {
                cp_alterPoints($comment->user_id, -get_option('cp_del_comment_points'));
                cp_log('schreikasten', $comment->user_id, -get_option('cp_del_comment_points'), $comment->id);
            }
        }
    }
}
Пример #5
0
/** Alter points and add to logs */
function cp_points($type, $uid, $points, $data)
{
    $points = apply_filters('cp_points', $points, $type, $uid, $data);
    cp_alterPoints($uid, $points);
    cp_log($type, $uid, $points, $data);
}