Passed
Push — master ( 3a2152...658ebb )
by Goffy
04:30 queued 12s
created
Severity
1
<?php
2
/**
3
 * Module: Lexikon - glossary module
4
 * Author: hsalazar
5
 * Licence: GNU
6
 */
7
8
use Xmf\Request;
9
use XoopsModules\Lexikon\{
10
    Helper,
11
    Keyhighlighter,
12
    Utility
13
};
14
/** @var Helper $helper */
15
16
$GLOBALS['xoopsOption']['template_main'] = 'lx_entry.tpl';
17
18
require __DIR__ . '/header.php';
19
require_once XOOPS_ROOT_PATH . '/header.php';
20
global $xoTheme, $xoopsUser, $lexikon_module_header;
21
$myts = \MyTextSanitizer::getInstance();
22
xoops_load('XoopsUserUtility');
23
24
$helper = Helper::getInstance();
25
26
require_once XOOPS_ROOT_PATH . '/modules/lexikon/include/common.inc.php';
27
$highlight = $utility::getModuleOption('config_highlighter');
28
if ($highlight) {
29
    require_once XOOPS_ROOT_PATH . '/modules/lexikon/class/keyhighlighter.class.php';
30
}
31
32
$entryID = Request::getInt('entryID', 0, 'GET');
33
if (empty($entryID)) {
34
    redirect_header('index.php', 3, _MD_LEXIKON_UNKNOWNERROR);
35
}
36
$entrytype = 1;
37
// permissions
38
/** @var \XoopsGroupPermHandler $grouppermHandler */
39
$grouppermHandler = xoops_getHandler('groupperm');
40
$groups           = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
41
$module_id        = $xoopsModule->getVar('mid');
42
$allowed_cats     = $grouppermHandler->getItemIds('lexikon_view', $groups, $module_id);
43
$catids           = implode(',', $allowed_cats);
44
$catperms         = " AND categoryID IN ($catids) ";
45
46
// If there's no entries yet in the system...
47
$publishedwords = $utility::countWords();
48
$xoopsTpl->assign('publishedwords', $publishedwords);
49
if (0 == $publishedwords) {
50
    $xoopsTpl->assign('empty', '1');
51
    $xoopsTpl->assign('stillnothing', _MD_LEXIKON_STILLNOTHINGHERE);
52
}
53
54
// To display the linked letter list
55
$alpha = $utility::getAlphaArray();
56
$xoopsTpl->assign('alpha', $alpha);
57
58
[$howmanyother] = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(entryID) FROM ' . $xoopsDB->prefix('lxentries') . " WHERE init = '#' AND offline ='0' " . $catperms . ' '));
59
$xoopsTpl->assign('totalother', $howmanyother);
60
61
$xoopsTpl->assign('multicats', (int)$helper->getConfig('multicats'));
62
// To display the list of categories
63
if (1 == $helper->getConfig('multicats')) {
64
    $xoopsTpl->assign('block0', $utility::getCategoryArray());
65
    $xoopsTpl->assign('layout', CONFIG_CATEGORY_LAYOUT_PLAIN);
66
    if (1 == $helper->getConfig('useshots')) {
67
        $xoopsTpl->assign('show_screenshot', true);
68
        $xoopsTpl->assign('logo_maximgwidth', $helper->getConfig('logo_maximgwidth'));
69
        $xoopsTpl->assign('lang_noscreenshot', _MD_LEXIKON_NOSHOTS);
70
    } else {
71
        $xoopsTpl->assign('show_screenshot', false);
72
    }
73
}
74
75
if (!$entryID) {
76
    redirect_header('<script>javascript:history.go(-1)</script>', 2, _MD_LEXIKON_UNKNOWNERROR);
77
} else {
78
    if ($entryID <= 0) {
79
        redirect_header('<script>javascript:history.go(-1)</script>', 2, _MD_LEXIKON_UNKNOWNERROR);
80
    }
81
    if (!$xoopsUser || ($xoopsUser->isAdmin($xoopsModule->mid()) && 1 == $helper->getConfig('adminhits'))
82
        || ($xoopsUser
83
            && !$xoopsUser->isAdmin($xoopsModule->mid()))) {
84
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('lxentries') . " SET counter = counter+1 WHERE entryID = $entryID ");
85
    }
