Completed
Branch master (ddc2b8)
by Michael
02:46
created

viewcat.php (2 issues)

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
/**
4
 * Module: XoopsTube
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * PHP version 5
11
 *
12
 * @category        Module
13
 * @package         Xoopstube
14
 * @author          XOOPS Development Team
15
 * @copyright       2001-2016 XOOPS Project (http://xoops.org)
16
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
17
 * @link            http://xoops.org/
18
 * @since           1.0.6
19
 */
20
21
include __DIR__ . '/header.php';
22
23
// Begin Main page Heading etc
24
$cid        = XoopsRequest::getInt('cid', 0, 'GET'); //xtubeCleanRequestVars($_REQUEST, 'cid', 0);
25
$selectdate = XoopsRequest::getString('selectdate', ''); //xtubeCleanRequestVars($_REQUEST, 'selectdate', '');
26
$list       = XoopsRequest::getString('list', '');// xtubeCleanRequestVars($_REQUEST, 'list', '');
27
$start      = XoopsRequest::getInt('start', 0, 'GET'); //xtubeCleanRequestVars($_REQUEST, 'start', 0);
28
29
$catsort = $GLOBALS['xoopsModuleConfig']['sortcats'];
30
$mytree  = new XoopstubeTree($GLOBALS['xoopsDB']->prefix('xoopstube_cat'), 'cid', 'pid');
31
$arr     = $mytree->getFirstChild($cid, $catsort);
32
33
if (is_array($arr) > 0 && !$list && !$selectdate) {
34
    if (false === XoopstubeUtility::xtubeCheckGroups($cid)) {
35
        redirect_header('index.php', 1, _MD_XOOPSTUBE_MUSTREGFIRST);
36
    }
37
}
38
39
$GLOBALS['xoopsOption']['template_main'] = 'xoopstube_viewcat.tpl';
40
41
include XOOPS_ROOT_PATH . '/header.php';
42
$xoTheme->addStylesheet('modules/'.$moduleDirName.'/assets/css/xtubestyle.css');
43
global $xoopsModule;
44
$catarray['letters']     = XoopstubeUtility::xtubeGetLetters();
45
//$catarray['letters']     = XoopstubeUtility::xoopstubeLettersChoice();
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
$catarray['imageheader'] = XoopstubeUtility::xtubeRenderImageHeader();
47
$xoopsTpl->assign('catarray', $catarray);
48
49
//$catArray['letters'] = XoopstubeUtility::xtubeLettersChoice();
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
//$catArray['letters'] = XoopstubeUtility::xoopstubeLettersChoice();
51
//$catArray['toolbar'] = xoopstube_toolbar();
52
//$xoopsTpl->assign('catarray', $catArray);
53
54
// Breadcrumb
55
$pathstring = '<li><a href="index.php">' . _MD_XOOPSTUBE_MAIN . '</a></li>';
56
$pathstring .= $mytree->getNicePathFromId($cid, 'title', 'viewcat.php?op=');
57
$xoopsTpl->assign('category_path', $pathstring);
58
$xoopsTpl->assign('category_id', $cid);
59
60
// Display Sub-categories for selected Category
61
if (is_array($arr) > 0 && !$list && !$selectdate) {
62
    $scount = 1;
63
    foreach ($arr as $ele) {
64
        if (false === XoopstubeUtility::xtubeCheckGroups($ele['cid'])) {
65
            continue;
66
        }
67
        $sub_arr         = array();
68
        $sub_arr         = $mytree->getFirstChild($ele['cid'], $catsort);
69
        $space           = 1;
70
        $chcount         = 1;
71
        $infercategories = '';
72 View Code Duplication
        foreach ($sub_arr as $sub_ele) {
73
            // Subitem file count
74
            $hassubitems = XoopstubeUtility::xtubeGetTotalItems($sub_ele['cid']);
75
            // Filter group permissions
76
            if (true === XoopstubeUtility::xtubeCheckGroups($sub_ele['cid'])) {
77
                // If subcategory count > 5 then finish adding subcats to $infercategories and end
78
                if ($chcount > 5) {
79
                    $infercategories .= '...';
80
                    break;
81
                }
82
                if ($space > 0) {
83
                    $infercategories .= ', ';
84
                }
85
86
                $infercategories .= '<a href="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewcat.php?cid=' . $sub_ele['cid'] . '">' . $xtubemyts->htmlSpecialCharsStrip($sub_ele['title']) . '</a> (' . $hassubitems['count'] . ')';
87
                ++$space;
88
                ++$chcount;
89
            }
90
        }
91
        $totalvideos = XoopstubeUtility::xtubeGetTotalItems($ele['cid']);
92
        $indicator   = XoopstubeUtility::xtubeIsNewImage($totalvideos['published']);
93
94
        // This code is copyright WF-Projects
95
        // Using this code without our permission or removing this code voids the license agreement
96
97
        $_image = $ele['imgurl'] ? urldecode($ele['imgurl']) : '';
98 View Code Duplication
        if ($_image !== '' && $GLOBALS['xoopsModuleConfig']['usethumbs']) {
99
            $_thumb_image = new XtubeThumbsNails($_image, $GLOBALS['xoopsModuleConfig']['catimage'], 'thumbs');
100
            if ($_thumb_image) {
101
                $_thumb_image->setUseThumbs(1);
102
                $_thumb_image->setImageType('gd2');
103
                $_image = $_thumb_image->createThumbnail($GLOBALS['xoopsModuleConfig']['shotwidth'], $GLOBALS['xoopsModuleConfig']['shotheight'], $GLOBALS['xoopsModuleConfig']['imagequality'], $GLOBALS['xoopsModuleConfig']['updatethumbs'], $GLOBALS['xoopsModuleConfig']['imageAspect']);
104
            }
105
        }
106
107 View Code Duplication
        if (empty($_image) || '' == $_image) {
108
            $imgurl  = $indicator['image'];
109
            $_width  = 33;
110
            $_height = 24;
111
        } else {
112
            $imgurl  = "{$GLOBALS['xoopsModuleConfig']['catimage']}/$_image";
113
            $_width  = $GLOBALS['xoopsModuleConfig']['shotwidth'];
114
            $_height = $GLOBALS['xoopsModuleConfig']['shotheight'];
115
        }
116
        /*
117
        * End
118
        */
119
120
        $xoopsTpl->append('subcategories', array(
121
            'title'           => $xtubemyts->htmlSpecialCharsStrip($ele['title']),
122
            'id'              => $ele['cid'],
123
            'image'           => XOOPS_URL . "/$imgurl",
124
            'width'           => $_width,
125
            'height'          => $_height,
126
            'infercategories' => $infercategories,
127
            'totalvideos'     => $totalvideos['count'],
128
            'count'           => $scount,
129
            'alttext'         => $ele['description']
130
        ));
131
        ++$scount;
132
    }
133
}
134
135
// Show Description for Category listing
136
$sql         = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_cat') . ' WHERE cid=' . (int)$cid;
137
$head_arr    = $GLOBALS['xoopsDB']->fetchArray($GLOBALS['xoopsDB']->query($sql));
138
$html        = $head_arr['nohtml'] ? 0 : 1;
139
$smiley      = $head_arr['nosmiley'] ? 0 : 1;
140
$xcodes      = $head_arr['noxcodes'] ? 0 : 1;
141
$images      = $head_arr['noimages'] ? 0 : 1;
142
$breaks      = $head_arr['nobreak'] ? 1 : 0;
143
$description =& $xtubemyts->displayTarea($head_arr['description'], $html, $smiley, $xcodes, $images, $breaks);
144
$xoopsTpl->assign('description', $description);
145
/** @var XoopsModuleHandler $moduleHandler */
146
$moduleHandler = xoops_getHandler('module');
147
$versioninfo   = $moduleHandler->get($xoopsModule->getVar('mid'));
148
if ($head_arr['title'] > '') {
149
    $xoopsTpl->assign('xoops_pagetitle', $versioninfo->getInfo('name') . ':&nbsp;' . $head_arr['title']);
150
} else {
151
    $xoopsTpl->assign('xoops_pagetitle', $versioninfo->getInfo('name'));
152
}
153
154
if ($head_arr['client_id'] > 0) {
155
    $catarray['imageheader'] = XoopstubeUtility::xtubeGetBannerFromClientId($head_arr['client_id']);
156
} elseif ($head_arr['banner_id'] > 0) {
157
    $catarray['imageheader'] = XoopstubeUtility::xtubeGetBannerFromBannerId($head_arr['banner_id']);
158
} else {
159
    $catarray['imageheader'] = XoopstubeUtility::xtubeRenderImageHeader();
160
}
161
$xoopsTpl->assign('catarray', $catarray);
162
// Extract linkload information from database
163
$xoopsTpl->assign('show_categort_title', true);
164
165
$orderby0 = (isset($_REQUEST['orderby'])
166
             && !empty($_REQUEST['orderby'])) ? XoopstubeUtility::xtubeConvertOrderByIn(htmlspecialchars($_REQUEST['orderby'])) : XoopstubeUtility::xtubeConvertOrderByIn($GLOBALS['xoopsModuleConfig']['linkxorder']);
