Advertisement
cipher87

av-helper-masonry

Sep 5th, 2020
1,609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 38.00 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Helper for masonry
  4.  *
  5.  */
  6. if ( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  7.  
  8.  
  9. if ( ! class_exists( 'avia_masonry' ) )
  10. {
  11.     class avia_masonry
  12.     {
  13.         /**
  14.          *
  15.          * @var int
  16.          */
  17.         static protected $element = 0;
  18.        
  19.         /**
  20.          *
  21.          * @var array
  22.          */
  23.         protected $atts;
  24.        
  25.         /**
  26.          *
  27.          * @var WP_Query
  28.          */
  29.         protected $entries;
  30.        
  31.         /**
  32.          *
  33.          * @var array
  34.          */
  35.         protected $screen_options;
  36.        
  37.        
  38.         /**
  39.          *
  40.          * @since 4.2.4
  41.          * @var array
  42.          */
  43.         protected $loop;
  44.        
  45.         /**
  46.          *
  47.          * @since 4.7.6.4
  48.          * @var int
  49.          */
  50.         protected $current_page;
  51.  
  52.        
  53.         /**
  54.          * @param array $atts
  55.          */
  56.         public function __construct( $atts = array() )
  57.         {
  58.             self::$element += 1;
  59.            
  60.             $this->entries = null;
  61.             $this->loop = array();
  62.             $this->screen_options = AviaHelper::av_mobile_sizes( $atts );
  63.             $this->current_page = 1;
  64.            
  65.             $this->atts = shortcode_atts( array(   
  66.                                 'ids'                   => false,
  67.                                 'action'                => false,
  68.                                 'link'                  => 'category',
  69.                                 'post_type'             => get_post_types(),
  70.                                 'items'                 => 24,
  71.                                 'size'                  => 'fixed',
  72.                                 'gap'                   => '1px',
  73.                                 'overlay_fx'            => 'active',
  74.                                 'animation'             => 'active',
  75.                                 'offset'                => 0,
  76.                                 'container_links'       => 'active',                //  'active' | '' | 'no_links'
  77.                                 'link_dest'             => '',
  78.                                 'lightbox_text'         => '',
  79.                                 'lazy_loading'          => 'disabled',
  80.                                 'container_class'       => '',
  81.                                 'paginate'              => 'none',              //  'pagination' | 'load_more' | 'none'
  82.                                 'caption_elements'      => 'title excerpt',
  83.                                 'caption_display'       => 'always',
  84.                                 'caption_styling'       => '',
  85.                                 'wc_prod_visible'       => '',
  86.                                 'wc_prod_hidden'        => '',
  87.                                 'wc_prod_featured'      => '',
  88.                                 'prod_order_by'         => '',
  89.                                 'prod_order'            => '',
  90.                                 'sort'                  => 'no',
  91.                                 'columns'               => 'automatic',
  92.                                 'auto_ratio'            => 1.7, //equals a 16:9 ratio
  93.                                 'set_breadcrumb'        => true, //no shortcode option for this, modifies the breadcrumb nav, must be false on taxonomy overview
  94.                                 'custom_markup'         => '',
  95.                                 'query_orderby'         => 'date',
  96.                                 'query_order'           => 'DESC',
  97.                                 'color'                 => '',
  98.                                 'custom_bg'             => '',
  99.                                 'custom_class'          => '',
  100.                                 'orientation'           => '',
  101.                                 'date_filter'           => '', 
  102.                                 'date_filter_start'     => '',
  103.                                 'date_filter_end'       => '',
  104.                                 'date_filter_format'    => 'yy/mm/dd',      //  'yy/mm/dd' | 'dd-mm-yy' | yyyymmdd
  105.                                 'id'                    => ''
  106.                
  107.                             ), $atts, 'av_masonry_entries' );
  108.  
  109.            
  110.             if( $this->atts['caption_elements'] == 'none' )
  111.             {
  112.                 $this->atts['caption_styling'] = '';
  113.             }
  114.                                                    
  115.             /**
  116.              * @param array $this->atts
  117.              * @param int self::$element
  118.              * @return array
  119.              */
  120.             $this->atts = apply_filters( 'avf_masonry_settings', $this->atts, self::$element );
  121.         }
  122.        
  123.         /**
  124.          *
  125.          * @since 4.2.4
  126.          */
  127.         public function __destruct()
  128.         {
  129.             unset( $this->atts );
  130.             unset( $this->entries );
  131.             unset( $this->loop );
  132.             unset( $this->screen_options );
  133.         }
  134.        
  135.  
  136.         /**
  137.          * Ajax callback function to load additional items
  138.          *
  139.          * @since < 4.0
  140.          */
  141.         static public function load_more()
  142.         {
  143.             if( check_ajax_referer( 'av-masonry-nonce', 'avno' ) );
  144.            
  145.             //increase the post items by one to fetch an additional item. this item is later removed by the javascript but it tells the script if there are more items to load or not
  146.             $_POST['items'] = empty( $_POST['items'] ) ? 1 : $_POST['items'] + 1;
  147.        
  148.             $masonry = new avia_masonry( $_POST );
  149.             $ajax = true;
  150.            
  151.             if( ! empty($_POST['ids'] ) )
  152.             {
  153.                 $masonry->query_entries_by_id( array(), $ajax );
  154.             }
  155.             else
  156.             {
  157.                 $masonry->extract_terms();
  158.                 $masonry->query_entries( array(), $ajax );
  159.             }
  160.            
  161.             $output = $masonry->html();
  162.                    
  163.             echo '{av-masonry-loaded}' . $output;
  164.             exit();
  165.         }
  166.        
  167.         /**
  168.          * Splits linkpicker string
  169.          *  
  170.          * @since < 4.0
  171.          */
  172.         public function extract_terms()
  173.         {
  174.             if( isset( $this->atts['link'] ) )
  175.             {
  176.                 $this->atts['link'] = explode( ',', $this->atts['link'], 2 );
  177.                 $this->atts['taxonomy'] = $this->atts['link'][0];
  178.  
  179.                 if( isset( $this->atts['link'][1] ) )
  180.                 {
  181.                     $this->atts['categories'] = $this->atts['link'][1];
  182.                 }
  183.                 else
  184.                 {
  185.                     $this->atts['categories'] = array();
  186.                 }
  187.             }
  188.         }
  189.        
  190.         /**
  191.          * @since < 4.0
  192.          * @return string
  193.          */
  194.         protected function sort_buttons()
  195.         {
  196.            
  197.             $term_args = array(
  198.                                 'taxonomy'      => $this->atts['taxonomy'],
  199.                                 'hide_empty'    => true
  200.                             );
  201.            
  202.             /**
  203.              * To display private posts you need to set 'hide_empty' to false,
  204.              * otherwise a category with ONLY private posts will not be returned !!
  205.              *
  206.              * You also need to add post_status 'private' to the query params with filter avia_masonry_entries_query.
  207.              *
  208.              * @since 4.4.2
  209.              * @added_by Günter
  210.              * @param array $term_args
  211.              * @param string $context
  212.              * @param array $params
  213.              * @param boolean $ajax
  214.              * @return array
  215.              */
  216.             $term_args = apply_filters( 'avf_masonry_term_args', $term_args, 'sort_buttons', $this->atts, false );
  217.            
  218.             $sort_terms = AviaHelper::get_terms( $term_args );
  219.            
  220.             $current_page_terms = array();
  221.             $term_count = array();
  222.             $display_terms = is_array( $this->atts['categories'] ) ? $this->atts['categories'] : array_filter( explode( ',', $this->atts['categories'] ) );
  223.  
  224.             foreach( $this->loop as $entry )
  225.             {
  226.                 $current_item_terms = get_the_terms( $entry['ID'], $this->atts['taxonomy'] );
  227.                
  228.                 if( is_array( $current_item_terms ) && ! empty( $current_item_terms ) )
  229.                 {
  230.                     foreach( $current_item_terms as $current_item_term )
  231.                     {
  232.                         if( empty( $display_terms ) || in_array( $current_item_term->term_id, $display_terms ) )
  233.                         {
  234.                             $current_page_terms[ $current_item_term->term_id ] = $current_item_term->term_id;
  235.  
  236.                             if( ! isset($term_count[ $current_item_term->term_id ] ) )
  237.                             {
  238.                                 $term_count[ $current_item_term->term_id ] = 0;
  239.                             }
  240.  
  241.                             $term_count[ $current_item_term->term_id ] ++;
  242.                         }
  243.                     }
  244.                 }
  245.                
  246.             }
  247.            
  248.            
  249.             $hide = count( $display_terms ) <= 1 ? 'hidden' : '';
  250.             $output = '';
  251.            
  252.             if( empty( $hide ) )
  253.             {
  254.                 $output  = "<div class='av-masonry-sort main_color av-sort-{$this->atts['sort']}' data-masonry-id='" . self::$element . "' >";
  255.                 //$output .= "<div class='container'>";
  256.                
  257.                 $first_item_name = apply_filters( 'avf_masonry_sort_first_label', __( 'All', 'avia_framework' ), $this->atts );
  258.                 $first_item_html = '<span class="inner_sort_button"><span>' . $first_item_name . '</span><small class="avia-term-count"> ' . count( $this->loop ) . ' </small></span>';
  259.                
  260.                 $output .= apply_filters( 'avf_masonry_sort_heading', '', $this->atts );
  261.                
  262.                 if( strpos( $this->atts['sort'], 'tax' ) !== false )
  263.                 {
  264.                     $output .= "<div class='av-current-sort-title'>{$first_item_html}</div>";
  265.                 }
  266.                
  267.                 $sort_loop = '';
  268.                 $allowed_terms = array();
  269.                
  270.                 foreach( $sort_terms as $term )
  271.                 {
  272.                     $show_item = in_array( $term->term_id, $current_page_terms ) ? 'avia_show_sort' : 'avia_hide_sort';
  273.                    
  274.                     if( ! isset( $term_count[ $term->term_id ] ) )
  275.                     {
  276.                         $term_count[ $term->term_id ] = 0;
  277.                     }
  278.                    
  279.                     $term->slug = str_replace( '%', '', $term->slug );
  280.                    
  281.                     if( empty( $display_terms ) || in_array( $term->term_id, $display_terms ) )
  282.                     {
  283.                         $allowed_terms[] = $term->slug . '_sort';
  284.                     }
  285.                    
  286.                     $sort_loop .=   "<span class='text-sep {$term->slug}_sort_sep {$show_item}'>/</span>";
  287.                     $sort_loop .=   '<a href="#" data-filter="' . $term->slug . '_sort" class="'.$term->slug.'_sort_button ' . $show_item . '" >';
  288.                     $sort_loop .=       '<span class="inner_sort_button">';
  289.                     $sort_loop .=           '<span>' . esc_html( trim( $term->name ) ) . '</span>';
  290.                     $sort_loop .=           "<small class='avia-term-count'> " . $term_count[ $term->term_id ] . ' </small>';
  291.                     $sort_loop .=       '</span>';
  292.                     $sort_loop .=   '</a>';
  293.                 }
  294.                
  295.                 $allowed_terms = json_encode( $allowed_terms );
  296.                
  297.                 $output .=  "<div class='av-sort-by-term {$hide} ' data-av-allowed-sort='{$allowed_terms}' >";
  298.                 $output .=      '<a href="#" data-filter="all_sort" class="all_sort_button active_sort">' . $first_item_html . '</a>';
  299.                 $output .=      $sort_loop;
  300.                 $output .=  '</div>';
  301.                
  302.                 $output .= '</div>';
  303.             }
  304.            
  305.             return $output;
  306.         }
  307.        
  308.         /**
  309.          * get the categories for each post and create a string that serves as classes so the javascript can sort by those classes
  310.          *
  311.          * @since < 4.0
  312.          * @param int|WP_Post $the_id
  313.          * @return string
  314.          */
  315.         protected function sort_array( $the_id )
  316.         {
  317.             $sort_classes = array( 'all_sort' );
  318.             $item_terms = get_the_terms( $the_id, $this->atts['taxonomy'] );
  319.  
  320.             if( is_array( $item_terms ) )
  321.             {
  322.                 foreach( $item_terms as $term )
  323.                 {
  324.                     $term->slug = str_replace( '%', '', $term->slug );
  325.                     $sort_classes[] = $term->slug . '_sort ';
  326.                 }
  327.             }
  328.  
  329.             return $sort_classes;
  330.         }
  331.  
  332.        
  333.         /**
  334.          * @since < 4.0
  335.          * @return string
  336.          */
  337.         public function html()
  338.         {
  339.             if( empty( $this->loop ) )
  340.             {
  341.                 return '';
  342.             }
  343.            
  344.             extract( $this->screen_options ); //return $av_font_classes, $av_title_font_classes, $av_display_classes and $av_column_classes
  345.            
  346.             $output = '';
  347.             $items = '';
  348.             $size = strpos( $this->atts['size'], 'fixed' ) !== false ? 'fixed' : 'flex';
  349.             $auto = strpos( $this->atts['size'], 'masonry' ) !== false ? true : false;
  350.             $manually = strpos( $this->atts['size'], 'manually' ) !== false ? true : false;
  351.            
  352.             $defaults = array(
  353.                             'ID'            => '',
  354.                             'thumb_ID'      => '',
  355.                             'title'         => '',
  356.                             'url'           => '',  
  357.                             'class'         => array(),  
  358.                             'date'          => '',
  359.                             'excerpt'       => '',
  360.                             'data'          => '',
  361.                             'attachment'    => array(),
  362.                             'attachment_overlay' => array(),
  363.                             'bg'            => '',
  364.                             'before_content' => '', // if set replaces the whole bg part
  365.                             'text_before'   => '',
  366.                             'text_after'    => '',
  367.                             'img_before'    => ''
  368.                         );
  369.            
  370.            
  371.             $style = '';
  372.  
  373.             if( ! empty( $this->atts['color'] ) )
  374.             {
  375.                 $style .= AviaHelper::style_string( $this->atts, 'custom_bg', 'background-color' );
  376.                 $style  = AviaHelper::style_string( $style );
  377.             }
  378.            
  379.             $orientation = $this->atts['size'] == 'fixed' ? $this->atts['orientation'] : '';
  380.            
  381.             $custom_class = isset( $this->atts['custom_class'] ) ? $this->atts['custom_class'] : '';
  382.             $id_el = ! empty( $this->atts['id'] ) ? $this->atts['id'] : 'av-masonry-' . self::$element;
  383.            
  384.             $output .= "<div id='{$id_el}' class='av-masonry {$custom_class} noHover av-{$size}-size av-{$this->atts['gap']}-gap av-hover-overlay-{$this->atts['overlay_fx']} av-masonry-animation-{$this->atts['animation']} av-masonry-col-{$this->atts['columns']} av-caption-{$this->atts['caption_display']} av-caption-style-{$this->atts['caption_styling']} {$this->atts['container_class']} {$orientation} {$av_display_classes} {$av_column_classes}' {$style} >";
  385.            
  386.             $output .= $this->atts['sort'] != 'no' ? $this->sort_buttons() : '';
  387.            
  388.             $output .= "<div class='av-masonry-container isotope av-js-disabled ' >";
  389.            
  390.             $all_sorts = array();
  391.             $sort_array = array();
  392.            
  393.             foreach( $this->loop as $index => $entry )
  394.             {
  395.                 extract( array_merge( $defaults, $entry ) );
  396.                
  397.                 $title = '';
  398.                 $outer_title = '';
  399.                 $alt = '';
  400.                 $outer_alt = '';
  401.                 $img_html = '';
  402.                 $img_style = '';
  403.                
  404.                 if( $this->atts['sort'] != 'no' )
  405.                 {
  406.                     $sort_array = $this->sort_array( $entry['ID'] );
  407.                 }
  408.                
  409.                 $class_string = implode( ' ', $class ) . ' ' . implode( ' ', $sort_array );
  410.                 $all_sorts = array_merge( $all_sorts, $sort_array );
  411.                
  412.                 if( ! empty( $attachment ) )
  413.                 {
  414.                     $title = trim( esc_attr( get_the_title( $thumb_ID ) ) );
  415.                     $outer_title = empty( $title ) ? '' : ' title="' . $title . '" ';
  416.                    
  417.                     $alt = get_post_meta( $thumb_ID, '_wp_attachment_image_alt', true );
  418.                     $alt = trim( esc_attr( $alt ) );
  419.                     $outer_alt = empty( $alt ) ? '' : ' alt="' . $alt . '" ';
  420.                    
  421.                     if( isset( $attachment[0] ) )
  422.                     {
  423.                         if( $size == 'flex' )  
  424.                         {
  425.                             $img_html = '<img src="'. $attachment[0] . '" title="' . $title . '" alt="' . $alt . '" />';
  426.                             $img_html = Av_Responsive_Images()->make_image_responsive( $img_html, $thumb_ID, $this->atts['lazy_loading'] );
  427.                            
  428.                             $outer_title = '';
  429.                             $outer_alt = '';
  430.                         }
  431.                        
  432.                         if( $size == 'fixed' )
  433.                         {
  434.                             $img_style = 'style="background-image: url(' . $attachment[0] . ');"';
  435.                         }
  436.                        
  437.                         $class_string .= ' av-masonry-item-with-image';
  438.                     }
  439.                     else
  440.                     {
  441.                         $outer_title = '';
  442.                         $outer_alt = '';
  443.                     }
  444.                    
  445.                     if( isset( $attachment_overlay[0] ) )
  446.                     {
  447.                         $over_html  = '<img src="' . $attachment_overlay[0] . '" title="' . $title . '" alt="' . $alt . '" />';
  448.                         $over_style = 'style="background-image: url(' . $attachment_overlay[0] . ');"';
  449.                         $img_before = '<div class="av-masonry-image-container av-masonry-overlay" ' . $over_style . '>' . $over_html . '</div>';
  450.                     }
  451.                    
  452.                     $bg = '<div class="av-masonry-outerimage-container">' . $img_before . '<div class="av-masonry-image-container" ' . $img_style . $outer_title . $outer_alt . '>' . $img_html . '</div></div>';
  453.                 }
  454.                 else
  455.                 {
  456.                     $class_string .= ' av-masonry-item-no-image';
  457.                 }
  458.                
  459.                
  460.                 if( $size == 'fixed' )
  461.                 {
  462.                     if( ! empty( $attachment ) || ! empty( $before_content ) )
  463.                     {
  464.                         if( $auto )
  465.                         {
  466.                             $class_string .= $this->ratio_check_by_image_size( $attachment );
  467.                         }
  468.                        
  469.                         if( $manually )
  470.                         {
  471.                             $class_string .= $this->ratio_check_by_tag( $entry['tags'] );  
  472.                         }
  473.                     }
  474.                 }
  475.                
  476.                 $linktitle = '';
  477.                
  478.                 if( $post_type == 'attachment' && strpos( $html_tags[0], 'a href=' ) !== false )
  479.                 {
  480.                     $lightbox_title = $title;
  481.                    
  482.                     switch( $this->atts['lightbox_text'] )
  483.                     {
  484.                         case 'caption':
  485.                             $lightbox_title = ( '' != $entry['content'] ) ? $entry['content'] : $title;
  486.                             break;
  487.                         case 'description':
  488.                             $lightbox_title = ( '' != $entry['image_content'] ) ? $entry['image_content'] : $title;
  489.                             break;
  490.                         case 'no_text':
  491.                             $lightbox_title = '';
  492.                     }
  493.                    
  494.                     $linktitle = 'title="' . esc_attr( $lightbox_title ) . '" alt="' . esc_attr( $alt ) . '" ';
  495.                 }
  496.                 else if( strpos( $html_tags[0], 'a href=' ) !== false )
  497.                 {
  498.                     $display = empty( $title ) ? $the_title : $title;
  499.                     $linktitle = 'title="' . esc_attr( $display ) . '"';
  500.                 }
  501.  
  502.                 $markup = ( $post_type == 'attachment' ) ? avia_markup_helper( array( 'context' => 'image_url', 'echo' => false, 'id' => $entry['ID'], 'custom_markup' => $this->atts['custom_markup'] ) ) : avia_markup_helper( array( 'context' => 'entry', 'echo' => false, 'id' => $entry['ID'], 'custom_markup' => $this->atts['custom_markup'] ) );
  503.  
  504.                 $items .=   "<{$html_tags[0]} id='av-masonry-" . self::$element . "-item-{$entry['ID']}' data-av-masonry-item='{$entry['ID']}' class='{$class_string}' {$linktitle} {$markup}>";
  505.                 $items .=       "<div class='av-inner-masonry-sizer'></div>"; //responsible for the size
  506.                 $items .=       "<figure class='av-inner-masonry main_color'>";
  507.                 $items .=           $bg;
  508.                
  509.                 //title and excerpt
  510.                 if( $this->atts['caption_elements'] != 'none' || ! empty( $text_add ) )
  511.                 {
  512.                     $items .=   "<figcaption class='av-inner-masonry-content site-background'><div class='av-inner-masonry-content-pos'><div class='av-inner-masonry-content-pos-content'><div class='avia-arrow'></div>".$text_before;
  513.                    
  514.                     if( strpos( $this->atts['caption_elements'], 'title' ) !== false )
  515.                     {
  516.                         $markup = avia_markup_helper( array( 'context' => 'entry_title', 'echo' => false, 'id' => $entry['ID'], 'custom_markup' => $this->atts['custom_markup'] ) );
  517.                        
  518.                         $default_heading = 'h3';
  519.                         $args = array(
  520.                                     'heading'       => $default_heading,
  521.                                     'extra_class'   => ''
  522.                                 );
  523.                        
  524.                         $extra_args = array( $this, $index, $entry );
  525.  
  526.                         /**
  527.                          * @since 4.5.5
  528.                          * @return array
  529.                          */
  530.                         $args = apply_filters( 'avf_customize_heading_settings', $args, __CLASS__, $extra_args );
  531.  
  532.                         $heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  533.                         $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
  534.                        
  535.                         $items .=   "<{$heading} class='av-masonry-entry-title entry-title {$css}' {$markup}>{$the_title}</{$heading}>";
  536.                     }
  537.  
  538.                     if( strpos( $this->atts['caption_elements'], 'excerpt' ) !== false && ! empty( $content ) )
  539.                     {
  540.                         $markup = avia_markup_helper( array( 'context' => 'entry_content', 'echo' => false, 'id' => $entry['ID'], 'custom_markup' => $this->atts['custom_markup'] ) );
  541.                         $items .=   "<div class='av-masonry-entry-content entry-content' {$markup}>{$content}</div>";
  542.                     }
  543.                    
  544.                     $items .=   $text_after . '</div></div></figcaption>';
  545.                 }
  546.                 $items .=       '</figure>';
  547.                 $items .=   "</{$html_tags[1]}><!--end av-masonry entry-->";                   
  548.             }
  549.            
  550.             //if its an ajax call return the items only without container
  551.             if( isset( $this->atts['action'] ) && $this->atts['action'] == 'avia_ajax_masonry_more' )
  552.             {
  553.                 return $items;
  554.             }
  555.            
  556.             // if its no ajax load prepend an empty invisible element as the first element. this is used for calculating the correct width of a default element.
  557.             // in theory this is not necessary because the masonry can detect that with an extra js parameter but sorting becomes slugish if that param is set
  558.             $all_sort_string = implode( ' ', array_unique( $all_sorts ) );
  559.            
  560.             $items = "<div class='av-masonry-entry isotope-item av-masonry-item-no-image {$all_sort_string}'></div>{$items}";
  561.            
  562.             $output .= $items;
  563.             $output .=  '</div>';
  564.            
  565.            
  566.             //append pagination
  567.             if( $this->atts['paginate'] == 'pagination' && $avia_pagination = avia_pagination( $this->entries->max_num_pages, 'nav', 'avia-element-paging', $this->current_page ) )
  568.             {
  569.                 $output .= "<div class='av-masonry-pagination av-masonry-pagination-{$this->atts['paginate']}'>{$avia_pagination}</div>";
  570.             }
  571.             else if( $this->atts['paginate'] == 'load_more' && $this->entries->max_num_pages > 1 )
  572.             {
  573.                 $output .= $this->load_more_button();
  574.             }
  575.            
  576.             $output .= '</div>';
  577.            
  578.             return $output;
  579.         }
  580.        
  581.                
  582.         /**
  583.          *
  584.          * @since < 4.0
  585.          * @return string
  586.          */
  587.         protected function load_more_button()
  588.         {
  589.             $data_string  = AviaHelper::create_data_string( $this->atts );
  590.             $data_string .= " data-avno='" . wp_create_nonce( 'av-masonry-nonce' ) . "'";
  591.            
  592.             $output  = '';
  593.             $output .=      "<a class='av-masonry-pagination av-masonry-load-more' href='#load-more' {$data_string}>" . __( 'Load more', 'avia_framework' ) . "</a>";
  594.            
  595.             return $output;
  596.         }  
  597.        
  598.         /**
  599.          *
  600.          * @since < 4.0
  601.          * @param array $attachment
  602.          * @return string
  603.          */
  604.         protected function ratio_check_by_image_size( $attachment )
  605.         {
  606.             $img_size = ' av-grid-img';
  607.            
  608.             if( ! empty( $attachment[1] ) && ! empty( $attachment[2] ) )
  609.             {
  610.                 if( $attachment[1] > $attachment[2] ) //landscape
  611.                 {
  612.                     //only consider it landscape if its 1.7 times wider than high
  613.                     if( $attachment[1] / $attachment[2] > $this->atts['auto_ratio'] )
  614.                     {
  615.                         $img_size = ' av-landscape-img';
  616.                     }
  617.                 }
  618.                 else //same check with portrait
  619.                 {
  620.                     if( $attachment[2] / $attachment[1] > $this->atts['auto_ratio'] )
  621.                     {
  622.                         $img_size = ' av-portrait-img';
  623.                     }
  624.                 }
  625.             }
  626.            
  627.             return $img_size;
  628.         }
  629.        
  630.         /**
  631.          *
  632.          * @since < 4.0
  633.          * @param mixed $tags
  634.          * @return string
  635.          */
  636.         protected function ratio_check_by_tag( $tags )
  637.         {
  638.             $img_size = '';
  639.            
  640.             if( is_array( $tags ) )
  641.             {  
  642.                 /**
  643.                  * Gets translated values for given tags
  644.                  *
  645.                  * @since < 4.0
  646.                  * @used_by         enfold\config-wpml\config.php   avia_translate_check_by_tag_values()
  647.                  * @return array
  648.                  */
  649.                 $tag_values = apply_filters( 'avf_ratio_check_by_tag_values', array( 'portrait' => 'portrait', 'landscape' => 'landscape' ) );
  650.  
  651.                 if( in_array( $tag_values['portrait'], $tags ) ) { $img_size .= ' av-portrait-img'; }
  652.                 if( in_array( $tag_values['landscape'], $tags ) ){ $img_size .= ' av-landscape-img'; }
  653.             }
  654.            
  655.             if( empty( $img_size ) )  
  656.             {
  657.                 $img_size .= ' av-grid-img';
  658.             }
  659.            
  660.             return $img_size;
  661.         }
  662.        
  663.         /**
  664.          * @since < 4.0
  665.          * @param boolean $ajax
  666.          * @return void
  667.          */
  668.         protected function prepare_loop_from_entries( $ajax = false )
  669.         {
  670.             $this->loop = array();
  671.             if( empty( $this->entries ) || empty( $this->entries->posts ) )
  672.             {
  673.                 return;
  674.             }
  675.            
  676.             $tagTax = 'post_tag';
  677.             $date_format = get_option( 'date_format' );
  678.            
  679.             foreach( $this->entries->posts as $key => $entry )
  680.             {  
  681.                 $overlay_img = false;
  682.                 $custom_url = false;
  683.                 $img_size = 'masonry';
  684.                
  685.                 $author = apply_filters( 'avf_author_name', get_the_author_meta( 'display_name', $entry->post_author ), $entry->post_author );
  686.  
  687.                 $this->loop[ $key ]['text_before'] = '';
  688.                 $this->loop[ $key ]['text_after'] = '';
  689.                 $this->loop[ $key ]['ID'] = $id = $entry->ID;
  690.                 $this->loop[ $key ]['post_type'] = $entry->post_type;
  691.                 $this->loop[ $key ]['thumb_ID'] = get_post_thumbnail_id( $id );
  692.                 $this->loop[ $key ]['the_title'] = get_the_title( $id );
  693.                 $this->loop[ $key ]['alt_text'] = '';
  694.                 $this->loop[ $key ]['url'] = get_permalink( $id );
  695.                 $this->loop[ $key ]['date'] = "<span class='av-masonry-date meta-color updated'>" . get_the_time( $date_format, $id ) . '</span>';
  696.                 $this->loop[ $key ]['author'] = "<span class='av-masonry-author meta-color author'><span class='fn'>" . __( 'by', 'avia_framework' ) . ' ' . $author . '</span></span>';
  697.                 $this->loop[ $key ]['class'] = get_post_class( 'av-masonry-entry isotope-item', $id );
  698.                
  699.                 $loop_excerpt = strip_tags( $entry->post_excerpt );
  700.                 $loop_content = ! empty( $entry->post_content ) ? $entry->post_content : $entry->post_excerpt;
  701.                 $aria_label_href = '';
  702.                
  703.                 /**
  704.                  * @since 4.7.1.1
  705.                  * @param string $loop_excerpt
  706.                  * @param WP_Post $entry
  707.                  * @param array $this->entries
  708.                  * @param int $key
  709.                  */
  710.                 $this->loop[ $key ]['content'] = apply_filters( 'avf_masonry_loop_entry_content', $loop_excerpt, $entry, $this->entries, $key );
  711.                
  712.                 /**
  713.                  * @since 4.7.1.1
  714.                  * @param string $loop_content
  715.                  * @param WP_Post $entry
  716.                  * @param array $this->entries
  717.                  * @param int $key
  718.                  */
  719.                 $this->loop[ $key ]['description'] = apply_filters( 'avf_masonry_loop_entry_description', $loop_content, $entry, $this->entries, $key );
  720.                
  721.                 if( empty( $this->loop[ $key ]['content'] ) )
  722.                 {
  723.                     if( $ajax )
  724.                     {
  725.                         $entry->post_content = preg_replace( "!\[.*?\]!", '', $entry->post_content );
  726.                     }
  727.                    
  728.                     $this->loop[ $key ]['content']  = avia_backend_truncate( $entry->post_content, apply_filters( 'avf_masonry_excerpt_length', 60 ), apply_filters( 'avf_masonry_excerpt_delimiter', ' ' ), '…', true, '' );
  729.                 }
  730.                
  731.                 $this->loop[ $key ]['content'] = nl2br( trim( $this->loop[ $key ]['content'] ) );
  732.                
  733.                 //post type specific
  734.                 switch( $entry->post_type )
  735.                 {
  736.                     case 'post':
  737.                    
  738.                         $post_format = get_post_format( $id ) ? get_post_format( $id ) : 'standard';
  739.                         $this->loop[ $key ] = apply_filters( 'post-format-' . $post_format, $this->loop[ $key ] );
  740.                         $this->loop[ $key ]['text_after'] .= $this->loop[ $key ]['date'];
  741.                         $this->loop[ $key ]['text_after'] .= '<span class="av-masonry-text-sep text-sep-author">/</span>';
  742.                         $this->loop[ $key ]['text_after'] .= $this->loop[ $key ]['author'];
  743.                    
  744.                         switch( $post_format )
  745.                         {
  746.                             case 'quote' :
  747.                             case 'link' :
  748.                             case 'image' :
  749.                             case 'gallery' :
  750.                                 if( ! $this->loop[ $key ]['thumb_ID'] )
  751.                                 {
  752.                                     $this->loop[ $key ]['text_before'] = av_icon_display( $post_format );
  753.                                 }
  754.                                 break;
  755.                            
  756.                             case 'audio' :
  757.                             case 'video' :
  758.                                 if( ! $this->loop[ $key ]['thumb_ID'] )
  759.                                 {
  760.                                     $this->loop[ $key ]['text_before'] = av_icon_display( $post_format );
  761.                                 }
  762.                                 else
  763.                                 {
  764.                                     $this->loop[ $key ]['text_before'] = av_icon_display( $post_format, 'av-masonry-media' );
  765.                                 }
  766.                                 break;
  767.                         }
  768.  
  769.                         break;
  770.                    
  771.                     case 'portfolio':
  772.                    
  773.                         //set portfolio breadcrumb navigation
  774.                         if( $this->atts['set_breadcrumb'] && is_page() )
  775.                         {
  776.                             $_SESSION[ "avia_{$entry->post_type}" ] = get_the_ID();
  777.                         }
  778.  
  779.                         //check if the user has set up a custom link
  780.                         if( ! post_password_required( $id ) )
  781.                         {
  782.                             $custom_link = get_post_meta( $id , '_portfolio_custom_link', true ) != '' ? get_post_meta( $id , '_portfolio_custom_link_url', true ) : false;
  783.                             if( $custom_link )
  784.                             {
  785.                                 $this->loop[ $key ]['url'] = $custom_link;
  786.                             }
  787.                         }
  788.                        
  789.                         break;
  790.                    
  791.                     case 'attachment':
  792.                    
  793.                         $this->loop[ $key ]['thumb_ID'] = $id;
  794.                         $this->loop[ $key ]['image_content'] = $entry->post_content;
  795.                         $this->loop[ $key ]['content'] = $entry->post_excerpt;
  796.                         $this->loop[ $key ]['alt_text'] = trim( get_post_meta( $id, '_wp_attachment_image_alt', true ) );
  797.                        
  798.                         /**
  799.                          * Added to avoid ARIA Empty link warnings (Masonry Grid with "Perfect Grid" - "No Title Excerpt"
  800.                          *
  801.                          * @since 4.7.5.1
  802.                          */
  803.                         if( ! empty( $this->loop[ $key ]['the_title'] ) )
  804.                         {
  805.                             $aria_text = $this->loop[ $key ]['the_title'];
  806.                         }
  807.                         else if( ! empty( $this->loop[ $key ]['alt_text'] ) )
  808.                         {
  809.                             $aria_text = $this->loop[ $key ]['alt_text'];
  810.                         }
  811.                         else
  812.                         {
  813.                             $aria_text = __( 'image with no title', 'avia_framework' );
  814.                         }
  815.                        
  816.                         $aria_text = sprintf( __( 'image %s', 'avia_framework' ), $aria_text );
  817.                        
  818.                         /**
  819.                          * @since 4.7.5.1
  820.                          * @param string $aria_text
  821.                          * @param array $this->loop
  822.                          * @param string $key
  823.                          * @return string
  824.                          *
  825.                          */
  826.                         $aria_text = apply_filters( 'avf_masonry_aria_image_link_text', $aria_text, $this->loop, $key );
  827.                        
  828.                         if( ! empty( $aria_text ) )
  829.                         {
  830.                             $aria_label_href = ' aria-label="' . esc_attr( $aria_text ) . '" ';
  831.                         }
  832.                        
  833.                         $custom_url = get_post_meta( $id, 'av-custom-link', true );
  834.                        
  835.                         if( 'no_links' == $this->atts['container_links'] )
  836.                         {
  837.                             $this->loop[ $key ]['url'] = '';
  838.                         }
  839.                         else if( '' == $this->atts['container_links'] )
  840.                         {
  841.                             $this->loop[ $key ]['url'] = $custom_url;
  842.                         }
  843.                         else
  844.                         {
  845.                             $this->loop[ $key ]['url'] = wp_get_attachment_image_src( $id, apply_filters( 'avf_avia_builder_masonry_lightbox_img_size', 'large' ) );
  846.                             $this->loop[ $key ]['url'] = is_array( $this->loop[ $key ]['url'] ) ? reset( $this->loop[ $key ]['url'] ) : '';
  847.                         }
  848.  
  849.                         break;
  850.                    
  851.                     case 'product':
  852.                        
  853.                         //check if woocommerce is enabled in the first place so we can use woocommerce functions
  854.                         if( function_exists( 'avia_woocommerce_enabled' ) && avia_woocommerce_enabled() )
  855.                         {
  856.                             $tagTax = 'product_tag';
  857.                             $product = function_exists('wc_get_product') ? wc_get_product( $id ) : get_product( $id );
  858.                             $overlay_img = avia_woocommerce_gallery_first_thumbnail( $id, $img_size, true );
  859.  
  860.                             $this->loop[ $key ]['text_after'] .= '<span class="av-masonry-price price">' . $product->get_price_html() . "</span>";
  861.                             if( $product->is_on_sale() )
  862.                             {
  863.                                 $this->loop[ $key ]['text_after'] .= '<span class="onsale">' . __( 'Sale!', 'avia_framework' ) . '</span>';
  864.                             }
  865.                         }
  866.                        
  867.                         break;
  868.                 }
  869.                
  870.                
  871.                 //check if post is password protected
  872.                 if( post_password_required( $id ) )
  873.                 {
  874.                     $this->loop[ $key ]['content'] = '';
  875.                     $this->loop[ $key ]['class'][] = 'entry-protected';
  876.                     $this->loop[ $key ]['thumb_ID'] = '';
  877.                     $this->loop[ $key ]['text_before'] = av_icon_display( 'closed' );
  878.                     $this->loop[ $key ]['text_after'] = $this->loop[ $key ]['date'];
  879.                 }
  880.                
  881.                 $set_link = false;
  882.                 $target = '';
  883.                
  884.                 if( $this->atts['container_links'] !== 'no_links' )
  885.                 {
  886.                     if( ! empty( $this->atts['container_links'] ) )
  887.                     {
  888.                         $set_link = true;
  889.                     }
  890.                     else
  891.                     {
  892.                         $set_link = ! empty( $custom_url );
  893.                         if( ! empty( $this->atts['link_dest'] ) )
  894.                         {
  895.                             $target = ' target="_blank" rel="noopener noreferrer"';
  896.                         }  
  897.                     }
  898.                 }
  899.                
  900.                 //set the html tags. depending on the link settings use either an a tag or a div tag
  901.                 if( $set_link )
  902.                 {
  903.                     $this->loop[ $key ]['html_tags'] = array( 'a href="' . $this->loop[ $key ]['url'] . '" ' . $aria_label_href . $target, 'a' ); //opening and closing tag for the masonry container
  904.                 }
  905.                 else
  906.                 {
  907.                     $this->loop[ $key ]['html_tags'] = array( 'div', 'div' );
  908.                 }
  909.                
  910.                
  911.                 //get post tags
  912.                 $this->loop[ $key ]['tags'] = wp_get_post_terms( $id, $tagTax, array( 'fields' => 'slugs' ) );
  913.                
  914.                 //check if the image got landscape as well as portrait class applied. in that case use a bigger image size
  915.                 if( strlen( $this->ratio_check_by_tag( $this->loop[ $key ]['tags'] ) ) > 20 )
  916.                 {
  917.                     $img_size = 'extra_large';
  918.                 }
  919.                
  920.                 //get attachment data
  921.                 $this->loop[ $key ]['attachment'] = ! empty( $this->loop[ $key ]['thumb_ID'] ) ? wp_get_attachment_image_src( $this->loop[ $key ]['thumb_ID'], $img_size ) : '';
  922.                
  923.                 //get overlay attachment in case the overlay is set
  924.                 $this->loop[ $key ]['attachment_overlay'] = ! empty( $overlay_img ) ? wp_get_attachment_image_src( $overlay_img, $img_size ) : '';
  925.                
  926.                 //apply filter for other post types, in case we want to use them and display additional/different information
  927.                 $this->loop[ $key ] = apply_filters( 'avf_masonry_loop_prepare', $this->loop[ $key ], $this->entries );
  928.             }
  929.         }
  930.        
  931.         /**
  932.          * Fetch new entries
  933.          *
  934.          * @since < 4.0
  935.          * @param array $params
  936.          * @param boolean $ajax
  937.          * @return void
  938.          */
  939.         public function query_entries( $params = array(), $ajax = false )
  940.         {
  941.             global $avia_config;
  942.  
  943.             if( empty( $params ) )
  944.             {
  945.                 $params = $this->atts;
  946.             }
  947.  
  948.             if( empty( $params['custom_query'] ) )
  949.             {
  950.                 $query = array();
  951.                 $terms = array();
  952.                 $avialable_terms = array();
  953.                
  954.                 if( ! empty( $params['categories'] ) )
  955.                 {
  956.                     //get the portfolio categories
  957.                     $terms = explode( ',', $params['categories'] );
  958.                    
  959.                     /**
  960.                      * Allows to translate id's to filter sort buttons correctly
  961.                      *
  962.                      * @used_by    config-wpml\config.php   avia_translate_object_ids()         10
  963.                      * @since 4.6.4
  964.                      * @param array $terms
  965.                      * @param string $params['taxonomy']
  966.                      * @return array
  967.                      */
  968.                     $terms = apply_filters( 'avf_alb_taxonomy_values', $terms, $params['taxonomy'] );
  969.                 }
  970.                
  971.                 $this->current_page = ( $params['paginate'] != 'none' ) ? avia_get_current_pagination_number( 'avia-element-paging' ) : 1;
  972.                
  973.                 $term_args = array(
  974.                                 'taxonomy'      => $params['taxonomy'],
  975.                                 'hide_empty'    => true
  976.                             );
  977.                 /**
  978.                  * To display private posts you need to set 'hide_empty' to false,
  979.                  * otherwise a category with ONLY private posts will not be returned !!
  980.                  *
  981.                  * You also need to add post_status 'private' to the query params with filter avia_masonry_entries_query.
  982.                  *
  983.                  * @since 4.4.2
  984.                  * @added_by Günter
  985.                  * @param array $term_args
  986.                  * @param string $context
  987.                  * @param array $params
  988.                  * @param boolean $ajax
  989.                  * @return array
  990.                  */
  991.                 $term_args = apply_filters( 'avf_masonry_term_args', $term_args, 'query_entries', $params, $ajax );
  992.                
  993.                 //if we find no terms for the taxonomy fetch all taxonomy terms
  994.                 if( empty( $terms[0] ) || is_null( $terms[0] ) || $terms[0] === 'null' )
  995.                 {
  996.                     $allTax = AviaHelper::get_terms( $term_args );
  997.  
  998.                     $terms = array();
  999.                     foreach( $allTax as $tax )
  1000.                     {
  1001.                         if( is_object( $tax ) )
  1002.                         {
  1003.                             $terms[] = $tax->term_id;
  1004.                         }
  1005.                     }
  1006.                 }
  1007.                
  1008.                 if( ! empty( $params['taxonomy'] ) )
  1009.                 {
  1010.                     $allTax = AviaHelper::get_terms( $term_args );
  1011.                    
  1012.                     foreach( $allTax as $tax )
  1013.                     {
  1014.                         if( is_object( $tax ) )
  1015.                         {
  1016.                             $avialable_terms[] = $tax->term_id;
  1017.                         }
  1018.                     }
  1019.                 }
  1020.                
  1021.                 //check if any of the terms passed are valid. if not all existing terms are used
  1022.                 $valid_terms = array();
  1023.                 foreach( $terms as $term )
  1024.                 {
  1025.                     if( in_array( $term, $avialable_terms ) )
  1026.                     {
  1027.                         $valid_terms[] = $term;
  1028.                     }
  1029.                 }
  1030.                
  1031.                 if( ! empty( $valid_terms ) )
  1032.                 {
  1033.                     $terms = $valid_terms;
  1034.                     $this->atts['categories'] = implode( ',', $terms );
  1035.                 }
  1036.                 else
  1037.                 {
  1038.                     $terms = $avialable_terms;
  1039.                     $this->atts['categories'] = implode( ',', $terms );
  1040.                 }
  1041.                
  1042.                 if( empty( $params['post_type'] ) )
  1043.                 {
  1044.                     $params['post_type'] = get_post_types();
  1045.                 }
  1046.                
  1047.                 if( is_string( $params['post_type'] ) )
  1048.                 {
  1049.                     $params['post_type'] = explode( ',', $params['post_type'] );
  1050.                 }
  1051.  
  1052.                 //wordpress 4.4 offset fix. only necessary for ajax loading, therefore we ignore the page param
  1053.                 if( $params['offset'] == 0 )
  1054.                 {
  1055.                     $params['offset'] = false;
  1056.                 }
  1057.                      
  1058.                 $date_query = array();
  1059.                 if( 'date_filter' == $params['date_filter'] )
  1060.                 {
  1061.                     $date_query = AviaHelper::add_date_query( $date_query, $params['date_filter_start'], $params['date_filter_end'], $params['date_filter_format'] );
  1062.                 }
  1063.                
  1064.                 // Meta query - replaced by Tax query in WC 3.0.0
  1065.                 $meta_query = array();
  1066.                 $tax_query = array();
  1067.  
  1068.                 // check if taxonomy are set to product or product attributes
  1069.                 $tax = get_taxonomy( $params['taxonomy'] );
  1070.                
  1071.                 if( class_exists( 'WooCommerce' ) && is_object( $tax ) && isset( $tax->object_type ) && in_array( 'product', (array) $tax->object_type ) )
  1072.                 {
  1073.                     $avia_config['woocommerce']['disable_sorting_options'] = true;
  1074.                    
  1075.                     avia_wc_set_out_of_stock_query_params( $meta_query, $tax_query, $params['wc_prod_visible'] );
  1076.                     avia_wc_set_hidden_prod_query_params( $meta_query, $tax_query, $params['wc_prod_hidden'] );
  1077.                     avia_wc_set_featured_prod_query_params( $meta_query, $tax_query, $params['wc_prod_featured'] );
  1078.                    
  1079.                         //  sets filter hooks !!
  1080.                     $ordering_args = avia_wc_get_product_query_order_args( $params['prod_order_by'], $params['prod_order'] );
  1081.                            
  1082.                     $params['query_orderby'] = $ordering_args['orderby'];
  1083.                     $params['query_order'] = $ordering_args['order'];
  1084.                     $params['meta_key'] = $ordering_args['meta_key'];
  1085.                 }
  1086.  
  1087.                 if( ! empty( $terms ) )
  1088.                 {
  1089.                     $tax_query[] =  array(
  1090.                                         'taxonomy'  =>  $params['taxonomy'],
  1091.                                         'field'     =>  'id',
  1092.                                         'terms'     =>  $terms,
  1093.                                         'operator'  =>  'IN'
  1094.                                 );
  1095.                 }
  1096.  
  1097.                 $query = array( 'orderby'       =>  $params['query_orderby'],
  1098.                                 'order'         =>  $params['query_order'],
  1099.                                 'paged'         =>  $this->current_page,
  1100.                                 'post_type'     =>  $params['post_type'],
  1101.                                 'post_status'   =>  'publish',
  1102.                                 'offset'        =>  $params['offset'],
  1103.                                 'posts_per_page' => $params['items'],
  1104.                                 'meta_query'    =>  $meta_query,
  1105.                                 'tax_query'     =>  $tax_query,
  1106.                                 'date_query'    => $date_query
  1107.                             );
  1108.  
  1109.                 if( ! empty( $params['meta_key'] ) )
  1110.                 {
  1111.                     $query['meta_key'] = $params['meta_key'];
  1112.                 }
  1113.  
  1114.                 if( $params['query_orderby'] == 'rand' && isset( $_POST['loaded'] ) )
  1115.                 {
  1116.                     $query['post__not_in'] = $_POST['loaded'];
  1117.                     $query['offset'] = false;
  1118.                 }                                          
  1119.                    
  1120.             }
  1121.             else
  1122.             {
  1123.                 $query = $params['custom_query'];
  1124.             }
  1125.  
  1126.  
  1127.             /**
  1128.              * @used_by         avia_remove_bbpress_post_type_from_query        10      (bbPress)
  1129.              *                  avia_translate_ids_from_query                   10      (WPML)
  1130.              *                  avia_events_modify_recurring_event_query        10      (Tribe Events Pro)
  1131.              * @since < 4.0
  1132.              * @param array $query
  1133.              * @param array $params
  1134.              * @return array
  1135.              */
  1136.             $query = apply_filters( 'avia_masonry_entries_query', $query, $params );
  1137.  
  1138.             $this->entries = new WP_Query( $query );
  1139.            
  1140.             /**
  1141.              * @used_by         avia_events_modify_recurring_event_query        10      (Tribe Events Pro)
  1142.              *
  1143.              * @added_by Günter
  1144.              * @since 4.2.4
  1145.              */
  1146.             do_action( 'ava_after_masonry_entries_query' );
  1147.            
  1148.             $this->prepare_loop_from_entries( $ajax );
  1149.            
  1150.             if( function_exists( 'WC' ) )
  1151.             {
  1152.                 avia_wc_clear_catalog_ordering_args_filters();
  1153.                 $avia_config['woocommerce']['disable_sorting_options'] = false;
  1154.             }
  1155.  
  1156.         }
  1157.        
  1158.         /**
  1159.          *
  1160.          * @since < 4.0
  1161.          * @param array $params
  1162.          * @param boolean $ajax
  1163.          * @return void
  1164.          */
  1165.         public function query_entries_by_id( $params = array(), $ajax = false )
  1166.         {
  1167.             global $avia_config;
  1168.  
  1169.             if( empty( $params ) )
  1170.             {
  1171.                 $params = $this->atts;
  1172.             }
  1173.            
  1174.             $ids = is_array( $this->atts['ids'] ) ? $this->atts['ids'] : array_filter( explode( ',', $this->atts['ids'] ) );
  1175.            
  1176.             $this->current_page = ( $params['paginate'] != 'none' ) ? avia_get_current_pagination_number( 'avia-element-paging' ) : 1;
  1177.  
  1178.             if( $params['offset'] == 0 )
  1179.             {
  1180.                 $params['offset'] = false;
  1181.             }
  1182.            
  1183.             $query = array(
  1184.                             'post__in'          => $ids,
  1185.                             'post_status'       => 'inherit',
  1186.                             'post_type'         => 'attachment',
  1187.                             'post_mime_type'    => 'image',
  1188.                             'paged'             => $this->current_page,
  1189.                             'order'             => 'ASC',
  1190.                             'offset'            => $params['offset'],
  1191.                             'posts_per_page'    => $params['items'],
  1192.                             'orderby'           => 'post__in'
  1193.                         );
  1194.            
  1195.             /**
  1196.              * @used_by         avia_remove_bbpress_post_type_from_query        10      (bbPress)
  1197.              *                  avia_translate_ids_from_query                   10      (WPML)
  1198.              *                  avia_events_modify_recurring_event_query        10      (Tribe Events Pro)
  1199.              * @since < 4.0
  1200.              * @param array $query
  1201.              * @param array $params
  1202.              * @return array
  1203.              */
  1204.             $query = apply_filters( 'avia_masonry_entries_query', $query, $params );
  1205.  
  1206.             $this->entries = new WP_Query( $query );
  1207.            
  1208.             /**
  1209.              * @used_by         avia_events_modify_recurring_event_query        10      (Tribe Events Pro)
  1210.              *
  1211.              * @added_by Günter
  1212.              * @since 4.2.4
  1213.              */
  1214.             do_action( 'ava_after_masonry_entries_query' );
  1215.            
  1216.             $this->prepare_loop_from_entries( $ajax );
  1217.         }
  1218.     }
  1219. }
  1220.  
  1221.  
  1222.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement