Completed
Push — master ( 954431...eec6a1 )
by Michael
12s
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
/**
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 === XoopstubeUtilities::xtubeCheckGroups($cid)) {
35
        redirect_header('index.php', 1, _MD_XOOPSTUBE_MUSTREGFIRST);
36
    }
37
}
38
39
$xoopsOption['template_main'] = 'xoopstube_viewcat.tpl';
40
41
include XOOPS_ROOT_PATH . '/header.php';
42
43
$xoTheme->addStylesheet('modules/'.$moduleDirName.'/assets/css/xtubestyle.css');
44
45
global $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

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