|
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 Image implements OutputInterface, AppendAttributeInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Location (URL). |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $loc; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The caption of the image. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $caption; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The geographic location of the image. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $geoLocation; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The title of the image. |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $title; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* A URL to the license of the image. |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $license; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Image constructor |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $loc |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct($loc) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->loc = $loc; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* {@inheritdoc} |
|
63
|
|
|
*/ |
|
64
|
|
|
public function generateXML(XMLWriter $XMLWriter) |
|
65
|
|
|
{ |
|
66
|
|
|
$XMLWriter->startElement('image:image'); |
|
67
|
|
|
$XMLWriter->writeElement('image:loc', $this->getLoc()); |
|
68
|
|
|
|
|
69
|
|
|
$this->optionalWriteElement($XMLWriter, 'image:caption', $this->getCaption()); |
|
70
|
|
|
$this->optionalWriteElement($XMLWriter, 'image:geo_location', $this->getGeoLocation()); |
|
71
|
|
|
$this->optionalWriteElement($XMLWriter, 'image:title', $this->getTitle()); |
|
72
|
|
|
$this->optionalWriteElement($XMLWriter, 'image:license', $this->getLicense()); |
|
73
|
|
|
|
|
74
|
|
|
$XMLWriter->endElement(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Location (URL). |
|
79
|
|
|
* |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getLoc() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->loc; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param XMLWriter $XMLWriter |
|
89
|
|
|
* @param string $name |
|
90
|
|
|
* @param string $value |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function optionalWriteElement(XMLWriter $XMLWriter, $name, $value) |
|
93
|
|
|
{ |
|
94
|
|
|
if ($value) { |
|
95
|
|
|
$XMLWriter->writeElement($name, $value); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* The caption of the image. |
|
101
|
|
|
* |
|
102
|
|
|
* @return string |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getCaption() |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->caption; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Set the caption of the image. |
|
111
|
|
|
* |
|
112
|
|
|
* @param string $caption |
|
113
|
|
|
* |
|
114
|
|
|
* @return $this |
|
115
|
|
|
*/ |
|
116
|
|
|
public function setCaption($caption) |
|
117
|
|
|
{ |
|
118
|
|
|
$this->caption = $caption; |
|
119
|
|
|
|
|
120
|
|
|
return $this; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* The geographic location of the image. |
|
125
|
|
|
* |
|
126
|
|
|
* @return string |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getGeoLocation() |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->geoLocation; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Set the geographic location of the image. |
|
135
|
|
|
* |
|
136
|
|
|
* @param string $geoLocation |
|
137
|
|
|
* |
|
138
|
|
|
* @return $this |
|
139
|
|
|
*/ |
|
140
|
|
|
public function setGeoLocation($geoLocation) |
|
141
|
|
|
{ |
|
142
|
|
|
$this->geoLocation = $geoLocation; |
|
143
|
|
|
|
|
144
|
|
|
return $this; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* The title of the image. |
|
149
|
|
|
* |
|
150
|
|
|
* @return string |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getTitle() |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->title; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Set the title of the image. |
|
159
|
|
|
* |
|
160
|
|
|
* @param string $title |
|
161
|
|
|
* |
|
162
|
|
|
* @return $this |
|
163
|
|
|
*/ |
|
164
|
|
|
public function setTitle($title) |
|
165
|
|
|
{ |
|
166
|
|
|
$this->title = $title; |
|
167
|
|
|
|
|
168
|
|
|
return $this; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* A URL to the license of the image. |
|
173
|
|
|
* |
|
174
|
|
|
* @return string |
|
175
|
|
|
*/ |
|
176
|
|
|
public function getLicense() |
|
177
|
|
|
{ |
|
178
|
|
|
return $this->license; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Set a URL to the license of the image. |
|
183
|
|
|
* |
|
184
|
|
|
* @param string $license |
|
185
|
|
|
* |
|
186
|
|
|
* @return $this |
|
187
|
|
|
*/ |
|
188
|
|
|
public function setLicense($license) |
|
189
|
|
|
{ |
|
190
|
|
|
$this->license = $license; |
|
191
|
|
|
|
|
192
|
|
|
return $this; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* {@inheritdoc} |
|
197
|
|
|
*/ |
|
198
|
|
|
public function appendAttributeToCollectionXML(XMLWriter $XMLWriter) |
|
199
|
|
|
{ |
|
200
|
|
|
$XMLWriter->writeAttribute('xmlns:image', 'http://www.google.com/schemas/sitemap-image/1.1'); |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
|