1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* showdiff.php - show diff between two revisions of a page |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright © 2013 geekwright, LLC. All rights reserved. |
6
|
|
|
* @license gwiki/docs/license.txt GNU General Public License (GPL) |
7
|
|
|
* @since 1.0 |
8
|
|
|
* @author Richard Griffith <[email protected]> |
9
|
|
|
* @package gwiki |
10
|
|
|
*/ |
11
|
|
|
include __DIR__ . '/header.php'; |
12
|
|
|
require_once __DIR__ . '/include/Diff.php'; |
13
|
|
|
global $xoTheme, $xoopsTpl; |
14
|
|
|
global $wikiPage; |
15
|
|
|
|
16
|
|
|
// $_GET variables we use |
17
|
|
|
$page = $wikiPage->normalizeKeyword(isset($_GET['page']) ? cleaner($_GET['page']) : $wikiPage->wikiHomePage); |
18
|
|
|
$id = isset($_GET['id']) ? cleaner($_GET['id']) : null; // old revision id |
19
|
|
|
$nid = isset($_GET['nid']) ? cleaner($_GET['nid']) : null; // new revision id |
20
|
|
|
|
21
|
|
|
$pageX = $wikiPage->getPage($page, $nid); |
22
|
|
|
$mayEdit = $wikiPage->checkEdit(); |
23
|
|
|
$dir = $wikiPage->getWikiDir(); |
24
|
|
|
|
25
|
|
|
if ($pageX) { |
26
|
|
|
// $pageX['body']=$wikiPage->renderPage($wikiPage->body); |
27
|
|
|
$pageX['mayEdit'] = $mayEdit; |
28
|
|
|
$pageX['pageFound'] = true; |
29
|
|
|
$oldpage = $wikiPage->getPage($page, $id); |
30
|
|
|
if (!$oldpage) { |
31
|
|
|
redirect_header(XOOPS_URL . "/modules/{$dir}/index.php?page={$page}", 2, _MD_GWIKI_PAGENOTFOUND); |
32
|
|
|
} |
33
|
|
|
$diff = new Diff; |
34
|
|
|
$diffout = $diff->getDiff(trim($oldpage['body']) . "\n", trim($pageX['body']) . "\n"); |
35
|
|
|
$difflines = explode("\n", $diffout); |
36
|
|
|
$body = '<div class="wikidiff"><pre>'; |
37
|
|
|
foreach ($difflines as $line) { |
38
|
|
|
if (strpos($line, "\n") === false) { |
39
|
|
|
$line .= "\n"; |
40
|
|
|
} |
41
|
|
|
switch ($line[0]) { |
42
|
|
|
case '+': |
43
|
|
|
$body .= '<span class="wikidiffadd">' . htmlspecialchars($line, ENT_QUOTES) . '</span>'; |
44
|
|
|
break; |
45
|
|
|
case '-': |
46
|
|
|
$body .= '<span class="wikidiffdel"">' . htmlspecialchars($line, ENT_QUOTES) . '</span>'; |
47
|
|
|
break; |
48
|
|
|
default: |
49
|
|
|
$body .= '<span class="wikidiffsame"">' . htmlspecialchars($line, ENT_QUOTES) . '</span>'; |
50
|
|
|
break; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
$body .= '</pre></div>'; |
54
|
|
|
$pageX['body'] = $body; |
55
|
|
|
} else { |
56
|
|
|
redirect_header(XOOPS_URL . "/modules/{$dir}/index.php?page={$page}", 2, _MD_GWIKI_PAGENOTFOUND); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$dir = basename(__DIR__); |
60
|
|
|
$pageX['moddir'] = $dir; |
61
|
|
|
$pageX['modpath'] = XOOPS_ROOT_PATH . '/modules/' . $dir; |
62
|
|
|
$pageX['modurl'] = XOOPS_URL . '/modules/' . $dir; |
63
|
|
|
|
64
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'gwiki_view.tpl'; |
65
|
|
|
include XOOPS_ROOT_PATH . '/header.php'; |
66
|
|
|
|
67
|
|
|
$pageX['title'] = sprintf(_MD_GWIKI_DIFF_TITLE, prepOut($pageX['title'])); |
68
|
|
|
$xoopsTpl->assign('gwiki', $pageX); |
69
|
|
|
|
70
|
|
|
//echo '<pre>';print_r($pageX);echo '</pre>'; |
71
|
|
|
|
72
|
|
|
$xoTheme->addStylesheet(XOOPS_URL . '/modules/gwiki/assets/css/module.css'); |
73
|
|
View Code Duplication |
if ($pageX['pageFound']) { |
|
|
|
|
74
|
|
|
$xoTheme->addMeta('meta', 'keywords', htmlspecialchars($pageX['meta_keywords'], ENT_QUOTES, null, false)); |
75
|
|
|
$xoTheme->addMeta('meta', 'description', htmlspecialchars($pageX['meta_description'], ENT_QUOTES, null, false)); |
76
|
|
|
} |
77
|
|
|
$title = $pageX['title']; |
78
|
|
|
if (empty($title)) { |
79
|
|
|
$title = htmlspecialchars($xoopsModule->name()); |
80
|
|
|
} |
81
|
|
|
$xoopsTpl->assign('xoops_pagetitle', $title); |
82
|
|
|
if (!empty($message)) { |
83
|
|
|
$xoopsTpl->assign('message', $message); |
84
|
|
|
} |
85
|
|
|
if (!empty($err_message)) { |
86
|
|
|
$xoopsTpl->assign('err_message', $err_message); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
include XOOPS_ROOT_PATH . '/footer.php'; |
90
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.