PortableInfobox/includes/services/Sanitizers/NodeImageSanitizer.php

35 lines
933 B
PHP
Raw Normal View History

2015-12-23 14:54:03 +00:00
<?php
namespace PortableInfobox\Sanitizers;
class NodeImageSanitizer extends NodeSanitizer {
2016-01-04 12:09:39 +00:00
protected $allowedTags = [ 'a' ];
protected $selectorsWrappingTextToPad = [ 'li' ];
2016-01-04 11:09:50 +00:00
protected $selectorsWrappingAllowedFeatures = [ 'sup[@class="reference"]' ];
2018-08-16 09:25:53 +00:00
protected $selectorsForFullRemoval = [
'script',
'span[@itemprop="duration"]',
'a[starts-with(@href, \'javascript:\')]'
];
2015-12-23 14:54:03 +00:00
/**
* @desc sanitize infobox image caption allowing only for links inside it
*
2018-08-16 09:25:53 +00:00
* @param mixed $data
2015-12-23 14:54:03 +00:00
* @return mixed
*/
public function sanitize( $data ) {
if ( isset( $data['images'] ) && is_array( $data['images'] ) ) {
$data['images'] = array_map( function ( $image ) {
$image['caption'] = $this->sanitizeElementData( $image['caption'] );
return $image;
}, $data['images'] );
} else {
2017-02-24 16:01:02 +00:00
$caption = $data['caption'] ?? '';
$data['caption'] = $this->sanitizeElementData( $caption );
}
2015-12-23 14:54:03 +00:00
return $data;
}
}