1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xmf\Template; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Feed implements a basic rss feed |
16
|
|
|
* |
17
|
|
|
* @category Xmf\Template\Feed |
18
|
|
|
* @package Xmf |
19
|
|
|
* @author trabis <[email protected]> |
20
|
|
|
* @author The SmartFactory <www.smartfactory.ca> |
21
|
|
|
* @copyright 2011-2016 XOOPS Project (http://xoops.org) |
22
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
23
|
|
|
* @version Release: 1.0 |
24
|
|
|
* @link http://xoops.org |
25
|
|
|
* @since 1.0 |
26
|
|
|
*/ |
27
|
|
|
class Feed extends AbstractTemplate |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $title = ''; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $url = ''; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $description = ''; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private $language = ''; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
private $charset = ''; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
private $category = ''; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
private $pubdate = ''; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var string |
66
|
|
|
*/ |
67
|
|
|
private $webmaster = ''; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var string |
71
|
|
|
*/ |
72
|
|
|
private $generator = ''; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var string |
76
|
|
|
*/ |
77
|
|
|
private $copyright = ''; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
private $lastbuild = ''; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var string |
86
|
|
|
*/ |
87
|
|
|
private $editor = ''; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var int |
91
|
|
|
*/ |
92
|
|
|
private $ttl = 60; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @var string |
96
|
|
|
*/ |
97
|
|
|
private $image_title = ''; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @var string |
101
|
|
|
*/ |
102
|
|
|
private $image_url = ''; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var string |
106
|
|
|
*/ |
107
|
|
|
private $image_link = ''; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @var int |
111
|
|
|
*/ |
112
|
|
|
private $image_width = 200; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @var int |
116
|
|
|
*/ |
117
|
|
|
private $image_height = 50; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @var array |
121
|
|
|
*/ |
122
|
|
|
private $items = array(); |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* init - called by parent::_construct |
126
|
|
|
* |
127
|
|
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
protected function init() |
130
|
|
|
{ |
131
|
|
|
$this->setTemplate('module:xmf/xmf_feed.tpl'); |
132
|
|
|
//$this->disableLogger(); |
133
|
|
|
|
134
|
|
|
global $xoopsConfig; |
|
|
|
|
135
|
|
|
$this->title = $xoopsConfig['sitename']; |
136
|
|
|
$this->url = \XoopsBaseConfig::get('url'); |
137
|
|
|
$this->description = $xoopsConfig['slogan']; |
138
|
|
|
$this->language = \XoopsLocale::getLangCode(); |
139
|
|
|
$this->charset = \XoopsLocale::getCharset(); |
140
|
|
|
$this->pubdate = \XoopsLocale::formatTimestamp(time(), 'short'); |
141
|
|
|
$this->lastbuild = \XoopsLocale::formatTimestamp(time(), 'D, d M Y H:i:s'); |
142
|
|
|
$this->webmaster = $xoopsConfig['adminmail']; |
143
|
|
|
$this->editor = $xoopsConfig['adminmail']; |
144
|
|
|
$this->generator = \Xoops::VERSION; |
145
|
|
|
$this->copyright = 'Copyright ' . \XoopsLocale::formatTimestamp(time(), 'Y') . ' ' . $xoopsConfig['sitename']; |
146
|
|
|
$this->image_title = $this->title; |
147
|
|
|
$this->image_url = \XoopsBaseConfig::get('url') . '/images/logo.gif'; |
148
|
|
|
$this->image_link = $this->url; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Render the feed and display it directly |
153
|
|
|
* |
154
|
|
|
* @return void |
155
|
|
|
*/ |
156
|
|
|
protected function render() |
157
|
|
|
{ |
158
|
|
|
$this->tpl->assign('channel_charset', $this->charset); |
159
|
|
|
$this->tpl->assign('channel_title', $this->title); |
160
|
|
|
$this->tpl->assign('channel_link', $this->url); |
161
|
|
|
$this->tpl->assign('channel_desc', $this->description); |
162
|
|
|
$this->tpl->assign('channel_webmaster', $this->webmaster); |
163
|
|
|
$this->tpl->assign('channel_editor', $this->editor); |
164
|
|
|
$this->tpl->assign('channel_category', $this->category); |
165
|
|
|
$this->tpl->assign('channel_generator', $this->generator); |
166
|
|
|
$this->tpl->assign('channel_language', $this->language); |
167
|
|
|
$this->tpl->assign('channel_lastbuild', $this->lastbuild); |
168
|
|
|
$this->tpl->assign('channel_copyright', $this->copyright); |
169
|
|
|
$this->tpl->assign('channel_ttl', $this->ttl); |
170
|
|
|
$this->tpl->assign('channel_image_url', $this->image_url); |
171
|
|
|
$this->tpl->assign('channel_image_title', $this->image_title); |
172
|
|
|
$this->tpl->assign('channel_image_url', $this->image_url); |
173
|
|
|
$this->tpl->assign('channel_image_link', $this->image_link); |
174
|
|
|
$this->tpl->assign('channel_image_width', $this->image_width); |
175
|
|
|
$this->tpl->assign('channel_image_height', $this->image_height); |
176
|
|
|
$this->tpl->assign('channel_items', $this->items); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* setCategory |
181
|
|
|
* |
182
|
|
|
* @param string $category feed category |
183
|
|
|
* |
184
|
|
|
* @return Feed |
185
|
|
|
*/ |
186
|
|
|
public function setCategory($category) |
187
|
|
|
{ |
188
|
|
|
$this->category = $category; |
189
|
|
|
return $this; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* getCategory |
194
|
|
|
* |
195
|
|
|
* @return string feed category |
196
|
|
|
*/ |
197
|
|
|
public function getCategory() |
198
|
|
|
{ |
199
|
|
|
return $this->category; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* setCharset |
204
|
|
|
* |
205
|
|
|
* @param string $charset feed character set |
206
|
|
|
* |
207
|
|
|
* @return Feed |
208
|
|
|
*/ |
209
|
|
|
public function setCharset($charset) |
210
|
|
|
{ |
211
|
|
|
$this->charset = $charset; |
212
|
|
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* getCharset |
217
|
|
|
* |
218
|
|
|
* @return string feed character set |
219
|
|
|
*/ |
220
|
|
|
public function getCharset() |
221
|
|
|
{ |
222
|
|
|
return $this->charset; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* setCopyright |
227
|
|
|
* |
228
|
|
|
* @param string $copyright feed copyright |
229
|
|
|
* |
230
|
|
|
* @return Feed |
231
|
|
|
*/ |
232
|
|
|
public function setCopyright($copyright) |
233
|
|
|
{ |
234
|
|
|
$this->copyright = $copyright; |
235
|
|
|
return $this; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* getCopyright |
240
|
|
|
* |
241
|
|
|
* @return string feed copyright |
242
|
|
|
*/ |
243
|
|
|
public function getCopyright() |
244
|
|
|
{ |
245
|
|
|
return $this->copyright; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* setDescription |
250
|
|
|
* |
251
|
|
|
* @param string $description feed description |
252
|
|
|
* |
253
|
|
|
* @return Feed |
254
|
|
|
*/ |
255
|
|
|
public function setDescription($description) |
256
|
|
|
{ |
257
|
|
|
$this->description = $description; |
258
|
|
|
return $this; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* getDescription |
263
|
|
|
* |
264
|
|
|
* @return string feed description |
265
|
|
|
*/ |
266
|
|
|
public function getDescription() |
267
|
|
|
{ |
268
|
|
|
return $this->description; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* setEditor |
273
|
|
|
* |
274
|
|
|
* @param string $editor editor of feed |
275
|
|
|
* |
276
|
|
|
* @return Feed |
277
|
|
|
*/ |
278
|
|
|
public function setEditor($editor) |
279
|
|
|
{ |
280
|
|
|
$this->editor = $editor; |
281
|
|
|
return $this; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* getEditor |
286
|
|
|
* |
287
|
|
|
* @return string editor of feed |
288
|
|
|
*/ |
289
|
|
|
public function getEditor() |
290
|
|
|
{ |
291
|
|
|
return $this->editor; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* setGenerator |
296
|
|
|
* |
297
|
|
|
* @param string $generator feed generator |
298
|
|
|
* |
299
|
|
|
* @return Feed |
300
|
|
|
*/ |
301
|
|
|
public function setGenerator($generator) |
302
|
|
|
{ |
303
|
|
|
$this->generator = $generator; |
304
|
|
|
return $this; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* getGenerator |
309
|
|
|
* |
310
|
|
|
* @return string feed generator |
311
|
|
|
*/ |
312
|
|
|
public function getGenerator() |
313
|
|
|
{ |
314
|
|
|
return $this->generator; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* setImageHeight |
319
|
|
|
* |
320
|
|
|
* @param int $image_height height of feed image |
321
|
|
|
* |
322
|
|
|
* @return Feed |
323
|
|
|
*/ |
324
|
|
|
public function setImageHeight($image_height) |
325
|
|
|
{ |
326
|
|
|
$this->image_height = $image_height; |
327
|
|
|
return $this; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* getImageHeight |
332
|
|
|
* |
333
|
|
|
* @return int height of feed image |
334
|
|
|
*/ |
335
|
|
|
public function getImageHeight() |
336
|
|
|
{ |
337
|
|
|
return $this->image_height; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* setImageLink |
342
|
|
|
* |
343
|
|
|
* @param string $image_link feed image link |
344
|
|
|
* |
345
|
|
|
* @return Feed |
346
|
|
|
*/ |
347
|
|
|
public function setImageLink($image_link) |
348
|
|
|
{ |
349
|
|
|
$this->image_link = $image_link; |
350
|
|
|
return $this; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* getImageLink |
355
|
|
|
* |
356
|
|
|
* @return string feed image link |
357
|
|
|
*/ |
358
|
|
|
public function getImageLink() |
359
|
|
|
{ |
360
|
|
|
return $this->image_link; |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* setImageTitle |
365
|
|
|
* |
366
|
|
|
* @param string $image_title feed image title |
367
|
|
|
* |
368
|
|
|
* @return Feed |
369
|
|
|
*/ |
370
|
|
|
public function setImageTitle($image_title) |
371
|
|
|
{ |
372
|
|
|
$this->image_title = $image_title; |
373
|
|
|
return $this; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* getImageTitle |
378
|
|
|
* |
379
|
|
|
* @return string feed image title |
380
|
|
|
*/ |
381
|
|
|
public function getImageTitle() |
382
|
|
|
{ |
383
|
|
|
return $this->image_title; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* setImageUrl |
388
|
|
|
* |
389
|
|
|
* @param string $image_url url of feed image |
390
|
|
|
* |
391
|
|
|
* @return Feed |
392
|
|
|
*/ |
393
|
|
|
public function setImageUrl($image_url) |
394
|
|
|
{ |
395
|
|
|
$this->image_url = $image_url; |
396
|
|
|
return $this; |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* getImageUrl |
401
|
|
|
* |
402
|
|
|
* @return string url of feed image |
403
|
|
|
*/ |
404
|
|
|
public function getImageUrl() |
405
|
|
|
{ |
406
|
|
|
return $this->image_url; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* setImageWidth |
411
|
|
|
* |
412
|
|
|
* @param int $image_width width of feed image |
413
|
|
|
* |
414
|
|
|
* @return Feed |
415
|
|
|
*/ |
416
|
|
|
public function setImageWidth($image_width) |
417
|
|
|
{ |
418
|
|
|
$this->image_width = $image_width; |
419
|
|
|
return $this; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* getImageWidth |
424
|
|
|
* |
425
|
|
|
* @return int width of feed image |
426
|
|
|
*/ |
427
|
|
|
public function getImageWidth() |
428
|
|
|
{ |
429
|
|
|
return $this->image_width; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* setItems |
434
|
|
|
* |
435
|
|
|
* @param array $items feed items |
436
|
|
|
* |
437
|
|
|
* @return Feed |
438
|
|
|
*/ |
439
|
|
|
public function setItems($items) |
440
|
|
|
{ |
441
|
|
|
$this->items = $items; |
442
|
|
|
return $this; |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* getItems |
447
|
|
|
* |
448
|
|
|
* @return array feed items |
449
|
|
|
*/ |
450
|
|
|
public function getItems() |
451
|
|
|
{ |
452
|
|
|
return $this->items; |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* setLanguage |
457
|
|
|
* |
458
|
|
|
* @param string $language feed language |
459
|
|
|
* |
460
|
|
|
* @return Feed |
461
|
|
|
*/ |
462
|
|
|
public function setLanguage($language) |
463
|
|
|
{ |
464
|
|
|
$this->language = $language; |
465
|
|
|
return $this; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* getLanguage |
470
|
|
|
* |
471
|
|
|
* @return string feed language |
472
|
|
|
*/ |
473
|
|
|
public function getLanguage() |
474
|
|
|
{ |
475
|
|
|
return $this->language; |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* setLastbuild |
480
|
|
|
* |
481
|
|
|
* @param string $lastbuild last build time |
482
|
|
|
* |
483
|
|
|
* @return Feed |
484
|
|
|
*/ |
485
|
|
|
public function setLastbuild($lastbuild) |
486
|
|
|
{ |
487
|
|
|
$this->lastbuild = $lastbuild; |
488
|
|
|
return $this; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* getLastbuild |
493
|
|
|
* |
494
|
|
|
* @return string last build time |
495
|
|
|
*/ |
496
|
|
|
public function getLastbuild() |
497
|
|
|
{ |
498
|
|
|
return $this->lastbuild; |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
/** |
502
|
|
|
* setPubdate |
503
|
|
|
* |
504
|
|
|
* @param string $pubdate publish date |
505
|
|
|
* |
506
|
|
|
* @return Feed |
507
|
|
|
*/ |
508
|
|
|
public function setPubdate($pubdate) |
509
|
|
|
{ |
510
|
|
|
$this->pubdate = $pubdate; |
511
|
|
|
return $this; |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
/** |
515
|
|
|
* getPubdate |
516
|
|
|
* |
517
|
|
|
* @return string publish date |
518
|
|
|
*/ |
519
|
|
|
public function getPubdate() |
520
|
|
|
{ |
521
|
|
|
return $this->pubdate; |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* setTitle |
526
|
|
|
* |
527
|
|
|
* @param string $title feed title |
528
|
|
|
* |
529
|
|
|
* @return Feed |
530
|
|
|
*/ |
531
|
|
|
public function setTitle($title) |
532
|
|
|
{ |
533
|
|
|
$this->title = $title; |
534
|
|
|
return $this; |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
/** |
538
|
|
|
* getTitle |
539
|
|
|
* |
540
|
|
|
* @return string feed title |
541
|
|
|
*/ |
542
|
|
|
public function getTitle() |
543
|
|
|
{ |
544
|
|
|
return $this->title; |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
/** |
548
|
|
|
* setTtl |
549
|
|
|
* |
550
|
|
|
* @param int $ttl feed time to live |
551
|
|
|
* |
552
|
|
|
* @return Feed |
553
|
|
|
*/ |
554
|
|
|
public function setTtl($ttl) |
555
|
|
|
{ |
556
|
|
|
$this->ttl = $ttl; |
557
|
|
|
return $this; |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* getTtl |
562
|
|
|
* |
563
|
|
|
* @return int feed time to live |
564
|
|
|
*/ |
565
|
|
|
public function getTtl() |
566
|
|
|
{ |
567
|
|
|
return $this->ttl; |
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
/** |
571
|
|
|
* set url |
572
|
|
|
* |
573
|
|
|
* @param string $url feed site url |
574
|
|
|
* |
575
|
|
|
* @return Feed |
576
|
|
|
*/ |
577
|
|
|
public function setUrl($url) |
578
|
|
|
{ |
579
|
|
|
$this->url = $url; |
580
|
|
|
return $this; |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
/** |
584
|
|
|
* getUrl |
585
|
|
|
* |
586
|
|
|
* @return string feed site url |
587
|
|
|
*/ |
588
|
|
|
public function getUrl() |
589
|
|
|
{ |
590
|
|
|
return $this->url; |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
/** |
594
|
|
|
* setWebmaster |
595
|
|
|
* |
596
|
|
|
* @param string $webmaster feed site webmaster |
597
|
|
|
* |
598
|
|
|
* @return Feed |
599
|
|
|
*/ |
600
|
|
|
public function setWebmaster($webmaster) |
601
|
|
|
{ |
602
|
|
|
$this->webmaster = $webmaster; |
603
|
|
|
return $this; |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
/** |
607
|
|
|
* getWebmaster |
608
|
|
|
* |
609
|
|
|
* @return string feed site webmaster |
610
|
|
|
*/ |
611
|
|
|
public function getWebmaster() |
612
|
|
|
{ |
613
|
|
|
return $this->webmaster; |
614
|
|
|
} |
615
|
|
|
} |
616
|
|
|
|
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state