class-affiliate.php
1 year ago
class-email-signup.php
1 year ago
class-help.php
1 year ago
class-polylang.php
1 year ago
class-review-box.php
1 year ago
class-upgrade-box.php
1 year ago
class-wpml.php
1 year ago
folders.class.php
1 year ago
form.class.php
1 year ago
form.fields.php
1 year ago
import.export.class.php
1 year ago
media.replace.php
1 year ago
notifications.class.php
1 year ago
plugins.class.php
1 year ago
svg.class.php
1 year ago
tree.class.php
1 year ago
svg.class.php
69 lines
| 1 | <?php |
| 2 | if(!class_exists('enshrined\svgSanitize\Sanitizer') ) { |
| 3 | $svgFiles = array( |
| 4 | 'libraries/svg-sanitizer/src/data/AttributeInterface.php', |
| 5 | 'libraries/svg-sanitizer/src/data/TagInterface.php', |
| 6 | 'libraries/svg-sanitizer/src/data/AllowedAttributes.php', |
| 7 | 'libraries/svg-sanitizer/src/data/AllowedTags.php', |
| 8 | 'libraries/svg-sanitizer/src/data/XPath.php', |
| 9 | 'libraries/svg-sanitizer/src/ElementReference/Resolver.php', |
| 10 | 'libraries/svg-sanitizer/src/ElementReference/Subject.php', |
| 11 | 'libraries/svg-sanitizer/src/ElementReference/Usage.php', |
| 12 | 'libraries/svg-sanitizer/src/Exceptions/NestingException.php', |
| 13 | 'libraries/svg-sanitizer/src/Helper.php', |
| 14 | 'libraries/svg-sanitizer/src/Sanitizer.php' |
| 15 | ); |
| 16 | |
| 17 | foreach( $svgFiles as $svgFile ) { |
| 18 | $real_path = WCP_FOLDERS_PLUGIN_PATH . $svgFile; |
| 19 | if(file_exists( $real_path ) ) { |
| 20 | require_once( $real_path ); |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | if(!function_exists('isGzipped') ) { |
| 26 | function isGzipped( $data ){ |
| 27 | if( function_exists('mb_strpos') ){ |
| 28 | return 0 === mb_strpos( $data, "\x1f" . "\x8b" . "\x08" ); |
| 29 | }else{ |
| 30 | return 0 === strpos( $data, "\x1f" . "\x8b" . "\x08" ); |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | if(!function_exists('sanitizeSvgFileContent')) { |
| 36 | function sanitizeSvgFileContent($filePath) |
| 37 | { |
| 38 | $data = file_get_contents( $filePath ); |
| 39 | |
| 40 | $is_zipped = isGzipped( $data ); |
| 41 | if( $is_zipped ){ |
| 42 | $data = gzdecode( $data ); |
| 43 | if( $data === false ){ |
| 44 | return false; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // load sanitizer |
| 49 | $sanitizer = new \enshrined\svgSanitize\Sanitizer(); |
| 50 | $sanitizer->removeXMLTag( true ); |
| 51 | $sanitizer->minify( true ); |
| 52 | |
| 53 | $clean = $sanitizer->sanitize( $data ); |
| 54 | |
| 55 | if( $clean === false ){ |
| 56 | |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | if( $is_zipped ){ |
| 61 | $clean = gzencode( $clean ); |
| 62 | } |
| 63 | |
| 64 | // Save cleaned file |
| 65 | file_put_contents( $filePath, $clean ); |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | } |