mb_ucfirst()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 2
b 0
f 0
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
//TODO needs to be adjusted for Wfdonwloads
11
12
use Xmf\Request;
13
use XoopsModules\Wfdownloads\{
14
    Helper,
15
    Utility
16
};
17
/** @var Helper $helper */
18
/** @var Utility $utility */
19
20
require __DIR__ . '/header.php';
21
$GLOBALS['xoopsOption']['template_main'] = 'lx_letter.tpl';
22
require_once XOOPS_ROOT_PATH . '/header.php';
23
require_once XOOPS_ROOT_PATH . '/modules/wfdownloads/include/common.inc.php';
24
$helper = Helper::getInstance();
25
$utility = new Utility();
26
27
global $xoTheme, $xoopsUser;
28
$myts = \MyTextSanitizer::getInstance();
29
30
$init = Request::getString('init', 0, 'GET');
31
$xoopsTpl->assign('firstletter', $init);
32
require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
33
$start = Request::getInt('start', 0, 'GET');
34
35
$publishedwords = $utility::countWords();
0 ignored issues
show
Bug introduced by
The method countWords() does not exist on XoopsModules\Wfdownloads\Utility. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
$publishedwords = $utility::/** @scrutinizer ignore-call */ countWords();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
$xoopsTpl->assign('publishedwords', $publishedwords);
37
38
//permissions
39
/** @var \XoopsGroupPermHandler $grouppermHandler */
40
$grouppermHandler = xoops_getHandler('groupperm');
41
$groups           = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
42
$module_id        = $xoopsModule->getVar('mid');
43
$allowed_cats     = $grouppermHandler->getItemIds('lexikon_view', $groups, $module_id);
44
$catids           = implode(',', $allowed_cats);
45
$catperms         = " AND categoryID IN ($catids) ";
46
47
$xoopsTpl->assign('multicats', (int)$helper->getConfig('multicats'));
48
49
if (!function_exists('mb_ucfirst') && function_exists('mb_substr')) {
50
    /**
51
     * @param $string
52
     * @return false|string
53
     */
54
    function mb_ucfirst($string)
55
    {
56
        $string = mb_ereg_replace('^[\ ]+', '', $string);
57
        $string = mb_strtoupper(mb_substr($string, 0, 1, 'UTF-8'), 'UTF-8') . mb_substr($string, 1, mb_strlen($string), 'UTF-8');
58
59
        return $string;
60
    }
61
}
62
// To display the linked letter list
63
$alpha = $utility::getAlphaArray();
0 ignored issues
show
Bug introduced by
The method getAlphaArray() does not exist on XoopsModules\Wfdownloads\Utility. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
$alpha = $utility::/** @scrutinizer ignore-call */ getAlphaArray();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
$xoopsTpl->assign('alpha', $alpha);
65
66
[$howmanyother] = $xoopsDB->fetchRow($xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('lxentries') . " WHERE init = '#' AND offline ='0' " . $catperms . ' '));
67
$xoopsTpl->assign('totalother', $howmanyother);
68
69
// To display the list of categories
70
if (1 == $helper->getConfig('multicats')) {
71
    $xoopsTpl->assign('block0', $utility::getCategoryArray());
0 ignored issues
show
Bug introduced by
The method getCategoryArray() does not exist on XoopsModules\Wfdownloads\Utility. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
    $xoopsTpl->assign('block0', $utility::/** @scrutinizer ignore-call */ getCategoryArray());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
    $xoopsTpl->assign('layout', CONFIG_CATEGORY_LAYOUT_PLAIN);
0 ignored issues
show
Bug introduced by
The constant CONFIG_CATEGORY_LAYOUT_PLAIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
73
    if ($utility::getModuleOption('useshots')) {
0 ignored issues
show
Bug introduced by
The method getModuleOption() does not exist on XoopsModules\Wfdownloads\Utility. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
    if ($utility::/** @scrutinizer ignore-call */ getModuleOption('useshots')) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
74
        $xoopsTpl->assign('show_screenshot', true);
75
        $xoopsTpl->assign('logo_maximgwidth', $helper->getConfig('logo_maximgwidth'));
76
        $xoopsTpl->assign('lang_noscreenshot', _MD_LEXIKON_NOSHOTS);
0 ignored issues
show
Bug introduced by
The constant _MD_LEXIKON_NOSHOTS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
77
    } else {
78
        $xoopsTpl->assign('show_screenshot', false);
79
    }
80
}
81
82
// No initial: we need to see all letters
83
if (!$init) {
84
    $entriesarray = [];
85
    $pagetype     = 0;
86
87
    // How many entries will we show in this page?
88
    //$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";
89
    //$resultA = $xoopsDB -> query ($queryA, $helper->getConfig('indexperpage'), $start );
90
    $queryA  = 'SELECT * FROM ' . $xoopsDB->prefix('lxentries') . " WHERE offline = '0' AND submit = '0' " . $catperms . ' ORDER BY term ASC';
91
    $resultA = $xoopsDB->query($queryA, $helper->getConfig('indexperpage'), $start);
92
93
    $allentries   = $xoopsDB->query('SELECT entryID FROM ' . $xoopsDB->prefix('lxentries') . " WHERE submit ='0' AND offline = '0' " . $catperms . ' ORDER BY term ASC ');
94
    $totalentries = $xoopsDB->getRowsNum($allentries);
95
    $xoopsTpl->assign('totalentries', $totalentries);
96
97
    while (list($entryID, $categoryID, $term, $init, $definition, $ref, $url, $uid, $submit, $datesub, $counter, $html, $smiley, $xcodes, $breaks, $block, $offline, $comments) = $xoopsDB->fetchRow($resultA)) {
98
        $eachentry        = [];
99
        $xoopsModule      = XoopsModule::getByDirname('lexikon');
100
        $eachentry['dir'] = $xoopsModule->dirname();
101
102
        if (1 == $helper->getConfig('multicats')) {
103
            $eachentry['catid'] = (int)$categoryID;
104
            $resultF            = $xoopsDB->query('SELECT name FROM ' . $xoopsDB->prefix('lxcategories') . " WHERE categoryID = $categoryID ORDER BY name ASC");
105
            while (list($name) = $xoopsDB->fetchRow($resultF)) {
106
                $eachentry['catname'] = htmlspecialchars($name, ENT_QUOTES | ENT_HTML5);
107
            }
108
        }
109
110
        $eachentry['id']   = (int)$entryID;
111
        $eachentry['term'] = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5));
