Completed
Push — master ( b236d1...786b6e )
by Michael
05:27 queued 02:40
created

viewcat.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
// $Id: viewcat.php 11819 2013-07-09 18:21:40Z zyspec $
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                    Copyright (c) 2000 XOOPS.org                           //
6
//                       <http://www.xoops.org/>                             //
7
// ------------------------------------------------------------------------- //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
include 'header.php';
28
$myts =& MyTextSanitizer::getInstance(); // MyTextSanitizer object
29
30
include_once XOOPS_ROOT_PATH . '/class/tree.php';
31
$mylinksCatHandler =& xoops_getmodulehandler('category', $xoopsModule->getVar('dirname'));
32
$catObjs           = $mylinksCatHandler->getAll();
33
$myCatTree         = new XoopsObjectTree($catObjs, 'cid', 'pid');
34
35
include_once './class/utility.php';
36
//xoops_load('utility', $xoopsModule->getVar('dirname'));
37
38
$cid   = mylinksUtility::mylinks_cleanVars($_GET, 'cid', 0, 'int', array('min'=>0));
39
$catid = $cid;
40
41
$xoopsOption['template_main'] = 'mylinks_viewcat.html';
42
include XOOPS_ROOT_PATH . '/header.php';
43
44
//wanikoo
45
$xoTheme->addStylesheet('browse.php?' . mylinksGetStylePath('mylinks.css', 'include'));
46
$xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
47
$xoTheme->addScript('browse.php?' . mylinksGetStylePath('mylinks.js', 'include'));
48
//
49
$xoopsTpl->assign('show_nav', false);  //set to not show nav bar
50
51
$show    = mylinksUtility::mylinks_cleanVars($_GET, 'show', $xoopsModuleConfig['perpage'], 'int');
52
$min     = mylinksUtility::mylinks_cleanVars($_GET, 'min', 0, 'int');
53
$max     = (!isset($max)) ? $min + $show : $max;
54
//$orderby = mylinksUtility::mylinks_cleanVars($_GET, 'orderby', 'title ASC', 'string');
55
$orderby = mylinksUtility::mylinks_cleanVars($_GET, 'orderby', 'titleA', 'string');
56
$validSortVals = array('titleA', 'hitsA', 'ratingA', 'dateA', 'titleD', 'hitsD', 'ratingD', 'dateD');
57
$orderby = in_array($orderby, $validSortVals) ? $orderby : 'titleA';
58
59
// list
60
//TODO: need to sanitize $_GET['list']
61
if (!isset($_GET['list'])) {
62
    //wanikoo
63
    $catObj = $mylinksCatHandler->get($cid);
64
    $imgurl = '';
65
    if (is_object($catObj) && !empty($catObj)) {
66
        $thisCatTitle = $myts->htmlSpecialChars($catObj->getVar('title'));
67 View Code Duplication
        if ( $catObj->getVar('imgurl') && (($catObj->getVar('imgurl') != 'http://') && ($catObj->getVar('imgurl') != '')) ) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
            $imgurl = $myts->htmlSpecialChars($catObj->getVar('imgurl'));
69
        }
70
    } else {
71
        $thisCatTitle = '';
72
    }
73
    $thisPageTitle = $thisCatTitle;
74
    $xoopsTpl->assign('thiscategorytitle', $thisCatTitle);
75
    $xoopsTpl->assign('moremetasearch', '');
76
/*
77
    if (file_exists(XOOPS_ROOT_PATH."/include/moremetasearch.php")&&$mylinks_show_externalsearch) {
78
      include_once XOOPS_ROOT_PATH."/include/moremetasearch.php";
79
      $_REQUEST['query']= $thisCatTitle;
80
      $engineblocktitle = _MD_MYLINKS_EXTERNALSEARCH;
81
      $engineblocktitle .= sprintf(_MD_MYLINKS_EXTERNALSEARCH_KEYWORD, _MD_MYLINKS_CATEGORY, $thisCatTitle);
82
      $location_list=moremeta("meta_page","on");
83
      $metaresult = more_meta_page($location_list, $target="_blank", $display = false, $engineblocktitle);
84
      $xoopsTpl->assign('moremetasearch', "<br><br>".$metaresult);
85
    } else {
86
      $xoopsTpl->assign('moremetasearch', '');
87
    }
88
*/
89
    //feed