86
87
    $result = $xoopsDB->query(
88
        'SELECT entryID, categoryID, term, init, definition, ref, url, uid, submit, datesub, counter, html, smiley, xcodes, breaks, block, offline, notifypub
89
                                 FROM ' . $xoopsDB->prefix('lxentries') . "
90
                                 WHERE entryID = $entryID"
91
    );
92
    // verify result
93
    if ($xoopsDB->getRowsNum($result) <= 0) {
94
        redirect_header('index.php', 2, _MD_LEXIKON_UNKNOWNERROR);
95
    }
96
}
97
98
while (list($entryID, $categoryID, $term, $init, $definition, $ref, $url, $uid, $submit, $datesub, $counter, $html, $smiley, $xcodes, $breaks, $block, $offline) = $xoopsDB->fetchRow($result)) {
99
    $catID = (int)$categoryID;
100
    if (!$grouppermHandler->checkRight('lexikon_view', (int)$categoryID, $groups, $module_id)) {
101
        redirect_header('index.php', 3, _NOPERM);
102
    }
103
104
    $thisterm            = [];
105
    $xoopsModule         = XoopsModule::getByDirname('lexikon');
106
    $thisterm['id']      = (int)$entryID;
107
    $thisterm['offline'] = (int)$offline;
108
    // exit if offline - except admin
109
    if (1 == $thisterm['offline'] && !$xoopsUserIsAdmin) {
110
        redirect_header('<script>javascript:history.go(-1)</script>', 3, _MD_LEXIKON_ENTRYISOFF);
111
    }
112
    if (1 == $helper->getConfig('multicats')) {
113
        $thisterm['categoryID'] = (int)$categoryID;
114
        $catname                = $xoopsDB->query('SELECT name FROM ' . $xoopsDB->prefix('lxcategories') . " WHERE categoryID = $categoryID ");
115
        while (list($name) = $xoopsDB->fetchRow($catname)) {
116
            $thisterm['catname'] = htmlspecialchars($name, ENT_QUOTES | ENT_HTML5);
117
        }
118
    }
119
120
    $glossaryterm     = htmlspecialchars($term, ENT_QUOTES | ENT_HTML5);
121
    $thisterm['term'] = ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5));
122
    if ('#' === $init) {
123
        $thisterm['init'] = _MD_LEXIKON_OTHER;
124
    } else {
125
        $thisterm['init'] = ucfirst($init);
126
    }
127
    $thisterm['offline'] = (int)$offline;
128
129
    if (1 != $helper->getConfig('linkterms') && 2 != $helper->getConfig('linkterms')) {
130
        $utility::getModuleHeader();
131
        $xoopsTpl->assign('xoops_module_header', $lexikon_module_header);
132
    } else {
133
        $xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" type="text/css" href="assets/css/style.css">');
134
    }
