Completed
Pull Request — master (#12)
by
unknown
01:54
created

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 252 and the first side effect is on line 8.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Module: Lexikon - glossary module
4
 * Author: hsalazar
5
 * Licence: GNU
6
 */
7
8
include __DIR__ . '/header.php';
9
$GLOBALS['xoopsOption']['template_main'] = 'lx_entry.tpl';
10
include_once XOOPS_ROOT_PATH . '/header.php';
11
global $xoTheme, $xoopsUser, $lexikon_module_header;
12
$myts = MyTextSanitizer::getInstance();
13
xoops_load('XoopsUserUtility');
14
15
include_once XOOPS_ROOT_PATH . '/modules/lexikon/include/common.inc.php';
16
$highlight = LexikonUtility::getModuleOption('config_highlighter');
17
if ($highlight) {
18
    include_once XOOPS_ROOT_PATH . '/modules/lexikon/class/keyhighlighter.class.php';
19
}
20
21
$entryID = isset($_GET['entryID']) ? (int)$_GET['entryID'] : 0;
22
if (empty($entryID)) {
23
    redirect_header('index.php', 3, _MD_LEXIKON_UNKNOWNERROR);
24
}
25
$entrytype = 1;
26
// permissions
27
$gpermHandler = xoops_getHandler('groupperm');
28
$groups       = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
29
$module_id    = $xoopsModule->getVar('mid');
30
$allowed_cats = $gpermHandler->getItemIds('lexikon_view', $groups, $module_id);
31
$catids       = implode(',', $allowed_cats);
32
$catperms     = " AND categoryID IN ($catids) ";
33
34
// If there's no entries yet in the system...
35
$publishedwords = LexikonUtility::countWords();
36
$xoopsTpl->assign('publishedwords', $publishedwords);
37
if ($publishedwords == 0) {
38
    $xoopsTpl->assign('empty', '1');
39
    $xoopsTpl->assign('stillnothing', _MD_LEXIKON_STILLNOTHINGHERE);
40
}
41
42
// To display the linked letter list
43
$alpha = LexikonUtility::getAlphaArray();
44
$xoopsTpl->assign('alpha', $alpha);
45
46
list($howmanyother) = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(entryID) FROM '
47
                                                          . $xoopsDB->prefix('lxentries')
48
                                                          . " WHERE init = '#' AND offline ='0' "
49
                                                          . $catperms
50
                                                          . ' '));
51
$xoopsTpl->assign('totalother', $howmanyother);
52
53
$xoopsTpl->assign('multicats', (int)$xoopsModuleConfig['multicats']);
54
// To display the list of categories
55 View Code Duplication
if ($xoopsModuleConfig['multicats'] == 1) {
56
    $xoopsTpl->assign('block0', LexikonUtility::getCategoryArray());
57
    $xoopsTpl->assign('layout', CONFIG_CATEGORY_LAYOUT_PLAIN);
58
    if ($xoopsModuleConfig['useshots'] == 1) {
59
        $xoopsTpl->assign('show_screenshot', true);
60
        $xoopsTpl->assign('logo_maximgwidth', $xoopsModuleConfig['logo_maximgwidth']);
61
        $xoopsTpl->assign('lang_noscreenshot', _MD_LEXIKON_NOSHOTS);
62
    } else {
63
        $xoopsTpl->assign('show_screenshot', false);
64
    }
65
}
66
67
if (!$entryID) {
68
    redirect_header('javascript:history.go(-1)', 2, _MD_LEXIKON_UNKNOWNERROR);
69
} else {
70
    if ($entryID <= 0) {
71
        redirect_header('javascript:history.go(-1)', 2, _MD_LEXIKON_UNKNOWNERROR);
72
    }
73
    if (!$xoopsUser || ($xoopsUser->isAdmin($xoopsModule->mid()) && $xoopsModuleConfig['adminhits'] == 1)
74
        || ($xoopsUser
75
            && !$xoopsUser->isAdmin($xoopsModule->mid()))
76
    ) {
77
        $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('lxentries') . " SET counter = counter+1 WHERE entryID = $entryID ");
78
    }
