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 | $formSearch = $utility::getFormSearch(); |
||
82 | $xoopsTpl->assign('searchform', $formSearch->render()); |
||
83 | |||
84 | //-------------------------------------------------------------- |
||
85 | // To display the linked letter list |
||
86 | $alpha = $utility::getAlphaArray(); |
||
87 | $xoopsTpl->assign('alpha', $alpha); |
||
88 | $alphaCount = count($alpha); |
||
89 | |||
90 | [$howmanyother] = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('lxentries') . " WHERE init = '#' AND offline ='0' " . $catperms . ' ')); |
||
91 | $xoopsTpl->assign('totalother', $howmanyother); |
||
92 | |||
93 | //----------------------------------------- |
||
94 | |||
95 | // Letter Choice Start --------------------------------------- |
||
96 | |||
97 | $moduleDirName = basename(__DIR__); |
||
98 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); |
||
99 | |||
100 | Helper::getInstance()->loadLanguage('common'); |
||
101 | $xoopsTpl->assign('letterChoiceTitle', constant('CO_' . $moduleDirNameUpper . '_' . 'BROWSETOTOPIC')); |
||
102 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
103 | $objHandler = Helper::getInstance()->getHandler('Entries'); |
||
104 | $choicebyletter = new LetterChoice($objHandler, null, null, range('a', 'z'), 'init', LEXIKON_URL . '/letter.php'); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
105 | $catarray['letters'] = $choicebyletter->render($alphaCount, $howmanyother); |
||
106 | $xoopsTpl->assign('catarray', $catarray); |
||
107 | |||
108 | // Letter Choice End ------------------------------------ |
||
109 | |||
110 | //--------------------------------------------- |
||
111 | // To display the tree of categories |
||
112 | if (1 == $helper->getConfig('multicats')) { |
||
113 | $xoopsTpl->assign('block0', $utility::getCategoryArray()); |
||
114 | $xoopsTpl->assign('layout', CONFIG_CATEGORY_LAYOUT_PLAIN); |
||
115 | if (1 == $helper->getConfig('useshots')) { |
||
116 | $xoopsTpl->assign('show_screenshot', true); |
||
117 | $xoopsTpl->assign('logo_maximgwidth', $helper->getConfig('logo_maximgwidth')); |
||
118 | $xoopsTpl->assign('lang_noscreenshot', _MD_LEXIKON_NOSHOTS); |
||
119 | } else { |
||
120 | $xoopsTpl->assign('show_screenshot', false); |
||
121 | } |
||
122 | } |
||
123 | // To display the recent entries block |
||
124 | $block1 = []; |
||
125 | $result05 = $xoopsDB->query( |
||
126 | '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', |
||
127 | (int)$helper->getConfig('blocksperpage'), |
||
128 | 0 |
||
129 | ); |
||
130 | if ($publishedwords > 0) { // If there are definitions |
||
131 | //while (list( $entryID, $term, $datesub ) = $xoopsDB->fetchRow($result05)) { |
||
132 | while (list($entryID, $categoryID, $term, $datesub) = $xoopsDB->fetchRow($result05)) { |
||
133 | $newentries = []; |
||
134 | $xoopsModule = XoopsModule::getByDirname('lexikon'); |
||
135 | $linktext = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5)); |
||
136 | $newentries['linktext'] = $linktext; |
||
137 | $newentries['id'] = $entryID; |
||
138 | $newentries['date'] = formatTimestamp($datesub, 's'); |
||
139 | |||
140 | $block1['newstuff'][] = $newentries; |
||
141 | } |
||
142 | $xoopsTpl->assign('block', $block1); |
||
143 | } |
||
144 | |||
145 | // To display the most read entries block |
||
146 | $block2 = []; |
||
147 | $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); |
||
148 | // If there are definitions |
||
149 | if ($publishedwords > 0) { |
||
150 | while (list($entryID, $term, $counter) = $xoopsDB->fetchRow($result06)) { |
||
151 | $popentries = []; |
||
152 | $xoopsModule = XoopsModule::getByDirname('lexikon'); |
||
153 | $linktext = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5)); |
||
154 | $popentries['linktext'] = $linktext; |
||
155 | $popentries['id'] = $entryID; |
||
156 | $popentries['counter'] = (int)$counter; |
||
157 | |||
158 | $block2['popstuff'][] = $popentries; |
||
159 | } |
||
160 | $xoopsTpl->assign('block2', $block2); |
||
161 | } |
||
162 | |||
163 | // To display the random term block |
||
164 | [$numrows] = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('lxentries') . " WHERE submit = 'O' AND offline = '0' " . $catperms . ' ')); |
||
165 | if ($numrows > 1) { |
||
166 | --$numrows; |
||
167 | $entrynumber = random_int(0, $numrows); |
||
168 | } else { |
||
169 | $entrynumber = 0; |
||
170 | } |
||
171 | |||
172 | $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"); |
||
173 | |||
174 | $zerotest = $xoopsDB->getRowsNum($resultZ); |
||
175 | if (0 != $zerotest) { |
||
176 | while (false !== ($myrow = $xoopsDB->fetchArray($resultZ))) { |
||
177 | $random = []; |
||
178 | $random['id'] = $myrow['entryID']; |
||
179 | $random['term'] = mb_ucfirst($myrow['term']); |
||
180 | |||
181 | if (!XOOPS_USE_MULTIBYTES) { |
||
182 | $random['definition'] = $myts->displayTarea(xoops_substr($myrow['definition'], 0, $rndlength - 1), $myrow['html'], $myrow['smiley'], $myrow['xcodes'], 1, $myrow['breaks']); |
||
183 | } |
||
184 | |||
185 | if (1 == $helper->getConfig('multicats')) { |
||
186 | $random['categoryID'] = $myrow['categoryID']; |
||
187 | |||
188 | $resultY = $xoopsDB->query('SELECT categoryID, name FROM ' . $xoopsDB->prefix('lxcategories') . ' WHERE categoryID = ' . $myrow['categoryID'] . ' '); |
||
189 | [$categoryID, $name] = $xoopsDB->fetchRow($resultY); |
||
190 | $random['categoryname'] = $myts->displayTarea($name); |
||
191 | } |
||
192 | } |
||
193 | $microlinks = $utility::getServiceLinks($random); |
||
194 | $xoopsTpl->assign('random', $random); |
||
195 | } |
||
196 | |||
197 | if ($xoopsUser && $xoopsUser->isAdmin()) { |
||
198 | // To display the submitted and requested terms box |
||
199 | $xoopsTpl->assign('userisadmin', 1); |
||
200 | |||
201 | $blockS = []; |
||
202 | $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"); |
||
203 | $totalSwords = $xoopsDB->getRowsNum($resultS); |
||
204 | |||
205 | if ($totalSwords > 0) { // If there are definitions |
||
206 | while (list($entryID, $term) = $xoopsDB->fetchRow($resultS)) { |
||
207 | $subentries = []; |
||
208 | $xoopsModule = XoopsModule::getByDirname('lexikon'); |
||
209 | $linktext = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5)); |
||
210 | $subentries['linktext'] = $linktext; |
||
211 | $subentries['id'] = $entryID; |
||
212 | |||
213 | $blockS['substuff'][] = $subentries; |
||
214 | } |
||
215 | $xoopsTpl->assign('blockS', $blockS); |
||
216 | $xoopsTpl->assign('wehavesubs', 1); |
||
217 | } else { |
||
218 | $xoopsTpl->assign('wehavesubs', 0); |
||
219 | } |
||
220 | |||
221 | $blockR = []; |
||
222 | $resultR = $xoopsDB->query('SELECT entryID, term FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE datesub < ' . time() . " AND datesub > 0 AND request = '1' ORDER BY term"); |
||
223 | $totalRwords = $xoopsDB->getRowsNum($resultR); |
||
224 | |||
225 | if ($totalRwords > 0) { // If there are definitions |
||
226 | while (list($entryID, $term) = $xoopsDB->fetchRow($resultR)) { |
||
227 | $reqentries = []; |
||
228 | $xoopsModule = XoopsModule::getByDirname('lexikon'); |
||
229 | $linktext = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5)); |
||
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 | } else { |
||
241 | $xoopsTpl->assign('userisadmin', 0); |
||
242 | $blockR = []; |
||
243 | $resultR = $xoopsDB->query('SELECT entryID, term FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE datesub < ' . time() . " AND datesub > 0 AND request = '1' " . $catperms . ' ORDER BY term'); |
||
244 | $totalRwords = $xoopsDB->getRowsNum($resultR); |
||
245 | |||
246 | if ($totalRwords > 0) { // If there are definitions |
||
247 | while (list($entryID, $term) = $xoopsDB->fetchRow($resultR)) { |
||
248 | $reqentries = []; |
||
249 | $xoopsModule = XoopsModule::getByDirname('lexikon'); |
||
250 | $linktext = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5)); |
||
251 | $reqentries['linktext'] = $linktext; |
||
252 | $reqentries['id'] = $entryID; |
||
253 | |||
254 | $blockR['reqstuff'][] = $reqentries; |
||
255 | } |
||
256 | $xoopsTpl->assign('blockR', $blockR); |
||
257 | $xoopsTpl->assign('wehavereqs', 1); |
||
258 | } else { |
||
259 | $xoopsTpl->assign('wehavereqs', 0); |
||
260 | } |
||
261 | } |
||
262 | // Various strings |
||
263 | $xoopsTpl->assign('lang_modulename', $xoopsModule->name()); |
||
264 | $xoopsTpl->assign('lang_moduledirname', $xoopsModule->getVar('dirname')); |
||
265 | if (0 != $publishedwords) { |
||
266 | $xoopsTpl->assign('microlinks', $microlinks); |
||
267 | $xoopsTpl->assign('showdate', (int)$helper->getConfig('showdate')); |
||
268 | $xoopsTpl->assign('showcount', (int)$helper->getConfig('showcount')); |
||
269 | } |
||
270 | $xoopsTpl->assign('alpha', $alpha); |
||
271 | $xoopsTpl->assign('teaser', $utility::getModuleOption('teaser')); |
||
272 | if (1 == $helper->getConfig('syndication')) { |
||
273 | $xoopsTpl->assign('syndication', true); |
||
274 | } |
||
275 | if ($xoopsUser) { |
||
276 | $xoopsTpl->assign('syndication', true); |
||
277 | } |
||
278 | $xoopsTpl->assign('xoops_pagetitle', htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5)); |
||
279 | |||
280 | // Meta data |
||
281 | $meta_description = htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5); |
||
282 | if (isset($xoTheme) && is_object($xoTheme)) { |
||
283 | $xoTheme->addMeta('meta', 'description', $meta_description); |
||
284 | } else { |
||
285 | $xoopsTpl->assign('xoops_meta_description', $meta_description); |
||
286 | } |
||
287 | $xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" type="text/css" href="assets/css/style.css">'); |
||
288 | |||
289 | require XOOPS_ROOT_PATH . '/footer.php'; |
||
290 |