1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package net.nemein.rss |
4
|
|
|
* @author CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
5
|
|
|
* @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
6
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
use SimplePie\Item; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Helper class for custom RSS handling |
13
|
|
|
* |
14
|
|
|
* @package net.nemein.rss |
15
|
|
|
*/ |
16
|
|
|
class net_nemein_rss_parser_item extends Item |
17
|
|
|
{ |
18
|
|
|
private $_id_missing = true; |
19
|
|
|
|
20
|
|
|
private $_local_guid; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @inheritdoc |
24
|
|
|
*/ |
25
|
4 |
|
public function get_title() |
26
|
|
|
{ |
27
|
4 |
|
$title = parent::get_title(); |
28
|
4 |
|
if (empty($title)) { |
29
|
3 |
|
$l10n = midcom::get()->i18n->get_l10n('net.nemein.rss'); |
30
|
3 |
|
$title = $l10n->get('untitled'); |
31
|
3 |
|
$description = $this->get_description(); |
32
|
3 |
|
$date = $this->get_date('U'); |
33
|
3 |
|
if (!empty($description)) { |
34
|
|
|
// Use 20 first characters from the description as title |
35
|
2 |
|
$title = mb_substr(strip_tags($this->_decode($description)), 0, 20) . '...'; |
36
|
1 |
|
} elseif (!empty($date)) { |
37
|
|
|
// Use publication date as title |
38
|
|
|
$title = $l10n->get_formatter()->date($date); |
39
|
|
|
} |
40
|
|
|
} |
41
|
4 |
|
return $title; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @inheritdoc |
46
|
|
|
*/ |
47
|
4 |
|
public function get_description($description_only = false) |
48
|
|
|
{ |
49
|
4 |
|
return $this->_decode(parent::get_description($description_only)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritdoc |
54
|
|
|
*/ |
55
|
2 |
|
public function get_content($content_only = false) |
56
|
|
|
{ |
57
|
2 |
|
return $this->_decode(parent::get_content($content_only)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritdoc |
62
|
|
|
*/ |
63
|
4 |
|
public function get_link($key = 0, $rel = 'alternate') |
64
|
|
|
{ |
65
|
4 |
|
$link = parent::get_link($key, $rel); |
66
|
4 |
|
if ( $rel !== 'alternate' |
67
|
|
|
|| $key !== 0) { |
68
|
1 |
|
return $link; |
69
|
|
|
} |
70
|
|
|
|
71
|
4 |
|
if (empty($link)) { |
72
|
4 |
|
if (!$this->_id_missing) { |
73
|
|
|
$link = $this->get_id(); |
74
|
|
|
} else { |
75
|
|
|
// No link or GUID defined |
76
|
|
|
// TODO: Generate a "link" using channel URL |
77
|
4 |
|
$link = ''; |
78
|
|
|
} |
79
|
|
|
} |
80
|
4 |
|
return $link; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @inheritdoc |
85
|
|
|
*/ |
86
|
4 |
|
public function get_id($hash = false, $fn = 'md5') |
87
|
|
|
{ |
88
|
4 |
|
$guid = parent::get_id($hash, false); |
89
|
|
|
|
90
|
4 |
|
if (empty($guid)) { |
91
|
2 |
|
$this->_id_missing = true; |
92
|
2 |
|
$guid = parent::get_link(); |
93
|
|
|
} |
94
|
|
|
|
95
|
4 |
|
return $guid; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function get_local_guid() |
99
|
|
|
{ |
100
|
|
|
return $this->_local_guid; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function set_local_guid(string $guid) |
104
|
|
|
{ |
105
|
|
|
$this->_local_guid = $guid; |
106
|
|
|
} |
107
|
|
|
|
108
|
4 |
|
private function _decode($string) : string |
109
|
|
|
{ |
110
|
4 |
|
return html_entity_decode((string) $string, ENT_QUOTES, midcom::get()->i18n->get_current_charset()); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|