79
80
    $result = $xoopsDB->query('SELECT entryID, categoryID, term, init, definition, ref, url, uid, submit, datesub, counter, html, smiley, xcodes, breaks, block, offline, notifypub
81
                                 FROM ' . $xoopsDB->prefix('lxentries') . "
82
                                 WHERE entryID = $entryID");
83
    // verify result
84
    if ($xoopsDB->getRowsNum($result) <= 0) {
85
        redirect_header('index.php', 2, _MD_LEXIKON_UNKNOWNERROR);
86
    }
87
}
88
89
while (list($entryID, $categoryID, $term, $init, $definition, $ref, $url, $uid, $submit, $datesub, $counter, $html, $smiley, $xcodes, $breaks, $block, $offline) = $xoopsDB->fetchRow($result)) {
90
    $catID = (int)$categoryID;
91
    if (!$gpermHandler->checkRight('lexikon_view', (int)$categoryID, $groups, $module_id)) {
92
        redirect_header('index.php', 3, _NOPERM);
93
    }
94
95
    $thisterm            = [];
96
    $xoopsModule         = XoopsModule::getByDirname('lexikon');
97
    $thisterm['id']      = (int)$entryID;
98
    $thisterm['offline'] = (int)$offline;
99
    // exit if offline - except admin
100
    if ($thisterm['offline'] == 1 && !$xoopsUserIsAdmin) {
101
        redirect_header('javascript:history.go(-1)', 3, _MD_LEXIKON_ENTRYISOFF);
102
    }
103 View Code Duplication
    if ($xoopsModuleConfig['multicats'] == 1) {
104
        $thisterm['categoryID'] = (int)$categoryID;
105
        $catname                = $xoopsDB->query('SELECT name FROM '
106
                                                  . $xoopsDB->prefix('lxcategories')
107
                                                  . " WHERE categoryID = $categoryID ");
108
        while (list($name) = $xoopsDB->fetchRow($catname)) {
109
            $thisterm['catname'] = $myts->htmlSpecialChars($name);
110
        }
111
    }
112
113
    $glossaryterm     = $myts->htmlSpecialChars($term);
114
    $thisterm['term'] = ucfirst($myts->htmlSpecialChars($term));
115
    if ($init === '#') {
116
        $thisterm['init'] = _MD_LEXIKON_OTHER;
117
    } else {
118
        $thisterm['init'] = ucfirst($init);
119
    }
120
    $thisterm['offline'] = (int)$offline;
121
122
    if ($xoopsModuleConfig['linkterms'] != 1 && $xoopsModuleConfig['linkterms'] != 2) {
123
        LexikonUtility::getModuleHeader();
124
        $xoopsTpl->assign('xoops_module_header', $lexikon_module_header);
125
    } else {
126
        $xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" type="text/css" href="assets/css/style.css" />');
127
    }
128
129
    if ($xoopsModuleConfig['linkterms'] != 1) {
130
        // Code to make links out of glossary terms
131
        $parts = explode('>', $definition);
132
133
        // First, retrieve all terms from the glossary...
134
        $allterms = $xoopsDB->query('SELECT entryID, term, definition FROM '
135
                                    . $xoopsDB->prefix('lxentries')
136
                                    . " WHERE offline ='0' "
137
                                    . $catperms
138
                                    . ' ');
139
140
        while (list($entryID, $term, $definition) = $xoopsDB->fetchrow($allterms)) {
141
            foreach ($parts as $key => $part) {
142
                if ($term != $glossaryterm) {
143
                    $term_q      = preg_quote($term, '/');
144
                    $search_term = "/\b$term_q\b/SsUi";
145
                    //static link
146
                    $staticURL = ''
147
                                . XOOPS_URL
148
                                . '/modules/'
149
                                . $xoopsModule->getVar('dirname')
150
                                . '/entry.php?entryID='
151
                                . ucfirst($entryID)
152
                                . '';
153
                    switch ($xoopsModuleConfig['linkterms']) {
154
                        default:
155
                            $replace_term = '<span><b><a style="cursor:help;border-bottom: 1px dotted #000;color: #2F5376;" href="'
156
                                              . $staticURL
157
                                              . '" >'
158
                                              . $term
159
                                              . '</a></b></span>';
160
                            break;
161 View Code Duplication
                        case 3: //tooltip
162
                            $tooltipdef   = $myts->htmlSpecialChars(xoops_substr(strip_tags($definition), 0, 150));
163
                            $replace_term = '<a class="parser" href="'
164
                                              . $staticURL
165
                                              . '" onMouseover="ddrivetip(\''
166
                                              . $tooltipdef
167
                                              . '\', 300)"; onMouseout=\'hideddrivetip()\'>'
168
                                              . $term
169
                                              . '</a>';
170
                            break;
171
                        case 4://simple popup
172
                            $replace_term = '<a style="cursor:help;border-bottom: 1px dotted #000;color: #2F5376;" href="#" onClick=\'popup("popup.php?entryID='
173
                                            . $entryID
174
                                            . '","details", 420, 350); return false\'>'
175
                                            . $term
176
                                            . '</a>';
177
                            break;
178 View Code Duplication
                        case 5:// balloon tooltip
179
                            $tooltipdef   = $myts->htmlSpecialChars(xoops_substr(strip_tags($definition), 0, 150));
180
                            $replace_term = '<a class="parser" href="'
181
                                            . $staticURL
182
                                            . '" onMouseover="showToolTip(event,\''
183
                                            . $tooltipdef
184
                                            . '\');return false"; onMouseout=\'hideToolTip()\'>'
185
                                            . $term
186
                                            . '</a>';
187
                            break;
188 View Code Duplication
                        case 6:// shadow tooltip
189
                            $tooltipdef   = $myts->htmlSpecialChars(xoops_substr(strip_tags($definition), 0, 150));
190
                            $replace_term = '<a class="parser" href="'
191
                                            . $staticURL
192
                                            . '" onmouseout="hideTooltip()" onmouseover="showTooltip(event,\''
193
                                            . $tooltipdef
194
                                            . '\')"; >'
195
                                            . $term
196
                                            . '</a>';
197
                            break;
198
                    }
199
                    $parts[$key] = preg_replace($search_term, $replace_term, $parts[$key]);
200
                }
201
            }
202
        }
203
        $definition = implode('>', $parts);
204
    }
205
    $thisterm['definition'] = $myts->displayTarea($definition, $html, $smiley, $xcodes, 1, $breaks);
206
    $thisterm['ref']        = $myts->displayTarea($ref, $html, $smiley, $xcodes, 1, $breaks);
207
    $thisterm['url']        = $myts->makeClickable($url, $allowimage = 0);
208
    //$thisterm['submitter'] = XoopsUserUtility::getUnameFromId ( $uid );
209
    if ($xoopsModuleConfig['showsubmitter'] == 1) {
210
        $xoopsTpl->assign('showsubmitter', true);
211
        if ($xoopsModuleConfig['authorprofile'] == 1) {
212
            $thisterm['submitter'] = LexikonUtility::getLinkedProfileFromId($uid);
213
        } else {
214
            $thisterm['submitter'] = XoopsUserUtility::getUnameFromId($uid);
215
        }
216
    } else {
217
        $xoopsTpl->assign('showsubmitter', false);
218
    }
219
    $thisterm['submit']  = (int)$submit;
220
    $thisterm['datesub'] = formatTimestamp($datesub, $xoopsModuleConfig['dateformat']);
221
    $thisterm['counter'] = (int)$counter;
222
    $thisterm['block']   = (int)$block;
223
    $thisterm['dir']     = $xoopsModule->dirname();
224
    if ($highlight && isset($_GET['keywords'])) {
225
        $keywords               = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords'])));
226
        $h                      = new lx_keyhighlighter($keywords, true, 'lx_myhighlighter');
227
        $thisterm['definition'] = $h->highlight($thisterm['definition']);
228
        $thisterm['ref']        = $h->highlight($thisterm['ref']);
229
    }
230
}
231
//smartry strings
232
$xoopsTpl->assign('thisterm', $thisterm);
233
$microlinks    = LexikonUtility::getServiceLinks($thisterm);
234
$microlinksnew = LexikonUtility::getServiceLinksNew($thisterm);
235
$xoopsTpl->assign('microlinks', $microlinks);
236
$xoopsTpl->assign('microlinksnew', $microlinksnew);
237
$xoopsTpl->assign('lang_modulename', $xoopsModule->name());
238
$xoopsTpl->assign('lang_moduledirname', $xoopsModule->getVar('dirname'));
239
$xoopsTpl->assign('entryID', $entryID);
240
$xoopsTpl->assign('submittedon', sprintf(_MD_LEXIKON_SUBMITTEDON, $thisterm['datesub']));
241
if ($xoopsModuleConfig['showsubmitter'] == 1) {
242
    $xoopsTpl->assign('submitter', sprintf(_MD_LEXIKON_SUBMITTEDBY, $thisterm['submitter']));
243
}
244
$xoopsTpl->assign('counter', sprintf(_MD_LEXIKON_COUNT, $thisterm['counter']));
245
$xoopsTpl->assign('entrytype', '1');
246
247
// --- keywordshighligher ---
248
/**
249
 * @param $matches
250
 * @return string
251
 */
