예제 #1
0
function xt_admin_notices()
{
    global $wpdb;
    $option_env = get_option(XT_OPTION_ENV);
    $env = IS_BAE ? 'BAE' : (IS_SAE ? 'SAE' : 'VPS');
    if (empty($option_env)) {
        update_option(XT_OPTION_ENV, $env);
    } else {
        if ($env != $option_env) {
            update_option(XT_OPTION_ENV, $env);
        }
    }
    $permalink_structure = get_option('permalink_structure');
    if (empty($permalink_structure)) {
        add_action('admin_notices', 'xt_admin_notice_permalink_structure');
        return true;
    }
    //HOME
    $base = xt_base();
    if (!empty($base)) {
        $home_id = $wpdb->get_var("SELECT id FROM `" . $wpdb->posts . "` WHERE `post_name` = '" . $base . "'\tAND `post_type` != 'revision'");
        if (empty($home_id)) {
            require_once XT_PLUGIN_DIR . '/xt-core/xt-installer-functions.php';
            $home_id = xt_install_home();
        }
    }
    //MENUS
    $global = get_option(XT_OPTION_GLOBAL);
    if (!$global['isMenu']) {
        require_once XT_PLUGIN_DIR . '/xt-core/xt-installer-functions.php';
        xt_install_menu($global);
    }
    $isInstalled = get_option(XT_OPTION_INSTALLED);
    if (!$isInstalled) {
        add_action('admin_notices', 'xt_admin_notice_installing');
    } else {
        if (!file_exists(get_template_directory() . '/xt-page.php')) {
            if (!@copy(XT_THEME_PATH . '/xt-page.php', get_template_directory() . '/xt-page.php')) {
                add_action('admin_notices', 'xt_admin_notice_template');
                return true;
            }
        }
        $app = xt_is_ready();
        if (empty($app)) {
            add_action('admin_notices', 'xt_admin_notice_app');
            return true;
        }
        $app = xt_taobao_is_ready();
        if (empty($app)) {
            add_action('admin_notices', 'xt_admin_notice_app_taobao');
            return true;
        }
        if (!isset($app['tkpid']) || empty($app['tkpid'])) {
            add_action('admin_notices', 'xt_admin_notice_app_taobao_tkpid');
            return true;
        }
        if (!isset($app['s8pid']) || empty($app['s8pid'])) {
            add_action('admin_notices', 'xt_admin_notice_app_taobao_s8pid');
            return true;
        }
        //        $app = xt_taobao_is_session_ready();
        //        if (empty($app)) {
        //            add_action('admin_notices', 'xt_admin_notice_app_taobao_session');
        //            return true;
        //        }
        $app = xt_paipai_is_ready();
        if (empty($app)) {
            add_action('admin_notices', 'xt_admin_notice_app_paipai');
            return true;
        }
        $app = xt_paipai_is_session_ready();
        if (empty($app)) {
            add_action('admin_notices', 'xt_admin_notice_app_paipai_session');
            return true;
        }
    }
}
function xt_install_home()
{
    return wp_insert_post(array('post_title' => '新淘客首页(默认)', 'post_type' => 'page', 'post_name' => xt_base(), 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_content' => '<h1>新淘客默认首页,请勿编辑该页面</h1>', 'post_status' => 'publish', 'post_author' => 0, 'menu_order' => 0));
}
예제 #3
0
function xt_screens()
{
    global $xt, $wp_query, $xt_catalog, $xt_user, $xt_album, $xt_taobao_item, $xt_template_name;
    if (xt_is_404()) {
        if (is_home()) {
            xt_clear_404();
            $xt->is_xintao = true;
            $xt->is_index = true;
            $xt_template_name = 'home';
        } elseif (is_front_page()) {
            if (is_page(xt_base()) && !isset($wp_query->query_vars['xt_action'])) {
                xt_clear_404();
                $xt->is_xintao = true;
                $xt->is_index = true;
                $xt_template_name = 'home';
            } elseif (!isset($wp_query->query_vars['xt_action'])) {
                $xt->is_xintao = false;
            }
        }
    }
    if (is_404() && !$xt->is_xintao) {
        $xt->is_xintao = true;
        xt_set_404();
    }
    if ($xt->is_xintao) {
        if (isset($_GET['invite']) && absint($_GET['invite']) > 0) {
            setcookie(XT_USER_PARENT, (string) $_GET['invite'], time() + 1296000, COOKIEPATH, COOKIE_DOMAIN);
        }
        $xt_share_param = isset($wp_query->query_vars['xt_param']) ? $wp_query->query_vars['xt_param'] : '';
        if ($xt->is_shares) {
            query_shares($xt_share_param);
            if (isset($xt_share_param['s']) && !empty($xt_share_param['s'])) {
                //设置搜索词
                $wp_query->set('s', $xt_share_param['s']);
            }
            if (absint($xt_share_param['cid']) > 0) {
                $_term = xt_get_catalog($xt_share_param['cid']);
                if (!empty($_term)) {
                    $xt_catalog = $_term;
                }
            }
        } elseif ($xt->is_albums) {
            query_albums($xt_share_param);
            if (isset($xt_share_param['s']) && !empty($xt_share_param['s'])) {
                //设置搜索词
                $wp_query->set('s', $xt_share_param['s']);
            }
        } elseif ($xt->is_share) {
            $xt_user = null;
            if (absint($xt_share_param) > 0) {
                query_shares(array('id' => absint($xt_share_param)));
                if (xt_have_shares()) {
                    xt_the_share();
                    $xt_user = new WP_User(get_the_share_userid());
                    if (!empty($xt_user) && $xt_user->ID != 0) {
                        xt_setup_single_userdata();
                    } else {
                        xt_set_404();
                    }
                } else {
                    xt_set_404();
                }
            } else {
                xt_set_404();
            }
        } elseif ($xt->is_user) {
            $xt_user = null;
            if (absint($xt_share_param) > 0) {
                $uid = absint($xt_share_param);
                $_user = wp_get_current_user();
                if ($_user->exists()) {
                    if ($_user->ID == $uid) {
                        $xt_user = $_user;
                    }
                }
                if (empty($xt_user) || $xt_user->ID == 0) {
                    $_user = new WP_User($uid);
                    if ($_user && $_user->ID != 0) {
                        $xt_user = $_user;
                    }
                }
                if (!empty($xt_user) && $xt_user->ID != 0) {
                    xt_setup_single_userdata();
                }
            }
            if (empty($xt_user) || $xt_user->ID == 0) {
                xt_set_404();
            }
        } elseif ($xt->is_account) {
            $xt_user = wp_get_current_user();
            if ($xt_user->exists()) {
                //xt_setup_single_userdata();
            } else {
                xt_set_404();
                wp_safe_redirect(site_url('wp-login.php'));
                exit;
            }
        } elseif ($xt->is_album) {
            $xt_user = null;
            $xt_album = null;
            if (absint($xt_share_param) > 0) {
                $xt_album = xt_get_album($xt_share_param);
                if (!empty($xt_album)) {
                    $_user = wp_get_current_user();
                    if ($_user->exists()) {
                        if ($_user->ID == $xt_album->user_id) {
                            $xt_user = $_user;
                        } else {
                            $xt_user = new WP_User($xt_album->user_id);
                        }
                    } else {
                        $xt_user = new WP_User($xt_album->user_id);
                    }
                    if (!empty($xt_user) && $xt_user->ID > 0) {
                        xt_setup_single_userdata();
                        //						query_albums(array (
                        //							'page' => 1,
                        //							'album_per_page' => 20,
                        //							'user_id' => $xt_album->user_id
                        //						));
                        //当前专辑所属用户的前20个专辑
                        query_shares(array('album_id' => absint($xt_share_param), 'page' => 1, 'share_per_page' => 40, 'user_id' => $xt_album->user_id));
                    }
                    //当前专辑内的宝贝
                }
                if (empty($xt_album) || empty($xt_user) || $xt_user->ID == 0) {
                    xt_set_404();
                }
            }
        } elseif ($xt->is_page) {
        } elseif ($xt->is_invite) {
            $xt_user = null;
            if (absint($xt_share_param) > 0) {
                $xt_user = new WP_User(absint($xt_share_param));
            }
            if (empty($xt_user) || $xt_user->ID == 0) {
                xt_set_404();
            } else {
                $user = wp_get_current_user();
                if (!$user->exists()) {
                    //15days
                    setcookie(XT_USER_PARENT, (string) $xt_user->ID, time() + 1296000, COOKIEPATH, COOKIE_DOMAIN);
                }
            }
        } elseif ($xt->is_taobao) {
            $xt_taobao_item = xt_taobao_item($xt_share_param, "detail_url,num_iid,title,nick,props_name,cid,pic_url,num,location,price,post_fee,express_fee,ems_fee,item_img,prop_imgs");
            if (is_wp_error($xt_taobao_item)) {
                xt_set_404();
            }
        }
        if (xt_is_404()) {
            $xt_template_name = 'error404';
        }
        if ($xt->is_login) {
            xt_load_template('xt-login', true, true);
        } elseif ($xt->is_jump) {
            xt_load_template('xt-jump', true, true);
        } elseif ($xt->is_sitemap) {
            xt_load_template('xt-sitemap', true, true);
        } else {
            xt_load_template('xt-template', true, true);
        }
    }
}
예제 #4
0
 function xt_site_url($uri)
 {
     return home_url(xt_index() . '/' . xt_base() . '/' . $uri);
 }