Server : Apache System : Linux server.lienzindia.com 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64 User : plutus ( 1007) PHP Version : 7.4.33 Disable Function : NONE Directory : /home/plutus/public_html/wp-content/themes/vrm/inc/ |
Upload File : |
<?php namespace TotalTheme; \defined( 'ABSPATH' ) || exit; /** * Sanitize inputted data. */ class Sanitize_Data { /** * Main class function parses input to return sanitized output. */ public function parse_data( $input, string $type ) { $type = \str_replace( '-', '_', $type ); if ( \method_exists( $this, $type ) ) { return $this->$type( $input ); } return $input; // perhaps we should at least strip all tags? } /** * URL. */ public function url( string $input ): string { return (string) \esc_url( $input ); } /** * Text. */ public function text( string $input ): string { return (string) \sanitize_text_field( $input ); } /** * Text Field. */ public function text_field( string $input ): string { return (string) \sanitize_text_field( $input ); } /** * Textarea. */ public function textarea( string $input ): string { return (string) \wp_kses_post( $input ); } /** * Boolean. */ public function boolean( $input ): bool { return \wpex_validate_boolean( $input ); } /** * Pixels. */ public function px( string $input ): string { if ( 'none' === $input ) { return '0px'; } else { return floatval( $input ) . 'px'; // Not sure why we used floatval but lets leave it incase } } /** * Milliseconds. */ public function ms( string $input ): string { return floatval( $input ) . 'ms'; } /** * Pixel Fallback. */ public function fallback_px( string $input ): string { if ( 'none' === $input ) { return '0px'; } elseif ( \is_numeric( $input ) ) { return floatval( $input ) . 'px'; // Not sure why we used floatval but lets leave it incase. } return (string) \sanitize_text_field( $input ); } /** * Container width. */ public function container_width( string $input ): ?string { if ( \is_numeric( $input ) ) { return null; // Prevent values without units from working - this is a fix for pre 5.4. } else { return (string) \sanitize_text_field( $input ); } } /** * Margin. */ public function margin( string $input ): string { if ( 'none' === $input || '0' === $input || 0 === $input || '0px' === $input ) { return '0px'; // must include px to prevent issues with calc } if ( \is_numeric( $input ) ) { return \sanitize_text_field( $input ) . 'px'; } return $input ? (string) \esc_attr( $input ) : ''; } /** * Padding. */ public function padding( string $input ): string { if ( 'none' === $input || '0' === $input || 0 === $input || '0px' === $input ) { return '0px'; // must include px to prevent issues with calc } if ( \is_numeric( $input ) ) { return \sanitize_text_field( $input ) . 'px'; } return $input ? (string) \esc_attr( $input ) : ''; } /** * Font Size utl. */ public function utl_font_size( string $input ) { if ( $input && \array_key_exists( $input, \wpex_utl_font_sizes() ) ) { return 'var(--wpex-text-' . \esc_attr( $input ) . ')'; } } /** * Border Radius. */ public function utl_border_radius( string $input ): string { if ( 'rounded-0' === $input ) { return '0'; } elseif ( 'rounded-full' === $input ) { return '9999px'; } elseif ( $input && \array_key_exists( $input, \wpex_utl_border_radius() ) ) { return 'var(--wpex-' . \esc_attr( $input ) . ')'; } else { return ''; } } /** * Font Size. */ public function font_size( string $input ) { return \wpex_sanitize_font_size( $input, 'font_size' ); } /** * Font Weight. */ public function font_weight( string $input ): string { $font_weight = ''; switch ( $input ) { case 'normal': $font_weight = '400'; break; case 'semibold': $font_weight = '600'; break; case 'bold': $font_weight = '700'; break; case 'bolder': $font_weight = '900'; break; default: $font_weight = (string) \sanitize_text_field( $input ); break; } return $font_weight; } /** * Hex Color. */ public function hex_color( string $input ): ?string { return (string) sanitize_hex_color( $input ); } /** * Border Radius. */ public function border_radius( string $input ): string { if ( 'none' === $input ) { return '0'; } if ( \is_numeric( $input ) ) { return "{$input}px"; } return $input ? \esc_attr( $input ) : ''; } /** * Pixel or Percent. */ public function px_pct( string $input ): string { if ( 'none' === $input || '0px' === $input ) { return '0'; } elseif ( \str_contains( $input, '%' ) ) { return \sanitize_text_field( $input ); } elseif ( $input = floatval( $input ) ) { return \sanitize_text_field( $input ) . 'px'; } else { return ''; } } /** * Pixel or Em. */ public function px_em( $input ): string { if ( 'none' === $input || '0px' === $input) { return '0'; } if ( \is_numeric( $input ) ) { return "{$input}px"; } $unit = $this->get_unit( $input ); if ( 'px' === $unit || 'em' === $unit ) { return \esc_attr( $input ); } $input = floatval( $input ); return $input ? "{$input}px" : ''; } /** * Opacity. */ public function opacity( string $input ): ?string { if ( ! \is_numeric( $input ) || $input > 1 ) { return null; } else { return (string) \sanitize_text_field( $input ); } } /** * HTML. */ public function html( string $input ): string { return (string) \wp_kses_post( $input ); } /** * Image. */ public function image( string $input ): string { return (string) \wp_kses( $input, [ 'img' => [ 'src' => [], 'alt' => [], 'srcset' => [], 'id' => [], 'class' => [], 'height' => [], 'width' => [], 'data' => [], 'data-rjs' => [], 'loading' => [], 'decoding' => [], 'itemprop' => [], ], ] ); } /** * Image. */ public function img( string $input ): string { return $this->image( $input ); } /** * Image from setting. */ public function image_src_from_mod( $input ): string { return (string) \wpex_get_image_url( $input ); } /** * Background Style. */ public function background_style_css( string $input ): string { $css = ''; switch ( $input ) { case 'stretched': $css = 'background-size: cover; background-position: center center; background-attachment: fixed; background-repeat: no-repeat;'; break; case 'cover': $css = 'background-position:center center;background-size: cover;'; break; case 'repeat': $css = 'background-repeat:repeat;'; break; case 'no-repeat': $css = 'background-repeat:no-repeat;'; break; case 'repeat-y': $css = 'background-position: center center;background-repeat:repeat-y;'; break; case 'fixed': $css = 'background-repeat: no-repeat;background-position: center center;background-attachment: fixed;'; break; case 'fixed-top': $css = 'background-repeat: no-repeat;background-position: center top;background-attachment: fixed;'; break; case 'fixed-bottom': $css = 'background-repeat: no-repeat;background-position: center bottom;background-attachment: fixed;'; break; default: $safe_input = esc_attr( $input ); if ( $safe_input ) { $css = "background-repeat:{$safe_input};"; } break; } return $css; } /** * Embed URL. */ public function embed_url( string $url ) { return (string) \wpex_get_video_embed_url( $url ); } /** * Google Map Embed. */ public function google_map( $input ): string { return (string) \wp_kses( $input, [ 'iframe' => [ 'src' => [], 'height' => [], 'width' => [], 'frameborder' => [], 'style' => [], 'allowfullscreen' => [], ], ] ); } /** * iFrame. */ public function iframe( $input ): string { return (string) \wp_kses( $input, [ 'iframe' => [ 'align' => [], 'width' => [], 'height' => [], 'frameborder' => [], 'name' => [], 'src' => [], 'id' => [], 'class' => [], 'style' => [], 'scrolling' => [], 'marginwidth' => [], 'marginheight' => [], 'allow' => [], ], ] ); } /** * SVG. */ public function svg( $input ): string { return (string) \wp_kses( $input, [ 'svg' => [ 'class' => true, 'aria-hidden' => true, 'aria-labelledby' => true, 'role' => true, 'xmlns' => true, 'width' => true, 'height' => true, 'viewbox' => true, // <= Must be lower case! 'style' => true, 'preserveAspectRatio' => true, // WP bug prevents this from working :( ], 'g' => [ 'fill' => true ], 'title' => [ 'title' => true ], 'path' => [ 'd' => true, 'fill' => true, 'class' => true, ], ] ); } /** * Return css unit (text) from input. */ protected function get_unit( string $input ): ?string { if ( $input && \is_string( $input ) && ! \is_numeric( $input ) ) { $non_numeric_string = \preg_replace( '/[^0-9.]/', '', $input ); $unit = \str_replace( $non_numeric_string, '', $input ); if ( $unit ) { return \trim( $unit ); } } return $unit ?? null; } }