-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.php
More file actions
407 lines (289 loc) · 10.1 KB
/
Copy pathmain.php
File metadata and controls
407 lines (289 loc) · 10.1 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<?php
//
include_once EB_THEME_PLUGIN_INDEX . 'main_function.php';
//echo date('r' ); exit();
//
//print_r( $_GET );
// chế độ bảo trì đang được bật -> tạm dừng mọi truy cập
if (is_file(EB_THEME_CACHE . 'update_running.txt')) {
//
$time_for_bao_tri = file_get_contents(EB_THEME_CACHE . 'update_running.txt', 1);
// Hiển thị chế độ bảo trì trong vòng 2 phút thôi
// if ( date_time - $time_for_bao_tri < 30 ) {
if (date_time - $time_for_bao_tri < 60) {
// if ( date_time - $time_for_bao_tri < 120 ) {
// if ( date_time - $time_for_bao_tri < 300 ) {
// Set trạng thái cho trang 404
EBE_set_header(404);
// $protocol = ( isset($_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
//echo $protocol;
// header( $protocol . ' 404 Not Found' );
$m = 'He thong dang duoc bao tri</title><h1>He thong dang duoc bao tri! Vui long quay lai sau ' . (60 - (date_time - $time_for_bao_tri)) . ' giay';
die('<h1>' . $m . '</h1><script>if (top != self) { alert("' . $m . '") }</script>');
} else {
// xóa file
_eb_remove_file(EB_THEME_CACHE . 'update_running.txt');
echo '<!-- Remove update_running.txt in ebcache dir -->';
}
}
//
//echo $__cf_row['cf_reset_cache'] . '<br>' . "\n";
//echo mtv_id . '<br>' . "\n";
//echo $act . '<br>' . "\n";
//print_r($post);
//echo $_SERVER['REQUEST_URI'] . '<br>' . "\n";
//echo $_SERVER['SCRIPT_NAME'] . '<br>' . "\n";
//echo $_SERVER['QUERY_STRING'] . '<br>' . "\n";
//echo ___eb_cache_getUrl () . '<br>' . "\n";
//exit();
// getUrl gets the queried page with query string
function ___eb_cache_display($cache_time = 60)
{
$filename = ___eb_cache_getUrl();
// nếu sử dụng redis cache thì trả về tham số này luôn
if (defined('EB_REDIS_CACHE') && EB_REDIS_CACHE == true) {
// echo WGR_redis_key($filename);
// die(__FUNCTION__ . ':' . __LINE__);
$rd = new Redis();
$rd->connect(REDIS_MY_HOST, REDIS_MY_PORT);
//echo "Connection to server sucessfully";
// Get the stored data and print it
$data = $rd->get(WGR_redis_key($filename));
// var_dump($data);
// echo "Stored string in redis: " . $data;
if ($data === false) {
return $filename;
}
} else {
// nếu không tồn tại file/
if (!is_file($filename)) {
//
/*
file_put_contents( $filename, '.', LOCK_EX ) or die('ERROR: create cache file');
chmod($filename, 0777);
*/
// exit();
// -> tạo file và trả về tên file
$filew = fopen($filename, 'x+');
// nhớ set 777 cho file
chmod($filename, 0777);
fclose($filew);
//
// exit();
// trả về tên file
return $filename;
}
// nếu tồn tại -> tiếp tục kiểm tra thời gian tạo cache
/*
$filer = fopen( $filename, 'r' );
$data = fread( $filer, filesize( $filename) );
fclose( $filer );
*/
//
$data = file_get_contents($filename, 1);
if ($data == '' || $data == '.') {
return $filename;
}
}
//
$content = explode('|WGR_CACHE|', $data, 2);
if (count($content) < 2 || !is_numeric($content[0])) {
return $filename;
}
//
// $time_file = filemtime($filename);
$time_file = $content[0] * 1;
// echo '<!-- ';
// echo date_time - $time_file . '<br>' . "\n";
// echo $cache_time . '<br>' . "\n";
// echo ' -->';
// 100 is the cache time here!!!
if (date_time - $time_file > $cache_time) {
return $filename;
}
//
die(___eb_cache_mobile_class($content[1]));
}
// set class cho bản mobile nếu sử dụng cache
function ___eb_cache_mobile_class($data)
{
// return false;
// global $func;
if (_eb_checkDevice() == 'mobile') {
$data = str_replace('eb-set-css-pc-mobile', 'style-for-mobile', $data);
}
echo _eb_ssl_template($data);
}
//
function ___eb_cache_end_ob_cache($strEBPageDynamicCache)
{
global $set_time_for_main_cache;
global $arr_private_info_setting;
// exit();
//
$main_content = ob_get_contents();
//
// ob_end_flush();
ob_end_clean();
// xóa các class của WP đi, lằng nhằng vãi -> chiếm dụng nhiều HTML quá
/*
$arr_remove_wp_class = array(
'menu-item-type-custom',
'menu-item-type-taxonomy',
'menu-item-object-blogs',
'menu-item-object-category',
'menu-item-has-children',
);
foreach ( $arr_remove_wp_class as $v ) {
$main_content = str_replace( $v, '', $main_content );
}
*/
// xóa các thẻ TAB đi -> rút gọn lại HTML 1 chút
// $main_content = preg_replace( "/\t/", "", $main_content );
// bỏ phần comment HTML
// $main_content = WGR_remove_js_multi_comment( $main_content, '<!--', '-->' );
// optimize javascript
// bỏ các dấu xuống dòng thừa
// $main_content = preg_replace( "/\n\n/", "\n", $main_content );
// -> echo nội dung ra -> bị ob nên nội dung không được in ra
// echo $main_content;
___eb_cache_mobile_class($main_content);
// thêm câu báo rằng đang lấy nội dung trong cache
$eb_cache_note = WGR_create_eb_cache_note();
//
// echo $eb_cache_note;
// lưu file tĩnh
// _eb_get_static_html ( $strEBPageDynamicCache, $main_content );
___eb_cache_cache($strEBPageDynamicCache, $main_content, $eb_cache_note);
}
// if no cache, callback cache
//ob_start ('___eb_cache_cache');
// mặc định là không cache
$enable_echbay_super_cache = 0;
// kiểm tra các chế độ cache
if ($__cf_row['cf_reset_cache'] > 0) {
/*
if ( is_home() ) {
echo 'home';
}
else {
echo 'not home';
}
*/
// echo $act . '<br>' . "\n";
// nếu thành viên đang đăng nhập -> không cache
if (mtv_id > 0) {
$enable_echbay_super_cache = 3;
}
// sử dụng cache echbay cho một số trang thôi, dùng nhiều chưa kiểm chứng lỗi
else if (
$act == ''
|| $act == 'archive'
|| $act == 'single'
|| $act == 'page'
|| isset($is_page_templates)
) {
// else if ( $act == 'archive' || $act == 'single' || $act == 'page' ) {
$enable_echbay_super_cache = 1;
//
if ($__cf_row['cf_reset_cache'] < 30) {
$enable_echbay_super_cache = 8;
}
// nếu chế độ cache wp đang được bật -> không dùng cache EchBay
else if (defined('WP_CACHE') && WP_CACHE == true) {
$enable_echbay_super_cache = 2;
}
// tắt ép cache -> dùng với các custom page mà cần kiểu submit -> tìm kiếm, đặt hàng
else if (defined('WGR_NO_CACHE') && WGR_NO_CACHE == true) {
$enable_echbay_super_cache = 7;
}
// tắt khi người dùng đang tìm kiếm
else if (isset($_GET['search_advanced'])) {
$enable_echbay_super_cache = 4;
}
} else {
$enable_echbay_super_cache = 9;
}
}
//echo WP_CACHE . '<br>' . "\n";
//
if (isset($css_m_css)) {
// print_r( $css_m_css );
$css_m_css = array_merge($css_m_css, get_body_class());
} else {
$css_m_css = get_body_class();
}
// css riêng của post, page...
$class_css_of_post = '';
// load file index theo theme
$file_index_theo_theme = EB_THEME_URL . 'i.php';
if (using_child_wgr_theme == 1 && is_file(EB_CHILD_THEME_URL . 'i.php')) {
$file_index_theo_theme = EB_CHILD_THEME_URL . 'i.php';
}
//echo $file_index_theo_theme;
// cache chỉ được kích hoạt khi tham số này = 1
if ($enable_echbay_super_cache == 1) {
// nếu có tham số DNS prefetch -> kiểm tra domain hiện tại có trùng với DNS prefetch không
if ($__cf_row['cf_dns_prefetch'] != '') {
$arr_dns_prefetch = explode("\n", trim($__cf_row['cf_dns_prefetch']));
// trùng thì hủy bỏ truy cập này luôn
foreach ($arr_dns_prefetch as $v) {
if (trim($v) == $_SERVER['HTTP_HOST']) {
EBE_set_header(403);
die(file_get_contents(EB_THEME_PLUGIN_INDEX . 'html/dns_prefetch.html', 1));
}
}
}
// check device (có cache) -> mặc định là 1 class css để lát replace nếu là mobile
$css_m_css[] = 'eb-set-css-pc-mobile';
// kiểm tra và hiển thị nội dung cũ nếu có -> có thì nó sẽ exist luôn rồi
$strEBPageDynamicCache = ___eb_cache_display($set_time_for_main_cache);
// tạo file trước để giữ chỗ luôn và ngay đã
// _eb_create_file ( EB_THEME_CACHE . $strEBPageDynamicCache . '.txt', ' ' );
// chưa có -> gọi lệnh cache luôn
// bắt đầu cho bộ cache toàn trang -> ở footer gọi hàm ob_end là được
ob_start();
// gọi đến file index của từng theme
include_once $file_index_theo_theme;
//
___eb_cache_end_ob_cache($strEBPageDynamicCache);
}
// nếu không có cache -> include bình thường thôi
else {
// echo 1;
// check device (không cache)
// $css_m_css = implode( ' ', get_body_class() );
// $css_m_css = '';
// dùng tính năng cache toàn trang thì tạm thời tắt chức năng phát hiện mobile bằng php
if (_eb_checkDevice() == 'mobile') {
$css_m_css[] = 'style-for-mobile';
}
// gọi đến file index của từng theme
//include_once EB_THEME_URL . 'index.php';
include_once $file_index_theo_theme;
// nếu cache đang được bật, nhưng lại dùng cache của đơn vị khác -> cũng hủy cache luôn
if ($enable_echbay_super_cache == 2) {
echo '<!-- EchBay Cache (ebcache) is enable, but an another plugin cache is enable too
If you want to using EchBay Cache, please set WP_CACHE = false or comment WP_CACHE in file wp-config.php -->';
}
// nếu cache đang được bật, nhưng người dùng đăng nhập -> thông báo tới người dùng
else if ($enable_echbay_super_cache == 3) {
echo '<!-- EchBay Cache (ebcache) is enable, but not caching requests by known users -->';
}
//
else if ($enable_echbay_super_cache == 4) {
echo '<!-- EchBay Cache (ebcache) not running in SEARCH method -->';
} else if ($enable_echbay_super_cache == 7) {
echo '<!-- EchBay Cache (ebcache) not running because WGR_NO_CACHE enable -->';
}
// chỉ cache với 1 số trang cụ thể thôi
else if ($enable_echbay_super_cache == 9) {
echo '<!-- EchBay Cache cache only home page, category page, post details page -->';
}
// thời gian tối thiểu để cache là 30s
else if ($enable_echbay_super_cache == 8) {
echo '<!-- EchBay Cache (ebcache) is enable, but not time for reset cache too many short (' . $__cf_row['cf_reset_cache'] . ' secondes). Min 30 secondes -->';
} else {
echo '<!-- EchBay Cache (ebcache) is disable -->';
}
}