112
113
        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...
114
            if (0 != $comments) {
115
                $eachentry['comments'] = "<a href='entry.php?entryID=" . $eachentry['id'] . "'>" . $comments . '&nbsp;' . _COMMENTS . '</a>';
116
            } else {
117
                $eachentry['comments'] = '';
118
            }
119
        }
120
121
        if (!XOOPS_USE_MULTIBYTES) {
122
            $eachentry['definition'] = $myts->displayTarea($definition, $html, $smiley, $xcodes, 1, $breaks);
123
        }
124
125
        // Functional links
126
        $microlinks              = $utility::getServiceLinks($eachentry);
0 ignored issues
show
Bug introduced by
The method getServiceLinks() does not exist on XoopsModules\Wfdownloads\Utility. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

126
        /** @scrutinizer ignore-call */ 
127
        $microlinks              = $utility::getServiceLinks($eachentry);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
127
        $eachentry['microlinks'] = $microlinks;
128
129
        $entriesarray['single'][] = $eachentry;
130
    }
131
    $pagenav                = new \XoopsPageNav($totalentries, $helper->getConfig('indexperpage'), $start, 'start');
132
    $entriesarray['navbar'] = '<div style="text-align:right;">' . $pagenav->renderNav(6) . '</div>';
133
134
    $xoopsTpl->assign('entriesarray', $entriesarray);
