PortableInfobox/services/Sanitizers/NodeImageSanitizer.php

29 lines
881 B
PHP
Raw Normal View History

2015-12-23 14:54:03 +00:00
<?php
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"]' ];
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
*
* @param $data
* @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;
}
}