167
$orderby  = XoopsRequest::getString('orderby', '', 'GET') ? XoopstubeUtility::xtubeConvertOrderByIn(XoopsRequest::getString('orderby', '', 'GET')) : XoopstubeUtility::xtubeConvertOrderByIn($GLOBALS['xoopsModuleConfig']['linkxorder']);
168
169
if ($selectdate) {
170
    $d = date('j', $selectdate);
171
    $m = date('m', $selectdate);
172
    $y = date('Y', $selectdate);
173
174
    $stat_begin = mktime(0, 0, 0, $m, $d, $y);
175
    $stat_end   = mktime(23, 59, 59, $m, $d, $y);
176
177
    $query  = ' WHERE published>=' . $stat_begin . ' AND published<=' . $stat_end . ' AND (expired=0 OR expired>' . time() . ') AND offline=0 AND cid>0';
178
    $sql    = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . $query . ' ORDER BY ' . $orderby;
179
    $result = $GLOBALS['xoopsDB']->query($sql, $GLOBALS['xoopsModuleConfig']['perpage'], $start);
180
181
    $sql = 'SELECT COUNT(*) FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . $query;
182
    list($count) = $GLOBALS['xoopsDB']->fetchRow($GLOBALS['xoopsDB']->query($sql));
183
184
    $list_by = 'selectdate=' . $selectdate;
185
186
    $xoopsTpl->assign('is_selectdate', true);
187
    $xoopsTpl->assign('selected_date', XoopstubeUtility::xtubeGetTimestamp(formatTimestamp($selectdate, $GLOBALS['xoopsModuleConfig']['dateformat'])));
188
189
} elseif ($list) {
190
    $query = " WHERE title LIKE '$list%' AND (published>0 AND published<=" . time() . ') AND (expired=0 OR expired>' . time() . ') AND offline=0 AND cid>0';
191
192
    $sql    = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . $query . ' ORDER BY ' . $orderby;
193
    $result = $GLOBALS['xoopsDB']->query($sql, $GLOBALS['xoopsModuleConfig']['perpage'], $start);
194
195
    $sql = 'SELECT COUNT(*) FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . $query;
196
    list($count) = $GLOBALS['xoopsDB']->fetchRow($GLOBALS['xoopsDB']->query($sql));
197
    $list_by = "list=$list";
198
} else {
199
    $query = 'WHERE a.published>0 AND a.published<=' . time() . ' AND (a.expired=0 OR a.expired>' . time() . ') AND a.offline=0' . ' AND (b.cid=a.cid OR (a.cid=' . $cid . ' OR b.cid=' . $cid . '))';
200
201
    $sql    = 'SELECT DISTINCT a.* FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . ' a LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('xoopstube_altcat') . ' b ON b.lid=a.lid ' . $query . ' ORDER BY ' . $orderby;
202
    $result = $GLOBALS['xoopsDB']->query($sql, $GLOBALS['xoopsModuleConfig']['perpage'], $start);
203
204
    $sql2 = 'SELECT COUNT(*) FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . ' a LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('xoopstube_altcat') . ' b ON b.lid=a.lid ' . $query;
205
    list($count) = $GLOBALS['xoopsDB']->fetchRow($GLOBALS['xoopsDB']->query($sql2));
206
    $order   = XoopstubeUtility::xtubeConvertOrderByOut($orderby);
207
    $list_by = 'cid=' . $cid . '&orderby=' . $order;
208
    $xoopsTpl->assign('show_categort_title', false);
209
}
210
$pagenav = new XoopsPageNav($count, $GLOBALS['xoopsModuleConfig']['perpage'], $start, 'start', $list_by);
211
212
// Show videos
213
if ($count > 0) {
214
    $moderate = 0;
215
    while (false !== ($video_arr = $GLOBALS['xoopsDB']->fetchArray($result))) {
216
        if (true === XoopstubeUtility::xtubeCheckGroups($video_arr['cid'])) {
217
            require XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/include/videoloadinfo.php';
218
            $xoopsTpl->append('video', $video);
219
        }
220
    }
221
222
    unset($video_arr);
223
224
    // Show order box
225
    $xoopsTpl->assign('show_videos', false);
226
    if ($count > 1 && $cid !== 0) {
227
        $xoopsTpl->assign('show_videos', true);
228
        $orderbyTrans = XoopstubeUtility::xtubeConvertOrderByTrans($orderby);
229
        $xoopsTpl->assign('lang_cursortedby', sprintf(_MD_XOOPSTUBE_CURSORTBY, XoopstubeUtility::xtubeConvertOrderByTrans($orderby)));
230
        $orderby = XoopstubeUtility::xtubeConvertOrderByOut($orderby);
231
    }
232
233
    // Screenshots display
234
    $xoopsTpl->assign('show_screenshot', false);
235 View Code Duplication
    if (isset($GLOBALS['xoopsModuleConfig']['screenshot']) && $GLOBALS['xoopsModuleConfig']['screenshot'] == 1) {
236
        $xoopsTpl->assign('shotwidth', $GLOBALS['xoopsModuleConfig']['shotwidth']);
237
        $xoopsTpl->assign('shotheight', $GLOBALS['xoopsModuleConfig']['shotheight']);
238
        $xoopsTpl->assign('show_screenshot', true);
239
    }
240
241
    // Nav page render
242
    $page_nav = $pagenav->renderNav();
243
    $istrue   = (isset($page_nav) && !empty($page_nav)) ? true : false;
244
    $xoopsTpl->assign('page_nav', $istrue);
245
    $xoopsTpl->assign('pagenav', $page_nav);
246
    $xoopsTpl->assign('module_dir', $xoopsModule->getVar('dirname'));
247
}
248
249
$xoopsTpl->assign('cat_columns', $GLOBALS['xoopsModuleConfig']['catcolumns']);
250
251
include XOOPS_ROOT_PATH . '/footer.php';
252