Advertisement
Guenni007

image

Aug 11th, 2021
1,247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 28.14 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Image
  4.  *
  5.  * Shortcode which inserts an image of your choice
  6.  */
  7. if ( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  8.  
  9.  
  10. if ( ! class_exists( 'avia_sc_image' ) )
  11. {
  12.     class avia_sc_image extends aviaShortcodeTemplate
  13.     {
  14.         /**
  15.          * Create the config array for the shortcode button
  16.          */
  17.         function shortcode_insert_button()
  18.         {
  19.             $this->config['version']        = '1.0';
  20.             $this->config['self_closing']   = 'no';
  21.             $this->config['base_element']   = 'yes';
  22.  
  23.             $this->config['name']           = __( 'Image', 'avia_framework' );
  24.             $this->config['tab']            = __( 'Media Elements', 'avia_framework' );
  25.             $this->config['icon']           = AviaBuilder::$path['imagesURL'] . 'sc-image.png';
  26.             $this->config['order']          = 100;
  27.             $this->config['target']         = 'avia-target-insert';
  28.             $this->config['shortcode']      = 'av_image';
  29. //          $this->config['modal_data']     = array( 'modal_class' => 'mediumscreen' );
  30.             $this->config['tooltip']        = __( 'Inserts an image of your choice', 'avia_framework' );
  31.             $this->config['preview']        = 1;
  32.             $this->config['disabling_allowed'] = true;
  33.             $this->config['id_name']        = 'id';
  34.             $this->config['id_show']        = 'yes';
  35.         }
  36.  
  37.         function extra_assets()
  38.         {
  39.  
  40. //load css from child-theme css - changed by Guenni007
  41.             wp_enqueue_style( 'avia-module-image', get_stylesheet_directory_uri().'/shortcodes/image.css', array( 'avia-layout' ), false );
  42.         }
  43.  
  44.         /**
  45.          * Popup Elements
  46.          *
  47.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  48.          * opens a modal window that allows to edit the element properties
  49.          *
  50.          * @return void
  51.          */
  52.         function popup_elements()
  53.         {
  54.             $this->elements = array(
  55.                
  56.                 array(
  57.                         'type'  => 'tab_container',
  58.                         'nodescription' => true
  59.                     ),
  60.                        
  61.                 array(
  62.                         'type'  => 'tab',
  63.                         'name'  => __( 'Content', 'avia_framework' ),
  64.                         'nodescription' => true
  65.                     ),
  66.                
  67.                     array(
  68.                             'type'          => 'template',
  69.                             'template_id'   => $this->popup_key( 'content_image' )
  70.                         ),
  71.                
  72.                 array(
  73.                         'type'  => 'tab_close',
  74.                         'nodescription' => true
  75.                     ),
  76.                
  77.                 array(
  78.                         'type'  => 'tab',
  79.                         'name'  => __( 'Styling', 'avia_framework' ),
  80.                         'nodescription' => true
  81.                     ),
  82.                
  83.                     array(
  84.                             'type'          => 'template',
  85.                             'template_id'   => 'toggle_container',
  86.                             'templates_include' => array(
  87.                                                     $this->popup_key( 'styling_image_styling' ),
  88.                                                     $this->popup_key( 'styling_image_caption' )
  89.                                                 ),
  90.                             'nodescription' => true
  91.                         ),
  92.                
  93.                
  94.                 array(
  95.                         'type'  => 'tab_close',
  96.                         'nodescription' => true
  97.                     ),
  98.                
  99.                 array(
  100.                         'type'  => 'tab',
  101.                         'name'  => __( 'Advanced', 'avia_framework' ),
  102.                         'nodescription' => true
  103.                     ),
  104.                
  105.                     array(
  106.                             'type'  => 'toggle_container',
  107.                             'nodescription' => true
  108.                         ),
  109.                
  110.                         array(
  111.                                 'type'          => 'template',
  112.                                 'template_id'   => $this->popup_key( 'advanced_animation' ),
  113.                             ),
  114.                
  115.                         array( 
  116.                                 'type'          => 'template',
  117.                                 'template_id'   => $this->popup_key( 'advanced_link' ),
  118.                             ),
  119.                
  120.                         array( 
  121.                                 'type'          => 'template',
  122.                                 'template_id'   => $this->popup_key( 'advanced_seo' ),
  123.                             ),
  124.                
  125.                         array(
  126.                                 'type'          => 'template',
  127.                                 'template_id'   => 'lazy_loading_toggle',
  128.                                 'lockable'      => true
  129.                             ),
  130.                
  131.                         array( 
  132.                                 'type'          => 'template',
  133.                                 'template_id'   => 'screen_options_toggle',
  134.                                 'lockable'      => true
  135.                             ),
  136.                
  137.                         array( 
  138.                                 'type'          => 'template',
  139.                                 'template_id'   => 'developer_options_toggle',
  140.                                 'args'          => array( 'sc' => $this )
  141.                             ),
  142.                
  143.                     array(
  144.                             'type'  => 'toggle_container_close',
  145.                             'nodescription' => true
  146.                         ),
  147.                
  148.                 array(
  149.                         'type'  => 'tab_close',
  150.                         'nodescription' => true
  151.                     ),
  152.                
  153.                 array( 
  154.                         'type'          => 'template',
  155.                         'template_id'   => 'element_template_selection_tab',
  156.                         'args'          => array(
  157.                                                 'sc'    => $this
  158.                                             )
  159.                     ),
  160.  
  161.                 array(
  162.                         'type'  => 'tab_container_close',
  163.                         'nodescription' => true
  164.                     ), 
  165.                    
  166.                 array( 
  167.                         'id'    => 'av_element_hidden_in_editor',
  168.                         'type'  => 'hidden',
  169.                         'std'   => '0'
  170.                     )
  171.             );
  172.            
  173.         }
  174.                        
  175.         /**
  176.          * Create and register templates for easier maintainance
  177.          *
  178.          * @since 4.6.4
  179.          */
  180.         protected function register_dynamic_templates()
  181.         {
  182.             /**
  183.              * Content Tab
  184.              * ===========
  185.              */
  186.                        
  187.             $c = array(
  188.                         array(
  189.                             'name'      => __( 'Choose Image', 'avia_framework' ),
  190.                             'desc'      => __( 'Either upload a new, or choose an existing image from your media library', 'avia_framework' ),
  191.                             'id'        => 'src',
  192.                             'type'      => 'image',
  193.                             'title'     => __( 'Insert Image', 'avia_framework' ),
  194.                             'button'    => __( 'Insert', 'avia_framework' ),
  195.                             'std'       => AviaBuilder::$path['imagesURL'] . 'placeholder.jpg',
  196.                             'lockable'  => true,
  197.                             'locked'    => array( 'src', 'attachment', 'attachment_size' )
  198.                         ),
  199.                
  200.                         array(
  201.                             'name'      => __( 'Copyright Info', 'avia_framework' ),
  202.                             'desc'      => __( 'Use the media manager to add/edit the copyright info.', 'avia_framework' ),
  203.                             'id'        => 'copyright',
  204.                             'type'      => 'select',
  205.                             'std'       => '',
  206.                             'lockable'  => true,
  207.                             'subtype'   => array(
  208.                                                 __( 'No', 'avia_framework' )                                    => '',
  209.                                                 __( 'Yes, always display copyright info', 'avia_framework' )    => 'always',
  210.                                                 __( 'Yes, display icon and reveal copyright info on hover', 'avia_framework' )  => 'icon-reveal',
  211.                                             )
  212.                         ),
  213.    
  214.                         array(
  215.                             'name'  => __( 'Image Caption', 'avia_framework' ),
  216.                             'desc'  => __( 'Display a caption overlay?', 'avia_framework' ),
  217.                             'id'    => 'caption',
  218.                             'type'  => 'select',
  219.                             'std'   => '',
  220.                             'lockable'  => true,
  221.                             'subtype'   => array(
  222.                                                 __( 'No', 'avia_framework' )    => '',
  223.                                                 __( 'Yes', 'avia_framework' )   => 'yes',
  224.                                             )
  225.                         ),
  226.                                    
  227.                         array(
  228.                             'name'      => __( 'Caption', 'avia_framework' ),
  229.                             'desc'      => __( 'Add your caption text', 'avia_framework' ),
  230.                             'id'        => 'content',
  231.                             'type'      => 'textarea',
  232.                             'std'       => '',
  233.                             'lockable'  => true,
  234.                             'required'  => array( 'caption', 'equals', 'yes' )
  235.                         ),
  236.  
  237.                     );
  238.            
  239.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_image' ), $c );
  240.            
  241.             /**
  242.              * Styling Tab
  243.              * ===========
  244.              */
  245.            
  246.             $c = array(
  247.                        
  248.                         array( 
  249.                             'name'      => __( 'Caption custom font size?', 'avia_framework' ),
  250.                             'desc'      => __( 'Size of your caption in pixel', 'avia_framework' ),
  251.                             'id'        => 'font_size',
  252.                             'type'      => 'select',
  253.                             'std'       => '',
  254.                             'lockable'  => true,
  255.                             'required'  => array( 'caption', 'equals', 'yes' ),
  256.                             'subtype'   => AviaHtmlHelper::number_array( 10, 40, 1, array( 'Default' => '' ), 'px' )
  257.                         ),
  258.  
  259.                         array(
  260.                             'name'      => __( 'Caption Overlay Opacity', 'avia_framework' ),
  261.                             'desc'      => __( 'Set the opacity of your overlay: 0.1 is barely visible, 1.0 is opaque ', 'avia_framework' ),
  262.                             'id'        => 'overlay_opacity',
  263.                             'type'      => 'select',
  264.                             'std'       => '0.4',
  265.                             'lockable'  => true,
  266.                             'required'  => array( 'caption', 'equals','yes' ),
  267.                             'subtype'   => array(  
  268.                                                 __( '0.1', 'avia_framework' )   => '0.1',
  269.                                                 __( '0.2', 'avia_framework' )   => '0.2',
  270.                                                 __( '0.3', 'avia_framework' )   => '0.3',
  271.                                                 __( '0.4', 'avia_framework' )   => '0.4',
  272.                                                 __( '0.5', 'avia_framework' )   => '0.5',
  273.                                                 __( '0.6', 'avia_framework' )   => '0.6',
  274.                                                 __( '0.7', 'avia_framework' )   => '0.7',
  275.                                                 __( '0.8', 'avia_framework' )   => '0.8',
  276.                                                 __( '0.9', 'avia_framework' )   => '0.9',
  277.                                                 __( '1.0', 'avia_framework' )   => '1',
  278.                                             )
  279.                         ),
  280.                                        
  281.                         array(
  282.                             'name'      => __( 'Caption Overlay Background Color', 'avia_framework' ),
  283.                             'desc'      => __( 'Select a background color for your overlay here.', 'avia_framework' ),
  284.                             'id'        => 'overlay_color',
  285.                             'type'      => 'colorpicker',
  286.                             'container_class' => 'av_half av_half_first',
  287.                             'std'       => '#000000',
  288.                             'lockable'  => true,
  289.                             'required'  => array( 'caption', 'equals', 'yes' )
  290.                         ), 
  291.                                    
  292.                         array( 
  293.                             'name'  => __( 'Caption Font Color', 'avia_framework' ),
  294.                             'desc'  => __( 'Select a font color for your overlay here.', 'avia_framework' ),
  295.                             'id'    => 'overlay_text_color',
  296.                             'type'  => 'colorpicker',
  297.                             'std'   => '#ffffff',
  298.                             'container_class' => 'av_half',
  299.                             'lockable'  => true,
  300.                             'required'  => array( 'caption', 'equals', 'yes' ),
  301.                         ),
  302.                
  303.                        
  304.                 );
  305.            
  306.             $template = array(
  307.                             array( 
  308.                                 'type'          => 'template',
  309.                                 'template_id'   => 'toggle',
  310.                                 'title'         => __( 'Image Caption', 'avia_framework' ),
  311.                                 'content'       => $c
  312.                             ),
  313.                     );
  314.            
  315.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_image_caption' ), $template );
  316.            
  317.            
  318.            
  319.             $c = array(
  320.                         array(
  321.                             'name'  => __( 'Image Styling', 'avia_framework' ),
  322.                             'desc'  => __( 'Choose a styling variaton', 'avia_framework' ),
  323.                             'id'    => 'styling',
  324.                             'type'  => 'select',
  325.                             'std'   => '',
  326.                             'lockable'  => true,
  327.                             'subtype'   => array(
  328.                                                 __( 'Default',  'avia_framework' )  => '',
  329.                                                 __( 'Circle (image height and width must be equal)',  'avia_framework' )    => 'circle',
  330.                                                 __( 'No Styling (no border, no border radius etc)',  'avia_framework' )     => 'no-styling',
  331.                                             )
  332.                         ),
  333.  
  334.                         array(
  335.                             'name'  => __( 'Image Alignment', 'avia_framework' ),
  336.                             'desc'  => __( 'Choose here, how to align your image', 'avia_framework' ),
  337.                             'id'    => 'align',
  338.                             'type'  => 'select',
  339.                             'std'   => 'center',
  340.                             'lockable'  => true,
  341.                             'subtype'   => array(
  342.                                                 __( 'Center',  'avia_framework' )       => 'center',
  343.                                                 __( 'Right',  'avia_framework' )        => 'right',
  344.                                                 __( 'Left',  'avia_framework' )         => 'left',
  345.                                                 __( 'No special alignment', 'avia_framework' )  => '',
  346.                                             )
  347.                         )
  348.  
  349.                 );
  350.            
  351.             $template = array(
  352.                             array( 
  353.                                 'type'          => 'template',
  354.                                 'template_id'   => 'toggle',
  355.                                 'title'         => __( 'Image Styling', 'avia_framework' ),
  356.                                 'content'       => $c
  357.                             ),
  358.                     );
  359.            
  360.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_image_styling' ), $template );
  361.            
  362.            
  363.            
  364.             /**
  365.              * Advanced Tab
  366.              * ============
  367.              */
  368.            
  369.             $c = array(
  370.                         array(
  371.                             'name'  => __( 'Image Fade in Animation', 'avia_framework' ),
  372.                             'desc'  => __( "Add a small animation to the image when the user first scrolls to the image position. This is only to add some 'spice' to the site and only works in modern browsers", 'avia_framework' ),
  373.                             'id'    => 'animation',
  374.                             'type'  => 'select',
  375.                             'std'   => 'no-animation',
  376.                             'lockable'  => true,
  377.                             'subtype'   => array(
  378.                                                 __( 'None', 'avia_framework' )  => 'no-animation',
  379.                                                 __( 'Fade Animations', 'avia_framework')    => array(
  380.                                                             __( 'Fade in', 'avia_framework' )   => 'fade-in',
  381.                                                             __( 'Pop up', 'avia_framework' )    => 'pop-up',
  382.                                                         ),
  383.                                                 __( 'Slide Animations', 'avia_framework' ) => array(
  384.                                                             __( 'Top to Bottom', 'avia_framework' ) => 'top-to-bottom',
  385.                                                             __( 'Bottom to Top', 'avia_framework' ) => 'bottom-to-top',
  386.                                                             __( 'Left to Right', 'avia_framework' ) => 'left-to-right',
  387.                                                             __( 'Right to Left', 'avia_framework' ) => 'right-to-left',
  388.                                                         ),
  389.                                                 __( 'Rotate',  'avia_framework' ) => array(
  390.                                                             __( 'Full rotation', 'avia_framework' )         => 'av-rotateIn',
  391.                                                             __( 'Bottom left rotation', 'avia_framework' )  => 'av-rotateInUpLeft',
  392.                                                             __( 'Bottom right rotation', 'avia_framework' ) => 'av-rotateInUpRight',
  393.                                                         )
  394.                                             )
  395.                         ),
  396.                
  397.                         array(
  398.                             'name'  => __( 'Image Hover effect', 'avia_framework' ),
  399.                             'desc'  => __( 'Add a mouse hover effect to the image', 'avia_framework' ),
  400.                             'id'    => 'hover',
  401.                             'type'  => 'select',
  402.                             'std'   => '',
  403.                             'lockable'  => true,
  404.                             'subtype'   => array(
  405.                                                 __( 'No', 'avia_framework' )    => '',
  406.                                                 __( 'Yes, slightly increase the image size', 'avia_framework' ) => 'av-hover-grow',
  407.                                                 __( 'Yes, slightly zoom the image', 'avia_framework' )          => 'av-hover-grow av-hide-overflow',
  408.                                             )
  409.                         ),
  410.                
  411.                         array(
  412.                             'name'  => __( 'Caption Appearance', 'avia_framework' ),
  413.                             'desc'  => __( 'When to display the caption?', 'avia_framework' ),
  414.                             'id'    => 'appearance',
  415.                             'type'  => 'select',
  416.                             'std'   => '',
  417.                             'lockable'  => true,
  418.                             'required'  => array( 'caption', 'equals', 'yes' ),
  419.                             'subtype'   => array(
  420.                                                 __( 'Always display caption', 'avia_framework' )    => '',
  421.                                                 __( 'Only display on hover', 'avia_framework' )     => 'on-hover',
  422.                                             )
  423.                         )
  424.                
  425.                 );
  426.            
  427.             $template = array(
  428.                             array( 
  429.                                 'type'          => 'template',
  430.                                 'template_id'   => 'toggle',
  431.                                 'title'         => __( 'Animation', 'avia_framework' ),
  432.                                 'content'       => $c
  433.                             ),
  434.                     );
  435.            
  436.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_animation' ), $template );
  437.            
  438.             $c = array(
  439.                         array(
  440.                             'name'  => __( 'Image Link?', 'avia_framework' ),
  441.                             'desc'  => __( 'Where should your image link to?', 'avia_framework' ),
  442.                             'id'    => 'link',
  443.                             'type'  => 'linkpicker',
  444.                             'fetchTMPL' => true,
  445.                             'std'       => '',
  446.                             'lockable'  => true,
  447.                             'subtype'   => array(
  448.                                             __( 'No Link', 'avia_framework' )   => '',
  449.                                             __( 'Lightbox', 'avia_framework' )  => 'lightbox',
  450.                                             __( 'Set Manually', 'avia_framework' )  => 'manually',
  451.                                             __( 'Single Entry', 'avia_framework' )  => 'single',
  452.                                             __( 'Taxonomy Overview Page', 'avia_framework' )    => 'taxonomy',
  453.                                         )
  454.                         ),
  455.                
  456.                         array(
  457.                             'name'  => __( 'Open new tab/window', 'avia_framework' ),
  458.                             'desc'  => __( 'Do you want to open the link url in a new tab/window?', 'avia_framework' ),
  459.                             'id'    => 'target',
  460.                             'type'  => 'select',
  461.                             'std'   => '',
  462.                             'lockable'  => true,
  463.                             'required'  => array( 'link', 'not_empty_and', 'lightbox' ),
  464.                             'subtype'   => AviaHtmlHelper::linking_options()
  465.                         ),
  466.  
  467.                     );
  468.                        
  469.             $template = array(
  470.                             array( 
  471.                                 'type'          => 'template',
  472.                                 'template_id'   => 'toggle',
  473.                                 'title'         => __( 'Image Link Settings', 'avia_framework' ),
  474.                                 'content'       => $c
  475.                             ),
  476.                     );
  477.            
  478.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_link' ), $template );
  479.            
  480.             $c = array(
  481.                         array(
  482.                             'name'          => __( 'Custom Title Attribute', 'avia_framework' ),
  483.                             'desc'          => __( 'Add a custom title attribute limited to this instance, replaces media gallery settings.', 'avia_framework' ),
  484.                             'id'            => 'title_attr',
  485.                             'type'          => 'input',
  486.                             'std'           => '',
  487.                             'lockable'      => true,
  488.                         ),
  489.  
  490.                         array(
  491.                             'name'          => __( 'Custom Alt Attribute', 'avia_framework' ),
  492.                             'desc'          => __( 'Add a custom alt attribute limited to this instance, replaces media gallery settings.', 'avia_framework' ),
  493.                             'id'            => 'alt_attr',
  494.                             'type'          => 'input',
  495.                             'std'           => '',
  496.                             'lockable'      => true,
  497.                         )
  498.                     );
  499.            
  500.            
  501.             $template = array(
  502.                             array( 
  503.                                 'type'          => 'template',
  504.                                 'template_id'   => 'toggle',
  505.                                 'title'         => __( 'SEO improvements', 'avia_framework' ),
  506.                                 'content'       => $c
  507.                             ),
  508.                     );
  509.            
  510.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_seo' ), $template );
  511.         }
  512.  
  513.         /**
  514.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  515.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  516.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  517.          *
  518.          *
  519.          * @param array $params this array holds the default values for $content and $args.
  520.          * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  521.          */
  522.         function editor_element( $params )
  523.         {
  524.             $default = array();
  525.             $locked = array();
  526.             $attr = $params['args'];
  527.             Avia_Element_Templates()->set_locked_attributes( $attr, $this, $this->config['shortcode'], $default, $locked );
  528.            
  529.             $template = $this->update_template_lockable( 'src', "<img src='{{src}}' alt=''/>", $locked );
  530.             $img = '';
  531.            
  532.             if( ! empty( $attr['attachment'] ) && ! empty( $attr['attachment_size'] ) )
  533.             {
  534.                 $img = wp_get_attachment_image( $attr['attachment'], $attr['attachment_size'] );
  535.             }
  536.             else if( isset( $attr['src'] ) && is_numeric( $attr['src'] ) )
  537.             {
  538.                 $img = wp_get_attachment_image( $attr['src'], 'large' );
  539.             }
  540.             else if( ! empty( $attr['src'] ) )
  541.             {
  542.                 $img = "<img src='" . esc_attr( $attr['src'] ) . "' alt=''  />";
  543.             }
  544.  
  545.             $params['innerHtml']  = "<div class='avia_image avia_image_style avia_hidden_bg_box' data-update_element_template='yes'>";
  546.             $params['innerHtml'] .=     '<div ' . $this->class_by_arguments_lockable( 'align', $attr, $locked ) . '>';
  547.             $params['innerHtml'] .=         "<div class='avia_image_container' {$template}>{$img}</div>";
  548.             $params['innerHtml'] .=     '</div>';
  549.             $params['innerHtml'] .= '</div>';
  550.            
  551.             $params['class'] = '';
  552.  
  553.             return $params;
  554.         }
  555.        
  556.         /**
  557.          * Create custom stylings
  558.          *
  559.          * @since 4.8.4
  560.          * @param array $args
  561.          * @return array
  562.          */
  563.         protected function get_element_styles( array $args )
  564.         {
  565.             $result = parent::get_element_styles( $args );
  566.            
  567.             extract( $result );
  568.            
  569.             $default = array(
  570.                             'src'               => '',
  571.                             'title_attr'        => '',
  572.                             'alt_attr'          => '',
  573.                             'animation'         => 'no-animation',
  574.                             'lazy_loading'      => 'disabled',
  575.                             'link'              => '',
  576.                             'attachment'        => '',
  577.                             'attachment_size'   => '',
  578.                             'target'            => '',
  579.                             'styling'           => '',
  580.                             'caption'           => '',
  581.                             'copyright'         => '',
  582.                             'font_size'         => '',
  583.                             'appearance'        => '',
  584.                             'hover'             => '',
  585.                             'align'             => 'center',
  586.                             'overlay_opacity'   => '0.4',
  587.                             'overlay_color'     => '#444444',
  588.                             'overlay_text_color'    => '#ffffff',
  589.                
  590.                                 //  added for shortcode handler html output
  591.                             'attachment_id'     => '',
  592.                             'src_original'      => '',          //  save original source in case shortcode was called directly and ID was added to source
  593.                             'img_h'             => '',
  594.                             'img_w'             => '',
  595.                             'copyright_text'    => ''
  596.                         );
  597.            
  598.             $default = $this->sync_sc_defaults_array( $default, 'no_modal_item', 'no_content' );
  599.            
  600.            
  601.             $locked = array();
  602.             Avia_Element_Templates()->set_locked_attributes( $atts, $this, $shortcodename, $default, $locked, $content );
  603.             Avia_Element_Templates()->add_template_class( $meta, $atts, $default );
  604.            
  605.             $atts = shortcode_atts( $default, $atts, $this->config['shortcode'] );
  606.            
  607.             //  save original value for shortcode handler
  608.             $atts['src_original'] = $atts['src'];
  609.            
  610.             if( ! empty( $atts['attachment'] ) )
  611.             {
  612.                 /**
  613.                  * Allows e.g. WPML to reroute to translated image
  614.                  */
  615.                 $posts = get_posts( array(
  616.                                         'include'           => $atts['attachment'],
  617.                                         'post_status'       => 'inherit',
  618.                                         'post_type'         => 'attachment',
  619.                                         'post_mime_type'    => 'image',
  620.                                         'order'             => 'ASC',
  621.                                         'orderby'           => 'post__in'
  622.                                     )
  623.                                 );
  624.  
  625.                 if( is_array( $posts ) && ! empty( $posts ) )
  626.                 {
  627.                     $attachment_entry = $posts[0];
  628.                     $atts['attachment_id'] = $attachment_entry->ID;
  629.                    
  630.                     if( ! empty( $atts['alt_attr'] ) )
  631.                     {
  632.                         $alt = $atts['alt_attr'];
  633.                     }
  634.                     else
  635.                     {
  636.                         $alt = get_post_meta( $attachment_entry->ID, '_wp_attachment_image_alt', true );
  637.                     }
  638.                    
  639.                     $atts['alt_attr'] = ! empty( $alt ) ? esc_attr( trim( $alt ) ) : '';
  640.                    
  641.                     if( ! empty( $atts['title_attr'] ) )
  642.                     {
  643.                         $title = $atts['title_attr'];
  644.                     }
  645.                     else
  646.                     {
  647.                         $title = $attachment_entry->post_title;
  648.                     }
  649.                    
  650.                     $atts['title_attr'] = ! empty( $title ) ? esc_attr( trim( $title ) ) : '';
  651.                    
  652.                     if( $atts['copyright'] !== '')
  653.                     {
  654.                         $copyright_text = get_post_meta( $attachment_entry->ID, '_avia_attachment_copyright', true );
  655.                        
  656.                         /**
  657.                          * Allow to filter the copyright text
  658.                          *
  659.                          * @since 4.7.4.1
  660.                          * @param string $copyright_text
  661.                          * @param string $shortcodename         context calling the filter
  662.                          * @param int $attachment_entry->ID
  663.                          * @return string
  664.                          */
  665.                         $atts['copyright_text'] = apply_filters( 'avf_attachment_copyright_text', $copyright_text, $shortcodename, $attachment_entry->ID );
  666.                     }
  667.  
  668.                     if( ! empty( $atts['attachment_size'] ) )
  669.                     {
  670.                         $src = wp_get_attachment_image_src( $attachment_entry->ID, $atts['attachment_size'] );
  671.  
  672.                         $atts['img_h'] = ! empty( $src[2] ) ? $src[2] : '';
  673.                         $atts['img_w'] = ! empty( $src[1] ) ? $src[1] : '';
  674.                         $atts['src'] = ! empty( $src[0] ) ? $src[0] : '';
  675.                     }
  676.                 }
  677.             }
  678.             else
  679.             {
  680.                 $atts['attachment'] = false;
  681.             }
  682.            
  683.             if( empty( $atts['src'] ) )
  684.             {
  685.                 $result['default'] = $default;
  686.                 $result['atts'] = $atts;
  687.                 $result['content'] = $content;
  688.  
  689.                 return $result;
  690.             }
  691.            
  692.            
  693.             $element_styling->create_callback_styles( $atts );
  694.            
  695.             if( is_numeric( $atts['src'] ) )
  696.             {
  697.                 $classes = array(
  698.                             'avia_image',
  699.                             $element_id
  700.                     );
  701.             }
  702.             else
  703.             {
  704.                 $classes = array(
  705.                             'avia-image-container',
  706.                             $element_id
  707.                     );
  708.             }
  709.            
  710.             $classes[] = "av-styling-{$atts['styling']}";
  711.            
  712.             if( ! empty( $atts['hover'] ) )
  713.             {
  714.                 $classes[] = $atts['hover'];
  715.             }
  716.            
  717.             if( $atts['animation'] != 'no-animation' )
  718.             {
  719.                 $classes[] = 'avia_animated_image';
  720.                 $classes[] = 'avia_animate_when_almost_visible';
  721.                 $classes[] = $atts['animation'];
  722.             }
  723.            
  724.             $element_styling->add_classes( 'container', $classes );
  725.             $element_styling->add_classes( 'container', $this->class_by_arguments( 'align', $atts, true, 'array' ) );
  726.             $element_styling->add_classes_from_array( 'container', $meta, 'el_class' );
  727.            
  728.             if( ! is_numeric( $atts['src'] ) )
  729.             {
  730.                
  731.                 $element_styling->add_styles( 'container-overlay', array( 'color' => $atts['overlay_text_color'] ) );
  732.            
  733.                 if( ! empty( $atts['font_size'] ) )
  734.                 {
  735.                     $element_styling->add_styles( 'container-overlay', array( 'font-size' => $atts['font_size'] . 'px' ) );
  736.                 }
  737.                
  738.                 if( $atts['caption'] == 'yes' )
  739.                 {
  740.                     $element_styling->add_styles( 'container-caption', array( 'opacity' => $atts['overlay_opacity'] ) );
  741.                     $element_styling->add_styles( 'container-caption', array( 'background-color' => $atts['overlay_color'] ) );
  742.                    
  743.                     $element_styling->add_classes( 'container', 'noHover' );
  744.                    
  745.                     if( empty( $atts['appearance'] ) )
  746.                     {
  747.                         $atts['appearance'] = 'hover-deactivate';
  748.                     }
  749.                    
  750.                     $element_styling->add_classes( 'container', "av-overlay-{$atts['appearance']}" );
  751.                 }
  752.                
  753.                 if( ! empty( $atts['copyright_text'] ) )
  754.                 {
  755.                     $element_styling->add_classes( 'container', 'av-has-copyright' );
  756.                    
  757.                     if( ! empty( $atts['copyright'] ) )
  758.                     {
  759.                         $element_styling->add_classes( 'container', "av-copyright-{$atts['copyright']}" );
  760.                     }
  761.                 }
  762.                
  763.                 $selectors = array(
  764.                             'container'             => ".avia-image-container.{$element_id}",
  765.                             'container-caption'     => ".avia-image-container.{$element_id} .av-caption-image-overlay-bg",
  766.                             'container-overlay'     => ".avia-image-container.{$element_id} .av-image-caption-overlay-center",
  767.                         );
  768.            
  769.                 $element_styling->add_selectors( $selectors );
  770.             }
  771.            
  772.             $result['default'] = $default;
  773.             $result['atts'] = $atts;
  774.             $result['content'] = $content;
  775.             $result['element_styling'] = $element_styling;
  776.            
  777.             return $result;
  778.         }
  779.  
  780.         /**
  781.          * Frontend Shortcode Handler
  782.          *
  783.          * @param array $atts array of attributes
  784.          * @param string $content text within enclosing form of shortcode element
  785.          * @param string $shortcodename the shortcode found, when == callback name
  786.          * @return string $output returns the modified html string
  787.          */
  788.         function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' )
  789.         {
  790.             $result = $this->get_element_styles( compact( array( 'atts', 'content', 'shortcodename', 'meta' ) ) );
  791.            
  792.             extract( $result );
  793.            
  794.             if( empty( $atts['src'] ) )
  795.             {
  796.                 return '';
  797.             }
  798.            
  799.             extract( AviaHelper::av_mobile_sizes( $atts ) ); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  800.            
  801.             extract( $atts );
  802.            
  803.  
  804.             $output = '';
  805.            
  806.             if( is_numeric( $src_original ) )
  807.             {
  808.                 $img_atts = array(
  809.                             'class' => $element_styling->get_class_string( 'container' )
  810.                         );
  811.  
  812.                 if( ! empty( $img_h ) )
  813.                 {
  814.                     $img_atts['height'] = $img_h;
  815.                 }
  816.                 if( ! empty( $img_w ) )
  817.                 {
  818.                     $img_atts['width'] = $img_w;
  819.                 }
  820.  
  821.                 if( $lazy_loading != 'enabled' )
  822.                 {
  823.                     Av_Responsive_Images()->add_attachment_id_to_not_lazy_loading( $src );
  824.                 }
  825.  
  826.                 $output .= wp_get_attachment_image( $src, 'large', false, $img_atts );
  827.             }
  828.             else
  829.             {
  830.                 $link = AviaHelper::get_url( $link, $attachment, true );
  831.                 $blank = AviaHelper::get_link_target( $target );
  832.  
  833.                 $overlay = '';
  834.  
  835.                 if( $caption == 'yes' )
  836.                 {  
  837.                     $overlay  = "<div class='av-image-caption-overlay'>";
  838.                     $overlay .=     "<div class='av-caption-image-overlay-bg'></div>";
  839.                     $overlay .=     "<div class='av-image-caption-overlay-position'>";
  840.                     $overlay .=         "<div class='av-image-caption-overlay-center'>";
  841.                     $overlay .=             ShortcodeHelper::avia_apply_autop( ShortcodeHelper::avia_remove_autop( $content ) );
  842.                     $overlay .=         '</div>';
  843.                     $overlay .=     '</div>';
  844.                     $overlay .= '</div>';
  845.                 }
  846.  
  847.                 $copyright_tag = '';
  848.                 if( ! empty( $copyright_text ) )
  849.                 {
  850.                     $copyright_tag = '<small class="avia-copyright">' . esc_html( $copyright_text ) . '</small>';
  851.                 }
  852.  
  853.                 $markup_url = avia_markup_helper( array( 'context' => 'image_url', 'echo' => false, 'custom_markup' => $meta['custom_markup'] ) );
  854.                 $markup_img = avia_markup_helper( array( 'context' => 'image', 'echo' => false, 'custom_markup' => $meta['custom_markup'] ) );
  855.  
  856.                 $style_tag = $element_styling->get_style_tag( $element_id );
  857.                 $container_class = $element_styling->get_class_string( 'container' );
  858.  
  859.                 $output .= $style_tag;
  860.                 $output .= "<div {$meta['custom_el_id']} class='{$container_class} {$av_display_classes}' {$markup_img}>";
  861.                 $output .=      '<div class="avia-image-container-inner">';
  862.                 $output .=          '<div class="avia-image-overlay-wrap">';
  863.  
  864.                 if( ! empty( $link ) )
  865.                 {
  866.                     $img_tag = "<img class='avia_image' src='{$src}' alt='{$alt_attr}' title='{$title_attr}' {$markup_url} />";
  867.                     $img_tag = Av_Responsive_Images()->prepare_single_image( $img_tag, $attachment_id, $lazy_loading );
  868.                     $lightbox_attr = Av_Responsive_Images()->html_attr_image_src( $link, false );
  869.  
  870.                     $output .=          "<a {$lightbox_attr} class='avia_image' {$blank}>{$overlay}{$img_tag}</a>";
  871.                 }
  872.                 else
  873.                 {
  874.                     $hw = '';
  875.                     if( ! empty( $img_h ) )
  876.                     {
  877.                         $hw .= ' height="' . $img_h . '"';
  878.                     }
  879.  
  880.                     if( ! empty( $img_w ) )
  881.                     {
  882.                         $hw .= ' width="' . $img_w . '"';
  883.                     }
  884.  
  885.                     $img_tag = "<img class='avia_image' src='{$src}' alt='{$alt_attr}' title='{$title_attr}' {$hw} {$markup_url} />";
  886.                     $img_tag = Av_Responsive_Images()->prepare_single_image( $img_tag, $attachment_id, $lazy_loading );
  887.  
  888.                     $output .=          "{$overlay}{$img_tag}";
  889.                 }
  890.                    
  891.                 $output .=          '</div>';
  892.                 $output .=      $copyright_tag;
  893.  
  894.                 $output .=      '</div>';
  895.                 $output .= '</div>';
  896.             }
  897.  
  898.             return Av_Responsive_Images()->make_content_images_responsive( $output );
  899.         }
  900.  
  901.     }
  902. }
  903.  
  904.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement