Passed
Pull Request — master (#19)
by Michael
06:45 queued 03:02
created
Labels
Severity
1
<?php
2
/**
3
 * Module: Lexikon - glossary module
4
 * Version: v 1.00
5
 * Release Date: 8 May 2004
6
 * Author: hsalazar
7
 * Licence: GNU
8
 */
9
10
use XoopsModules\Lexikon\{
11
    Common\LetterChoice,
12
    Helper,
13
    Utility
14
};
15
16
$GLOBALS['xoopsOption']['template_main'] = 'lx_index.tpl';
17
18
require __DIR__ . '/header.php';
19
20
21
$helper = Helper::getInstance();
22
$utility = new Utility();
23
24
require_once XOOPS_ROOT_PATH . '/header.php';
25
require_once XOOPS_ROOT_PATH . '/modules/lexikon/include/common.inc.php';
26
global $xoTheme, $xoopsUser;
27
$myts = \MyTextSanitizer::getInstance();
28
29
// Disable cache since content differs for each user
30
//$xoopsConfig["module_cache"][$xoopsModule->getVar("mid")] = 0;
31
32
$utility::calculateTotals();
33
$xoopsTpl->assign('multicats', (int)$helper->getConfig('multicats'));
34
$rndlength = !empty($helper->getConfig('rndlength')) ? (int)$helper->getConfig('rndlength') : 150;
35
36
//permissions
37
/** @var \XoopsGroupPermHandler $grouppermHandler */
38
$grouppermHandler = xoops_getHandler('groupperm');
39
$groups           = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
40
$module_id        = $xoopsModule->getVar('mid');
41
$perm_itemid      = $categoryID ?? 0;
42
if (!$grouppermHandler->checkRight('lexikon_view', $perm_itemid, $groups, $module_id)) {
43
    redirect_header('<script>javascript:history.go(-1)</script>', 2, _NOPERM);
44
}
45
$allowed_cats = $grouppermHandler->getItemIds('lexikon_view', $groups, $module_id);
46
if (count($allowed_cats) > 0) {
47
    $catids   = implode(',', $allowed_cats);
48
    $catperms = " AND categoryID IN ($catids) ";
49
} else {
50
    return '0';
51
}
52
53
if (!function_exists('mb_ucfirst') && function_exists('mb_substr')) {
54
    /**
55
     * @param $string
56
     * @return string
57
     */
58
    function mb_ucfirst($string)
59
    {
60
        $string = mb_ereg_replace('^[\ ]+', '', $string);
61
        $string = mb_strtoupper(mb_substr($string, 0, 1, 'UTF-8'), 'UTF-8') . mb_substr($string, 1, mb_strlen($string), 'UTF-8');
62
63
        return $string;
64
    }
65
}
66
67
// Counts
68
$xoopsTpl->assign('multicats', (int)$helper->getConfig('multicats'));
69
if (1 == $helper->getConfig('multicats')) {
70
    $xoopsTpl->assign('totalcats', $utility::countCats());
71
}
72
$publishedwords = $utility::countWords();
73
$xoopsTpl->assign('publishedwords', $publishedwords);
74
75
// If there's no entries yet in the system...
76
if (0 == $publishedwords) {
77
    $xoopsTpl->assign('empty', '1');
78
}
79
80
// To display the search form
81
$xoopsTpl->assign('searchform', $utility::showSearchForm());
82
83
//--------------------------------------------------------------
84
// To display the linked letter list
85
$alpha = $utility::getAlphaArray();
86
$xoopsTpl->assign('alpha', $alpha);
87
$alphaCount = count($alpha);
88
89
[$howmanyother] = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('lxentries') . " WHERE init = '#' AND offline ='0' " . $catperms . ' '));
90
$xoopsTpl->assign('totalother', $howmanyother);
91
92
//-----------------------------------------
93
94
// Letter Choice Start ---------------------------------------
95
96
$moduleDirName      = basename(__DIR__);
97
$moduleDirNameUpper = mb_strtoupper($moduleDirName);
98
99
Helper::getInstance()->loadLanguage('common');
100
$xoopsTpl->assign('letterChoiceTitle', constant('CO_' . $moduleDirNameUpper . '_' . 'BROWSETOTOPIC'));
101
$db                  = \XoopsDatabaseFactory::getDatabaseConnection();
102
$objHandler          = Helper::getInstance()->getHandler('Entries');
103
$choicebyletter      = new LetterChoice($objHandler, null, null, range('a', 'z'), 'init', LEXIKON_URL . '/letter.php');
0 ignored issues
show
The constant LEXIKON_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
104
$catarray['letters'] = $choicebyletter->render($alphaCount, $howmanyother);
105
$xoopsTpl->assign('catarray', $catarray);
106
107
// Letter Choice End ------------------------------------
108
109
//---------------------------------------------
110
// To display the tree of categories
111
if (1 == $helper->getConfig('multicats')) {
112
    $xoopsTpl->assign('block0', $utility::getCategoryArray());
113
    $xoopsTpl->assign('layout', CONFIG_CATEGORY_LAYOUT_PLAIN);
114
    if (1 == $helper->getConfig('useshots')) {
115
        $xoopsTpl->assign('show_screenshot', true);
116
        $xoopsTpl->assign('logo_maximgwidth', $helper->getConfig('logo_maximgwidth'));
117
        $xoopsTpl->assign('lang_noscreenshot', _MD_LEXIKON_NOSHOTS);
118
    } else {
119
        $xoopsTpl->assign('show_screenshot', false);
120
    }
121
}
122
// To display the recent entries block
123
$block1   = [];
124
$result05 = $xoopsDB->query(
125
    'SELECT entryID, categoryID, term, datesub FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE datesub < ' . time() . " AND datesub > 0 AND submit = '0' AND offline = '0' AND request = '0' " . $catperms . ' ORDER BY datesub DESC',
126
    (int)$helper->getConfig('blocksperpage'),
127
    0
128
);
129
if ($publishedwords > 0) { // If there are definitions
130
    //while (list( $entryID, $term, $datesub ) = $xoopsDB->fetchRow($result05)) {
131
    while (list($entryID, $categoryID, $term, $datesub) = $xoopsDB->fetchRow($result05)) {
132
        $newentries             = [];
133
        $xoopsModule            = XoopsModule::getByDirname('lexikon');
134
        $linktext               = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5));
