forked from 6tu/phpcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeljs.php
More file actions
executable file
·166 lines (145 loc) · 4.2 KB
/
deljs.php
File metadata and controls
executable file
·166 lines (145 loc) · 4.2 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
<?php
set_time_limit(0);
# 获取$srcdir目录下的 .htm* 文件列表
$srcdir = 'F://yuanjian'; #绝对路径
$updatedir = $srcdir . '-update/';
$filelist = $srcdir . '/list.txt';
if(!is_dir($srcdir)) mkdir($srcdir);
if(!is_dir($updatedir)) mkdir($updatedir);
if(file_exists($filelist)) rename($filelist, $filelist . '.bak');
$filenames = get_filenamesbydir($srcdir);
$fn = '';
foreach ($filenames as $value){
$ext = pathinfo($value, PATHINFO_EXTENSION);
if(strstr($ext, 'htm')) $fn .= $value. PHP_EOL;
}
file_put_contents($filelist, $fn, FILE_APPEND);
echo "\r\n";
$len = strlen($srcdir);
$list_array = explode("\r\n", $fn);
//print_r($list_array);
$i = 1;
foreach($list_array as $v){
if(empty($v)) continue;
$reldir = substr($v, $len);
$srcfn = $srcdir . $reldir;
$str = file_get_contents($srcfn);
# 多个空格转为一个空格
$article = preg_replace ( "/\s(?=\s)/","\\1",$str);
# 删除js
$preg = "/<script[\s\S]*?<\/script>/i";
$html = preg_replace($preg, "", $article, -1);
# 替换其它字串
$article = str_replace("href='https://ysuo.org/blog", "href='/blog", $article);
$article = str_replace('href="https://ysuo.org/blog', 'href="/blog', $article);
$article = str_replace('<a href="https://ys138.win/">', '<a href="https://popcn.net/">', $article);
$html = $article;
$html = beautify_html($html);
$newdir = pathinfo($updatedir . $reldir, PATHINFO_DIRNAME);
if(!is_dir($newdir)) mkdir($newdir, 777, true);
file_put_contents($updatedir . $reldir, $html);
$compstr = bytecomplement($reldir);
echo $i . ' ...... ' . '.' . $reldir . ' ' . $compstr ." done\r\n";
$i++;
}
# 长度补齐
function bytecomplement($str){
$bv = 30;
$length = strlen($str);
if($length < $bv){
$dv = $bv - $length;
$space = '';
for($i = 0; $i < $dv; $i++){
$space .= '.';
}
}else{
$space = ' ';
}
return $space;
}
# HTML 格式化
function beautify_html($html){
$tidy_config = array(
'clean' => true,
'indent' => true,
'indent-spaces' => 4,
'output-xhtml' => true,
'show-body-only' => false,
'wrap' => 0
);
if(function_exists('tidy_parse_string')){
$tidy = new tidy();
$tidy = tidy_parse_string($html, $tidy_config, 'utf8');
$tidy -> cleanRepair();
$tidy = tidy_get_output($tidy);
return $tidy;
}else return $html;
}
# 获取目录下所有文件,包括子目录
function get_allfiles($path,&$files){
if(is_dir($path)){
$dp = dir($path);
while ($file = $dp ->read()){
if($file !== "." && $file !== ".."){
get_allfiles($path."/".$file, $files);
}
}
$dp ->close();
}
if(is_file($path)){
$files[] = $path;
}
}
function get_filenamesbydir($dir){
$files = array();
get_allfiles($dir,$files);
return $files;
}
?>
for($i = 0; $i < $dv; $i++){
$space .= '.';
}
}else{
$space = ' ';
}
return $space;
}
# HTML 格式化
function beautify_html($html){
$tidy_config = array(
'clean' => true,
'indent' => true,
'indent-spaces' => 4,
'output-xhtml' => true,
'show-body-only' => false,
'wrap' => 0
);
if(function_exists('tidy_parse_string')){
$tidy = new tidy();
$tidy = tidy_parse_string($html, $tidy_config, 'utf8');
$tidy -> cleanRepair();
$tidy = tidy_get_output($tidy);
return $tidy;
}else return $html;
}
# 获取目录下所有文件,包括子目录
function get_allfiles($path,&$files){
if(is_dir($path)){
$dp = dir($path);
while ($file = $dp ->read()){
if($file !== "." && $file !== ".."){
get_allfiles($path."/".$file, $files);
}
}
$dp ->close();
}
if(is_file($path)){
$files[] = $path;
}
}
function get_filenamesbydir($dir){
$files = array();
get_allfiles($dir,$files);
return $files;
}
?>