-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha.php
152 lines (148 loc) · 4.29 KB
/
a.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
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
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
require 'framwork/MooPHP.php';
class MyFiles {
function __construct(){
$f = trim($_GET['f']);
empty($f) && $f = 'index';
$this->$f();
}
function index(){
$key = trim($_GET['key']);
$dir = dirname(__file__);
if($key){
$data = $this->getFiles($dir,$key);
if($data){
exit(json_encode($data));
}
exit('');
}
}
function format(){
if($_POST['files']){
foreach ($_POST['files'] as $k => $v) {
if(is_file($v)){
if(strpos($v, '.source')===false){
$suffix = $this->fileSuffix($v);
$filename = basename($v,'.'.$suffix);
$newfile = dirname($v).'/'.$filename.'.source.'.$suffix;
copy($v, $newfile);
}
$this->encrypt($v);
echo '<p style="color:red;font-size:14px;">'.$v.' 处理完成!</p>';
}
}
}
}
function encrypt($f){
if(empty($f) || !is_file($f)) return false;
$str = php_strip_whitespace($f);
if(strrpos($f, '.source')!==false){
$f = str_replace('.source', '', $f);
}
file_put_contents($f, $str);
return true;
}
function getFiles($dir,$key){
if(!is_dir($dir) || empty($key)) return null;
$files = array();
if($dh = opendir($dir)){
while(($file = readdir($dh))!==false){
$path = $dir.'/'.$file;
if( filetype($path) == dir && $file !='.' && $file!='..' && (strpos($path, 'module')!==false || strpos($path, 'ework')!==false || strpos($path, 'framwork')!==false || strpos($path, 'company')!==false || strpos($path, 'devel')!==false )){
if(strpos($path, 'ework')!==false){
if(preg_match('/\/ework(\/templates)?$/', $path)){
$oFiles = $this->getFiles($path,$key);
}else
continue;
}
if(strpos($path, 'module')!==false){
if(preg_match('/\/module(\/[a-z]+)?(\/templates)?(\/public)?$/', $path)){
$oFiles = $this->getFiles($path,$key);
}else
continue;
}
if(strpos($path, 'framwork')!==false){
if(preg_match('/\/framwork(\/libraries)?(\/plugins)?$/', $path)){
$oFiles = $this->getFiles($path,$key);
}else
continue;
}
if(strpos($path, 'company')!==false){
if(preg_match('/\/company(\/core)?(\/index)?$/', $path)){
$oFiles = $this->getFiles($path,$key);
}else
continue;
}
if(strpos($path, 'devel')!==false){
if(preg_match('/\/devel$/', $path)){
$oFiles = $this->getFiles($path,$key);
}else
continue;
}
if(!empty($oFiles)){
$files = array_merge($files,$oFiles);unset($oFiles);
}
}elseif(!in_array($file,array('.','..')) && in_array($this->fileSuffix($file), array('php','htm'))){
if(strrpos(strtolower($path), strtolower($key))!==false)
$files[] = $path;
}
}
closedir($dh);
}
return $files;
}
function fileSuffix($filename){
return strtolower(trim(substr(strrchr($filename, '.'), 1)));
}
function compress_html($compress) {
$i = array('/>[^S ]+/s','/[^S ]+</s','/(s)+/s');
$ii = array('>','<','1');
return preg_replace($i, $ii, $compress);
}
}
$mf = new MyFiles();
?>
<html>
<head>
<meta charset="UTF-8">
<title>文件操作</title>
<link rel="stylesheet" type="text/css" href="/public/default/css/global_import_new.css">
<script type="text/javascript" src="public/system/js/jquery-1.7.2.min.js"></script>
<style type="text/css">
#files ul {padding: 10px;border: 1px solid #d73c90;font-size: 16px;float: left;}
#files ul li {margin: 5px;color:#33bdef;}
</style>
</head>
<body>
文件:<input type="text" name="file" id="file" placeholder="请输入准确的文件路径"/>
<form action="/a.php?f=format" method="post">
<div id="files"></div>
</form>
<script>
$(function(){
$('form').submit(function(event) {
if(!$("input[name='files[]']:checked").val()){
alert('请选择!');return false;
}
});
});
$("#file").blur(function(event) {
var val = $(this).val();
if(val){
$.get('/a.php?key='+val,function(data){
if(data){
data = eval('('+data+')');
var html = '<ul><li><input type="submit" value="提交"></li>';
$.each(data, function(index, val) {
html += '<li><input type="checkbox" value="'+val+'" id="files_'+index+'" name="files[]"/><label for="files_'+index+'">'+val+'</label></li>';
});
html += '</ul>';
$("#files").html(html);
}
});
}
});
</script>
</body>
</html>