-
Notifications
You must be signed in to change notification settings - Fork 5
/
letter.php
234 lines (199 loc) · 11.1 KB
/
letter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
/**
* Module: Xooopstube
* Licence: GNU
*/
use Xmf\Request;
use XoopsModules\Xoopstube\{
Helper,
Utility
};
/** @var Helper $helper */
require_once __DIR__ . '/header.php';
$GLOBALS['xoopsOption']['template_main'] = 'lx_letter.tpl';
require_once XOOPS_ROOT_PATH . '/header.php';
require_once XOOPS_ROOT_PATH . '/modules/lexikon/include/common.inc.php';
$helper = Helper::getInstance();
$utility = new Utility();
global $xoTheme, $xoopsUser;
$myts = \MyTextSanitizer::getInstance();
$init = Request::getString('init', 0, 'GET');
$xoopsTpl->assign('firstletter', $init);
require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
$start = Request::getInt('start', 0, 'GET');
$publishedwords = $utility::countWords();
$xoopsTpl->assign('publishedwords', $publishedwords);
//permissions
/** @var \XoopsGroupPermHandler $grouppermHandler */
$grouppermHandler = xoops_getHandler('groupperm');
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
$module_id = $xoopsModule->getVar('mid');
$allowed_cats = $grouppermHandler->getItemIds('lexikon_view', $groups, $module_id);
$catids = implode(',', $allowed_cats);
$catperms = " AND categoryID IN ($catids) ";
$xoopsTpl->assign('multicats', (int)$helper->getConfig('multicats'));
if (!function_exists('mb_ucfirst') && function_exists('mb_substr')) {
/**
* @param $string
* @return string
*/
function mb_ucfirst($string)
{
$string = mb_ereg_replace('^[\ ]+', '', $string);
$string = mb_strtoupper(mb_substr($string, 0, 1, 'UTF-8'), 'UTF-8') . mb_substr($string, 1, mb_strlen($string), 'UTF-8');
return $string;
}
}
// To display the linked letter list
$alpha = $utility::getAlphaArray();
$xoopsTpl->assign('alpha', $alpha);
[$howmanyother] = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('lxentries') . " WHERE init = '#' AND offline ='0' " . $catperms . ' '));
$xoopsTpl->assign('totalother', $howmanyother);
// To display the list of categories
if (1 == $helper->getConfig('multicats')) {
$xoopsTpl->assign('block0', $utility::getCategoryArray());
$xoopsTpl->assign('layout', CONFIG_CATEGORY_LAYOUT_PLAIN);
if ($utility::getModuleOption('useshots')) {
$xoopsTpl->assign('show_screenshot', true);
$xoopsTpl->assign('logo_maximgwidth', $helper->getConfig('logo_maximgwidth'));
$xoopsTpl->assign('lang_noscreenshot', _MD_LEXIKON_NOSHOTS);
} else {
$xoopsTpl->assign('show_screenshot', false);
}
}
// No initial: we need to see all letters
if (!$init) {
$entriesarray = [];
$pagetype = 0;
// How many entries will we show in this page?
//$queryA = "SELECT w. * , c.name AS catname FROM ".$xoopsDB -> prefix( 'lxentries' )." w LEFT JOIN ".$xoopsDB -> prefix( 'lxcategories' )." c ON w.categoryID = c.categoryID WHERE w.submit = '0' AND w.offline = '0' ORDER BY w.term ASC";
//$resultA = $xoopsDB -> query ($queryA, $helper->getConfig('indexperpage'), $start );
$queryA = 'SELECT * FROM ' . $xoopsDB->prefix('lxentries') . " WHERE offline = '0' AND submit = '0' " . $catperms . ' ORDER BY term ASC';
$resultA = $xoopsDB->query($queryA, $helper->getConfig('indexperpage'), $start);
$allentries = $xoopsDB->query('SELECT entryID FROM ' . $xoopsDB->prefix('lxentries') . " WHERE submit ='0' AND offline = '0' " . $catperms . ' ORDER BY term ASC ');
$totalentries = $xoopsDB->getRowsNum($allentries);
$xoopsTpl->assign('totalentries', $totalentries);
while (list($entryID, $categoryID, $term, $init, $definition, $ref, $url, $uid, $submit, $datesub, $counter, $html, $smiley, $xcodes, $breaks, $block, $offline, $comments) = $xoopsDB->fetchRow($resultA)) {
$eachentry = [];
$xoopsModule = XoopsModule::getByDirname('lexikon');
$eachentry['dir'] = $xoopsModule->dirname();
if (1 == $helper->getConfig('multicats')) {
$eachentry['catid'] = (int)$categoryID;
$resultF = $xoopsDB->query('SELECT name FROM ' . $xoopsDB->prefix('lxcategories') . " WHERE categoryID = $categoryID ORDER BY name ASC");
while (list($name) = $xoopsDB->fetchRow($resultF)) {
$eachentry['catname'] = htmlspecialchars($name, ENT_QUOTES | ENT_HTML5);
}
}
$eachentry['id'] = (int)$entryID;
$eachentry['term'] = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5));
if ((0 != $helper->getConfig('com_rule')) || ((0 != $helper->getConfig('com_rule')) && is_object($xoopsUser))) {
if (0 != $comments) {
$eachentry['comments'] = "<a href='entry.php?entryID=" . $eachentry['id'] . "'>" . $comments . ' ' . _COMMENTS . '</a>';
} else {
$eachentry['comments'] = '';
}
}
if (!XOOPS_USE_MULTIBYTES) {
$eachentry['definition'] = $myts->displayTarea($definition, $html, $smiley, $xcodes, 1, $breaks);
}
// Functional links
$microlinks = $utility::getServiceLinks($eachentry);
$eachentry['microlinks'] = $microlinks;
$entriesarray['single'][] = $eachentry;
}
$pagenav = new \XoopsPageNav($totalentries, $helper->getConfig('indexperpage'), $start, 'start');
$entriesarray['navbar'] = '<div style="text-align:right;">' . $pagenav->renderNav(6) . '</div>';
$xoopsTpl->assign('entriesarray', $entriesarray);
$xoopsTpl->assign('pagetype', '0');
$xoopsTpl->assign('pageinitial', _MD_LEXIKON_ALL);
$utility::createPageTitle(htmlspecialchars(_MD_LEXIKON_BROWSELETTER . ' - ' . _MD_LEXIKON_ALL, ENT_QUOTES | ENT_HTML5));
} else { // $init does exist
$pagetype = 1;
// There IS an initial letter, so we want to show just that letter's terms
$entriesarray2 = [];
// How many entries will we show in this page?
if (_MD_LEXIKON_OTHER == $init) {
$queryB = 'SELECT entryID, categoryID, term, definition, uid, html, smiley, xcodes, breaks, comments FROM ' . $xoopsDB->prefix('lxentries') . " WHERE submit ='0' AND offline = '0' AND init = '#' " . $catperms . ' ORDER BY term ASC';
$resultB = $xoopsDB->query($queryB, $helper->getConfig('indexperpage'), $start);
} else {
$queryB = 'SELECT entryID, categoryID, term, definition, uid, html, smiley, xcodes, breaks, comments FROM ' . $xoopsDB->prefix('lxentries') . " WHERE submit ='0' AND offline = '0' AND init = '$init' AND init != '#' " . $catperms . ' ORDER BY term ASC';
$resultB = $xoopsDB->query($queryB, $helper->getConfig('indexperpage'), $start);
}
$entrieshere = $xoopsDB->getRowsNum($resultB);
if (0 == $entrieshere) {
redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_LEXIKON_NOTERMSINLETTER);
}
if (_MD_LEXIKON_OTHER == $init) {
$allentries = $xoopsDB->query('SELECT entryID FROM ' . $xoopsDB->prefix('lxentries') . " WHERE init = '#' AND submit ='0' AND offline = '0' " . $catperms . ' ORDER BY term ASC ');
} else {
$allentries = $xoopsDB->query('SELECT entryID FROM ' . $xoopsDB->prefix('lxentries') . " WHERE init = '$init' AND init != '#' AND submit ='0' AND offline = '0' " . $catperms . ' ORDER BY term ASC ');
}
$totalentries = $xoopsDB->getRowsNum($allentries);
$xoopsTpl->assign('totalentries', $totalentries);
$utility::createPageTitle(htmlspecialchars(_MD_LEXIKON_BROWSELETTER . (isset($init['init']) ? (' - ' . $init['init']) : ''), ENT_QUOTES | ENT_HTML5));
while (list($entryID, $categoryID, $term, $definition, $uid, $html, $smiley, $xcodes, $breaks, $comments) = $xoopsDB->fetchRow($resultB)) {
$eachentry = [];
$xoopsModule = XoopsModule::getByDirname('lexikon');
$eachentry['dir'] = $xoopsModule->dirname();
if (1 == $helper->getConfig('multicats')) {
$eachentry['catid'] = (int)$categoryID;
$resultF = $xoopsDB->query('SELECT name FROM ' . $xoopsDB->prefix('lxcategories') . " WHERE categoryID = $categoryID ORDER BY name ASC");
while (list($name) = $xoopsDB->fetchRow($resultF)) {
$eachentry['catname'] = htmlspecialchars($name, ENT_QUOTES | ENT_HTML5);
}
}
$eachentry['id'] = (int)$entryID;
$eachentry['term'] = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5));
if ('#' === $init) {
$eachentry['init'] = _MD_LEXIKON_OTHER;
} else {
$eachentry['init'] = $init;
}
if ((0 != $helper->getConfig('com_rule')) || ((0 != $helper->getConfig('com_rule')) && is_object($xoopsUser))) {
if (0 != $comments) {
$eachentry['comments'] = "<a href='entry.php?entryID=" . $eachentry['id'] . "'>" . $comments . ' ' . _COMMENTS . '</a>';
} else {
$eachentry['comments'] = '';
}
}
if (!XOOPS_USE_MULTIBYTES) {
$eachentry['definition'] = $myts->displayTarea($definition, $html, $smiley, $xcodes, 1, $breaks);
}
// Functional links
$microlinks = $utility::getServiceLinks($eachentry);
$eachentry['microlinks'] = $microlinks;
$entriesarray2['single'][] = $eachentry;
}
$pagenav = new \XoopsPageNav($totalentries, $helper->getConfig('indexperpage'), $start, 'init=' . $eachentry['init'] . '&start');
$entriesarray2['navbar'] = '<div style="text-align:right;">' . $pagenav->renderNav(6) . '</div>';
$xoopsTpl->assign('entriesarray2', $entriesarray2);
$xoopsTpl->assign('pagetype', '1');
if ('#' === $eachentry['init']) {
$xoopsTpl->assign('pageinitial', _MD_LEXIKON_OTHER);
$utility::createPageTitle(htmlspecialchars(_MD_LEXIKON_BROWSELETTER . ' - ' . _MD_LEXIKON_OTHER, ENT_QUOTES | ENT_HTML5));
} else {
$xoopsTpl->assign('pageinitial', mb_ucfirst($eachentry['init']));
}
}
$xoopsTpl->assign('lang_modulename', $xoopsModule->name());
$xoopsTpl->assign('lang_moduledirname', $xoopsModule->getVar('dirname'));
$xoopsTpl->assign('alpha', $alpha);
if (1 == $helper->getConfig('syndication')) {
$xoopsTpl->assign('syndication', true);
}
if ($xoopsUser) {
$xoopsTpl->assign('syndication', true);
}
// Meta data
if (0 == $publishedwords) {
$meta_description = xoops_substr($utility::convertHtml2text($eachentry['definition']), 0, 150);
if (1 == $helper->getConfig('multicats')) {
$utility::extractKeywords($xoopsModule->name() . ' ,' . $eachentry['term'] . ', ' . $meta_description);
$utility::getMetaDescription(htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5) . ' ' . $eachentry['catname'] . ' ' . $eachentry['term']);
} else {
$utility::extractKeywords(htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5) . ', ' . $eachentry['term'] . ', ' . $meta_description);
$utility::getMetaDescription(htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5) . ' ' . $eachentry['term'] . ' ' . $meta_description);
}
}
$xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" type="text/css" href="assets/css/style.css">');
require_once XOOPS_ROOT_PATH . '/footer.php';