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