Completed
Push — master ( 9ae314...b50459 )
by Michael
01:45
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
/**
3
 * File: viewcat.php
4
 * Module: WF-Links
5
 * Developer: John N
6
 * Team: WF-Projects
7
 * Licence: GNU
8
 */
9
10
require_once __DIR__ . '/header.php';
11
12
// Begin Main page Heading etc
13
$cid        = WfLinksUtility::cleanRequestVars($_REQUEST, 'cid', 0);
14
$selectdate = WfLinksUtility::cleanRequestVars($_REQUEST, 'selectdate', '');
15
$list       = WfLinksUtility::cleanRequestVars($_REQUEST, 'list', '');
16
$cid        = (int)$cid;
17
$catsort    = $xoopsModuleConfig['sortcats'];
18
19
$mytree = new WflinksXoopsTree($xoopsDB->prefix('wflinks_cat'), 'cid', 'pid');
20
$arr    = $mytree->getFirstChild($cid, $catsort);
21
22
if (is_array($arr) > 0 && !$list && !$selectdate) {
23
    if (false === WfLinksUtility::checkGroups($cid)) {
24
        redirect_header('index.php', 1, _MD_WFL_MUSTREGFIRST);
25
    }
26
}
27
$GLOBALS['xoopsOption']['template_main'] = 'wflinks_viewcat.tpl';
28
include XOOPS_ROOT_PATH . '/header.php';
29
30
global $xoopsModuleConfig;
31
32
// Breadcrumb
33
$pathstring = '<a href="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/index.php">' . _MD_WFL_MAIN . '</a>&nbsp;:&nbsp;';
34
$pathstring .= $mytree->getNicePathFromId($cid, 'title', 'viewcat.php?op=');
35
$xoopsTpl->assign('category_path', $pathstring);
36
$xoopsTpl->assign('category_id', $cid);
37
38
$time = time();
39
40
// Display Sub-categories for selected Category
41
if (is_array($arr) > 0 && !$list && !$selectdate) {
42
    $scount = 1;
43
    foreach ($arr as $ele) {
44
        if (WfLinksUtility::checkGroups($ele['cid']) === false) {
45
            continue;
46
        }
47
        $sub_arr         = array();
48
        $sub_arr         = $mytree->getFirstChild($ele['cid'], 'title');
49
        $space           = 1;
50
        $chcount         = 1;
51
        $infercategories = '';
52
        foreach ($sub_arr as $sub_ele) {
53
            // Subitem file count
54
            $hassubitems = WfLinksUtility::getTotalItems($sub_ele['cid']);
55
            // Filter group permissions
56
            if (true === WfLinksUtility::checkGroups($sub_ele['cid'])) {
57
                // If subcategory count > 5 then finish adding subcats to $infercategories and end
58
                if ($chcount > 5) {
59
                    $infercategories .= '...';
60
                    break;
61
                }
62
                if ($space > 0) {
63
                    $infercategories .= ', ';
64
                }
65
                $infercategories .= "<a href='" . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewcat.php?cid=' . $sub_ele['cid'] . "'>" . $wfmyts->htmlSpecialCharsStrip($sub_ele['title']) . '</a> (' . $hassubitems['count'] . ')';
66
                ++$space;
67
                ++$chcount;
68
            }
69
        }
70
        $totallinks = WfLinksUtility::getTotalItems($ele['cid']);
71
        $indicator  = WfLinksUtility::isNewImage($totallinks['published']);
72
73
        // This code is copyright WF-Projects
74
        // Using this code without our permission or removing this code voids the license agreement
75
        $_image = $ele['imgurl'] ? urldecode($ele['imgurl']) : '';
76
        if ($_image !== '' && $xoopsModuleConfig['usethumbs']) {
77
            $_thumb_image = new WfThumbsNails($_image, $xoopsModuleConfig['catimage'], 'thumbs');
78 View Code Duplication
            if ($_thumb_image) {
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...
79
                $_thumb_image->setUseThumbs(1);
80
                $_thumb_image->setImageType('gd2');
81
                $_image = $_thumb_image->createThumb($xoopsModuleConfig['shotwidth'], $xoopsModuleConfig['shotheight'], $xoopsModuleConfig['imagequality'], $xoopsModuleConfig['updatethumbs'], $xoopsModuleConfig['keepaspect']);
82
            }
83
        }
84
        $imgurl = "{$xoopsModuleConfig['catimage']}/$_image";
85
        if (empty($_image) || $_image === '') {
86
            $imgurl = $indicator['image'];
87
        }
88
        // End
89
        $xoopsTpl->append('subcategories', array(
90
            'title'           => $wfmyts->htmlSpecialCharsStrip($ele['title']),
91
            'id'              => $ele['cid'],
92
            'image'           => XOOPS_URL . "/$imgurl",
93
            'infercategories' => $infercategories,
94
            'totallinks'      => $totallinks['count'],
95
            'count'           => $scount,
96
            'alttext'         => $ele['description']
97
        ));
98
        ++$scount;
99
    }
100
}
101
102
// Show Description for Category listing
103
$sql      = 'SELECT title, description, nohtml, nosmiley, noxcodes, noimages, nobreak, imgurl, client_id, banner_id FROM ' . $xoopsDB->prefix('wflinks_cat') . ' WHERE cid =' . $cid;
104
$head_arr = $xoopsDB->fetchArray($xoopsDB->query($sql));
105
$html     = $head_arr['nohtml'] ? 0 : 1;
106
$smiley   = $head_arr['nosmiley'] ? 0 : 1;
107
$xcodes   = $head_arr['noxcodes'] ? 0 : 1;
108
$images   = $head_arr['noimages'] ? 0 : 1;
109
$breaks   = $head_arr['nobreak'] ? 1 : 0;
110
111
$description = $wfmyts->displayTarea($head_arr['description'], $html, $smiley, $xcodes, $images, $breaks);
112
$xoopsTpl->assign('description', $description);
113
$xoopsTpl->assign('xoops_pagetitle', $head_arr['title']);
114
//$xoopsTpl -> assign( 'client_banner', WfLinksUtility::getBannerFromIdClient($head_arr['client_id']) );
115
116
if ($head_arr['client_id'] > 0) {
117
    $catarray['imageheader'] = WfLinksUtility::getBannerFromIdClient($head_arr['client_id']);
118
} elseif ($head_arr['banner_id'] > 0) {
119
    $catarray['imageheader'] = WfLinksUtility::getBannerFromIdBanner($head_arr['banner_id']);
120
} else {
121
    $catarray['imageheader'] = WfLinksUtility::getImageHeader();
122
}
123
$catarray['letters'] = WfLinksUtility::getLetters();
124
$catarray['toolbar'] = WfLinksUtility::getToolbar();
125
$xoopsTpl->assign('catarray', $catarray);
126
127
// Extract linkload information from database
128
$xoopsTpl->assign('show_categort_title', true);
129
130
$start   = WfLinksUtility::cleanRequestVars($_REQUEST, 'start', 0);
131
$orderby = (isset($_REQUEST['orderby'])
132
            && !empty($_REQUEST['orderby'])) ? WfLinksUtility::convertOrderByIn(htmlspecialchars($_REQUEST['orderby'])) : WfLinksUtility::convertOrderByIn($xoopsModuleConfig['linkxorder']);
