1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Xmf\Request; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* wiki page anywhere - call it anything, put it anywhere |
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
|
|
|
|
15
|
|
|
// ****************************************************************** |
16
|
|
|
// adjust these next few lines to reflect your installation |
17
|
|
|
include __DIR__ . '/../../../mainfile.php'; |
18
|
|
|
$dir = 'gwiki'; // wiki module directory |
19
|
|
|
$pagevar = 'page'; // what is our page variable name? |
20
|
|
|
|
21
|
|
|
// $_GET variables we use |
22
|
|
|
$page = Request::getString($pagevar, null, 'GET'); |
23
|
|
|
$highlight = Request::getString('query', null, 'GET'); |
24
|
|
|
|
25
|
|
|
// build a URL template to point wiki links to this script |
26
|
|
|
$script = (!empty($_SERVER['HTTPS'])) |
27
|
|
|
? 'https://' . $_SERVER['SERVER_NAME'] . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) |
28
|
|
|
: 'http://' . $_SERVER['SERVER_NAME'] . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); |
29
|
|
|
$ourWikiLinkURL = $script . '?' . $pagevar . '=%s'; |
30
|
|
|
|
31
|
|
|
// normally, adjustments to the remaining code are not required |
32
|
|
|
// ****************************************************************** |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param $string |
36
|
|
|
* |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
View Code Duplication |
function cleaner($string) |
40
|
|
|
{ |
41
|
|
|
$string = stripcslashes($string); |
42
|
|
|
$string = html_entity_decode($string); |
43
|
|
|
$string = strip_tags($string); // DANGER -- kills wiki text |
44
|
|
|
$string = trim($string); |
45
|
|
|
$string = stripslashes($string); |
46
|
|
|
|
47
|
|
|
return $string; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param $var |
52
|
|
|
* |
53
|
|
|
* @return array|string |
54
|
|
|
*/ |
55
|
|
View Code Duplication |
function prepOut(&$var) |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
if (is_array($var)) { |
58
|
|
|
foreach ($var as $i => $v) { |
59
|
|
|
$var[$i] = prepOut($v); |
60
|
|
|
} |
61
|
|
|
} else { |
62
|
|
|
if (is_string($var)) { |
63
|
|
|
$var = htmlspecialchars($var); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $var; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param $name |
72
|
|
|
* @param string $domain |
73
|
|
|
* @param null $language |
74
|
|
|
*/ |
75
|
|
View Code Duplication |
function loadLanguage($name, $domain = '', $language = null) |
76
|
|
|
{ |
77
|
|
|
global $xoopsConfig; |
78
|
|
|
if (!@include_once XOOPS_ROOT_PATH . "/modules/{$domain}/language/" . $xoopsConfig['language'] . "/{$name}.php") { |
79
|
|
|
include_once XOOPS_ROOT_PATH . "/modules/{$domain}/language/english/{$name}.php"; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
// Access module configs from outside module: |
84
|
|
|
$moduleHelper = Xmf\Module\Helper::getHelper($dir); |
85
|
|
|
|
86
|
|
|
loadLanguage('main', $dir); |
87
|
|
|
loadLanguage('modinfo', $dir); |
88
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/' . $dir . '/class/GwikiPage.php'; |
89
|
|
|
|
90
|
|
|
$wikiPage = new GwikiPage; |
91
|
|
|
$wikiPage->setRecentCount($moduleHelper->getConfig('number_recent', 10)); |
92
|
|
|
$wikiPage->setWikiLinkURL($ourWikiLinkURL); |
93
|
|
|
|
94
|
|
|
if (empty($page)) { |
95
|
|
|
$page = $wikiPage->wikiHomePage; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
// if we get a naked or external prefix, try and do something useful |
99
|
|
|
$pfx = $wikiPage->getPrefix($page); |
100
|
|
View Code Duplication |
if ($pfx && $pfx['defined']) { |
101
|
|
|
$page = $pfx['actual_page']; |
102
|
|
|
if ($pfx['prefix_is_external']) { |
103
|
|
|
header("Location: {$pfx['actual_page']}"); |
104
|
|
|
exit; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$pageX = $wikiPage->getPage($page); |
109
|
|
|
$attachments = $wikiPage->getAttachments($page); |
110
|
|
|
$mayEdit = $wikiPage->checkEdit(); |
111
|
|
|
|
112
|
|
|
if ($pageX) { |
113
|
|
|
$pageX['body'] = $wikiPage->renderPage($wikiPage->body); |
114
|
|
|
$pageX['author'] = $wikiPage->getUserName($wikiPage->uid); |
115
|
|
|
$pageX['revisiontime'] = date($wikiPage->dateFormat, $pageX['lastmodified']); |
116
|
|
|
$pageX['mayEdit'] = $mayEdit; |
117
|
|
|
$pageX['pageFound'] = true; |
118
|
|
|
if (!empty($highlight)) { |
119
|
|
|
$pageX['body'] = $wikiPage->highlightWords($highlight); |
120
|
|
|
} |
121
|
|
|
} else { |
122
|
|
|
$pageX = array(); |
123
|
|
|
$pageX['keyword'] = $page; |
124
|
|
|
$pageX['title'] = _MD_GWIKI_NOEDIT_NOTFOUND_TITLE; |
125
|
|
|
$pageX['body'] = _MD_GWIKI_NOEDIT_NOTFOUND_BODY; |
126
|
|
|
$pageX['author'] = ''; |
127
|
|
|
$pageX['revisiontime'] = ''; |
128
|
|
|
$pageX['mayEdit'] = $mayEdit; |
129
|
|
|
$pageX['pageFound'] = false; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
$pageX['moddir'] = $dir; |
133
|
|
|
$pageX['modpath'] = XOOPS_ROOT_PATH . '/modules/' . $dir; |
134
|
|
|
$pageX['modurl'] = XOOPS_URL . '/modules/' . $dir; |
135
|
|
|
if (!empty($attachments)) { |
136
|
|
|
$pageX['attachments'] = prepOut($attachments); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$GLOBALS['xoopsOption']['template_main'] = $wikiPage->getTemplateName(); // 'gwiki_view.tpl'; |
140
|
|
|
include XOOPS_ROOT_PATH . '/header.php'; |
141
|
|
|
|
142
|
|
|
$pageX['title'] = prepOut($pageX['title']); |
143
|
|
|
$xoopsTpl->assign('gwiki', $pageX); |
144
|
|
|
|
145
|
|
|
$xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $dir . '/assets/css/module.css'); |
146
|
|
View Code Duplication |
if ($pageX['pageFound']) { |
147
|
|
|
$xoTheme->addMeta('meta', 'keywords', htmlspecialchars($pageX['meta_keywords'], ENT_QUOTES, null, false)); |
148
|
|
|
$xoTheme->addMeta('meta', 'description', htmlspecialchars($pageX['meta_description'], ENT_QUOTES, null, false)); |
149
|
|
|
} |
150
|
|
|
$title = $pageX['title']; |
151
|
|
|
$xoopsTpl->assign('xoops_pagetitle', $title); |
152
|
|
|
|
153
|
|
|
include XOOPS_ROOT_PATH . '/footer.php'; |
154
|
|
|
|
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.