芝麻web文件管理V1.00
编辑当前文件:/home/freeclou/optimyar/wp-content/plugins/jet-elements/includes/class-jet-elements-svg-manager.php
get( 'svg_uploads', 'enabled' ); if ( 'enabled' !== $svg_enabled ) { return; } add_filter( 'upload_mimes', array( $this, 'allow_svg' ) ); add_action( 'admin_head', array( $this, 'fix_svg_thumb_display' ) ); add_filter( 'wp_generate_attachment_metadata', array( $this, 'generate_svg_media_files_metadata' ), 10, 2 ); add_filter( 'wp_prepare_attachment_for_js', array( $this, 'wp_prepare_attachment_for_js' ), 10, 3 ); } /** * Allow SVG images uploading * * @return array */ public function allow_svg( $mimes ) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } /** * Fix thumbnails display * * @return void */ public function fix_svg_thumb_display() { ?> svg_dimensions( $svg_path ); $metadata['width'] = $dimensions->width; $metadata['height'] = $dimensions->height; } return $metadata; } /** * Prepares an attachment post object for JS * * @return array */ public function wp_prepare_attachment_for_js( $response, $attachment, $meta ){ if( $response['mime'] == 'image/svg+xml' && empty( $response['sizes'] ) ){ $svg_path = get_attached_file( $attachment->ID ); if( ! file_exists( $svg_path ) ){ $svg_path = $response['url']; } $dimensions = $this->svg_dimensions( $svg_path ); $response['sizes'] = array( 'full' => array( 'url' => $response['url'], 'width' => $dimensions->width, 'height' => $dimensions->height, 'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait' ) ); } return $response; } /** * Get the width and height of the SVG * * @return object */ public function svg_dimensions( $svg ){ $svg = function_exists( 'simplexml_load_file' ) ? simplexml_load_file( $svg ) : null; $width = 0; $height = 0; if( $svg ){ $attributes = $svg->attributes(); if( isset( $attributes->width, $attributes->height ) ){ $width = floatval( $attributes->width ); $height = floatval( $attributes->height ); }elseif( isset( $attributes->viewBox ) ){ $sizes = explode( " ", $attributes->viewBox ); if( isset( $sizes[2], $sizes[3] ) ){ $width = floatval( $sizes[2] ); $height = floatval( $sizes[3] ); } } } return (object)array( 'width' => $width, 'height' => $height ); } /** * Returns the instance. * * @since 1.0.0 * @return object */ public static function get_instance() { // If the single instance hasn't been set, set it now. if ( null == self::$instance ) { self::$instance = new self; } return self::$instance; } } } /** * Returns instance of Jet_Elements_SVG_Manager * * @return object */ function jet_elements_svg_manager() { return Jet_Elements_SVG_Manager::get_instance(); }