This commit has been accessed 587 times via Git panel.
commit 1e1fc96dc01690f1251519ed7d74c2767e7d6d95
tree a9477f13ccfd0fdf98ca512f73b865970270051b
parent a0577241d7eb702022d0d8bbee6a2b937bc92a91
author Engels Antonio <engels@majcms.org> 1277314193 +0800
committer Engels Antonio <engels@majcms.org> 1277314193 +0800
maj-0.14-20071219-bb.zip
diff --git a/edit.php b/edit.php
index b75e7c5..ded4662 100644
--- a/edit.php
+++ b/edit.php
@@ -45,7 +45,7 @@ if ($_SESSION['logged_in'] == $login_username) {
}
-if (file_exists("data/members/active/{$_SESSION['logged_in']}/rw.txt") and file_exists("data/wiki.txt") and file_exists("data/items/{$_REQUEST['entry']}/edit.txt")) {
+if (file_exists("data/members/active/{$_SESSION['logged_in']}/rw.txt") and file_exists("data/wiki.txt") and (file_exists("data/items/{$_REQUEST['entry']}/edit.txt") or (file_get_contents("data/items/{$_REQUEST['entry']}/author.txt") == $_SESSION['logged_in']))) {
$do = 1;
}
@@ -848,7 +848,12 @@ if (file_exists("data/wiki.txt") and (($title_get_content != file_get_contents("
mkdir("data/items/{$_REQUEST['entry']}/wiki/delta/$ddate");
}
- copy("data/items/{$_REQUEST['entry']}/body.txt","data/items/{$_REQUEST['entry']}/wiki/delta/$ddate/body.txt");
+
+ $new = fopen("data/items/{$_REQUEST['entry']}/wiki/delta/$ddate/body.txt","w");
+ fwrite($new,$body_write_content);
+ fclose($new);
+
+ copy("data/items/{$_REQUEST['entry']}/body.txt","data/items/{$_REQUEST['entry']}/wiki/delta/$ddate/prev.txt");
copy("data/items/{$_REQUEST['entry']}/date.txt","data/items/{$_REQUEST['entry']}/wiki/delta/$ddate/date.txt");
copy("data/items/{$_REQUEST['entry']}/title.txt","data/items/{$_REQUEST['entry']}/wiki/delta/$ddate/title.txt");
@@ -870,7 +875,7 @@ fclose($open_body_file);
// start of wiki mod (20071130)
-if (file_exists("data/wiki.txt") and file_exists("data/items/{$_REQUEST['entry']}/edit.txt")) {
+if (file_exists("data/wiki.txt") and (file_exists("data/items/{$_REQUEST['entry']}/edit.txt") or (file_get_contents("data/items/{$_REQUEST['entry']}/author.txt") == $_SESSION['logged_in']))) {
$open_contrib_file = fopen("data/items/{$_REQUEST['entry']}/contrib.txt","w");
fwrite($open_contrib_file,$_SESSION['logged_in']);
fclose($open_contrib_file);
diff --git a/index.php b/index.php
index 8d3154b..27798e8 100644
--- a/index.php
+++ b/index.php
@@ -1797,7 +1797,7 @@ foreach ($disp as $d) {
// start of wiki mod (20071130)
- if (isset($_SESSION['logged_in']) and ($_SESSION['logged_in'] != $login_username) and file_exists("data/members/active/{$_SESSION['logged_in']}") and file_exists("data/wiki.txt") and file_exists("$dir/$d/edit.txt") and file_exists("data/members/active/{$_SESSION['logged_in']}/rw.txt") and !file_exists("$dir/$d/passwd.txt")) {
+ if (isset($_SESSION['logged_in']) and ($_SESSION['logged_in'] != $login_username) and file_exists("data/members/active/{$_SESSION['logged_in']}") and file_exists("data/wiki.txt") and (file_exists("$dir/$d/edit.txt") or (file_get_contents("$dir/$d/author.txt") == $_SESSION['logged_in'])) and file_exists("data/members/active/{$_SESSION['logged_in']}/rw.txt") and !file_exists("$dir/$d/passwd.txt")) {
if (file_exists("$dir/$d/wiki/delta") and (count(glob("$dir/$d/wiki/delta/*")) > 0)) {
echo "<a href=wiki.php?entry=$d>";
diff --git a/wiki.php b/wiki.php
index 8b41e7c..247a752 100644
--- a/wiki.php
+++ b/wiki.php
@@ -41,7 +41,7 @@ if ($_SESSION['logged_in'] == $login_username) {
}
-if (file_exists("data/members/active/{$_SESSION['logged_in']}/rw.txt") and file_exists("data/wiki.txt") and file_exists("data/items/{$_REQUEST['entry']}/edit.txt")) {
+if (file_exists("data/members/active/{$_SESSION['logged_in']}/rw.txt") and file_exists("data/wiki.txt") and (file_exists("data/items/{$_REQUEST['entry']}/edit.txt") or (file_get_contents("data/items/{$_REQUEST['entry']}/author.txt") == $_SESSION['logged_in']))) {
$do = 1;
}
@@ -73,6 +73,49 @@ function rmdirr($recurse_dirname) {
return rmdir($recurse_dirname);
}
+/*
+
+start of diff mod (20071219)
+
+Simple Diff Algorithm v 0.1
+(C) Paul Butler 2007 <http://www.paulbutler.org/>
+
+*/
+
+
+function diff($old, $new){
+ foreach($old as $oindex => $ovalue){
+ $nkeys = array_keys($new, $ovalue);
+ foreach($nkeys as $nindex){
+ $matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ?
+ $matrix[$oindex - 1][$nindex - 1] + 1 : 1;
+ if($matrix[$oindex][$nindex] > $maxlen){
+ $maxlen = $matrix[$oindex][$nindex];
+ $omax = $oindex + 1 - $maxlen;
+ $nmax = $nindex + 1 - $maxlen;
+ }
+ }
+ }
+ if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new));
+ return array_merge(
+ diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)),
+ array_slice($new, $nmax, $maxlen),
+ diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)));
+}
+
+function htmlDiff($old, $new){
+ $diff = diff(explode(' ', $old), explode(' ', $new));
+ foreach($diff as $k){
+ if(is_array($k))
+ $ret .= (!empty($k['d'])?"<del>".implode(' ',$k['d'])."</del> ":'').
+ (!empty($k['i'])?"<ins>".implode(' ',$k['i'])."</ins> ":'');
+ else $ret .= $k . ' ';
+ }
+ return $ret;
+}
+
+// end of diff mod (20071219)
+
?>
<style>
@@ -209,7 +252,7 @@ if (file_exists("data/items/$entry/wiki/delta")) {
}
closedir($dh_delta);
}
- sort($show_delta);
+ rsort($show_delta);
reset($show_delta);
$count_delta = count($show_delta);
@@ -232,9 +275,12 @@ if (file_exists("data/items/$entry/wiki/delta")) {
$mod = date("l, M j, g:i A", mktime($itemHour,$itemMinute,$itemSecond,$itemMonth,$itemDay,$itemYear));
+ $prev = file_get_contents("data/items/$entry/wiki/delta/$item/prev.txt");
+ $diff = htmlDiff($prev,$body);
+
echo "<p><table border=0 cellspacing=0 cellpadding=0 bgcolor=#CCCCCC><tr><td width=525>";
echo "<div id=panel_title>$title</div>";
- echo "<div id=panel_body><font style=\"font-size: 10px; color: #999999;\">$author - $date<br><br></font>$body</div>";
+ echo "<div id=panel_body><font style=\"font-size: 10px; color: #999999;\">$author - $date<br><br></font>$diff</div>";
echo "<div id=panel_footer>Edited by $editor last $mod</div>";
echo "</td></tr></table></p>";
}
tree a9477f13ccfd0fdf98ca512f73b865970270051b
parent a0577241d7eb702022d0d8bbee6a2b937bc92a91
author Engels Antonio <engels@majcms.org> 1277314193 +0800
committer Engels Antonio <engels@majcms.org> 1277314193 +0800
maj-0.14-20071219-bb.zip
diff --git a/edit.php b/edit.php
index b75e7c5..ded4662 100644
--- a/edit.php
+++ b/edit.php
@@ -45,7 +45,7 @@ if ($_SESSION['logged_in'] == $login_username) {
}
-if (file_exists("data/members/active/{$_SESSION['logged_in']}/rw.txt") and file_exists("data/wiki.txt") and file_exists("data/items/{$_REQUEST['entry']}/edit.txt")) {
+if (file_exists("data/members/active/{$_SESSION['logged_in']}/rw.txt") and file_exists("data/wiki.txt") and (file_exists("data/items/{$_REQUEST['entry']}/edit.txt") or (file_get_contents("data/items/{$_REQUEST['entry']}/author.txt") == $_SESSION['logged_in']))) {
$do = 1;
}
@@ -848,7 +848,12 @@ if (file_exists("data/wiki.txt") and (($title_get_content != file_get_contents("
mkdir("data/items/{$_REQUEST['entry']}/wiki/delta/$ddate");
}
- copy("data/items/{$_REQUEST['entry']}/body.txt","data/items/{$_REQUEST['entry']}/wiki/delta/$ddate/body.txt");
+
+ $new = fopen("data/items/{$_REQUEST['entry']}/wiki/delta/$ddate/body.txt","w");
+ fwrite($new,$body_write_content);
+ fclose($new);
+
+ copy("data/items/{$_REQUEST['entry']}/body.txt","data/items/{$_REQUEST['entry']}/wiki/delta/$ddate/prev.txt");
copy("data/items/{$_REQUEST['entry']}/date.txt","data/items/{$_REQUEST['entry']}/wiki/delta/$ddate/date.txt");
copy("data/items/{$_REQUEST['entry']}/title.txt","data/items/{$_REQUEST['entry']}/wiki/delta/$ddate/title.txt");
@@ -870,7 +875,7 @@ fclose($open_body_file);
// start of wiki mod (20071130)
-if (file_exists("data/wiki.txt") and file_exists("data/items/{$_REQUEST['entry']}/edit.txt")) {
+if (file_exists("data/wiki.txt") and (file_exists("data/items/{$_REQUEST['entry']}/edit.txt") or (file_get_contents("data/items/{$_REQUEST['entry']}/author.txt") == $_SESSION['logged_in']))) {
$open_contrib_file = fopen("data/items/{$_REQUEST['entry']}/contrib.txt","w");
fwrite($open_contrib_file,$_SESSION['logged_in']);
fclose($open_contrib_file);
diff --git a/index.php b/index.php
index 8d3154b..27798e8 100644
--- a/index.php
+++ b/index.php
@@ -1797,7 +1797,7 @@ foreach ($disp as $d) {
// start of wiki mod (20071130)
- if (isset($_SESSION['logged_in']) and ($_SESSION['logged_in'] != $login_username) and file_exists("data/members/active/{$_SESSION['logged_in']}") and file_exists("data/wiki.txt") and file_exists("$dir/$d/edit.txt") and file_exists("data/members/active/{$_SESSION['logged_in']}/rw.txt") and !file_exists("$dir/$d/passwd.txt")) {
+ if (isset($_SESSION['logged_in']) and ($_SESSION['logged_in'] != $login_username) and file_exists("data/members/active/{$_SESSION['logged_in']}") and file_exists("data/wiki.txt") and (file_exists("$dir/$d/edit.txt") or (file_get_contents("$dir/$d/author.txt") == $_SESSION['logged_in'])) and file_exists("data/members/active/{$_SESSION['logged_in']}/rw.txt") and !file_exists("$dir/$d/passwd.txt")) {
if (file_exists("$dir/$d/wiki/delta") and (count(glob("$dir/$d/wiki/delta/*")) > 0)) {
echo "<a href=wiki.php?entry=$d>";
diff --git a/wiki.php b/wiki.php
index 8b41e7c..247a752 100644
--- a/wiki.php
+++ b/wiki.php
@@ -41,7 +41,7 @@ if ($_SESSION['logged_in'] == $login_username) {
}
-if (file_exists("data/members/active/{$_SESSION['logged_in']}/rw.txt") and file_exists("data/wiki.txt") and file_exists("data/items/{$_REQUEST['entry']}/edit.txt")) {
+if (file_exists("data/members/active/{$_SESSION['logged_in']}/rw.txt") and file_exists("data/wiki.txt") and (file_exists("data/items/{$_REQUEST['entry']}/edit.txt") or (file_get_contents("data/items/{$_REQUEST['entry']}/author.txt") == $_SESSION['logged_in']))) {
$do = 1;
}
@@ -73,6 +73,49 @@ function rmdirr($recurse_dirname) {
return rmdir($recurse_dirname);
}
+/*
+
+start of diff mod (20071219)
+
+Simple Diff Algorithm v 0.1
+(C) Paul Butler 2007 <http://www.paulbutler.org/>
+
+*/
+
+
+function diff($old, $new){
+ foreach($old as $oindex => $ovalue){
+ $nkeys = array_keys($new, $ovalue);
+ foreach($nkeys as $nindex){
+ $matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ?
+ $matrix[$oindex - 1][$nindex - 1] + 1 : 1;
+ if($matrix[$oindex][$nindex] > $maxlen){
+ $maxlen = $matrix[$oindex][$nindex];
+ $omax = $oindex + 1 - $maxlen;
+ $nmax = $nindex + 1 - $maxlen;
+ }
+ }
+ }
+ if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new));
+ return array_merge(
+ diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)),
+ array_slice($new, $nmax, $maxlen),
+ diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)));
+}
+
+function htmlDiff($old, $new){
+ $diff = diff(explode(' ', $old), explode(' ', $new));
+ foreach($diff as $k){
+ if(is_array($k))
+ $ret .= (!empty($k['d'])?"<del>".implode(' ',$k['d'])."</del> ":'').
+ (!empty($k['i'])?"<ins>".implode(' ',$k['i'])."</ins> ":'');
+ else $ret .= $k . ' ';
+ }
+ return $ret;
+}
+
+// end of diff mod (20071219)
+
?>
<style>
@@ -209,7 +252,7 @@ if (file_exists("data/items/$entry/wiki/delta")) {
}
closedir($dh_delta);
}
- sort($show_delta);
+ rsort($show_delta);
reset($show_delta);
$count_delta = count($show_delta);
@@ -232,9 +275,12 @@ if (file_exists("data/items/$entry/wiki/delta")) {
$mod = date("l, M j, g:i A", mktime($itemHour,$itemMinute,$itemSecond,$itemMonth,$itemDay,$itemYear));
+ $prev = file_get_contents("data/items/$entry/wiki/delta/$item/prev.txt");
+ $diff = htmlDiff($prev,$body);
+
echo "<p><table border=0 cellspacing=0 cellpadding=0 bgcolor=#CCCCCC><tr><td width=525>";
echo "<div id=panel_title>$title</div>";
- echo "<div id=panel_body><font style=\"font-size: 10px; color: #999999;\">$author - $date<br><br></font>$body</div>";
+ echo "<div id=panel_body><font style=\"font-size: 10px; color: #999999;\">$author - $date<br><br></font>$diff</div>";
echo "<div id=panel_footer>Edited by $editor last $mod</div>";
echo "</td></tr></table></p>";
}