Advertisement
Guest User

galcontenturl

a guest
Feb 10th, 2022
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 23.60 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Gallery
  4.  *
  5.  * Shortcode that allows to create a gallery based on images selected from the media library
  6.  */
  7. if( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  8.  
  9.  
  10. if ( ! class_exists( 'avia_sc_gallery' ) )
  11. {
  12.     class avia_sc_gallery extends aviaShortcodeTemplate
  13.     {
  14.         /**
  15.          *
  16.          * @var int
  17.          */
  18.         static protected $gallery = 0;
  19.  
  20.         /**
  21.          * Array of WP_Post attachments
  22.          *
  23.          * @since 4.8.4
  24.          * @var array
  25.          */
  26.         protected $attachments;
  27.  
  28.         /**
  29.          * @since 4.8.4
  30.          * @param AviaBuilder $builder
  31.          */
  32.         public function __construct(AviaBuilder $builder)
  33.         {
  34.             parent::__construct($builder);
  35.  
  36.             $this->attachments = array();
  37.         }
  38.  
  39.         /**
  40.          * @since 4.8.4
  41.          */
  42.         public function __destruct()
  43.         {
  44.             parent::__destruct();
  45.  
  46.             unset( $this->attachments );
  47.         }
  48.  
  49.         /**
  50.          * Create the config array for the shortcode button
  51.          */
  52.         function shortcode_insert_button()
  53.         {
  54.             $this->config['version']        = '1.0';
  55.             $this->config['self_closing']   = 'yes';
  56.             $this->config['base_element']   = 'yes';
  57.  
  58.             $this->config['name']           = __( 'Gallery', 'avia_framework' );
  59.             $this->config['tab']            = __( 'Media Elements', 'avia_framework' );
  60.             $this->config['icon']           = AviaBuilder::$path['imagesURL'] . 'sc-gallery.png';
  61.             $this->config['order']          = 6;
  62.             $this->config['target']         = 'avia-target-insert';
  63.             $this->config['shortcode']      = 'av_gallery';
  64.             $this->config['modal_data']     = array( 'modal_class' => 'mediumscreen' );
  65.             $this->config['tooltip']        = __( 'Creates a custom gallery', 'avia_framework' );
  66.             $this->config['preview']        = 1;
  67.             $this->config['disabling_allowed'] = 'manually'; //only allowed manually since the default [gallery shortcode] is also affected
  68.             $this->config['id_name']        = 'id';
  69.             $this->config['id_show']        = 'yes';
  70.             $this->config['alb_desc_id']    = 'alb_description';
  71.         }
  72.  
  73.         function extra_assets()
  74.         {
  75.             //load css
  76.             wp_enqueue_style( 'avia-module-gallery', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/gallery/gallery.css', array( 'avia-layout' ), false );
  77.  
  78.             wp_enqueue_script( 'avia-module-gallery', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/gallery/gallery.js', array( 'avia-shortcodes' ), false, true );
  79.         }
  80.  
  81.         /**
  82.          * Popup Elements
  83.          *
  84.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  85.          * opens a modal window that allows to edit the element properties
  86.          *
  87.          * @return void
  88.          */
  89.         function popup_elements()
  90.         {
  91.             $this->elements = array(
  92.  
  93.                 array(
  94.                         'type'  => 'tab_container',
  95.                         'nodescription' => true
  96.                     ),
  97.  
  98.                 array(
  99.                         'type'  => 'tab',
  100.                         'name'  => __( 'Content', 'avia_framework' ),
  101.                         'nodescription' => true
  102.                     ),
  103.  
  104.                     array(
  105.                                 'type'          => 'template',
  106.                                 'template_id'   => $this->popup_key( 'content_entries' )
  107.                             ),
  108.  
  109.                 array(
  110.                         'type'  => 'tab_close',
  111.                         'nodescription' => true
  112.                     ),
  113.  
  114.                 array(
  115.                         'type'  => 'tab',
  116.                         'name'  => __( 'Styling', 'avia_framework' ),
  117.                         'nodescription' => true
  118.                     ),
  119.  
  120.                     array(
  121.                             'type'          => 'template',
  122.                             'template_id'   => $this->popup_key( 'styling_gallery' )
  123.                         ),
  124.  
  125.                 array(
  126.                         'type'  => 'tab_close',
  127.                         'nodescription' => true
  128.                     ),
  129.  
  130.                 array(
  131.                         'type'  => 'tab',
  132.                         'name'  => __( 'Advanced', 'avia_framework' ),
  133.                         'nodescription' => true
  134.                     ),
  135.  
  136.                     array(
  137.                             'type'  => 'toggle_container',
  138.                             'nodescription' => true
  139.                         ),
  140.  
  141.                         array(
  142.                                 'type'          => 'template',
  143.                                 'template_id'   => $this->popup_key( 'advanced_link' )
  144.                             ),
  145.  
  146.                         array(
  147.                                 'type'          => 'template',
  148.                                 'template_id'   => $this->popup_key( 'advanced_animation' )
  149.                             ),
  150.  
  151.                         array(
  152.                                 'type'          => 'template',
  153.                                 'template_id'   => 'lazy_loading_toggle',
  154.                                 'id'            => 'html_lazy_loading',
  155.                                 'lockable'      => true
  156.                             ),
  157.  
  158.                         array(
  159.                                 'type'          => 'template',
  160.                                 'template_id'   => 'screen_options_toggle',
  161.                                 'lockable'      => true
  162.                             ),
  163.  
  164.                         array(
  165.                                 'type'          => 'template',
  166.                                 'template_id'   => 'developer_options_toggle',
  167.                                 'args'          => array( 'sc' => $this )
  168.                             ),
  169.  
  170.                     array(
  171.                             'type'  => 'toggle_container_close',
  172.                             'nodescription' => true
  173.                         ),
  174.  
  175.                 array(
  176.                         'type'  => 'tab_close',
  177.                         'nodescription' => true
  178.                     ),
  179.  
  180.                 array(
  181.                         'type'          => 'template',
  182.                         'template_id'   => 'element_template_selection_tab',
  183.                         'args'          => array( 'sc' => $this )
  184.                     ),
  185.  
  186.                 array(
  187.                         'type'  => 'tab_container_close',
  188.                         'nodescription' => true
  189.                     )
  190.  
  191.                 );
  192.  
  193.         }
  194.  
  195.         /**
  196.          * Create and register templates for easier maintainance
  197.          *
  198.          * @since 4.6.4
  199.          */
  200.         protected function register_dynamic_templates()
  201.         {
  202.  
  203.             /**
  204.              * Content Tab
  205.              * ===========
  206.              */
  207.  
  208.             $c = array(
  209.                         array(
  210.                             'name'      => __( 'Edit Gallery', 'avia_framework' ),
  211.                             'desc'      => __( 'Create a new Gallery by selecting existing or uploading new images', 'avia_framework' ),
  212.                             'id'        => 'ids',
  213.                             'type'      => 'gallery',
  214.                             'title'     => __( 'Add/Edit Gallery', 'avia_framework' ),
  215.                             'button'    => __( 'Insert Images', 'avia_framework' ),
  216.                             'std'       => '',
  217.                             'modal_class' => 'av-show-image-custom-link',
  218.                             'lockable'  => true
  219.                         )
  220.                 );
  221.  
  222.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_entries' ), $c );
  223.  
  224.             /**
  225.              * Styling Tab
  226.              * ===========
  227.              */
  228.  
  229.             $c = array(
  230.                         array(
  231.                             'name'  => __( 'Gallery Style', 'avia_framework' ),
  232.                             'desc'  => __( 'Choose the layout of your Gallery', 'avia_framework' ),
  233.                             'id'    => 'style',
  234.                             'type'  => 'select',
  235.                             'std'   => 'thumbnails',
  236.                             'lockable'  => true,
  237.                             'subtype'   => array(
  238.                                                 __( 'Small Thumbnails', 'avia_framework' )                  => 'thumbnails',
  239.                                                 __( 'Big image with thumbnails below', 'avia_framework' )   => 'big_thumb',
  240.                                                 __( 'Big image only, other images can be accessed via lightbox', 'avia_framework' ) => 'big_thumb lightbox_gallery',
  241.                                             )
  242.                         ),
  243.  
  244.                         array(
  245.                             'name'  => __( 'Gallery Big Preview Image Size', 'avia_framework' ),
  246.                             'desc'  => __( 'Choose image size for the Big Preview Image', 'avia_framework' ),
  247.                             'id'    => 'preview_size',
  248.                             'type'  => 'select',
  249.                             'std'   => 'portfolio',
  250.                             'lockable'  => true,
  251.                             'required'  => array( 'style', 'contains', 'big_thumb' ),
  252.                             'subtype'   => AviaHelper::get_registered_image_sizes( array( 'logo' ) )
  253.                         ),
  254.  
  255.                         array(
  256.                             'name'  => __( 'Force same size for all big preview images?', 'avia_framework' ),
  257.                             'desc'  => __( 'Depending on the size you selected above, preview images might differ in size. Should the theme force them to display at exactly the same size?', 'avia_framework' ),
  258.                             'id'    => 'crop_big_preview_thumbnail',
  259.                             'type'  => 'select',
  260.                             'std'   => 'avia-gallery-big-crop-thumb',
  261.                             'lockable'  => true,
  262.                             'required'  => array( 'style', 'equals', 'big_thumb' ),
  263.                             'subtype'   => array(
  264.                                                 __( 'Yes, force same size on all Big Preview images, even if they use a different aspect ratio', 'avia_framework' ) => 'avia-gallery-big-crop-thumb',
  265.                                                 __( 'No, do not force the same size', 'avia_framework' ) => 'avia-gallery-big-no-crop-thumb'
  266.                                             )
  267.                         ),
  268.  
  269.                         array(
  270.                             'name'  => __( 'Gallery Preview Image Size', 'avia_framework' ),
  271.                             'desc'  => __( 'Choose image size for the small preview thumbnails', 'avia_framework' ),
  272.                             'id'    => 'thumb_size',
  273.                             'type'  => 'select',
  274.                             'std'   => 'portfolio',
  275.                             'lockable'  => true,
  276.                             'required'  => array( 'style', 'not', 'big_thumb lightbox_gallery' ),
  277.                             'subtype'   =>  AviaHelper::get_registered_image_sizes( array( 'logo' ) )
  278.                         ),
  279.  
  280.                         array(
  281.                             'name'  => __('Thumbnail Columns', 'avia_framework' ),
  282.                             'desc'  => __('Choose the column count of your Gallery', 'avia_framework' ),
  283.                             'id'    => 'columns',
  284.                             'type'  => 'select',
  285.                             'std'   => '5',
  286.                             'lockable'  => true,
  287.                             'required'  => array( 'style', 'not', 'big_thumb lightbox_gallery' ),
  288.                             'subtype'   => AviaHtmlHelper::number_array( 1, 12, 1 )
  289.                         )
  290.  
  291.                 );
  292.  
  293.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_gallery' ), $c );
  294.  
  295.             /**
  296.              * Advanced Tab
  297.              * ============
  298.              */
  299.  
  300.             $c = array(
  301.                         array(
  302.                             'name'  => __( 'Image Link', 'avia_framework' ),
  303.                             'desc'  => __( 'By default images link to a larger image version in a lightbox. You can change this here. A custom link can be added when editing the images in the gallery.', 'avia_framework' ),
  304.                             'id'    => 'imagelink',
  305.                             'type'  => 'select',
  306.                             'std'   => 'lightbox',
  307.                             'lockable'  => true,
  308.                             'required'  => array( 'style', 'not', 'big_thumb lightbox_gallery' ),
  309.                             'subtype'   => array(
  310.                                                 __( 'Lightbox linking active', 'avia_framework' )                       => 'lightbox',
  311.                                                 __( 'Use custom link (fallback is image link)', 'avia_framework' )      => 'custom_link',
  312.                                                 __( 'Open the images in the browser window', 'avia_framework' )         => 'aviaopeninbrowser noLightbox',
  313.                                                 __( 'Open the images in a new browser window/tab', 'avia_framework' )   => 'aviaopeninbrowser aviablank noLightbox',
  314.                                                 __( 'No, don\'t add a link to the images at all', 'avia_framework' )    => 'avianolink noLightbox'
  315.                                             )
  316.                         ),
  317.  
  318.                         array(
  319.                             'name'      => __( 'Custom link destination', 'avia_framework' ),
  320.                             'desc'      => __( 'Select where an existing custom link should be opened.', 'avia_framework' ),
  321.                             'id'        => 'link_dest',
  322.                             'type'      => 'select',
  323.                             'std'       => '',
  324.                             'lockable'  => true,
  325.                             'required'  => array( 'imagelink', 'equals', 'custom_link' ),
  326.                             'subtype'   => array(
  327.                                                 __( 'Open in same window', 'avia_framework' )       => '',
  328.                                                 __( 'Open in a new window', 'avia_framework' )      => '_blank'
  329.                                             )
  330.                         ),
  331.  
  332.                         array(
  333.                             'name'      => __( 'Lightbox image description text', 'avia_framework' ),
  334.                             'desc'      => __( 'Select which text defined in the media gallery is displayed below the lightbox image.', 'avia_framework' ),
  335.                             'id'        => 'lightbox_text',
  336.                             'type'      => 'select',
  337.                             'std'       => 'caption',
  338.                             'lockable'  => true,
  339.                             'required'  => array( 'imagelink', 'equals', 'lightbox' ),
  340.                             'subtype'   => array(
  341.                                                 __( 'No text', 'avia_framework' )                                       => 'no_text',
  342.                                                 __( 'Image title', 'avia_framework' )                                   => '',
  343.                                                 __ ('Image description (or image title if empty)', 'avia_framework' )   => 'description',
  344.                                                 __( 'Image caption (or image title if empty)', 'avia_framework' )       => 'caption'
  345.                                             )
  346.                         )
  347.  
  348.                 );
  349.  
  350.             $template = array(
  351.                             array(
  352.                                 'type'          => 'template',
  353.                                 'template_id'   => 'toggle',
  354.                                 'title'         => __( 'Link Settings', 'avia_framework' ),
  355.                                 'content'       => $c
  356.                             ),
  357.                     );
  358.  
  359.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_link' ), $template );
  360.  
  361.             $c = array(
  362.                         array(
  363.                             'name'      => __( 'Thumbnail fade in effect', 'avia_framework' ),
  364.                             'desc'      => __( 'You can set when the gallery thumbnail animation starts', 'avia_framework' ),
  365.                             'id'        => 'lazyload',
  366.                             'type'      => 'select',
  367.                             'std'       => 'avia_lazyload',
  368.                             'lockable'  => true,
  369.                             'required'  => array( 'style', 'not', 'big_thumb lightbox_gallery' ),
  370.                             'subtype'   => array(
  371.                                                 __( 'Disable all animations', 'avia_framework' )                                => 'animations_off',
  372.                                                 __( 'Show the animation when user scrolls to the gallery', 'avia_framework' )   => 'avia_lazyload',
  373.                                                 __( 'Activate animation on page load (might be preferable on large galleries)', 'avia_framework' ) => 'deactivate_avia_lazyload'
  374.                                             )
  375.                         )
  376.                 );
  377.  
  378.             $template = array(
  379.                             array(
  380.                                 'type'          => 'template',
  381.                                 'template_id'   => 'toggle',
  382.                                 'title'         => __( 'Animation', 'avia_framework' ),
  383.                                 'content'       => $c
  384.                             ),
  385.                     );
  386.  
  387.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_animation' ), $template );
  388.  
  389.  
  390.         }
  391.  
  392.  
  393.         /**
  394.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  395.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  396.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  397.          *
  398.          *
  399.          * @param array $params this array holds the default values for $content and $args.
  400.          * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  401.          */
  402.         function editor_element( $params )
  403.         {
  404.             $params = parent::editor_element( $params );
  405.             $params['content'] = null; //remove to allow content elements
  406.  
  407.             return $params;
  408.         }
  409.  
  410.         /**
  411.          * Create custom stylings
  412.          *
  413.          * @since 4.8.4
  414.          * @param array $args
  415.          * @return array
  416.          */
  417.         protected function get_element_styles( array $args )
  418.         {
  419.             $result = parent::get_element_styles( $args );
  420.  
  421.             extract( $result );
  422.  
  423.             //  make sure to have a value - fallback situation only
  424.             if( empty( $atts['columns'] ) && isset( $atts['ids'] ) )
  425.             {
  426.                 $atts['columns'] = count( explode( ',', $atts['ids'] ) );
  427.                 if( $atts['columns'] == 0 )
  428.                 {
  429.                     $atts['columns'] = 5;
  430.                 }
  431.                 else if( $atts['columns'] > 10 )
  432.                 {
  433.                     $atts['columns'] = 10;
  434.                 }
  435.             }
  436.  
  437.  
  438.             $default = array(
  439.                         'order'         => 'ASC',
  440.                         'thumb_size'    => 'thumbnail',
  441.                         'size'          => '',
  442.                         'preview_size'  => 'portfolio',
  443.                         'ids'           => '',
  444.                         'imagelink'     => 'lightbox',
  445.                         'link_dest'     => '',
  446.                         'lightbox_text' => 'caption',
  447.                         'style'         => 'thumbnails',
  448.                         'columns'       => 5,
  449.                         'lazyload'      => 'avia_lazyload',
  450.                         'html_lazy_loading'             => 'disabled',
  451.                         'crop_big_preview_thumbnail'    => 'avia-gallery-big-crop-thumb',
  452.  
  453.                         'ajax_request'  => false
  454.                     );
  455.  
  456.             $default = $this->sync_sc_defaults_array( $default );
  457.  
  458.  
  459.             $locked = array();
  460.             Avia_Element_Templates()->set_locked_attributes( $atts, $this, $shortcodename, $default, $locked, $content );
  461.             Avia_Element_Templates()->add_template_class( $meta, $atts, $default );
  462.  
  463.             $atts = shortcode_atts( $default, $atts, $this->config['shortcode'] );
  464.  
  465.             $this->attachments = get_posts( array(
  466.                                     'include'       => $atts['ids'],
  467.                                     'post_status'   => 'inherit',
  468.                                     'post_type'     => 'attachment',
  469.                                     'post_mime_type' => 'image',
  470.                                     'order'         => $atts['order'],
  471.                                     'orderby'       => 'post__in'
  472.                                 )
  473.                         );
  474.  
  475.             if( empty( $this->attachments ) || ! is_array( $this->attachments ) )
  476.             {
  477.                 return $result;
  478.             }
  479.  
  480.             //compatibility mode for default wp galleries - used e.g. by post type gallery posts
  481.             if( ! empty( $atts['size'] ) )
  482.             {
  483.                 $atts['thumb_size'] = $atts['size'];
  484.             }
  485.  
  486.  
  487.             $classes = array(
  488.                         'avia-gallery',
  489.                         $element_id,
  490.                         'avia_animate_when_visible',
  491.                     );
  492.  
  493.             $element_styling->add_classes( 'container', $classes );
  494.             $element_styling->add_classes_from_array( 'container', $meta, 'el_class' );
  495.             $element_styling->add_responsive_classes( 'container', 'hide_element', $atts );
  496.  
  497.             if( 'big_thumb lightbox_gallery' == $atts['style']  )
  498.             {
  499.                 $atts['imagelink'] = 'lightbox';
  500.                 $element_styling->add_classes( 'big-thumb-link', 'lightbox' );
  501.                 $element_styling->add_classes( 'thumb-link', 'lightbox' );
  502.                 $element_styling->add_classes( 'container', array( 'av-hide-gallery-thumbs', 'deactivate_avia_lazyload' ) );
  503.  
  504.                 $atts['lazyload'] = 'deactivate_avia_lazyload';
  505.             }
  506.             else
  507.             {
  508.                 $element_styling->add_classes( 'big-thumb-link', $atts['imagelink'] );
  509.                 $element_styling->add_classes( 'thumb-link', $atts['imagelink'] );
  510.                 $element_styling->add_classes( 'container', $atts['lazyload'] );
  511.  
  512.                 if( 'custom_link' == $atts['imagelink'] )
  513.                 {
  514.                     $element_styling->add_classes( 'big-thumb-link', array( 'aviaopeninbrowser', 'noLightbox' ) );
  515.                     $element_styling->add_classes( 'thumb-link', 'lightbox' );
  516.  
  517.                     if( '_blank' == $atts['link_dest']  )
  518.                     {
  519.                         $element_styling->add_classes( 'big-thumb-link', 'aviablank' );
  520.                         $element_styling->add_classes( 'thumb-link', 'aviablank' );
  521.                     }
  522.                 }
  523.             }
  524.  
  525.             // animation
  526.             if( $atts['lazyload'] != 'animations_off' )
  527.             {
  528.                 $element_styling->add_classes( 'container', 'avia-gallery-animate' );
  529.             }
  530.  
  531.             $thumb_width = round( 100 / $atts['columns'], 4 );
  532.             $element_styling->add_styles( 'thumb-link', array( 'width' => $thumb_width . '%' ) );
  533.  
  534.  
  535.             $selectors = array(
  536.                         'container'     => ".avia-gallery.{$element_id}",
  537.                         'thumb-link'    => "#top .avia-gallery.{$element_id} .avia-gallery-thumb a"
  538.                     );
  539.  
  540.             $element_styling->add_selectors( $selectors );
  541.  
  542.  
  543.             $result['default'] = $default;
  544.             $result['atts'] = $atts;
  545.             $result['content'] = $content;
  546.             $result['meta'] = $meta;
  547.  
  548.             return $result;
  549.         }
  550.  
  551.         /**
  552.          * Frontend Shortcode Handler
  553.          *
  554.          * @param array $atts array of attributes
  555.          * @param string $content text within enclosing form of shortcode element
  556.          * @param string $shortcodename the shortcode found, when == callback name
  557.          * @return string $output returns the modified html string
  558.          */
  559.         function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' )
  560.         {
  561.             $result = $this->get_element_styles( compact( array( 'atts', 'content', 'shortcodename', 'meta' ) ) );
  562.  
  563.             extract( $result );
  564.             extract( $atts );
  565.  
  566.             if( empty( $this->attachments ) || ! is_array( $this->attachments ) )
  567.             {
  568.                 return '';
  569.             }
  570.  
  571.             if( 'disabled' == $atts['img_scrset'] )
  572.             {
  573.                 Av_Responsive_Images()->force_disable( 'disabled' );
  574.             }
  575.  
  576.             //  must be done here to avoid duplicate count on first page load building the CSS file
  577.             self::$gallery++;
  578.  
  579.             $rel = '';
  580.             if( 'big_thumb lightbox_gallery' != $style && 'custom_link' == $imagelink && '_blank' == $link_dest )
  581.             {
  582.                 $rel .= 'rel="noopener noreferrer" target="_blank"';
  583.             }
  584.  
  585.             $big_thumb = '';
  586.             $thumbs = '';
  587.             $counter = 0;
  588.  
  589.             /**
  590.              * @since 4.8.2
  591.              * @param string $image_size
  592.              * @param string $shortcode
  593.              * @param array $atts
  594.              * @param string $content
  595.              * @return string
  596.              */
  597.             $lightbox_img_size = apply_filters( 'avf_alb_lightbox_image_size', 'large', $this->config['shortcode'], $atts, $content );
  598.  
  599.             foreach( $this->attachments as $attachment )
  600.             {
  601.                 $lightbox_img_src = Av_Responsive_Images()->responsive_image_src( $attachment->ID, $lightbox_img_size );
  602.  
  603.                 if( false !== strpos( $imagelink, 'custom_link') )
  604.                 {
  605.                     $c_link = $custom_url = get_post_meta( $attachment->ID, 'av-custom-link', true );
  606.                     if( ! empty( $c_link ) )
  607.                     {
  608.                         $lightbox_img_src[0] = $c_link;
  609.                     }
  610.                 }
  611.  
  612.                 /**
  613.                  * Allows to add a custom link class.
  614.                  * To change the default lightbox image size use above filter avf_alb_lightbox_image_size (added 4.8.2).
  615.                  *
  616.                  * @since ????
  617.                  * @param array $link
  618.                  * @param WP_Post $attachment
  619.                  * @param array $atts
  620.                  * @param array $meta
  621.                  * @return array
  622.                  */
  623.                 $lightbox_img_src = apply_filters( 'avf_avia_builder_gallery_image_link', $lightbox_img_src, $attachment, $atts, $meta );
  624.  
  625.                 $custom_link_class = ! empty( $lightbox_img_src['custom_link_class'] ) ? $lightbox_img_src['custom_link_class'] : '';
  626.                 $class = $counter++ % $columns ? "class='$imagelink $custom_link_class'" : "class='first_thumb $imagelink $custom_link_class'";
  627.  
  628.                 $img = wp_get_attachment_image_src( $attachment->ID, $thumb_size );
  629.                 $prev = wp_get_attachment_image_src( $attachment->ID, $preview_size );
  630.  
  631.                 $caption = trim( $attachment->post_excerpt ) ? wptexturize( $attachment->post_excerpt ) : '';
  632.                 $tooltip = $caption ? "data-avia-tooltip='{$caption}'" : '';
  633.  
  634.                 $alt = get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true );
  635.                 $alt = ! empty( $alt ) ? esc_attr( $alt ) : '';
  636.  
  637.                 $title = trim( $attachment->post_title ) ? esc_attr( $attachment->post_title ) : '';
  638.                 $description = trim( $attachment->post_content ) ? esc_attr( $attachment->post_content ) : '';
  639.  
  640.                 $lightbox_title = $title;
  641.                 switch( $lightbox_text )
  642.                 {
  643.                     case 'caption':
  644.                         $lightbox_title = ( '' != $caption ) ? $caption : $title;
  645.                         break;
  646.                     case 'description':
  647.                         $lightbox_title = ( '' != $description ) ? $description : $title;
  648.                         break;
  649.                     case 'no_text':
  650.                         $lightbox_title = '';
  651.                 }
  652.  
  653.                 $markup_url = avia_markup_helper( array( 'context' => 'image_url', 'echo' => false, 'id' => $attachment->ID, 'custom_markup' => $meta['custom_markup'] ) );
  654.  
  655.                 if( strpos( $style, 'big_thumb' ) !== false && 1 == $counter )
  656.                 {
  657.                     $img_tag = "<img width='{$prev[1]}' height='{$prev[2]}' src='{$prev[0]}' title='{$title}' alt='{$alt}' />";
  658.                     $img_tag = Av_Responsive_Images()->prepare_single_image( $img_tag, $attachment->ID, $html_lazy_loading );
  659.                     $lightbox_attr = Av_Responsive_Images()->html_attr_image_src( $lightbox_img_src, false );
  660.  
  661.                     $big_thumb .= "<a class='avia-gallery-big fakeLightbox {$imagelink} {$crop_big_preview_thumbnail} {$custom_link_class}' {$lightbox_attr}  data-onclick='1' title='{$lightbox_title}' {$rel}>";
  662.                     $big_thumb .=       "<span class='avia-gallery-big-inner' {$markup_url}>";
  663.                     $big_thumb .=           $img_tag;
  664.  
  665.                     if( $caption )
  666.                     {
  667.                         $big_thumb .=       "<span class='avia-gallery-caption'>{$caption}</span>";
  668.                     }
  669.  
  670.                     $big_thumb .=       '</span>';
  671.                     $big_thumb .= '</a>';
  672.                 }
  673.  
  674.                 $img_tag = "<img {$tooltip} src='{$img[0]}' width='{$img[1]}' height='{$img[2]}'  title='{$title}' alt='{$alt}' />";
  675.                 $img_tag = Av_Responsive_Images()->prepare_single_image( $img_tag, $attachment->ID, $html_lazy_loading );
  676.                 $lightbox_attr = Av_Responsive_Images()->html_attr_image_src( $lightbox_img_src, false );
  677.  
  678.                 // @since 4.8.8.2 support for responsive images:  https://kriesi.at/support/topic/missing-scrset-in-alb-gallery/
  679.                 $prev_img_tag = "<img width='{$prev[1]}' height='{$prev[2]}' src='{$prev[0]}' title='{$title}' alt='{$alt}' />";
  680.                 $prev_img_tag = Av_Responsive_Images()->prepare_single_image( $prev_img_tag, $attachment->ID, 'enabled' );
  681.  
  682.                 $thumbs .= "<a {$lightbox_attr} data-rel='gallery-" . self::$gallery . "' data-prev-img='{$prev[0]}' {$class} data-onclick='{$counter}' title='{$lightbox_title}' {$markup_url} {$rel}>";
  683.                 $thumbs .=      $img_tag;
  684.                 $thumbs .=      "<div class='big-prev-fake'>{$prev_img_tag}</div>";
  685.                 $thumbs .= '</a>';
  686.             }
  687.  
  688.             $markup_gallery = avia_markup_helper( array( 'context' => 'image', 'echo' => false, 'custom_markup' => $meta['custom_markup'] ) );
  689.  
  690.  
  691.             /**
  692.              * https://kriesi.at/support/topic/contenturl-or-url-missing-from-rich-snippets/
  693.              *
  694.              * @since 4.8.9.1
  695.              */
  696.             $post_link = trim( get_the_permalink( get_the_ID() ) );
  697.             $markup_meta = '<meta itemprop="contentURL" content="' . esc_attr( $post_link ) . '" />';
  698.  
  699.             $style_tag = $element_styling->get_style_tag( $element_id );
  700.             $container_class = $element_styling->get_class_string( 'container' );
  701.  
  702.             $output  = '';
  703.             $output .= $style_tag;
  704.             $output .= "<div {$meta['custom_el_id']} class='{$container_class} avia-gallery-" . self::$gallery . "' {$markup_gallery}>";
  705.             $output .=      $markup_meta;
  706.             $output .=      $big_thumb;
  707.             $output .=      "<div class='avia-gallery-thumb'>{$thumbs}</div>";
  708.             $output .= '</div>';
  709.  
  710.             $html = Av_Responsive_Images()->make_content_images_responsive( $output );
  711.  
  712.             Av_Responsive_Images()->force_disable( 'reset' );
  713.  
  714.             return $html;
  715.         }
  716.  
  717.     }
  718. }
  719.  
  720.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement