|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Modulebuilder\Files\User; |
|
4
|
|
|
|
|
5
|
|
|
use XoopsModules\Modulebuilder; |
|
6
|
|
|
use XoopsModules\Modulebuilder\Files; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* You may not change or alter any portion of this comment or credits |
|
10
|
|
|
* of supporting developers from this source code or any supporting source code |
|
11
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
16
|
|
|
*/ |
|
17
|
|
|
/** |
|
18
|
|
|
* modulebuilder module. |
|
19
|
|
|
* |
|
20
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
21
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
22
|
|
|
* |
|
23
|
|
|
* @since 2.5.0 |
|
24
|
|
|
* |
|
25
|
|
|
* @author Txmod Xoops https://xoops.org |
|
26
|
|
|
* Goffy https://myxoops.org |
|
27
|
|
|
* |
|
28
|
|
|
*/ |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Class UserRss. |
|
32
|
|
|
*/ |
|
33
|
|
|
class UserRss extends Files\CreateFile |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* @var mixed |
|
37
|
|
|
*/ |
|
38
|
|
|
private $uxc = null; |
|
39
|
|
|
/** |
|
40
|
|
|
* @var mixed |
|
41
|
|
|
*/ |
|
42
|
|
|
private $xc = null; |
|
43
|
|
|
/** |
|
44
|
|
|
* @var mixed |
|
45
|
|
|
*/ |
|
46
|
|
|
private $pc = null; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @public function constructor |
|
50
|
|
|
* @param null |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct() |
|
53
|
|
|
{ |
|
54
|
|
|
parent::__construct(); |
|
55
|
|
|
$this->xc = Modulebuilder\Files\CreateXoopsCode::getInstance(); |
|
56
|
|
|
$this->pc = Modulebuilder\Files\CreatePhpCode::getInstance(); |
|
57
|
|
|
$this->uxc = UserXoopsCode::getInstance(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @static function getInstance |
|
62
|
|
|
* @param null |
|
63
|
|
|
* @return UserRss |
|
64
|
|
|
*/ |
|
65
|
|
|
public static function getInstance() |
|
66
|
|
|
{ |
|
67
|
|
|
static $instance = false; |
|
68
|
|
|
if (!$instance) { |
|
69
|
|
|
$instance = new self(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $instance; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @public function write |
|
77
|
|
|
* @param string $module |
|
78
|
|
|
* @param mixed $table |
|
79
|
|
|
* @param string $filename |
|
80
|
|
|
*/ |
|
81
|
|
|
public function write($module, $table, $filename) |
|
82
|
|
|
{ |
|
83
|
|
|
$this->setModule($module); |
|
84
|
|
|
$this->setTable($table); |
|
85
|
|
|
$this->setFileName($filename); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @public function getUserRss |
|
90
|
|
|
* @param string $moduleDirname |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getUserRss($moduleDirname) |
|
94
|
|
|
{ |
|
95
|
|
|
$table = $this->getTable(); |
|
96
|
|
|
$tableName = $table->getVar('table_name'); |
|
97
|
|
|
$fppf = ''; |
|
98
|
|
|
$fpmf = ''; |
|
99
|
|
|
$fieldId = ''; |
|
100
|
|
|
$fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
|
101
|
|
|
foreach (\array_keys($fields) as $f) { |
|
102
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
103
|
|
|
$fieldMain[] = $fields[$f]->getVar('field_main'); |
|
104
|
|
|
$fieldParent[] = $fields[$f]->getVar('field_parent'); |
|
105
|
|
|
|
|
106
|
|
|
if (0 == $f) { |
|
107
|
|
|
$fieldId = $fieldName; |
|
108
|
|
|
} |
|
109
|
|
|
if (\in_array(1, $fieldMain)) { |
|
|
|
|
|
|
110
|
|
|
$fpmf = $fieldName; |
|
111
|
|
|
} |
|
112
|
|
|
if (\in_array(1, $fieldParent)) { |
|
|
|
|
|
|
113
|
|
|
$fppf = $fieldName; |
|
114
|
|
|
} else { |
|
115
|
|
|
$fppf = 'cid'; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$ret = $this->pc->getPhpCodeUseNamespace(['Xmf', 'Request']); |
|
120
|
|
|
$ret .= $this->getRequire(); |
|
121
|
|
|
|
|
122
|
|
|
$ret .= <<<EOT |
|
123
|
|
|
|
|
124
|
|
|
\${$fppf} = Request::getInt('{$fppf}', 0, 'GET'); |
|
125
|
|
|
require_once \XOOPS_ROOT_PATH.'/class/template.php'; |
|
126
|
|
|
if (\\function_exists('mb_http_output')) { |
|
127
|
|
|
mb_http_output('pass'); |
|
128
|
|
|
} |
|
129
|
|
|
//header ('Content-Type:text/xml; charset=UTF-8'); |
|
130
|
|
|
\$xoopsModuleConfig['utf8'] = false; |
|
131
|
|
|
|
|
132
|
|
|
\$tpl = new \XoopsTpl(); |
|
133
|
|
|
\$tpl->xoops_setCaching(2); //1 = Cache global, 2 = Cache individual (for template) |
|
134
|
|
|
\$tpl->xoops_setCacheTime(\$helper->getConfig('timecacherss')*60); // Time of the cache on seconds |
|
135
|
|
|
\$categories = {$moduleDirname}MyGetItemIds('{$moduleDirname}_view', '{$moduleDirname}'); |
|
136
|
|
|
\$criteria = new \CriteriaCompo(); |
|
137
|
|
|
|
|
138
|
|
|
\$criteria->add(new \Criteria('cat_status', 0, '!=')); |
|
139
|
|
|
\$criteria->add(new \Criteria('{$fppf}', '(' . \implode(',', \$categories) . ')','IN')); |
|
140
|
|
|
if (0 != \${$fppf}){ |
|
141
|
|
|
\$criteria->add(new \Criteria('{$fppf}', \${$fppf})); |
|
142
|
|
|
\${$tableName} = \${$tableName}Handler->get(\${$fppf}); |
|
143
|
|
|
\$title = \$xoopsConfig['sitename'] . ' - ' . \$xoopsModule->getVar('name') . ' - ' . \${$tableName}->getVar('{$fpmf}'); |
|
144
|
|
|
} else { |
|
145
|
|
|
\$title = \$xoopsConfig['sitename'] . ' - ' . \$xoopsModule->getVar('name'); |
|
146
|
|
|
} |
|
147
|
|
|
\$criteria->setLimit(\$helper->getConfig('perpagerss')); |
|
148
|
|
|
\$criteria->setSort('date'); |
|
149
|
|
|
\$criteria->setOrder('DESC'); |
|
150
|
|
|
\${$tableName}Arr = \${$tableName}Handler->getAll(\$criteria); |
|
151
|
|
|
unset(\$criteria); |
|
152
|
|
|
|
|
153
|
|
|
if (!\$tpl->is_cached('db:{$moduleDirname}_rss.tpl', \${$fppf})) { |
|
154
|
|
|
\$tpl->assign('channel_title', \htmlspecialchars(\$title, ENT_QUOTES)); |
|
155
|
|
|
\$tpl->assign('channel_link', \XOOPS_URL.'/'); |
|
156
|
|
|
\$tpl->assign('channel_desc', \htmlspecialchars(\$xoopsConfig['slogan'], ENT_QUOTES)); |
|
157
|
|
|
\$tpl->assign('channel_lastbuild', \\formatTimestamp(\time(), 'rss')); |
|
158
|
|
|
\$tpl->assign('channel_webmaster', \$xoopsConfig['adminmail']); |
|
159
|
|
|
\$tpl->assign('channel_editor', \$xoopsConfig['adminmail']); |
|
160
|
|
|
\$tpl->assign('channel_category', 'Event'); |
|
161
|
|
|
\$tpl->assign('channel_generator', 'XOOPS - ' . \htmlspecialchars(\$xoopsModule->getVar('{$fpmf}'), ENT_QUOTES)); |
|
162
|
|
|
\$tpl->assign('channel_language', _LANGCODE); |
|
163
|
|
|
if ( 'fr' == _LANGCODE ) { |
|
164
|
|
|
\$tpl->assign('docs', 'http://www.scriptol.fr/rss/RSS-2.0.html'); |
|
165
|
|
|
} else { |
|
166
|
|
|
\$tpl->assign('docs', 'http://cyber.law.harvard.edu/rss/rss.html'); |
|
167
|
|
|
} |
|
168
|
|
|
\$tpl->assign('image_url', \XOOPS_URL . \$xoopsModuleConfig['logorss']); |
|
169
|
|
|
\$dimention = \getimagesize(\XOOPS_ROOT_PATH . \$xoopsModuleConfig['logorss']); |
|
170
|
|
|
if (empty(\$dimention[0])) { |
|
171
|
|
|
\$width = 88; |
|
172
|
|
|
} else { |
|
173
|
|
|
\$width = (\$dimention[0] > 144) ? 144 : \$dimention[0]; |
|
174
|
|
|
} |
|
175
|
|
|
if (empty(\$dimention[1])) { |
|
176
|
|
|
\$height = 31; |
|
177
|
|
|
} else { |
|
178
|
|
|
\$height = (\$dimention[1] > 400) ? 400 : \$dimention[1]; |
|
179
|
|
|
} |
|
180
|
|
|
\$tpl->assign('image_width', \$width); |
|
181
|
|
|
\$tpl->assign('image_height', \$height); |
|
182
|
|
|
foreach (\array_keys(\${$tableName}Arr) as \$i) { |
|
183
|
|
|
\$description = \${$tableName}Arr[\$i]->getVar('description'); |
|
184
|
|
|
//permet d'afficher uniquement la description courte |
|
185
|
|
|
if (false == \strpos(\$description,'[pagebreak]')){ |
|
186
|
|
|
\$description_short = \$description; |
|
187
|
|
|
} else { |
|
188
|
|
|
\$description_short = \substr(\$description,0,\strpos(\$description,'[pagebreak]')); |
|
189
|
|
|
} |
|
190
|
|
|
\$tpl->append('items', ['title' => \htmlspecialchars(\${$tableName}Arr[\$i]->getVar('{$fpmf}'), ENT_QUOTES), |
|
191
|
|
|
'link' => \XOOPS_URL . '/modules/{$moduleDirname}/single.php?{$fppf}=' . \${$tableName}Arr[\$i]->getVar('{$fppf}') . '&{$fieldId}=' . \${$tableName}Arr[\$i]->getVar('{$fieldId}'), |
|
192
|
|
|
'guid' => \XOOPS_URL . '/modules/{$moduleDirname}/single.php?{$fppf}=' . \${$tableName}Arr[\$i]->getVar('{$fppf}') . '&{$fieldId}=' . \${$tableName}Arr[\$i]->getVar('{$fieldId}'), |
|
193
|
|
|
'pubdate' => \\formatTimestamp(\${$tableName}Arr[\$i]->getVar('date'), 'rss'), |
|
194
|
|
|
'description' => \htmlspecialchars(\$description_short, ENT_QUOTES) |
|
195
|
|
|
]); |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
header('Content-Type:text/xml; charset=' . _CHARSET); |
|
199
|
|
|
\$tpl->display('db:{$moduleDirname}_rss.tpl', \${$fppf}); |
|
200
|
|
|
|
|
201
|
|
|
EOT; |
|
202
|
|
|
|
|
203
|
|
|
return $ret; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* @public function render |
|
208
|
|
|
* @param null |
|
209
|
|
|
* @return bool|string |
|
210
|
|
|
*/ |
|
211
|
|
|
public function render() |
|
212
|
|
|
{ |
|
213
|
|
|
$module = $this->getModule(); |
|
214
|
|
|
$filename = $this->getFileName(); |
|
215
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
216
|
|
|
$content = $this->getHeaderFilesComments($module); |
|
217
|
|
|
$content .= $this->getUserRss($moduleDirname); |
|
218
|
|
|
$this->create($moduleDirname, '/', $filename, $content, \_AM_MODULEBUILDER_FILE_CREATED, \_AM_MODULEBUILDER_FILE_NOTCREATED); |
|
219
|
|
|
|
|
220
|
|
|
return $this->renderFile(); |
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
|