示例#1
0
function xt_admin_ajax_tag_add()
{
    $result = array('code' => 0, 'msg' => '', 'result' => array());
    if (!current_user_can('manage_options')) {
        exit('您无权操作此功能');
    }
    if (!isset($_POST['title']) || empty($_POST['title'])) {
        exit('未指定分类标题');
    }
    if ($result['code'] == 0) {
        $title = $_POST['title'];
        $cid = $_POST['catalog'];
        $sort = isset($_POST['sort']) ? absint($_POST['sort']) : 100;
        $data = array();
        $data['title'] = $title;
        $data['sort'] = $sort;
        $data['is_hot'] = 0;
        if (!empty($data)) {
            $tag = xt_get_tag(0, $title);
            $tagSort = 100;
            $id = 0;
            if (empty($tag)) {
                $id = xt_new_tag($data);
                $tagSort = xt_tag_default_sort($title);
            } else {
                $id = $tag->id;
                $tagSort = $tag->sort;
            }
            if ($id > 0 && $cid > 0 && xt_catalog_exit($cid)) {
                if (!xt_tag_catalog_exit($id, $cid)) {
                    xt_new_tag_catalog(array('id' => $id, 'cid' => $cid, 'sort' => $tagSort));
                }
            }
        }
        exit;
    }
    exit('未知错误');
}
示例#2
0
function xt_insert_catalog($catalogdata)
{
    global $wpdb;
    extract(stripslashes_deep($catalogdata), EXTR_SKIP);
    if ($parent > 0) {
        $_catalog = xt_get_catalog($parent);
        if (empty($_catalog)) {
            return 0;
        }
    }
    if (xt_catalog_exit(0, $title, $parent, $type)) {
        return 0;
    }
    $data = compact('title', 'pic', 'sort', 'parent', 'is_front', 'keywords', 'description', 'type');
    if (isset($catalogdata['id'])) {
        $data['id'] = $catalogdata['id'];
    }
    if ($wpdb->insert(XT_TABLE_CATALOG, $data)) {
        if ($parent > 0) {
            $children = $wpdb->get_col('SELECT id FROM ' . XT_TABLE_CATALOG . ' WHERE parent=' . intval($parent));
            if (!empty($children)) {
                $wpdb->update(XT_TABLE_CATALOG, array('children' => implode(',', $children)), array('id' => intval($parent)));
            }
        }
        return $wpdb->insert_id;
    }
    return 0;
}