90
    $xoopsTpl->assign('category_id', $cid);
91
    $xoopsTpl->assign('lang_categoryfeed', _MD_MYLINKS_FEED_CAT);
92
93
    //$thisCatObj = $mylinksCatHandler->get($cid);
94
    $homePath   = "<a href='" . XOOPSMYLINKURL . "/index.php'>" . _MD_MYLINKS_MAIN . '</a>&nbsp;:&nbsp;';
95
    $itemPath   = $catObj->getVar('title');
96
    $path       = '';
97
    $myParent = $catObj->getVar('pid');
98 View Code Duplication
    while ( $myParent != 0 ) {
99
        $ancestorObj = $myCatTree->getByKey($myParent);
100
        $path  = "<a href='" . XOOPSMYLINKURL . '/viewcat.php?cid=' . $ancestorObj->getVar('cid') . "'>" . $ancestorObj->getVar('title') . "</a>&nbsp;:&nbsp;{$path}";
101
        $myParent = $ancestorObj->getVar('pid');
102
    }
103
104
    $path = "{$homePath}{$path}{$itemPath}";
105
    $path = str_replace('&nbsp;:&nbsp;', " <img src='" . mylinksGetIconURL('arrow.gif') . "' style='border-width: 0px;' alt=''> ", $path);
106
107
    $xoopsTpl->assign('category_path', $path);
108
    $xoopsTpl->assign('category_id', $cid);
109
110
    $subCatLimit = 5;
111
112
    // get all the subcats for this category
113
    $subCatObjs  = $myCatTree->getFirstChild($cid);
114
115
    $count = 1;
116
    foreach ($subCatObjs as $subCatObj) {
117
        // get 3rd level cats
118
        $gchildCatObjs = $myCatTree->getFirstChild($subCatObj->getVar('cid'));
119
        $gchildCategories = '';
120
        $subCatCount = count($gchildCatObjs);
121
        $lpLimit = min( array( $subCatLimit , $subCatCount ) );
122
        $i = 0;
123
        foreach ($gchildCatObjs as $gchildCatObj) {
124
            $gchtitle = $myts->htmlSpecialChars($gchildCatObj->getVar('title'));
125
            $gchildCategories .= ($i>0) ? ', ' : '';
126
            $gchildCategories .= "<a href='" . XOOPSMYLINKURL . '/viewcat.php?cid=' . $gchildCatObj->getVar('cid') . "'>{$gchtitle}</a>";
127
            if ($i < $lpLimit) {
128
                $i++;
129
            } else {
130
                break;
131
            }
132
        }
133
        $gchildCategories = ($subCatCount > $subCatLimit) ? $gchildCategories . '...' : $gchildCategories;
134
        $totalLinks = getTotalItems($subCatObj->getVar('cid'), 0, '>');
135
        $xoopsTpl->append('subcategories', array('image'           => '',
136
                                                 'id'              => $subCatObj->getVar('cid'),
137
                                                 'title'           => $myts->htmlSpecialChars($subCatObj->getVar('title')),
138
                                                 'infercategories' => $gchildCategories,
139
                                                 'totallinks'      => $totalLinks,
140
                                                 'count'           => $count));
141
        $count++;
142
    }
143
144
    $LinkCountResult=$xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mylinks_links') . " WHERE cid='{$cid}' AND status>0");