252
function lx_myhighlighter($matches)
253
{
254
    return '<span style="font-weight: bolder; background-color: #FFFF80;">' . $matches[0] . '</span>';
255
}
256
257
//--- Display tags of this term
258
#$itemid = $entryID;
259
/** @var XoopsModuleHandler $moduleHandler */
260
$moduleHandler = xoops_getHandler('module');
261
$tagsModule    = $moduleHandler->getByDirname('tag');
262
if (is_object($tagsModule)) {
263
    include_once XOOPS_ROOT_PATH . '/modules/tag/include/tagbar.php';
264
265
    $itemid = isset($_GET['entryID']) ? (int)$_GET['entryID'] : 0;
266
    $catid  = 0;
267
    //$xoopsTpl->assign('tagbar', tagBar($itemid, $catid = 0));
268
    $tagbar = tagBar($itemid, $catid);
269
    if ($tagbar) {
270
        $xoopsTpl->assign('tagbar', $tagbar);
271
        $tagsmeta = implode(' ', $tagbar['tags']);
272
    } else {
273
        $tagsmeta = '';
274
    }
275
} else {
276
    $xoopsTpl->assign('tagbar', false);
277
    $tagsmeta = '';
278
}
279
280
//--- linkterms assigns
281
// Balloontips
282
if ($xoopsModuleConfig['linkterms'] == 5) {
283
    $xoopsTpl->assign('balloontips', true);
284
} else {
285
    $xoopsTpl->assign('balloontips', false);
286
}
287
288
// Show Bookmark icons ?
289
switch ($xoopsModuleConfig['bookmarkme']) {
290
    case '0':
291
    default:
292
        $xoopsTpl->assign('bookmarkme', false);
293
        break;
294
    case '1':
295
        $xoopsTpl->assign('bookmarkme', 1);
296
        $xoopsTpl->assign('encoded_title', rawurlencode($thisterm['term']));
297
        break;
298
    case '2':
299
        $xoopsTpl->assign('bookmarkme', 2);
300
        break;
301
    case '3':
302
        $xoopsTpl->assign('bookmarkme', 3);
303
        break;
304
}
305
// Meta data
306
$meta_description = xoops_substr(LexikonUtility::convertHtml2text($thisterm['definition']), 0, 150);
307
if ($xoopsModuleConfig['multicats'] == 1) {
308
    LexikonUtility::createPageTitle($thisterm['term'] . ' - ' . $thisterm['catname']);
309
    LexikonUtility::extractKeywords($myts->htmlSpecialChars($xoopsModule->name()) . ' ,' . $thisterm['term'] . ' ,' . $thisterm['catname'] . ', ' . $meta_description . ', ' . $tagsmeta);
310
    LexikonUtility::getMetaDescription($myts->htmlSpecialChars($xoopsModule->name()) . ' ' . $thisterm['catname'] . ' ' . $thisterm['term'] . ' ' . $meta_description);
311
} else {
312
    LexikonUtility::createPageTitle($thisterm['term']);
313
    LexikonUtility::extractKeywords($myts->htmlSpecialChars($xoopsModule->name()) . ' ,' . $thisterm['term'] . ', ' . $meta_description . ', ' . $tagsmeta);
314
    LexikonUtility::getMetaDescription($myts->htmlSpecialChars($xoopsModule->name()) . ' ' . $thisterm['term'] . ' ' . $meta_description);
315
}
316
//Mondarse
317
include XOOPS_ROOT_PATH . '/include/comment_view.php';
318
//Mondarse
319
include_once XOOPS_ROOT_PATH . '/footer.php';
320