Advertisement
Guenni007

masonry_gallery

Sep 15th, 2023 (edited)
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 27.13 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Masonry Gallery
  4.  * new subtype on lines 382ff
  5.  * Shortcode that allows to display a fullwidth masonry of any post type
  6.  */
  7. if( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  8.  
  9.  
  10. if( ! class_exists( 'avia_sc_masonry_gallery', false ) )
  11. {
  12.     class avia_sc_masonry_gallery extends aviaShortcodeTemplate
  13.     {
  14.         /**
  15.          * @since 4.5.7.2
  16.          * @var int
  17.          */
  18.         static protected $gallery_count = 0;
  19.  
  20.         /**
  21.          * Save avia_masonry objects for reuse. As we need to access the same object when creating the post css file in header,
  22.          * create the styles and HTML creation. Makes sure to get the same id.
  23.          *
  24.          *          $element_id => avia_masonry
  25.          *
  26.          * @since 4.8.4
  27.          * @var array
  28.          */
  29.         protected $obj_masonry = array();
  30.  
  31.         /**
  32.          * @since 4.8.9
  33.          * @param AviaBuilder $builder
  34.          */
  35.         public function __construct( AviaBuilder $builder )
  36.         {
  37.             parent::__construct( $builder );
  38.  
  39.             $this->obj_masonry = array();
  40.         }
  41.  
  42.         /**
  43.          * @since 4.8.9
  44.          */
  45.         public function __destruct()
  46.         {
  47.             unset( $this->obj_masonry );
  48.  
  49.             parent::__destruct();
  50.         }
  51.  
  52.         /**
  53.          * Create the config array for the shortcode button
  54.          */
  55.         protected function shortcode_insert_button()
  56.         {
  57.             $this->config['version']        = '1.0';
  58.             $this->config['is_fullwidth']   = 'yes';
  59.             $this->config['base_element']   = 'yes';
  60.  
  61.             /**
  62.              * inconsistent behaviour up to 4.2: a new element was created with a close tag, after editing it was self closing !!!
  63.              * @since 4.2.1: We make new element self closing now because no id='content' exists.
  64.              */
  65.             $this->config['self_closing']   = 'yes';
  66.  
  67.             $this->config['name']           = __( 'Masonry Gallery', 'avia_framework' );
  68.             $this->config['tab']            = __( 'Media Elements', 'avia_framework' );
  69.             $this->config['icon']           = AviaBuilder::$path['imagesURL'] . 'sc-masonry-gallery.png';
  70.             $this->config['order']          = 5;
  71.             $this->config['target']         = 'avia-target-insert';
  72.             $this->config['shortcode']      = 'av_masonry_gallery';
  73.             $this->config['tooltip']        = __( 'Display a fullwidth masonry/grid gallery', 'avia_framework' );
  74.             $this->config['drag-level']     = 3;
  75.             $this->config['preview']        = false;
  76.             $this->config['disabling_allowed'] = true;
  77.             $this->config['id_name']        = 'id';
  78.             $this->config['id_show']        = 'always';
  79.             $this->config['alb_desc_id']    = 'alb_description';
  80.         }
  81.  
  82.         protected function admin_assets()
  83.         {
  84.             add_action( 'wp_ajax_avia_ajax_masonry_more', array( 'avia_masonry', 'handler_ajax_load_more' ) );
  85.             add_action( 'wp_ajax_nopriv_avia_ajax_masonry_more', array( 'avia_masonry', 'handler_ajax_load_more' ) );
  86.         }
  87.  
  88.  
  89.         protected function extra_assets()
  90.         {
  91.             $ver = Avia_Builder()->get_theme_version();
  92.             $min_js = avia_minify_extension( 'js' );
  93.             $min_css = avia_minify_extension( 'css' );
  94.  
  95.             wp_enqueue_style( 'avia-module-masonry', AviaBuilder::$path['pluginUrlRoot'] . "avia-shortcodes/masonry_entries/masonry_entries{$min_css}.css", array( 'avia-layout' ), $ver );
  96.  
  97.             //loading icon
  98.             wp_enqueue_style( 'avia-siteloader', get_template_directory_uri() . "/css/avia-snippet-site-preloader{$min_css}.css", array( 'avia-layout' ), $ver );
  99.  
  100.             wp_enqueue_script( 'avia-module-isotope', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/portfolio/isotope.min.js', array( 'avia-shortcodes' ), $ver , true );
  101.             wp_enqueue_script( 'avia-module-masonry', AviaBuilder::$path['pluginUrlRoot'] . "avia-shortcodes/masonry_entries/masonry_entries{$min_js}.js", array( 'avia-module-isotope' ), $ver, true );
  102.         }
  103.  
  104.         /**
  105.          * Popup Elements
  106.          *
  107.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  108.          * opens a modal window that allows to edit the element properties
  109.          *
  110.          * @return void
  111.          */
  112.         protected function popup_elements()
  113.         {
  114.             $this->elements = array(
  115.  
  116.                 array(
  117.                         'type'  => 'tab_container',
  118.                         'nodescription' => true
  119.                     ),
  120.  
  121.                 array(
  122.                         'type'  => 'tab',
  123.                         'name'  => __( 'Content', 'avia_framework' ),
  124.                         'nodescription' => true
  125.                     ),
  126.  
  127.                     array(
  128.                             'type'          => 'template',
  129.                             'template_id'   => 'toggle_container',
  130.                             'templates_include' => array(
  131.                                                     $this->popup_key( 'content_entries' ),
  132.                                                     $this->popup_key( 'content_captions' ),
  133.                                                     $this->popup_key( 'content_copyright' )
  134.                                                 ),
  135.                             'nodescription' => true
  136.                         ),
  137.  
  138.                 array(
  139.                         'type'  => 'tab_close',
  140.                         'nodescription' => true
  141.                     ),
  142.  
  143.                 array(
  144.                         'type'  => 'tab',
  145.                         'name'  => __( 'Styling', 'avia_framework' ),
  146.                         'nodescription' => true
  147.                     ),
  148.  
  149.                     array(
  150.                             'type'          => 'template',
  151.                             'template_id'   => 'toggle_container',
  152.                             'templates_include' => array(
  153.                                                     $this->popup_key( 'styling_masonry' ),
  154.                                                     $this->popup_key( 'styling_columns' ),
  155.                                                     $this->popup_key( 'styling_pagination' ),
  156.                                                     $this->popup_key( 'styling_colors' ),
  157.                                                     $this->popup_key( 'styling_copyright' )
  158.                                                 ),
  159.                             'nodescription' => true
  160.                         ),
  161.  
  162.                 array(
  163.                         'type'  => 'tab_close',
  164.                         'nodescription' => true
  165.                     ),
  166.  
  167.                 array(
  168.                         'type'  => 'tab',
  169.                         'name'  => __( 'Advanced', 'avia_framework' ),
  170.                         'nodescription' => true
  171.                     ),
  172.  
  173.                     array(
  174.                             'type'  => 'toggle_container',
  175.                             'nodescription' => true
  176.                         ),
  177.  
  178.                         array(
  179.                                 'type'          => 'template',
  180.                                 'template_id'   => $this->popup_key( 'advanced_animation' )
  181.                             ),
  182.  
  183.                         array(
  184.                                 'type'          => 'template',
  185.                                 'template_id'   => $this->popup_key( 'advanced_link' )
  186.                             ),
  187.  
  188.                         array(
  189.                                 'type'          => 'template',
  190.                                 'template_id'   => 'lazy_loading_toggle',
  191.                                 'lockable'      => true
  192.                             ),
  193.  
  194.                         array(
  195.                                 'type'          => 'template',
  196.                                 'template_id'   => 'screen_options_toggle',
  197.                                 'lockable'      => true
  198.                             ),
  199.  
  200.                         array(
  201.                                 'type'          => 'template',
  202.                                 'template_id'   => 'developer_options_toggle',
  203.                                 'args'          => array( 'sc' => $this )
  204.                             ),
  205.  
  206.                     array(
  207.                             'type'  => 'toggle_container_close',
  208.                             'nodescription' => true
  209.                         ),
  210.  
  211.                 array(
  212.                         'type'  => 'tab_close',
  213.                         'nodescription' => true
  214.                     ),
  215.  
  216.                 array(
  217.                         'type'          => 'template',
  218.                         'template_id'   => 'element_template_selection_tab',
  219.                         'args'          => array( 'sc' => $this )
  220.                     ),
  221.  
  222.                 array(
  223.                         'type'  => 'tab_container_close',
  224.                         'nodescription' => true
  225.                     )
  226.  
  227.                 );
  228.         }
  229.  
  230.         /**
  231.          * Create and register templates for easier maintainance
  232.          *
  233.          * @since 4.6.4
  234.          */
  235.         protected function register_dynamic_templates()
  236.         {
  237.  
  238.             /**
  239.              * Content Tab
  240.              * ===========
  241.              */
  242.  
  243.             $c = array(
  244.                         array(
  245.                             'name'      => __( 'Edit Gallery', 'avia_framework' ),
  246.                             'desc'      => __( 'Create a new Gallery by selecting existing or uploading new images', 'avia_framework' ),
  247.                             'id'        => 'ids',
  248.                             'type'      => 'gallery',
  249.                             'title'     => __( 'Add/Edit Gallery', 'avia_framework' ),
  250.                             'button'    => __( 'Insert Images', 'avia_framework' ),
  251.                             'std'       => '',
  252.                             'modal_class' => 'av-show-image-custom-link',
  253.                             'lockable'  => true
  254.                         )
  255.                 );
  256.  
  257.             $template = array(
  258.                             array(
  259.                                 'type'          => 'template',
  260.                                 'template_id'   => 'toggle',
  261.                                 'title'         => __( 'Select Images', 'avia_framework' ),
  262.                                 'content'       => $c
  263.                             )
  264.                     );
  265.  
  266.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_entries' ), $template );
  267.  
  268.             $c = array(
  269.                         array(
  270.                                 'type'          => 'template',
  271.                                 'template_id'   => 'masonry_captions',
  272.                                 'lockable'      => true,
  273.                         )
  274.  
  275.                 );
  276.  
  277.             $template = array(
  278.                             array(
  279.                                 'type'          => 'template',
  280.                                 'template_id'   => 'toggle',
  281.                                 'title'         => __( 'Captions', 'avia_framework' ),
  282.                                 'content'       => $c
  283.                             )
  284.                     );
  285.  
  286.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_captions' ), $template );
  287.  
  288.             $desc  = __( 'Select to show the image copyright info added to the media library.', 'avia_framework' ) . ' ';
  289.             $desc .= __( 'Due to layout restrictions &quot;Caption at bottom of image&quot; might hide this info. Please check the frontend.', 'avia_framework' );
  290.  
  291.             $c = array(
  292.                         array(
  293.                                 'type'          => 'template',
  294.                                 'template_id'   => 'image_copyright_toggle',
  295.                                 'desc'          => $desc,
  296.                                 'lockable'      => true
  297.                         )
  298.  
  299.                 );
  300.  
  301.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_copyright' ), $c );
  302.  
  303.  
  304.             /**
  305.              * Styling Tab
  306.              * ===========
  307.              */
  308.  
  309.             $c = array(
  310.                         array(
  311.                             'name'      => __( 'Size Settings', 'avia_framework' ),
  312.                             'desc'      => __( 'Here you can select how the masonry should behave and handle the images', 'avia_framework' ),
  313.                             'id'        => 'size',
  314.                             'type'      => 'radio',
  315.                             'std'       => 'flex',
  316.                             'lockable'  => true,
  317.                             'options'   => array(
  318.                                                 'flex'          => __( 'Flexible Masonry: All images get the same width but are displayed with their original height and width ratio', 'avia_framework' ),
  319.                                                 'fixed'         => __( 'Perfect Grid: Display a perfect grid where each image has exactly the same size. Images get cropped/stretched if they don\'t fit', 'avia_framework' ),
  320.                                                 'fixed masonry' => __( 'Perfect Automatic Masonry: Display a grid where most images get the same size, only very wide images get twice the width and very high images get twice the height. To qualify for &quot;very wide&quot; or &quot;very high&quot; the image must have a aspect ratio of 16:9 or higher', 'avia_framework' ),
  321.                                             )
  322.                         ),
  323.  
  324.                         array(
  325.                             'name'      => __( 'Orientation', 'avia_framework' ),
  326.                             'desc'      => __( 'Set the orientation of the cropped preview images', 'avia_framework' ),
  327.                             'id'        => 'orientation',
  328.                             'type'      => 'select',
  329.                             'std'       => '',
  330.                             'lockable'  => true,
  331.                             'required'  => array( 'size', 'equals', 'fixed' ),
  332.                             'subtype'   => array(
  333.                                                 __( 'Wide Landscape', 'avia_framework' )    => 'av-orientation-landscape-large',
  334.                                                 __( 'Landscape', 'avia_framework' )         => '',
  335.                                                 __( 'Square', 'avia_framework' )            => 'av-orientation-square',
  336.                                                 __( 'Portrait', 'avia_framework' )          => 'av-orientation-portrait',
  337.                                                 __( 'High Portrait', 'avia_framework' )     => 'av-orientation-portrait-large',
  338.                                             )
  339.                         ),
  340.  
  341.                         array(
  342.                             'type'          => 'template',
  343.                             'template_id'   => 'image_size_select',
  344.                             'std'           => 'masonry',
  345.                             'lockable'      => true,
  346.                             'multi'         => true
  347.                         ),
  348.  
  349.                         array(
  350.                             'name'      => __( 'Gap between elements', 'avia_framework' ),
  351.                             'desc'      => __( 'Select the gap between the elements', 'avia_framework' ),
  352.                             'id'        => 'gap',
  353.                             'type'      => 'select',
  354.                             'std'       => 'large',
  355.                             'lockable'  => true,
  356.                             'subtype'   => array(
  357.                                                 __( 'No Gap', 'avia_framework' )        => 'no',
  358.                                                 __( '1 Pixel Gap', 'avia_framework' )   => '1px',
  359.                                                 __( 'Large Gap', 'avia_framework' )     => 'large',
  360.                                             )
  361.                         ),
  362.  
  363.  
  364.                 );
  365.  
  366.             $template = array(
  367.                             array(
  368.                                 'type'          => 'template',
  369.                                 'template_id'   => 'toggle',
  370.                                 'title'         => __( 'Masonry Settings', 'avia_framework' ),
  371.                                 'content'       => $c
  372.                             ),
  373.                     );
  374.  
  375.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_masonry' ), $template );
  376.  
  377.             $c = array(
  378.  
  379.                         array(
  380.                                 'type'          => 'template',
  381.                                 'template_id'   => 'columns_count_icon_switcher',
  382.                                 'subtype'       => array(
  383.                                                     'default'   => AviaHtmlHelper::number_array( 2, 7, 1, array( __( 'Use default', 'avia_framework' )  => '', __( '1 column', 'avia_framework' ) => '1' ), ' ' . __( 'columns', 'avia_framework' ) ),
  384.                                                     'desktop'   => AviaHtmlHelper::number_array( 2, 7, 1, array( __( 'Use default', 'avia_framework' )  => '', __( '1 column', 'avia_framework' ) => '1' ), ' ' . __( 'columns', 'avia_framework' ) ),
  385.                                                     'medium'    => AviaHtmlHelper::number_array( 2, 5, 1, array( __( 'Use default', 'avia_framework' )  => '', __( '1 column', 'avia_framework' ) => '1' ), ' ' . __( 'columns', 'avia_framework' ) ),
  386.                                                     'small'     => AviaHtmlHelper::number_array( 2, 4, 1, array( __( 'Use default', 'avia_framework' )  => '', __( '1 column', 'avia_framework' ) => '1' ), ' ' . __( 'columns', 'avia_framework' ) ),
  387.                                                     'mini'      => AviaHtmlHelper::number_array( 2, 3, 1, array( __( 'Use default', 'avia_framework' )  => '', __( '1 column', 'avia_framework' ) => '1' ), ' ' . __( 'columns', 'avia_framework' ) ),
  388.                                                 ),
  389.                                 'std'           => array(
  390.                                                     'default'   => '',
  391.                                                     'desktop'   => '',
  392.                                                     'medium'    => '',
  393.                                                     'small'     => '',
  394.                                                     'mini'      => ''
  395.                                                 ),
  396.  
  397.                                 'lockable'      => true
  398.                             )
  399.                 );
  400.  
  401.             $template = array(
  402.                             array(
  403.                                 'type'          => 'template',
  404.                                 'template_id'   => 'toggle',
  405.                                 'title'         => __( 'Columns', 'avia_framework' ),
  406.                                 'content'       => $c
  407.                             ),
  408.                     );
  409.  
  410.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_columns' ), $template );
  411.  
  412.             $c = array(
  413.                         array(
  414.                             'name'  => __( 'Image Number', 'avia_framework' ),
  415.                             'desc'  => __( 'How many images should be displayed per page?', 'avia_framework' ),
  416.                             'id'    => 'items',
  417.                             'type'  => 'select',
  418.                             'std'   => '24',
  419.                             'lockable'  => true,
  420.                             'subtype'   => AviaHtmlHelper::number_array( 1, 100, 1, array( __( 'All', 'avia_framework' ) => '-1' ) )
  421.                         ),
  422.  
  423.                         array(
  424.                             'name'  => __( 'Pagination', 'avia_framework' ),
  425.                             'desc'  => __( 'Should a pagination or load more option be displayed to view additional images?', 'avia_framework' ),
  426.                             'id'    => 'paginate',
  427.                             'type'  => 'select',
  428.                             'std'   => 'none',
  429.                             'lockable'  => true,
  430.                             'required'  => array( 'items', 'not', '-1' ),
  431.                             'subtype'   => array(
  432.                                                 __( 'Display Pagination', 'avia_framework' )                    => 'pagination',
  433.                                                 __( 'Display "Load More" Button', 'avia_framework' )            => 'load_more',
  434.                                                 __( 'No option to view additional images', 'avia_framework' )   => 'none'
  435.                                             )
  436.                         ),
  437.  
  438.                 );
  439.  
  440.             $template = array(
  441.                             array(
  442.                                 'type'          => 'template',
  443.                                 'template_id'   => 'toggle',
  444.                                 'title'         => __( 'Pagination', 'avia_framework' ),
  445.                                 'content'       => $c
  446.                             ),
  447.                     );
  448.  
  449.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_pagination' ), $template );
  450.  
  451.             $c = array(
  452.                         array(
  453.                             'name'      => __( 'Custom Colors', 'avia_framework' ),
  454.                             'desc'      => __( 'Either use the themes default colors or apply some custom ones', 'avia_framework' ),
  455.                             'id'        => 'color',
  456.                             'type'      => 'select',
  457.                             'std'       => '',
  458.                             'lockable'  => true,
  459.                             'subtype'   => array(
  460.                                                 __( 'Default', 'avia_framework' )               => '',
  461.                                                 __( 'Define Custom Colors', 'avia_framework' )  => 'custom'
  462.                                             )
  463.                         ),
  464.  
  465.                         array(
  466.                             'name'      => __( 'Custom Background Color', 'avia_framework' ),
  467.                             'desc'      => __( 'Select a custom background color. Leave empty to use the default', 'avia_framework' ),
  468.                             'id'        => 'custom_bg',
  469.                             'type'      => 'colorpicker',
  470.                             'std'       => '',
  471.                             'rgba'      => true,
  472.                             //'container_class' => 'av_third av_third_first',
  473.                             'lockable'  => true,
  474.                             'required'  => array( 'color', 'equals', 'custom' )
  475.                         )
  476.                 );
  477.  
  478.             $template = array(
  479.                             array(
  480.                                 'type'          => 'template',
  481.                                 'template_id'   => 'toggle',
  482.                                 'title'         => __( 'Colors', 'avia_framework' ),
  483.                                 'content'       => $c
  484.                             ),
  485.                     );
  486.  
  487.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_colors' ), $template );
  488.  
  489.  
  490.             $c = array(
  491.                         array(
  492.                                 'type'          => 'template',
  493.                                 'template_id'   => 'image_copyright_styling_toggle',
  494.                                 'lockable'      => true
  495.                         )
  496.  
  497.                 );
  498.  
  499.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_copyright' ), $c );
  500.  
  501.             /**
  502.              * Animation Tab
  503.              * =============
  504.              */
  505.  
  506.             $c = array(
  507.  
  508.                         array(
  509.                             'type'          => 'template',
  510.                             'template_id'   => 'animation',
  511.                             'lockable'      => true,
  512.                             'std'           => 'active',
  513.                             'std_none'      => '',
  514.                             'name'          => __( 'Masonry Images Animation', 'avia_framework' ),
  515.                             'desc'          => __( 'Add a small animation to the masonry items when the user first scrolls to the masonry element. This is only to add some &quot;spice&quot; to the site and only works in modern browsers.', 'avia_framework' ),
  516.                             'groups'        => array( 'default', 'curtain' ),
  517.                             'multicolor'    => true
  518.                         ),
  519.  
  520.                         array(
  521.                             'type'          => 'template',
  522.                             'template_id'   => 'image_hover',
  523.                             'id'            => 'overlay_fx',
  524.                             'std'           => 'active',
  525.                             'lockable'      => true
  526.                         )
  527.  
  528.                 );
  529.  
  530.             $template = array(
  531.                             array(
  532.                                 'type'          => 'template',
  533.                                 'template_id'   => 'toggle',
  534.                                 'title'         => __( 'Animation', 'avia_framework' ),
  535.                                 'content'       => $c
  536.                             ),
  537.                     );
  538.  
  539.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_animation' ), $template );
  540.  
  541.             $c = array(
  542.                         array(
  543.                             'name'  => __( 'Image Link', 'avia_framework' ),
  544.                             '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' ),
  545.                             'id'    => 'container_links',
  546.                             'type'  => 'select',
  547.                             'std'   => 'active',
  548.                             'lockable'  => true,
  549.                             'subtype'   => array(
  550.                                                 __( 'Lightbox linking active', 'avia_framework' )                       => 'active',
  551.                                                 __( 'Use custom link (fallback is no link)', 'avia_framework' )         => '',
  552.                                                 __( 'Use custom link (fallback is image link)', 'avia_framework' )      => 'custom_image',
  553.                                                 __( 'No, don\'t add a link to the images at all', 'avia_framework' )    => 'no_links',
  554.                                             )
  555.                         ),
  556.  
  557.                         array(
  558.                             'name'      => __( 'Custom link destination', 'avia_framework' ),
  559.                             'desc'      => __( 'Select where an existing custom link should be opened.', 'avia_framework' ),
  560.                             'id'        => 'link_dest',
  561.                             'type'      => 'select',
  562.                             'std'       => '',
  563.                             'lockable'  => true,
  564.                             'required'  => array( 'container_links', 'parent_in_array', ',custom_image' ),
  565.                             'subtype'   => array(
  566.                                                 __( 'Open in same window', 'avia_framework' )       => '',
  567.                                                 __( 'Open in a new window', 'avia_framework' )      => '_blank'
  568.                                             )
  569.                         ),
  570.  
  571.                         array(
  572.                             'name'      => __( 'Lightbox image description text', 'avia_framework' ),
  573.                             'desc'      => __( 'Select which text defined in the media gallery is displayed below the lightbox image.', 'avia_framework' ),
  574.                             'id'        => 'lightbox_text',
  575.                             'type'      => 'select',
  576.                             'std'       => '',
  577.                             'lockable'  => true,
  578.                             'required'  => array( 'container_links', 'equals', 'active' ),
  579.                             'subtype'   => array(
  580.                                                 __( 'No text', 'avia_framework' )                                       => 'no_text',
  581.                                                 __( 'Image title', 'avia_framework' )                                   => '',
  582.                                                 __ ('Image description (or image title if empty)', 'avia_framework' )   => 'description',
  583.                                                 __( 'Image caption (or image title if empty)', 'avia_framework' )       => 'caption'
  584.                                             )
  585.                         )
  586.  
  587.                 );
  588.  
  589.             $template = array(
  590.                             array(
  591.                                 'type'          => 'template',
  592.                                 'template_id'   => 'toggle',
  593.                                 'title'         => __( 'Link Settings', 'avia_framework' ),
  594.                                 'content'       => $c
  595.                             ),
  596.                     );
  597.  
  598.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_link' ), $template );
  599.  
  600.         }
  601.  
  602.         /**
  603.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  604.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  605.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  606.          *
  607.          * @param array $params         holds the default values for $content and $args.
  608.          * @return array                usually holds an innerHtml key that holds item specific markup.
  609.          */
  610.         public function editor_element( $params )
  611.         {
  612.             $params = parent::editor_element( $params );
  613.             $params['innerHtml'] .= AviaPopupTemplates()->get_html_template( 'alb_element_fullwidth_stretch' );
  614.  
  615.             return $params;
  616.         }
  617.  
  618.         /**
  619.          * Editor Sub Element - this function defines the visual appearance of an element that is displayed within a modal window and on click opens its own modal window
  620.          * Works in the same way as Editor Element
  621.          *
  622.          * @param array $params         holds the default values for $content and $args.
  623.          * @return array                usually holds an innerHtml key that holds item specific markup.
  624.          */
  625.         public function editor_sub_element( $params )
  626.         {
  627.             /**
  628.              * Currently not used because we have no modal_group defined for this element
  629.              */
  630.  
  631. //          $img_template       = $this->update_template( 'img_fakeArg', '{{img_fakeArg}}' );
  632. //          $template           = $this->update_template( 'title', '{{title}}' );
  633. //          $content            = $this->update_template( 'content', '{{content}}' );
  634. //
  635. //          $thumbnail = isset( $params['args']['id'] ) ? wp_get_attachment_image( $params['args']['id'] ) : '';
  636. //
  637. //
  638. //          $params['innerHtml']  = '';
  639. //          $params['innerHtml'] .= "<div class='avia_title_container' data-update_element_template='yes'>";
  640. //          $params['innerHtml'] .=     "<span class='avia_slideshow_image' {$img_template} >{$thumbnail}</span>";
  641. //          $params['innerHtml'] .=     "<div class='avia_slideshow_content'>";
  642. //          $params['innerHtml'] .=         "<h4 class='avia_title_container_inner' {$template} >{$params['args']['title']}</h4>";
  643. //          $params['innerHtml'] .=         "<p class='avia_content_container' {$content}>" . stripslashes( $params['content'] ) . '</p>';
  644. //          $params['innerHtml'] .=     '</div>';
  645. //          $params['innerHtml'] .= '</div>';
  646.  
  647.             return $params;
  648.         }
  649.  
  650.         /**
  651.          * Create custom stylings
  652.          *
  653.          * @since 4.8.4
  654.          * @since 4.8.9.1                   added $ajax
  655.          * @param array $args
  656.          * @param boolean $ajax
  657.          * @return array
  658.          */
  659.         protected function get_element_styles( array $args, $ajax = false )
  660.         {
  661.             $result = parent::get_element_styles( $args );
  662.  
  663.             extract( $result );
  664.  
  665.             //  Backwards comp. - make sure to provide "old" defaults for options not set
  666.             $default = avia_masonry::default_args( $this->get_default_sc_args() );
  667.  
  668.             $locked = array();
  669.             Avia_Element_Templates()->set_locked_attributes( $atts, $this, $shortcodename, $default, $locked, $content );
  670.             Avia_Element_Templates()->add_template_class( $meta, $atts, $default );
  671.  
  672.             $atts = shortcode_atts( $default, $atts, $this->config['shortcode'] );
  673.  
  674.             $atts['container_class'] = 'av-masonry-gallery' . trim( " {$atts['container_class']}" );
  675.  
  676.             if( ! isset( $this->obj_masonry[ $element_id ] ) )
  677.             {
  678.                 $this->obj_masonry[ $element_id ] = new avia_masonry( $atts, $this );
  679.             }
  680.  
  681.             $masonry = $this->obj_masonry[ $element_id ];
  682.             $masonry->query_entries_by_id( array(), $ajax );
  683.  
  684.             $result['default'] = $default;
  685.             $result['atts'] = $atts;
  686.             $result['content'] = $content;
  687.             $result['element_styling'] = $element_styling;
  688.             $result['meta'] = $meta;
  689.  
  690.             $result = $masonry->get_element_styles( $result, $this );
  691.  
  692.             return $result;
  693.         }
  694.  
  695.         /**
  696.          * Returns output for ajax callback "Load More" button.
  697.          * Called as callback from class avia_masonry
  698.          *
  699.          * @since 4.8.5.1
  700.          * @param array $atts
  701.          * @return string
  702.          */
  703.         public function ajax_load_more( array $atts )
  704.         {
  705.             $args = array(
  706.                         'atts'          => $atts,
  707.                         'content'       => '',
  708.                         'shortcodename' => $this->config['shortcode']
  709.                     );
  710.  
  711.             $ajax = true;
  712.             $result = $this->get_element_styles( $args, $ajax );
  713.  
  714.             extract( $result );
  715.  
  716.             if( 'disabled' == $atts['img_scrset'] )
  717.             {
  718.                 Av_Responsive_Images()->force_disable( 'disabled' );
  719.             }
  720.  
  721.             $masonry = $this->obj_masonry[ $element_id ];
  722.             $output = $masonry->html( true );
  723.  
  724.             Av_Responsive_Images()->force_disable( 'reset' );
  725.  
  726.             return $output;
  727.         }
  728.  
  729.         /**
  730.          * Frontend Shortcode Handler
  731.          *
  732.          * @param array $atts array of attributes
  733.          * @param string $content text within enclosing form of shortcode element
  734.          * @param string $shortcodename the shortcode found, when == callback name
  735.          * @return string $output returns the modified html string
  736.          */
  737.         public function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' )
  738.         {
  739.             $result = $this->get_element_styles( compact( array( 'atts', 'content', 'shortcodename', 'meta' ) ) );
  740.  
  741.             extract( $result );
  742.             extract( $atts );
  743.  
  744.             if( 'disabled' == $atts['img_scrset'] )
  745.             {
  746.                 Av_Responsive_Images()->force_disable( 'disabled' );
  747.             }
  748.  
  749.             //  Needed to add to surrounding section
  750.             $av_display_classes = $element_styling->responsive_classes_string( 'hide_element', $atts );
  751.  
  752.             avia_sc_masonry_gallery::$gallery_count ++;
  753.             $skipSecond = false;
  754.  
  755.             $params['class'] = "main_color {$av_display_classes} {$meta['el_class']}";
  756.             $params['open_structure'] = false;
  757.             $params['id'] = AviaHelper::save_string( $meta['custom_id_val'] , '-', 'av-sc-masonry-gallery-' . avia_sc_masonry_gallery::$gallery_count );
  758.  
  759.             //we dont need a closing structure if the element is the first one or if a previous fullwidth element was displayed before
  760.             if( $meta['index'] == 0 )
  761.             {
  762.                 $params['close'] = false;
  763.             }
  764.  
  765.             if( ! empty( $meta['siblings']['prev']['tag']) && in_array( $meta['siblings']['prev']['tag'], AviaBuilder::$full_el_no_section ) )
  766.             {
  767.                 $params['close'] = false;
  768.             }
  769.  
  770.             if( $meta['index'] > 0 )
  771.             {
  772.                 $params['class'] .= ' masonry-not-first';
  773.             }
  774.  
  775.             if( $meta['index'] == 0 && get_post_meta( get_the_ID(), 'header', true ) != 'no' )
  776.             {
  777.                 $params['class'] .= ' masonry-not-first';
  778.             }
  779.  
  780.             if( $atts['gap'] == 'no' )
  781.             {
  782.                 $params['class'] .= ' avia-no-border-styling';
  783.             }
  784.  
  785.             $masonry = $this->obj_masonry[ $element_id ];
  786.  
  787.             /**
  788.              * Remove custom CSS from element if it is top level (otherwise added twice - $meta['el_class'] )
  789.              */
  790.             if( ShortcodeHelper::is_top_level() )
  791.             {
  792.                 $update = array(
  793.                             'custom_class'  => '',
  794.                             'id'            => ''
  795.                 );
  796.  
  797.                 $masonry->update_config( $update );
  798.             }
  799.  
  800.             $masonry_html = $masonry->html();
  801.  
  802.             Av_Responsive_Images()->force_disable( 'reset' );
  803.  
  804.             if( ! ShortcodeHelper::is_top_level() )
  805.             {
  806.                 return $masonry_html;
  807.             }
  808.  
  809.             if( ! empty( $atts['color'] ) && ! empty( $atts['custom_bg'] ) )
  810.             {
  811.                 $params['class'] .= ' masonry-no-border';
  812.             }
  813.  
  814.             $output  = '';
  815.             $output .= avia_new_section( $params );
  816.             $output .=      $masonry_html;
  817.             $output .= '</div><!-- close section -->'; //close section
  818.  
  819.  
  820.             //if the next tag is a section dont create a new section from this shortcode
  821.             if( ! empty( $meta['siblings']['next']['tag'] ) && in_array( $meta['siblings']['next']['tag'], AviaBuilder::$full_el ) )
  822.             {
  823.                 $skipSecond = true;
  824.             }
  825.  
  826.             //if there is no next element dont create a new section.
  827.             if( empty( $meta['siblings']['next']['tag'] ) )
  828.             {
  829.                 $skipSecond = true;
  830.             }
  831.  
  832.             if( empty( $skipSecond ) )
  833.             {
  834.                 $output .= avia_new_section( array( 'close' => false, 'id' => 'after_masonry' ) );
  835.             }
  836.  
  837.             return $output;
  838.         }
  839.  
  840.     }
  841. }
  842.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement