Advertisement
Guest User

Untitled

a guest
Jun 15th, 2022
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 32.90 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.             //load css
  40.             wp_enqueue_style( 'avia-module-image', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/image/image.css', array( 'avia-layout' ), false );
  41.         }
  42.  
  43.         /**
  44.          * Popup Elements
  45.          *
  46.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  47.          * opens a modal window that allows to edit the element properties
  48.          *
  49.          * @return void
  50.          */
  51.         function popup_elements()
  52.         {
  53.             $this->elements = array(
  54.  
  55.                 array(
  56.                         'type'  => 'tab_container',
  57.                         'nodescription' => true
  58.                     ),
  59.  
  60.                 array(
  61.                         'type'  => 'tab',
  62.                         'name'  => __( 'Content', 'avia_framework' ),
  63.                         'nodescription' => true
  64.                     ),
  65.  
  66.                     array(
  67.                             'type'          => 'template',
  68.                             'template_id'   => $this->popup_key( 'content_image' )
  69.                         ),
  70.  
  71.                 array(
  72.                         'type'  => 'tab_close',
  73.                         'nodescription' => true
  74.                     ),
  75.  
  76.                 array(
  77.                         'type'  => 'tab',
  78.                         'name'  => __( 'Styling', 'avia_framework' ),
  79.                         'nodescription' => true
  80.                     ),
  81.  
  82.                     array(
  83.                             'type'          => 'template',
  84.                             'template_id'   => 'toggle_container',
  85.                             'templates_include' => array(
  86.                                                     $this->popup_key( 'styling_image_size' ),
  87.                                                     $this->popup_key( 'styling_image_styling' ),
  88.                                                     $this->popup_key( 'styling_image_alignment' ),
  89.                                                     $this->popup_key( 'styling_image_caption' )
  90.                                                 ),
  91.                             'nodescription' => true
  92.                         ),
  93.  
  94.  
  95.                 array(
  96.                         'type'  => 'tab_close',
  97.                         'nodescription' => true
  98.                     ),
  99.  
  100.                 array(
  101.                         'type'  => 'tab',
  102.                         'name'  => __( 'Advanced', 'avia_framework' ),
  103.                         'nodescription' => true
  104.                     ),
  105.  
  106.                     array(
  107.                             'type'  => 'toggle_container',
  108.                             'nodescription' => true
  109.                         ),
  110.  
  111.                         array(
  112.                                 'type'          => 'template',
  113.                                 'template_id'   => $this->popup_key( 'advanced_animation' ),
  114.                             ),
  115.  
  116.                         array(
  117.                                 'name'          => __( 'Image Position', 'avia_framework' ),
  118.                                 'desc'          => __( 'Set a position for the image.', 'avia_framework' ),
  119.                                 'type'          => 'template',
  120.                                 'template_id'   => 'position',
  121.                                 'toggle'        => true,
  122.                                 'lockable'      => true
  123.                             ),
  124.  
  125.                         array(
  126.                                 'type'          => 'template',
  127.                                 'template_id'   => 'transform',
  128.                                 'toggle'        => true,
  129.                                 'lockable'      => true
  130.                             ),
  131.  
  132.                         array(
  133.                                 'type'          => 'template',
  134.                                 'template_id'   => $this->popup_key( 'advanced_link' ),
  135.                             ),
  136.  
  137.                         array(
  138.                                 'type'          => 'template',
  139.                                 'template_id'   => $this->popup_key( 'advanced_seo' ),
  140.                             ),
  141.  
  142.                         array(
  143.                                 'type'          => 'template',
  144.                                 'template_id'   => 'lazy_loading_toggle',
  145.                                 'lockable'      => true
  146.                             ),
  147.  
  148.                         array(
  149.                                 'type'          => 'template',
  150.                                 'template_id'   => 'screen_options_toggle',
  151.                                 'lockable'      => true
  152.                             ),
  153.  
  154.                         array(
  155.                                 'type'          => 'template',
  156.                                 'template_id'   => 'developer_options_toggle',
  157.                                 'args'          => array( 'sc' => $this )
  158.                             ),
  159.  
  160.                     array(
  161.                             'type'  => 'toggle_container_close',
  162.                             'nodescription' => true
  163.                         ),
  164.  
  165.                 array(
  166.                         'type'  => 'tab_close',
  167.                         'nodescription' => true
  168.                     ),
  169.  
  170.                 array(
  171.                         'type'          => 'template',
  172.                         'template_id'   => 'element_template_selection_tab',
  173.                         'args'          => array(
  174.                                                 'sc'    => $this
  175.                                             )
  176.                     ),
  177.  
  178.                 array(
  179.                         'type'  => 'tab_container_close',
  180.                         'nodescription' => true
  181.                     ),
  182.  
  183.                 array(
  184.                         'id'    => 'av_element_hidden_in_editor',
  185.                         'type'  => 'hidden',
  186.                         'std'   => '0'
  187.                     )
  188.             );
  189.  
  190.         }
  191.  
  192.         /**
  193.          * Create and register templates for easier maintainance
  194.          *
  195.          * @since 4.6.4
  196.          */
  197.         protected function register_dynamic_templates()
  198.         {
  199.             /**
  200.              * Content Tab
  201.              * ===========
  202.              */
  203.  
  204.             $c = array(
  205.                         array(
  206.                             'name'      => __( 'Choose Image', 'avia_framework' ),
  207.                             'desc'      => __( 'Either upload a new, or choose an existing image from your media library', 'avia_framework' ),
  208.                             'id'        => 'src',
  209.                             'type'      => 'image',
  210.                             'title'     => __( 'Insert Image', 'avia_framework' ),
  211.                             'button'    => __( 'Insert', 'avia_framework' ),
  212.                             'std'       => AviaBuilder::$path['imagesURL'] . 'placeholder.jpg',
  213.                             'lockable'  => true,
  214.                             'locked'    => array( 'src', 'attachment', 'attachment_size' )
  215.                         ),
  216.  
  217.                         array(
  218.                             'name'      => __( 'Copyright Info', 'avia_framework' ),
  219.                             'desc'      => __( 'Use the media manager to add/edit the copyright info.', 'avia_framework' ),
  220.                             'id'        => 'copyright',
  221.                             'type'      => 'select',
  222.                             'std'       => '',
  223.                             'lockable'  => true,
  224.                             'subtype'   => array(
  225.                                                 __( 'No', 'avia_framework' )                                    => '',
  226.                                                 __( 'Yes, always display copyright info', 'avia_framework' )    => 'always',
  227.                                                 __( 'Yes, display icon and reveal copyright info on hover', 'avia_framework' )  => 'icon-reveal',
  228.                                             )
  229.                         ),
  230.  
  231.                         array(
  232.                             'name'  => __( 'Image Caption', 'avia_framework' ),
  233.                             'desc'  => __( 'Display a caption overlay?', 'avia_framework' ),
  234.                             'id'    => 'caption',
  235.                             'type'  => 'select',
  236.                             'std'   => '',
  237.                             'lockable'  => true,
  238.                             'subtype'   => array(
  239.                                                 __( 'No', 'avia_framework' )    => '',
  240.                                                 __( 'Yes', 'avia_framework' )   => 'yes',
  241.                                             )
  242.                         ),
  243.  
  244.                         array(
  245.                             'name'      => __( 'Caption', 'avia_framework' ),
  246.                             'desc'      => __( 'Add your caption text', 'avia_framework' ),
  247.                             'id'        => 'content',
  248.                             'type'      => 'textarea',
  249.                             'std'       => '',
  250.                             'lockable'  => true,
  251.                             'required'  => array( 'caption', 'equals', 'yes' )
  252.                         ),
  253.  
  254.                     );
  255.  
  256.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_image' ), $c );
  257.  
  258.             /**
  259.              * Styling Tab
  260.              * ===========
  261.              */
  262.  
  263.             $c = array(
  264.  
  265.                         array(
  266.                             'name'      => __( 'Caption custom font size?', 'avia_framework' ),
  267.                             'desc'      => __( 'Size of your caption in pixel', 'avia_framework' ),
  268.                             'id'        => 'font_size',
  269.                             'type'      => 'select',
  270.                             'std'       => '',
  271.                             'lockable'  => true,
  272.                             'required'  => array( 'caption', 'equals', 'yes' ),
  273.                             'subtype'   => AviaHtmlHelper::number_array( 10, 40, 1, array( 'Default' => '' ), 'px' )
  274.                         ),
  275.  
  276.                         array(
  277.                             'name'      => __( 'Caption Overlay Opacity', 'avia_framework' ),
  278.                             'desc'      => __( 'Set the opacity of your overlay: 0.1 is barely visible, 1.0 is opaque ', 'avia_framework' ),
  279.                             'id'        => 'overlay_opacity',
  280.                             'type'      => 'select',
  281.                             'std'       => '0.4',
  282.                             'lockable'  => true,
  283.                             'required'  => array( 'caption', 'equals','yes' ),
  284.                             'subtype'   => array(
  285.                                                 __( '0.1', 'avia_framework' )   => '0.1',
  286.                                                 __( '0.2', 'avia_framework' )   => '0.2',
  287.                                                 __( '0.3', 'avia_framework' )   => '0.3',
  288.                                                 __( '0.4', 'avia_framework' )   => '0.4',
  289.                                                 __( '0.5', 'avia_framework' )   => '0.5',
  290.                                                 __( '0.6', 'avia_framework' )   => '0.6',
  291.                                                 __( '0.7', 'avia_framework' )   => '0.7',
  292.                                                 __( '0.8', 'avia_framework' )   => '0.8',
  293.                                                 __( '0.9', 'avia_framework' )   => '0.9',
  294.                                                 __( '1.0', 'avia_framework' )   => '1',
  295.                                             )
  296.                         ),
  297.  
  298.                         array(
  299.                             'name'      => __( 'Caption Overlay Background Color', 'avia_framework' ),
  300.                             'desc'      => __( 'Select a background color for your overlay here.', 'avia_framework' ),
  301.                             'id'        => 'overlay_color',
  302.                             'type'      => 'colorpicker',
  303.                             'container_class' => 'av_half av_half_first',
  304.                             'std'       => '#000000',
  305.                             'lockable'  => true,
  306.                             'required'  => array( 'caption', 'equals', 'yes' )
  307.                         ),
  308.  
  309.                         array(
  310.                             'name'  => __( 'Caption Font Color', 'avia_framework' ),
  311.                             'desc'  => __( 'Select a font color for your overlay here.', 'avia_framework' ),
  312.                             'id'    => 'overlay_text_color',
  313.                             'type'  => 'colorpicker',
  314.                             'std'   => '#ffffff',
  315.                             'container_class' => 'av_half',
  316.                             'lockable'  => true,
  317.                             'required'  => array( 'caption', 'equals', 'yes' ),
  318.                         ),
  319.  
  320.  
  321.                 );
  322.  
  323.             $template = array(
  324.                             array(
  325.                                 'type'          => 'template',
  326.                                 'template_id'   => 'toggle',
  327.                                 'title'         => __( 'Image Caption', 'avia_framework' ),
  328.                                 'content'       => $c
  329.                             ),
  330.                     );
  331.  
  332.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_image_caption' ), $template );
  333.  
  334.  
  335.  
  336.             $c = array(
  337.                         array(
  338.                             'type'          => 'template',
  339.                             'template_id'   => 'image_size_select',
  340.                             'lockable'      => true,
  341.                             'method'        => 'fallback_media'
  342.                         )
  343.                 );
  344.  
  345.             $template = array(
  346.                             array(
  347.                                 'type'          => 'template',
  348.                                 'template_id'   => 'toggle',
  349.                                 'title'         => __( 'Size', 'avia_framework' ),
  350.                                 'content'       => $c
  351.                             ),
  352.                     );
  353.  
  354.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_image_size' ), $template );
  355.  
  356.  
  357.             $c = array(
  358.  
  359.                         array(
  360.                             'name'      => __( 'Image Styling', 'avia_framework' ),
  361.                             'desc'      => __( 'Choose a styling variaton', 'avia_framework' ),
  362.                             'id'        => 'styling',
  363.                             'type'      => 'select',
  364.                             'std'       => '',
  365.                             'lockable'  => true,
  366.                             'subtype'   => array(
  367.                                                 __( 'Default',  'avia_framework' )  => '',
  368.                                                 __( 'Circle (image height and width must be equal)',  'avia_framework' )    => 'circle',
  369.                                                 __( 'No Styling (no border, no border radius etc)',  'avia_framework' )     => 'no-styling',
  370.                                             )
  371.                         ),
  372.  
  373.                         array(
  374.                             'type'          => 'template',
  375.                             'template_id'   => 'box_shadow',
  376.                             'sub_shadow'    => array(
  377.                                                     __( 'No shadow', 'avia_framework' )     => 'none',
  378.                                                     __( 'Outside', 'avia_framework' )       => 'outside'
  379.                                                 ),
  380.                             'animated'      => 'auto',
  381.                             'simplified'    => true,
  382.                             'lockable'      => true
  383.                         )
  384.  
  385.                 );
  386.  
  387.             $template = array(
  388.                             array(
  389.                                 'type'          => 'template',
  390.                                 'template_id'   => 'toggle',
  391.                                 'title'         => __( 'Styling', 'avia_framework' ),
  392.                                 'content'       => $c
  393.                             ),
  394.                     );
  395.  
  396.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_image_styling' ), $template );
  397.  
  398.  
  399.             $c = array(
  400.  
  401.                     array(
  402.                             'name'      => __( 'Image Alignment', 'avia_framework' ),
  403.                             'desc'      => __( 'Choose here, how to align your image', 'avia_framework' ),
  404.                             'id'        => 'align',
  405.                             'type'      => 'select',
  406.                             'std'       => 'center',
  407.                             'lockable'  => true,
  408.                             'subtype'   => array(
  409.                                                 __( 'Center',  'avia_framework' )       => 'center',
  410.                                                 __( 'Right',  'avia_framework' )        => 'right',
  411.                                                 __( 'Left',  'avia_framework' )         => 'left',
  412.                                                 __( 'No special alignment', 'avia_framework' )  => '',
  413.                                             )
  414.                         )
  415.  
  416.                 );
  417.  
  418.             $template = array(
  419.                             array(
  420.                                 'type'          => 'template',
  421.                                 'template_id'   => 'toggle',
  422.                                 'title'         => __( 'Alignment', 'avia_framework' ),
  423.                                 'content'       => $c
  424.                             ),
  425.                     );
  426.  
  427.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_image_alignment' ), $template );
  428.  
  429.  
  430.             /**
  431.              * Advanced Tab
  432.              * ============
  433.              */
  434.  
  435.             $c = array(
  436.                         array(
  437.                             'type'          => 'template',
  438.                             'template_id'   => 'animation',
  439.                             'lockable'      => true,
  440.                             'std'           => 'no-animation',
  441.                             'std_none'      => 'no-animation',
  442.                             'name'          => __( 'Image Animation', 'avia_framework' ),
  443.                             'desc'          => __( 'Add a small animation to the image when the user first scrolls to the image position. This is only to add some &quot;spice&quot; to the site.', 'avia_framework' ),
  444.                             'groups'        => array( 'fade', 'slide', 'rotate', 'curtain', 'fade-adv', 'special' )
  445.                         ),
  446.  
  447.                         array(
  448.                             'type'          => 'template',
  449.                             'template_id'   => 'parallax',
  450.                             'lockable'      => true,
  451.                             'std'           => '',
  452.                         ),
  453.  
  454.                         array(
  455.                             'name'  => __( 'Image Hover effect', 'avia_framework' ),
  456.                             'desc'  => __( 'Add a mouse hover effect to the image. Box shadow does not work when you select to zoom the image. This is not a bug.', 'avia_framework' ),
  457.                             'id'    => 'hover',
  458.                             'type'  => 'select',
  459.                             'std'   => '',
  460.                             'lockable'  => true,
  461.                             'subtype'   => array(
  462.                                                 __( 'No', 'avia_framework' )    => '',
  463.                                                 __( 'Yes, slightly increase the image size', 'avia_framework' ) => 'av-hover-grow',
  464.                                                 __( 'Yes, slightly zoom the image', 'avia_framework' )          => 'av-hover-grow av-hide-overflow',
  465.                                             )
  466.                         ),
  467.  
  468.                         array(
  469.                             'name'  => __( 'Caption Appearance', 'avia_framework' ),
  470.                             'desc'  => __( 'When to display the caption?', 'avia_framework' ),
  471.                             'id'    => 'appearance',
  472.                             'type'  => 'select',
  473.                             'std'   => '',
  474.                             'lockable'  => true,
  475.                             'required'  => array( 'caption', 'equals', 'yes' ),
  476.                             'subtype'   => array(
  477.                                                 __( 'Always display caption', 'avia_framework' )    => '',
  478.                                                 __( 'Only display on hover', 'avia_framework' )     => 'on-hover',
  479.                                             )
  480.                         )
  481.                 );
  482.  
  483.             $template = array(
  484.                             array(
  485.                                 'type'          => 'template',
  486.                                 'template_id'   => 'toggle',
  487.                                 'title'         => __( 'Animation', 'avia_framework' ),
  488.                                 'content'       => $c
  489.                             ),
  490.                     );
  491.  
  492.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_animation' ), $template );
  493.  
  494.             $c = array(
  495.                         array(
  496.                             'type'          => 'template',
  497.                             'template_id'   => 'linkpicker_toggle',
  498.                             'name'          => __( 'Image Link?', 'avia_framework' ),
  499.                             'desc'          => __( 'Where should your image link to?', 'avia_framework' ),
  500.                             'subtypes'      => array( 'no', 'lightbox', 'manually', 'single', 'taxonomy' ),
  501.                             'target_id'     => 'target',
  502.                             'lockable'      => true
  503.                         )
  504.                     );
  505.  
  506.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_link' ), $c );
  507.  
  508.             $c = array(
  509.                         array(
  510.                             'name'          => __( 'Custom Title Attribute', 'avia_framework' ),
  511.                             'desc'          => __( 'Add a custom title attribute limited to this instance, replaces media gallery settings.', 'avia_framework' ),
  512.                             'id'            => 'title_attr',
  513.                             'type'          => 'input',
  514.                             'std'           => '',
  515.                             'lockable'      => true,
  516.                         ),
  517.  
  518.                         array(
  519.                             'name'          => __( 'Custom Alt Attribute', 'avia_framework' ),
  520.                             'desc'          => __( 'Add a custom alt attribute limited to this instance, replaces media gallery settings.', 'avia_framework' ),
  521.                             'id'            => 'alt_attr',
  522.                             'type'          => 'input',
  523.                             'std'           => '',
  524.                             'lockable'      => true,
  525.                         )
  526.                     );
  527.  
  528.  
  529.             $template = array(
  530.                             array(
  531.                                 'type'          => 'template',
  532.                                 'template_id'   => 'toggle',
  533.                                 'title'         => __( 'SEO improvements', 'avia_framework' ),
  534.                                 'content'       => $c
  535.                             ),
  536.                     );
  537.  
  538.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_seo' ), $template );
  539.         }
  540.  
  541.         /**
  542.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  543.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  544.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  545.          *
  546.          *
  547.          * @param array $params this array holds the default values for $content and $args.
  548.          * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  549.          */
  550.         function editor_element( $params )
  551.         {
  552.             $default = array();
  553.             $locked = array();
  554.             $attr = $params['args'];
  555.             Avia_Element_Templates()->set_locked_attributes( $attr, $this, $this->config['shortcode'], $default, $locked );
  556.  
  557.             $template = $this->update_template_lockable( 'src', "<img src='{{src}}' alt=''/>", $locked );
  558.             $img = '';
  559.  
  560.             if( ! empty( $attr['attachment'] ) && ! empty( $attr['attachment_size'] ) )
  561.             {
  562.                 $img = wp_get_attachment_image( $attr['attachment'], $attr['attachment_size'] );
  563.             }
  564.             else if( isset( $attr['src'] ) && is_numeric( $attr['src'] ) )
  565.             {
  566.                 $img = wp_get_attachment_image( $attr['src'], 'large' );
  567.             }
  568.             else if( ! empty( $attr['src'] ) )
  569.             {
  570.                 $img = "<img src='" . esc_attr( $attr['src'] ) . "' alt=''  />";
  571.             }
  572.  
  573.             $params['innerHtml']  = "<div class='avia_image avia_image_style avia_hidden_bg_box' data-update_element_template='yes'>";
  574.             $params['innerHtml'] .=     '<div ' . $this->class_by_arguments_lockable( 'align', $attr, $locked ) . '>';
  575.             $params['innerHtml'] .=         "<div class='avia_image_container' {$template}>{$img}</div>";
  576.             $params['innerHtml'] .=     '</div>';
  577.             $params['innerHtml'] .= '</div>';
  578.  
  579.             $params['class'] = '';
  580.  
  581.             return $params;
  582.         }
  583.  
  584.         /**
  585.          * Create custom stylings
  586.          *
  587.          * @since 4.8.4
  588.          * @param array $args
  589.          * @return array
  590.          */
  591.         protected function get_element_styles( array $args )
  592.         {
  593.             $result = parent::get_element_styles( $args );
  594.  
  595.             extract( $result );
  596.  
  597.             $default = array(
  598.                             'src'               => '',
  599.                             'title_attr'        => '',
  600.                             'alt_attr'          => '',
  601.                             'animation'         => 'no-animation',
  602.                             'lazy_loading'      => 'disabled',
  603.                             'link'              => '',
  604.                             'attachment'        => '',
  605.                             'attachment_size'   => '',
  606.                             'image_size'        => '',
  607.                             'target'            => '',
  608.                             'styling'           => '',
  609.                             'caption'           => '',
  610.                             'copyright'         => '',
  611.                             'font_size'         => '',
  612.                             'appearance'        => '',
  613.                             'hover'             => '',
  614.                             'align'             => 'center',
  615.                             'overlay_opacity'   => '0.4',
  616.                             'overlay_color'     => '#444444',
  617.                             'overlay_text_color'    => '#ffffff',
  618.  
  619.                                 //  added for shortcode handler html output
  620.                             'attachment_id'     => '',
  621.                             'src_original'      => '',          //  save original source in case shortcode was called directly and ID was added to source
  622.                             'img_h'             => '',
  623.                             'img_w'             => '',
  624.                             'copyright_text'    => ''
  625.                         );
  626.  
  627.             $default = $this->sync_sc_defaults_array( $default, 'no_modal_item', 'no_content' );
  628.  
  629.             $locked = array();
  630.             Avia_Element_Templates()->set_locked_attributes( $atts, $this, $shortcodename, $default, $locked, $content );
  631.             Avia_Element_Templates()->add_template_class( $meta, $atts, $default );
  632.  
  633.             $atts = shortcode_atts( $default, $atts, $this->config['shortcode'] );
  634.  
  635.             //  @since 4.8.6.3
  636.             if( ! empty( $atts['image_size'] ) )
  637.             {
  638.                 if( 'no scaling' == $atts['image_size'] )
  639.                 {
  640.                     $atts['image_size'] = 'full';
  641.                 }
  642.  
  643.                 $atts['attachment_size'] = $atts['image_size'];
  644.             }
  645.  
  646.             //  save original value for shortcode handler
  647.             $atts['src_original'] = $atts['src'];
  648.  
  649.             if( ! empty( $atts['attachment'] ) )
  650.             {
  651.                 /**
  652.                  * Allows e.g. WPML to reroute to translated image
  653.                  */
  654.                 $posts = get_posts( array(
  655.                                         'include'           => $atts['attachment'],
  656.                                         'post_status'       => 'inherit',
  657.                                         'post_type'         => 'attachment',
  658.                                         'post_mime_type'    => 'image',
  659.                                         'order'             => 'ASC',
  660.                                         'orderby'           => 'post__in'
  661.                                     )
  662.                                 );
  663.  
  664.                 if( is_array( $posts ) && ! empty( $posts ) )
  665.                 {
  666.                     $attachment_entry = $posts[0];
  667.                     $atts['attachment_id'] = $attachment_entry->ID;
  668.  
  669.                     if( ! empty( $atts['alt_attr'] ) )
  670.                     {
  671.                         $alt = $atts['alt_attr'];
  672.                     }
  673.                     else
  674.                     {
  675.                         $alt = get_post_meta( $attachment_entry->ID, '_wp_attachment_image_alt', true );
  676.                     }
  677.  
  678.                     $atts['alt_attr'] = ! empty( $alt ) ? esc_attr( trim( $alt ) ) : '';
  679.  
  680.                     if( ! empty( $atts['title_attr'] ) )
  681.                     {
  682.                         $title = $atts['title_attr'];
  683.                     }
  684.                     else
  685.                     {
  686.                         $title = $attachment_entry->post_title;
  687.                     }
  688.  
  689.                     $atts['title_attr'] = ! empty( $title ) ? esc_attr( trim( $title ) ) : '';
  690.  
  691.                     if( $atts['copyright'] !== '')
  692.                     {
  693.                         $copyright_text = get_post_meta( $attachment_entry->ID, '_avia_attachment_copyright', true );
  694.  
  695.                         /**
  696.                          * Allow to filter the copyright text
  697.                          *
  698.                          * @since 4.7.4.1
  699.                          * @param string $copyright_text
  700.                          * @param string $shortcodename         context calling the filter
  701.                          * @param int $attachment_entry->ID
  702.                          * @return string
  703.                          */
  704.                         $atts['copyright_text'] = apply_filters( 'avf_attachment_copyright_text', $copyright_text, $shortcodename, $attachment_entry->ID );
  705.                     }
  706.  
  707.                     if( ! empty( $atts['attachment_size'] ) )
  708.                     {
  709.                         $src = wp_get_attachment_image_src( $attachment_entry->ID, $atts['attachment_size'] );
  710.  
  711.                         $atts['img_h'] = ! empty( $src[2] ) ? $src[2] : '';
  712.                         $atts['img_w'] = ! empty( $src[1] ) ? $src[1] : '';
  713.                         $atts['src'] = ! empty( $src[0] ) ? $src[0] : '';
  714.                     }
  715.                 }
  716.             }
  717.             else
  718.             {
  719.                 $atts['attachment'] = false;
  720.             }
  721.  
  722.             if( empty( $atts['src'] ) )
  723.             {
  724.                 $result['default'] = $default;
  725.                 $result['atts'] = $atts;
  726.                 $result['content'] = $content;
  727.  
  728.                 return $result;
  729.             }
  730.  
  731.  
  732.             $element_styling->create_callback_styles( $atts );
  733.  
  734.             if( is_numeric( $atts['src'] ) )
  735.             {
  736.                 $classes = array(
  737.                             'avia_image',
  738.                             $element_id
  739.                     );
  740.             }
  741.             else
  742.             {
  743.                 $classes = array(
  744.                             'avia-image-container',
  745.                             $element_id
  746.                     );
  747.             }
  748.  
  749.             $classes[] = "av-styling-{$atts['styling']}";
  750.  
  751.             if( ! empty( $atts['hover'] ) )
  752.             {
  753.                 $classes[] = $atts['hover'];
  754.             }
  755.  
  756.             if( ! in_array( $atts['animation'], array( 'no-animation', '' ) ) )
  757.             {
  758.                 if( false !== strpos( $atts['animation'], 'curtain-reveal-' ) )
  759.                 {
  760.                     $classes_curtain = array(
  761.                                 'avia-curtain-reveal-overlay',
  762.                                 'av-animated-when-visible-95',
  763.                                 'animate-all-devices',
  764.                                 $atts['animation']
  765.                             );
  766.  
  767.                     //  animate in preview window
  768.                     if( is_admin() )
  769.                     {
  770.                         $classes_curtain[] = 'avia-animate-admin-preview';
  771.                     }
  772.  
  773.                     $element_styling->add_classes( 'curtain', $classes_curtain );
  774.                     $element_styling->add_callback_styles( 'curtain', array( 'animation' ) );
  775.                 }
  776.                 else
  777.                 {
  778.                     $classes[] = 'avia_animated_image';
  779.                     $classes[] = 'av-animated-when-visible-95';
  780. //                  $classes[] = 'animate-all-devices';
  781.                     $classes[] = $atts['animation'];
  782.  
  783.                     if( is_admin() )
  784.                     {
  785.                         $classes[] = 'avia-animate-admin-preview';
  786.  
  787.                         $element_styling->add_callback_styles( 'container', array( 'animation' ) );
  788.                     }
  789.                     else
  790.                     {
  791.                         $element_styling->add_callback_styles( 'container-animation', array( 'animation' ) );
  792.                     }
  793.                 }
  794.             }
  795.  
  796.             $element_styling->add_classes( 'container', $classes );
  797.             $element_styling->add_classes( 'container', $this->class_by_arguments( 'align', $atts, true, 'array' ) );
  798.             $element_styling->add_classes_from_array( 'container', $meta, 'el_class' );
  799.             $element_styling->add_responsive_classes( 'container', 'hide_element', $atts );
  800.  
  801.             if( $element_styling->add_responsive_styles( 'container', 'css_position', $atts, $this ) > 0 )
  802.             {
  803.                 $element_styling->add_classes( 'container', array( 'av-custom-positioned' ) );
  804.             }
  805.  
  806.             if( $element_styling->add_responsive_styles( 'container-inner', 'transform', $atts, $this ) > 0 )
  807.             {
  808.                 $element_styling->add_classes( 'container', array( 'av-custom-transform' ) );
  809.             }
  810.  
  811.             if( $element_styling->add_callback_data_attributes( 'container', array ( 'parallax' ) ) > 0 )
  812.             {
  813.                 $element_styling->add_data_attributes( 'container', array(
  814.                                                             'parallax-container'    => ".{$element_id}",
  815.                                                             'parallax-selector'     => ".avia-image-container-inner"
  816.                                                         ) );
  817.                 $element_styling->add_classes( 'container', 'av-parallax-object' );
  818.             }
  819.  
  820.             if( ! is_numeric( $atts['src'] ) )
  821.             {
  822.                 $element_styling->add_styles( 'container-overlay', array( 'color' => $atts['overlay_text_color'] ) );
  823.  
  824.                 if( ! empty( $atts['font_size'] ) )
  825.                 {
  826.                     $element_styling->add_styles( 'container-overlay', array( 'font-size' => $atts['font_size'] . 'px' ) );
  827.                 }
  828.  
  829.                 if( $atts['caption'] == 'yes' )
  830.                 {
  831.                     $element_styling->add_styles( 'container-caption', array( 'opacity' => $atts['overlay_opacity'] ) );
  832.                     $element_styling->add_styles( 'container-caption', array( 'background-color' => $atts['overlay_color'] ) );
  833.  
  834.                     $element_styling->add_classes( 'container', 'noHover' );
  835.  
  836.                     if( empty( $atts['appearance'] ) )
  837.                     {
  838.                         $atts['appearance'] = 'hover-deactivate';
  839.                     }
  840.  
  841.                     $element_styling->add_classes( 'container', "av-overlay-{$atts['appearance']}" );
  842.                 }
  843.  
  844.                 if( ! empty( $atts['copyright_text'] ) )
  845.                 {
  846.                     $element_styling->add_classes( 'container', 'av-has-copyright' );
  847.  
  848.                     if( ! empty( $atts['copyright'] ) )
  849.                     {
  850.                         $element_styling->add_classes( 'container', "av-copyright-{$atts['copyright']}" );
  851.                     }
  852.                 }
  853.  
  854.                 if( 'none' == $atts['box_shadow'] )
  855.                 {
  856.                     $element_styling->add_callback_styles( 'container-img', array( 'box_shadow' ) );
  857.                 }
  858.                 else if( '' != $atts['box_shadow'] )
  859.                 {
  860.                     $classes = array( 'av-img-box-shadow' );
  861.  
  862.                     //  animated box shadow only when curtain reveal - this is a default behaviour
  863.                     if( false !== strpos( $atts['animation'], 'curtain-reveal-' ) )
  864.                     {
  865.                         $classes[] = 'av-box-shadow-auto-animated';
  866.  
  867.                         $duration = ! empty( $atts['animation_duration'] ) ? $atts['animation_duration'] : 4;
  868.                         $delay_rule = $element_styling->animation_delay_rules( $duration );
  869.  
  870.                         if( is_admin() )
  871.                         {
  872.                             $element_styling->add_classes( 'container-img', array( 'avia-animate-admin-preview', 'av-animated-generic' ) );
  873.                             $element_styling->add_callback_styles( 'shadow-admin-animated', array( 'box_shadow_animated' ) );
  874.                             $element_styling->add_styles( 'shadow-admin-animated', $delay_rule );
  875.                         }
  876.                         else
  877.                         {
  878.                             $element_styling->add_classes( 'container-img', array( 'shadow-animated', 'av-animated-when-visible-95', 'animate-all-devices' ) );
  879.                             $element_styling->add_callback_styles( 'shadow-front-animated', array( 'box_shadow_animated' ) );
  880.                             $element_styling->add_styles( 'shadow-front-animated', $delay_rule );
  881.                         }
  882.                     }
  883.                     else
  884.                     {
  885.                         $classes[] = 'av-box-shadow-not-animated';
  886.  
  887.                         $element_styling->add_classes( 'container-img', 'shadow-not-animated' );
  888.                         $element_styling->add_callback_styles( 'container-img', array( 'box_shadow_not_animated' ) );
  889.                     }
  890.  
  891.                     $element_styling->add_classes( 'container', $classes );
  892.                 }
  893.  
  894.                 $selectors = array(
  895.                             'container'                 => ".avia-image-container.{$element_id}",
  896.                             'container-inner'           => ".avia-image-container.{$element_id} .avia-image-container-inner",
  897.                             'container-animation'       => ".avia_transform .avia-image-container.{$element_id}",
  898.                             'container-img'             => ".avia-image-container.{$element_id} img.avia_image",
  899.                             'container-caption'         => ".avia-image-container.{$element_id} .av-caption-image-overlay-bg",
  900.                             'container-overlay'         => ".avia-image-container.{$element_id} .av-image-caption-overlay-center",
  901.                             'curtain'                   => ".avia-image-container.{$element_id} .avia-curtain-reveal-overlay",
  902.                                     //  animated box shadow
  903.                             'shadow-admin-animated'     => ".avia-image-container.{$element_id} img.avia_image.avia-animate-admin-preview.av-animated-generic",
  904.                             'shadow-front-animated'     => ".avia-image-container.{$element_id} img.avia_image.avia_start_delayed_animation.shadow-animated",
  905.                         );
  906.  
  907.                 $element_styling->add_selectors( $selectors );
  908.             }
  909.  
  910.             $result['default'] = $default;
  911.             $result['atts'] = $atts;
  912.             $result['content'] = $content;
  913.             $result['element_styling'] = $element_styling;
  914.  
  915.             return $result;
  916.         }
  917.  
  918.         /**
  919.          * Frontend Shortcode Handler
  920.          *
  921.          * @param array $atts array of attributes
  922.          * @param string $content text within enclosing form of shortcode element
  923.          * @param string $shortcodename the shortcode found, when == callback name
  924.          * @return string $output returns the modified html string
  925.          */
  926.         function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' )
  927.         {
  928.             $result = $this->get_element_styles( compact( array( 'atts', 'content', 'shortcodename', 'meta' ) ) );
  929.  
  930.             extract( $result );
  931.  
  932.             if( empty( $atts['src'] ) )
  933.             {
  934.                 return '';
  935.             }
  936.  
  937.             if( 'disabled' == $atts['img_scrset'] )
  938.             {
  939.                 Av_Responsive_Images()->force_disable( 'disabled' );
  940.             }
  941.  
  942.             extract( $atts );
  943.  
  944.             $output = '';
  945.  
  946.             if( is_numeric( $src_original ) )
  947.             {
  948.                 $img_atts = array(
  949.                             'class' => $element_styling->get_class_string( 'container' )
  950.                         );
  951.  
  952.                 if( ! empty( $img_h ) )
  953.                 {
  954.                     $img_atts['height'] = $img_h;
  955.                 }
  956.                 if( ! empty( $img_w ) )
  957.                 {
  958.                     $img_atts['width'] = $img_w;
  959.                 }
  960.  
  961.                 if( $lazy_loading != 'enabled' )
  962.                 {
  963.                     Av_Responsive_Images()->add_attachment_id_to_not_lazy_loading( $src );
  964.                 }
  965.  
  966.                 $output .= wp_get_attachment_image( $src, 'large', false, $img_atts );
  967.             }
  968.             else
  969.             {
  970.                 $link = AviaHelper::get_url( $link, $attachment, true );
  971.                 $blank = AviaHelper::get_link_target( $target );
  972.                 $content = ! empty( $content ) ? $content : get_the_content(null, false, $attachment_id);
  973.  
  974.                 $overlay = '';
  975.  
  976.                 if( $caption == 'yes' )
  977.                 {
  978.                     $overlay  = '<div class="av-image-caption-overlay">';
  979.                     $overlay .=     '<div class="av-caption-image-overlay-bg"></div>';
  980.                     $overlay .=     '<div class="av-image-caption-overlay-position">';
  981.                     $overlay .=         '<div class="av-image-caption-overlay-center">';
  982.                     $overlay .=             ShortcodeHelper::avia_apply_autop( ShortcodeHelper::avia_remove_autop( $content ) );
  983.                     $overlay .=         '</div>';
  984.                     $overlay .=     '</div>';
  985.                     $overlay .= '</div>';
  986.                 }
  987.  
  988.                 $copyright_tag = '';
  989.  
  990.                 if( ! empty( $copyright_text ) )
  991.                 {
  992.                     /**
  993.                      * Filter Copyright text e.g. to allow HTML tage
  994.                      *
  995.                      * @since 4.8.6.3
  996.                      * @param string $copyright_text_escaped
  997.                      * @param string $copyright_text
  998.                      * @return string
  999.                      */
  1000.                     $copyright_tag = '<small class="avia-copyright">' . apply_filters( 'avf_alb_image_copyright_text', esc_html( $copyright_text ), $copyright_text ) . '</small>';
  1001.                 }
  1002.  
  1003.                 $markup_url = avia_markup_helper( array( 'context' => 'image_url', 'echo' => false, 'custom_markup' => $meta['custom_markup'] ) );
  1004.                 $markup_img = avia_markup_helper( array( 'context' => 'image', 'echo' => false, 'custom_markup' => $meta['custom_markup'] ) );
  1005.  
  1006.                 /**
  1007.                  *
  1008.                  * @since 4.8.9 we add height and width
  1009.                  */
  1010.                 $hw = '';
  1011.                 if( ! empty( $img_h ) )
  1012.                 {
  1013.                     $hw .= ' height="' . $img_h . '"';
  1014.                 }
  1015.  
  1016.                 if( ! empty( $img_w ) )
  1017.                 {
  1018.                     $hw .= ' width="' . $img_w . '"';
  1019.                 }
  1020.  
  1021.                 $img_class = $element_styling->get_class_string( 'container-img' );
  1022.  
  1023.                 $img_tag = "<img class='avia_image {$img_class}' src='{$src}' alt='{$alt_attr}' title='{$title_attr}' {$hw} {$markup_url} />";
  1024.                 $img_tag = Av_Responsive_Images()->prepare_single_image( $img_tag, $attachment_id, $lazy_loading );
  1025.  
  1026.                 $curtain_reveal_overlay = '';
  1027.  
  1028.                 if( false !== strpos( $animation, 'curtain-reveal-' ) )
  1029.                 {
  1030.                     $curtain_class = $element_styling->get_class_string( 'curtain' );
  1031.                     $curtain_reveal_overlay = "<div class='{$curtain_class}'></div>";
  1032.                 }
  1033.  
  1034.                 $style_tag = $element_styling->get_style_tag( $element_id );
  1035.                 $container_class = $element_styling->get_class_string( 'container' );
  1036.                 $container_data = $element_styling->get_data_attributes_json_string( 'container', 'parallax' );
  1037.  
  1038.                 $output .= $style_tag;
  1039.                 $output .= "<div {$meta['custom_el_id']} class='{$container_class}' {$container_data} {$markup_img}>";
  1040.                 $output .=      '<div class="avia-image-container-inner">';
  1041.                 $output .=          '<div class="avia-image-overlay-wrap">';
  1042.                 $output .=          $curtain_reveal_overlay;
  1043.  
  1044.                 if( ! empty( $link ) )
  1045.                 {
  1046.                     $lightbox_attr = Av_Responsive_Images()->html_attr_image_src( $link, false );
  1047.  
  1048.                     $output .=          "<a {$lightbox_attr} class='avia_image' {$blank}>{$overlay}{$img_tag}</a>";
  1049.                 }
  1050.                 else
  1051.                 {
  1052.                     $output .=          "{$overlay}{$img_tag}";
  1053.                 }
  1054.  
  1055.                 $output .=          '</div>';
  1056.                 $output .=      $copyright_tag;
  1057.  
  1058.                 $output .=      '</div>';
  1059.                 $output .= '</div>';
  1060.             }
  1061.  
  1062.             $html = Av_Responsive_Images()->make_content_images_responsive( $output );
  1063.  
  1064.             Av_Responsive_Images()->force_disable( 'reset' );
  1065.  
  1066.             return $html;
  1067.         }
  1068.  
  1069.     }
  1070. }
  1071.  
  1072.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement