Completed
Pull Request — master (#12)
by
unknown
02:07
created

index.php (2 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 ' . $xoopsDB->prefix('lxentries') . " WHERE init = '#' AND offline ='0' " . $catperms . ''));
71
$xoopsTpl->assign('totalother', $howmanyother);
72
73
// To display the tree of categories
74 View Code Duplication
if ($xoopsModuleConfig['multicats'] == 1) {
75
    $xoopsTpl->assign('block0', LexikonUtility::getCategoryArray());
76
    $xoopsTpl->assign('layout', CONFIG_CATEGORY_LAYOUT_PLAIN);
77
    if ($xoopsModuleConfig['useshots'] == 1) {
78
        $xoopsTpl->assign('show_screenshot', true);
79
        $xoopsTpl->assign('logo_maximgwidth', $xoopsModuleConfig['logo_maximgwidth']);
80
        $xoopsTpl->assign('lang_noscreenshot', _MD_LEXIKON_NOSHOTS);
81
    } else {
82
        $xoopsTpl->assign('show_screenshot', false);
83
    }
84
}
85
// To display the recent entries block
86
$block1   = array();
87
$result05 = $xoopsDB->query('SELECT entryID, categoryID, term, datesub FROM '
88
                            . $xoopsDB->prefix('lxentries')
89
                            . ' WHERE datesub < '
90
                            . time()
91
                            . " AND datesub > 0 AND submit = '0' AND offline = '0' AND request = '0' "
92
                            . $catperms
93
                            . ' ORDER BY datesub DESC', (int)$xoopsModuleConfig['blocksperpage'], 0);
94 View Code Duplication
if ($publishedwords > 0) { // If there are definitions
95
    //while (list( $entryID, $term, $datesub ) = $xoopsDB->fetchRow($result05)) {
96
    while (list($entryID, $categoryID, $term, $datesub) = $xoopsDB->fetchRow($result05)) {
97
        $newentries             = array();
98
        $xoopsModule            = XoopsModule::getByDirname('lexikon');
99
        $linktext               = mb_ucfirst($myts->htmlSpecialChars($term));
100
        $newentries['linktext'] = $linktext;
101
        $newentries['id']       = $entryID;
102
        $newentries['date']     = formatTimestamp($datesub, 's');
103
104
        $block1['newstuff'][] = $newentries;
105
    }
106
    $xoopsTpl->assign('block', $block1);
107
}
108
109
// To display the most read entries block
110
$block2   = array();
111
$result06 = $xoopsDB->query('SELECT entryID, term, counter FROM '
112
                            . $xoopsDB->prefix('lxentries')
113
                            . ' WHERE datesub < '
114
                            . time()
115
                            . " AND datesub > 0 AND submit = '0' AND offline = '0' AND request = '0' "
116
                            . $catperms
117
                            . ' ORDER BY counter DESC', (int)$xoopsModuleConfig['blocksperpage'], 0);
118
// If there are definitions
119
if ($publishedwords > 0) {
120
    while (list($entryID, $term, $counter) = $xoopsDB->fetchRow($result06)) {
121
        $popentries             = array();
122
        $xoopsModule            = XoopsModule::getByDirname('lexikon');
123
        $linktext               = mb_ucfirst($myts->htmlSpecialChars($term));
124
        $popentries['linktext'] = $linktext;
125
        $popentries['id']       = $entryID;
126
        $popentries['counter']  = (int)$counter;
127
128
        $block2['popstuff'][] = $popentries;
129
    }
130
    $xoopsTpl->assign('block2', $block2);
131
}
132
133
// To display the random term block
134
list($numrows) = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('lxentries') . " WHERE submit = 'O' AND offline = '0' " . $catperms . ' '));
135 View Code Duplication
if ($numrows > 1) {
136
    --$numrows;
137
    mt_srand((double)microtime() * 1000000);
138
    $entrynumber = mt_rand(0, $numrows);
139
} else {
140
    $entrynumber = 0;
141
}
142
143
$resultZ = $xoopsDB->query('SELECT entryID, categoryID, term, definition, html, smiley, xcodes, breaks FROM '
144
                           . $xoopsDB->prefix('lxentries')
145
                           . " WHERE submit = 'O' AND offline = '0' "
146
                           . $catperms
147
                           . " LIMIT $entrynumber, 1");
