Completed
Push — master ( ee521d...91b0ad )
by Michael
01:55
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        = wfl_cleanRequestVars($_REQUEST, 'cid', 0);
14
$selectdate = wfl_cleanRequestVars($_REQUEST, 'selectdate', '');
15
$list       = wfl_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 == wfl_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 (wfl_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 = wfl_getTotalItems($sub_ele['cid']);
55
            // Filter group permissions
56
            if (true == wfl_checkgroups($sub_ele['cid'])) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
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 = wfl_getTotalItems($ele['cid']);
71
        $indicator  = wfl_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
            if ($_thumb_image) {
79
                $_thumb_image->setUseThumbs(1);
80
                $_thumb_image->setImageType('gd2');
81
                $_image = $_thumb_image->do_thumb($xoopsModuleConfig['shotwidth'], $xoopsModuleConfig['shotheight'], $xoopsModuleConfig['imagequality'], $xoopsModuleConfig['updatethumbs'], $xoopsModuleConfig['keepaspect']);
82
            }
83
        }
84
        if (empty($_image) || $_image === '') {
85
            $imgurl = $indicator['image'];
86
        } else {
87
            $imgurl = "{$xoopsModuleConfig['catimage']}/$_image";
88
        }
89
        // End
90
        $xoopsTpl->append('subcategories', array(
91
            'title'           => $wfmyts->htmlSpecialCharsStrip($ele['title']),
92
            'id'              => $ele['cid'],
93
            'image'           => XOOPS_URL . "/$imgurl",
94
            'infercategories' => $infercategories,
95
            'totallinks'      => $totallinks['count'],
96
            'count'           => $scount,
97
            'alttext'         => $ele['description']
98
        ));
99
        ++$scount;
100
    }
101
}
102
103
// Show Description for Category listing
104
$sql      = 'SELECT title, description, nohtml, nosmiley, noxcodes, noimages, nobreak, imgurl, client_id, banner_id FROM ' . $xoopsDB->prefix('wflinks_cat') . ' WHERE cid =' . $cid;
105
$head_arr = $xoopsDB->fetchArray($xoopsDB->query($sql));
106
$html     = $head_arr['nohtml'] ? 0 : 1;
107
$smiley   = $head_arr['nosmiley'] ? 0 : 1;
108
$xcodes   = $head_arr['noxcodes'] ? 0 : 1;
109
$images   = $head_arr['noimages'] ? 0 : 1;
110
$breaks   = $head_arr['nobreak'] ? 1 : 0;
111
112
$description = $wfmyts->displayTarea($head_arr['description'], $html, $smiley, $xcodes, $images, $breaks);
113
$xoopsTpl->assign('description', $description);
114
$xoopsTpl->assign('xoops_pagetitle', $head_arr['title']);
115
//$xoopsTpl -> assign( 'client_banner', wfl_getbanner_from_id_client($head_arr['client_id']) );
116
117
if ($head_arr['client_id'] > 0) {
118
    $catarray['imageheader'] = wfl_getbanner_from_id_client($head_arr['client_id']);
119
} elseif ($head_arr['banner_id'] > 0) {
120
    $catarray['imageheader'] = wfl_getbanner_from_id_banner($head_arr['banner_id']);
121
} else {
122
    $catarray['imageheader'] = wfl_imageheader();
123
}
124
$catarray['letters'] = wfl_letters();
125
$catarray['toolbar'] = wfl_toolbar();
126
$xoopsTpl->assign('catarray', $catarray);
127
128
// Extract linkload information from database
129
$xoopsTpl->assign('show_categort_title', true);
130
131
$start   = wfl_cleanRequestVars($_REQUEST, 'start', 0);
132
$orderby = (isset($_REQUEST['orderby'])
133
            && !empty($_REQUEST['orderby'])) ? wfl_convertorderbyin(htmlspecialchars($_REQUEST['orderby'])) : wfl_convertorderbyin($xoopsModuleConfig['linkxorder']);
