Passed
Pull Request — master (#88)
by Michael
08:00 queued 04:03
created

viewcat.php (2 issues)

Labels
Severity
1
<?php
2
/**
3
 * TDMDownload
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright   Gregory Mage (Aka Mage)
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Gregory Mage (Aka Mage)
15
 */
16
require_once __DIR__ . '/header.php';
17
$moduleDirName = basename(__DIR__);
18
19
/** @var \XoopsModules\Tdmdownloads\Helper $helper */
20
$helper = \XoopsModules\Tdmdownloads\Helper::getInstance();
21
22
// template d'affichage
23
$GLOBALS['xoopsOption']['template_main'] = 'tdmdownloads_viewcat.tpl';
24
require_once XOOPS_ROOT_PATH . '/header.php';
25
/** @var \xos_opal_Theme $xoTheme */
26
$xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $moduleDirName . '/assets/css/styles.css', null);
27
$cid = \Xmf\Request::getInt('cid', 0, 'REQUEST');
28
29
// pour les permissions
30
$categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName);
31
32
// redirection si la catégorie n'existe pas
33
$criteria = new \CriteriaCompo();
34
$criteria->add(new \Criteria('cat_cid', $cid));
35
if (0 === $cid || 0 === $categoryHandler->getCount($criteria)) {
36
    redirect_header('index.php', 3, _MD_TDMDOWNLOADS_CAT_NONEXISTENT);
37
}
38
// pour les permissions (si pas de droit, redirection)
39
if (!in_array($cid, $categories, true)) {
40
    redirect_header('index.php', 2, _NOPERM);
41
}
42
43
//tableau des catégories
44
$criteria = new \CriteriaCompo();
45
$criteria->setSort('cat_weight ASC, cat_title');
46
$criteria->setOrder('ASC');
47
$criteria->add(new \Criteria('cat_cid', '(' . implode(',', $categories) . ')', 'IN'));
48
$downloadscatArray = $categoryHandler->getAll($criteria);
49
$mytree            = new \XoopsModules\Tdmdownloads\Tree($downloadscatArray, 'cat_cid', 'cat_pid');
50
51
//tableau des téléchargements
52
$criteria = new \CriteriaCompo();
53
$criteria->add(new \Criteria('status', 0, '!='));
54
$criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN'));
55
$downloadsArray = $downloadsHandler->getAll($criteria);
56
$xoopsTpl->assign('lang_thereare', sprintf(_MD_TDMDOWNLOADS_INDEX_THEREARE, count($downloadsArray)));
57
58
//navigation
59
$navCategory = $utility->getPathTreeUrl($mytree, $cid, $downloadscatArray, 'cat_title', $prefix = ' <img src="assets/images/deco/arrow.gif" alt="arrow"> ', true, 'ASC');
60
$xoopsTpl->assign('category_path', $navCategory);
61
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
79
//affichage des catégories
80
$xoopsTpl->assign('nb_catcol', $helper->getConfig('nb_catcol'));
81
$count    = 1;
82
$keywords = '';
83
foreach (array_keys($downloadscatArray) as $i) {
84
    /** @var \XoopsModules\Tdmdownloads\Category[] $downloadscatArray */
85
    if ($downloadscatArray[$i]->getVar('cat_pid') == $cid) {
86
        $totaldownloads    = $utility->getNumbersOfEntries($mytree, $categories, $downloadsArray, $downloadscatArray[$i]->getVar('cat_cid'));
87
        $subcategories_arr = $mytree->getFirstChild($downloadscatArray[$i]->getVar('cat_cid'));
88
        $chcount           = 0;
89
        $subcategories     = '';
90
        //pour les mots clef
91
        $keywords .= $downloadscatArray[$i]->getVar('cat_title') . ',';
92
        foreach (array_keys($subcategories_arr) as $j) {
93
            /** @var \XoopsModules\Tdmdownloads\Category[] $subcategories_arr */
94
            if ($chcount >= $helper->getConfig('nbsouscat')) {
95
                $subcategories .= '<li>[<a href="' . XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $downloadscatArray[$i]->getVar('cat_cid') . '">+</a>]</li>';
96
                break;
97
            }
98
            $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>';
99
            $keywords      .= $downloadscatArray[$i]->getVar('cat_title') . ',';
100
            ++$chcount;
101
        }
102
        $xoopsTpl->append('subcategories', [
103
            'image'            => $uploadurl . $downloadscatArray[$i]->getVar('cat_imgurl'),
104
            'id'               => $downloadscatArray[$i]->getVar('cat_cid'),
105
            'title'            => $downloadscatArray[$i]->getVar('cat_title'),
106
            'description_main' => $downloadscatArray[$i]->getVar('cat_description_main'),
107
            'infercategories'  => $subcategories,
108
            'totaldownloads'   => $totaldownloads,
109
            'count'            => $count,
110
        ]);
111
        ++$count;
112
    }
113
}
114
115
//pour afficher les résumés
116
//----------------------------------------------------------------------------------------------------------------------------------------------------
117
//téléchargements récents
118
if (1 == $helper->getConfig('bldate')) {
119
    $criteria = new \CriteriaCompo();
120
    $criteria->add(new \Criteria('status', 0, '!='));
121
    $criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN'));
122
    $criteria->add(new \Criteria('cid', \Xmf\Request::getInt('cid', 0, 'REQUEST')));
123
    $criteria->setSort('date');
124
    $criteria->setOrder('DESC');
125
    $criteria->setLimit($helper->getConfig('nbbl'));
126
    $downloadsArray = $downloadsHandler->getAll($criteria);
127
    foreach (array_keys($downloadsArray) as $i) {
128
        /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */
129
        $title = $downloadsArray[$i]->getVar('title');
130
        if (mb_strlen($title) >= $helper->getConfig('longbl')) {
0 ignored issues
show
It seems like $title can also be of type array and array; however, parameter $str of mb_strlen() 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

130
        if (mb_strlen(/** @scrutinizer ignore-type */ $title) >= $helper->getConfig('longbl')) {
Loading history...
131
            $title = mb_substr($title, 0, $helper->getConfig('longbl')) . '...';
0 ignored issues
show
It seems like $title can also be of type array and array; however, parameter $str of mb_substr() 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

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