Passed
Pull Request — master (#9)
by Michael
03:24
created

viewcat.php (4 issues)

1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team
18
 */
19
20
use XoopsModules\Mylinks;
21
use XoopsModules\Mylinks\Utility;
22
23
require_once __DIR__ . '/header.php';
24
$myts = \MyTextSanitizer::getInstance(); // MyTextSanitizer object
25
/** @var Mylinks\Helper $helper */
26
$helper = Mylinks\Helper::getInstance();
27
28
require_once XOOPS_ROOT_PATH . '/class/tree.php';
29
$categoryHandler = $helper->getHandler('Category');
30
$catObjs           = $categoryHandler->getAll();
31
$myCatTree         = new \XoopsObjectTree($catObjs, 'cid', 'pid');
32
33
//xoops_load('utility', $xoopsModule->getVar('dirname'));
34
35
$cid   = Mylinks\Utility::cleanVars($_GET, 'cid', 0, 'int', ['min' => 0]);
0 ignored issues
show
'cid' of type string is incompatible with the type XoopsModules\Mylinks\unknown_type expected by parameter $key of XoopsModules\Mylinks\Utility::cleanVars(). ( Ignorable by Annotation )

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

35
$cid   = Mylinks\Utility::cleanVars($_GET, /** @scrutinizer ignore-type */ 'cid', 0, 'int', ['min' => 0]);
Loading history...
36
$catid = $cid;
37
38
$GLOBALS['xoopsOption']['template_main'] = 'mylinks_viewcat.tpl';
39
require_once XOOPS_ROOT_PATH . '/header.php';
40
41
//wanikoo
42
$xoTheme->addStylesheet('browse.php?' . Utility::getStylePath('mylinks.css', 'include'));
43
$xoTheme->addScript('browse.php?' . Utility::getStylePath('mylinks.js', 'include'));
44
45
$xoopsTpl->assign('show_nav', false);  //set to not show nav bar
46
47
$show = Mylinks\Utility::cleanVars($_GET, 'show', $helper->getConfig('perpage'), 'int');
48
$min  = Mylinks\Utility::cleanVars($_GET, 'min', 0, 'int');
49
$max  = !isset($max) ? $min + $show : $max;
50
//$orderby = Mylinks\Utility::cleanVars($_GET, 'orderby', 'title ASC', 'string');
51
$orderby       = Mylinks\Utility::cleanVars($_GET, 'orderby', 'titleA', 'string');
52
$validSortVals = ['titleA', 'hitsA', 'ratingA', 'dateA', 'titleD', 'hitsD', 'ratingD', 'dateD'];
53
$orderby       = in_array($orderby, $validSortVals) ? $orderby : 'titleA';
54
55
// list
56
//TODO: need to sanitize $_GET['list']
57
if (!isset($_GET['list'])) {
58
    //wanikoo
59
    $catObj = $categoryHandler->get($cid);
60
    $imgurl = '';
61
    if (is_object($catObj) && !empty($catObj)) {
62
        $thisCatTitle = $myts->htmlSpecialChars($catObj->getVar('title'));
63
        if ($catObj->getVar('imgurl')
64
            && (('http://' !== $catObj->getVar('imgurl'))
65
                && ('' != $catObj->getVar('imgurl')))) {
66
            $imgurl = $myts->htmlSpecialChars($catObj->getVar('imgurl'));
67
        }
68
    } else {
69
        $thisCatTitle = '';
70
    }
71
    $thisPageTitle = $thisCatTitle;
72
    $xoopsTpl->assign('thiscategorytitle', $thisCatTitle);
73
    $xoopsTpl->assign('moremetasearch', '');
74
    /*
75
        if (file_exists(XOOPS_ROOT_PATH."/include/moremetasearch.php")&&$mylinks_show_externalsearch) {
76
          require_once XOOPS_ROOT_PATH."/include/moremetasearch.php";
77
          $_REQUEST['query']= $thisCatTitle;
78
          $engineblocktitle = _MD_MYLINKS_EXTERNALSEARCH;
79
          $engineblocktitle .= sprintf(_MD_MYLINKS_EXTERNALSEARCH_KEYWORD, _MD_MYLINKS_CATEGORY, $thisCatTitle);
80
          $location_list=moremeta("meta_page","on");
81
          $metaresult = more_meta_page($location_list, $target="_blank", $display = false, $engineblocktitle);
82
          $xoopsTpl->assign('moremetasearch', "<br><br>".$metaresult);
83
        } else {
84
          $xoopsTpl->assign('moremetasearch', '');
85
        }
86
    */
87
    //feed
88
    $xoopsTpl->assign('category_id', $cid);
89
    $xoopsTpl->assign('lang_categoryfeed', _MD_MYLINKS_FEED_CAT);
90
91
    //$thisCatObj = $categoryHandler->get($cid);
92
    $homePath = "<a href='" . XOOPSMYLINKURL . "/index.php'>" . _MD_MYLINKS_MAIN . '</a>&nbsp;:&nbsp;';
93
    $itemPath = $catObj->getVar('title');
94
    $path     = '';
95
    $myParent = $catObj->getVar('pid');
96
    while (0 != $myParent) {
97
        $ancestorObj = $myCatTree->getByKey($myParent);
98
        $path        = "<a href='" . XOOPSMYLINKURL . '/viewcat.php?cid=' . $ancestorObj->getVar('cid') . "'>" . $ancestorObj->getVar('title') . "</a>&nbsp;:&nbsp;{$path}";
99
        $myParent    = $ancestorObj->getVar('pid');
100
    }
101
102
    $path = "{$homePath}{$path}{$itemPath}";
103
    $path = str_replace('&nbsp;:&nbsp;', " <img src='" . Utility::getIconURL('arrow.gif') . "' style='border-width: 0px;' alt=''> ", $path);
104
105
    $xoopsTpl->assign('category_path', $path);
106
    $xoopsTpl->assign('category_id', $cid);
107
108
    $subCatLimit = 5;
109
110
    // get all the subcats for this category
111
    $subCatObjs = $myCatTree->getFirstChild($cid);
112
113
    $count = 1;
114
    foreach ($subCatObjs as $subCatObj) {
115
        // get 3rd level cats
116
        $gchildCatObjs    = $myCatTree->getFirstChild($subCatObj->getVar('cid'));
117
        $gchildCategories = '';
118
        $subCatCount      = count($gchildCatObjs);
119
        $lpLimit          = min([$subCatLimit, $subCatCount]);
120
        $i                = 0;
121
        foreach ($gchildCatObjs as $gchildCatObj) {
122
            $gchtitle         = $myts->htmlSpecialChars($gchildCatObj->getVar('title'));
123
            $gchildCategories .= ($i > 0) ? ', ' : '';
124
            $gchildCategories .= "<a href='" . XOOPSMYLINKURL . '/viewcat.php?cid=' . $gchildCatObj->getVar('cid') . "'>{$gchtitle}</a>";
125
            if ($i < $lpLimit) {
126
                ++$i;
127
            } else {
128
                break;
129
            }
130
        }
131
        $gchildCategories = ($subCatCount > $subCatLimit) ? $gchildCategories . '...' : $gchildCategories;
132
        $totalLinks       = Utility::getTotalItems($subCatObj->getVar('cid'), 0, '>');
133
        $xoopsTpl->append(
134
            'subcategories',
135
            [
136
                'image'           => '',
137
                'id'              => $subCatObj->getVar('cid'),
138
                'title'           => $myts->htmlSpecialChars($subCatObj->getVar('title')),
139
                'infercategories' => $gchildCategories,
140
                'totallinks'      => $totalLinks,
141
                'count'           => $count,
142
            ]
143
        );
144
        ++$count;
145
    }
146
147
    $LinkCountResult = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mylinks_links') . " WHERE cid='{$cid}' AND status>0");
148
} else {
149
    $list = $_GET['list'];
150
    //    $orderby = "title ASC";
151
    $orderby = 'titleA';
152
153
    $xoopsTpl->assign('list_mode', true);
154
    //TODO:  need to filter $_GET['list'] input var
155
    $categoryPath  = sprintf(_MD_MYLINKS_LINKS_LIST, $myts->htmlSpecialChars($list));
156
    $thisPageTitle = $categoryPath;
157
    $xoopsTpl->assign('category_path', $categoryPath);
158
159
    $LinkCountResult = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mylinks_links') . " WHERE title LIKE '" . $myts->addSlashes($_GET['list']) . "%' AND STATUS>0");
160
}
161
$useShots = $helper->getConfig('useshots');
162
if (1 == $useShots) {
163
    $shotWidth = $helper->getConfig('shotwidth');
164
    $xoopsTpl->assign(
165
        [
166
            'shotwidth'         => $shotWidth . 'px',
167
            //                            'tablewidth'        => ($shotWidth + 10) . "px",
168
            'show_screenshot'   => true,
169
            'lang_noscreenshot' => _MD_MYLINKS_NOSHOTS,
170
        ]
171
    );
172
} else {
173
    $xoopsTpl->assign('show_screenshot', false);
174
}
175
176
$xoopsTpl->assign('anontellafriend', $GLOBALS['xoopsModuleConfig']['anontellafriend']);
177
178
$page_nav = '';
179
list($numrows) = $xoopsDB->fetchRow($LinkCountResult);
180
181
if ($numrows > 0) {
182
    $xoopsTpl->assign(
183
        [
184
            'lang_description'  => _MD_MYLINKS_DESCRIPTIONC,
185
            'lang_lastupdate'   => _MD_MYLINKS_LASTUPDATEC,
186
            'lang_hits'         => _MD_MYLINKS_HITSC,
187
            'lang_rating'       => _MD_MYLINKS_RATINGC,
188
            'lang_ratethissite' => _MD_MYLINKS_RATETHISSITE,
189
            'lang_reportbroken' => _MD_MYLINKS_REPORTBROKEN,
190
            'lang_tellafriend'  => _MD_MYLINKS_TELLAFRIEND,
191
            'lang_modify'       => _MD_MYLINKS_MODIFY,
192
            'lang_category'     => _MD_MYLINKS_CATEGORYC,
193
            'lang_visit'        => _MD_MYLINKS_VISIT,
194
            'show_links'        => true,
195
            'lang_comments'     => _COMMENTS,
196
        ]
197
    );
198
199
    //if 2 or more items in result, show the sort menu
200
    if ($numrows > 1) {
201
        $xoopsTpl->assign(
202
            [
203
                'show_nav'         => true,
204
                'lang_sortby'      => _MD_MYLINKS_SORTBY,
205
                'lang_title'       => _MD_MYLINKS_TITLE,
206
                'lang_date'        => _MD_MYLINKS_DATE,
207
                'lang_rating'      => _MD_MYLINKS_RATING,
208
                'lang_popularity'  => _MD_MYLINKS_POPULARITY,
209
                'lang_cursortedby' => sprintf(_MD_MYLINKS_CURSORTEDBY, convertorderbytrans(convertorderbyin($orderby))),
0 ignored issues
show
The function convertorderbyin was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

209
                'lang_cursortedby' => sprintf(_MD_MYLINKS_CURSORTEDBY, convertorderbytrans(/** @scrutinizer ignore-call */ convertorderbyin($orderby))),
Loading history...
The function convertorderbytrans was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

209
                'lang_cursortedby' => sprintf(_MD_MYLINKS_CURSORTEDBY, /** @scrutinizer ignore-call */ convertorderbytrans(convertorderbyin($orderby))),
Loading history...
210
            ]
211
        );
212
    }
213
214
    if (!isset($_GET['list'])) {
215
        $sql = 'SELECT l.lid, l.cid, l.title, l.url, l.logourl, l.status, l.date, l.hits, l.rating, l.votes, l.comments, t.description FROM '
216
               . $xoopsDB->prefix('mylinks_links')
217
               . ' l, '
218
               . $xoopsDB->prefix('mylinks_text')
219
               . ' t '
220
               . "WHERE cid='{$cid}' AND l.lid=t.lid AND status>0 "
221
               . 'ORDER BY '
222
               . convertorderbyin($orderby)
223
               . '';
224
    } else {
225
        $sql = 'SELECT l.lid, l.cid, l.title, l.url, l.logourl, l.status, l.date, l.hits, l.rating, l.votes, l.comments, t.description FROM '
226
               . $xoopsDB->prefix('mylinks_links')
227
               . ' l, '
228
               . $xoopsDB->prefix('mylinks_text')
229
               . ' t '
230
               . "WHERE l.title LIKE '"
231
               . $myts->addSlashes($_GET['list'])
232
               . "%' AND l.lid=t.lid AND STATUS>0 "
233
               . 'ORDER BY '
234
               . convertorderbyin($orderby)
235
               . '';
236
    }
237
    $shotAttribution = '';
238
    $result          = $xoopsDB->query($sql, $show, $min);
239
    while (list($lid, $cid, $ltitle, $url, $logourl, $status, $time, $hits, $rating, $votes, $comments, $description) = $xoopsDB->fetchRow($result)) {
240
        if (!empty($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) {
241
            $isadmin   = true;
242
            $adminlink = "<a href='" . XOOPSMYLINKURL . "/admin/main.php?op=modLink&amp;lid={$lid}'><img src='" . Utility::getIconURL('edit.png') . "' style='border-width: 0px;' alt='" . _MD_MYLINKS_EDITTHISLINK . "'></a>";
243
        } else {
244
            $isadmin   = false;
245
            $adminlink = '';
246
        }
247
        $votestring = (1 == $votes) ? _MD_MYLINKS_ONEVOTE : sprintf(_MD_MYLINKS_NUMVOTES, $votes);
248
        $thisCatObj = $categoryHandler->get($cid);
249
        $homePath   = "<a href='" . XOOPSMYLINKURL . "/index.php'>" . _MD_MYLINKS_MAIN . '</a>&nbsp;:&nbsp;';
250
        $itemPath   = $thisCatObj->getVar('title');
251
        $path       = '';
252
        $myParent   = $thisCatObj->getVar('pid');
253
        while (0 != $myParent) {
254
            $ancestorObj = $myCatTree->getByKey($myParent);
255
            $path        = "<a href='" . XOOPSMYLINKURL . '/viewcat.php?cid=' . $ancestorObj->getVar('cid') . "'>" . $ancestorObj->getVar('title') . "</a>&nbsp;:&nbsp;{$path}";
256
            $myParent    = $ancestorObj->getVar('pid');
257
        }
258
259
        $path = "{$homePath}{$path}{$itemPath}";
260
        $path = str_replace('&nbsp;:&nbsp;', " <img src='" . Utility::getIconURL('arrow.gif') . "' style='border-width: 0px;' alt=''> ", $path);
261
        $new  = Utility::newLinkGraphic($time, $status);
262
        $pop  = Utility::popGraphic($hits);
263
        //by wanikoo
264
        /* setup shot provider information */
265
        $shotImgSrc = $shotImgHref = '';
266
        if ($useShots) {
267
            $shotProvider = mb_strtolower($helper->getConfig('shotprovider'));
268
            $shotImgHref  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/visit.php?cid={$cid}&amp;lid={$lid}";
269
            $logourl      = trim($logourl);
270
            if (!empty($logourl)) {
271
                if (file_exists(XOOPSMYLINKIMGPATH . "/{$mylinks_theme}")) {
272
                    $shotImgSrc = XOOPSMYLINKIMGURL . "/{$mylinks_theme}/shots/" . $myts->htmlSpecialChars($logourl);
273
                } else {
274
                    $shotImgSrc = XOOPSMYLINKIMGURL . '/shots/' . $myts->htmlSpecialChars($logourl);
275
                }
276
            } elseif (_NONE != $shotProvider) {
277
                if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/class/Providers/' . mb_strtolower($shotProvider) . '.php')) {
278
                    //                    require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/class/providers/' . mb_strtolower($shotProvider) . '.php';
279
                    $shotClass = ucfirst($xoopsModule->getVar('dirname')) . ucfirst($shotProvider);
280
                    $shotObj   = new $shotClass();
281
                    $shotObj->setProviderPublicKey($helper->getConfig('shotpubkey'));
282
                    $shotObj->setProviderPrivateKey($helper->getConfig('shotprivkey'));
283
                    $shotObj->setShotSize(['width' => $helper->getConfig('shotwidth')]);
284
                    $shotObj->setSiteUrl($myts->htmlSpecialChars($url));
285
                    $shotImgSrc = $shotObj->getProviderUrl();
286
                    if ($helper->getConfig('shotattribution')) {
287
                        if ('' == $shotAttribution) {
288
                            $shotAttribution = $shotObj->getAttribution(true);
289
                        }
290
                    } else {
291
                        $shotAttribution = '';
292
                    }
293
                }
294
            }
295
        }
296
        $xoopsTpl->assign('shot_attribution', $shotAttribution);
297
        $xoopsTpl->append(
298
            'links',
299
            [
300
                'url'           => $myts->htmlSpecialChars($url),
301
                'id'            => $lid,
302
                'cid'           => $cid,
303
                'rating'        => number_format($rating, 2),
304
                'ltitle'        => $myts->htmlSpecialChars($myts->stripSlashesGPC($ltitle)),
305
                'title'         => $myts->htmlSpecialChars($myts->stripSlashesGPC($ltitle)) . $new . $pop,
306
                'category'      => $path,
307
                'logourl'       => $myts->htmlSpecialChars(trim($logourl)),
308
                'updated'       => formatTimestamp($time, 'm'),
309
                'description'   => $myts->displayTarea($myts->stripSlashesGPC($description), 0),
310
                'adminlink'     => $adminlink,
311
                'hits'          => $hits,
312
                'comments'      => $comments,
313
                'votes'         => $votestring,
314
                'mail_subject'  => rawurlencode(sprintf(_MD_MYLINKS_INTRESTLINK, $xoopsConfig['sitename'])),
315
                'mail_body'     => rawurlencode(sprintf(_MD_MYLINKS_INTLINKFOUND, $xoopsConfig['sitename']) . ':  ' . XOOPSMYLINKURL . '/singlelink.php?cid=' . $cid . '&lid=' . $lid),
316
                'shot_img_src'  => $shotImgSrc,
317
                'shot_img_href' => $shotImgHref,
318
            ]
319
        );
320
    }
321
    //  $orderby = convertorderbyout($orderby);
322
    // for navi in case of list
323
    $cid = $catid;
324
    // new navi
325
    //    require_once XOOPSMYLINKPATH . '/class/mylinkspagenav.php';
326
    if (!isset($_GET['list'])) {
327
        $mylinksnav = new Mylinks\PageNav($numrows, $show, $min, 'min', "cid={$cid}&amp;orderby={$orderby}&amp;show={$show}");
328
    } else {
329
        $mylinksnav = new Mylinks\PageNav($numrows, $show, $min, 'min', "list={$list}&amp;orderby={$orderby}&amp;show={$show}");
330
    }
331
    $page_nav = $mylinksnav->renderNav($offset = 5);
332
} else {
333
    $xoopsTpl->assign('show_links', false);
334
}
335
$xoopsTpl->assign('page_nav', $page_nav);
336
337
//wanikoo theme changer
338
$xoopsTpl->assign('lang_themechanger', _MD_MYLINKS_THEMECHANGER);
339
$mymylinkstheme_options = '';
340
341
foreach ($GLOBALS['mylinks_allowed_theme'] as $mymylinkstheme) {
342
    $mymylinkstheme_options .= "<option value='{$mymylinkstheme}'";
343
    if ($mymylinkstheme == $GLOBALS['mylinks_theme']) {
344
        $mymylinkstheme_options .= ' selected';
345
    }
346
    $mymylinkstheme_options .= ">{$mymylinkstheme}</option>";
347
}
348
349
$mylinkstheme_select = "<select name='mylinks_theme_select' onchange='submit();' size='1'>{$mymylinkstheme_options}</select>";
350
351
$xoopsTpl->assign('mylinksthemeoption', $mylinkstheme_select);
352
//wanikoo end
353
354
//wanikoo search
355
if (file_exists(XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/search.php')) {
356
    require_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/search.php';
357
} else {
358
    require_once XOOPS_ROOT_PATH . '/language/english/search.php';
359
}
360
$xoopsTpl->assign('lang_all', _SR_ALL);
361
$xoopsTpl->assign('lang_any', _SR_ANY);
362
$xoopsTpl->assign('lang_exact', _SR_EXACT);
363
$xoopsTpl->assign('lang_search', _SR_SEARCH);
364
$xoopsTpl->assign('module_id', $xoopsModule->getVar('mid'));
365
//category head
366
$catarray = [];
367
if ($mylinks_show_letters) {
368
    $catarray['letters'] = Utility::letters();
369
}
370
if ($mylinks_show_toolbar) {
371
    $catarray['toolbar'] = Utility::toolbar();
372
}
373
$xoopsTpl->assign('catarray', $catarray);
374
//pagetitle (module name - category)
375
$xoopsTpl->assign('xoops_pagetitle', $xoopsModule->getVar('name') . ' - ' . $thisPageTitle);
376
//category jump box
377
$catjumpbox = "<form name='catjumpbox' method='get' action='viewcat.php'>\n" . '  <strong>' . _MD_MYLINKS_CATEGORYC . "</strong>&nbsp;\n" . '  ' . $myCatTree->makeSelBox('cid', 'title', ' - ', $cid) . "\n" . "  &nbsp;<input type='submit' value='" . _SUBMIT . "'>\n</form>\n";
0 ignored issues
show
Deprecated Code introduced by
The function XoopsObjectTree::makeSelBox() has been deprecated: since 2.5.9, please use makeSelectElement() ( Ignorable by Annotation )

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

377
$catjumpbox = "<form name='catjumpbox' method='get' action='viewcat.php'>\n" . '  <strong>' . _MD_MYLINKS_CATEGORYC . "</strong>&nbsp;\n" . '  ' . /** @scrutinizer ignore-deprecated */ $myCatTree->makeSelBox('cid', 'title', ' - ', $cid) . "\n" . "  &nbsp;<input type='submit' value='" . _SUBMIT . "'>\n</form>\n";

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
378
$xoopsTpl->assign('mylinksjumpbox', $catjumpbox);
379
380
require_once XOOPSMYLINKPATH . '/footer.php';
381