This commit has been accessed 568 times via Git panel.
commit 7ed2998e3552daf3bec9b8a95fc4300ffb23c933
tree 8279296a1367d3966d3eff768d50d923a1d6a180
parent 3110a34b8a4715bc82b6a9a073efd6e7eaa1ddde
author Engels Antonio <engels@majcms.org> 1277314195 +0800
committer Engels Antonio <engels@majcms.org> 1277314195 +0800
maj-0.14-20080223-bb.zip
diff --git a/add.php b/add.php
index 6ee193b..98d9acf 100644
--- a/add.php
+++ b/add.php
@@ -651,7 +651,7 @@ if (isset($_FILES['image_input']) and !empty($_FILES['image_input'])) {
$entry_image_height = (int) ($entry_image_height * $sizefactor);
}
- $body_write_content = '<img src=' . $image_dir . '/' . $_FILES['image_input']['name'] . ' border=0 width=' . $entry_image_width . ' height=' . $entry_image_height . '><br>' . $body_write_content;
+ $body_write_content = '<img src="' . $image_dir . '/' . $_FILES['image_input']['name'] . '" border="0" width="' . $entry_image_width . '" height="' . $entry_image_height . '"><br>' . $body_write_content;
}
}
diff --git a/edit.php b/edit.php
index b6e300f..10c522c 100644
--- a/edit.php
+++ b/edit.php
@@ -766,7 +766,7 @@ if (isset($_FILES['entry_image_input']) and !empty($_FILES['entry_image_input'])
$entry_image_height = (int) ($entry_image_height * $sizefactor);
}
- $body_write_content = '<img src=' . $image_path . $_REQUEST['entry'] . '/' . $_FILES['entry_image_input']['name'] . ' border=0 width=' . $entry_image_width . ' height=' . $entry_image_height . '><br>' . $body_write_content;
+ $body_write_content = '<img src="' . $image_path . $_REQUEST['entry'] . '/' . $_FILES['entry_image_input']['name'] . '" border="0" width="' . $entry_image_width . '" height="' . $entry_image_height . '"><br>' . $body_write_content;
}
else {
diff --git a/wiki.php b/wiki.php
index 247a752..283aea5 100644
--- a/wiki.php
+++ b/wiki.php
@@ -1,5 +1,7 @@
<?php
+
session_start();
+
header("Cache-control: private");
error_reporting(E_ERROR);
@@ -73,49 +75,6 @@ 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>
@@ -234,6 +193,15 @@ a:active {
border-width: 0px 1px 1px 1px;
border-style: none solid solid solid;
}
+
+ins {
+ background-color: #ccffcc;
+}
+
+del {
+ background-color: #ffbbbb;
+}
+
</style>
<?php
@@ -276,13 +244,59 @@ 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);
+
+ $prev = str_replace("<br />","<br>",$prev);
+ $prev = str_replace("\n"," ",$prev);
+ $prev = str_replace("\r"," ",$prev);
+ $prev = preg_replace("/<img[^>]+src[\s='\"]+([^\"'>\s]+)[^>]*>/is","[\\1]",$prev);
+ $prev = htmlentities($prev,ENT_QUOTES);
+
+ $body = str_replace("<br />","<br>",$body);
+ $body = str_replace("\n"," ",$body);
+ $body = str_replace("\r"," ",$body);
+ $body = preg_replace("/<img[^>]+src[\s='\"]+([^\"'>\s]+)[^>]*>/is","[\\1]",$body);
+ $body = htmlentities($body,ENT_QUOTES);
+
+ $prev_array = explode(" ",$prev);
+ $body_array = explode(" ",$body);
+
+ if (count($prev_array) <= count($body_array)) {
+ $elements = count($body_array);
+ }
+ else {
+ $elements = count($prev_array);
+ }
+
+ $count = "0";
+
+ $elements = $elements - 1;
+
+ $diff = "";
+
+ while ($count <= $elements) {
+
+ if ($prev_array[$count] == $body_array[$count]) {
+ $diff .= $prev_array[$count] . " ";
+ }
+ else {
+ $diff .= "<del>" . $prev_array[$count] . "</del> <ins>" . $body_array[$count] . " </ins> ";
+ }
+
+ $count = $count + 1;
+ }
+
+ $diff = str_replace("<br>","<br>",$diff);
+ $diff = trim($diff);
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>$diff</div>";
echo "<div id=panel_footer>Edited by $editor last $mod</div>";
echo "</td></tr></table></p>";
+
+ unset($diff);
+ unset($body);
+ unset($prev);
}
}
}
tree 8279296a1367d3966d3eff768d50d923a1d6a180
parent 3110a34b8a4715bc82b6a9a073efd6e7eaa1ddde
author Engels Antonio <engels@majcms.org> 1277314195 +0800
committer Engels Antonio <engels@majcms.org> 1277314195 +0800
maj-0.14-20080223-bb.zip
diff --git a/add.php b/add.php
index 6ee193b..98d9acf 100644
--- a/add.php
+++ b/add.php
@@ -651,7 +651,7 @@ if (isset($_FILES['image_input']) and !empty($_FILES['image_input'])) {
$entry_image_height = (int) ($entry_image_height * $sizefactor);
}
- $body_write_content = '<img src=' . $image_dir . '/' . $_FILES['image_input']['name'] . ' border=0 width=' . $entry_image_width . ' height=' . $entry_image_height . '><br>' . $body_write_content;
+ $body_write_content = '<img src="' . $image_dir . '/' . $_FILES['image_input']['name'] . '" border="0" width="' . $entry_image_width . '" height="' . $entry_image_height . '"><br>' . $body_write_content;
}
}
diff --git a/edit.php b/edit.php
index b6e300f..10c522c 100644
--- a/edit.php
+++ b/edit.php
@@ -766,7 +766,7 @@ if (isset($_FILES['entry_image_input']) and !empty($_FILES['entry_image_input'])
$entry_image_height = (int) ($entry_image_height * $sizefactor);
}
- $body_write_content = '<img src=' . $image_path . $_REQUEST['entry'] . '/' . $_FILES['entry_image_input']['name'] . ' border=0 width=' . $entry_image_width . ' height=' . $entry_image_height . '><br>' . $body_write_content;
+ $body_write_content = '<img src="' . $image_path . $_REQUEST['entry'] . '/' . $_FILES['entry_image_input']['name'] . '" border="0" width="' . $entry_image_width . '" height="' . $entry_image_height . '"><br>' . $body_write_content;
}
else {
diff --git a/wiki.php b/wiki.php
index 247a752..283aea5 100644
--- a/wiki.php
+++ b/wiki.php
@@ -1,5 +1,7 @@
<?php
+
session_start();
+
header("Cache-control: private");
error_reporting(E_ERROR);
@@ -73,49 +75,6 @@ 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>
@@ -234,6 +193,15 @@ a:active {
border-width: 0px 1px 1px 1px;
border-style: none solid solid solid;
}
+
+ins {
+ background-color: #ccffcc;
+}
+
+del {
+ background-color: #ffbbbb;
+}
+
</style>
<?php
@@ -276,13 +244,59 @@ 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);
+
+ $prev = str_replace("<br />","<br>",$prev);
+ $prev = str_replace("\n"," ",$prev);
+ $prev = str_replace("\r"," ",$prev);
+ $prev = preg_replace("/<img[^>]+src[\s='\"]+([^\"'>\s]+)[^>]*>/is","[\\1]",$prev);
+ $prev = htmlentities($prev,ENT_QUOTES);
+
+ $body = str_replace("<br />","<br>",$body);
+ $body = str_replace("\n"," ",$body);
+ $body = str_replace("\r"," ",$body);
+ $body = preg_replace("/<img[^>]+src[\s='\"]+([^\"'>\s]+)[^>]*>/is","[\\1]",$body);
+ $body = htmlentities($body,ENT_QUOTES);
+
+ $prev_array = explode(" ",$prev);
+ $body_array = explode(" ",$body);
+
+ if (count($prev_array) <= count($body_array)) {
+ $elements = count($body_array);
+ }
+ else {
+ $elements = count($prev_array);
+ }
+
+ $count = "0";
+
+ $elements = $elements - 1;
+
+ $diff = "";
+
+ while ($count <= $elements) {
+
+ if ($prev_array[$count] == $body_array[$count]) {
+ $diff .= $prev_array[$count] . " ";
+ }
+ else {
+ $diff .= "<del>" . $prev_array[$count] . "</del> <ins>" . $body_array[$count] . " </ins> ";
+ }
+
+ $count = $count + 1;
+ }
+
+ $diff = str_replace("<br>","<br>",$diff);
+ $diff = trim($diff);
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>$diff</div>";
echo "<div id=panel_footer>Edited by $editor last $mod</div>";
echo "</td></tr></table></p>";
+
+ unset($diff);
+ unset($body);
+ unset($prev);
}
}
}