148
149
$zerotest = $xoopsDB->getRowsNum($resultZ);
150
if ($zerotest != 0) {
151
    while ($myrow = $xoopsDB->fetchArray($resultZ)) {
152
        $random         = array();
153
        $random['id']   = $myrow['entryID'];
154
        $random['term'] = mb_ucfirst($myrow['term']);
155
156
        if (!XOOPS_USE_MULTIBYTES) {
157
            $random['definition'] = $myts->displayTarea(xoops_substr($myrow['definition'], 0, $rndlength - 1), $myrow['html'], $myrow['smiley'], $myrow['xcodes'], 1, $myrow['breaks']);
158
        }
159
160 View Code Duplication
        if ($xoopsModuleConfig['multicats'] == 1) {
161
            $random['categoryID'] = $myrow['categoryID'];
162
163
            $resultY = $xoopsDB->query('SELECT categoryID, name FROM ' . $xoopsDB->prefix('lxcategories') . ' WHERE categoryID = ' . $myrow['categoryID'] . ' ');
164
            list($categoryID, $name) = $xoopsDB->fetchRow($resultY);
165
            $random['categoryname'] = $myts->displayTarea($name);
166
        }
167
    }
168
    $microlinks = LexikonUtility::getServiceLinks($random);
169
    $xoopsTpl->assign('random', $random);
170
}
171
172
if ($xoopsUser && $xoopsUser->isAdmin()) {
173
    // To display the submitted and requested terms box
174
    $xoopsTpl->assign('userisadmin', 1);
175
176
    $blockS      = array();
177
    $resultS     = $xoopsDB->query('SELECT entryID, term FROM '
178
                                   . $xoopsDB->prefix('lxentries')
179
                                   . ' WHERE datesub < '
180
                                   . time()
181
                                   . " AND datesub > 0 AND submit = '1' AND offline = '1' AND request = '0' ORDER BY term");
182
    $totalSwords = $xoopsDB->getRowsNum($resultS);
183
184 View Code Duplication
    if ($totalSwords > 0) { // If there are definitions
185
        while (list($entryID, $term) = $xoopsDB->fetchRow($resultS)) {
186
            $subentries             = array();
187
            $xoopsModule            = XoopsModule::getByDirname('lexikon');
188
            $linktext               = mb_ucfirst($myts->htmlSpecialChars($term));
189
            $subentries['linktext'] = $linktext;
190
            $subentries['id']       = $entryID;
191
192
            $blockS['substuff'][] = $subentries;
193
        }
194
        $xoopsTpl->assign('blockS', $blockS);
195
        $xoopsTpl->assign('wehavesubs', 1);
196
    } else {
197
        $xoopsTpl->assign('wehavesubs', 0);
198
    }
199
200
    $blockR      = array();
201
    $resultR     = $xoopsDB->query('SELECT entryID, term FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE datesub < ' . time() . " AND datesub > 0 AND request = '1' ORDER BY term");
202
    $totalRwords = $xoopsDB->getRowsNum($resultR);
203
204 View Code Duplication
    if ($totalRwords > 0) { // If there are definitions
205
        while (list($entryID, $term) = $xoopsDB->fetchRow($resultR)) {
206
            $reqentries             = array();
207
            $xoopsModule            = XoopsModule::getByDirname('lexikon');
208
            $linktext               = mb_ucfirst($myts->htmlSpecialChars($term));
209
            $reqentries['linktext'] = $linktext;
210
            $reqentries['id']       = $entryID;
211
212
            $blockR['reqstuff'][] = $reqentries;
213
        }
214
        $xoopsTpl->assign('blockR', $blockR);
215
        $xoopsTpl->assign('wehavereqs', 1);
216
    } else {
217
        $xoopsTpl->assign('wehavereqs', 0);
218
    }
219
} else {
220
    $xoopsTpl->assign('userisadmin', 0);
221
    $blockR      = array();
222
    $resultR     = $xoopsDB->query('SELECT entryID, term FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE datesub < ' . time() . " AND datesub > 0 AND request = '1' " . $catperms . ' ORDER BY term');
223
    $totalRwords = $xoopsDB->getRowsNum($resultR);
224
225 View Code Duplication
    if ($totalRwords > 0) { // If there are definitions
226
        while (list($entryID, $term) = $xoopsDB->fetchRow($resultR)) {
227
            $reqentries             = array();
228
            $xoopsModule            = XoopsModule::getByDirname('lexikon');
229
            $linktext               = mb_ucfirst($myts->htmlSpecialChars($term));
230
            $reqentries['linktext'] = $linktext;
231
            $reqentries['id']       = $entryID;
232
233
            $blockR['reqstuff'][] = $reqentries;
234
        }
235
        $xoopsTpl->assign('blockR', $blockR);
236
        $xoopsTpl->assign('wehavereqs', 1);
237
    } else {
238
        $xoopsTpl->assign('wehavereqs', 0);
239
    }
240
}
241
// Various strings
242
$xoopsTpl->assign('lang_modulename', $xoopsModule->name());
243
$xoopsTpl->assign('lang_moduledirname', $xoopsModule->getVar('dirname'));
244
if ($publishedwords != 0) {
245
    $xoopsTpl->assign('microlinks', $microlinks);
246
    $xoopsTpl->assign('showdate', (int)$xoopsModuleConfig['showdate']);
247
    $xoopsTpl->assign('showcount', (int)$xoopsModuleConfig['showcount']);
248
}
249
$xoopsTpl->assign('alpha', $alpha);
250
$xoopsTpl->assign('teaser', LexikonUtility::getModuleOption('teaser'));
251
if ($xoopsModuleConfig['syndication'] == 1) {
252
    $xoopsTpl->assign('syndication', true);
253
}
254
if ($xoopsUser) {
255
    $xoopsTpl->assign('syndication', true);
256
}
257
$xoopsTpl->assign('xoops_pagetitle', $myts->htmlSpecialChars($xoopsModule->name()));
258
259
// Meta data
260
$meta_description = $myts->htmlSpecialChars($xoopsModule->name());
261
if (isset($xoTheme) && is_object($xoTheme)) {
262
    $xoTheme->addMeta('meta', 'description', $meta_description);
263
} else {
264
    $xoopsTpl->assign('xoops_meta_description', $meta_description);
265
}
266
$xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" type="text/css" href="assets/css/style.css" />');
267
268
include XOOPS_ROOT_PATH . '/footer.php';
269