文件操作 - ma-advanced-image.php
返回文件管理
返回主菜单
删除本文件
文件: /root/Desktop/OLD/plugin-wordpress/master-addons/addons/ma-advanced-image/ma-advanced-image.php
编辑文件内容
<?php namespace Elementor; use Elementor\Widget_Base; use MasterAddons\Lib\AqResizer; /** * Author Name: Liton Arefin * Author URL: https://jeweltheme.com * Date: 1/3/20 */ if ( ! defined( 'ABSPATH' ) ) exit; // If this file is called directly, abort. class Master_Addons_Advanced_Image extends Widget_Base { public function get_name() { return 'ma-call-to-action'; } public function get_title() { return esc_html__( 'MA Advaned Image', MELA_TD); } public function get_icon() { return 'ma-el-icon eicon-image'; } public function get_categories() { return [ 'master-addons' ]; } protected function _register_controls() { /* * Tab: Content */ $this->start_controls_section( 'ma_el_adv_image_section', array( 'label' => __('Image', MELA_TD ), ) ); $this->add_control( 'ma_el_adv_image', array( 'label' => __('Image',MELA_TD ), 'type' => Controls_Manager::MEDIA, 'show_label' => false, 'default' => array( 'url' => Utils::get_placeholder_image_src() ) ) ); $this->add_group_control( Group_Control_Image_Size::get_type(), array( 'name' => 'ma_el_adv_image', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `thumbnail_size` and `thumbnail_custom_dimension`. 'separator' => 'none', 'default' => 'large' ) ); $this->add_control( 'ma_el_adv_link', array( 'label' => __('Image Link',MELA_TD ), 'type' => Controls_Manager::URL, 'placeholder' => 'https://master-addons.com', 'show_external' => true ) ); $this->end_controls_section(); $this->start_controls_section( 'ma_el_adv_hover_section', array( 'label' => __('Hover Image', MELA_TD ), ) ); $this->add_control( 'ma_el_adv_display_hover', array( 'label' => __('Display Hover Image',MELA_TD ), 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'On', MELA_TD ), 'label_off' => __( 'Off', MELA_TD ), 'return_value' => 'yes', 'default' => 'no' ) ); $this->add_control( 'ma_el_adv_hover_image', array( 'label' => __( 'Image', MELA_TD ), 'type' => Controls_Manager::MEDIA, 'show_label' => false, 'condition' => array( 'ma_el_adv_display_hover' => 'yes' ) ) ); $this->end_controls_section(); $this->start_controls_section( 'ma_el_adv_ribbon_section', array( 'label' => __('Ribbon', MELA_TD ), ) ); $this->add_control( 'ma_el_adv_display_ribbon', array( 'label' => __('Diplay Ribbon',MELA_TD ), 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'On', MELA_TD ), 'label_off' => __( 'Off', MELA_TD ), 'return_value' => 'yes', 'default' => 'no' ) ); $this->add_control( 'ma_el_adv_ribbon_text', array( 'label' => __('Text',MELA_TD ), 'type' => Controls_Manager::TEXT, 'default' => 'NEW', 'condition' => array( 'ma_el_adv_display_ribbon' => 'yes' ) ) ); $this->add_control( 'ma_el_adv_ribbon_style', array( 'label' => __('Ribbon Style', MELA_TD), 'type' => Controls_Manager::SELECT, 'default' => 'simple', 'options' => array( 'simple' => __('Simple' , MELA_TD ) , 'corner' => __('Corner' , MELA_TD ), 'cross' => __('Cross' , MELA_TD ) ), 'condition' => array( 'ma_el_adv_display_ribbon' => 'yes' ) ) ); $this->add_control( 'ma_el_adv_ribbon_position', array( 'label' => __('Ribbon Position', MELA_TD), 'type' => Controls_Manager::SELECT, 'default' => 'top-right', 'options' => array( 'top-left' => __('Top Left' , MELA_TD ) , 'top-right' => __('Top Right' , MELA_TD ), 'bottom-left' => __('Bottom Left' , MELA_TD ), 'bottom-right' => __('Bottom Right' , MELA_TD ) ), 'condition' => array( 'ma_el_adv_display_ribbon' => 'yes' ) ) ); $this->add_responsive_control( 'ma_el_adv_ribbon_thickness', array( 'label' => __('Ribbon Thickness',MELA_TD ), 'type' => Controls_Manager::SLIDER, 'size_units' => array('px', 'em'), 'range' => array( 'px' => array( 'min' => 0, 'max' => 50, 'step' => 1 ), 'em' => array( 'min' => 0, 'max' => 3, 'step' => 0.1 ) ), 'selectors' => array( '{{WRAPPER}} .ma-el-ribbon-wrapper' => 'line-height: {{SIZE}}{{UNIT}};', ), 'condition' => array( 'ma_el_adv_display_ribbon' => 'yes' ) ) ); $this->end_controls_section(); $this->start_controls_section( 'ma_el_adv_settings_section', array( 'label' => __('Settings', MELA_TD ), 'tab' => Controls_Manager::TAB_SETTINGS, ) ); $this->add_control( 'ma_el_adv_colorized_shadow', array( 'label' => __( 'Colorized Shadow', MELA_TD ), 'description' => __( 'Adds colorized shadow to the image. Note: This feature is not available when image hover is active.', MELA_TD ), 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'On', MELA_TD ), 'label_off' => __( 'Off', MELA_TD ), 'return_value' => 'yes', 'default' => 'no', 'condition' => array( 'ma_el_adv_display_hover!' => 'yes' ) ) ); $this->end_controls_section(); /* * Tab: Style */ $this->start_controls_section( 'ma_el_adv_image_style_section', array( 'label' => __( 'Image', MELA_TD ), 'tab' => Controls_Manager::TAB_STYLE, 'condition' => array( 'ma_el_adv_image!' => '', ), ) ); $this->add_responsive_control( 'ma_el_adv_image_max_width', array( 'label' => __('Max Width',MELA_TD ), 'type' => Controls_Manager::SLIDER, 'size_units' => array('px', 'em','%'), 'range' => array( '%' => array( 'min' => 1, 'max' => 100, 'step' => 1 ), 'em' => array( 'min' => 1, 'max' => 100, 'step' => 1 ), 'px' => array( 'min' => 1, 'max' => 1600, 'step' => 1 ) ), 'selectors' => array( '{{WRAPPER}} .ma-el-media-image' => 'max-width:{{SIZE}}{{UNIT}};' ) ) ); $this->add_responsive_control( 'ma_el_adv_image_max_height', array( 'label' => __('Max Height',MELA_TD ), 'type' => Controls_Manager::SLIDER, 'size_units' => array('px', 'em','%'), 'range' => array( '%' => array( 'min' => 1, 'max' => 100, 'step' => 1 ), 'em' => array( 'min' => 1, 'max' => 100, 'step' => 1 ), 'px' => array( 'min' => 1, 'max' => 1600, 'step' => 1 ) ), 'selectors' => array( '{{WRAPPER}} .ma-el-media-image' => 'max-height:{{SIZE}}{{UNIT}};' ) ) ); $this->add_responsive_control( 'ma_el_adv_image_border_radius', array( 'label' => __( 'Border radius', MELA_TD ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', 'em', '%' ), 'selectors' => array( '{{WRAPPER}} .ma-el-media-image' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}; overflow:hidden;', ), 'separator' => 'after' ) ); $this->start_controls_tabs( 'ma_el_adv_image_style_tabs' ); $this->start_controls_tab( 'ma_el_adv_image_status_normal', array( 'label' => __( 'Normal' , MELA_TD ) ) ); $this->add_group_control( Group_Control_Box_Shadow::get_type(), array( 'name' => 'ma_el_adv_image_box_shadow', 'selector' => '{{WRAPPER}} .ma-el-media-image', 'separator' => 'none' ) ); $this->add_group_control( Group_Control_Border::get_type(), array( 'name' => 'ma_el_adv_image_border', 'selector' => '{{WRAPPER}} .ma-el-media-image', 'separator' => 'none' ) ); $this->add_group_control( Group_Control_Background::get_type(), array( 'name' => 'ma_el_adv_image_background', 'selector' => '{{WRAPPER}} .ma-el-media-image', 'separator' => 'none' ) ); $this->end_controls_tab(); $this->start_controls_tab( 'ma_el_adv_image_status_hover', array( 'label' => __( 'Hover' , MELA_TD ) ) ); $this->add_group_control( Group_Control_Box_Shadow::get_type(), array( 'name' => 'ma_el_adv_image_box_shadow_hover', 'selector' => '{{WRAPPER}} .ma-el-media-image:hover', 'separator' => 'none' ) ); $this->add_group_control( Group_Control_Border::get_type(), array( 'name' => 'ma_el_adv_image_border_hover', 'selector' => '{{WRAPPER}} .ma-el-media-image:hover', 'separator' => 'none' ) ); $this->add_group_control( Group_Control_Background::get_type(), array( 'name' => 'ma_el_adv_image_background_hover', 'selector' => '{{WRAPPER}} .ma-el-media-image:hover', 'separator' => 'none' ) ); $this->add_control( 'ma_el_adv_image_transition_duration', array( 'label' => __('Transition Duration',MELA_TD ), 'type' => Controls_Manager::SLIDER, 'range' => array( 'px' => array( 'min' => 0, 'max' => 2000, 'step' => 10 ) ), 'selectors' => array( '{{WRAPPER}} .ma-el-media-image' => 'transition-duration: {{SIZE}}ms;', ) ) ); $this->add_responsive_control( 'ma_el_adv_image_translate_y', array( 'label' => __('Vertical Move',MELA_TD ), 'type' => Controls_Manager::SLIDER, 'size_units' => array('px', 'em', '%'), 'range' => array( 'px' => array( 'min' => -100, 'max' => 100, 'step' => 10 ) ), 'selectors' => array( '{{WRAPPER}} .ma-el-media-image:hover' => 'transform: translateY({{SIZE}}{{UNIT}});', ) ) ); $this->end_controls_tab(); $this->end_controls_tabs(); $this->end_controls_section(); $this->start_controls_section( 'ma_el_adv_ribbon_style_section', array( 'label' => __( 'Ribbon', MELA_TD ), 'tab' => Controls_Manager::TAB_STYLE, 'condition' => array( 'ma_el_adv_display_ribbon' => 'yes' ), ) ); $this->add_control( 'ma_el_adv_ribbon_bg_color', array( 'label' => __( 'Background Color', MELA_TD ), 'type' => Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} .ma-el-ribbon-wrapper' => 'background-color: {{VALUE}} !important;', ) ) ); $this->add_control( 'ma_el_adv_ribbon_border_color', array( 'label' => __( 'Border Color', MELA_TD ), 'type' => Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} .ma-el-ribbon-wrapper::before' => 'border-color: {{VALUE}};', ), 'condition' => array( 'ma_el_adv_ribbon_style' => array('cross'), ), ) ); $this->add_group_control( Group_Control_Box_Shadow::get_type(), array( 'label' => __( 'Box Shadow', MELA_TD ), 'name' => 'ma_el_adv_header_box_shadow', 'selector' => '{{WRAPPER}} .ma-el-ribbon-wrapper' ) ); $this->add_control( 'ma_el_adv_ribbon_text_color', array( 'label' => __( 'Text Color', MELA_TD ), 'type' => Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} .ma-el-ribbon-wrapper span' => 'color: {{VALUE}} !important;', ) ) ); $this->add_group_control( Group_Control_Typography::get_type(), array( 'name' => 'ma_el_adv_ribbon_typography', 'scheme' => Scheme_Typography::TYPOGRAPHY_1, 'selector' => '{{WRAPPER}} .ma-el-ribbon-wrapper span' ) ); $this->add_group_control( Group_Control_Text_Shadow::get_type(), array( 'name' => 'ma_el_adv_ribbon_text_shadow', 'label' => __( 'Text Shadow', MELA_TD ), 'selector' => '{{WRAPPER}} .ma-el-ribbon-wrapper span', ) ); $this->end_controls_section(); } public function ma_el_is_true( $var ) { if ( is_bool( $var ) ) { return $var; } if ( is_string( $var ) ){ $var = strtolower( $var ); if( in_array( $var, array( 'yes', 'on', 'true', 'checked' ) ) ){ return true; } } if ( is_numeric( $var ) ) { return (bool) $var; } return false; } public function ma_el_random_token( $length = 32 ){ $length = ! is_numeric( $length ) ? 4 : $length; $length = $length < 1 ? 32 : $length; if ( function_exists('random_bytes') ) { return bin2hex(random_bytes( $length )); } if (function_exists('mcrypt_create_iv')) { return bin2hex(mcrypt_create_iv( $length, MCRYPT_DEV_URANDOM )); } if ( function_exists('openssl_random_pseudo_bytes') ) { return bin2hex(openssl_random_pseudo_bytes( $length )); } } public function ma_el_merge_css_classes( $classes = array(), $class = '' ){ if( empty( $classes ) && empty( $class ) ) return array(); if ( ! empty( $class ) ) { if ( !is_array( $class ) ) $class = preg_split( '#\s+#', $class ); $classes = array_merge( $class, $classes ); } return $classes; } public function ma_el_error( $error ){ if ( WP_DEBUG && apply_filters( 'auxin_trigger_error_message', true ) ) { trigger_error( $error ); } } public function ma_el_get_widget_scafold( $atts, $default_atts, $shortcode_content = '' ){ $result = array( 'parsed_atts' => '', 'widget_info' => '', 'widget_header' => '', 'widget_title' => '', 'widget_footer' => '', 'ajax_data' => '' ); // ---- if( ! isset( $default_atts['extra_classes'] ) ){ $default_atts['extra_classes'] = ''; } if( ! isset( $default_atts['custom_el_id'] ) ){ $default_atts['custom_el_id'] = ''; } if( ! isset( $default_atts['content'] ) ){ $default_atts['content'] = ''; } if( empty( $default_atts['universal_id'] ) ){ $default_atts['universal_id'] = 'au'. $this->ma_el_random_token(4); } if( ! isset( $default_atts['skip_wrappers'] ) ){ $default_atts['skip_wrappers'] = false; } if( ! isset( $default_atts['loadmore_type'] ) ){ $default_atts['loadmore_type'] = ''; } if( ! isset( $default_atts['base'] ) ){ $default_atts['base'] = ''; } if( ! isset( $default_atts['content_width'] ) ){ if( ! did_action( 'wp' ) && function_exists( 'auxin_set_content_width' ) ){ $default_atts['content_width'] = auxin_set_content_width(); } else { global $aux_content_width; $default_atts['content_width'] = $aux_content_width; } } // animation options if( ! isset( $default_atts['inview_transition'] ) ){ $default_atts['inview_transition'] = 'none'; } if( ! isset( $default_atts['inview_duration'] ) ){ $default_atts['inview_duration'] = ''; } if( ! isset( $default_atts['inview_delay'] ) ){ $default_atts['inview_delay'] = ''; } if( ! isset( $default_atts['inview_repeat'] ) ){ $default_atts['inview_repeat'] = 'no'; } if( ! isset( $default_atts['inview_offset'] ) ){ $default_atts['inview_offset'] = ''; } // What called the widget fallback function if( ! isset( $default_atts['called_from'] ) ){ $default_atts['called_from'] = ''; } // prevent nested query while placing a recent posts widget in the same post if( isset( $atts['exclude'] ) && ! empty( $atts['exclude'] ) ){ global $post; if( ! empty( $post->ID ) ){ $atts['exclude'] .= ',' . $post->ID; } } // Widget general info $before_widget = $after_widget = ''; $before_title = $after_title = ''; // If widget info is passed, extract them in above variables if( isset( $atts['widget_info'] ) ){ $result['widget_info'] = $atts['widget_info']; extract( $atts['widget_info'] ); } // CSS class names for section ------------- // The default CSS classes for widget container // Note that 'widget-container' should be in all element $_css_classes = array( 'widget-container' ); // Parse shortcode attributes $parsed_atts = shortcode_atts( $default_atts, $atts, __FUNCTION__ ); if( empty( $parsed_atts['content'] ) ){ $parsed_atts['content'] = $shortcode_content; } if( empty( $parsed_atts['loadmore_per_page'] ) ){ $parsed_atts['loadmore_per_page'] = ! empty( $parsed_atts['num'] ) ? $parsed_atts['num'] : 12; } $result['parsed_atts'] = $parsed_atts; // make the result params filterable prior to generating markup variables $result = apply_filters( 'auxin_pre_widget_scafold_params', $result, $atts, $default_atts, $shortcode_content ); if( $result['parsed_atts']['skip_wrappers'] ){ return $result; } if( ! empty( $result['parsed_atts']['loadmore_type'] ) ){ if( empty( $result['parsed_atts']["base"] ) ){ _doing_it_wrong( __FUNCTION__, 'For using ajax load more feature, "base" parameter in element default attributes is required.' ); } // Enqueue wp-mediaelement wp_enqueue_style ( 'wp-mediaelement' ); wp_enqueue_script( 'wp-mediaelement' ); $ajax_args = $result['parsed_atts']; if( isset( $ajax_args['use_wp_query'] ) && $ajax_args['use_wp_query'] ){ $queried_object = get_queried_object(); if( $queried_object instanceof WP_Term ){ $ajax_args['cat'] = $queried_object->term_id; $ajax_args['taxonomy_name'] = $queried_object->taxonomy; } } // remove redundant ajax args unset( $ajax_args['base'] ); unset( $ajax_args['base_class'] ); unset( $ajax_args['use_wp_query'] ); // force the element not to render wrappers for ajax handler $ajax_args['skip_wrappers'] = true; $result['ajax_data'] = array( 'nonce' => wp_create_nonce('auxin_front_load_more'), 'args' => $ajax_args, 'handler' => $result['parsed_atts']["base"], 'per_page'=> $parsed_atts['loadmore_per_page'] ); $_css_classes[] = 'aux-ajax-type-' . $result['parsed_atts']['loadmore_type']; if ( 'infinite-scroll' === $result['parsed_atts']['loadmore_type'] ) { $_css_classes[] = 'aux-ajax-type-scroll'; } } // Defining extra class names -------------- // Add extra class names to class list here - widget-{element_name} $_css_classes[] = $result['parsed_atts']['base_class']; $_css_classes[] = 'aux-parent-' . $result['parsed_atts']['universal_id']; $_widget_attrs = ''; $_widget_styles = ''; if( ! empty( $result['parsed_atts']['inview_transition'] ) && 'none' !== $result['parsed_atts']['inview_transition'] ){ $_css_classes[] = 'aux-appear-watch'; $_css_classes[] = esc_attr( $result['parsed_atts']['inview_transition'] ); if( ! empty( $result['parsed_atts']['inview_duration'] ) && 600 != $result['parsed_atts']['inview_duration'] ){ $_widget_styles .= 'animation-duration:' . esc_attr( rtrim( $result['parsed_atts']['inview_duration'], 'ms') ) . 'ms;'; $_widget_styles .= 'transition-duration:' . esc_attr( rtrim( $result['parsed_atts']['inview_duration'], 'ms') ) . 'ms;'; } if( ! empty( $result['parsed_atts']['inview_delay'] ) ){ $_widget_styles .= 'animation-delay:' . esc_attr( rtrim( $result['parsed_atts']['inview_delay'], 'ms') ) . 'ms;'; $_widget_styles .= 'transition-delay:' . esc_attr( rtrim( $result['parsed_atts']['inview_delay'], 'ms') ) . 'ms;'; } if( ! empty( $result['parsed_atts']['inview_repeat'] ) && 'no' !== $result['parsed_atts']['inview_repeat'] ){ $_css_classes[] = 'aux-appear-repeat'; } if( ! empty( $result['parsed_atts']['inview_offset'] ) ){ $offset = $result['parsed_atts']['inview_offset']; if( false === strpos( $offset, '%' ) ){ $offset = trim( $offset, 'px' ) . 'px'; } $_widget_attrs .= 'data-offset="' . esc_attr( $offset ) . '" '; } } $_widget_classes = $this->ma_el_merge_css_classes( $_css_classes, $result['parsed_atts']['extra_classes'] ); $_widget_classes = esc_attr( trim( join( ' ', array_unique( $_widget_classes ) ) ) ); // Generate the opening tags for widget or shortcode element if( $before_widget ){ $result['widget_header'] .= str_replace( array( 'class="', '>','<div'), array( 'class="'.$_widget_classes.' ', ' style="'. $_widget_styles .'" '. $_widget_attrs .' >', '<section' ), $before_widget ); } elseif ( !empty($result['parsed_atts']['custom_el_id']) ){ $result['widget_header'] .= sprintf('<section id="%s" class="%s" style="%s" %s>', $result['parsed_atts']['custom_el_id'], $_widget_classes, $_widget_styles, $_widget_attrs ); } else { $result['widget_header'] .= sprintf('<section class="%s" style="%s" %s>', $_widget_classes, $_widget_styles, $_widget_attrs ); } // Generate the title for widget or shortcode element if( ! empty( $result['parsed_atts']['title'] ) ){ if( $before_title ){ $result['widget_title'] .= $before_title . $result['parsed_atts']['title'] . $after_title; } elseif( ! empty( $result['parsed_atts']['title'] ) ){ $result['widget_title'] .= '<h3 class="widget-title">'. $result['parsed_atts']['title'] .'</h3>'; } } // Generate the close tags for widget or shortcode element if( $after_widget ){ // fix for the difference in end tag in siteorigin page builder $result['widget_footer'] .= str_replace( '</div', '</section', $after_widget ); } else { $result['widget_footer'] .= '</section><!-- widget-container -->'; } // Enable filtering the result variable $result = apply_filters( 'auxin_widget_scafold_params', $result, $atts, $default_atts, $shortcode_content ); // Prints the javascript variable if load more is enabled // We can modify the ajax args using "auxin_widget_scafold_params" filter if( ! empty( $result['parsed_atts']['loadmore_type'] ) ){ // echo js dependencies $this->ma_el_print_script_object( "auxin.content.loadmore." . $result['parsed_atts']['universal_id'], $result['ajax_data'] ); } return $result; } public function ma_el_get_all_image_sizes() { global $_wp_additional_image_sizes; $default_image_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' ); $all_image_sizes = array(); foreach ( $default_image_sizes as $size ) { $all_image_sizes[ $size ] = array( 'width' => (int) get_option( $size . '_size_w' ), 'height' => (int) get_option( $size . '_size_h' ), 'crop' => (bool) get_option( $size . '_crop' ) ); } if ( ! empty( $_wp_additional_image_sizes ) ) { $all_image_sizes = array_merge( $all_image_sizes, $_wp_additional_image_sizes ); } return apply_filters( 'auxin_all_image_sizes', $all_image_sizes ); } public function ma_el_wp_get_image_size( $size_name ){ $all_image_sizes = $this->ma_el_get_all_image_sizes(); if( ! empty( $all_image_sizes[ $size_name ] ) ){ return $all_image_sizes[ $size_name ]; } auxin_error( sprintf( 'Invalid image size name (%s) for "%s" function.', $size_name, __FUNCTION__ ) ); return false; } public function ma_el_print_script_object( $object_name, $object_value = array() ){ if( empty( $object_name ) ){ _doing_it_wrong( __FUNCTION__, 'The object name cannot be empty' ); return; } // remove unespected chars $object_name = trim( $object_name, '.' ); if( false !== strpos( $object_name, '.') ){ $script = sprintf( 'auxinNS("%1$s"); %1$s=%2$s;', esc_js( $object_name ), wp_json_encode( $object_value ) ); } else { $script = sprintf( 'var %1$s=%2$s;', esc_js( $object_name ), wp_json_encode( $object_value ) ); } echo $script ? '<script>'. $script .'</script>' : ''; } /** * The default WP image sizes * * @return array the list of default image sizes */ public function ma_el_base_image_sizes(){ return apply_filters( 'ma_el_base_image_sizes', array('thumbnail', 'medium', 'medium_large', 'large') ); } public function ma_el_get_the_resized_attachment_src( $attach_id = null, $width = null , $height = null, $crop = null , $quality = 100, $upscale = false ) { if( is_null( $attach_id ) ) return ''; if( is_array( $attach_id ) ){ $srcs = array(); foreach ( $attach_id as $id ) { if( wp_attachment_is( 'ma_el_adv_image', $id ) ){ // $image_url = wp_get_attachment_url( $id ,'full' ); //get img URL // $srcs[ $id ] = $image_url ? ma_el_aq_resize( $image_url, $width, $height, $crop, $quality,true,$upscale ) : ''; $srcs[ $id ] = wp_get_attachment_url( $id ,'full' ); //get img URL } elseif ( wp_attachment_is( 'audio', $id ) ){ $srcs[ $id ] = includes_url() . 'images/media/audio.png'; } elseif ( wp_attachment_is( 'video', $id ) ){ $srcs[ $id ] = includes_url() . 'images/media/video.png'; } elseif ( 0 === strpos( get_post_mime_type( $id ), 'text/' ) ){ $srcs[ $id ] = includes_url() . 'images/media/file.png'; } } return $srcs; } if( wp_attachment_is( 'ma_el_adv_image', $attach_id ) ){ $image_url = wp_get_attachment_url( $attach_id ,'full' ); //get img URL return $image_url ? $image_url : false; } elseif ( wp_attachment_is( 'audio', $attach_id ) ){ return includes_url() . 'images/media/audio.png'; } elseif ( wp_attachment_is( 'video', $attach_id ) ){ return includes_url() . 'images/media/video.png'; } elseif ( 0 === strpos( get_post_mime_type( $attach_id ), 'text/' ) ){ return includes_url() . 'images/media/file.png'; } return false; } function ma_el_generate_image_sizes( $image_sizes ){ if( 'auto' === $image_sizes ){ return $image_sizes; } $attr_sizes = ''; foreach ( $image_sizes as $element_size ) { $attr_sizes .= ! empty( $element_size['min'] ) ? '(min-width:'. $element_size['min'] .') ' : ''; $attr_sizes .= ! empty( $element_size['min'] ) && ! empty( $element_size['max'] ) ? 'and ' : ''; $attr_sizes .= ! empty( $element_size['max'] ) ? '(max-width:'. $element_size['max'] .') ' : ''; $attr_sizes .= ! empty( $element_size['width'] ) ? $element_size['width'] . ',' : ','; } return rtrim( $attr_sizes, ',' ); } /** * Retrieves the resized attachment image custom srcset and sizes */ public function ma_el_get_the_responsive_attachment( $attachment_id = null, $args = array() ) { $defaults = array( 'quality' => 100, 'attr' => '', 'upscale' => false, 'size' => 'large', 'crop' => null, 'add_hw' => true, 'add_ratio' => true, 'sizes' => 'auto', // (sizes) 'srcset' => 'auto', // (srcset) automatically calculate the image sizes based on the 'size' param, OR 'wp' generates image srcs based on WP default image sizes 'original_src' => true, 'extra_class' => '' ); $args = wp_parse_args( $args, $defaults ); // fallback for deprecated attributes if( isset( $args['image_sizes'] ) ){ $args['sizes'] = $args['image_sizes']; unset( $args['image_sizes'] ); } if( isset( $args['srcset_sizes'] ) ){ $args['srcset'] = $args['srcset_sizes']; unset( $args['srcset_sizes'] ); } extract( $args ); // Throw error if $size is not defined if( empty( $size ) ){ $this->ma_el_error( sprintf( '"size" option for "%s" function is not defined.', __FUNCTION__ ) ); } $attachment = get_post( $attachment_id ); // get original image info $original_image = wp_get_attachment_image_src( $attachment_id, 'full' ); $original_image_width = $original_image['1']; // Check crop value $crop = empty( $crop ) ? $crop : $this->ma_el_is_true( $crop ); // Make sure there is a valid $size value passed if( is_array( $size ) ){ if( empty( $size['width'] ) && empty( $size['height'] ) ){ $size = 'medium_large'; } // since the size is a custom width and height, the hard crop is required if( is_null( $crop ) ){ $crop = true; } } // Get the $size dimensions $dimensions = $size; if( in_array( $dimensions, array( 'full', 'original' ) ) ){ $dimensions = array( 'width' => $original_image['1'], 'height' => $original_image['2'] ); // prevent generating srcset if the original image size is requested $srcset = null; $sizes = null; } elseif ( is_string( $dimensions ) ){ $dimensions = $this->ma_el_wp_get_image_size( $dimensions ); $dimensions = array( 'width' => $dimensions['width'], 'height' => $dimensions['height'] ); } // calculate the image aspect ratio $image_aspect_ratio = empty( $dimensions['width'] ) || empty( $dimensions['height'] ) ? null : $dimensions['width']/$dimensions['height']; // if aspect ratio is available, turn on the upscale for improving accuracy in cropping images if( $image_aspect_ratio ){ $upscale = true; } /* Generate main image /*-------------------------------------*/ // crop the main image if( is_string( $size ) ){ $main_image = wp_get_attachment_image_src( $attachment_id, $size ); $src = $main_image['0']; } else { $src = $this->ma_el_get_the_resized_attachment_src( $attachment_id, $dimensions['width'] , $dimensions['height'], $crop, $quality, $upscale ); } if( empty( $src ) ) return ''; // image width of default image src $default_image_width = round( $original_image_width > $dimensions['width'] ? $dimensions['width'] : $original_image_width ); /* Calculate SRCSET /*-------------------------------------*/ $attr_srcset = ''; if( ! empty( $srcset ) ){ // generate src sizes based on the list of sizes if( is_array( $srcset ) ){ foreach ( $srcset as $srcset_size ) { // width is required for each src item if( ! $srcset_size['width'] = empty( $srcset_size['width' ] ) ? null : $srcset_size['width' ] ){ continue; } // dont generate image src bigger than original image if( $srcset_size['width'] >= $original_image_width ){ break; } $srcset_size['height'] = empty( $srcset_size['height'] ) ? null : $srcset_size['height']; $attr_srcset .= $this->ma_el_get_the_resized_attachment_src( $attachment_id, $srcset_size['width'] , $srcset_size['height'], $crop, $quality, $upscale ); $attr_srcset .= ' '. round( $srcset_size['width'] ).'w,'; } // generate image sizes based on the default WordPress image sizes } elseif( 'wp' == $srcset || ( ( is_string( $size ) || empty( $image_aspect_ratio ) ) && 'auto' === $srcset ) ){ $default_image_sizes = $this->ma_el_base_image_sizes(); foreach ( $default_image_sizes as $image_size ) { // Check if the image size is defined before if( ! $current_image_dimensions = wp_get_attachment_image_src( $attachment_id, $image_size ) ){ $this->ma_el_error( sprintf( 'Intermediate image size name not found in "%s" function.', __FUNCTION__ ) ); continue; } // dont generate image src bigger than original image if( $current_image_dimensions['1'] >= $original_image_width ){ break; } if( is_array( $size ) ){ $attr_srcset .= $this->ma_el_get_the_resized_attachment_src( $attachment_id, $current_image_dimensions['1'] , $current_image_dimensions['2'], $crop, $quality, $upscale ); $attr_srcset .= ' '. round( $current_image_dimensions['1'] ).'w,'; } else { $attr_srcset .= $current_image_dimensions['0']; $attr_srcset .= ' '. round( $current_image_dimensions['1'] ).'w,'; } } // automatically generate general image sizes based on the aspect ratio of the main image according the dimensions in $size } elseif( is_array( $size ) && 'auto' === $srcset && $image_aspect_ratio ){ $default_image_sizes = $this->ma_el_base_image_sizes(); foreach ( $default_image_sizes as $image_size ) { $current_image_width = get_option( $image_size. '_size_w' ); // dont generate image src bigger than original image if( $current_image_width >= $original_image_width ){ break; } $attr_srcset .= $this->ma_el_get_the_resized_attachment_src( $attachment_id, $current_image_width, $current_image_width/$image_aspect_ratio, $crop, $quality, $upscale ); $attr_srcset .= ' '. round( $current_image_width ).'w,'; } } // Add the original image src if the original size greater that large size exists if( $attr_srcset ){ // Add main image to srcset too $attr_srcset .= $src . ' ' . $default_image_width . 'w,'; if( $original_src ){ if( $image_aspect_ratio ){ $full_width = (int) ( $original_image[1] -10 ); $full_height = (int) ($full_width/$image_aspect_ratio); $attr_srcset .= $this->ma_el_get_the_resized_attachment_src( $attachment_id, $full_width, $full_height, true, $quality, true ); $attr_srcset .= ' ' . round( $full_width ) . 'w'; } else { $attr_srcset .= $original_image[0] . ' ' . $original_image[1] . 'w'; } } $attr_srcset = rtrim( $attr_srcset, ',' ); } } /* Add essential attribute /*-------------------------------------*/ $html = ''; $width_attribute = $original_image['1'] < $dimensions['width' ] ? $original_image['1'] : $dimensions['width']; $height_attribute = $original_image['2'] < $dimensions['height'] ? $original_image['2'] : $dimensions['height']; $string_size = $width_attribute . 'x' . $height_attribute; $hwstring = image_hwstring( $width_attribute, $height_attribute ); // default image attributes $default_attr = array( 'src' => $src, 'class' => "aux-attachment aux-featured-image attachment-$string_size aux-attachment-id-$attachment_id $extra_class", 'alt' => trim(strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) )), // Use Alt field first 'width_attr_name' => '', 'height_attr_name' => '' ); if ( empty( $default_attr['alt'] ) ) $default_attr['alt'] = trim( strip_tags( $attachment->post_excerpt ) ); // If not, Use the Caption if ( empty( $default_attr['alt'] ) ) $default_attr['alt'] = trim( strip_tags( $attachment->post_title ) ); // Finally, use the title // parse the attr $attr = wp_parse_args( $attr, $default_attr ); // Generate 'srcset' and 'sizes' if not already present. if ( empty( $attr['srcset'] ) ) { if ( $attr_srcset ) { $attr['srcset'] = $attr_srcset; } } if( $image_aspect_ratio ){ $attr['data-ratio'] = round( $image_aspect_ratio, 2 ); } $attr['data-original-w'] = $original_image_width; if( ! empty( $attr['width_attr_name'] ) || ! empty( $attr['height_attr_name'] ) ) $metadata = wp_get_attachment_metadata( $attachment_id ); if( ! empty( $attr['width_attr_name'] ) ) $attr[ $attr['width_attr_name'] ] = $metadata['width']; if( ! empty( $attr['height_attr_name'] ) ) $attr[ $attr['height_attr_name'] ] = $metadata['height']; /* Calculate sizes /*-------------------------------------*/ if( ! empty( $sizes ) ){ $attr_sizes = $this->ma_el_generate_image_sizes( $sizes ); if ( empty( $attr['sizes'] ) && $attr_sizes ) { $attr['sizes'] = $attr_sizes; } } if( 'auto' === $sizes ){ $auto_sizes = array( array( 'min' => '', 'max' => '479px' , 'width' => '480px' ), array( 'min' => '', 'max' => '767px' , 'width' => '768px' ), array( 'min' => '', 'max' => '1023px', 'width' => '1024px' ) ); if( $dimensions['width'] ){ $auto_sizes[] = array( 'min' => '', 'max' => '', 'width' => $default_image_width . 'px' ); } $attr['sizes'] = $this->ma_el_generate_image_sizes( $auto_sizes ); } // Display a blurred preview of the main image if ( 'auto' === $sizes ) { // add the required class name to make it visible to image size-calculation script $attr['class'] .= ' aux-preload'; if ( ! empty( $attr['src'] ) && empty( $attr['srcset'] ) ) { $attr['data-src'] = $attr['src']; } $attr['src'] = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; $preload_ratio = null === $image_aspect_ratio ? null : 40 / $image_aspect_ratio; $attr['src'] = $this->ma_el_get_the_resized_attachment_src( $attachment_id, 40, $preload_ratio, $crop,100, false ); $attr['class'] .= ' ma-el-has-preview'; // the class name to add style and transition to the preview } unset( $attr['width_attr_name' ] ); unset( $attr['height_attr_name'] ); /** * Filter the list of attachment image attributes. * * @param mixed $attr Attributes for the image markup. * @param int $attachment_id Image attachment ID. */ $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size ); $attr = array_map( 'esc_attr', $attr ); $html = rtrim("<img $hwstring"); foreach ( $attr as $name => $value ) { if( $value ){ $html .= " $name=" . '"' . $value . '"'; } } $html .= ' />'; return $html; } public function ma_el_attachment_caption( $attach_id = null, $stripe = true ) { $attachment_post = get_post( $attach_id ); if( empty( $attachment_post ) ){ return ''; } $caption = $attachment_post->post_excerpt; if ( empty( $caption ) ) $caption = $attachment_post->post_title; if ( empty( $caption ) ) $caption = get_post_meta( $attach_id, '_wp_attachment_image_alt', true ); if ( $stripe ) { $caption = strip_tags( $caption ); } return trim( $caption ); } public function ma_el_get_attachment_url( $attach_id, $featured_img_size = "medium" ) { if( is_numeric( $attach_id ) ){ $image_url = wp_get_attachment_image_src( $attach_id, $featured_img_size ); return $image_url[0]; } return ''; } // This is the widget call back in fact the front end out put of this widget comes from this function public function ma_el_adv_image_callback( $atts, $shortcode_content = null ){ // Defining default attributes $default_atts = array( 'title' => '', // header title 'add_content' => false, 'content_title' => '', 'content_subtitle' => '', 'colorized_shadow' => false, 'attach_id' => '', // attachment id for main image 'attach_id_hover' => '', // attachment id for hover image 'link' => '', // link on image 'target' => '_self', // link target 'nofollow' => '', // link nofollow 'alt' => '', // alternative text 'size' => 'medium_large', // image size 'width' => '', // final width of image 'height' => '', // final height of image 'icon' => 'plus', // icon type. plus, zoom, none 'image_html' => '', 'display_ribbon' => '1', 'ribbon_style' => 'simple', 'ribbon_position' => 'top-right', 'ribbon_text' => '', 'extra_classes' => '', // custom css class names for this element 'custom_el_id' => '', // custom id attribute for this element 'base_class' => 'ma-el-advanced-image' // base class name for container ); $result = $this->ma_el_get_widget_scafold( $atts, $default_atts, $shortcode_content ); extract( $result['parsed_atts'] ); $image_primary = ''; $image_primary_full = ''; $image_secondary = ''; $image_classes = "aux-attachment aux-featured-image aux-attachment-id-$attach_id"; $frame_classes = ''; if( empty( $size ) ){ $size = 'medium_large'; } if( 'custom' == $size ){ $size = array( 'width' => $width, 'height' => $height ); } if ( $add_content ) { $frame_classes .= 'aux-image-box-widget-bg-cover'; } if ( $this->ma_el_is_true( $colorized_shadow ) && empty( $attach_id_hover ) ) { $image_classes .= ' aux-img-dynamic-dropshadow'; } if( ! empty( $attach_id ) && is_numeric( $attach_id ) ) { $image_primary = $this->ma_el_get_the_responsive_attachment( $attach_id, array( 'quality' => 100, 'size' => $size, 'crop' => true, 'add_hw' => true, 'upscale' => false, 'original_src' => 'full' === $size ? true : false, 'attr' => array( 'class' => $image_classes ) ) ); } elseif( ! empty( $image_html ) ) { $image_primary = $image_html; } if( ! empty( $attach_id_hover ) && is_numeric( $attach_id_hover ) ) { $image_secondary = $this->ma_el_get_the_responsive_attachment( $attach_id_hover, array( 'quality' => 100, 'size' => $size, 'crop' => true, 'add_hw' => true, 'upscale' => false ) ); } // hover effect $hover_class = ''; if ( !empty($anchor_link) ) { $hover_class = 'aux-hover-active'; } $overflow_class = ''; if( $ribbon_style === 'corner' ) { $overflow_class = ' ma-el-hidden-overflow'; } // add alignment class on main element $result['widget_header'] = str_replace( $base_class, $base_class.' ma-el-alignnone',$result['widget_header'] ); ob_start(); // widget header ------------------------------ echo $result['widget_header']; echo $result['widget_title']; // widget output ----------------------- ?> <div class="ma-el-adv-image-wrapper"> <div class="ma-el-media-image <?php echo esc_attr( $hover_class ); echo esc_attr( $frame_classes ); echo esc_attr( $overflow_class ); ?>" > <?php if( !empty($anchor_link) ) { ?> <a class="<?php echo $anchor_class; ?>" href="<?php echo $anchor_link; ?>" > <?php } ?> <?php if ( $this->ma_el_is_true( $display_ribbon ) && ! empty( $ribbon_text ) ) { ?> <div class="ma-el-ribbon-wrapper ma-el-<?php echo $ribbon_style;?>-ribbon <?php echo $ribbon_position;?>"> <span><?php echo $ribbon_text;?></span> </div> <?php } ?> <?php if ( !empty( $image_secondary ) ) { ?> <div class="aux-image-holder ma-el-image-has-secondary"> <?php echo $image_primary; ?> <?php echo $image_secondary; ?> </div> <?php } ?> <?php if( ! empty( $anchor_link ) ) { ?> </a> <?php } ?> </div> </div> <?php // widget footer ------------------------------ echo $result['widget_footer']; return ob_get_clean(); } protected function render() { $settings = $this->get_settings_for_display(); $link_target = $settings['ma_el_adv_link']['is_external'] ? '_blank' : '_self'; $args = array( 'image_html' => Group_Control_Image_Size::get_attachment_image_html( $settings, 'ma_el_adv_image' ), 'attach_id' => $settings['ma_el_adv_image']['id'], 'size' => $settings['ma_el_adv_image_size'], 'width' => $settings['ma_el_adv_image_custom_dimension']['width'], 'height' => $settings['ma_el_adv_image_custom_dimension']['height'], 'link' => $settings['ma_el_adv_link']['url'], 'nofollow' => $settings['ma_el_adv_link']['nofollow'], 'target' => $link_target, 'attach_id_hover' => $settings['ma_el_adv_hover_image']['id'], 'display_ribbon' => $settings['ma_el_adv_display_ribbon'], 'ribbon_text' => $settings['ma_el_adv_ribbon_text'], 'ribbon_style' => $settings['ma_el_adv_ribbon_style'], 'ribbon_position' => $settings['ma_el_adv_ribbon_position'], 'colorized_shadow' => $settings['ma_el_adv_colorized_shadow'] ); // pass the args through the corresponding shortcode callback echo $this->ma_el_adv_image_callback( $args ); } } Plugin::instance()->widgets_manager->register_widget_type( new Master_Addons_Advanced_Image() );
修改文件时间
将文件时间修改为当前时间的前一年
删除文件