135
136
    if (1 != $helper->getConfig('linkterms')) {
137
        // Code to make links out of glossary terms
138
        $parts = explode('>', $definition);
139
140
        // First, retrieve all terms from the glossary...
141
        $allterms = $xoopsDB->query('SELECT entryID, term, definition FROM ' . $xoopsDB->prefix('lxentries') . " WHERE offline ='0' " . $catperms . ' ');
142
143
        while (list($entryID, $term, $definition) = $xoopsDB->fetchRow($allterms)) {
144
            foreach ($parts as $key => $part) {
145
                if ($term != $glossaryterm) {
146
                    $term_q      = preg_quote($term, '/');
147
                    $search_term = "/\b$term_q\b/SsUi";
148
                    //static link
149
                    $staticURL = '' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/entry.php?entryID=' . ucfirst($entryID) . '';
150
                    switch ($helper->getConfig('linkterms')) {
151
                        default:
152
                            $replace_term = '<span><b><a style="cursor:help;border-bottom: 1px dotted #000;color: #2F5376;" href="' . $staticURL . '" >' . $term . '</a></b></span>';
153
                            break;
154
                        case 3: //tooltip
155
                            $tooltipdef   = htmlspecialchars(xoops_substr(strip_tags($definition), 0, 150), ENT_QUOTES | ENT_HTML5);
156
                            $replace_term = '<a class="parser" href="' . $staticURL . '" onMouseover="ddrivetip(\'' . $tooltipdef . '\', 300)"; onMouseout=\'hideddrivetip()\'>' . $term . '</a>';
157
                            break;
158
                        case 4://simple popup
159
                            $replace_term = '<a style="cursor:help;border-bottom: 1px dotted #000;color: #2F5376;" href="#" onClick=\'popup("popup.php?entryID=' . $entryID . '","details", 420, 350); return false\'>' . $term . '</a>';
160
                            break;
161
                        case 5:// balloon tooltip
162
                            $tooltipdef   = htmlspecialchars(xoops_substr(strip_tags($definition), 0, 150), ENT_QUOTES | ENT_HTML5);
163
                            $replace_term = '<a class="parser" href="' . $staticURL . '" onMouseover="showToolTip(event,\'' . $tooltipdef . '\');return false"; onMouseout=\'hideToolTip()\'>' . $term . '</a>';
164
                            break;
165
                        case 6:// shadow tooltip
166
                            $tooltipdef   = htmlspecialchars(xoops_substr(strip_tags($definition), 0, 150), ENT_QUOTES | ENT_HTML5);
167
                            $replace_term = '<a class="parser" href="' . $staticURL . '" onmouseout="hideTooltip()" onmouseover="showTooltip(event,\'' . $tooltipdef . '\')"; >' . $term . '</a>';
168
                            break;
169
                    }
170
                    $parts[$key] = preg_replace($search_term, $replace_term, $parts[$key]);
171
                }
172
            }
173
        }
174
        $definition = implode('>', $parts);
175
    }
176
    $thisterm['definition'] = $myts->displayTarea($definition, $html, $smiley, $xcodes, 1, $breaks);
177
    $thisterm['ref']        = $myts->displayTarea($ref, $html, $smiley, $xcodes, 1, $breaks);
178
    $thisterm['url']        = $myts->makeClickable($url, $allowimage = 0);
0 ignored issues
show
The call to MyTextSanitizer::makeClickable() has too many arguments starting with $allowimage = 0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

178
    /** @scrutinizer ignore-call */ 
179
    $thisterm['url']        = $myts->makeClickable($url, $allowimage = 0);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
179
    //$thisterm['submitter'] = XoopsUserUtility::getUnameFromId ( $uid );
180
    if (1 == $helper->getConfig('showsubmitter')) {
181
        $xoopsTpl->assign('showsubmitter', true);
182
        if (1 == $helper->getConfig('authorprofile')) {
183
            $thisterm['submitter'] = $utility::getLinkedProfileFromId($uid);
184
        } else {
185
            $thisterm['submitter'] = \XoopsUserUtility::getUnameFromId($uid);
186
        }
187
    } else {
188
        $xoopsTpl->assign('showsubmitter', false);
189
    }
190
    $thisterm['submit']  = (int)$submit;
191
    $thisterm['datesub'] = formatTimestamp($datesub, $helper->getConfig('dateformat'));
192
    $thisterm['counter'] = (int)$counter;
193
    $thisterm['block']   = (int)$block;
194
    $thisterm['dir']     = $xoopsModule->dirname();
195
    if ($highlight && isset($_GET['keywords'])) {
196
        $keywords               = htmlspecialchars(trim(urldecode($_GET['keywords'])), ENT_QUOTES | ENT_HTML5);
197
        $h                      = new Keyhighlighter($keywords, true, 'lx_myhighlighter');
198
        $thisterm['definition'] = $h->highlight($thisterm['definition']);
199
        $thisterm['ref']        = $h->highlight($thisterm['ref']);
200
    }
