1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Sitemap node |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace FRUIT\GoogleServices\Domain\Model; |
8
|
|
|
|
9
|
|
|
use FRUIT\GoogleServices\Domain\Model\Node\GeoNode; |
10
|
|
|
use FRUIT\GoogleServices\Domain\Model\Node\ImageNode; |
11
|
|
|
use FRUIT\GoogleServices\Domain\Model\Node\NewsNode; |
12
|
|
|
use FRUIT\GoogleServices\Domain\Model\Node\VideoNode; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Sitemap Node |
16
|
|
|
*/ |
17
|
|
|
class Node extends AbstractModel |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Constants for usage in setChangefreq() |
22
|
|
|
*/ |
23
|
|
|
const CHANGE_FREQ_AWLAYS = 'always'; |
24
|
|
|
const CHANGE_FREQ_HOURLY = 'hourly'; |
25
|
|
|
const CHANGE_FREQ_DAILY = 'daily'; |
26
|
|
|
const CHANGE_FREQ_WEEKLY = 'weekly'; |
27
|
|
|
const CHNAGE_FREQ_MONTHLY = 'monthly'; |
28
|
|
|
const CHANGE_FREQ_YEARLY = 'yearly'; |
29
|
|
|
const CHANGE_FREQ_NEVER = 'never'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Location |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $loc; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Last modifcation |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $lastmod; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Change frequency |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $changefreq; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Priority |
54
|
|
|
* |
55
|
|
|
* @var float |
56
|
|
|
*/ |
57
|
|
|
protected $priority; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Geo |
61
|
|
|
* |
62
|
|
|
* @var GeoNode |
63
|
|
|
*/ |
64
|
|
|
protected $geo; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Images |
68
|
|
|
* |
69
|
|
|
* @var array |
70
|
|
|
*/ |
71
|
|
|
protected $images = []; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Video |
75
|
|
|
* |
76
|
|
|
* @var VideoNode |
77
|
|
|
*/ |
78
|
|
|
protected $video; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* News |
82
|
|
|
* |
83
|
|
|
* @var NewsNode |
84
|
|
|
*/ |
85
|
|
|
protected $news; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get location |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function getLoc() |
93
|
|
|
{ |
94
|
|
|
return $this->loc; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Get last modification |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function getLastmod() |
103
|
|
|
{ |
104
|
|
|
return $this->lastmod; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get change frequency |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function getChangefreq() |
113
|
|
|
{ |
114
|
|
|
if (!strlen($this->changefreq)) { |
115
|
|
|
return false; |
116
|
|
|
} |
117
|
|
|
return $this->changefreq; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Get priotiy |
122
|
|
|
* |
123
|
|
|
* @return float |
124
|
|
|
*/ |
125
|
|
|
public function getPriority() |
126
|
|
|
{ |
127
|
|
|
if ($this->priority === null) { |
128
|
|
|
return -1; |
129
|
|
|
} |
130
|
|
|
return $this->priority; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get geo |
135
|
|
|
* |
136
|
|
|
* @return GeoNode |
137
|
|
|
*/ |
138
|
|
|
public function getGeo() |
139
|
|
|
{ |
140
|
|
|
return $this->geo; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Get images |
145
|
|
|
* |
146
|
|
|
* @return array |
147
|
|
|
*/ |
148
|
|
|
public function getImages() |
149
|
|
|
{ |
150
|
|
|
return $this->images; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Add image |
155
|
|
|
* |
156
|
|
|
* @param ImageNode $image |
157
|
|
|
*/ |
158
|
|
|
public function addImage(ImageNode $image) |
159
|
|
|
{ |
160
|
|
|
$this->images[] = $image; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* get Video |
165
|
|
|
* |
166
|
|
|
* @return VideoNode |
167
|
|
|
*/ |
168
|
|
|
public function getVideo() |
169
|
|
|
{ |
170
|
|
|
return $this->video; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Get news |
175
|
|
|
* |
176
|
|
|
* @return NewsNode |
177
|
|
|
*/ |
178
|
|
|
public function getNews() |
179
|
|
|
{ |
180
|
|
|
return $this->news; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Set location |
185
|
|
|
* |
186
|
|
|
* @param string $loc |
187
|
|
|
* |
188
|
|
|
* @throws \Exception |
189
|
|
|
*/ |
190
|
|
|
public function setLoc($loc) |
191
|
|
|
{ |
192
|
|
|
if (!filter_var($loc, FILTER_VALIDATE_URL)) { |
193
|
|
|
throw new \Exception('The location of a google sitemap has have to be a valid URL'); |
194
|
|
|
} |
195
|
|
|
$this->loc = $loc; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Set last modifiction date |
200
|
|
|
* |
201
|
|
|
* @param string $lastmod |
202
|
|
|
*/ |
203
|
|
|
public function setLastmod($lastmod) |
204
|
|
|
{ |
205
|
|
|
|
206
|
|
|
// timestamp or parsable date |
207
|
|
|
|
208
|
|
|
$this->lastmod = $lastmod; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Set change frequency |
213
|
|
|
* |
214
|
|
|
* @param string $changefreq One of the Node::CHANGE_FREQ_* constants. |
215
|
|
|
* |
216
|
|
|
* @throws \Exception |
217
|
|
|
*/ |
218
|
|
|
public function setChangefreq($changefreq) |
219
|
|
|
{ |
220
|
|
|
$possibleValues = [ |
221
|
|
|
self::CHANGE_FREQ_AWLAYS, |
222
|
|
|
self::CHANGE_FREQ_HOURLY, |
223
|
|
|
self::CHANGE_FREQ_DAILY, |
224
|
|
|
self::CHANGE_FREQ_WEEKLY, |
225
|
|
|
self::CHNAGE_FREQ_MONTHLY, |
226
|
|
|
self::CHANGE_FREQ_YEARLY, |
227
|
|
|
self::CHANGE_FREQ_NEVER, |
228
|
|
|
]; |
229
|
|
|
|
230
|
|
|
if (!in_array(trim($changefreq), $possibleValues)) { |
231
|
|
|
throw new \Exception('The value of the changefreq have to be one of theses values: ' . implode(',', $possibleValues)); |
232
|
|
|
} |
233
|
|
|
$this->changefreq = $changefreq; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Set priority |
238
|
|
|
* |
239
|
|
|
* @param float $priority |
240
|
|
|
* |
241
|
|
|
* @throws \Exception |
242
|
|
|
*/ |
243
|
|
|
public function setPriority($priority) |
244
|
|
|
{ |
245
|
|
|
if (!is_float($priority)) { |
246
|
|
|
throw new \Exception('Parameter $priority has to be a float value'); |
247
|
|
|
} |
248
|
|
|
if ($priority < 0) { |
249
|
|
|
$this->setPriority(0.0); |
250
|
|
|
} |
251
|
|
|
if ($priority > 1) { |
252
|
|
|
$this->setPriority(1.0); |
253
|
|
|
} |
254
|
|
|
$this->priority = $priority; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Set geo |
259
|
|
|
* |
260
|
|
|
* @param GeoNode $geo |
261
|
|
|
*/ |
262
|
|
|
public function setGeo(GeoNode $geo) |
263
|
|
|
{ |
264
|
|
|
$this->geo = $geo; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* Set images |
269
|
|
|
* |
270
|
|
|
* @param array $images |
271
|
|
|
*/ |
272
|
|
|
public function setImages(array $images) |
273
|
|
|
{ |
274
|
|
|
$this->images = $images; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Set video |
279
|
|
|
* |
280
|
|
|
* @param VideoNode $video |
281
|
|
|
*/ |
282
|
|
|
public function setVideo(VideoNode $video) |
283
|
|
|
{ |
284
|
|
|
$this->video = $video; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Set news |
289
|
|
|
* |
290
|
|
|
* @param NewsNode $news |
291
|
|
|
*/ |
292
|
|
|
public function setNews(NewsNode $news) |
293
|
|
|
{ |
294
|
|
|
$this->news = $news; |
295
|
|
|
} |
296
|
|
|
} |
297
|
|
|
|