예제 #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));
            }
        }
    }
}
예제 #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));
}
예제 #3
0
function xt_catalog_delete($ids)
{
    global $wpdb;
    $ids = explode(',', $ids);
    if (!empty($ids)) {
        foreach ($ids as $id) {
            $id = intval($id);
            $_catalog = xt_get_catalog($id);
            if (!empty($_catalog)) {
                if ($_catalog->type == 'share') {
                    //删除分享与分类的关系
                    xt_delete_share_catalog($id);
                    xt_delete_tag_catalog($id);
                    //删除标签与分类的关系
                    $wpdb->query('DELETE FROM ' . XT_TABLE_CATALOG_ITEMCAT . ' WHERE id=' . $id);
                    //删除自动分类配置
                } elseif ($_catalog->type == 'album') {
                    xt_delete_album_catalog($id);
                    //删除专辑与分类的关系
                }
                $childs = $wpdb->get_col('SELECT id FROM ' . XT_TABLE_CATALOG . ' WHERE parent=' . $id);
                if (!empty($childs)) {
                    //删除子分类
                    xt_catalog_delete(implode(',', $childs));
                }
                $wpdb->delete(XT_TABLE_CATALOG, array('id' => $id));
            }
        }
    }
}