201
}
202
//smartry strings
203
$xoopsTpl->assign('thisterm', $thisterm);
204
$microlinks    = $utility::getServiceLinks($thisterm);
205
$microlinksnew = $utility::getServiceLinksNew($thisterm);
206
$xoopsTpl->assign('microlinks', $microlinks);
207
$xoopsTpl->assign('microlinksnew', $microlinksnew);
208
$xoopsTpl->assign('lang_modulename', $xoopsModule->name());
209
$xoopsTpl->assign('lang_moduledirname', $xoopsModule->getVar('dirname'));
210
$xoopsTpl->assign('entryID', $entryID);
211
$xoopsTpl->assign('submittedon', sprintf(_MD_LEXIKON_SUBMITTEDON, $thisterm['datesub']));
212
if (1 == $helper->getConfig('showsubmitter')) {
213
    $xoopsTpl->assign('submitter', sprintf(_MD_LEXIKON_SUBMITTEDBY, $thisterm['submitter']));
214
}
215
$xoopsTpl->assign('counter', sprintf(_MD_LEXIKON_COUNT, $thisterm['counter']));
216
$xoopsTpl->assign('entrytype', '1');
217
218
// --- keywordshighligher ---
219
/**
220
 * @param $matches
221
 * @return string
222
 */
223
function lx_myhighlighter($matches)
224
{
225
    return '<span style="font-weight: bolder; background-color: #FFFF80;">' . $matches[0] . '</span>';
226
}
227
228
229
//--- Display tags of this term
230
$tagsmeta = '';
231
#$itemid = $entryID;
232
/** @var \XoopsModuleHandler $moduleHandler */
233
//$moduleHandler = xoops_getHandler('module');
234
//$tagsModule    = $moduleHandler->getByDirname('tag');
235
//if (is_object($tagsModule)) {
236
//    require_once XOOPS_ROOT_PATH . '/modules/tag/include/tagbar.php';
237
//
238
//    $itemid = Request::getInt('entryID', 0, 'GET');
239
//    $catid  = 0;
240
//    //$xoopsTpl->assign('tagbar', tagBar($itemid, $catid = 0));
241
//    $tagbar = tagBar($itemid, $catid);
242
//    if ($tagbar) {
243
//        $xoopsTpl->assign('tagbar', $tagbar);
244
//        $tagsmeta = implode(' ', $tagbar['tags']);
245
//    } else {
246
//        $tagsmeta = '';
247
//    }
248
//} else {
249
//    $xoopsTpl->assign('tagbar', false);
250
//    $tagsmeta = '';
251
//}
252
253
//--- linkterms assigns
254
// Balloontips
255
if (5 == $helper->getConfig('linkterms')) {
256
    $xoopsTpl->assign('balloontips', true);
257
} else {
258
    $xoopsTpl->assign('balloontips', false);
259
}
260
261
// Show Bookmark icons ?
262
switch ($helper->getConfig('bookmarkme')) {
263
    case '0':
264
    default:
265
        $xoopsTpl->assign('bookmarkme', false);
266
        break;
267
    case '1':
268
        $xoopsTpl->assign('bookmarkme', 1);
269
        $xoopsTpl->assign('encoded_title', rawurlencode($thisterm['term']));
270
        break;
271
    case '2':
272
        $xoopsTpl->assign('bookmarkme', 2);
273
        break;
274
    case '3':
275
        $xoopsTpl->assign('bookmarkme', 3);
276
        break;
277
}
278
// Meta data
279
$meta_description = xoops_substr($utility::convertHtml2text($thisterm['definition']), 0, 150);
280
if (1 == $helper->getConfig('multicats')) {
281
    $utility::createPageTitle($thisterm['term'] . ' - ' . $thisterm['catname']);
282
    $utility::extractKeywords(htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5) . ' ,' . $thisterm['term'] . ' ,' . $thisterm['catname'] . ', ' . $meta_description . ', ' . $tagsmeta);
283
    $utility::getMetaDescription(htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5) . ' ' . $thisterm['catname'] . ' ' . $thisterm['term'] . ' ' . $meta_description);
284
} else {
285
    $utility::createPageTitle($thisterm['term']);
286
    $utility::extractKeywords(htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5) . ' ,' . $thisterm['term'] . ', ' . $meta_description . ', ' . $tagsmeta);
287
    $utility::getMetaDescription(htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5) . ' ' . $thisterm['term'] . ' ' . $meta_description);
288
}
289
//Mondarse
290
require XOOPS_ROOT_PATH . '/include/comment_view.php';
291
//Mondarse
292
require_once XOOPS_ROOT_PATH . '/footer.php';
293