Passed
Push — master ( 3a2152...658ebb )
by Goffy
04:30 queued 12s
created

letter.php (2 issues)

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