diff.html.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <?php
  2. /**
  3. * The diff view file of repo module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2012 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @author Wang Yidong, Zhu Jinyong
  7. * @package repo
  8. * @version $Id: browse.html.php $
  9. */
  10. ?>
  11. <?php include $app->getModuleRoot() . 'common/view/header.html.php';?>
  12. <?php include $app->getModuleRoot() . 'common/view/form.html.php';?>
  13. <?php include $app->getModuleRoot() . 'common/view/kindeditor.html.php';?>
  14. <?php include 'header.review.html.php';?>
  15. <?php js::set('revision', $newRevision);?>
  16. <?php js::set('sourceRevision', $oldRevision);?>
  17. <?php js::set('repoID', $repoID);?>
  18. <?php js::set('arrange', $arrange);?>
  19. <?php js::set('repo', $repo);?>
  20. <?php js::set('repoLang', $lang->repo);?>
  21. <?php js::set('objectID', $objectID);?>
  22. <?php js::set('edition', $config->edition);?>
  23. <?php
  24. $browser = helper::getBrowser();
  25. js::set('browser', $browser['name']);
  26. ?>
  27. <?php $titleWidth = common::checkNotCN() ? '240' : '210';?>
  28. <?php if(!isonlybody()):?>
  29. <div id='mainMenu' class='clearfix'>
  30. <div class='btn-toolbar pull-left repo-diff'>
  31. <?php if($diffs):?>
  32. <div class="pull-left" id="sidebarHeader" style="width: <?php echo $titleWidth;?>px">
  33. <div class="title" title="<?php echo $lang->repo->changeFile;?>"><?php echo $lang->repo->changeFile;?></div>
  34. </div>
  35. <?php
  36. else:
  37. $backURI = $this->session->repoView ? $this->session->repoView : $this->session->repoList;
  38. if($backURI)
  39. {
  40. echo html::a($backURI, "<i class='icon icon-back icon-sm'></i> " . $lang->goback, '', "class='btn btn-link' data-app='{$app->tab}'");
  41. }
  42. else
  43. {
  44. echo html::backButton("<i class='icon icon-back icon-sm'></i> " . $lang->goback, '', "btn btn-link");
  45. }
  46. ?>
  47. <?php endif;?>
  48. <div class="page-title">
  49. <?php if($repo->SCM == 'Subversion'):?>
  50. <div class="svn-path">
  51. <?php
  52. echo html::a($this->repo->createLink('browse', "repoID=$repoID&branchID=&objectID=$objectID"), $repo->name, '', "data-app='{$app->tab}'");
  53. $paths = explode('/', $entry);
  54. $fileName = array_pop($paths);
  55. $postPath = '';
  56. foreach($paths as $pathName)
  57. {
  58. $postPath .= $pathName . '/';
  59. echo '/' . ' ' . html::a($this->repo->createLink('browse', "repoID=$repoID&branchID=$branchID&objectID=$objectID&path=" . $this->repo->encodePath($postPath)), trim($pathName, '/'), '', "data-app='{$app->tab}'");
  60. }
  61. $oldRevision = $oldRevision == '^' ? $newRevision - 1 : $oldRevision;
  62. echo "/ $fileName ";
  63. ?>
  64. </div>
  65. <form class='main-table pull-right' id="svnForm" data-ride='table'>
  66. <input type="hidden" name="repoID" id="repoID" value="<?php echo $repoID;?>">
  67. <?php echo html::input("oldRevision", $oldRevision, "id='oldRevision' class='form-control svn-version' placeholder='{$lang->repo->source}'");?>
  68. <span class="label label-exchange"><i class="icon icon-exchange"></i></span>
  69. <?php echo html::input("newRevision", $newRevision, "id='newRevision' class='form-control svn-version' placeholder='{$lang->repo->target}'");?>
  70. <input type="hidden" name="isBranchOrTag" id="isBranchOrTag" value="">
  71. <?php echo html::commonButton($lang->repo->compare, '', 'btn btn-primary diffForm');?>
  72. </form>
  73. <?php else:?>
  74. <div class='btn-group' id='sourceSwapper'>
  75. <button data-toggle='dropdown' type='button' class='btn btn-link btn-limit repo-select text-ellipsis'title='<?php echo $oldRevision ? $oldRevision : $lang->repo->select;?>'>
  76. <span class='text pull-left'><?php echo $lang->repo->source . ': ';?></span>
  77. <span class='text version-name pull-left text-ellipsis' <?php echo common::checkNotCN() ? '' : 'style="max-width: 110px;"';?>><?php echo $oldRevision;?></span>
  78. <span class='caret' style='margin-bottom: -1px'></span>
  79. </button>
  80. <div id='dropMenuSource' class='dropdown-menu search-list' data-ride='searchList' data-url=''>
  81. <div class="input-control search-box has-icon-left has-icon-right search-example">
  82. <input type="search" class="form-control search-input" id="searchSource" placeholder="<?php echo $lang->repo->searchPlaceholder;?>"/>
  83. <label class="input-control-icon-left search-icon"><i class="icon icon-search"></i></label>
  84. <a class="input-control-icon-right search-clear-btn"><i class="icon icon-close icon-sm"></i></a>
  85. </div>
  86. <div class="table-row">
  87. <div class="table-col col-left">
  88. <div class="list-group" id="sourceList"></div>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. <span class="label label-exchange-git"><i class="icon icon-exchange"></i></span>
  94. <div class='btn-group' id='targetSwapper'>
  95. <button data-toggle='dropdown' type='button' class='btn btn-link btn-limit repo-select text-ellipsis' title='<?php echo $newRevision ? $newRevision : $lang->repo->select;?>'>
  96. <span class='text pull-left'><?php echo $lang->repo->target . ': ';?></span>
  97. <span class='text version-name pull-left text-ellipsis' <?php echo common::checkNotCN() ? '' : 'style="max-width: 110px;"';?>><?php echo $newRevision;?></span>
  98. <span class='caret' style='margin-bottom: -1px'></span>
  99. </button>
  100. <div id='dropMenuTarget' class='dropdown-menu search-list' data-ride='searchList' data-url=''>
  101. <div class="input-control search-box has-icon-left has-icon-right search-example">
  102. <input type="search" class="form-control search-input" id="searchTarget" placeholder="<?php echo $lang->repo->searchPlaceholder;?>"/>
  103. <label class="input-control-icon-left search-icon"><i class="icon icon-search"></i></label>
  104. <a class="input-control-icon-right search-clear-btn"><i class="icon icon-close icon-sm"></i></a>
  105. </div>
  106. <div class="table-row">
  107. <div class="table-col col-left">
  108. <div class="list-group" id="targetList"></div>
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. <?php endif;?>
  114. <?php if($repo->SCM != 'Subversion'):?>
  115. <form class='main-table pull-right' id="gitForm" data-ride='table'>
  116. <input type="hidden" name="repoID" id="repoID" value="<?php echo $repoID;?>">
  117. <input type="hidden" name="oldRevision" id="oldRevision" value="<?php echo $oldRevision;?>">
  118. <input type="hidden" name="newRevision" id="newRevision" value="<?php echo $newRevision;?>">
  119. <input type="hidden" name="isBranchOrTag" id="isBranchOrTag" value="1">
  120. <?php echo html::commonButton($lang->repo->compare, '', 'btn btn-primary diffForm');?>
  121. </form>
  122. <?php endif;?>
  123. </div>
  124. </div>
  125. </div>
  126. <?php endif;?>
  127. <?php if($browser['name'] == 'ie'):?>
  128. <?php if($oldRevision != '' and $newRevision != ''):?>
  129. <div class="fade main-row split-row" id="mainRow">
  130. <?php if($diffs):?>
  131. <?php $sideWidth = common::checkNotCN() ? '260' : '230';?>
  132. <div class="side-col" style="width: <?php echo $sideWidth;?>px; padding-top: <?php echo isonlybody() ? 22 : 0;?>px;">
  133. <?php if(isonlybody()):?>
  134. <div id="sidebarHeader" style="width: <?php echo $titleWidth;?>px">
  135. <div class="title" title="<?php echo $lang->repo->changeFile;?>"><?php echo $lang->repo->changeFile;?></div>
  136. </div>
  137. <?php endif;?>
  138. <div class="side-col file-tree" style="width: <?php echo $sideWidth;?>px;" data-min-width="<?php echo $sideWidth;?>">
  139. <div class="cell <?php if(isonlybody()) echo 'pull-left';?>">
  140. <?php echo $this->repo->getDiffFileTree($diffs);?>
  141. </div>
  142. </div>
  143. </div>
  144. <?php endif;?>
  145. <div class="repo panel cell main-col pull-left col-12">
  146. <div class='panel-heading'>
  147. <form method='post'>
  148. <div class='btn-group pull-right'>
  149. <?php echo html::commonButton($lang->repo->viewDiffList['inline'], "id='inline'", $arrange == 'inline' ? 'active btn btn-sm' : 'btn btn-sm')?>
  150. <?php echo html::commonButton($lang->repo->viewDiffList['appose'], "id='appose'", $arrange == 'appose' ? 'active btn btn-sm' : 'btn btn-sm')?>
  151. </div>
  152. <div class='btn-toolbar'>
  153. <div class='btn-group'>
  154. <?php
  155. if(common::hasPriv('repo', 'download'))
  156. {
  157. $oldVersion = $isBranchOrTag ? helper::safe64Encode(urlencode($oldRevision)) : $oldRevision;
  158. $newVersion = $isBranchOrTag ? helper::safe64Encode(urlencode($newRevision)) : $newRevision;
  159. echo html::a($this->repo->createLink('download', "repoID=$repoID&path=" . $this->repo->encodePath($entry) . "&fromRevison=$oldVersion&toRevision=$newVersion&type=path&isBranchOrTag=$isBranchOrTag"), $lang->repo->downloadDiff, 'hiddenwin', "class='btn btn-sm btn-download'");
  160. }
  161. ?>
  162. <div class='btn-group'>
  163. <?php echo html::commonButton(zget($lang->repo->encodingList, $encoding, $lang->repo->encoding) . "<span class='caret'></span>", "data-toggle='dropdown'", 'btn dropdown-toggle btn-sm')?>
  164. <ul class='dropdown-menu' role='menu'>
  165. <?php foreach($lang->repo->encodingList as $key => $val):?>
  166. <li><?php echo html::a('javascript:changeEncoding("'. $key . '")', $val)?></li>
  167. <?php endforeach;?>
  168. </ul>
  169. </div>
  170. </div>
  171. </div>
  172. <?php echo html::hidden('arrange', $arrange) . html::hidden('encoding', $encoding) . html::hidden('revision[]', helper::safe64Encode(urlencode($newRevision))) . html::hidden('revision[]', helper::safe64Encode(urlencode($oldRevision))) . html::hidden('isBranchOrTag', 1);?>
  173. </form>
  174. </div>
  175. <div class='btn-group header-btn' id="fileSwapper">
  176. <?php $fileCount = count($diffs);?>
  177. <button <?php if($fileCount > 0) echo 'data-toggle="dropdown"';?> type='button' class='btn'>
  178. <span class='text'><?php echo sprintf($lang->repo->fileTotal, $fileCount);?></span>
  179. <span class='caret' style='margin-bottom: -1px'></span>
  180. </button>
  181. <div id='dropMenu' class='dropdown-menu search-list' data-ride='searchList'>
  182. <div class="input-control search-box has-icon-left has-icon-right search-example">
  183. <input type="search" class="form-control search-input" />
  184. <label class="input-control-icon-left search-icon">
  185. <i class="icon icon-search"></i>
  186. </label>
  187. <a class="input-control-icon-right search-clear-btn">
  188. <i class="icon icon-close icon-sm"></i>
  189. </a>
  190. </div>
  191. <div class="list-group">
  192. <div class="table-row">
  193. <div class="table-col col-left">
  194. <div class="list-group">
  195. <ul class="tree tree-simple" data-ride="tree" id="fileTree" data-name="tree-program">
  196. <?php $deletedLine = $addedLine = 0;?>
  197. <?php foreach($diffs as $key => $diffFile):?>
  198. <?php if(isset($diffFile->contents)):?>
  199. <?php foreach($diffFile->contents as $content):?>
  200. <?php foreach($content->lines as $line):?>
  201. <?php if($line->type == 'old') $deletedLine ++;?>
  202. <?php if($line->type == 'new') $addedLine ++;?>
  203. <?php endforeach;?>
  204. <?php endforeach;?>
  205. <?php endif;?>
  206. <li><a href="#filePath<?php echo $key;?>" class="text-ellipsis fileName search-list-item" onclick="jumpFile('<?php echo $key;?>', this)" title="<?php echo $diffFile->fileName;?>" data-key="<?php echo $diffFile->fileName;?>"><?php echo $diffFile->fileName;?></a></li>
  207. <?php endforeach;?>
  208. </ul>
  209. </div>
  210. </div>
  211. </div>
  212. </div>
  213. </div>
  214. </div>
  215. <div class='code-survey'><?php echo sprintf($lang->repo->codeSurvey, $addedLine, $deletedLine);?></div>
  216. <?php foreach($diffs as $key => $diffFile):?>
  217. <div class='repoCode'>
  218. <a name="filePath<?php echo $key;?>" href="#"></a>
  219. <table class='table diff' id='file<?php echo $key;?>'>
  220. <caption>
  221. <i class="icon list-toggle list-toggle-open" onclick="diffToggle(this)"></i>
  222. <a class="file-name"><?php echo $diffFile->fileName;?></a>
  223. </caption>
  224. <?php if(empty($diffFile->contents)) continue;?>
  225. <?php if($repo->SCM == 'Subversion') $diffFile->fileName = $fileName . '/' . $diffFile->fileName;?>
  226. <?php foreach($diffFile->contents as $content):?>
  227. <?php
  228. $oldCurrentLine = $content->oldStartLine;
  229. $newCurrentLine = $content->newStartLine;
  230. ?>
  231. <?php if(!in_array($oldCurrentLine, array('0', '1')) and !in_array($newCurrentLine, array('0', '1'))):?>
  232. <tr data-line='<?php echo $newCurrentLine ?>' class='empty'>
  233. <th class='w-num text-center'>...</th>
  234. <?php if($arrange == 'appose'):?>
  235. <td class='none code'></td>
  236. <?php endif;?>
  237. <th class='w-num text-center'>...</th>
  238. <td class='none code'></td>
  239. </tr>
  240. <?php endif?>
  241. <?php if($arrange == 'inline'):?>
  242. <?php foreach($content->lines as $line):?>
  243. <tr data-line='<?php echo $line->type == 'old' ? $line->oldlc : $line->newlc;?>' data-src='<?php echo helper::safe64Encode(urlencode($diffFile->fileName));?>' data-type='<?php echo $line->type;?>'>
  244. <th class='w-num text-center'><?php if($line->type != 'new' and $line->oldlc) echo $line->oldlc;?></th>
  245. <th class='w-num text-center' data-line='<?php echo $line->type == 'new' ? $line->newlc : $line->oldlc;?>'>
  246. <?php if($line->type != 'old') echo $line->newlc;?>
  247. </th>
  248. <td class='line-<?php echo $line->type?> code'><?php
  249. $line->line = $repo->SCM == 'Subversion' ? htmlspecialchars($line->line) : $line->line;
  250. echo $line->type == 'old' ? preg_replace('/^\-/', '&ndash;', $line->line) : ($line->type == 'new' ? $line->line : ' ' . $line->line);
  251. ?></td>
  252. </tr>
  253. <?php endforeach;?>
  254. <?php else:?>
  255. <?php foreach($content->lines as $line):?>
  256. <?php if($line->type != 'old' and !isset($content->new[$line->newlc])) continue;?>
  257. <tr data-line='<?php echo $line->type == 'old' ? $line->oldlc : $line->newlc;?>' data-src='<?php echo helper::safe64Encode(urlencode($diffFile->fileName));?>' data-type='<?php echo $line->type;?>'>
  258. <?php
  259. if($line->type == 'old')
  260. {
  261. $oldlc = $line->oldlc;
  262. $newlc = '';
  263. if(isset($content->new[$oldlc]) and !isset($content->new[$oldlc - 1]))
  264. {
  265. $newlc = $line->oldlc;
  266. $line->type = 'custom';
  267. }
  268. }
  269. else
  270. {
  271. $oldlc = $line->oldlc > 0 ? $line->oldlc : ' ';
  272. $newlc = $line->newlc;
  273. }
  274. ?>
  275. <th class='w-num text-center'><?php echo $oldlc?></th>
  276. <td class='w-code line-<?php if($line->type != 'new')echo $line->type?> <?php if($line->type == 'custom') echo "line-old"?> code'>
  277. <?php
  278. if(!isset($content->old[$oldlc])) $content->old[$oldlc] = '';
  279. $content->old[$oldlc] = $repo->SCM == 'Subversion' ? htmlspecialchars($content->old[$oldlc]) : $content->old[$oldlc];
  280. if(!empty($oldlc)) echo $line->type != 'all' ? preg_replace('/^\-/', '&ndash;', $content->old[$oldlc]) : ' ' . $content->old[$oldlc];
  281. ?>
  282. </td>
  283. <th class='w-num text-center' data-line='<?php echo $line->type == 'new' ? $line->newlc : $line->oldlc;?>'><?php echo $newlc?></th>
  284. <td class='w-code line-<?php if($line->type != 'old') echo $line->type?> <?php if($line->type == 'custom') echo "line-new"?> code'>
  285. <?php
  286. if(!isset($content->new[$newlc])) $content->new[$newlc] = '';
  287. $content->new[$newlc] = $repo->SCM == 'Subversion' ? htmlspecialchars($content->new[$newlc]) : $content->new[$newlc];
  288. if(!empty($newlc)) echo $line->type != 'all' ? $content->new[$newlc] : ' ' . $content->new[$newlc];
  289. ?>
  290. </td>
  291. <?php
  292. if(isset($content->old[$oldlc])) unset($content->old[$oldlc]);
  293. if(isset($content->new[$newlc])) unset($content->new[$newlc]);
  294. ?>
  295. </tr>
  296. <?php endforeach;?>
  297. <?php endif;?>
  298. <?php endforeach;?>
  299. </table>
  300. </div>
  301. <?php endforeach?>
  302. </div>
  303. </div>
  304. <?php endif;?>
  305. <?php elseif($diffs):?>
  306. <?php include $app->getModuleRoot() . 'repo/view/diffeditor.html.php';?>
  307. <?php endif;?>
  308. <div class='revisions hidden'>
  309. <?php
  310. if($repo->SCM != 'Subversion')
  311. {
  312. $oldRevision = $oldRevision == '^' ? "$newRevision" : $oldRevision;
  313. echo " <span class='label label-info'>" . substr($oldRevision, 0, 10) . " : " . substr($newRevision, 0, 10) . ' (' . zget($historys, $oldRevision, '') . ' : ' . zget($historys, $newRevision, '') . ')</span>';
  314. }
  315. else
  316. {
  317. $oldRevision = $oldRevision == '^' ? $newRevision - 1 : $oldRevision;
  318. echo " <span class='label label-info'>$oldRevision : $newRevision</span>";
  319. }
  320. ?>
  321. </div>
  322. <form method="post" id="exchange" class="hidden">
  323. <input type="hidden" name="revision[]" value="<?php echo $oldRevision;?>"/>
  324. <input type="hidden" name="revision[]" value="<?php echo $newRevision;?>"/>
  325. </form>
  326. <?php include $app->getModuleRoot() . 'common/view/footer.html.php';?>