133
134
if ($selectdate) {
135
    $d = date('j', $selectdate);
136
    $m = date('m', $selectdate);
137
    $y = date('Y', $selectdate);
138
139
    $stat_begin = mktime(0, 0, 0, $m, $d, $y);
140
    $stat_end   = mktime(23, 59, 59, $m, $d, $y);
141
142
    $query = ' WHERE published >= ' . $stat_begin . ' AND published <= ' . $stat_end . '
143
        AND (expired = 0 OR expired > ' . $time . ')
144
        AND offline = 0
145
        AND cid > 0';
146
147
    $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('wflinks_links') . $query . ' ORDER BY ' . $orderby;
148
    $result = $xoopsDB->query($sql, $xoopsModuleConfig['perpage'], $start);
149
150
    $sql = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('wflinks_links') . $query;
151
    list($count) = $xoopsDB->fetchRow($xoopsDB->query($sql));
152
153
    $list_by = 'selectdate=' . $selectdate;
154
} elseif ($list) {
155
    $query = " WHERE title LIKE '$list%' AND (published > 0 AND published <= " . $time . ') AND (expired = 0 OR expired > ' . $time . ') AND offline = 0 AND cid > 0';
156
157
    $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('wflinks_links') . $query . ' ORDER BY ' . $orderby;
158
    $result = $xoopsDB->query($sql, $xoopsModuleConfig['perpage'], $start);
159
160
    $sql = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('wflinks_links') . $query;
161
    list($count) = $xoopsDB->fetchRow($xoopsDB->query($sql));
162
    $list_by = 'list=' . $list;
163
} else {
164
    $sql    = 'SELECT DISTINCT a.* FROM '
165
              . $xoopsDB->prefix('wflinks_links')
166
              . ' a LEFT JOIN '
167
              . $xoopsDB->prefix('wflinks_altcat')
168
              . ' b '
169
              . ' ON b.lid = a.lid'
170
              . ' WHERE a.published > 0 AND a.published <= '
171
              . $time
172
              . ' AND (a.expired = 0 OR a.expired > '
173
              . $time
174
              . ') AND a.offline = 0'
175
              . ' AND (b.cid=a.cid OR (a.cid='
176
              . $cid
177
              . ' OR b.cid='
178
              . $cid
179
              . '))'
180
              . ' ORDER BY '
181
              . $orderby;
182
    $result = $xoopsDB->query($sql, $xoopsModuleConfig['perpage'], $start);
183
    $xoopsTpl->assign('show_categort_title', false);
184
185
    $sql2 = 'SELECT COUNT(*) FROM '
186
            . $xoopsDB->prefix('wflinks_links')
187
            . ' a LEFT JOIN '
188
            . $xoopsDB->prefix('wflinks_altcat')
189
            . ' b '
190
            . ' ON b.lid = a.lid'
191
            . ' WHERE a.published > 0 AND a.published <= '
192
            . $time
193
            . ' AND (a.expired = 0 OR a.expired > '
194
            . $time
195
            . ') AND a.offline = 0'
196
            . ' AND (b.cid=a.cid OR (a.cid='
197
            . $cid
198
            . ' OR b.cid='
199
            . $cid
200
            . '))';
201
    list($count) = $xoopsDB->fetchRow($xoopsDB->query($sql2));
202
    $order   = WfLinksUtility::convertOrderByOut($orderby);
203
    $cid     = $cid;
204
    $list_by = 'cid=' . $cid . '&orderby=' . $order;
205
}
206
$pagenav  = new XoopsPageNav($count, $xoopsModuleConfig['perpage'], $start, 'start', $list_by);
207
$page_nav = $pagenav->renderNav();
208
$istrue   = (isset($page_nav) && !empty($page_nav));
209
$xoopsTpl->assign('page_nav', $istrue);
210
$xoopsTpl->assign('pagenav', $page_nav);
211
$xoopsTpl->assign('module_dir', $xoopsModule->getVar('dirname'));
212
213
// Show links
214
if ($count > 0) {
215
    $moderate = 0;
216
    while ($link_arr = $xoopsDB->fetchArray($result)) {
217
        $res_type = 0;
218
        require XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/include/linkloadinfo.php';
219
        $xoopsTpl->append('wfllink', $link);
220
    }
221
222
    // Show order box
223
    $xoopsTpl->assign('show_links', false);
224
    if ($count > 1 && $cid != 0) {
225
        $xoopsTpl->assign('show_links', true);
226
        $orderbyTrans = WfLinksUtility::convertOrderByTrans($orderby);
227
        $xoopsTpl->assign('lang_cursortedby', sprintf(_MD_WFL_CURSORTBY, WfLinksUtility::convertOrderByTrans($orderby)));
228
        $orderby = WfLinksUtility::convertOrderByOut($orderby);
229
    }
230
231
    // Screenshots display
232
    $xoopsTpl->assign('show_screenshot', false);
233
    if (isset($xoopsModuleConfig['screenshot']) && $xoopsModuleConfig['screenshot'] == 1) {
234
        $xoopsTpl->assign('shots_dir', $xoopsModuleConfig['screenshots']);
235
        $xoopsTpl->assign('shotwidth', $xoopsModuleConfig['shotwidth']);
236
        $xoopsTpl->assign('shotheight', $xoopsModuleConfig['shotheight']);
237
        $xoopsTpl->assign('show_screenshot', true);
238
    }
239
}
240
unset($link_arr);
241
242
include XOOPS_ROOT_PATH . '/footer.php';
243