forked from nukeviet/nukeviet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
robots.php
96 lines (82 loc) · 2.85 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
95
96
<?php
/**
* @Project NUKEVIET 4.x
* @Author VINADES.,JSC ([email protected])
* @Copyright (C) 2014 VINADES.,JSC. All rights reserved
* @License GNU/GPL version 2 or any later version
* @Createdate 4/12/2010, 17:25
*/
define( 'NV_MAINFILE', true );
define( 'NV_ROOTDIR', pathinfo( str_replace( DIRECTORY_SEPARATOR, '/', __file__ ), PATHINFO_DIRNAME ) );
require NV_ROOTDIR . '/includes/constants.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 = array();
$robots_data['/' . NV_CACHEDIR . '/'] = 0;
$robots_data['/' . NV_DATADIR . '/'] = 0;
$robots_data['/' . NV_EDITORSDIR . '/'] = 0;
$robots_data['/includes/'] = 0;
$robots_data['/install/'] = 0;
$robots_data['/language/'] = 0;
$robots_data['/' . NV_LOGS_DIR . '/'] = 0;
$robots_data['/mainfile.php'] = 0;
$robots_data['/modules/'] = 0;
$robots_data['/robots.php'] = 0;
$robots_data['/' . NV_SESSION_SAVE_PATH . '/'] = 0;
$robots_data['/tmp/'] = 0;
$robots_data['/web.config'] = 0;
$robots_other = array();
}
$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'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) == '"' . $hash . '"' )
{
header( 'HTTP/1.1 304 Not Modified' );
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 = array();
$contents[] = 'User-agent: *';
foreach( $robots_data as $key => $value )
{
if( $value == 0 )
{
$contents[] = 'Disallow: ' . $key;
}
}
foreach( $robots_other as $key => $value )
{
if( $value == 0 )
{
$contents[] = 'Disallow: ' . $key;
}
}
$contents[] = 'Sitemap: http://' . $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' );
print_r( $contents );