-
Notifications
You must be signed in to change notification settings - Fork 0
/
doEdit.php
executable file
·94 lines (84 loc) · 2.38 KB
/
doEdit.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
<?php
require('lib/misc.inc.php');
require('lib/classes.class.php');
if(!isset($_SESSION['uid'])) {
die('Sorry, you need to be logged in to edit pages');
}
if($_POST['address'] == '' || $_POST['source'] == '') {
die('Sorry, there was an error recieving all the fields');
}
$s = new Site($_POST['address']);
if(!$s->loaded) {
$s->checkWWW();
}
if($s->lock) {
print "Sorry, this page is locked";
die();
}
if(!$s->loaded) {
$s->save();
}
$ip = $_SERVER['REMOTE_ADDR'];
$rating = 0;
$comment = htmlentities($_POST['comment']);
$source = str_replace("\r", '', WikiWideWebize($s, getSource($_POST['address'])));
$source = str_replace(" />", ">", $source);
$nsource = str_replace("\r", '', stripslashes($_POST['source']));
$nsource = str_replace(" />", ">", $nsource);
$nsource = preg_replace("/<\/?([A-Z]+)[^>]*>/Ue", "strtolower('$1')", $nsource);
$source = preg_replace("/<\/?([A-Z]+)[^>]*>/Ue", "strtolower('$1')", $source);
$source2 = explode("\n", $source);
$source = explode("\n", entityScrub($source));
$nsource = explode("\n", $nsource);
$diff = array_diff($nsource, $source);
$diff2 = array_diff($source, $nsource);
if(current($diff2)) {
$temp = new Diff();
$temp->uid = $_SESSION['uid'];
$temp->sid = $s->sid;
$temp->comment = $comment;
$temp->toreplace = $source2[key($diff2)];
$temp->replacewith = $nsource[key($diff2)];
$temp->ip = $ip;
$temp->rating = $rating;
$temp->commitChanges();
}
while(next($diff2)) {
$temp = new Diff();
$temp->sid = $s->sid;
$temp->comment = $comment;
$temp->uid = $_SESSION['uid'];
$temp->toreplace = $source2[key($diff2)];
$temp->replacewith = $nsource[key($diff2)];
$temp->ip = $ip;
$temp->rating = $rating;
$temp->commitChanges();
}
$diff = array_diff_key($diff, $diff2);
if (current($diff)) {
$temp = new Diff();
$temp->uid = $_SESSION['uid'];
$temp->sid = $s->sid;
$temp->comment = $comment;
$temp->toreplace = $source2[key($diff) - 1];
$temp->ip = $ip;
$temp->rating = $rating;
$temp->replacewith = $source2[key($diff) - 1]."\n".$nsource[key($diff)];
$temp->commitChanges();
}
while(next($diff)) {
$temp = new Diff();
$temp->sid = $s->sid;
$temp->comment = $comment;
$temp->uid = $_SESSION['uid'];
$temp->toreplace = $source2[key($diff) - 1];
$temp->ip = $ip;
$temp->rating = $rating;
$temp->replacewith = $source2[key($diff) - 1]."\n".$nsource[key($diff)];
$temp->commitChanges();
}
?>
<html>
<body onload="window.close();">
</body>
</html>