<?php
/**
 *  Guojiz网址导航系统
 *  www.guojiz.com
 *  作者：梦雨
 *  @ QQ50361804
 */
namespace app\admin\controller;

use think\Controller;
use org\Http;
use think\Db;
use think\Config;
use think\Url;
class Index extends Common
{
    public function home()
    {
        $html = Db::name('html');
        $swang = $html->where("open = 1")->count();
        $this->assign('swang', $swang);
        $wwang = $html->where("open = 0")->count();
        $this->assign('wwang', $wwang);
        $gwang = $html->count();
        $this->assign('gwang', $gwang);
        $news = Db::name('news');
        $show = 1;
        $news = $news->where($show)->count();
        $this->assign('news', $news);
        $this->assign('bb', config('banben.BANBEN'));
        $this->assign('key', warning());
        $this->assign('times', pa(2));
        // 优化加速
        Db::name('top')->where('time<'.Date_k(-30))->delete();
        xml();Logoing();return $this->fetch();
    }
    public function sj()
    {
        $xiazai = preg_replace("/\?(.*)|&(.*)|=(.*)/is", '', $_POST['title']);
        if (strpos($xiazai, pa('II1-gcAid5j5kYcnVKC9nUFWbHWibJV6UZTjX5T5vYMqt')) !== false) {
            $url = $xiazai . urlencode(iconv("GB2312", "UTF-8", ""));
            $save_dir = 'runtime/';
            $filename = 'shengji.zip';
            $res = getFile($url, $save_dir, $filename, 0);
            return json(array('code' => 200, 'msg' => '升级成功'));
        } else {
            return json(array('code' => 0, 'msg' => '请复制官方的升级链接'));
        }
        
            $xiazai = $_POST['title'];
            $url = $xiazai . urlencode(iconv("GB2312", "UTF-8", ""));
            $save_dir = 'runtime/';
            $filename = 'shengji.zip';
            $res = getFile($url, $save_dir, $filename, 0);
            return json(array('code' => 200, 'msg' => '升级成功'));
    }
    //解压
    public function ad()
    {
            $zip = new \ZipArchive();
            if ($zip->open('runtime/shengji.zip') === TRUE) {
                $zip->extractTo('.');
                $zip->close();
                unlink('runtime/shengji.zip');
                header("content-type:text/html;charset=utf-8");
                header('location:/admin.php/index/home.html');
            }

    }
    function update()
    {
        array_map('unlink', glob(TEMP_PATH . '/*.php'));
        rmdir(TEMP_PATH);Logoing();
        return json(array('code' => 200, 'msg' => '更新缓存成功'));
    }
    public function index()
    {
        return view();
    }
}