145
} else {
146
    $list    = $_GET['list'];
147
//    $orderby = "title ASC";
148
    $orderby = 'titleA';
149
150
    $xoopsTpl->assign('list_mode', true);
151
    //TODO:  need to filter $_GET['list'] input var
152
    $categoryPath = sprintf(_MD_MYLINKS_LINKS_LIST, $myts->htmlSpecialChars($list));
153
    $thisPageTitle = $categoryPath;
154
    $xoopsTpl->assign('category_path', $categoryPath );
155
156
    $LinkCountResult=$xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mylinks_links') . " WHERE title LIKE '" . $myts->addSlashes($_GET['list']) . "%' AND status>0");
157
}
158
$useShots = $xoopsModuleConfig['useshots'];
159 View Code Duplication
if (1 == $useShots) {
160
    $shotWidth = $xoopsModuleConfig['shotwidth'];
161
    $xoopsTpl->assign(array('shotwidth'         => $shotWidth . 'px',
162
                            //                            'tablewidth'        => ($shotWidth + 10) . "px",
163
                            'show_screenshot'   => true,
164
                            'lang_noscreenshot' => _MD_MYLINKS_NOSHOTS)
165
    );
166
} else {
167
    $xoopsTpl->assign('show_screenshot', false);
168
}
169
170
$xoopsTpl->assign('anontellafriend', $GLOBALS['xoopsModuleConfig']['anontellafriend']);
171
172
$page_nav = '';
173
list($numrows) = $xoopsDB->fetchRow($LinkCountResult);
174
175
if ( $numrows > 0 ) {
176
    $xoopsTpl->assign(array('lang_description'  => _MD_MYLINKS_DESCRIPTIONC,
177
                            'lang_lastupdate'   => _MD_MYLINKS_LASTUPDATEC ,
178
                            'lang_hits'         => _MD_MYLINKS_HITSC ,
179
                            'lang_rating'       => _MD_MYLINKS_RATINGC ,
180
                            'lang_ratethissite' => _MD_MYLINKS_RATETHISSITE ,
181
                            'lang_reportbroken' => _MD_MYLINKS_REPORTBROKEN ,
182
                            'lang_tellafriend'  => _MD_MYLINKS_TELLAFRIEND ,
183
                            'lang_modify'       => _MD_MYLINKS_MODIFY ,
184
                            'lang_category'     => _MD_MYLINKS_CATEGORYC ,
185
                            'lang_visit'        => _MD_MYLINKS_VISIT ,
186
                            'show_links'        => true ,
187
                            'lang_comments'     => _COMMENTS)
188
    );
189
190
    //if 2 or more items in result, show the sort menu
191
    if ( $numrows > 1 ) {
192
        $xoopsTpl->assign(array('show_nav'         => true,
193
                              'lang_sortby'      => _MD_MYLINKS_SORTBY,
194
                                'lang_title'       => _MD_MYLINKS_TITLE,
195
                                'lang_date'        => _MD_MYLINKS_DATE,
196
                                'lang_rating'      => _MD_MYLINKS_RATING,
197
                                'lang_popularity'  => _MD_MYLINKS_POPULARITY,
198
                                'lang_cursortedby' => sprintf(_MD_MYLINKS_CURSORTEDBY, convertorderbytrans(convertorderbyin($orderby))))
199
        );
200
    }
201
202
    if (!isset($_GET['list'])) {
203
        $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 '
204
               . $xoopsDB->prefix('mylinks_links') . ' l, '
205
               . $xoopsDB->prefix('mylinks_text') . ' t '
206
               . "WHERE cid='{$cid}' AND l.lid=t.lid AND status>0 "
207
               . 'ORDER BY ' . convertorderbyin($orderby) . '';
208
    } else {
209
        $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 '
210
               . $xoopsDB->prefix('mylinks_links') . ' l, '
211
               . $xoopsDB->prefix('mylinks_text') . ' t '
212
               . "WHERE l.title LIKE '" . $myts->addSlashes($_GET['list']) . "%' AND l.lid=t.lid AND status>0 "
213
               . 'ORDER BY ' . convertorderbyin($orderby) . '';
214
    }
215
    $shotAttribution = '';
216
    $result=$xoopsDB->query($sql, $show, $min);
217
    while (list($lid, $cid, $ltitle, $url, $logourl, $status, $time, $hits, $rating, $votes, $comments, $description) = $xoopsDB->fetchRow($result)) {
218 View Code Duplication
        if (!empty($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) {
219
            $isadmin = true;
220
            $adminlink = "<a href='" . XOOPSMYLINKURL . "/admin/main.php?op=modLink&amp;lid={$lid}'><img src='" . mylinksGetIconURL('edit.png') . "' style='border-width: 0px;' alt='" . _MD_MYLINKS_EDITTHISLINK . "'></a>";
221
        } else {
222
            $isadmin = false;
223
            $adminlink = '';
224
        }
225
        $votestring = (1 == $votes) ? _MD_MYLINKS_ONEVOTE : sprintf(_MD_MYLINKS_NUMVOTES, $votes);
226
        $thisCatObj = $mylinksCatHandler->get($cid);
227
        $homePath   = "<a href='" . XOOPSMYLINKURL . "/index.php'>" . _MD_MYLINKS_MAIN . '</a>&nbsp;:&nbsp;';
228
        $itemPath   = $thisCatObj->getVar('title');
229
        $path       = '';
230
        $myParent = $thisCatObj->getVar('pid');
231 View Code Duplication
        while ( $myParent != 0 ) {
232
            $ancestorObj = $myCatTree->getByKey($myParent);
233
            $path  = "<a href='" . XOOPSMYLINKURL . '/viewcat.php?cid=' . $ancestorObj->getVar('cid') . "'>" . $ancestorObj->getVar('title') . "</a>&nbsp;:&nbsp;{$path}";
234
            $myParent = $ancestorObj->getVar('pid');
235
        }
236
237
        $path = "{$homePath}{$path}{$itemPath}";
238
        $path = str_replace('&nbsp;:&nbsp;', " <img src='" . mylinksGetIconURL('arrow.gif') . "' style='border-width: 0px;' alt=''> ", $path);
239
        $new = newlinkgraphic($time, $status);
240
        $pop = popgraphic($hits);
241
        //by wanikoo
242
        /* setup shot provider information */
243
        $shotImgSrc = $shotImgHref = '';
244 View Code Duplication
        if ($useShots) {
245
            $shotProvider = mb_strtolower($xoopsModuleConfig['shotprovider']);
246
            $shotImgHref = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/visit.php?cid={$cid}&amp;lid={$lid}";
247
            $logourl = trim($logourl);
248
            if (!empty($logourl)) {
249
                if (file_exists(XOOPSMYLINKIMGPATH . "/{$mylinks_theme}")) {
250
                    $shotImgSrc = XOOPSMYLINKIMGURL . "/{$mylinks_theme}/shots/" . $myts->htmlSpecialChars($logourl);
251
                } else {
252
                    $shotImgSrc = XOOPSMYLINKIMGURL . '/shots/' . $myts->htmlSpecialChars($logourl);
253
                }
254
            } elseif (_NONE != $shotProvider) {
255
                if (file_exists(XOOPS_ROOT_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $xoopsModule->getVar('dirname') . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'providers' . DIRECTORY_SEPARATOR . mb_strtolower($shotProvider) . '.php')) {
256
                    include_once XOOPS_ROOT_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $xoopsModule->getVar('dirname') . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'providers' . DIRECTORY_SEPARATOR . mb_strtolower($shotProvider) . '.php';
257
                    $shotClass = ucfirst($xoopsModule->getVar('dirname')) . ucfirst($shotProvider);
258
                    $shotObj = new $shotClass;
259
                    $shotObj->setProviderPublicKey($xoopsModuleConfig['shotpubkey']);
260
                    $shotObj->setProviderPrivateKey($xoopsModuleConfig['shotprivkey']);
261
                    $shotObj->setShotSize(array('width' => $xoopsModuleConfig['shotwidth']));
262
                    $shotObj->setSiteUrl($myts->htmlSpecialChars($url));
263
                    $shotImgSrc = $shotObj->getProviderUrl();
264
                    if ($xoopsModuleConfig['shotattribution']) {
265
                        if ('' == $shotAttribution) {
266
                            $shotAttribution = $shotObj->getAttribution(true);
267
                        }
268
                    } else {
269
                        $shotAttribution = '';
270
                    }
271
                }
272
            }
273
        }
274
        $xoopsTpl->assign('shot_attribution', $shotAttribution);
275
        $xoopsTpl->append('links', array('url'           => $myts->htmlSpecialChars($url),
276
                                         'id'            => $lid,
277
                                         'cid'           => $cid,
278
                                         'rating'        => number_format($rating, 2),
279
                                         'ltitle'        => $myts->htmlSpecialChars($myts->stripSlashesGPC($ltitle)),
280
                                         'title'         => $myts->htmlSpecialChars($myts->stripSlashesGPC($ltitle)).$new.$pop,
281
                                         'category'      => $path,
282
                                         'logourl'       => $myts->htmlSpecialChars(trim($logourl)),
283
                                         'updated'       => formatTimestamp($time, 'm'),
284
                                         'description'   => $myts->displayTarea($myts->stripSlashesGPC($description), 0),
285
                                         'adminlink'     => $adminlink,
286
                                         'hits'          => $hits,
287
                                         'comments'      => $comments,
288
                                         'votes'         => $votestring,
289
                                         'mail_subject'  => rawurlencode(sprintf(_MD_MYLINKS_INTRESTLINK, $xoopsConfig['sitename'])),
290
                                         'mail_body'     => rawurlencode(sprintf(_MD_MYLINKS_INTLINKFOUND, $xoopsConfig['sitename']).':  '.XOOPSMYLINKURL.'/singlelink.php?cid='.$cid.'&lid='.$lid),
291
                                         'shot_img_src'  => $shotImgSrc,
292
                                         'shot_img_href' => $shotImgHref)
293
        );
294
    }
295
  //  $orderby = convertorderbyout($orderby);
296
    // for navi in case of list
297
    $cid = $catid;
298
    // new navi
299
    include_once XOOPSMYLINKPATH . '/class/mylinkspagenav.php';
300
    if (!isset($_GET['list'])) {
301
        $mylinksnav = new MylinksPageNav($numrows, $show, $min, 'min', "cid={$cid}&amp;orderby={$orderby}&amp;show={$show}");
302
    } else {
303
        $mylinksnav = new MylinksPageNav($numrows, $show, $min, 'min', "list={$list}&amp;orderby={$orderby}&amp;show={$show}");
304
    }
305
    $page_nav = $mylinksnav->renderNav($offset = 5);
306
} else {
307
    $xoopsTpl->assign('show_links', false);
308
}
309
$xoopsTpl->assign('page_nav', $page_nav);
310
311
//wanikoo theme changer
312
$xoopsTpl->assign('lang_themechanger', _MD_MYLINKS_THEMECHANGER);
313
$mymylinkstheme_options = '';
314
315 View Code Duplication
foreach ($GLOBALS['mylinks_allowed_theme'] as $mymylinkstheme) {
316
    $mymylinkstheme_options .= "<option value='{$mymylinkstheme}'";
317
    if ($mymylinkstheme == $GLOBALS['mylinks_theme']) {
318
        $mymylinkstheme_options .= " selected='selected'";
319
    }
320
    $mymylinkstheme_options .= ">{$mymylinkstheme}</option>";
321
}
322
323
$mylinkstheme_select = "<select name='mylinks_theme_select' onchange='submit();' size='1'>{$mymylinkstheme_options}</select>";
324
325
$xoopsTpl->assign('mylinksthemeoption', $mylinkstheme_select);
326
//wanikoo end
327
328
//wanikoo search
329 View Code Duplication
if ( file_exists(XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/search.php') ) {
330
   include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/search.php';
331
} else {
332
   include_once XOOPS_ROOT_PATH . '/language/english/search.php';
333
}
334
$xoopsTpl->assign('lang_all', _SR_ALL);
335
$xoopsTpl->assign('lang_any', _SR_ANY);
336
$xoopsTpl->assign('lang_exact', _SR_EXACT);
337
$xoopsTpl->assign('lang_search', _SR_SEARCH);
338
$xoopsTpl->assign('module_id', $xoopsModule->getVar('mid'));
339
//category head
340
$catarray = array();
341
if ( $mylinks_show_letters ) {
342
    $catarray['letters'] = ml_wfd_letters();
343
}
344
if ( $mylinks_show_toolbar ) {
345
    $catarray['toolbar'] = ml_wfd_toolbar();
346
}
347
$xoopsTpl->assign('catarray', $catarray);
348
//pagetitle (module name - category)
349
$xoopsTpl->assign('xoops_pagetitle', $xoopsModule->getVar('name').' - '.$thisPageTitle);
350
//category jump box
351
$catjumpbox = "<form name='catjumpbox' method='get' action='viewcat.php'>\n"
352
              . '  <strong>' . _MD_MYLINKS_CATEGORYC . "</strong>&nbsp;\n"
353
              . '  ' . $myCatTree->makeSelBox('cid', 'title', ' - ', $cid) . "\n"
354
       ."  &nbsp;<input type='submit' value='" . _SUBMIT . "'>\n</form>\n";
355
$xoopsTpl->assign('mylinksjumpbox', $catjumpbox);
356
357
include_once XOOPSMYLINKPATH . '/footer.php';
358