Completed
Push — master ( 7e38e2...812d3d )
by Michael
02:25
created

ajaxgwiki.php (1 issue)

Severity

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
 * ajaxwiki.php - serve wiki page via ajax
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__ . '/../../mainfile.php';
12
$xoopsLogger->activated = false;
13
// provide error logging for our sanity in debugging ajax use (won't see xoops logger)
14
//restore_error_handler();
15
//error_reporting(-1);
16
17
/**
18
 * @param $string
19
 *
20
 * @return string
21
 */
22 View Code Duplication
function cleaner($string)
0 ignored issues
show
The function cleaner() has been defined more than once; this definition is ignored, only the first definition in admin/prefixes.php (L601-612) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
23
{
24
    $string = stripcslashes($string);
25
    $string = html_entity_decode($string);
26
    $string = strip_tags($string); // DANGER -- kills wiki text
27
    $string = trim($string);
28
    $string = stripslashes($string);
29
30
    return $string;
31
}
32
33
// $_GET variables we use
34
unset($page, $bid, $id);
35
$page = isset($_GET['page']) ? cleaner($_GET['page']) : null;
36
37
// strip rid of any anchor references
38
//$x=strpos($page,'#');
39
//if($x!==false) $page=substr($page,0,$x);
40
//trigger_error($page);
41
42
if (isset($_GET['bid'])) {
43
    $bid = (int)$_GET['bid'];
44
} // from a block
45
if (isset($_GET['id'])) {
46
    $id = (int)$_GET['id'];
47
}    // from utility (i.e. history)
48
49
$dir = basename(__DIR__);
50
// Access module configs from block:
51
/** @var XoopsModuleHandler $moduleHandler */
52
$moduleHandler = xoops_getHandler('module');
53
$module        = $moduleHandler->getByDirname($dir);
54
$configHandler = xoops_getHandler('config');
55
$moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
56
57
$alloworigin = $moduleConfig['allow_origin'];
58
if (!empty($alloworigin)) {
59
    header('Access-Control-Allow-Origin: ' . $alloworigin);
60
}
61
62
include_once XOOPS_ROOT_PATH . '/modules/' . $dir . '/class/gwikiPage.php';
63
$imgdir = XOOPS_URL . '/modules/' . $dir . '/images';
64
65
$wikiPage = new GwikiPage;
66
$wikiPage->setRecentCount($moduleConfig['number_recent']);
67
68
if (empty($page)) {
69
    $page = $wikiPage->wikiHomePage;
70
}
71
$page = $wikiPage->normalizeKeyword($page);
72
73
if (isset($id)) {
74
    $wikiPage->setWikiLinkURL("javascript:alert('%s');");
75
    $wikiPage->setTocFormat('toc' . $id . '-', '#%s');
76
}
77
if (isset($bid)) {
78
    $wikiPage->setWikiLinkURL("javascript:ajaxGwikiLoad('%s','{$bid}');");
79
    $wikiPage->setTocFormat('toc' . $bid . '-', '#%s');
80
}
81
if (isset($id)) {
82
    $thispage = $wikiPage->getPage($page, $id);
83
} else {
84
    $thispage = $wikiPage->getPage($page);
85
}
86
if ($thispage) {
87 View Code Duplication
    if (!defined('_MI_GWIKI_NAME')) {
88
        $langfile = XOOPS_ROOT_PATH . '/modules/' . $dir . '/language/' . $xoopsConfig['language'] . '/modinfo.php';
89
        if (!file_exists($langfile)) {
90
            $langfile = XOOPS_ROOT_PATH . '/modules/' . $dir . '/language/english/modinfo.php';
91
        }
92
        include_once $langfile;
93
    }
94
95
    $rendered = '<h1 class="wikititle">' . htmlspecialchars($wikiPage->title) . '</h1>';
96
    $rendered .= $wikiPage->renderPage();
97
    if (!empty($thispage['pageset']['first']['link'])) {
98
        $rendered .= '<div class="wikipagesetnav">';
99
        $rendered .= '<a href="' . $thispage['pageset']['first']['link'] . '"><img src="' . $imgdir . '/psfirst.png" alt="' . $thispage['pageset']['first']['desc'] . '" title="'
100
                     . $thispage['pageset']['first']['text'] . '" /></a>';
101
        $rendered .= '<a href="' . $thispage['pageset']['prev']['link'] . '"><img src="' . $imgdir . '/psprev.png" alt="' . $thispage['pageset']['prev']['desc'] . '" title="'
102
                     . $thispage['pageset']['prev']['text'] . '" /></a>';
103
        $rendered .= '<a href="' . $thispage['pageset']['home']['link'] . '"><img src="' . $imgdir . '/pshome.png" alt="' . $thispage['pageset']['home']['desc'] . '" title="'
104
                     . $thispage['pageset']['home']['text'] . '" /></a>';
105
        $rendered .= '<a href="' . $thispage['pageset']['next']['link'] . '"><img src="' . $imgdir . '/psnext.png" alt="' . $thispage['pageset']['next']['desc'] . '" title="'
106
                     . $thispage['pageset']['next']['text'] . '" /></a>';
107
        $rendered .= '<a href="' . $thispage['pageset']['last']['link'] . '"><img src="' . $imgdir . '/pslast.png" alt="' . $thispage['pageset']['last']['desc'] . '" title="'
108
                     . $thispage['pageset']['last']['text'] . '" /></a>';
109
        $rendered .= '</div>';
110
    }
111
112
    if (!isset($id)) {
113
        $wikiPage->registerHit($page);
114
    } // don't count hits from utilities
115
} else {
116
    //if ($mayEdit) redirect_header("edit.php?page=$page", 2, _MD_GWIKI_PAGENOTFOUND);
117
    $rendered = '<h1 class="wikititle">' . _MD_GWIKI_NOEDIT_NOTFOUND_TITLE . '</h1>';
118
    $rendered .= _MD_GWIKI_NOEDIT_NOTFOUND_BODY;
119
}
120
echo $rendered;
121
exit;
122