135
    $xoopsTpl->assign('pagetype', '0');
136
    $xoopsTpl->assign('pageinitial', _MD_LEXIKON_ALL);
0 ignored issues
show
Bug introduced by
The constant _MD_LEXIKON_ALL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
137
138
    $utility::createPageTitle(htmlspecialchars(_MD_LEXIKON_BROWSELETTER . ' - ' . _MD_LEXIKON_ALL, ENT_QUOTES | ENT_HTML5));
0 ignored issues
show
Bug introduced by
The method createPageTitle() does not exist on XoopsModules\Wfdownloads\Utility. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

138
    $utility::/** @scrutinizer ignore-call */ 
139
              createPageTitle(htmlspecialchars(_MD_LEXIKON_BROWSELETTER . ' - ' . _MD_LEXIKON_ALL, ENT_QUOTES | ENT_HTML5));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The constant _MD_LEXIKON_BROWSELETTER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
139
} else {    // $init does exist
140
    $pagetype = 1;
141
    // There IS an initial letter, so we want to show just that letter's terms
142
    $entriesarray2 = [];
143
144
    // How many entries will we show in this page?
145
    if (_MD_LEXIKON_OTHER == $init) {
0 ignored issues
show
Bug introduced by
The constant _MD_LEXIKON_OTHER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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 = '#' " . $catperms . '  ORDER BY term ASC';
147
        $resultB = $xoopsDB->query($queryB, $helper->getConfig('indexperpage'), $start);
148
    } else {
149
        $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';
150
        $resultB = $xoopsDB->query($queryB, $helper->getConfig('indexperpage'), $start);
151
    }
152
153
    $entrieshere = $xoopsDB->getRowsNum($resultB);
154
    if (0 == $entrieshere) {
155
        redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_LEXIKON_NOTERMSINLETTER);
0 ignored issues
show
Bug introduced by
The constant _MD_LEXIKON_NOTERMSINLETTER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
156
    }
157
158
    if (_MD_LEXIKON_OTHER == $init) {
159
        $allentries = $xoopsDB->query('SELECT entryID FROM ' . $xoopsDB->prefix('lxentries') . " WHERE init = '#' AND submit ='0' AND offline = '0' " . $catperms . '  ORDER BY term ASC ');
160
    } else {
161
        $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 ');
162
    }
163
    $totalentries = $xoopsDB->getRowsNum($allentries);
164
    $xoopsTpl->assign('totalentries', $totalentries);
165
    $utility::createPageTitle(htmlspecialchars(_MD_LEXIKON_BROWSELETTER . (isset($init['init']) ? (' - ' . $init['init']) : ''), ENT_QUOTES | ENT_HTML5));
166
167
    while (list($entryID, $categoryID, $term, $definition, $uid, $html, $smiley, $xcodes, $breaks, $comments) = $xoopsDB->fetchRow($resultB)) {
168
        $eachentry        = [];
169
        $xoopsModule      = XoopsModule::getByDirname('lexikon');
170
        $eachentry['dir'] = $xoopsModule->dirname();
171
172
        if (1 == $helper->getConfig('multicats')) {
173
            $eachentry['catid'] = (int)$categoryID;
174
            $resultF            = $xoopsDB->query('SELECT name FROM ' . $xoopsDB->prefix('lxcategories') . " WHERE categoryID = $categoryID ORDER BY name ASC");
175
            while (list($name) = $xoopsDB->fetchRow($resultF)) {
176
                $eachentry['catname'] = htmlspecialchars($name, ENT_QUOTES | ENT_HTML5);
177
            }
178
        }
179
        $eachentry['id']   = (int)$entryID;
180
        $eachentry['term'] = mb_ucfirst(htmlspecialchars($term, ENT_QUOTES | ENT_HTML5));
181
        if ('#' === $init) {
182
            $eachentry['init'] = _MD_LEXIKON_OTHER;
183
        } else {
184
            $eachentry['init'] = $init;
185
        }
186
187
        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...
188
            if (0 != $comments) {
189
                $eachentry['comments'] = "<a href='entry.php?entryID=" . $eachentry['id'] . "'>" . $comments . '&nbsp;' . _COMMENTS . '</a>';
190
            } else {
191
                $eachentry['comments'] = '';
192
            }
193
        }
