1
|
|
|
<?php declare(strict_types=1);
|
2
|
|
|
/*
|
3
|
|
|
You may not change or alter any portion of this comment or credits of
|
4
|
|
|
supporting developers from this source code or any supporting source code
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit
|
6
|
|
|
authors.
|
7
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, but
|
9
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
11
|
|
|
*/
|
12
|
|
|
|
13
|
|
|
/**
|
14
|
|
|
* XoopsFAQ module
|
15
|
|
|
* Description: RSS Definition file
|
16
|
|
|
*
|
17
|
|
|
* @param int $max
|
18
|
|
|
* @return array
|
19
|
|
|
* @copyright Copyright (c) 2001-2017 {@link https://xoops.org XOOPS Project}
|
20
|
|
|
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU Public License
|
21
|
|
|
*
|
22
|
|
|
* @see Xmf\Request
|
23
|
|
|
* @see \XoopsModules\Xoopsfaq\Helper
|
24
|
|
|
* @author XOOPS Module Development Team
|
25
|
|
|
*/
|
26
|
|
|
|
27
|
|
|
use XoopsModules\Xoopsfaq\{
|
28
|
|
|
Constants,
|
29
|
|
|
CategoryHandler,
|
30
|
|
|
ContentsHandler,
|
31
|
|
|
Helper
|
32
|
|
|
};
|
33
|
|
|
|
34
|
|
|
/**
|
35
|
|
|
* @param int $max
|
36
|
|
|
* @return array
|
37
|
|
|
*/
|
38
|
|
|
function xoopsfaq_rss(int $max = 10)
|
39
|
|
|
{
|
40
|
|
|
/** @var CategoryHandler $categoryHandler */
|
41
|
|
|
/** @var ContentsHandler $contentsHandler */
|
42
|
|
|
/** @var Helper $helper */
|
43
|
|
|
$helper = Helper::getInstance();
|
44
|
|
|
$categoryHandler = $helper->getHandler('Category');
|
45
|
|
|
$contentsHandler = $helper->getHandler('Contents');
|
46
|
|
|
$catId = Xmf\Request::getInt('categoryid', Constants::DEFAULT_CATEGORY, 'GET');
|
47
|
|
|
$cat_title = '';
|
48
|
|
|
if ($catId > Constants::DEFAULT_CATEGORY) {
|
49
|
|
|
$categoryObj = $categoryHandler->get($catId);
|
50
|
|
|
if ($categoryObj) {
|
|
|
|
|
51
|
|
|
$cat_title = $categoryObj->getVar('category_title');
|
52
|
|
|
unset($categoryHandler, $categoryObj);
|
53
|
|
|
}
|
54
|
|
|
}
|
55
|
|
|
|
56
|
|
|
$max = ($max > 0) ? $max : 10;
|
57
|
|
|
$criteria = new \CriteriaCompo();
|
58
|
|
|
$criteria->setLimit($max);
|
59
|
|
|
$criteria->add(new \Criteria('contents_active', Constants::ACTIVE, '='));
|
60
|
|
|
$criteria->add(new \Criteria('contents_publish', Constants::NOT_PUBLISHED, '>'));
|
61
|
|
|
$criteria->add(new \Criteria('contents_publish', time(), '<='));
|
62
|
|
|
if ($catId > Constants::DEFAULT_CATEGORY) {
|
63
|
|
|
$criteria->add(new \Criteria('contents_cid', $catId, '='));
|
64
|
|
|
}
|
65
|
|
|
$contentObjs = $contentsHandler->getAll($criteria);
|
66
|
|
|
|
67
|
|
|
$retVal = [];
|
68
|
|
|
|
69
|
|
|
/** @var XoopsObject $contentObj */
|
70
|
|
|
foreach ($contentObjs as $contentObj) {
|
71
|
|
|
$retVal[] = [
|
72
|
|
|
'image' => '',
|
73
|
|
|
'title' => $contentObj->getVar('contents_title'),
|
74
|
|
|
'link' => $contentObj->getVar('contents_contents'),
|
75
|
|
|
'time' => $contentObj->getVar('contents_publish'),
|
76
|
|
|
'desc' => '',
|
77
|
|
|
'category' => $cat_title,
|
78
|
|
|
];
|
79
|
|
|
}
|
80
|
|
|
unset($contentsHandler, $contentObjs);
|
81
|
|
|
|
82
|
|
|
return $retVal;
|
83
|
|
|
}
|
84
|
|
|
|