[TASK] Use secure deserialization in extension manager
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / Parser / AbstractExtensionXmlParser.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility\Parser;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Abstract parser for TYPO3's extension.xml file.
19 */
20 abstract class AbstractExtensionXmlParser extends AbstractXmlParser
21 {
22 /**
23 * Keeps current author company of an extension's version.
24 *
25 * @var string
26 */
27 protected $authorcompany;
28
29 /**
30 * Keeps current author mail address of an extension's version.
31 *
32 * @var string
33 */
34 protected $authoremail;
35
36 /**
37 * Keeps current author name of an extension's version.
38 *
39 * @var string
40 */
41 protected $authorname;
42
43 /**
44 * Keeps current category of an extension's version.
45 *
46 * @var string
47 */
48 protected $category;
49
50 /**
51 * Keeps current dependencies of an extension's version.
52 *
53 * @var string
54 */
55 protected $dependencies;
56
57 /**
58 * Keeps current description of an extension's version.
59 *
60 * @var string
61 */
62 protected $description;
63
64 /**
65 * Keeps current download number sum of all extension's versions.
66 *
67 * @var string
68 */
69 protected $extensionDownloadCounter;
70
71 /**
72 * Keeps current key of an extension.
73 *
74 * @var string
75 */
76 protected $extensionKey;
77
78 /**
79 * Keeps current upload date of an extension's version.
80 *
81 * @var string
82 */
83 protected $lastuploaddate;
84
85 /**
86 * Keeps current owner username of an extension's version.
87 *
88 * @var string
89 */
90 protected $ownerusername;
91
92 /**
93 * Keeps current reviewstate of an extension's version.
94 *
95 * @var string
96 */
97 protected $reviewstate;
98
99 /**
100 * Keeps current state of an extension's version.
101 *
102 * @var string
103 */
104 protected $state;
105
106 /**
107 * Keeps current t3x file hash of an extension's version.
108 *
109 * @var string
110 */
111 protected $t3xfilemd5;
112
113 /**
114 * Keeps current title of an extension's version.
115 *
116 * @var string
117 */
118 protected $title;
119
120 /**
121 * Keeps current upload comment of an extension's version.
122 *
123 * @var string
124 */
125 protected $uploadcomment;
126
127 /**
128 * Keeps current version number.
129 *
130 * @var string
131 */
132 protected $version;
133
134 /**
135 * Keeps current download number of an extension's version.
136 *
137 * @var string
138 */
139 protected $versionDownloadCounter;
140
141 /**
142 * Returns an assoziative array of all extension version properties.
143 *
144 * Valid array keys of returned array are:
145 * extkey, version, alldownloadcounter, downloadcounter, title, description,
146 * state, reviewstate, category, lastuploaddate, uploadcomment, dependencies,
147 * authorname, authoremail, authorcompany, ownerusername, t3xfilemd5
148 *
149 * @access public
150 * @see $extensionKey, $version, $extensionDownloadCounter,
151 * @return array assoziative array of an extension version's properties
152 */
153 public function getAll()
154 {
155 $versionProperties = [];
156 $versionProperties['extkey'] = $this->extensionKey;
157 $versionProperties['version'] = $this->version;
158 $versionProperties['alldownloadcounter'] = $this->extensionDownloadCounter;
159 $versionProperties['downloadcounter'] = $this->versionDownloadCounter;
160 $versionProperties['title'] = $this->title;
161 $versionProperties['description'] = $this->description;
162 $versionProperties['state'] = $this->state;
163 $versionProperties['reviewstate'] = $this->reviewstate;
164 $versionProperties['category'] = $this->category;
165 $versionProperties['lastuploaddate'] = $this->lastuploaddate;
166 $versionProperties['uploadcomment'] = $this->uploadcomment;
167 $versionProperties['dependencies'] = $this->dependencies;
168 $versionProperties['authorname'] = $this->authorname;
169 $versionProperties['authoremail'] = $this->authoremail;
170 $versionProperties['authorcompany'] = $this->authorcompany;
171 $versionProperties['ownerusername'] = $this->ownerusername;
172 $versionProperties['t3xfilemd5'] = $this->t3xfilemd5;
173 return $versionProperties;
174 }
175
176 /**
177 * Returns download number sum of all extension's versions.
178 *
179 * @access public
180 * @return string download number sum
181 * @see $extensionDLCounter, getAll()
182 */
183 public function getAlldownloadcounter()
184 {
185 return $this->extensionDownloadCounter;
186 }
187
188 /**
189 * Returns company name of extension author.
190 *
191 * @access public
192 * @return string company name of extension author
193 * @see $authorcompany, getAll()
194 */
195 public function getAuthorcompany()
196 {
197 return $this->authorcompany;
198 }
199
200 /**
201 * Returns e-mail address of extension author.
202 *
203 * @access public
204 * @return string e-mail address of extension author
205 * @see $authoremail, getAll()
206 */
207 public function getAuthoremail()
208 {
209 return $this->authoremail;
210 }
211
212 /**
213 * Returns name of extension author.
214 *
215 * @access public
216 * @return string name of extension author
217 * @see $authorname, getAll()
218 */
219 public function getAuthorname()
220 {
221 return $this->authorname;
222 }
223
224 /**
225 * Returns category of an extension.
226 *
227 * @access public
228 * @return string extension category
229 * @see $category, getAll()
230 */
231 public function getCategory()
232 {
233 return $this->category;
234 }
235
236 /**
237 * Returns dependencies of an extension's version.
238 *
239 * @access public
240 * @return string extension dependencies
241 * @see $dependencies, getAll()
242 */
243 public function getDependencies()
244 {
245 return $this->dependencies;
246 }
247
248 /**
249 * Returns description of an extension's version.
250 *
251 * @access public
252 * @return string extension description
253 * @see $description, getAll()
254 */
255 public function getDescription()
256 {
257 return $this->description;
258 }
259
260 /**
261 * Returns download number of an extension's version.
262 *
263 * @access public
264 * @return string download number
265 * @see $versionDLCounter, getAll()
266 */
267 public function getDownloadcounter()
268 {
269 return $this->versionDownloadCounter;
270 }
271
272 /**
273 * Returns key of an extension.
274 *
275 * @access public
276 * @return string extension key
277 * @see $extensionKey, getAll()
278 */
279 public function getExtkey()
280 {
281 return $this->extensionKey;
282 }
283
284 /**
285 * Returns last uploaddate of an extension's version.
286 *
287 * @access public
288 * @return string last upload date of an extension's version
289 * @see $lastuploaddate, getAll()
290 */
291 public function getLastuploaddate()
292 {
293 return $this->lastuploaddate;
294 }
295
296 /**
297 * Returns username of extension owner.
298 *
299 * @access public
300 * @return string extension owner's username
301 * @see $ownerusername, getAll()
302 */
303 public function getOwnerusername()
304 {
305 return $this->ownerusername;
306 }
307
308 /**
309 * Returns review state of an extension's version.
310 *
311 * @access public
312 * @return string extension review state
313 * @see $reviewstate, getAll()
314 */
315 public function getReviewstate()
316 {
317 return $this->reviewstate;
318 }
319
320 /**
321 * Returns state of an extension's version.
322 *
323 * @access public
324 * @return string extension state
325 * @see $state, getAll()
326 */
327 public function getState()
328 {
329 return $this->state;
330 }
331
332 /**
333 * Returns t3x file hash of an extension's version.
334 *
335 * @access public
336 * @return string t3x file hash *
337 * @see $t3xfilemd5, getAll()
338 */
339 public function getT3xfilemd5()
340 {
341 return $this->t3xfilemd5;
342 }
343
344 /**
345 * Returns title of an extension's version.
346 *
347 * @access public
348 * @return string extension title
349 * @see $title, getAll()
350 */
351 public function getTitle()
352 {
353 return $this->title;
354 }
355
356 /**
357 * Returns extension upload comment.
358 *
359 * @access public
360 * @return string extension upload comment
361 * @see $uploadcomment, getAll()
362 */
363 public function getUploadcomment()
364 {
365 return $this->uploadcomment;
366 }
367
368 /**
369 * Returns version number.
370 *
371 * @access public
372 * @return string version number
373 * @see $version, getAll()
374 */
375 public function getVersion()
376 {
377 return $this->version;
378 }
379
380 /**
381 * Method resets version class properties.
382 *
383 * @param bool $resetAll If TRUE, additionally extension properties are reset
384 * @see $extensionKey, $version, $extensionDLCounter, $versionDLCounter,
385 */
386 protected function resetProperties($resetAll = false)
387 {
388 // resetting at least class property "version" is mandatory
389 // as we need to do some magic in regards to
390 // an extension's and version's child node "downloadcounter"
391 $this->version = $this->title = $this->versionDownloadCounter = $this->description = $this->state = $this->reviewstate = $this->category = $this->lastuploaddate = $this->uploadcomment = $this->dependencies = $this->authorname = $this->authoremail = $this->authorcompany = $this->ownerusername = $this->t3xfilemd5 = null;
392 if ($resetAll) {
393 $this->extensionKey = $this->extensionDownloadCounter = null;
394 }
395 }
396
397 /**
398 * Convert dependencies from TER format to EM_CONF format
399 *
400 * @param string $dependencies serialized dependency array
401 * @return string
402 */
403 protected function convertDependencies($dependencies)
404 {
405 $newDependencies = [];
406 $dependenciesArray = unserialize($dependencies, ['allowed_classes' => false]);
407 if (is_array($dependenciesArray)) {
408 foreach ($dependenciesArray as $version) {
409 if (!empty($version['kind']) && !empty($version['extensionKey'])) {
410 $newDependencies[$version['kind']][$version['extensionKey']] = $version['versionRange'];
411 }
412 }
413 }
414 return serialize($newDependencies);
415 }
416 }