Passed
Push — master ( 396afe...6672c5 )
by Goffy
22:30 queued 19:01
created

viewcat.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * TDMDownload
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright   Gregory Mage (Aka Mage)
16
 * @license     GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @author      Gregory Mage (Aka Mage)
18
 */
19
20
use XoopsModules\Tdmdownloads\{
21
    Helper,
22
    Tree
23
};
24
25
require_once __DIR__ . '/header.php';
26
$moduleDirName = basename(__DIR__);
27
$helper = Helper::getInstance();
28
// template d'affichage
29
$GLOBALS['xoopsOption']['template_main'] = 'tdmdownloads_viewcat.tpl';
30
require_once XOOPS_ROOT_PATH . '/header.php';
31
/** @var \xos_opal_Theme $xoTheme */
32
$xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/styles.css', null);
33
$cid = \Xmf\Request::getInt('cid', 0, 'REQUEST');
34
// pour les permissions
35
$categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName);
36
// redirection si la catégorie n'existe pas
37
$criteria = new \CriteriaCompo();
38
$criteria->add(new \Criteria('cat_cid', $cid));
39
if (0 === $cid || 0 === $categoryHandler->getCount($criteria)) {
40
    redirect_header('index.php', 3, _MD_TDMDOWNLOADS_CAT_NONEXISTENT);
41
}
42
// pour les permissions (si pas de droit, redirection)
43
if (!in_array($cid, $categories)) {
44
    redirect_header('index.php', 2, _NOPERM);
45
}
46
//tableau des catégories
47
$criteria = new \CriteriaCompo();
48
$criteria->setSort('cat_weight ASC, cat_title');
49
$criteria->setOrder('ASC');
50
$criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN'));
51
$downloadscatArray = $categoryHandler->getAll($criteria);
52
$mytree            = new Tree($downloadscatArray, 'cat_cid', 'cat_pid');
53
//tableau des téléchargements
54
$criteria = new \CriteriaCompo();
55
$criteria->add(new \Criteria('status', 0, '!='));
56
$criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN'));
57
$downloadsArray = $downloadsHandler->getAll($criteria);
58
$xoopsTpl->assign('lang_thereare', sprintf(_MD_TDMDOWNLOADS_INDEX_THEREARE, count($downloadsArray)));
59
//navigation
60
$navCategory = $utility::getPathTreeUrl($mytree, $cid, $downloadscatArray, 'cat_title', $prefix = ' <img src="assets/images/deco/arrow.gif" alt="arrow"> ', true, 'ASC');
61
$xoopsTpl->assign('category_path', $navCategory);
62
// info catégorie
63
$xoopsTpl->assign('category_id', $cid);
64
$cat_info = $categoryHandler->get($cid);
65
$xoopsTpl->assign('cat_description', $cat_info->getVar('cat_description_main'));
66
$uploadurl      = XOOPS_URL . '/uploads/' . $moduleDirName . '/images/cats/';
67
$categoryObject = $categoryHandler->get($cid);
68
$tempCategory   = [
69
    'image'            => $cat_info->getVar('cat_imgurl'),
70
    'id'               => $cat_info->getVar('cat_cid'),
71
    'title'            => $cat_info->getVar('cat_title'),
72
    'description_main' => $cat_info->getVar('cat_description_main'),
73
];
74
if (!empty($tempCategory['image'])) {
75
    $tempCategory['image'] = $uploadurl . $tempCategory['image'];
76
}
77
$xoopsTpl->assign('category', $tempCategory);
78
//affichage des catégories
79
$xoopsTpl->assign('nb_catcol', $helper->getConfig('nb_catcol'));
80
$count    = 1;
81
$keywords = '';
82
foreach (array_keys($downloadscatArray) as $i) {
83
    /** @var \XoopsModules\Tdmdownloads\Category[] $downloadscatArray */
84
    if ($downloadscatArray[$i]->getVar('cat_pid') == $cid) {
85
        $totaldownloads    = $utility->getNumbersOfEntries($mytree, $categories, $downloadsArray, $downloadscatArray[$i]->getVar('cat_cid'));
86
        $subcategories_arr = $mytree->getFirstChild($downloadscatArray[$i]->getVar('cat_cid'));
0 ignored issues
show
It seems like $downloadscatArray[$i]->getVar('cat_cid') can also be of type array and array; however, parameter $key of XoopsObjectTree::getFirstChild() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

86
        $subcategories_arr = $mytree->getFirstChild(/** @scrutinizer ignore-type */ $downloadscatArray[$i]->getVar('cat_cid'));
Loading history...
87
        $chcount           = 0;
88
        $subcategories     = '';
89
        //pour les mots clef
90
        $keywords .= $downloadscatArray[$i]->getVar('cat_title') . ',';
91
        foreach (array_keys($subcategories_arr) as $j) {
92
            /** @var \XoopsModules\Tdmdownloads\Category[] $subcategories_arr */
93
            if ($chcount >= $helper->getConfig('nbsouscat')) {
94
                $subcategories .= '<li>[<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $downloadscatArray[$i]->getVar('cat_cid') . '">+</a>]</li>';
95
                break;
96
            }
97
            $subcategories .= '<li><a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $subcategories_arr[$j]->getVar('cat_cid') . '">' . $subcategories_arr[$j]->getVar('cat_title') . '</a></li>';
98
            $keywords      .= $downloadscatArray[$i]->getVar('cat_title') . ',';
99
            ++$chcount;
100
        }
101
        $xoopsTpl->append('subcategories', [
102
            'image'            => $uploadurl . $downloadscatArray[$i]->getVar('cat_imgurl'),
103
            'id'               => $downloadscatArray[$i]->getVar('cat_cid'),
104
            'title'            => $downloadscatArray[$i]->getVar('cat_title'),
105
            'description_main' => $downloadscatArray[$i]->getVar('cat_description_main'),
106
            'infercategories'  => $subcategories,
107
            'totaldownloads'   => $totaldownloads,
108
            'count'            => $count,
109
        ]);
110
        ++$count;
111
    }
112
}
113
//pour afficher les résumés
114
//----------------------------------------------------------------------------------------------------------------------------------------------------
115
//téléchargements récents
116
if (1 == $helper->getConfig('bldate')) {
117
    $criteria = new \CriteriaCompo();
118
    $criteria->add(new \Criteria('status', 0, '!='));
119
    $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN'));
120
    $criteria->add(new \Criteria('cid', \Xmf\Request::getInt('cid', 0, 'REQUEST')));
121
    $criteria->setSort('date');
122
    $criteria->setOrder('DESC');
123
    $criteria->setLimit($helper->getConfig('nbbl'));
124
    $downloadsArray = $downloadsHandler->getAll($criteria);
125
    foreach (array_keys($downloadsArray) as $i) {
126
        /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */
127
        $title = $downloadsArray[$i]->getVar('title');
128
        if (mb_strlen($title) >= $helper->getConfig('longbl')) {
129
            $title = mb_substr($title, 0, $helper->getConfig('longbl')) . '...';
130
        }
131
        $date = formatTimestamp($downloadsArray[$i]->getVar('date'), 's');
132
        $xoopsTpl->append('bl_date', [
133
            'id'    => $downloadsArray[$i]->getVar('lid'),
134
            'cid'   => $downloadsArray[$i]->getVar('cid'),
135
            'date'  => $date,
136
            'title' => $title,
137
        ]);
138
    }
139
}
140
//plus téléchargés
141
if (1 == $helper->getConfig('blpop')) {
142
    $criteria = new \CriteriaCompo();
143
    $criteria->add(new \Criteria('status', 0, '!='));
144
    $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN'));
145
    $criteria->add(new \Criteria('cid', \Xmf\Request::getInt('cid', 0, 'REQUEST')));
146
    $criteria->setSort('hits');
147
    $criteria->setOrder('DESC');
148
    $criteria->setLimit($helper->getConfig('nbbl'));
149
    $downloadsArray = $downloadsHandler->getAll($criteria);
150
    foreach (array_keys($downloadsArray) as $i) {
151
        $title = $downloadsArray[$i]->getVar('title');
152
        if (mb_strlen($title) >= $helper->getConfig('longbl')) {
153
            $title = mb_substr($title, 0, $helper->getConfig('longbl')) . '...';
154
        }
155
        $xoopsTpl->append('bl_pop', [
156
            'id'    => $downloadsArray[$i]->getVar('lid'),
157
            'cid'   => $downloadsArray[$i]->getVar('cid'),
158
            'hits'  => $downloadsArray[$i]->getVar('hits'),
159
            'title' => $title,
160
        ]);
161
    }
162
}
163
//mieux notés
164
if (1 == $helper->getConfig('blrating')) {
165
    $criteria = new \CriteriaCompo();
166
    $criteria->add(new \Criteria('status', 0, '!='));
167
    $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN'));
168
    $criteria->add(new \Criteria('cid', \Xmf\Request::getInt('cid', 0, 'REQUEST')));
169
    $criteria->setSort('rating');
170
    $criteria->setOrder('DESC');
171
    $criteria->setLimit($helper->getConfig('nbbl'));
172
    $downloadsArray = $downloadsHandler->getAll($criteria);
173
    foreach (array_keys($downloadsArray) as $i) {
174
        $title = $downloadsArray[$i]->getVar('title');
175
        if (mb_strlen($title) >= $helper->getConfig('longbl')) {
176
            $title = mb_substr($title, 0, $helper->getConfig('longbl')) . '...';
177
        }
178
        $rating = number_format((float)$downloadsArray[$i]->getVar('rating'), 1);
179
        $xoopsTpl->append('bl_rating', [
180
            'id'     => $downloadsArray[$i]->getVar('lid'),
181
            'cid'    => $downloadsArray[$i]->getVar('cid'),
182
            'rating' => $rating,
183
            'title'  => $title,
184
        ]);
185
    }
186
}
187
// affichage du résumé
188
$bl_affichage = 1;
189
if (0 === $helper->getConfig('bldate') && 0 === $helper->getConfig('blpop') && 0 === $helper->getConfig('blrating')) {
190
    $bl_affichage = 0;
191
}
192
//----------------------------------------------------------------------------------------------------------------------------------------------------
193
// affichage des téléchargements
194
if ($helper->getConfig('perpage') > 0) {
195
    $xoopsTpl->assign('nb_dowcol', $helper->getConfig('nb_dowcol'));
196
    //Utilisation d'une copie d'écran avec la largeur selon les préférences
197
    if (1 == $helper->getConfig('useshots')) {
198
        $xoopsTpl->assign('shotwidth', $helper->getConfig('shotwidth'));
199
        $xoopsTpl->assign('show_screenshot', true);
200
        $xoopsTpl->assign('img_float', $helper->getConfig('img_float'));
201
    }
202
    $criteria = new \CriteriaCompo();
203
    $criteria->add(new \Criteria('status', 0, '!='));
204
    $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN'));
205
    $criteria->add(new \Criteria('cid', \Xmf\Request::getInt('cid', 0, 'REQUEST')));
206
    $numrows = $downloadsHandler->getCount($criteria);
207
    $xoopsTpl->assign('lang_thereare', sprintf(_MD_TDMDOWNLOADS_CAT_THEREARE, $numrows));
208
    // Pour un affichage sur plusieurs pages
209
    if (\Xmf\Request::hasVar('limit', 'REQUEST')) {
210
        $criteria->setLimit(\Xmf\Request::getInt('limit', 0, 'REQUEST'));
211
        $limit = \Xmf\Request::getInt('limit', 0, 'REQUEST');
212
    } else {
213
        $criteria->setLimit($helper->getConfig('perpage'));
214
        $limit = $helper->getConfig('perpage');
215
    }
216
    if (\Xmf\Request::hasVar('start', 'REQUEST')) {
217
        $criteria->setStart(\Xmf\Request::getInt('start', 0, 'REQUEST'));
218
        $start = \Xmf\Request::getInt('start', 0, 'REQUEST');
219
    } else {
220
        $criteria->setStart(0);
221
        $start = 0;
222
    }
223
    if (\Xmf\Request::hasVar('sort', 'REQUEST')) {
224
        $criteria->setSort(\Xmf\Request::getString('sort', '', 'REQUEST'));
225
        $sort = \Xmf\Request::getString('sort', '', 'REQUEST');
226
    } else {
227
        $criteria->setSort('date');
228
        $sort = 'date';
229
    }
230
    if (\Xmf\Request::hasVar('order', 'REQUEST')) {
231
        $criteria->setOrder(\Xmf\Request::getString('order', '', 'REQUEST'));
232
        $order = \Xmf\Request::getString('order', '', 'REQUEST');
233
    } else {
234
        $criteria->setOrder('DESC');
235
        $order = 'DESC';
236
    }
237
    $downloadsArray = $downloadsHandler->getAll($criteria);
238
    if ($numrows > $limit) {
239
        require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
240
        $pagenav = new \XoopsPageNav($numrows, $limit, $start, 'start', 'limit=' . $limit . '&cid=' . \Xmf\Request::getInt('cid', 0, 'REQUEST') . '&sort=' . $sort . '&order=' . $order);
241
        $pagenav = $pagenav->renderNav(4);
242
    } else {
243
        $pagenav = '';
244
    }
245
    $xoopsTpl->assign('pagenav', $pagenav);
246
    $summary    = '';
247
    $cpt        = 0;
248
    $categories = $utility->getItemIds('tdmdownloads_download', $moduleDirName);
249
    $item       = $utility->getItemIds('tdmdownloads_download_item', $moduleDirName);
250
    foreach (array_keys($downloadsArray) as $i) {
251
        if ('blank.gif' === $downloadsArray[$i]->getVar('logourl')) {
252
            $logourl = '';
253
        } else {
254
            $logourl = $downloadsArray[$i]->getVar('logourl');
255
            $logourl = $uploadurl_shots . $logourl;
256
        }
257
        $datetime    = formatTimestamp($downloadsArray[$i]->getVar('date'), 's');
258
        $submitter   = \XoopsUser::getUnameFromId($downloadsArray[$i]->getVar('submitter'));
259
        $description = $downloadsArray[$i]->getVar('description');
260
        //permet d'afficher uniquement la description courte
261
        if (false === mb_strpos($description, '[pagebreak]')) {
262
            $descriptionShort = $description;
263
        } else {
264
            $descriptionShort = mb_substr($description, 0, mb_strpos($description, '[pagebreak]'));
265
        }
266
        // pour les vignettes "new" et "mis à jour"
267
        $new = $utility->getStatusImage($downloadsArray[$i]->getVar('date'), $downloadsArray[$i]->getVar('status'));
268
        $pop = $utility->getPopularImage($downloadsArray[$i]->getVar('hits'));
269
        // Défini si la personne est un admin
270
        $adminlink = '';
271
        if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) {
272
            $adminlink = '<a href="'
273
                         . XOOPS_URL
274
                         . '/modules/'
275
                         . $moduleDirName
276
                         . '/admin/downloads.php?op=view_downloads&amp;downloads_lid='
277
                         . $downloadsArray[$i]->getVar('lid')
278
                         . '" title="'
279
                         . _MD_TDMDOWNLOADS_EDITTHISDL
280
                         . '"><img src="'
281
                         . XOOPS_URL
282
                         . '/modules/'
283
                         . $moduleDirName
284
                         . '/assets/images/icons/16/edit.png" width="16px" height="16px" border="0" alt="'
285
                         . _MD_TDMDOWNLOADS_EDITTHISDL
286
                         . '"></a>';
287
        }
288
        //permission de télécharger
289
        $downloadPermission = true;
290
        if (1 === $helper->getConfig('permission_download')) {
291
            if (!in_array($downloadsArray[$i]->getVar('cid'), $categories)) {
292
                $downloadPermission = false;
293
            }
294
        } else {
295
            if (!in_array($downloadsArray[$i]->getVar('lid'), $item)) {
296
                $downloadPermission = false;
297
            }
298
        }
299
        // utilisation du sommaire
300
        ++$cpt;
301
        $summary = $cpt . '- <a href="#l' . $cpt . '">' . $downloadsArray[$i]->getVar('title') . '</a><br>';
302
        $xoopsTpl->append('summary', ['title' => $summary, 'count' => $cpt]);
303
        $xoopsTpl->append('file', [
304
            'id'                => $downloadsArray[$i]->getVar('lid'),
305
            'cid'               => $downloadsArray[$i]->getVar('cid'),
306
            'title'             => $downloadsArray[$i]->getVar('title'),
307
            'rating'            => number_format((float)$downloadsArray[$i]->getVar('rating'), 1),
308
            'hits'              => $downloadsArray[$i]->getVar('hits'),
309
            'new'               => $new,
310
            'pop'               => $pop,
311
            'logourl'           => $logourl,
312
            'updated'           => $datetime,
313
            'description_short' => $descriptionShort,
314
            'adminlink'         => $adminlink,
315
            'submitter'         => $submitter,
316
            'perm_download'     => $downloadPermission,
317
            'count'             => $cpt,
318
        ]);
319
        //pour les mots clef
320
        $keywords .= $downloadsArray[$i]->getVar('title') . ',';
321
    }