135
        $newentries['linktext'] = $linktext;
136
        $newentries['id']       = $entryID;
137
        $newentries['date']     = formatTimestamp($datesub, 's');
138
139
        $block1['newstuff'][] = $newentries;
140
    }
141
    $xoopsTpl->assign('block', $block1);
142
}
143
144
// To display the most read entries block
145
$block2   = [];
146
$result06 = $xoopsDB->query('SELECT entryID, term, counter FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE datesub < ' . time() . " AND datesub > 0 AND submit = '0' AND offline = '0' AND request = '0' " . $catperms . ' ORDER BY counter DESC', (int)$helper->getConfig('blocksperpage'), 0);
147
// If there are definitions
148
if ($publishedwords > 0) {
149
    while (list($entryID, $term, $counter) = $xoopsDB->fetchRow($result06)) {
150
        $popentries             = [];
151
        $xoopsModule            = XoopsModule::getByDirname('lexikon');
152
        $linktext               = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5));
153
        $popentries['linktext'] = $linktext;
154
        $popentries['id']       = $entryID;
155
        $popentries['counter']  = (int)$counter;
156
157
        $block2['popstuff'][] = $popentries;
158
    }
159
    $xoopsTpl->assign('block2', $block2);
160
}
161
162
// To display the random term block
163
[$numrows] = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('lxentries') . " WHERE submit = 'O' AND offline = '0' " . $catperms . ' '));
164
if ($numrows > 1) {
165
    --$numrows;
166
    $entrynumber = random_int(0, $numrows);
167
} else {
168
    $entrynumber = 0;
169
}
170
171
$resultZ = $xoopsDB->query('SELECT entryID, categoryID, term, definition, html, smiley, xcodes, breaks FROM ' . $xoopsDB->prefix('lxentries') . " WHERE submit = 'O' AND offline = '0' " . $catperms . " LIMIT $entrynumber, 1");
172
173
$zerotest = $xoopsDB->getRowsNum($resultZ);
174
if (0 != $zerotest) {
175
    while (false !== ($myrow = $xoopsDB->fetchArray($resultZ))) {
176
        $random         = [];
177
        $random['id']   = $myrow['entryID'];
178
        $random['term'] = mb_ucfirst($myrow['term']);
179
180
        if (!XOOPS_USE_MULTIBYTES) {
181
            $random['definition'] = $myts->displayTarea(xoops_substr($myrow['definition'], 0, $rndlength - 1), $myrow['html'], $myrow['smiley'], $myrow['xcodes'], 1, $myrow['breaks']);
182
        }
183
184
        if (1 == $helper->getConfig('multicats')) {
185
            $random['categoryID'] = $myrow['categoryID'];
186
187
            $resultY = $xoopsDB->query('SELECT categoryID, name FROM ' . $xoopsDB->prefix('lxcategories') . ' WHERE categoryID = ' . $myrow['categoryID'] . ' ');
188
            [$categoryID, $name] = $xoopsDB->fetchRow($resultY);
189
            $random['categoryname'] = $myts->displayTarea($name);
190
        }
191
    }
192
    $microlinks = $utility::getServiceLinks($random);
193
    $xoopsTpl->assign('random', $random);
194
}
195
196
if ($xoopsUser && $xoopsUser->isAdmin()) {
197
    // To display the submitted and requested terms box
198
    $xoopsTpl->assign('userisadmin', 1);
199
200
    $blockS      = [];
201
    $resultS     = $xoopsDB->query('SELECT entryID, term FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE datesub < ' . time() . " AND datesub > 0 AND submit = '1' AND offline = '1' AND request = '0' ORDER BY term");
202
    $totalSwords = $xoopsDB->getRowsNum($resultS);
203
204
    if ($totalSwords > 0) { // If there are definitions
205
        while (list($entryID, $term) = $xoopsDB->fetchRow($resultS)) {
206
            $subentries             = [];
207
            $xoopsModule            = XoopsModule::getByDirname('lexikon');
208
            $linktext               = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5));
209
            $subentries['linktext'] = $linktext;
210
            $subentries['id']       = $entryID;
211
212
            $blockS['substuff'][] = $subentries;
213
        }
