/**
  * 系统解密方法
  * @param  string $data 要解密的字符串 (必须是think_encrypt方法加密的字符串)
  * @param  string $key  加密密钥
  * @return string
  */
 static function think_decrypt($data, $key = '')
 {
     $key = md5(empty($key) ? Conf::param('data_auth_key') : $key);
     $data = str_replace(array('-', '_'), array('+', '/'), $data);
     $mod4 = strlen($data) % 4;
     if ($mod4) {
         $data .= substr('====', $mod4);
     }
     $data = base64_decode($data);
     $expire = substr($data, 0, 10);
     $data = substr($data, 10);
     if ($expire > 0 && $expire < time()) {
         return '';
     }
     $x = 0;
     $len = strlen($data);
     $l = strlen($key);
     $char = $str = '';
     for ($i = 0; $i < $len; $i++) {
         if ($x == $l) {
             $x = 0;
         }
         $char .= substr($key, $x, 1);
         $x++;
     }
     for ($i = 0; $i < $len; $i++) {
         if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) {
             $str .= chr(ord(substr($data, $i, 1)) + 256 - ord(substr($char, $i, 1)));
         } else {
             $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
         }
     }
     return base64_decode($str);
 }
예제 #2
0
 public static function _init()
 {
     date_default_timezone_set(Conf::param('timezone'));
     //设置默认时区
     //地址重写
     Rewrite::init();
 }
예제 #3
0
 public function db($linkNum, $config = array())
 {
     static $_db = array();
     if (isset($_db[$linkNum])) {
         return $this->conn = $_db[$linkNum];
     }
     empty($config) && ($config = Conf::param('db'));
     $dbType = ucfirst($config['dbtype']);
     return $this->conn = $_db[$linkNum] = new $dbType($config);
 }
 public static function checkCache($tmpFile)
 {
     if (!Conf::param('tpl_cache_on') || APP_DEBUG) {
         return false;
     }
     if (!is_file($tmpFile)) {
         return false;
     } else {
         if (filectime($tmpFile) > filemtime($tmpFile)) {
             return false;
         } else {
             if (time() > filemtime($tmpFile) + Conf::param('tpl_cache_time')) {
                 return false;
             }
         }
     }
     return true;
 }
예제 #5
0
    static function getHeader($data)
    {
        isset($data['title']) || ($data['title'] = 'BEETHINK');
        isset($data['other']) || ($data['other'] = '');
        isset($data['charset']) || ($data['charset'] = Conf::param('tpl_charset'));
        $str = '<!DOCTYPE html>
<html>
<head>
<meta charset="%s">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">%s
<link rel="shortcut icon" href="../Common/images/favicon.png" type="image/png">
<title>%s</title>';
        $str = sprintf($str, $data['charset'], $data['other'], $data['title']);
        if (isset(self::$tVar['styles'])) {
            $str .= self::getFile(self::$tVar['styles'], 'css');
        }
        return $str;
    }
예제 #6
0
 /**
  * 缓存待基础支持文件
  */
 static function cacheBaseFile()
 {
     $baseList = Conf::param('basefile');
     $cArr = array();
     $con = '';
     $cArr[] = '<?php ';
     foreach ($baseList as $v) {
         $con = file_get_contents($v);
         $cArr[] = self::strip_whitespace($con);
     }
     $cArr[] = ' ?>';
     $fpath = RUNTIME_PATH . 'Class/class.php';
     return file_put_contents($fpath, implode('', $cArr));
 }
예제 #7
0
<?php

$CONF = array('load_ext_config' => '', 'cookie_expire' => 3600, 'cookie_domain' => '', 'cookie_path' => '/', 'charset' => 'utf8', 'contenttype' => 'text/html', 'timezone' => 'PRC', 'autoload' => array(), 'basefile' => array(CORE_PATH . 'Db/Driver/DbMysqli.class.php', CORE_PATH . 'App.class.php', CORE_PATH . 'Model.class.php', CORE_PATH . 'Error.class.php', CORE_PATH . 'View.class.php', CORE_PATH . 'Sys.class.php', CORE_PATH . 'Loadfile.class.php', CORE_PATH . 'Rewrite.class.php'), 'db' => array('dbtype' => 'DbMysqli', 'host' => 'localhost', 'port' => 3306, 'uname' => 'root', 'psd' => '', 'dbname' => 'test', 'charset' => 'utf8', 'type' => 1), 'url' => array('dep' => '/', 'suffix' => ''), 'error_msg' => '您浏览的页面暂时发生错误!请稍后再试', 'error_page' => '', 'show_error_msg' => false, 'tpl_charset' => 'utf-8', 'tpl_content_type' => 'text/html', 'tpl_action_error' => APP_PATH . 'Tpl/dispathch_jump.tpl', 'tpl_action_success' => APP_PATH . 'Tpl/dispath_jump.tpl', 'tpl_exception_page' => APP_PATH . 'Tpl/exception.tpl', 'tpl_template_suffix' => '.html', 'tpl_cache_on' => true, 'tpl_cache_time' => 0, 'tpl_cache_suffix' => '.html', 'rewrite_module' => 'normal', 'data_auth_key' => 'hello bee');
class Conf
{
    static $conf = array();
    public static function param($data)
    {
        if (is_string($data)) {
            return isset(self::$conf[$data]) ? self::$conf[$data] : null;
        } else {
            if (empty($data)) {
                return self::$conf;
            } else {
                self::$conf = array_merge(self::$conf, array_change_key_case($data));
                return true;
            }
        }
    }
}
Conf::param($CONF);