* remove diff method.
This commit is contained in:
@@ -423,80 +423,6 @@ class doc extends control
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Diff doc.
|
||||
*
|
||||
* @param int $docID
|
||||
* @param int $newVersion
|
||||
* @param int $oldVersion
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function diff($docID, $newVersion, $oldVersion = '')
|
||||
{
|
||||
if(empty($oldVersion)) $oldVersion = $newVersion - 1;
|
||||
if(empty($oldVersion) or empty($newVersion)) die(js::error($this->lang->doc->versionNotFound) . js::locate('back'));
|
||||
|
||||
$newDoc = $this->doc->getById($docID, $newVersion, true);
|
||||
$oldDoc = $this->doc->getById($docID, $oldVersion, true);
|
||||
if(!$newDoc) die(js::error($this->lang->notFound) . js::locate('back'));
|
||||
|
||||
/* Merge files in doc. */
|
||||
$dbOldDocFiles = $this->dao->select('files')->from(TABLE_DOCCONTENT)->where('doc')->eq($docID)->andWhere('version')->eq($oldVersion)->fetch('files');
|
||||
$dbOldDocFiles = explode(',', $dbOldDocFiles);
|
||||
sort($dbOldDocFiles);
|
||||
$oldDocFiles = array();
|
||||
foreach($dbOldDocFiles as $fileID)
|
||||
{
|
||||
if(!isset($oldDoc->files[$fileID])) continue;
|
||||
$file = $oldDoc->files[$fileID];
|
||||
$oldDocFiles[$fileID] = 'File #' . $fileID;
|
||||
if($file) $oldDocFiles[$fileID] .= ' ' . $file->title . '.' . $file->extension;
|
||||
}
|
||||
$oldDoc->files = join("\n", $oldDocFiles);
|
||||
|
||||
$dbNewDocFiles = $this->dao->select('files')->from(TABLE_DOCCONTENT)->where('doc')->eq($docID)->andWhere('version')->eq($newVersion)->fetch('files');
|
||||
$dbNewDocFiles = explode(',', $dbNewDocFiles);
|
||||
sort($dbNewDocFiles);
|
||||
$newDocFiles = array();
|
||||
foreach($dbNewDocFiles as $fileID)
|
||||
{
|
||||
if(!isset($newDoc->files[$fileID])) continue;
|
||||
$file = $newDoc->files[$fileID];
|
||||
$newDocFiles[$fileID] = 'File #' . $fileID;
|
||||
if($file) $newDocFiles[$fileID] .= ' ' . $file->title . '.' . $file->extension;
|
||||
}
|
||||
$newDoc->files = join("\n", $newDocFiles);
|
||||
|
||||
/* Get diff. */
|
||||
$diff = new stdclass();
|
||||
$diff->content = $this->doc->diff($oldDoc->content, $newDoc->content);
|
||||
$diff->digest = $this->doc->diff($oldDoc->digest, $newDoc->digest);
|
||||
$diff->files = $this->doc->diff($oldDoc->files, $newDoc->files);
|
||||
|
||||
/* Check priv when lib is product or project. */
|
||||
$lib = $this->doc->getLibByID($newDoc->lib);
|
||||
$type = $lib->product ? 'product' : ($lib->project ? 'project' : 'custom');
|
||||
|
||||
/* Set menu. */
|
||||
$this->doc->setMenu($newDoc->lib, $newDoc->module);
|
||||
|
||||
$this->view->title = "DOC #$newDoc->id $newDoc->title - " . $lib->name;
|
||||
$this->view->position[] = html::a($this->createLink('doc', 'browse', "libID=$newDoc->lib"), $lib->name);
|
||||
$this->view->position[] = $this->lang->doc->view;
|
||||
|
||||
$this->view->newDoc = $newDoc;
|
||||
$this->view->oldDoc = $oldDoc;
|
||||
$this->view->docID = $docID;
|
||||
$this->view->lib = $lib;
|
||||
$this->view->type = $type;
|
||||
$this->view->newVersion = $newVersion;
|
||||
$this->view->oldVersion = $oldVersion;
|
||||
$this->view->diff = $diff;
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a doc.
|
||||
*
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
table.alldiff th{width:70px;border-right:1px solid #ddd;}
|
||||
table.table.alldiff td:last-child{padding:0px;}
|
||||
table.table.diff {border:none}
|
||||
table.alldiff table.table.diff td{border:none;}
|
||||
table.alldiff table.table.diff .num{border-right:1px solid #ddd; text-align:right; width:20px;}
|
||||
table.alldiff table.table.diff .oldLine{border-right:1px solid #ddd;}
|
||||
table.table.diff td.newLine{padding:3px;}
|
||||
table.table.diff td.oldLine{padding:3px;}
|
||||
table.table.diff td.line{padding-left:20px;}
|
||||
table.table.diff td.diffline.newLine{background: #8eff8e}
|
||||
table.table.diff td.diffline.oldLine{background: #f6b2b2}
|
||||
@@ -1037,166 +1037,6 @@ class docModel extends model
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Diff doc.
|
||||
*
|
||||
* @param string $text1
|
||||
* @param string $text2
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function diff($text1, $text2)
|
||||
{
|
||||
$text1 = explode("\n", trim($text1));
|
||||
$text2 = explode("\n", trim($text2));
|
||||
$text1Len = count($text1);
|
||||
$text2Len = count($text2);
|
||||
$trace = array();
|
||||
$trace[-1] = array_fill(-1, $text2Len + 1, +1);
|
||||
$lcs0 = array_fill(-1, $text2Len + 1, 0);
|
||||
$lcs1[-1] = 0;
|
||||
|
||||
foreach($text1 as $line)
|
||||
{
|
||||
$temp = array();
|
||||
$temp[-1] = -1;
|
||||
for($i = 0; $i < $text2Len; $i++)
|
||||
{
|
||||
if($line == $text2[$i])
|
||||
{
|
||||
$lcs1[$i] = $lcs0[$i - 1] + 1;
|
||||
$temp[$i] = 0;
|
||||
}
|
||||
elseif($lcs0[$i] > $lcs1[$i - 1])
|
||||
{
|
||||
$lcs1[$i] = $lcs0[$i];
|
||||
$temp[$i] = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$lcs1[$i] = $lcs1[$i - 1];
|
||||
$temp[$i] = +1;
|
||||
}
|
||||
}
|
||||
array_push($trace, $temp);
|
||||
$temp = $lcs1;
|
||||
$lcs1 = $lcs0;
|
||||
$lcs0 = $temp;
|
||||
}
|
||||
|
||||
$same = 0;
|
||||
$out = false;
|
||||
$ret = array();
|
||||
for($i = $text1Len - 1, $j = $text2Len - 1; $i != -1 || $j != -1;)
|
||||
{
|
||||
if($trace[$i][$j] == 0)
|
||||
{
|
||||
$same++;
|
||||
if($out && $same > 0)
|
||||
{
|
||||
$outbegina = $i + $same;
|
||||
$outbeginb = $j + $same;
|
||||
for($k = $i + $same - 1; $k >= $outbegina; $k--) array_push($ret, array('cmd' => ' ', 'dat' => $text1[$k]));
|
||||
$dat = array($outbegina, $outenda - $outbegina + 1, $outbeginb, $outendb - $outbeginb + 1);
|
||||
array_push($ret, array('cmd' => '@', 'dat'=> $dat));
|
||||
$out = false;
|
||||
}
|
||||
$i--;
|
||||
$j--;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$out)
|
||||
{
|
||||
$same = min($same, 0);
|
||||
$out = true;
|
||||
$outenda = $i + $same;
|
||||
$outendb = $j + $same;
|
||||
}
|
||||
for($k = $i + $same; $k > $i; $k--) array_push($ret, array('cmd' => ' ', 'dat' => $text1[$k]));
|
||||
$same = 0;
|
||||
if($trace[$i][$j] == -1)
|
||||
{
|
||||
array_push($ret, array('cmd' => '-', 'dat' => $text1[$i]));
|
||||
$i--;
|
||||
}
|
||||
else
|
||||
{
|
||||
array_push($ret, array('cmd' => '+', 'dat' => $text2[$j]));
|
||||
$j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($out)
|
||||
{
|
||||
$outbegina = max(0, $same);
|
||||
$outbeginb = max(0, $same);
|
||||
for($k = $same - 1; $k >= $outbegina; $k--) array_push($ret, array('cmd' => ' ', 'dat' => $text1[$k]));
|
||||
$dat = array($outbegina, $outenda - $outbegina + 1, $outbeginb, $outendb - $outbeginb + 1);
|
||||
array_push($ret, array('cmd' => '@', 'dat'=> $dat));
|
||||
}
|
||||
|
||||
$diffs = array_reverse($ret);
|
||||
if(empty($diffs)) return array();
|
||||
|
||||
$processedDiff = array();
|
||||
foreach($diffs as $i => $diff)
|
||||
{
|
||||
if($diff['cmd'] == '@')
|
||||
{
|
||||
$max = max($diff['dat'][1], $diff['dat'][3]);
|
||||
for($number = 0; $number < $max; $number++)
|
||||
{
|
||||
$oldLineNO = $diff['dat'][0] + $number;
|
||||
$newLineNO = $diff['dat'][2] + $number;
|
||||
$oldLine = '';
|
||||
$newLine = '';
|
||||
if($diff['dat'][1] > 0 and $diff['dat'][1] >= $number + 1) $oldLine = $diffs[$i + $number + 1]['dat'];
|
||||
if($diff['dat'][3] > 0 and $diff['dat'][3] >= $number + 1) $newLine = $diffs[$i + $number + 1 + $diff['dat'][1]]['dat'];
|
||||
$processedDiff['old'][$oldLineNO] = $oldLine;
|
||||
$processedDiff['new'][$newLineNO] = $newLine;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return $processedDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line number by diff.
|
||||
*
|
||||
* @param array $diff
|
||||
* @param int $i
|
||||
* @param int $lineNO
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getLineNumber($diff, $i, $lineNO)
|
||||
{
|
||||
$action = '';
|
||||
if(isset($diff[$i]))
|
||||
{
|
||||
if(empty($diff[$i]))
|
||||
{
|
||||
$showNumber = '';
|
||||
$action = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$showNumber = $lineNO + 1;
|
||||
$action = 'diff';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$showNumber = $lineNO + 1;
|
||||
$action = '';
|
||||
}
|
||||
|
||||
return array($showNumber, $action, 'number' => $showNumber, 'action' => $action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get crumbs.
|
||||
*
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* The view of doc module of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
|
||||
* @license ZPL (http://zpl.pub/page/zplv12.html)
|
||||
* @author Jia Fu <fujia@cnezsoft.com>
|
||||
* @package doc
|
||||
* @version $Id: view.html.php 975 2010-07-29 03:30:25Z jajacn@126.com $
|
||||
* @link http://www.zentao.net
|
||||
*/
|
||||
?>
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<div id='titlebar'>
|
||||
<div class='heading'>
|
||||
<span class='prefix' title='DOC'><?php echo html::icon($lang->icons['doc']);?> <strong><?php echo $docID;?></strong></span>
|
||||
<strong><?php echo $newDoc->title;?></strong>
|
||||
<span><?php echo " #" . $oldVersion . ' : ' . $newVersion?></span>
|
||||
<?php if($newDoc->deleted):?>
|
||||
<span class='label label-danger'><?php echo $lang->doc->deleted;?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class='actions'><?php echo html::backButton(); ?></div>
|
||||
</div>
|
||||
<div class='row-table'>
|
||||
<table class='table table-data alldiff'>
|
||||
<?php if($oldDoc->title != $newDoc->title):?>
|
||||
<tr>
|
||||
<th><?php $lang->doc->title?></th>
|
||||
<td><?php echo $oldDoc->title?></td>
|
||||
<td><?php echo $newDoc->title?></td>
|
||||
</tr>
|
||||
<?php endif;?>
|
||||
<?php foreach($diff as $field => $diffLines):?>
|
||||
<?php if(empty($diffLines)) continue;?>
|
||||
<tr>
|
||||
<th><?php echo $lang->doc->$field?></th>
|
||||
<td colspan='2'>
|
||||
<table class='diff table table-data table-hover table-condensed'>
|
||||
<?php
|
||||
$oldLines = explode("\n", htmlspecialchars(trim($oldDoc->$field)));
|
||||
$newLines = explode("\n", htmlspecialchars(trim($newDoc->$field)));
|
||||
$lines = max(count($oldLines), count($newLines));
|
||||
$oldLineNO = 0;
|
||||
$newLineNO = 0;
|
||||
?>
|
||||
<?php for($i = 0; $i < $lines; $i++):?>
|
||||
<tr>
|
||||
<?php
|
||||
list($showNumber, $action) = $this->doc->getLineNumber($diffLines['old'], $i, $oldLineNO);
|
||||
$showLine = '';
|
||||
if($showNumber)
|
||||
{
|
||||
$showLine = $oldLines[$oldLineNO];
|
||||
$oldLineNO ++;
|
||||
}
|
||||
elseif(isset($oldLines[$oldLineNO]) and empty($oldLines[$oldLineNO]))
|
||||
{
|
||||
$showNumber = $oldLineNO + 1;
|
||||
$oldLineNO ++;
|
||||
if(isset($diffLines['old'][$i])) $action = 'diff';
|
||||
}
|
||||
if($action) $showLine = "<i class='icon icon-minus'></i> " . $showLine;
|
||||
?>
|
||||
<td class='oldNO num'><?php echo $showNumber?></td>
|
||||
<td class='oldLine <?php echo $action?>line'><?php echo $showLine?></td>
|
||||
<?php
|
||||
list($showNumber, $action) = $this->doc->getLineNumber($diffLines['new'], $i, $newLineNO);
|
||||
$showLine = '';
|
||||
if($showNumber)
|
||||
{
|
||||
$showLine = $newLines[$newLineNO];
|
||||
$newLineNO ++;
|
||||
}
|
||||
elseif(isset($newLines[$newLineNO]) and empty($newLines[$newLineNO]))
|
||||
{
|
||||
$showNumber = $newLineNO + 1;
|
||||
$newLineNO ++;
|
||||
if(isset($diffLines['new'][$i])) $action = 'diff';
|
||||
}
|
||||
if($action) $showLine = "<i class='icon icon-plus'></i> " . $showLine;
|
||||
?>
|
||||
<td class='newNO num'><?php echo $showNumber?></td>
|
||||
<td class='newLine <?php echo $action?>line'><?php echo $showLine?></td>
|
||||
</tr>
|
||||
<?php endfor;?>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach;?>
|
||||
</table>
|
||||
</div>
|
||||
<?php include '../../common/view/footer.html.php';?>
|
||||
@@ -42,19 +42,6 @@
|
||||
if(!$doc->deleted)
|
||||
{
|
||||
ob_start();
|
||||
//if($doc->version > 1 and common::hasPriv('doc', 'diff'))
|
||||
//{
|
||||
// echo "<div class='btn-group'>";
|
||||
// echo "<button data-toggle='dropdown' type='button' class='btn dropdown-toggle'>{$lang->doc->diff} <span class='caret'></span></button>";
|
||||
// echo "<ul class='dropdown-menu'>";
|
||||
// for($i = $doc->version; $i >= 1; $i --)
|
||||
// {
|
||||
// if($i == $version) continue;
|
||||
// echo '<li>' . html::a(inlink('diff', "docID=$doc->id&newVersion=$version&version=$i"), '#' . $i) . '</li>';
|
||||
// }
|
||||
// echo "</ul>";
|
||||
// echo "</div>";
|
||||
//}
|
||||
echo "<div class='btn-group'>";
|
||||
common::printCommentIcon('doc');
|
||||
common::printIcon('doc', 'edit', $params);
|
||||
|
||||
Reference in New Issue
Block a user