-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_line.php
189 lines (157 loc) · 10.1 KB
/
edit_line.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
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
<?php define('ACCESS', true);
include_once 'function.php';
if (IS_LOGIN) {
$title = 'Sửa dòng';
$page = array('current' => 0, 'paramater_0' => null, 'paramater_1' => null);
$page['current'] = isset($_GET['page']) ? intval($_GET['page']) : 1;
$page['current'] = $page['current'] <= 0 ? 1 : $page['current'];
include_once 'header.php';
echo '<div class="title">' . $title . '</div>';
if ($dir == null || $name == null || !is_file(processDirectory($dir . '/' . $name))) {
echo '<div class="list"><span>Đường dẫn không tồn tại</span></div>
<div class="title">Chức năng</div>
<ul class="list">
<li><img src="icon/list.png"/> <a href="index.php' . $pages['paramater_0'] . '">Danh sách</a></li>
</ul>';
} else if (!isFormatText($name) && !isFormatUnknown($name)) {
echo '<div class="list"><span>Tập tin này không phải dạng văn bản</span></div>
<div class="title">Chức năng</div>
<ul class="list">
<li><img src="icon/list.png"/> <a href="index.php?dir=' . $dirEncode . $pages['paramater_1'] . '">Danh sách</a></li>
</ul>';
} else {
function process()
{
global $content, $lines, $count, $path;
$content = file_get_contents($path);
if (strlen($content) > 0) {
$content = str_replace("\r\n", "\n", $content);
$content = str_replace("\r", "\n", $content);
if (strpos($content, "\n") !== false)
$lines = explode("\n", $content);
else
$lines[] = $content;
} else {
$lines[] = $content;
}
$count = count($lines);
}
$path = $dir . '/' . $name;
$line = isset($_GET['line']) ? intval($_GET['line']) : 0;
$lines = array();
$content = null;
$notice = null;
$count = 0;
if ($page['current'] > 1) {
$page['paramater_0'] = '?page=' . $page['current'];
$page['paramater_1'] = '&page=' . $page['current'];
}
process();
if (isset($_POST['continue']) || isset($_POST['save'])) {
$data = null;
$con = stripslashes($_POST['content']);
if ($con != null && !empty($con)) {
$con = str_replace("\r\n", "\n", $con);
$con = str_replace("\r", "\n", $con);
}
if ($count > 1) {
if ($line > 0) {
for ($i = 0; $i < $line; ++$i)
$data .= $lines[$i] . "\n";
}
$data .= $con;
if ($line < $count - 1) {
for ($i = ($line + 1); $i < $count; ++$i)
$data .= "\n" . $lines[$i];
}
} else {
$data = $con;
}
if (file_put_contents($path, $data)) {
$notice = '<div class="notice_succeed">Lưu lại thành công</div>';
if (isset($_POST['save']))
goURL('edit_text_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . $page['paramater_1'] . '#line_number_' . $line);
} else {
$notice = '<div class="notice_failure">Lưu lại thất bại</div>';
}
process();
}
$isGO = false;
if (isset($_POST['go']) && !empty($_POST['line']) && preg_match('#\\b[0-9]+\\b#', $_POST['line'])) {
$li = intval($_POST['line']);
if ($li >= 0 && $li <= $count - 1) {
$line = $li;
$isGO = true;
}
}
if ($line < 0)
goURL('edit_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=0' . $page['paramater_1']);
if ($line > $count - 1)
goURL('edit_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . ($count - 1) . $page['paramater_1']);
$page['current'] = $line + 1 > $configs['page_file_edit_line'] ? ceil(($line + 1) / $configs['page_file_edit_line']) : 1;
if ($page['current'] > 1) {
$page['paramater_0'] = '?page=' . $page['current'];
$page['paramater_1'] = '&page=' . $page['current'];
}
if ($isGO)
goURL('edit_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . $line . $page['paramater_1']);
$url = array('action' => null, 'prev' => null, 'next' => null);
$url['action'] = 'edit_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . $line . $page['paramater_1'] . '#line_label';
$url['prev'] = $line > 0 ? '<a href="edit_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . ($line - 1) . ($configs['page_file_edit_line'] > 0 && $line <= $configs['page_file_edit_line'] ? null : '&page=' . ceil($line / $configs['page_file_edit_line'])) . '#line_label"><img src="icon/arrow_left.png"/></a>' : '<img src="icon/arrow_left.png"/>';
$url['next'] = $line < $count - 1 ? '<a href="edit_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . ($line + 1) . ($configs['page_file_edit_line'] > 0 && $line <= $configs['page_file_edit_line'] ? null : '&page=' . ceil(($line + 2) / $configs['page_file_edit_line'])) . '#line_label"><img src="icon/arrow_right.png"/></a>' : '<img src="icon/arrow_right.png"/>';
echo $notice;
echo '<div class="list">
<span class="bull">•</span><span>' . printPath($dir, true) . '</span><hr/>
<div class="ellipsis break-word">
<span class="bull">•</span>Tập tin: <strong class="file_name_edit">' . $name . '</strong>
</div><hr/>
<form action="edit_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . $line . $page['paramater_1'] . '#line_label" method="post">
<span class="bull" id="line_label">•</span>Dòng [<strong class="line_number_form">' . $line . '</strong>/<strong class="line_number_form">' . ($count - 1) . '</strong>]:<br/>
<div class="parent_box_edit">
<textarea class="box_edit_normal" name="content" rows="10">' . htmlspecialchars($lines[$line]) . '</textarea>
</div>
<div style="margin-left: -4px">
<input type="submit" name="continue" value="Tiếp tục"/>
<input type="submit" name="save" value="Lưu"/>
<a href="delete_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . $line . $page['paramater_1'] . '" id="href_line_edit">Xóa</a>
</div>
</form><hr/>
<form action="' . $url['action'] . '" method="post">
<table id="action_page">
<tr>
<td id="prev">' . $url['prev'] . '</td>
<td id="input">
<input type="text" name="line" value="' . $line . '"/>
</td>
<td id="submit">
<input type="submit" name="go" value="Đến"/>
</td>
<td id="next">' . $url['next'] . '</td>
</tr>
</table>
</form>
</div>
<div class="tips">
<img src="icon/tips.png"/>
<span>Ấn tiếp tục để lưu lại ở lại trang và ấn lưu để lưu lại và quay về danh sách dòng</span>
</div>
<div class="title">Chức năng</div>
<ul class="list">
<li><img src="icon/delete.png"/> <a href="delete_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '&line=' . $line . $page['paramater_1'] . '">Xóa dòng</a></li>
<li><img src="icon/edit_text_line.png"/> <a href="edit_text_line.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . $page['paramater_1'] . '#line_number_' . $line . '">Sửa theo dòng</a></li>
<li><img src="icon/edit.png"/> <a href="edit_text.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Sửa văn bản</a></li>
<li><img src="icon/download.png"/> <a href="file_download.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Tải về</a></li>
<li><img src="icon/info.png"/> <a href="file.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Thông tin</a></li>
<li><img src="icon/rename.png"/> <a href="file_rename.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Đổi tên</a></li>
<li><img src="icon/copy.png"/> <a href="file_copy.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Sao chép</a></li>
<li><img src="icon/move.png"/> <a href="file_move.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Di chuyển</a></li>
<li><img src="icon/delete.png"/> <a href="file_delete.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Xóa</a></li>
<li><img src="icon/access.png"/> <a href="file_chmod.php?dir=' . $dirEncode . '&name=' . $name . $pages['paramater_1'] . '">Chmod</a></li>
<li><img src="icon/list.png"/> <a href="index.php?dir=' . $dirEncode . $pages['paramater_1'] . '">Danh sách</a></li>
</ul>';
}
} else {
goURL('login.php');
}
include_once 'footer.php';
?>