194
        if (!XOOPS_USE_MULTIBYTES) {
195
            $eachentry['definition'] = $myts->displayTarea($definition, $html, $smiley, $xcodes, 1, $breaks);
196
        }
197
198
        // Functional links
199
        $microlinks              = $utility::getServiceLinks($eachentry);
200
        $eachentry['microlinks'] = $microlinks;
201
202
        $entriesarray2['single'][] = $eachentry;
203
    }
204
    $pagenav                 = new \XoopsPageNav($totalentries, $helper->getConfig('indexperpage'), $start, 'init=' . $eachentry['init'] . '&start');
205
    $entriesarray2['navbar'] = '<div style="text-align:right;">' . $pagenav->renderNav(6) . '</div>';
206
207
    $xoopsTpl->assign('entriesarray2', $entriesarray2);
208
    $xoopsTpl->assign('pagetype', '1');
209
    if ('#' === $eachentry['init']) {
210
        $xoopsTpl->assign('pageinitial', _MD_LEXIKON_OTHER);
211
        $utility::createPageTitle(htmlspecialchars(_MD_LEXIKON_BROWSELETTER . ' - ' . _MD_LEXIKON_OTHER, ENT_QUOTES | ENT_HTML5));
212
    } else {
213
        $xoopsTpl->assign('pageinitial', mb_ucfirst($eachentry['init']));
214
    }
215
}
216
217
$xoopsTpl->assign('lang_modulename', $xoopsModule->name());
218
$xoopsTpl->assign('lang_moduledirname', $xoopsModule->getVar('dirname'));
219
$xoopsTpl->assign('alpha', $alpha);
220
if (1 == $helper->getConfig('syndication')) {
221
    $xoopsTpl->assign('syndication', true);
222
}
223
if ($xoopsUser) {
224
    $xoopsTpl->assign('syndication', true);
225
}
226
// Meta data
227
if (0 == $publishedwords) {
228
    $meta_description = xoops_substr($utility::convertHtml2text($eachentry['definition']), 0, 150);
229
    if (1 == $helper->getConfig('multicats')) {
230
        $utility::extractKeywords($xoopsModule->name() . ' ,' . $eachentry['term'] . ', ' . $meta_description);
0 ignored issues
show
Bug introduced by
The method extractKeywords() does not exist on XoopsModules\Wfdownloads\Utility. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

230
        $utility::/** @scrutinizer ignore-call */ 
231
                  extractKeywords($xoopsModule->name() . ' ,' . $eachentry['term'] . ', ' . $meta_description);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
231
        $utility::getMetaDescription(htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5) . ' ' . $eachentry['catname'] . ' ' . $eachentry['term']);
0 ignored issues
show
Bug introduced by
The method getMetaDescription() does not exist on XoopsModules\Wfdownloads\Utility. Did you maybe mean getMeta()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

231
        $utility::/** @scrutinizer ignore-call */ 
232
                  getMetaDescription(htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5) . ' ' . $eachentry['catname'] . ' ' . $eachentry['term']);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
232
    } else {
233
        $utility::extractKeywords(htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5) . ', ' . $eachentry['term'] . ', ' . $meta_description);
234
        $utility::getMetaDescription(htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5) . ' ' . $eachentry['term'] . ' ' . $meta_description);
235
    }
236
}
237
238
$xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" type="text/css" href="assets/css/style.css">');
239
240
require_once XOOPS_ROOT_PATH . '/footer.php';
241