function xt_ajax_album_join()
{
    $result = array('code' => 0, 'msg' => '', 'result' => array());
    if (!isset($_POST['album_id'])) {
        $result['code'] = 500;
        $result['msg'] = '未指定专辑';
    }
    if (!isset($_POST['user_id'])) {
        $result['code'] = 500;
        $result['msg'] = '未指定用户';
    }
    if (!isset($_POST['share_id'])) {
        $result['code'] = 500;
        $result['msg'] = '未指定分享';
    }
    // If the user is logged in
    $user = wp_get_current_user();
    if ($user->exists()) {
        global $wpdb;
        if ($user->ID != absint($_POST['user_id'])) {
            $result['code'] = 500;
            $result['msg'] = '用户不一致';
        }
        if (empty($user->display_name)) {
            $user->display_name = $user->user_login;
        }
        $user_name = $wpdb->escape($user->display_name);
    } else {
        $result['code'] = 500;
        $result['msg'] = '未登录';
    }
    if ($result['code'] == 0) {
        $album_id = absint($_POST['album_id']);
        $share_id = $id = absint($_POST['share_id']);
        $user_id = absint($_POST['user_id']);
        $content = $_POST['content'];
        $album = array();
        if ($album_id == 0) {
            $title = $user_name . '的分享';
            $albumdata = compact('title', 'user_id', 'user_name');
            $album_id = xt_new_album($albumdata);
        } else {
            $album = xt_get_share_album($id, $album_id, $user_id);
        }
        if (empty($album)) {
            $albumdata = compact('id', 'album_id', 'user_id', 'user_name');
            $album = xt_new_share_album($albumdata);
            $result['result'] = $album;
            if (!empty($content)) {
                $commentdata = compact('share_id', 'user_name', 'user_id', 'content');
                $comment_id = xt_new_comment($commentdata);
            }
        } else {
            $result['code'] = 2001;
            $result['msg'] = '已经被该专辑收藏过啦!';
        }
    }
    exit(json_encode($result));
}
Exemple #2
0
function xt_share_share($data)
{
    $sharedata = array();
    $sharedata['share_key'] = $data['share_key'];
    $sharedata['title'] = $data['title'];
    $sharedata['pic_url'] = $data['pic_url'];
    $sharedata['price'] = $data['price'];
    $sharedata['cid'] = (int) $data['cid'];
    $sharedata['user_id'] = (int) $data['user_id'];
    $sharedata['user_name'] = $data['user_name'];
    $sharedata['cache_data'] = $data['cache_data'];
    $sharedata['from_type'] = $data['from_type'];
    $sharedata['data_type'] = (int) $data['data_type'];
    $sharedata['content'] = isset($data['content']) ? trim(strip_tags($data['content'])) : null;
    $share_id = xt_new_share($sharedata);
    if ($share_id > 0 && isset($data['album_id'])) {
        $album_id = $albumdata['album_id'] = $data['album_id'];
        if ($albumdata['album_id'] == 0) {
            //insert default album
            if (isset($data['album_title']) && !empty($data['album_title'])) {
                $albumdata['album_title'] = $data['album_title'];
                $album_id = xt_new_album(array('title' => $albumdata['album_title'], 'user_id' => $sharedata['user_id'], 'user_name' => $sharedata['user_name'], 'content' => ''));
            }
        }
        if ($share_id > 0 && $album_id > 0) {
            xt_new_share_album(array('id' => $share_id, 'album_id' => $album_id, 'user_name' => $sharedata['user_name'], 'user_id' => $sharedata['user_id']));
        }
    }
    return $share_id;
}