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

index.php (4 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
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 43 and the first side effect is on line 11.

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