Example #1
0
function xt_ajax_admin_share_catalog()
{
    $share_id = isset($_POST['id']) ? intval($_POST['id']) : 0;
    $cids = isset($_POST['cids']) ? $_POST['cids'] : array();
    if ($share_id > 0) {
        xt_delete_share_catalog(0, $share_id);
        //share AND catalog
        if (!empty($cids)) {
            foreach ($cids as $cid) {
                xt_new_share_catalog(array('id' => $share_id, 'cid' => $cid));
            }
        }
    }
}
Example #2
0
function xt_admin_ajax_share_update()
{
    $result = array('code' => 0, 'msg' => '', 'result' => array());
    if (!current_user_can('manage_options')) {
        $result['code'] = 500;
        $result['msg'] = '您无权操作此功能';
    }
    if (!isset($_POST['id']) || empty($_POST['id'])) {
        $result['code'] = 500;
        $result['msg'] = '未指定分享';
    }
    $id = intval(trim($_POST['id']));
    $cids = isset($_POST['cids']) ? $_POST['cids'] : '';
    if ($result['code'] == 0) {
        global $wpdb;
        $query = "SELECT t.*, tr.id AS share_id FROM " . XT_TABLE_CATALOG . " AS t INNER JOIN " . XT_TABLE_SHARE_CATALOG . " AS tr ON t.id = tr.cid WHERE t.type = 'share' AND tr.id =" . $id . " ORDER BY t.sort ASC,t.count DESC";
        $term = $wpdb->get_results($query);
        $old = array();
        if (!empty($term)) {
            foreach ($term as $_term) {
                $old[] = $_term->id;
            }
        }
        $cids = array_map('intval', explode(',', $cids));
        if (empty($cids)) {
            $cids = array();
        }
        $deleteIds = array_diff($old, $cids);
        //delete
        $addIds = array_diff($cids, $old);
        //add
        if (!empty($deleteIds)) {
            foreach ($deleteIds as $del) {
                xt_delete_share_catalog($del, $id);
            }
        }
        if (!empty($addIds)) {
            foreach ($addIds as $add) {
                xt_new_share_catalog(array('cid' => $add, 'id' => $id));
            }
        }
        $share = get_share($id);
        $term = $wpdb->get_results($query);
        //reload
        xt_update_catalog_terms_cache($id, $term, 'share');
        exit(xt_row_share($share, isset($_POST['alternate']) && $_POST['alternate'] ? 0 : 1));
    }
    exit(json_encode($result));
}
Example #3
0
function xt_insert_share($sharedata)
{
    global $wpdb;
    extract(stripslashes_deep($sharedata), EXTR_SKIP);
    $guid = xt_user_guid($user_id);
    $data = compact('title', 'share_key', 'pic_url', 'price', 'cid', 'guid', 'user_id', 'user_name', 'tags', 'cache_data', 'content', 'from_type', 'data_type', 'create_date', 'create_date_gmt', 'update_date', 'update_date_gmt');
    if ($wpdb->insert(XT_TABLE_SHARE, $data)) {
        $id = $wpdb->insert_id;
        //match
        xt_insert_share_match(array('share_id' => $id, 'content_match' => xt_segment_unicode($title)));
        if ($cid > 0) {
            $cids = array();
            //Auto Catalog(By cid)
            if (in_array($from_type, array('taobao', 'paipai'))) {
                $cids = xt_get_catalogs_by_cid($cid, $from_type);
                if (!empty($cids)) {
                    if (!empty($tags)) {
                        xt_update_share_tags(explode(' ', $tags), $cids);
                    }
                }
            }
            //Auto Catalog(By Tags)
            //            if (empty($cids)) {
            //                if (!empty($tags)) {
            //                    $cids = xt_get_catalogs_by_tags(explode(' ', $tags));
            //                }
            //            }
            if (!empty($cids)) {
                foreach ($cids as $_cid) {
                    xt_new_share_catalog(array('id' => absint($id), 'cid' => absint($_cid)));
                }
            }
        } else {
            if (!empty($tags)) {
                xt_update_share_tags(explode(' ', $tags));
            }
        }
        $count = xt_update_user_share_count($user_id);
        return $id;
    }
    return 0;
}