Passed
Pull Request — master (#88)
by Michael
02:56
created
Severity
1
<?php declare(strict_types=1);
2
3
/**
4
 * TDMDownload
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
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright   Gregory Mage (Aka Mage)
14
 * @license     GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
15
 * @author      Gregory Mage (Aka Mage)
16
 */
17
18
use XoopsModules\Tdmdownloads\Helper;
19
20
require_once __DIR__ . '/header.php';
21
$xoopsLogger->activated = false;
22
require_once XOOPS_ROOT_PATH . '/class/template.php';
23
24
global $xoopsModuleConfig;
25
/** @var \XoopsModules\Tdmdownloads\Helper $helper */
26
$helper = Helper::getInstance();
27
28
$itemsCount = $helper->getConfig('perpagerss');
29
$cid        = \Xmf\Request::getInt('cid', 0, 'GET');
30
if (function_exists('mb_http_output')) {
31
    mb_http_output('pass');
32
}
33
//header ('Content-Type:text/xml; charset=UTF-8');
34
$xoopsModuleConfig['utf8'] = false;
35
36
$moduleDirName = basename(__DIR__);
37
38
//$xoopsTpl          = new \XoopsTpl();
39
$xoopsTpl->caching = 2; //1 = Cache global, 2 = Cache individuel (par template)
40
$xoopsTpl->xoops_setCacheTime($helper->getConfig('timecacherss') * 60); // Temps de cache en secondes
41
$categories = $utility->getItemIds('tdmdownloads_view', $moduleDirName);
42
$criteria   = new \CriteriaCompo();
43
$criteria->add(new \Criteria('status', 0, '!='));
44
$criteria->add(new \Criteria('cid', '(' . implode(',', $categories) . ')', 'IN'));
45
if (0 !== $cid) {
46
    $criteria->add(new \Criteria('cid', $cid));
47
48
    $cat = $categoryHandler->get($cid);
49
50
    $title = $xoopsConfig['sitename'] . ' - ' . $xoopsModule->getVar('name') . ' - ' . $cat->getVar('cat_title');
51
} else {
52
    $title = $xoopsConfig['sitename'] . ' - ' . $xoopsModule->getVar('name');
53
}
54
$criteria->setLimit($helper->getConfig('perpagerss'));
55
$criteria->setSort('date');
56
$criteria->setOrder('DESC');
57
$downloadsArray = $downloadsHandler->getAll($criteria);
58
59
if (!$xoopsTpl->is_cached('db:tdmdownloads_rss.tpl', $cid)) {
60
    $xoopsTpl->assign('channel_title', htmlspecialchars($title, ENT_QUOTES));
61
62
    $xoopsTpl->assign('channel_link', XOOPS_URL . '/');
63
64
    $xoopsTpl->assign('channel_desc', htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES));
65
66
    $xoopsTpl->assign('channel_lastbuild', formatTimestamp(time(), 'rss'));
67
68
    $xoopsTpl->assign('channel_webmaster', $xoopsConfig['adminmail']);
69
70
    $xoopsTpl->assign('channel_editor', $xoopsConfig['adminmail']);
71
72
    $xoopsTpl->assign('channel_category', 'Event');
73
74
    $xoopsTpl->assign('channel_generator', 'XOOPS - ' . htmlspecialchars($xoopsModule->getVar('name'), ENT_QUOTES));
75
76
    $xoopsTpl->assign('channel_language', _LANGCODE);
77
78
    if (_LANGCODE === 'fr') {
0 ignored issues
show
The condition _LANGCODE === 'fr' is always false.
Loading history...
79
        $xoopsTpl->assign('docs', 'http://www.scriptol.fr/rss/RSS-2.0.html');
80
    } else {
81
        $xoopsTpl->assign('docs', 'http://cyber.law.harvard.edu/rss/rss.html');
82
    }
83
84
    $xoopsTpl->assign('image_url', XOOPS_URL . $helper->getConfig('logorss'));
85
86
    $dimention = getimagesize(XOOPS_ROOT_PATH . $helper->getConfig('logorss'));
87
88
    if (empty($dimention[0])) {
89
        $width = 88;
90
    } else {
91
        $width = $dimention[0] > 144 ? 144 : $dimention[0];
92
    }
93
94
    if (empty($dimention[1])) {
95
        $height = 31;
96
    } else {
97
        $height = $dimention[1] > 400 ? 400 : $dimention[1];
98
    }
99
100
    $xoopsTpl->assign('image_width', $width);
101
102
    $xoopsTpl->assign('image_height', $height);
103
104
    foreach (array_keys($downloadsArray) as $i) {
105
        /** @var \XoopsModules\Tdmdownloads\Downloads[] $downloadsArray */
106
107
        $description = $downloadsArray[$i]->getVar('description');
108
109
        //permet d'afficher uniquement la description courte
110
111
        if (false === mb_strpos($description, '[pagebreak]')) {
112
            $descriptionShort = $description;
113
        } else {
114
            $descriptionShort = mb_substr($description, 0, mb_strpos($description, '[pagebreak]'));
115
        }
116
117
        $xoopsTpl->append(
118
            'items',
119
            [
120
                'title'       => htmlspecialchars($downloadsArray[$i]->getVar('title'), ENT_QUOTES),
121
                'link'        => XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . $downloadsArray[$i]->getVar('cid') . '&amp;lid=' . $downloadsArray[$i]->getVar('lid'),
122
                'guid'        => XOOPS_URL . '/modules/' . $moduleDirName . '/singlefile.php?cid=' . $downloadsArray[$i]->getVar('cid') . '&amp;lid=' . $downloadsArray[$i]->getVar('lid'),
123
                'pubdate'     => formatTimestamp($downloadsArray[$i]->getVar('date'), 'rss'),
124
                'description' => htmlspecialchars($descriptionShort, ENT_QUOTES),
125
            ]
126
        );
127
    }
128
}
129
header('Content-Type:text/xml; charset=' . _CHARSET);
130
$xoopsTpl->display('db:tdmdownloads_rss.tpl', $cid);
131