322
    if (0 == $numrows) {
323
        $bl_affichage = 0;
324
    }
325
    $xoopsTpl->assign('bl_affichage', $bl_affichage);
326
    // affichage du sommaire
327
    if ($helper->getConfig('autosummary')) {
328
        if (0 == $numrows) {
329
            $xoopsTpl->assign('aff_summary', false);
330
        } else {
331
            $xoopsTpl->assign('aff_summary', true);
332
        }
333
    } else {
334
        $xoopsTpl->assign('aff_summary', false);
335
    }
336
    // sort menu display
337
    if ($numrows > 1) {
338
        $xoopsTpl->assign('navigation', true);
339
        $sortorder = $sort . $order;
340
        if ('hitsASC' === $sortorder) {
341
            $displaySort = _MD_TDMDOWNLOADS_CAT_POPULARITYLTOM;
342
        }
343
        if ('hitsDESC' === $sortorder) {
344
            $displaySort = _MD_TDMDOWNLOADS_CAT_POPULARITYMTOL;
345
        }
346
        if ('titleASC' === $sortorder) {
347
            $displaySort = _MD_TDMDOWNLOADS_CAT_TITLEATOZ;
348
        }
349
        if ('titleDESC' === $sortorder) {
350
            $displaySort = _MD_TDMDOWNLOADS_CAT_TITLEZTOA;
351
        }
352
        if ('dateASC' === $sortorder) {
353
            $displaySort = _MD_TDMDOWNLOADS_CAT_DATEOLD;
354
        }
355
        if ('dateDESC' === $sortorder) {
356
            $displaySort = _MD_TDMDOWNLOADS_CAT_DATENEW;
357
        }
358
        if ('ratingASC' === $sortorder) {
359
            $displaySort = _MD_TDMDOWNLOADS_CAT_RATINGLTOH;
360
        }
361
        if ('ratingDESC' === $sortorder) {
362
            $displaySort = _MD_TDMDOWNLOADS_CAT_RATINGHTOL;
363
        }
364
        $xoopsTpl->assign('affichage_tri', sprintf(_MD_TDMDOWNLOADS_CAT_CURSORTBY, $displaySort));
365
    }
366
}
367
// référencement
368
// titre de la page
369
$pagetitle = $utility::getPathTreeUrl($mytree, $cid, $downloadscatArray, 'cat_title', $prefix = ' - ', false, 'DESC');
370
$xoopsTpl->assign('xoops_pagetitle', $pagetitle);
371
//description
372
$xoTheme->addMeta('meta', 'description', strip_tags($downloadscatArray[$cid]->getVar('cat_description_main')));
373
//keywords
374
$keywords = mb_substr($keywords, 0, -1);
375
$xoTheme->addMeta('meta', 'keywords', $keywords);
376
$GLOBALS['xoopsTpl']->assign('mod_url', XOOPS_URL . '/modules/' . $moduleDirName);
377
require XOOPS_ROOT_PATH . '/footer.php';
378