214
        $xoopsTpl->assign('blockS', $blockS);
215
        $xoopsTpl->assign('wehavesubs', 1);
216
    } else {
217
        $xoopsTpl->assign('wehavesubs', 0);
218
    }
219
220
    $blockR      = [];
221
    $resultR     = $xoopsDB->query('SELECT entryID, term FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE datesub < ' . time() . " AND datesub > 0 AND request = '1' ORDER BY term");
222
    $totalRwords = $xoopsDB->getRowsNum($resultR);
223
224
    if ($totalRwords > 0) { // If there are definitions
225
        while (list($entryID, $term) = $xoopsDB->fetchRow($resultR)) {
226
            $reqentries             = [];
227
            $xoopsModule            = XoopsModule::getByDirname('lexikon');
228
            $linktext               = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5));
229
            $reqentries['linktext'] = $linktext;
230
            $reqentries['id']       = $entryID;
231
232
            $blockR['reqstuff'][] = $reqentries;
233
        }
234
        $xoopsTpl->assign('blockR', $blockR);
235
        $xoopsTpl->assign('wehavereqs', 1);
236
    } else {
237
        $xoopsTpl->assign('wehavereqs', 0);
238
    }
239
} else {
240
    $xoopsTpl->assign('userisadmin', 0);
241
    $blockR      = [];
242
    $resultR     = $xoopsDB->query('SELECT entryID, term FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE datesub < ' . time() . " AND datesub > 0 AND request = '1' " . $catperms . ' ORDER BY term');
243
    $totalRwords = $xoopsDB->getRowsNum($resultR);
244
245
    if ($totalRwords > 0) { // If there are definitions
246
        while (list($entryID, $term) = $xoopsDB->fetchRow($resultR)) {
247
            $reqentries             = [];
248
            $xoopsModule            = XoopsModule::getByDirname('lexikon');
249
            $linktext               = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5));
250
            $reqentries['linktext'] = $linktext;
251
            $reqentries['id']       = $entryID;
252
253
            $blockR['reqstuff'][] = $reqentries;
254
        }
255
        $xoopsTpl->assign('blockR', $blockR);
256
        $xoopsTpl->assign('wehavereqs', 1);
257
    } else {
258
        $xoopsTpl->assign('wehavereqs', 0);
259
    }
260
}
261
// Various strings
262
$xoopsTpl->assign('lang_modulename', $xoopsModule->name());
263
$xoopsTpl->assign('lang_moduledirname', $xoopsModule->getVar('dirname'));
264
if (0 != $publishedwords) {
265
    $xoopsTpl->assign('microlinks', $microlinks);
266
    $xoopsTpl->assign('showdate', (int)$helper->getConfig('showdate'));
267
    $xoopsTpl->assign('showcount', (int)$helper->getConfig('showcount'));
268
}
269
$xoopsTpl->assign('alpha', $alpha);
270
$xoopsTpl->assign('teaser', $utility::getModuleOption('teaser'));
271
if (1 == $helper->getConfig('syndication')) {
272
    $xoopsTpl->assign('syndication', true);
273
}
274
if ($xoopsUser) {
275
    $xoopsTpl->assign('syndication', true);
276
}
277
$xoopsTpl->assign('xoops_pagetitle', htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5));
278
279
// Meta data
280
$meta_description = htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5);
281
if (isset($xoTheme) && is_object($xoTheme)) {
282
    $xoTheme->addMeta('meta', 'description', $meta_description);
283
} else {
284
    $xoopsTpl->assign('xoops_meta_description', $meta_description);
285
}
286
$xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" type="text/css" href="assets/css/style.css">');
287
288
require XOOPS_ROOT_PATH . '/footer.php';
289