' . base64_encode( $output ) . '' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons. } public static function json_valid_check( $data ) { if ( is_array( $data ) ) { $output = array(); foreach ( $data as $key => $value ) { if ( is_string( $key ) ) { $id = self::json_convert_string( $key ); } else { $id = $key; } if ( is_array( $value ) || is_object( $value ) ) { $output[ $id ] = self::json_valid_check( $value ); } elseif ( is_string( $value ) ) { $output[ $id ] = self::json_convert_string( $value ); } else { $output[ $id ] = $value; } } } elseif ( is_object( $data ) ) { $output = new stdClass(); foreach ( $data as $key => $value ) { if ( is_string( $key ) ) { $id = self::json_convert_string( $key ); } else { $id = $key; } if ( is_array( $value ) || is_object( $value ) ) { $output->$id = self::json_valid_check( $value ); } elseif ( is_string( $value ) ) { $output->$id = self::json_convert_string( $value ); } else { $output->$id = $value; } } } elseif ( is_string( $data ) ) { return self::json_convert_string( $data ); } else { return $data; } return $output; } public function json_convert_string( $str ) { if ( function_exists( 'mb_convert_encoding' ) ) { $encoding = mb_detect_encoding( $str, mb_detect_order(), true ); if ( $encoding ) { return mb_convert_encoding( $str, 'UTF-8', $encoding ); } else { return mb_convert_encoding( $str, 'UTF-8', 'UTF-8' ); } } return $str; } public static function safe_json_encode( $value, $options = 0, $depth = 512 ) { $encoded = json_encode( $value, $options, $depth ); if ( false === $encoded && ! empty( $value ) && JSON_ERROR_UTF8 == json_last_error() ) { $encoded = json_encode( self::json_valid_check( $value ), $options, $depth ); } return $encoded; } public static function close_connection( $val = null ) { if ( isset( $_REQUEST['json_result'] ) && true == $_REQUEST['json_result'] ) : $output = self::safe_json_encode( $val ); else : $output = serialize( $val ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions. endif; $output = '' . base64_encode( $output ) . ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons. // Close browser connection so that it can resume AJAX polling. header( 'Content-Length: ' . strlen( $output ) ); header( 'Connection: close' ); header( 'Content-Encoding: none' ); if ( session_id() ) { session_write_close(); } echo $output; if ( ob_get_level() ) { ob_end_flush(); } flush(); } public static function error( $error, $code = null ) { $information['error'] = $error; if ( null !== $code ) { $information['error_code'] = $code; } self::write( $information ); } /** * PARSE * Parses some CSS into an array * CSSPARSER * Copyright (C) 2009 Peter Kröner */ public static function parse_css( $css ) { // Remove CSS-Comments. $css = preg_replace( '/\/\*.*?\*\//ms', '', $css ); // Remove HTML-Comments. $css = preg_replace( '/([^\'"]+?)(\