-
Notifications
You must be signed in to change notification settings - Fork 235
/
init.php
150 lines (133 loc) · 3.39 KB
/
init.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
error_reporting(E_ALL & ~E_NOTICE);
date_default_timezone_set('PRC');
define('TIME', time());
!defined('ROOT') && define('ROOT', str_replace("\\", "/", dirname(__FILE__)) . '/');
//__autoload方法
function i_autoload($className) {
if (is_int(strripos($className, '..'))) {
return;
}
$file = ROOT . 'lib/' . $className . '.php';
if (file_exists($file)) {
include $file;
}
}
spl_autoload_register('i_autoload');
!defined('FILE_FLAGS') && define('FILE_FLAGS', LOCK_EX);
/**
* config('name');
* config('name@file');
* config('@file');
*/
if (!function_exists('config')) {
!defined('CONFIG_PATH') && define('CONFIG_PATH', ROOT . 'config/');
function config($key) {
static $configs = array();
list($key, $file) = explode('@', $key, 2);
$file = empty($file) ? 'base' : $file;
$file_name = CONFIG_PATH . $file . '.php';
//读取配置
if (empty($configs[$file]) AND file_exists($file_name)) {
$configs[$file] = @include $file_name;
}
if (func_num_args() === 2) {
$value = func_get_arg(1);
//写入配置
if (!empty($key)) {
$configs[$file] = (array) $configs[$file];
if (is_null($value)) {
unset($configs[$file][$key]);
} else {
$configs[$file][$key] = $value;
}
} else {
if (is_null($value)) {
return unlink($file_name);
} else {
$configs[$file] = $value;
}
}
file_put_contents($file_name, "<?php return " . var_export($configs[$file], true) . ";", FILE_FLAGS);
} else {
//返回结果
if (!empty($key)) {
return $configs[$file][$key];
}
return $configs[$file];
}
}
}
// cache
define('CACHE_PATH', ROOT.'cache/');
cache::$type = empty( config('cache_type') )?'secache':config('cache_type');
if (!function_exists('db')) {
function db($table) {
return db::table($table);
}
}
if (!function_exists('view')) {
function view($file, $set = null) {
return view::load($file, $set = null);
}
}
if (!function_exists('_')) {
function _($str) {
return htmlspecialchars($str);
}
}
if (!function_exists('e')) {
function e($str) {
echo $str;
}
}
if (!function_exists('str_is')) {
function str_is($pattern, $value)
{
if (is_null($pattern)) {
$patterns = [];
}
$patterns = ! is_array($pattern) ? [$pattern] : $pattern;
if (empty($patterns)) {
return false;
}
foreach ($patterns as $pattern) {
if ($pattern == $value) {
return true;
}
$pattern = preg_quote($pattern, '#');
$pattern = str_replace('\*', '.*', $pattern);
if (preg_match('#^'.$pattern.'\z#u', $value) === 1) {
return true;
}
}
return false;
}
}
if (!function_exists('get_domain')) {
function get_domain($url=null)
{
if (is_null($url)) {
return $_SERVER['HTTP_HOST'];
}
return strstr(ltrim(strstr($url, '://'), '://'), '/', true);
}
}
function get_absolute_path($path) {
$path = str_replace(array('/', '\\', '//'), '/', $path);
$parts = array_filter(explode('/', $path), 'strlen');
$absolutes = array();
foreach ($parts as $part) {
if ('.' == $part) continue;
if ('..' == $part) {
array_pop($absolutes);
} else {
$absolutes[] = $part;
}
}
return str_replace('//','/','/'.implode('/', $absolutes).'/');
}
!defined('CONTROLLER_PATH') && define('CONTROLLER_PATH', ROOT.'controller/');
onedrive::$client_id = config('client_id');
onedrive::$client_secret = config('client_secret');
onedrive::$redirect_uri = config('redirect_uri');