Completed
Push — master ( 122be0...67bca0 )
by Michael
02:40
created

index.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * index.php - display wiki 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
global $xoTheme, $xoopsTpl;
13
global $wikiPage;
14
15
// this exists to make xoops comments work
16
// index.php?page_id=15&com_mode=thread&com_order=0&com_id=2&com_rootid=1
17
if (isset($_GET['page_id']) && !isset($_GET['page'])) {
18
    $page_id = $_GET['page_id'];
19
    $page    = $wikiPage->getKeywordById($page_id);
20
    if (!empty($page)) {
21
        $extra = '';
22
        if (isset($_GET['com_mode'])) {
23
            $extra .= '&com_mode=' . $_GET['com_mode'];
24
        }
25
        if (isset($_GET['com_order'])) {
26
            $extra .= '&com_order=' . $_GET['com_order'];
27
        }
28
        if (isset($_GET['com_id'])) {
29
            $extra .= '&com_id=' . $_GET['com_id'];
30
        }
31
        if (isset($_GET['com_rootid'])) {
32
            $extra .= '&com_rootid=' . $_GET['com_rootid'];
33
        }
34
        $header = sprintf($xoopsModuleConfig['wikilink_template'], $page) . $extra;
35
        header("Location: {$header}");
36
        exit;
37
    }
38
}
39
// $_GET variables we use
40
$page      = $wikiPage->normalizeKeyword(isset($_GET['page']) ? cleaner($_GET['page']) : $wikiPage->wikiHomePage);
41
$highlight = isset($_GET['query']) ? cleaner($_GET['query']) : null;
42
43
// if we get a naked or external prefix, try and do something useful
44
$pfx = $wikiPage->getPrefix($page);
45 View Code Duplication
if ($pfx && $pfx['defined']) {
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
46
    $page = $pfx['actual_page'];
47
    if ($pfx['prefix_is_external']) {
48
        header("Location: {$pfx['actual_page']}");
49
        exit;
50
    }
51
}
52
53
global $wikiPage;
54
$pageX       = $wikiPage->getPage($page);
55
$attachments = $wikiPage->getAttachments($page);
56
$wikiPage->registerHit($page);
57
$mayEdit = $wikiPage->checkEdit();
58
59
if ($pageX) {
60
    $pageX['body']      = $wikiPage->renderPage($wikiPage->body);
61
    $pageX['mayEdit']   = $mayEdit;
62
    $pageX['pageFound'] = true;
63
    if (!empty($highlight)) {
64
        $pageX['body'] = $wikiPage->highlightWords($highlight);
65
    }
66
} else {
67
    $dir = $wikiPage->getWikiDir();
68
    if ($mayEdit) {
69
        redirect_header(XOOPS_URL . "/modules/{$dir}/edit.php?page={$page}", 2, _MD_GWIKI_PAGENOTFOUND);
70
    }
71
    $pageX                 = array();
72
    $pageX['keyword']      = $page;
73
    $pageX['title']        = _MD_GWIKI_NOEDIT_NOTFOUND_TITLE;
74
    $pageX['body']         = _MD_GWIKI_NOEDIT_NOTFOUND_BODY;
75
    $pageX['author']       = '';
76
    $pageX['revisiontime'] = '';
77
    $pageX['createdtime']  = '';
78
    $pageX['mayEdit']      = $mayEdit;
79
    $pageX['pageFound']    = false;
80
}
81
82
$dir              = basename(__DIR__);
83
$pageX['moddir']  = $dir;
84
$pageX['modpath'] = XOOPS_ROOT_PATH . '/modules/' . $dir;
85
$pageX['modurl']  = XOOPS_URL . '/modules/' . $dir;
86
if (!empty($attachments)) {
87
    $pageX['attachments'] = prepOut($attachments);
88
}
89
90
$_GET['page_id'] = $wikiPage->page_id;
91
$_GET['nsid']    = $wikiPage->currentprefixid;
92
93
$xoopsOption['template_main'] = $wikiPage->getTemplateName(); // 'gwiki_view.tpl';
94
include XOOPS_ROOT_PATH . '/header.php';
95
96
$pageX['title'] = prepOut($pageX['title']);
97
$xoopsTpl->assign('gwiki', $pageX);
98
99
//echo '<pre>';print_r($pageX);echo '</pre>';
100
101
$xoTheme->addStylesheet(XOOPS_URL . '/modules/gwiki/assets/css/module.css');
102 View Code Duplication
if ($pageX['pageFound']) {
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
103
    $xoTheme->addMeta('meta', 'keywords', htmlspecialchars($pageX['meta_keywords'], ENT_QUOTES, null, false));
104
    $xoTheme->addMeta('meta', 'description', htmlspecialchars($pageX['meta_description'], ENT_QUOTES, null, false));
105
}
106
$title = $pageX['title'];
107
if (empty($title)) {
108
    $title = htmlspecialchars($xoopsModule->name());
109
}
110
$xoopsTpl->assign('xoops_pagetitle', $title);
111
if (!empty($message)) {
112
    $xoopsTpl->assign('message', $message);
113
}
114
if (!empty($err_message)) {
115
    $xoopsTpl->assign('err_message', $err_message);
116
}
117
118
include XOOPS_ROOT_PATH . '/include/comment_view.php';
119
120
include XOOPS_ROOT_PATH . '/footer.php';
121