-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathself.php
66 lines (61 loc) · 1.87 KB
/
self.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
<?php
/*
*
* Self-editable HTML file using CKeditor
*
*/
if (isset($_POST['content'])) {
/* Handling POST of new content */
$filename = __FILE__;
$match_comment = "CONTENT";
$new_content = $_POST['content'];
// Cleaning new content from wrong newline and matching tag
$new_content = preg_replace("/<!--$match_comment-->/", "", $new_content);
$new_content = preg_replace("/\\r\\n/", "\n", $new_content);
// Read current file and update the content
$full_content = file_get_contents($filename);
$full_content = preg_replace(
"/<!--$match_comment-->(.*?)<!--$match_comment-->/s",
"<!--$match_comment-->$new_content<!--$match_comment-->",
$full_content);
/*
// For debug
print "<pre>$new_content</pre>";
print "<pre>$full_content</pre>";
exit(0);
*/
// Write to current file and redirect user
file_put_contents($filename, $full_content);
$script = basename(__FILE__, '.php');
header("Location: $script");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Support homepage</title>
<script src="//cdn.ckeditor.com/4.5.1/full/ckeditor.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
<?php if ( isset($_GET['edit']) ) { ?>
<form method="post">
<textarea name="content" id="content" rows="10" cols="80">
<!--CONTENT-->
<h1>Support homepage</h1>
<!--CONTENT-->
</textarea>
<script>
CKEDITOR.replace('content');
</script>
<button type="submit">Ok</button>
</form>
</body>
<?php } else { ?>
<form method="get"><input type="hidden" value="1" name=edit><button type="submit">Edit</button></form>
<!--CONTENT-->
<h1>MFI Support homepage</h1>
<!--CONTENT-->
<?php } ?>
</html>