1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Xmf\Request; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* index.php - display wiki page |
7
|
|
|
* |
8
|
|
|
* @copyright Copyright © 2013 geekwright, LLC. All rights reserved. |
9
|
|
|
* @license gwiki/docs/license.txt GNU General Public License (GPL) |
10
|
|
|
* @since 1.0 |
11
|
|
|
* @author Richard Griffith <[email protected]> |
12
|
|
|
* @package gwiki |
13
|
|
|
*/ |
14
|
|
|
include __DIR__ . '/header.php'; |
15
|
|
|
global $xoTheme, $xoopsTpl; |
16
|
|
|
global $wikiPage; |
17
|
|
|
|
18
|
|
|
// this exists to make xoops comments work |
19
|
|
|
// index.php?page_id=15&com_mode=thread&com_order=0&com_id=2&com_rootid=1 |
20
|
|
|
if (Request::hasVar('page_id', 'GET')) { |
21
|
|
|
$page_id = Request::getInt('page_id', 0, 'GET'); |
22
|
|
|
$page = $wikiPage->getKeywordById($page_id); |
23
|
|
|
if (!empty($page)) { |
24
|
|
|
$extra = ''; |
25
|
|
|
if (isset($_GET['com_mode'])) { |
26
|
|
|
$extra .= '&com_mode=' . $_GET['com_mode']; |
27
|
|
|
} |
28
|
|
|
if (isset($_GET['com_order'])) { |
29
|
|
|
$extra .= '&com_order=' . $_GET['com_order']; |
30
|
|
|
} |
31
|
|
|
if (isset($_GET['com_id'])) { |
32
|
|
|
$extra .= '&com_id=' . $_GET['com_id']; |
33
|
|
|
} |
34
|
|
|
if (isset($_GET['com_rootid'])) { |
35
|
|
|
$extra .= '&com_rootid=' . $_GET['com_rootid']; |
36
|
|
|
} |
37
|
|
|
$header = sprintf($xoopsModuleConfig['wikilink_template'], $page) . $extra; |
38
|
|
|
header("Location: {$header}"); |
39
|
|
|
exit; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
// $_GET variables we use |
43
|
|
|
$page = $wikiPage->normalizeKeyword(Request::getString('page', $wikiPage->wikiHomePage, 'GET')); |
44
|
|
|
$highlight = Request::getString('query', null, 'GET'); |
45
|
|
|
|
46
|
|
|
// if we get a naked or external prefix, try and do something useful |
47
|
|
|
$pfx = $wikiPage->getPrefix($page); |
48
|
|
View Code Duplication |
if ($pfx && $pfx['defined']) { |
|
|
|
|
49
|
|
|
$page = $pfx['actual_page']; |
50
|
|
|
if ($pfx['prefix_is_external']) { |
51
|
|
|
header("Location: {$pfx['actual_page']}"); |
52
|
|
|
exit; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
global $wikiPage; |
57
|
|
|
$pageX = $wikiPage->getPage($page); |
58
|
|
|
$attachments = $wikiPage->getAttachments($page); |
59
|
|
|
$wikiPage->registerHit($page); |
60
|
|
|
$mayEdit = $wikiPage->checkEdit(); |
61
|
|
|
|
62
|
|
|
if ($pageX) { |
63
|
|
|
$pageX['body'] = $wikiPage->renderPage($wikiPage->body); |
64
|
|
|
$pageX['mayEdit'] = $mayEdit; |
65
|
|
|
$pageX['pageFound'] = true; |
66
|
|
|
if (!empty($highlight)) { |
67
|
|
|
$pageX['body'] = $wikiPage->highlightWords($highlight); |
68
|
|
|
} |
69
|
|
|
} else { |
70
|
|
|
$dir = $wikiPage->getWikiDir(); |
71
|
|
|
if ($mayEdit) { |
72
|
|
|
redirect_header(XOOPS_URL . "/modules/{$dir}/edit.php?page={$page}", 2, _MD_GWIKI_PAGENOTFOUND); |
73
|
|
|
} |
74
|
|
|
$pageX = array(); |
75
|
|
|
$pageX['keyword'] = $page; |
76
|
|
|
$pageX['title'] = _MD_GWIKI_NOEDIT_NOTFOUND_TITLE; |
77
|
|
|
$pageX['body'] = _MD_GWIKI_NOEDIT_NOTFOUND_BODY; |
78
|
|
|
$pageX['author'] = ''; |
79
|
|
|
$pageX['revisiontime'] = ''; |
80
|
|
|
$pageX['createdtime'] = ''; |
81
|
|
|
$pageX['mayEdit'] = $mayEdit; |
82
|
|
|
$pageX['pageFound'] = false; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$dir = basename(__DIR__); |
86
|
|
|
$pageX['moddir'] = $dir; |
87
|
|
|
$pageX['modpath'] = XOOPS_ROOT_PATH . '/modules/' . $dir; |
88
|
|
|
$pageX['modurl'] = XOOPS_URL . '/modules/' . $dir; |
89
|
|
|
if (!empty($attachments)) { |
90
|
|
|
$pageX['attachments'] = prepOut($attachments); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$_GET['page_id'] = $wikiPage->page_id; |
94
|
|
|
$_GET['nsid'] = $wikiPage->currentprefixid; |
95
|
|
|
|
96
|
|
|
$GLOBALS['xoopsOption']['template_main'] = $wikiPage->getTemplateName(); // 'gwiki_view.tpl'; |
97
|
|
|
include XOOPS_ROOT_PATH . '/header.php'; |
98
|
|
|
|
99
|
|
|
$pageX['title'] = prepOut($pageX['title']); |
100
|
|
|
$xoopsTpl->assign('gwiki', $pageX); |
101
|
|
|
|
102
|
|
|
//echo '<pre>';print_r($pageX);echo '</pre>'; |
103
|
|
|
|
104
|
|
|
$xoTheme->addStylesheet(XOOPS_URL . '/modules/gwiki/assets/css/module.css'); |
105
|
|
View Code Duplication |
if ($pageX['pageFound']) { |
|
|
|
|
106
|
|
|
$xoTheme->addMeta('meta', 'keywords', htmlspecialchars($pageX['meta_keywords'], ENT_QUOTES, null, false)); |
107
|
|
|
$xoTheme->addMeta('meta', 'description', htmlspecialchars($pageX['meta_description'], ENT_QUOTES, null, false)); |
108
|
|
|
} |
109
|
|
|
$title = $pageX['title']; |
110
|
|
|
if (empty($title)) { |
111
|
|
|
$title = htmlspecialchars($xoopsModule->name()); |
112
|
|
|
} |
113
|
|
|
$xoopsTpl->assign('xoops_pagetitle', $title); |
114
|
|
|
if (!empty($message)) { |
115
|
|
|
$xoopsTpl->assign('message', $message); |
116
|
|
|
} |
117
|
|
|
if (!empty($err_message)) { |
118
|
|
|
$xoopsTpl->assign('err_message', $err_message); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
include XOOPS_ROOT_PATH . '/include/comment_view.php'; |
122
|
|
|
|
123
|
|
|
include XOOPS_ROOT_PATH . '/footer.php'; |
124
|
|
|
|
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.