function_cache.php
5.08 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: function_cache.php 33604 2013-07-16 03:20:08Z nemohou $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
function updatecache($cachename = '') {
$updatelist = empty($cachename) ? array() : (is_array($cachename) ? $cachename : array($cachename));
if(!$updatelist) {
@include_once libfile('cache/setting', 'function');
build_cache_setting();
$cachedir = DISCUZ_ROOT.'./source/function/cache';
$cachedirhandle = dir($cachedir);
while($entry = $cachedirhandle->read()) {
if(!in_array($entry, array('.', '..')) && preg_match("/^cache\_([\_\w]+)\.php$/", $entry, $entryr) && $entryr[1] != 'setting' && substr($entry, -4) == '.php' && is_file($cachedir.'/'.$entry)) {
@include_once libfile('cache/'.$entryr[1], 'function');
call_user_func('build_cache_'.$entryr[1]);
}
}
foreach(C::t('common_plugin')->fetch_all_data(1) as $plugin) {
$dir = substr($plugin['directory'], 0, -1);
$cachedir = DISCUZ_ROOT.'./source/plugin/'.$dir.'/cache';
if(file_exists($cachedir)) {
$cachedirhandle = dir($cachedir);
while($entry = $cachedirhandle->read()) {
if(!in_array($entry, array('.', '..')) && preg_match("/^cache\_([\_\w]+)\.php$/", $entry, $entryr) && substr($entry, -4) == '.php' && is_file($cachedir.'/'.$entry)) {
@include_once libfile('cache/'.$entryr[1], 'plugin/'.$dir);
call_user_func('build_cache_plugin_'.$entryr[1]);
}
}
}
}
} else {
foreach($updatelist as $entry) {
$entrys = explode(':', $entry);
if(count($entrys) == 1) {
@include_once libfile('cache/'.$entry, 'function');
call_user_func('build_cache_'.$entry);
} else {
@include_once libfile('cache/'.$entrys[1], 'plugin/'.$entrys[0]);
call_user_func('build_cache_plugin_'.$entrys[1]);
}
}
}
}
function writetocache($script, $cachedata, $prefix = 'cache_') {
global $_G;
$dir = DISCUZ_ROOT.'./data/sysdata/';
if(!is_dir($dir)) {
dmkdir($dir, 0777);
}
if($fp = @fopen("$dir$prefix$script.php", 'wb')) {
fwrite($fp, "<?php\n//Discuz! cache file, DO NOT modify me!\n//Identify: ".md5($prefix.$script.'.php'.$cachedata.$_G['config']['security']['authkey'])."\n\n$cachedata?>");
fclose($fp);
} else {
exit('Can not write to cache files, please check directory ./data/ and ./data/sysdata/ .');
}
}
function getcachevars($data, $type = 'VAR') {
$evaluate = '';
foreach($data as $key => $val) {
if(!preg_match("/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/", $key)) {
continue;
}
if(is_array($val)) {
$evaluate .= "\$$key = ".arrayeval($val).";\n";
} else {
$val = addcslashes($val, '\'\\');
$evaluate .= $type == 'VAR' ? "\$$key = '$val';\n" : "define('".strtoupper($key)."', '$val');\n";
}
}
return $evaluate;
}
function smthumb($size, $smthumb = 50) {
if($size[0] <= $smthumb && $size[1] <= $smthumb) {
return array('w' => $size[0], 'h' => $size[1]);
}
$sm = array();
$x_ratio = $smthumb / $size[0];
$y_ratio = $smthumb / $size[1];
if(($x_ratio * $size[1]) < $smthumb) {
$sm['h'] = ceil($x_ratio * $size[1]);
$sm['w'] = $smthumb;
} else {
$sm['w'] = ceil($y_ratio * $size[0]);
$sm['h'] = $smthumb;
}
return $sm;
}
function arrayeval($array, $level = 0) {
if(!is_array($array)) {
return "'".$array."'";
}
if(is_array($array) && function_exists('var_export')) {
return var_export($array, true);
}
$space = '';
for($i = 0; $i <= $level; $i++) {
$space .= "\t";
}
$evaluate = "Array\n$space(\n";
$comma = $space;
if(is_array($array)) {
foreach($array as $key => $val) {
$key = is_string($key) ? '\''.addcslashes($key, '\'\\').'\'' : $key;
$val = !is_array($val) && (!preg_match("/^\-?[1-9]\d*$/", $val) || strlen($val) > 12) ? '\''.addcslashes($val, '\'\\').'\'' : $val;
if(is_array($val)) {
$evaluate .= "$comma$key => ".arrayeval($val, $level + 1);
} else {
$evaluate .= "$comma$key => $val";
}
$comma = ",\n$space";
}
}
$evaluate .= "\n$space)";
return $evaluate;
}
function pluginsettingvalue($type) {
$pluginsetting = $pluginvalue = array();
@include DISCUZ_ROOT.'./data/sysdata/cache_pluginsetting.php';
$pluginsetting = isset($pluginsetting[$type]) ? $pluginsetting[$type] : array();
$varids = $pluginids = array();
foreach($pluginsetting as $pluginid => $v) {
foreach($v['setting'] as $varid => $var) {
$varids[] = $varid;
$pluginids[$varid] = $pluginid;
}
}
if($varids) {
foreach(C::t('common_pluginvar')->fetch_all($varids) as $plugin) {
$values = (array)dunserialize($plugin['value']);
foreach($values as $id => $value) {
$pluginvalue[$id][$pluginids[$plugin['pluginvarid']]][$plugin['variable']] = $value;
}
}
}
return $pluginvalue;
}
function cleartemplatecache() {
$tpl = dir(DISCUZ_ROOT.'./data/template');
while($entry = $tpl->read()) {
if(preg_match("/\.tpl\.php$/", $entry)) {
@unlink(DISCUZ_ROOT.'./data/template/'.$entry);
}
}
$tpl->close();
}
?>