134
135
if ($selectdate) {
136
    $d = date('j', $selectdate);
137
    $m = date('m', $selectdate);
138
    $y = date('Y', $selectdate);
139
140
    $stat_begin = mktime(0, 0, 0, $m, $d, $y);
141
    $stat_end   = mktime(23, 59, 59, $m, $d, $y);
142
143
    $query = ' WHERE published >= ' . $stat_begin . ' AND published <= ' . $stat_end . '
144
        AND (expired = 0 OR expired > ' . $time . ')
145
        AND offline = 0
146
        AND cid > 0';
147
148
    $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('wflinks_links') . $query . ' ORDER BY ' . $orderby;
149
    $result = $xoopsDB->query($sql, $xoopsModuleConfig['perpage'], $start);
150
151
    $sql = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('wflinks_links') . $query;
152
    list($count) = $xoopsDB->fetchRow($xoopsDB->query($sql));
153
154
    $list_by = 'selectdate=' . $selectdate;
155
} elseif ($list) {
156
    $query = " WHERE title LIKE '$list%' AND (published > 0 AND published <= " . $time . ') AND (expired = 0 OR expired > ' . $time . ') AND offline = 0 AND cid > 0';
157
158
    $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('wflinks_links') . $query . ' ORDER BY ' . $orderby;
159
    $result = $xoopsDB->query($sql, $xoopsModuleConfig['perpage'], $start);
160
161
    $sql = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('wflinks_links') . $query;
162
    list($count) = $xoopsDB->fetchRow($xoopsDB->query($sql));
163
    $list_by = 'list=' . $list;
164
} else {
165
    $sql    = 'SELECT DISTINCT a.* FROM '
166
              . $xoopsDB->prefix('wflinks_links')
167
              . ' a LEFT JOIN '
168
              . $xoopsDB->prefix('wflinks_altcat')
169
              . ' b '
170
              . ' ON b.lid = a.lid'
171
              . ' WHERE a.published > 0 AND a.published <= '
172
              . $time
173
              . ' AND (a.expired = 0 OR a.expired > '
174
              . $time
175
              . ') AND a.offline = 0'
176
              . ' AND (b.cid=a.cid OR (a.cid='
177
              . $cid
178
              . ' OR b.cid='
179
              . $cid
180
              . '))'
181
              . ' ORDER BY '
182
              . $orderby;
183
    $result = $xoopsDB->query($sql, $xoopsModuleConfig['perpage'], $start);
184
    $xoopsTpl->assign('show_categort_title', false);
185
186
    $sql2 = 'SELECT COUNT(*) FROM '
187
            . $xoopsDB->prefix('wflinks_links')
188
            . ' a LEFT JOIN '
189
            . $xoopsDB->prefix('wflinks_altcat')
190
            . ' b '
191
            . ' ON b.lid = a.lid'
192
            . ' WHERE a.published > 0 AND a.published <= '
193
            . $time
194
            . ' AND (a.expired = 0 OR a.expired > '
195
            . $time
196
            . ') AND a.offline = 0'
197
            . ' AND (b.cid=a.cid OR (a.cid='
198
            . $cid
199
            . ' OR b.cid='
200
            . $cid
201
            . '))';
202
    list($count) = $xoopsDB->fetchRow($xoopsDB->query($sql2));
203
    $order   = wfl_convertorderbyout($orderby);
204
    $cid     = $cid;
205
    $list_by = 'cid=' . $cid . '&orderby=' . $order;
206
}
207
$pagenav  = new XoopsPageNav($count, $xoopsModuleConfig['perpage'], $start, 'start', $list_by);
208
$page_nav = $pagenav->renderNav();
209
$istrue   = (isset($page_nav) && !empty($page_nav));
210
$xoopsTpl->assign('page_nav', $istrue);
211
$xoopsTpl->assign('pagenav', $page_nav);
212
$xoopsTpl->assign('module_dir', $xoopsModule->getVar('dirname'));
213
214
// Show links
215
if ($count > 0) {
216
    $moderate = 0;
217
    while ($link_arr = $xoopsDB->fetchArray($result)) {
218
        $res_type = 0;
219
        require XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/include/linkloadinfo.php';
220
        $xoopsTpl->append('wfllink', $link);
221
    }
222
223
    // Show order box
224
    $xoopsTpl->assign('show_links', false);
225
    if ($count > 1 && $cid != 0) {
226
        $xoopsTpl->assign('show_links', true);
227
        $orderbyTrans = wfl_convertorderbytrans($orderby);
228
        $xoopsTpl->assign('lang_cursortedby', sprintf(_MD_WFL_CURSORTBY, wfl_convertorderbytrans($orderby)));
229
        $orderby = wfl_convertorderbyout($orderby);
230
    }
231
232
    // Screenshots display
233
    $xoopsTpl->assign('show_screenshot', false);
234
    if (isset($xoopsModuleConfig['screenshot']) && $xoopsModuleConfig['screenshot'] == 1) {
235
        $xoopsTpl->assign('shots_dir', $xoopsModuleConfig['screenshots']);
236
        $xoopsTpl->assign('shotwidth', $xoopsModuleConfig['shotwidth']);
237
        $xoopsTpl->assign('shotheight', $xoopsModuleConfig['shotheight']);
238
        $xoopsTpl->assign('show_screenshot', true);
239
    }
240
}
241
unset($link_arr);
242
243
include XOOPS_ROOT_PATH . '/footer.php';
244