Completed
Push — master ( c1777d...d193e2 )
by Michael
13:22
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
2
/**
3
 * $Id: index.php v 1.0 8 May 2004 hsalazar Exp $
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( "header.php" );
12
13
$xoopsOption['template_main'] = 'lx_index.html';
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
lx_calculateTotals();
23
$xoopsTpl->assign('multicats', intval($xoopsModuleConfig['multicats']));
24
$rndlength = !empty($xoopsModuleConfig['rndlength']) ? intval($xoopsModuleConfig['rndlength']) : 150 ;
25
26
//permissions
27
$gperm_handler = xoops_gethandler('groupperm');
28
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
29
$module_id= $xoopsModule->getVar('mid');
30
$perm_itemid = isset($categoryID) ? intval($categoryID) :  0;
31
if (!$gperm_handler->checkRight('lexikon_view', $perm_itemid, $groups, $module_id)) {
32
    redirect_header('javascript:history.go(-1)', 2, _NOPERM );
33
    exit();
34
}
35
$allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id);
36
if(count($allowed_cats) > 0 ) {
37
    $catids = implode(',', $allowed_cats);
38
    $catperms = " AND categoryID IN ($catids) ";
39
} else {
40
    return '0';
41
}
42
    
43
// Counts
44
$xoopsTpl->assign('multicats', intval($xoopsModuleConfig['multicats']));
45
if ($xoopsModuleConfig['multicats'] == 1) {
46
    $xoopsTpl->assign('totalcats', intval(lx_countCats()));
47
}
48
$publishedwords = lx_countWords();
49
$xoopsTpl->assign('publishedwords', $publishedwords);
50
51
// If there's no entries yet in the system...
52
if ( $publishedwords == 0 ) {
53
    $xoopsTpl -> assign ('empty', '1');
54
}
55
56
// To display the search form
57
$xoopsTpl->assign('searchform', lx_showSearchForm());
58
59
// To display the linked letter list
60
$alpha = lx_alphaArray();
61
$xoopsTpl->assign('alpha', $alpha);
62
63
list($howmanyother) = $xoopsDB -> fetchRow($xoopsDB->query("SELECT COUNT(*) FROM " . $xoopsDB -> prefix ( "lxentries") . " WHERE init = '#' AND offline ='0' ".$catperms."" ));
64
$xoopsTpl->assign('totalother', $howmanyother);
65
66
// To display the tree of categories
67 View Code Duplication
if ( $xoopsModuleConfig['multicats'] == 1 ) {
68
    $xoopsTpl -> assign ( 'block0', lx_CatsArray() );
69
    $xoopsTpl->assign('layout', CONFIG_CATEGORY_LAYOUT_PLAIN);
70
    if ( $xoopsModuleConfig['useshots'] == 1 ) {
71
        $xoopsTpl->assign('show_screenshot', true);
72
        $xoopsTpl->assign('logo_maximgwidth', $xoopsModuleConfig['logo_maximgwidth']);
73
        $xoopsTpl->assign('lang_noscreenshot', _MD_LEXIKON_NOSHOTS);
74
    } else {
75
        $xoopsTpl->assign('show_screenshot', false);
76
    }
77
}
78
// To display the recent entries block
79
    $block1 = array();
80
    $result05 = $xoopsDB -> query( "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", intval($xoopsModuleConfig['blocksperpage']), 0 );
81
    if ( $publishedwords > 0 ) // If there are definitions
82
    {
83
        //while (list( $entryID, $term, $datesub ) = $xoopsDB->fetchRow($result05)) {
84
        while (list( $entryID, $categoryID, $term, $datesub ) = $xoopsDB->fetchRow($result05)) {
85
            $newentries = array();
86
            $xoopsModule = XoopsModule::getByDirname("lexikon");
87
            $linktext = ucfirst($myts -> htmlSpecialChars( $term ));
88
            $newentries['linktext'] = $linktext;
89
            $newentries['id'] = $entryID;
90
            $newentries['date'] = formatTimestamp( $datesub, "s" );
91
92
            $block1['newstuff'][] = $newentries;
93
        }
94
        $xoopsTpl -> assign( 'block', $block1);
95
    }
96
97
    // To display the most read entries block
98
    $block2 = array();
99
    $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", intval($xoopsModuleConfig['blocksperpage']), 0 );
100
     // If there are definitions
101
    if ( $publishedwords > 0 ) {
102
        while (list( $entryID, $term, $counter ) = $xoopsDB->fetchRow($result06)) {
103
            $popentries = array();
104
            $xoopsModule = XoopsModule::getByDirname("lexikon");
105
            $linktext = ucfirst($myts -> htmlSpecialChars( $term ));
106
            $popentries['linktext'] = $linktext;
107
            $popentries['id'] = $entryID;
108
            $popentries['counter'] = intval( $counter );
109
110
            $block2['popstuff'][] = $popentries;
111
        }
112
        $xoopsTpl -> assign( 'block2', $block2);
113
    }
114
115
    // To display the random term block
116
    list($numrows) = $xoopsDB -> fetchRow($xoopsDB->query("SELECT COUNT(*) FROM ".$xoopsDB -> prefix("lxentries")." WHERE submit = 'O' AND offline = '0' ".$catperms." "));
117 View Code Duplication
    if ( $numrows > 1) {
118
        $numrows = $numrows-1;
119
        mt_srand((double)microtime()*1000000);
120
        $entrynumber = mt_rand(0, $numrows);
121
    } else {
122
        $entrynumber = 0;
123
    }
124
125
    $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");
126
127
    $zerotest = $xoopsDB -> getRowsNum( $resultZ );
128
    if ( $zerotest != 0 ) {
129
        while ( $myrow = $xoopsDB->fetchArray($resultZ)) {
130
            $random = array();
131
            $random['id'] = $myrow['entryID'];
132
            $random['term'] = ucfirst($myrow['term']);
133
134
            if ( !XOOPS_USE_MULTIBYTES ) {
135
                $random['definition'] = $myts -> displayTarea ( xoops_substr ( $myrow['definition'], 0, $rndlength -1 ), $myrow['html'], $myrow['smiley'], $myrow['xcodes'], 1, $myrow['breaks']);
136
            }
137
138 View Code Duplication
            if ( $xoopsModuleConfig['multicats'] == 1 ) {
139
                $random['categoryID'] = $myrow['categoryID'];
140
141
                $resultY = $xoopsDB -> query ("SELECT categoryID, name FROM ". $xoopsDB -> prefix ("lxcategories") . " WHERE categoryID = ".$myrow['categoryID']." ");
142
                list ( $categoryID, $name ) = $xoopsDB -> fetchRow ( $resultY );
143
                $random['categoryname'] = $myts -> displayTarea ($name);
144
            }
145
        }
146
        $microlinks = lx_serviceLinks ( $random );
147
        $xoopsTpl -> assign ( 'random', $random );
148
    }
149
150
if ( $xoopsUser && $xoopsUser->isAdmin() ) {
151
    // To display the submitted and requested terms box
152
    $xoopsTpl -> assign ('userisadmin', 1 );
153
154
    $blockS = array();
155
    $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" );
156
    $totalSwords = $xoopsDB -> getRowsNum ( $resultS );
157
158 View Code Duplication
    if ( $totalSwords > 0 ) // If there are definitions
159
    {
160
        while (list( $entryID, $term ) = $xoopsDB->fetchRow($resultS)) {
161
            $subentries = array();
162
            $xoopsModule = XoopsModule::getByDirname("lexikon");
163
            $linktext = ucfirst($myts -> htmlSpecialChars( $term ));
164
            $subentries['linktext'] = $linktext;
165
            $subentries['id'] = $entryID;
166
167
            $blockS['substuff'][] = $subentries;
168
        }
169
        $xoopsTpl -> assign( 'blockS', $blockS);
170
        $xoopsTpl -> assign ( 'wehavesubs', 1 );
171
    } else {
172
        $xoopsTpl -> assign ( 'wehavesubs', 0 );
173
    }
174
175
    $blockR = array();
176
    $resultR = $xoopsDB -> query( "SELECT entryID, term FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE datesub < ".time()." AND datesub > 0 AND request = '1' ORDER BY term" );
177
    $totalRwords = $xoopsDB -> getRowsNum ( $resultR );
178
179 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...
180
    {
181
        while (list( $entryID, $term ) = $xoopsDB->fetchRow($resultR)) {
182
            $reqentries = array();
183
            $xoopsModule = XoopsModule::getByDirname("lexikon");
184
            $linktext = ucfirst($myts -> htmlSpecialChars( $term ));
185
            $reqentries['linktext'] = $linktext;
186
            $reqentries['id'] = $entryID;
187
188
            $blockR['reqstuff'][] = $reqentries;
189
        }
190
        $xoopsTpl -> assign( 'blockR', $blockR);
191
        $xoopsTpl -> assign ( 'wehavereqs', 1 );
192
    } else {
193
        $xoopsTpl -> assign ( 'wehavereqs', 0 );
194
    }
195
196
} else {
197
    $xoopsTpl -> assign ('userisadmin', 0 );
198
    $blockR = array();
199
    $resultR = $xoopsDB -> query( "SELECT entryID, term FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE datesub < ".time()." AND datesub > 0 AND request = '1' ".$catperms." ORDER BY term" );
200
    $totalRwords = $xoopsDB -> getRowsNum ( $resultR );
201
202 View Code Duplication
    if ( $totalRwords > 0 ) // If there are definitions
203
    {
204
        while (list( $entryID, $term ) = $xoopsDB->fetchRow($resultR)) {
205
            $reqentries = array();
206
            $xoopsModule = XoopsModule::getByDirname("lexikon");
207
            $linktext = ucfirst($myts -> htmlSpecialChars( $term ));
208
            $reqentries['linktext'] = $linktext;
209
            $reqentries['id'] = $entryID;
210
211
            $blockR['reqstuff'][] = $reqentries;
212
        }
213
        $xoopsTpl -> assign( 'blockR', $blockR);
214
        $xoopsTpl -> assign ( 'wehavereqs', 1 );
215
    } else {
216
        $xoopsTpl -> assign ( 'wehavereqs', 0 );
217
    }
218
219
}
220
// Various strings
221
$xoopsTpl -> assign ( 'lang_modulename', $xoopsModule->name() );
222
$xoopsTpl -> assign ( 'lang_moduledirname', $xoopsModule->getVar('dirname') );
223
if ( $publishedwords != 0 ) {
224
    $xoopsTpl -> assign ( 'microlinks', $microlinks );
225
    $xoopsTpl -> assign ( 'showdate', intval($xoopsModuleConfig["showdate"]) );
226
    $xoopsTpl -> assign ( 'showcount', intval($xoopsModuleConfig["showcount"]) );
227
}
228
$xoopsTpl -> assign ( 'alpha', $alpha );
229
$xoopsTpl -> assign ( 'teaser', lx_getmoduleoption('teaser') );
230
if ($xoopsModuleConfig['syndication'] == 1) $xoopsTpl->assign('syndication', true);
231
if ($xoopsUser) $xoopsTpl->assign('syndication', true);
232
$xoopsTpl->assign('xoops_pagetitle', $myts->htmlSpecialChars($xoopsModule->name()));
233
234
// Meta data
235
$meta_description = $myts->htmlSpecialChars($xoopsModule->name());
236
if (isset($xoTheme) && is_object($xoTheme)) {
237
    $xoTheme->addMeta( 'meta', 'description', $meta_description);
238
} else {
239
    $xoopsTpl->assign('xoops_meta_description', $meta_description);
240
}
241
$xoopsTpl->assign("xoops_module_header", '<link rel="stylesheet" type="text/css" href="style.css" />');
242
243
include( XOOPS_ROOT_PATH . "/footer.php" );
244