PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Utility / Sanitize.php

Sanitize.php in Depicter — Popup & Slider Builder trunk, at app/src/Utility/Sanitize.php

114 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Utility;
3
4 use \Averta\WordPress\Utility\Sanitize as SanitizeBase;
5
6 class Sanitize extends SanitizeBase {
7
8 public static function html( $input, $allowed_tags = null, $namespace = null, $auto_p = false ){
9 // A fix to allow empty data url for src in image tag
10 if( $namespace === 'depicter/output' ){
11 add_filter( 'wp_kses_uri_attributes', [ __CLASS__, 'skipSrcEscapeTemporary' ], 25 );
12 add_filter( 'safe_style_css', [ __CLASS__, 'modifyAllowedCssAttributes' ]);
13 add_filter( 'safecss_filter_attr_allow_css', [ __CLASS__, 'checkAllowedCssValue' ], 10, 2);
14 }
15 $sanitized = parent::html( $input, $allowed_tags, $namespace, $auto_p );
16 if( $namespace === 'depicter/output' ){
17 remove_filter( 'wp_kses_uri_attributes', [ __CLASS__, 'skipSrcEscapeTemporary' ], 25 );
18 remove_filter( 'safe_style_css', [ __CLASS__, 'modifyAllowedCssAttributes' ]);
19 remove_filter( 'safecss_filter_attr_allow_css', [ __CLASS__, 'checkAllowedCssValue' ], 10, 2);
20 }
21
22 return $sanitized;
23 }
24
25 /**
26 * Retrieves default WordPress HTML tags
27 *
28 * @return array
29 */
30 protected static function defaultAllowedTags(){
31 $tags = parent::defaultAllowedTags();
32
33 $tags['style'] = [
34 'type' => true
35 ];
36 $tags['script'] = [
37 'id' => true,
38 'src' => true
39 ];
40 $tags['link'] = [
41 'rel' => true,
42 'id' => true,
43 'href' => true,
44 'media' => true,
45 ];
46 return $tags;
47 }
48
49 /**
50 * Ignore src escaping because `wp_kses` strips `data:` from image placeholder source in PHP 8.0+
51 *
52 * @param array $uriAttributes
53 *
54 * @return array $uriAttributes
55 */
56 public static function skipSrcEscapeTemporary( $uriAttributes ) {
57 if ( ( $key = array_search( 'src', $uriAttributes ) ) !== false) {
58 unset( $uriAttributes[ $key ] );
59 }
60 return $uriAttributes;
61 }
62
63 /**
64 * Modify allowed css attributes
65 *
66 * @param $properties
67 *
68 * @return mixed
69 */
70 public static function modifyAllowedCssAttributes( $properties ) {
71 $properties = array_merge( $properties, [
72 'fill',
73 'opacity',
74 'stroke',
75 'stroke-width',
76 'stroke-opacity',
77 'fill-opacity',
78 'stop-color',
79 'transform',
80 'fill-rule',
81 'clip-rule',
82 'stroke-linejoin',
83 'stroke-miterlimit'
84 ]);
85
86 return $properties;
87 }
88
89 /**
90 * Check for allowed css values
91 *
92 * @param $allowed
93 * @param $css_test_string
94 *
95 * @return bool
96 */
97 public static function checkAllowedCssValue( $allowed, $css_test_string ): bool{
98
99 $allowedCssValues = [
100 'rotate',
101 'scale',
102 'evenodd',
103 'round'
104 ];
105
106 foreach( $allowedCssValues as $value ) {
107 if ( ! $allowed && str_contains( $css_test_string, $value ) ) {
108 return true;
109 }
110 }
111 return $allowed;
112 }
113 }
114