PluginProbe
Borderless – Addons and Templates for Elementor / 1.1.9
Borderless – Addons and Templates for Elementor v1.1.9
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 All 78 releases
borderless / includes / svg / sanitizer.php

sanitizer.php in Borderless – Addons and Templates for Elementor 1.1.9, at includes/svg/sanitizer.php

58 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // If this file is called directly, abort.
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /* Sanitize SVG during uploading */
8 class BORDERLESS_SvgSanitizer {
9
10 private $document;
11 private static $whitelist_elems = array();
12 private static $whitelist_attrs = array();
13
14 function __construct() {
15 global $whitelist_elems;
16 global $whitelist_attrs;
17
18 $this->document = new DOMDocument();
19 $this->document->preserveWhiteSpace = FALSE;
20
21 require_once 'whitelist.php';
22
23 self::$whitelist_elems = $whitelist_elems;
24 self::$whitelist_attrs = $whitelist_attrs;
25 }
26
27 function load_svg( $file ) {
28 $this->document->load( $file );
29 }
30
31 function borderless_sanitize_svg() {
32 $elems = $this->document->getElementsByTagName( "*" );
33
34 for( $i = 0; $i < $elems->length; $i++ ) {
35 $node = $elems->item($i);
36
37 $tag_name = $node->tagName;
38 if( in_array( $tag_name, self::$whitelist_elems ) ) {
39 for( $j = 0; $j < $node->attributes->length; $j++ ) {
40 $attr_name = $node->attributes->item($j)->name;
41 if( !in_array( $attr_name, self::$whitelist_attrs ) ) {
42 $node->removeAttribute( $attr_name );
43 }
44 }
45 } else {
46 $node->parentNode->removeChild( $node );
47 }
48 }
49 }
50
51 function save_svg() {
52 $this->document->formatOutput = TRUE;
53
54 return $this->document->saveXML();
55 }
56 }
57
58 ?>