forked from qupb/oneindex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
147 lines (127 loc) · 3.3 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
<?php
error_reporting(E_ALL & ~E_NOTICE);
date_default_timezone_set('PRC');
define('TIME', time());
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');
/**
* config('name');
* config('name@file');
* config('@file');
*/
!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) . ";", LOCK_EX);
} else {
//返回结果
if (!empty($key)) {
return $configs[$file][$key];
}
return $configs[$file];
}
}
/**
* config('name');
* config('name@file');
* config('@file');
*/
!defined('CACHE_PATH') && define('CACHE_PATH', ROOT . 'cache/');
if(config('cache_type') == 'sqlite'){
function cache($key, $value = null) {
$store = new sqlite('cache',CACHE_PATH.'data.sqlite3');
if (is_null($value)) {
$cache = $store->get($key);
return (array)json_decode($cache, true);
} else {
$data = array(TIME, $value);
$store->set($key, json_encode($data));
return $data;
}
}
}else{
function cache($key, $value = null) {
$file = CACHE_PATH . md5($key) . '.php';
if (is_null($value)) {
$cache = @include $file;
return (array)$cache;
} else {
file_put_contents($file, "<?php return " . var_export(array(TIME, $value), true) . ";", LOCK_EX);
return array(TIME, $value);
}
}
}
if (!function_exists('db')) {
function db($table) {
return db::table($table);
}
}
!defined('VIEW_PATH') && define('VIEW_PATH', ROOT . 'view/');
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("fastcgi_finish_request")) {
function fastcgi_finish_request() {
ob_flush();
flush();
}
}
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).'/');
}
onedrive::$client_id = config('client_id');
onedrive::$client_secret = config('client_secret');
onedrive::$redirect_uri = config('redirect_uri');
onedrive::$app_url = config('app_url');