forked from nukeviet/nukeviet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
robots.php
94 lines (80 loc) · 2.93 KB
/
robots.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
<?php
/**
* NukeViet Content Management System
* @version 4.x
* @author VINADES.,JSC <[email protected]>
* @copyright (C) 2009-2021 VINADES.,JSC. All rights reserved
* @license GNU/GPL version 2 or any later version
* @see https://github.com/nukeviet The NukeViet CMS GitHub project
*/
define('NV_SYSTEM', true);
define('NV_ROOTDIR', pathinfo(str_replace(DIRECTORY_SEPARATOR, '/', __FILE__), PATHINFO_DIRNAME));
require NV_ROOTDIR . '/includes/mainfile.php';
$cache_file = NV_ROOTDIR . '/' . NV_DATADIR . '/robots.php';
if (file_exists($cache_file)) {
$createTime = filemtime($cache_file);
include $cache_file;
$robots_data = unserialize($cache);
$robots_other = unserialize($cache_other);
} else {
$createTime = gmmktime(0, 0, 0, date('m'), 1, date('Y'));
$robots_data = [];
$robots_data['/' . NV_DATADIR . '/'] = 0;
$robots_data['/includes/'] = 0;
$robots_data['/install/'] = 0;
$robots_data['/modules/'] = 0;
$robots_data['/robots.php'] = 0;
$robots_data['/web.config'] = 0;
$robots_other = [];
}
$host = (isset($_GET['action']) and !empty($_GET['action'])) ? $_GET['action'] : $_SERVER['HTTP_HOST'];
$maxAge = 2592000;
$expTme = $createTime + $maxAge;
$hash = $createTime . '-' . md5($host);
header('Etag: "' . $hash . '"');
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) and stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == '"' . $hash . '"') {
http_response_code(304);
header('Content-Length: 0');
exit();
}
$base_siteurl = pathinfo($_SERVER['PHP_SELF'], PATHINFO_DIRNAME);
if ($base_siteurl == '\\' or $base_siteurl == '/') {
$base_siteurl = '';
}
if (!empty($base_siteurl)) {
$base_siteurl = str_replace('\\', '/', $base_siteurl);
}
if (!empty($base_siteurl)) {
$base_siteurl = preg_replace('/[\/]+$/', '', $base_siteurl);
}
if (!empty($base_siteurl)) {
$base_siteurl = preg_replace('/^[\/]*(.*)$/', '/\\1', $base_siteurl);
$base_siteurl = preg_replace('#/index\.php(.*)$#', '', $base_siteurl);
}
$base_siteurl .= '/';
$contents = [];
$contents[] = 'User-agent: *';
foreach ($robots_data as $key => $value) {
if ($value == 0) {
$contents[] = 'Disallow: ' . $key;
} elseif ($value == 2) {
$contents[] = 'Allow: ' . $key;
}
}
foreach ($robots_other as $key => $value) {
if ($value == 0) {
$contents[] = 'Disallow: ' . $key;
} elseif ($value == 2) {
$contents[] = 'Allow: ' . $key;
}
}
$contents[] = 'Sitemap: http' . ($global_config['ssl_https'] == 1 ? 's' : '') . '://' . $host . $base_siteurl . 'sitemap.xml';
$contents = implode("\n", $contents);
header('Content-Type: text/plain; charset=utf-8');
header('Cache-Control: public, max-age=' . $maxAge);
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $createTime) . ' GMT');
header('expires: ' . gmdate('D, d M Y H:i:s', $expTme) . ' GMT');
header('X-Frame-Options: SAMEORIGIN');
header('X-Content-Type-Options: nosniff');
header('X-XSS-Protection: 1; mode=block');
print_r($contents);