1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Thepixeldeveloper\Sitemap\Subelements; |
4
|
|
|
|
5
|
|
|
use Thepixeldeveloper\Sitemap\AppendAttributeInterface; |
6
|
|
|
use Thepixeldeveloper\Sitemap\OutputInterface; |
7
|
|
|
use XMLWriter; |
8
|
|
|
/** |
9
|
|
|
* Class Image |
10
|
|
|
* |
11
|
|
|
* @package Thepixeldeveloper\Sitemap\Subelements |
12
|
|
|
*/ |
13
|
|
|
class News implements OutputInterface, AppendAttributeInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $loc; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Publication name |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $publicationName; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Publication language |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $publicationLanguage; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Access |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $access; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* List of genres, comma-separated string values |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $genres; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Date of publication |
49
|
|
|
* |
50
|
|
|
* @var \DateTime |
51
|
|
|
*/ |
52
|
|
|
protected $publicationDate; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Title |
56
|
|
|
* |
57
|
|
|
* @var string |
58
|
|
|
*/ |
59
|
|
|
protected $title; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Key words, comma-separated string values |
63
|
|
|
* |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
protected $keywords; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getPublicationName() |
72
|
|
|
{ |
73
|
|
|
return $this->publicationName; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param string $publicationName |
78
|
|
|
* @return News |
79
|
|
|
*/ |
80
|
|
|
public function setPublicationName($publicationName) |
81
|
|
|
{ |
82
|
|
|
$this->publicationName = $publicationName; |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function getPublicationLanguage() |
91
|
|
|
{ |
92
|
|
|
return $this->publicationLanguage; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $publicationLanguage |
97
|
|
|
* @return News |
98
|
|
|
*/ |
99
|
|
|
public function setPublicationLanguage($publicationLanguage) |
100
|
|
|
{ |
101
|
|
|
$this->publicationLanguage = $publicationLanguage; |
102
|
|
|
|
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getAccess() |
110
|
|
|
{ |
111
|
|
|
return $this->access; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param string $access |
116
|
|
|
* @return News |
117
|
|
|
*/ |
118
|
|
|
public function setAccess($access) |
119
|
|
|
{ |
120
|
|
|
$this->access = $access; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
public function getGenres() |
129
|
|
|
{ |
130
|
|
|
return $this->genres; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param string $genres |
135
|
|
|
* @return News |
136
|
|
|
*/ |
137
|
|
|
public function setGenres($genres) |
138
|
|
|
{ |
139
|
|
|
$this->genres = $genres; |
140
|
|
|
|
141
|
|
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return \DateTime |
146
|
|
|
*/ |
147
|
|
|
public function getPublicationDate() |
148
|
|
|
{ |
149
|
|
|
return $this->publicationDate; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param \DateTime $publicationDate |
154
|
|
|
* @return News |
155
|
|
|
*/ |
156
|
|
|
public function setPublicationDate(\DateTime $publicationDate) |
157
|
|
|
{ |
158
|
|
|
$this->publicationDate = $publicationDate; |
159
|
|
|
|
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
|
|
public function getTitle() |
167
|
|
|
{ |
168
|
|
|
return $this->title; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param string $title |
173
|
|
|
* @return News |
174
|
|
|
*/ |
175
|
|
|
public function setTitle($title) |
176
|
|
|
{ |
177
|
|
|
$this->title = $title; |
178
|
|
|
|
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return string |
184
|
|
|
*/ |
185
|
|
|
public function getKeywords() |
186
|
|
|
{ |
187
|
|
|
return $this->keywords; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param string $keywords |
192
|
|
|
* @return News |
193
|
|
|
*/ |
194
|
|
|
public function setKeywords($keywords) |
195
|
|
|
{ |
196
|
|
|
$this->keywords = $keywords; |
197
|
|
|
|
198
|
|
|
return $this; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @inheritDoc |
203
|
|
|
*/ |
204
|
|
|
public function appendAttributeToCollectionXML(XMLWriter $XMLWriter) |
205
|
|
|
{ |
206
|
|
|
$XMLWriter->writeAttribute('xmlns:news', 'http://www.google.com/schemas/sitemap-news/0.9'); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @inheritDoc |
211
|
|
|
*/ |
212
|
|
|
public function generateXML(XMLWriter $XMLWriter) |
213
|
|
|
{ |
214
|
|
|
$XMLWriter->startElement('news:news'); |
215
|
|
|
$XMLWriter->startElement('news:publication'); |
216
|
|
|
$XMLWriter->writeElement('news:name', $this->getPublicationName()); |
217
|
|
|
$XMLWriter->writeElement('news:language', $this->getPublicationLanguage()); |
218
|
|
|
$XMLWriter->endElement(); |
219
|
|
|
$this->optionalWriteElement($XMLWriter, 'news:access', $this->getAccess()); |
220
|
|
|
$this->optionalWriteElement($XMLWriter, 'news:genres', $this->getGenres()); |
221
|
|
|
$XMLWriter->writeElement('news:publication_date', $this->getPublicationDate()->format(DATE_ISO8601)); |
222
|
|
|
$XMLWriter->writeElement('news:title', $this->getTitle()); |
223
|
|
|
$this->optionalWriteElement($XMLWriter, 'news:keywords', $this->getKeywords()); |
224
|
|
|
$XMLWriter->endElement(); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @param XMLWriter $XMLWriter |
229
|
|
|
* @param string $name |
230
|
|
|
* @param string $value |
231
|
|
|
*/ |
232
|
|
|
protected function optionalWriteElement(XMLWriter $XMLWriter, $name, $value) |
233
|
|
|
{ |
234
|
|
|
if ($value) { |
235
|
|
|
$XMLWriter->writeElement($name, $value); |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
} |