Passed
Push — master ( 396afe...6672c5 )
by Goffy
22:30 queued 19:01
created
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\Helper;
21
22
require_once __DIR__ . '/header.php';
23
$xoopsLogger->activated = false;
24
require_once XOOPS_ROOT_PATH . '/class/template.php';
25
global $xoopsModuleConfig;
26
$helper     = Helper::getInstance();
27
$itemsCount = $helper->getConfig('perpagerss');
28
$cid        = \Xmf\Request::getInt('cid', 0, 'GET');
29
if (function_exists('mb_http_output')) {
30
    mb_http_output('pass');
31
}
32
//header ('Content-Type:text/xml; charset=UTF-8');
33
$xoopsModuleConfig['utf8'] = false;
34
$moduleDirName             = basename(__DIR__);
35
//$xoopsTpl          = new \XoopsTpl();
36
$xoopsTpl->caching = 2; //1 = Cache global, 2 = Cache individuel (par template)
37
$xoopsTpl->xoops_setCacheTime($helper->getConfig('timecacherss') * 60); // Temps de cache en secondes
38
$categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName);
39
$criteria   = new \CriteriaCompo();
40
$criteria->add(new \Criteria('status', 0, '!='));
41
$criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN'));
42
if (0 !== $cid) {
43
    $criteria->add(new \Criteria('cid', $cid));
44
    $cat   = $categoryHandler->get($cid);
45
    $title = $xoopsConfig['sitename'] . ' - ' . $xoopsModule->getVar('name') . ' - ' . $cat->getVar('cat_title');
46
} else {
47
    $title = $xoopsConfig['sitename'] . ' - ' . $xoopsModule->getVar('name');
48
}
49
$criteria->setLimit($helper->getConfig('perpagerss'));
50
$criteria->setSort('date');
51
$criteria->setOrder('DESC');
52
$downloadsArray = $downloadsHandler->getAll($criteria);
53
if (!$xoopsTpl->is_cached('db:tdmdownloads_rss.tpl', $cid)) {
54
    $xoopsTpl->assign('channel_title', htmlspecialchars($title, ENT_QUOTES));
55
    $xoopsTpl->assign('channel_link', XOOPS_URL . '/');
56
    $xoopsTpl->assign('channel_desc', htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES));
57
    $xoopsTpl->assign('channel_lastbuild', formatTimestamp(time(), 'rss'));
58
    $xoopsTpl->assign('channel_webmaster', $xoopsConfig['adminmail']);
59
    $xoopsTpl->assign('channel_editor', $xoopsConfig['adminmail']);
60
    $xoopsTpl->assign('channel_category', 'Event');
61
    $xoopsTpl->assign('channel_generator', 'XOOPS - ' . htmlspecialchars($xoopsModule->getVar('name'), ENT_QUOTES));
62
    $xoopsTpl->assign('channel_language', _LANGCODE);
63
    if (_LANGCODE === 'fr') {
0 ignored issues
show
The condition _LANGCODE === 'fr' is always false.
Loading history...
64
        $xoopsTpl->assign('docs', 'http://www.scriptol.fr/rss/RSS-2.0.html');
65
    } else {
66
        $xoopsTpl->assign('docs', 'http://cyber.law.harvard.edu/rss/rss.html');
67
    }
68
    $xoopsTpl->assign('image_url', XOOPS_URL . $helper->getConfig('logorss'));
69
    $dimention = getimagesize(XOOPS_ROOT_PATH . $helper->getConfig('logorss'));
70
    if (empty($dimention[0])) {
71
        $width = 88;
72
    } else {
73
        $width = $dimention[0] > 144 ? 144 : $dimention[0];
74
    }
75
    if (empty($dimention[1])) {
76
        $height = 31;
77
    } else {
78
        $height = $dimention[1] > 400 ? 400 : $dimention[1];
79
    }
80
    $xoopsTpl->assign('image_width', $width);
81
    $xoopsTpl->assign('image_height', $height);
82
    foreach (array_keys($downloadsArray) as $i) {
83
        /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */
84
        $description = $downloadsArray[$i]->getVar('description');
85
        //permet d'afficher uniquement la description courte
86
        if (false === mb_strpos($description, '[pagebreak]')) {
87
            $descriptionShort = $description;
88
        } else {
89
            $descriptionShort = mb_substr($description, 0, mb_strpos($description, '[pagebreak]'));
90
        }
91
        $xoopsTpl->append('items', [
92
            'title'       => htmlspecialchars($downloadsArray[$i]->getVar('title'), ENT_QUOTES),
93
            'link'        => XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . $downloadsArray[$i]->getVar('cid') . '&amp;lid=' . $downloadsArray[$i]->getVar('lid'),
94
            'guid'        => XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . $downloadsArray[$i]->getVar('cid') . '&amp;lid=' . $downloadsArray[$i]->getVar('lid'),
95
            'pubdate'     => formatTimestamp($downloadsArray[$i]->getVar('date'), 'rss'),
96
            'description' => htmlspecialchars($descriptionShort, ENT_QUOTES),
97
        ]);
98
    }
99
}
100
header('Content-Type:text/xml; charset=' . _CHARSET);
101
$xoopsTpl->display('db:tdmdownloads_rss.tpl', $cid);
102