Advertisement
cipher87

Post Slider with category-image-author-title-excerpt-more

Mar 25th, 2021
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 35.29 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Post Slider
  4.  *
  5.  * Display a Slideshow of Post Entries
  6.  * Element is in Beta and by default disabled. Todo: test with layerslider elements. currently throws error bc layerslider is only included if layerslider element is detected which is not the case with the post/page element
  7.  * Based on: 4.8.1
  8.  * Thread: https://kriesi.at/support/topic/blog-grid-with-full-info-and-elements/
  9.  */
  10. if ( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  11.  
  12.  
  13. if ( ! class_exists( 'avia_sc_postslider' ) )
  14. {
  15.     class avia_sc_postslider extends aviaShortcodeTemplate
  16.     {
  17.  
  18.         /**
  19.          * Create the config array for the shortcode button
  20.          */
  21.         function shortcode_insert_button()
  22.         {
  23.             $this->config['version']        = '1.0';
  24.             $this->config['self_closing']   = 'yes';
  25.             $this->config['base_element']   = 'yes';
  26.            
  27.             $this->config['name']           = __( 'Post Slider', 'avia_framework' );
  28.             $this->config['tab']            = __( 'Content Elements', 'avia_framework' );
  29.             $this->config['icon']           = AviaBuilder::$path['imagesURL'] . 'sc-postslider.png';
  30.             $this->config['order']          = 30;
  31.             $this->config['target']         = 'avia-target-insert';
  32.             $this->config['shortcode']      = 'av_postslider';
  33.             $this->config['tooltip']        = __( 'Display a Slideshow of Post Entries', 'avia_framework' );
  34.             $this->config['drag-level']     = 3;
  35.             $this->config['disabling_allowed'] = true;
  36.             $this->config['id_name']        = 'id';
  37.             $this->config['id_show']        = 'yes';
  38.             $this->config['alb_desc_id']    = 'alb_description';
  39.         }
  40.        
  41.         function extra_assets()
  42.         {
  43.             //load css
  44.             wp_enqueue_style( 'avia-module-slideshow', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/slideshow/slideshow.css', array( 'avia-layout' ), false );
  45.             wp_enqueue_style( 'avia-module-postslider', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/postslider/postslider.css', array( 'avia-module-slideshow' ), false );
  46.            
  47.                 //load js
  48.             wp_enqueue_script( 'avia-module-slideshow', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/slideshow/slideshow.js', array( 'avia-shortcodes' ), false, true );
  49.         }
  50.  
  51.         /**
  52.          * Popup Elements
  53.          *
  54.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  55.          * opens a modal window that allows to edit the element properties
  56.          *
  57.          * @return void
  58.          */
  59.         function popup_elements()
  60.         {
  61.             $this->elements = array(
  62.                
  63.                 array(
  64.                         'type'  => 'tab_container',
  65.                         'nodescription' => true
  66.                     ),
  67.                        
  68.                 array(
  69.                         'type'  => 'tab',
  70.                         'name'  => __( 'Content', 'avia_framework' ),
  71.                         'nodescription' => true
  72.                     ),
  73.                
  74.                     array(
  75.                             'type'          => 'template',
  76.                             'template_id'   => 'toggle_container',
  77.                             'templates_include' => array(
  78.                                                     $this->popup_key( 'content_slides' ),
  79.                                                     $this->popup_key( 'content_filter' ),
  80.                                                     $this->popup_key( 'content_excerpt' ),
  81.                                                 ),
  82.                             'nodescription' => true
  83.                         ),
  84.                
  85.                 array(
  86.                         'type'  => 'tab_close',
  87.                         'nodescription' => true
  88.                     ),
  89.                
  90.                 array(
  91.                         'type'  => 'tab',
  92.                         'name'  => __( 'Styling', 'avia_framework' ),
  93.                         'nodescription' => true
  94.                     ),
  95.                
  96.                     array(
  97.                             'type'          => 'template',
  98.                             'template_id'   => 'toggle_container',
  99.                             'templates_include' => array(
  100.                                                     $this->popup_key( 'styling_columns' ),
  101.                                                     $this->popup_key( 'styling_image' )
  102.                                                 ),
  103.                             'nodescription' => true
  104.                         ),
  105.                
  106.                 array(
  107.                         'type'  => 'tab_close',
  108.                         'nodescription' => true
  109.                     ),
  110.                
  111.                 array(
  112.                         'type'  => 'tab',
  113.                         'name'  => __( 'Advanced', 'avia_framework' ),
  114.                         'nodescription' => true
  115.                     ),
  116.                
  117.                     array(
  118.                             'type'  => 'toggle_container',
  119.                             'nodescription' => true
  120.                         ),
  121.                
  122.                         array(
  123.                                 'type'          => 'template',
  124.                                 'template_id'   => $this->popup_key( 'advanced_animation_slider' ),
  125.                                 'nodescription' => true
  126.                             ),
  127.                
  128.                         array(
  129.                                 'type'          => 'template',
  130.                                 'template_id'   => 'lazy_loading_toggle',
  131.                                 'lockable'      => true
  132.                             ),
  133.                
  134.                         array( 
  135.                                 'type'          => 'template',
  136.                                 'template_id'   => 'screen_options_toggle',
  137.                                 'lockable'      => true
  138.                             ),
  139.  
  140.                         array( 
  141.                                 'type'          => 'template',
  142.                                 'template_id'   => 'developer_options_toggle',
  143.                                 'args'          => array( 'sc' => $this )
  144.                             ),
  145.                
  146.                     array(
  147.                             'type'  => 'toggle_container_close',
  148.                             'nodescription' => true
  149.                         ),
  150.                
  151.                 array(
  152.                         'type'  => 'tab_close',
  153.                         'nodescription' => true
  154.                     ),
  155.                
  156.                 array( 
  157.                         'type'          => 'template',
  158.                         'template_id'   => 'element_template_selection_tab',
  159.                         'args'          => array( 'sc' => $this )
  160.                     ),
  161.  
  162.                 array(
  163.                         'type'  => 'tab_container_close',
  164.                         'nodescription' => true
  165.                     )
  166.                
  167.                 );
  168.            
  169.         }
  170.        
  171.         /**
  172.          * Create and register templates for easier maintainance
  173.          *
  174.          * @since 4.6.4
  175.          */
  176.         protected function register_dynamic_templates()
  177.         {
  178.            
  179.             /**
  180.              * Content Tab
  181.              * ===========
  182.              */
  183.            
  184.             $c = array(
  185.                         array(
  186.                             'name'  => __( 'Which Entries?', 'avia_framework' ),
  187.                             'desc'  => __( 'Select which entries should be displayed by selecting a taxonomy', 'avia_framework' ),
  188.                             'id'    => 'link',
  189.                             'type'  => 'linkpicker',
  190.                             'fetchTMPL' => true,
  191.                             'multiple'  => 6,
  192.                             'std'       => 'category',
  193.                             'lockable'  => true,
  194.                             'subtype'   => array( __( 'Display Entries from:', 'avia_framework' ) => 'taxonomy' )
  195.                         )
  196.                
  197.                 );
  198.            
  199.             if( current_theme_supports( 'add_avia_builder_post_type_option' ) )
  200.             {
  201.                 $element = array(  
  202.                                 'type'          => 'template',
  203.                                 'template_id'   => 'avia_builder_post_type_option',
  204.                                 'lockable'      => true,
  205.                             );
  206.                        
  207.                 array_unshift( $c, $element );
  208.             }
  209.            
  210.             $template = array(
  211.                             array( 
  212.                                 'type'          => 'template',
  213.                                 'template_id'   => 'toggle',
  214.                                 'title'         => __( 'Select Slide Content', 'avia_framework' ),
  215.                                 'content'       => $c
  216.                             ),
  217.                     );
  218.                
  219.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_slides' ), $template );
  220.            
  221.             $c = array(
  222.                         array( 
  223.                             'type'          => 'template',
  224.                             'template_id'   => 'wc_options_non_products',
  225.                             'lockable'      => true
  226.                         ),
  227.                
  228.                
  229.                         array( 
  230.                             'type'          => 'template',
  231.                             'template_id'   => 'date_query',
  232.                             'lockable'      => true
  233.                         ),
  234.                
  235.                         array(
  236.                             'name'  => __( 'Entry Number', 'avia_framework' ),
  237.                             'desc'  => __( 'How many items should be displayed?', 'avia_framework' ),
  238.                             'id'    => 'items',
  239.                             'type'  => 'select',
  240.                             'std'   => '9',
  241.                             'lockable'  => true,
  242.                             'subtype'   => AviaHtmlHelper::number_array( 1, 100, 1, array( 'All' => '-1' ) )
  243.                         ),
  244.  
  245.                         array(
  246.                             'name'  => __( 'Offset Number', 'avia_framework' ),
  247.                             'desc'  => __( 'The offset determines where the query begins pulling posts. Useful if you want to remove a certain number of posts because you already query them with another post slider element.', 'avia_framework' ),
  248.                             'id'    => 'offset',
  249.                             'type'  => 'select',
  250.                             'std'   => '0',
  251.                             'lockable'  => true,
  252.                             'subtype'   => AviaHtmlHelper::number_array( 1, 100, 1, array( __( 'Deactivate offset', 'avia_framework') => '0', __( 'Do not allow duplicate posts on the entire page (set offset automatically)', 'avia_framework' ) => 'no_duplicates' ) )
  253.                         )
  254.                 );
  255.            
  256.             $template = array(
  257.                             array( 
  258.                                 'type'          => 'template',
  259.                                 'template_id'   => 'toggle',
  260.                                 'title'         => __( 'Filters', 'avia_framework' ),
  261.                                 'content'       => $c
  262.                             ),
  263.                     );
  264.                
  265.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_filter' ), $template );
  266.            
  267.             $c = array(
  268.                         array(
  269.                             'name'  => __( 'Title and Excerpt', 'avia_framework' ),
  270.                             'desc'  => __( 'Choose if you want to only display the post title or title and excerpt', 'avia_framework' ),
  271.                             'id'    => 'contents',
  272.                             'type'  => 'select',
  273.                             'std'   => 'excerpt',
  274.                             'lockable'  => true,
  275.                             'subtype'   => array(
  276.                                                 __( 'Title and Excerpt', 'avia_framework' )                     => 'excerpt',
  277.                                                 __( 'Title and Excerpt + Read More Link', 'avia_framework' )    => 'excerpt_read_more',
  278.                                                 __( 'Only Title', 'avia_framework' )                            => 'title',
  279.                                                 __( 'Only Title + Read More Link', 'avia_framework' )           => 'title_read_more',
  280.                                                 __( 'Only excerpt', 'avia_framework' )                          => 'only_excerpt',
  281.                                                 __( 'Only excerpt + Read More Link', 'avia_framework' )         => 'only_excerpt_read_more',
  282.                                                 __( 'No Title and no excerpt', 'avia_framework' )               => 'no'
  283.                                             )
  284.                         ),
  285.                
  286.                 );
  287.            
  288.             $template = array(
  289.                             array( 
  290.                                 'type'          => 'template',
  291.                                 'template_id'   => 'toggle',
  292.                                 'title'         => __( 'Excerpt', 'avia_framework' ),
  293.                                 'content'       => $c
  294.                             ),
  295.                     );
  296.                
  297.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_excerpt' ), $template );
  298.            
  299.            
  300.             /**
  301.              * Styling Tab
  302.              * ===========
  303.              */
  304.            
  305.             $c = array(
  306.                         array(
  307.                             'name'  => __( 'Columns', 'avia_framework' ),
  308.                             'desc'  => __( 'How many columns should be displayed?', 'avia_framework' ),
  309.                             'id'    => 'columns',
  310.                             'type'  => 'select',
  311.                             'std'   => '3',
  312.                             'lockable'  => true,
  313.                             'subtype'   => array(  
  314.                                                 __( '1 Columns', 'avia_framework' ) => '1',
  315.                                                 __( '2 Columns', 'avia_framework' ) => '2',
  316.                                                 __( '3 Columns', 'avia_framework' ) => '3',
  317.                                                 __( '4 Columns', 'avia_framework' ) => '4',
  318.                                                 __( '5 Columns', 'avia_framework' ) => '5',
  319.                                             )
  320.                         )
  321.                
  322.                 );
  323.            
  324.             $template = array(
  325.                             array( 
  326.                                 'type'          => 'template',
  327.                                 'template_id'   => 'toggle',
  328.                                 'title'         => __( 'Columns', 'avia_framework' ),
  329.                                 'content'       => $c
  330.                             ),
  331.                     );
  332.                
  333.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_columns' ), $template );
  334.            
  335.             $c = array(
  336.                         array(
  337.                             'name'  => __( 'Preview Image Size', 'avia_framework' ),
  338.                             'desc'  => __( 'Set the image size of the preview images', 'avia_framework' ),
  339.                             'id'    => 'preview_mode',
  340.                             'type'  => 'select',
  341.                             'std'   => 'auto',
  342.                             'lockable'  => true,
  343.                             'subtype'   => array(
  344.                                                 __( 'Set the preview image size automatically based on column width', 'avia_framework' )    => 'auto',
  345.                                                 __( 'Choose the preview image size manually (select thumbnail size)', 'avia_framework' )    => 'custom'
  346.                                             )
  347.                         ),
  348.  
  349.                         array(
  350.                             'name'  => __( 'Select custom preview image size', 'avia_framework' ),
  351.                             'desc'  => __( 'Choose image size for Preview Image', 'avia_framework' ),
  352.                             'id'    => 'image_size',
  353.                             'type'  => 'select',
  354.                             'std'   => 'portfolio',
  355.                             'lockable'  => true,
  356.                             'required'  => array( 'preview_mode', 'equals', 'custom' ),
  357.                             'subtype'   =>  AviaHelper::get_registered_image_sizes( array( 'logo' ) )
  358.                         )
  359.                 );
  360.            
  361.             $template = array(
  362.                             array( 
  363.                                 'type'          => 'template',
  364.                                 'template_id'   => 'toggle',
  365.                                 'title'         => __( 'Preview Image', 'avia_framework' ),
  366.                                 'content'       => $c
  367.                             ),
  368.                     );
  369.                
  370.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_image' ), $template );
  371.            
  372.             /**
  373.              * Advanced Tab
  374.              * ===========
  375.              */
  376.            
  377.             $c = array(
  378. /*             
  379.                         array(
  380.                             'name'  => __( 'Post Slider Transition', 'avia_framework' ),
  381.                             'desc'  => __( 'Choose the transition for your Post Slider.', 'avia_framework' ),
  382.                             'id'    => 'animation',
  383.                             'type'  => 'select',
  384.                             'std'   => 'fade',
  385.                             'subtype'   => array(
  386.                                                 __( 'Slide', 'avia_framework' ) => 'slide',
  387.                                                 __( 'Fade', 'avia_framework' )  => 'fade'
  388.                                             ),
  389.                         ),
  390. */
  391.                
  392.                
  393.                         array(
  394.                             'name'  => __( 'Autorotation active?', 'avia_framework' ),
  395.                             'desc'  => __( 'Check if the slideshow should rotate by default', 'avia_framework' ),
  396.                             'id'    => 'autoplay',
  397.                             'type'  => 'select',
  398.                             'std'   => 'no',
  399.                             'lockable'  => true,
  400.                             'subtype'   => array(
  401.                                                 __( 'Yes', 'avia_framework' )   => 'yes',
  402.                                                 __( 'No', 'avia_framework' )    => 'no'
  403.                                             )
  404.                         ),
  405.  
  406.                         array(
  407.                             'name'  => __( 'Slideshow autorotation duration', 'avia_framework' ),
  408.                             'desc'  => __( 'Slideshow will rotate every X seconds', 'avia_framework' ),
  409.                             'id'    => 'interval',
  410.                             'type'  => 'select',
  411.                             'std'   => '5',
  412.                             'lockable'  => true,
  413.                             'required'  => array( 'autoplay', 'equals', 'yes' ),
  414.                             'subtype'   => array( '3'=>'3', '4'=>'4', '5'=>'5', '6'=>'6', '7'=>'7', '8'=>'8', '9'=>'9', '10'=>'10', '15'=>'15', '20'=>'20', '30'=>'30', '40'=>'40', '60'=>'60', '100'=>'100' )
  415.                         )
  416.                 );
  417.            
  418.             $template = array(
  419.                             array( 
  420.                                 'type'          => 'template',
  421.                                 'template_id'   => 'toggle',
  422.                                 'title'         => __( 'Slider Animation', 'avia_framework' ),
  423.                                 'content'       => $c
  424.                             ),
  425.                     );
  426.                
  427.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_animation_slider' ), $template );
  428.            
  429.         }
  430.  
  431.         /**
  432.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  433.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  434.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  435.          *
  436.          *
  437.          * @param array $params this array holds the default values for $content and $args.
  438.          * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  439.          */
  440.         function editor_element( $params )
  441.         {
  442.             $params = parent::editor_element( $params );
  443.             $params['content'] = null; //remove to allow content elements
  444.            
  445.             return $params;
  446.         }
  447.  
  448.         /**
  449.          * Frontend Shortcode Handler
  450.          *
  451.          * @param array $atts array of attributes
  452.          * @param string $content text within enclosing form of shortcode element
  453.          * @param string $shortcodename the shortcode found, when == callback name
  454.          * @return string $output returns the modified html string
  455.          */
  456.         function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' )
  457.         {  
  458.             $default = avia_post_slider::get_defaults();
  459.            
  460.             $locked = array();
  461.             Avia_Element_Templates()->set_locked_attributes( $atts, $this, $shortcodename, $default, $locked, $content );
  462.             Avia_Element_Templates()->add_template_class( $meta, $atts, $default );
  463.            
  464.             $screen_sizes = AviaHelper::av_mobile_sizes( $atts );
  465.            
  466.             if( isset( $atts['link'] ) )
  467.             {
  468.                 $atts['link'] = explode(',', $atts['link'], 2 );
  469.                 $atts['taxonomy'] = $atts['link'][0];
  470.  
  471.                 if( isset( $atts['link'][1] ) )
  472.                 {
  473.                     $atts['categories'] = $atts['link'][1];
  474.                 }
  475.             }
  476.  
  477.             $atts['class'] = $meta['el_class'];
  478.             $atts['el_id'] = $meta['custom_el_id'];
  479.            
  480.             $atts = array_merge( $atts, $screen_sizes );
  481.            
  482.             /**
  483.              * @since 4.5.5
  484.              * @return array
  485.              */
  486.             $atts = apply_filters( 'avf_post_slider_args', $atts, $this->config['shortcode'], $this );
  487.                    
  488.             $slider = new avia_post_slider( $atts );
  489.             $slider->query_entries();
  490.            
  491.             return $slider->html();
  492.         }
  493.  
  494.     }
  495. }
  496.  
  497.  
  498.  
  499.  
  500. if ( ! class_exists( 'avia_post_slider' ) )
  501. {
  502.     class avia_post_slider
  503.     {  
  504.         /**
  505.          * @since < 4.0
  506.          * @var int
  507.          */
  508.         static public $slide = 0;
  509.        
  510.         /**
  511.          *
  512.          * @since < 4.0
  513.          * @var array
  514.          */
  515.         protected $atts;
  516.        
  517.         /**
  518.          *
  519.          * @since < 4.0
  520.          * @var WP_Query
  521.          */
  522.         protected $entries;
  523.        
  524.         /**
  525.          *
  526.          * @since 4.7.6.4
  527.          * @var int
  528.          */
  529.         protected $current_page;
  530.  
  531.         /**
  532.          * @since < 4.0
  533.          * @param array $atts
  534.          */
  535.         public function __construct( $atts = array() )
  536.         {
  537.             $this->entries = array();
  538.             $this->current_page = 1;
  539.  
  540.             $this->atts = shortcode_atts( avia_post_slider::get_defaults(), $atts, 'av_postslider' );
  541.         }
  542.        
  543.        
  544.         /**
  545.          * @since 4.5.5
  546.          */
  547.         public function __destruct()
  548.         {
  549.             unset( $this->atts );
  550.             unset( $this->entries );
  551.         }
  552.        
  553.         /**
  554.          * Returns the defaults array
  555.          *
  556.          * @since 4.8
  557.          * @return array
  558.          */
  559.         static public function get_defaults()
  560.         {
  561.             $defaults = array(
  562.                             'type'              => 'slider', // can also be used as grid
  563.                             'style'             => '', //no_margin
  564.                             'columns'           => '4',
  565.                             'items'             => '16',
  566.                             'taxonomy'          => 'category',
  567.                             'wc_prod_visible'   => '',
  568.                             'wc_prod_hidden'    => '',
  569.                             'wc_prod_featured'  => '',
  570.                             'prod_order_by'     => '',
  571.                             'prod_order'        => '',
  572.                             'show_meta_data'    => '',      //  '' | 'always' | 'on_empty_title' | 'on_empty_content' (use filter to change)
  573.                             'post_type'         => get_post_types(),
  574.                             'contents'          => 'excerpt',
  575.                             'preview_mode'      => 'auto',
  576.                             'image_size'        => 'portfolio',
  577.                             'autoplay'          => 'no',
  578.                             'animation'         => 'fade',
  579.                             'paginate'          => 'no',
  580.                             'use_main_query_pagination' => 'no',
  581.                             'interval'          => 5,
  582.                             'class'             => '',
  583.                             'el_id'             => '',
  584.                             'categories'        => array(),
  585.                             'custom_query'      => array(),
  586.                             'offset'            => 0,
  587.                             'custom_markup'     => '',
  588.                             'av_display_classes'    => '',
  589.                             'date_filter'       => '', 
  590.                             'date_filter_start' => '',
  591.                             'date_filter_end'   => '',
  592.                             'date_filter_format'    => 'yy/mm/dd',      //  'yy/mm/dd' | 'dd-mm-yy' | yyyymmdd
  593.                             'lazy_loading'          => 'disabled'
  594.             );
  595.            
  596.             return $defaults;
  597.         }
  598.  
  599.         /**
  600.          *
  601.          * @since < 4.0
  602.          * @return string
  603.          */
  604.         public function html()
  605.         {
  606.             $output = '';
  607.  
  608.             if( empty( $this->entries ) || empty( $this->entries->posts ) )
  609.             {
  610.                 return $output;
  611.             }
  612.            
  613.             avia_post_slider::$slide ++;
  614.             extract( $this->atts );
  615.  
  616.             if( $preview_mode == 'auto' )
  617.             {
  618.                 $image_size = 'portfolio';
  619.             }
  620.            
  621.             $extraClass         = 'first';
  622.             $grid               = 'one_third';
  623.             $post_loop_count    = 1;
  624.             $loop_counter       = 1;
  625.             $autoplay           = $autoplay == 'no' ? false : true;
  626.             $total              = $columns % 2 ? 'odd' : 'even';
  627.             $blogstyle          = function_exists( 'avia_get_option' ) ? avia_get_option( 'blog_global_style', '' ) : '';
  628.             $excerpt_length     = 60;
  629.            
  630.            
  631.             if( $blogstyle !== '' )
  632.             {
  633.                 $excerpt_length = 240;
  634.             }
  635.            
  636.             switch( $columns )
  637.             {
  638.                 case '1':
  639.                     $grid = 'av_fullwidth';  
  640.                     if( $preview_mode == 'auto' )
  641.                     {
  642.                         $image_size = 'large';
  643.                     }
  644.                     break;
  645.                 case '2':
  646.                     $grid = 'av_one_half';  
  647.                     break;
  648.                 case '3':
  649.                     $grid = 'av_one_third';  
  650.                     break;
  651.                 case '4':
  652.                     $grid = 'av_one_fourth';
  653.                     if( $preview_mode == 'auto' )
  654.                     {
  655.                         $image_size = 'portfolio_small';
  656.                     }
  657.                     break;
  658.                 case '5':
  659.                     $grid = 'av_one_fifth';  
  660.                     if( $preview_mode == 'auto' )
  661.                     {
  662.                         $image_size = 'portfolio_small';
  663.                     }
  664.                     break;
  665.             }
  666.  
  667.  
  668.             $data = AviaHelper::create_data_string( array( 'autoplay' => $autoplay, 'interval' => $interval, 'animation' => $animation, 'show_slide_delay' => 90 ) );
  669.  
  670.             $thumb_fallback = '';
  671.             $markup = avia_markup_helper( array( 'context' => 'blog', 'echo' => false, 'custom_markup' => $custom_markup ) );
  672.             $output .= "<div {$el_id} {$data} class='avia-content-slider avia-content-{$type}-active avia-content-slider" . avia_post_slider::$slide . " avia-content-slider-{$total} {$class} {$av_display_classes}' $markup>";
  673.             $output .=      "<div class='avia-content-slider-inner'>";
  674.  
  675.             foreach( $this->entries->posts as $index => $entry )
  676.             {
  677.                 $the_id     = $entry->ID;
  678.                 $parity     = $loop_counter % 2 ? 'odd' : 'even';
  679.                 $last       = $this->entries->post_count == $post_loop_count ? ' post-entry-last ' : '';
  680.                 $post_class = "post-entry post-entry-{$the_id} slide-entry-overview slide-loop-{$post_loop_count} slide-parity-{$parity} {$last}";
  681.                 $link       = get_post_meta( $the_id , '_portfolio_custom_link', true ) != '' ? get_post_meta( $the_id , '_portfolio_custom_link_url', true ) : get_permalink( $the_id );
  682.                 $excerpt    = '';
  683.                 $title      = '';
  684.                 $show_meta  = ! is_post_type_hierarchical( $entry->post_type );
  685.                 $commentCount = get_comments_number( $the_id );
  686.                 $format     = get_post_format( $the_id );
  687.                
  688.                 $post_thumbnail_id = get_post_thumbnail_id( $the_id );
  689.                 if( $lazy_loading != 'enabled' )
  690.                 {
  691.                     Av_Responsive_Images()->add_attachment_id_to_not_lazy_loading( $post_thumbnail_id );
  692.                 }
  693.  
  694.                 $thumbnail = get_the_post_thumbnail( $the_id, $image_size );
  695.  
  696.                 if( empty( $format ) )
  697.                 {
  698.                     $format = 'standard';
  699.                 }
  700.  
  701.                 if( $thumbnail )
  702.                 {
  703.                     $thumb_fallback = $thumbnail;
  704.                     $thumb_class    = 'real-thumbnail';
  705.                 }
  706.                 else
  707.                 {
  708.                     $thumbnail = "<span class=' fallback-post-type-icon' " . av_icon_string($format).  "></span><span class='slider-fallback-image'>{{thumbnail}}</span>";
  709.                     $thumb_class = 'fake-thumbnail';
  710.                 }
  711.  
  712.  
  713.                 $permalink = '<div class="read-more-link"><a href="' . get_permalink( $the_id ) . '" class="more-link">' . __( 'Read more', 'avia_framework' ) . '<span class="more-link-arrow"></span></a></div>';
  714.                 $prepare_excerpt = ! empty( $entry->post_excerpt ) ? $entry->post_excerpt : avia_backend_truncate( $entry->post_content, apply_filters( 'avf_postgrid_excerpt_length', $excerpt_length ) , apply_filters( 'avf_postgrid_excerpt_delimiter' , ' ' ), '…', true, '' );
  715.  
  716.                 if( $format == 'link' )
  717.                 {
  718.                     $current_post = array();
  719.                     $current_post['content'] = $entry->post_content;
  720.                     $current_post['title'] = avia_wp_get_the_title( $entry );
  721.  
  722.                     if( function_exists( 'avia_link_content_filter' ) )
  723.                     {
  724.                         $current_post = avia_link_content_filter( $current_post );
  725.                     }
  726.  
  727.                     $link = $current_post['url'];
  728.                 }
  729.  
  730.                 switch( $contents )
  731.                 {
  732.                     case 'excerpt':
  733.                             $excerpt = $prepare_excerpt;
  734.                             $title = avia_wp_get_the_title( $entry );
  735.                             break;
  736.                     case 'excerpt_read_more':
  737.                             $excerpt = $prepare_excerpt;
  738.                             $excerpt .= $permalink;
  739.                             $title = avia_wp_get_the_title( $entry );
  740.                             break;
  741.                     case 'title':
  742.                             $excerpt = '';
  743.                             $title = avia_wp_get_the_title( $entry );
  744.                             break;
  745.                     case 'title_read_more':
  746.                             $excerpt = $permalink;
  747.                             $title = avia_wp_get_the_title( $entry );
  748.                             break;
  749.                     case 'only_excerpt':
  750.                             $excerpt = $prepare_excerpt;
  751.                             $title = '';
  752.                             break;
  753.                     case 'only_excerpt_read_more':
  754.                             $excerpt = $prepare_excerpt;
  755.                             $excerpt .= $permalink;
  756.                             $title = '';
  757.                             break;
  758.                     case 'no':
  759.                             $excerpt = '';
  760.                             $title = '';
  761.                             break;
  762.                 }
  763.  
  764.                 /**
  765.                  * @since < 4.0
  766.                  * @param string $title
  767.                  * @param WP_Post $entry
  768.                  * @return string
  769.                  */
  770.                 $title = apply_filters( 'avf_postslider_title', $title, $entry );
  771.                
  772.                
  773.                 /**
  774.                  * @since 4.7.3.1
  775.                  * @param string $image_link_title
  776.                  * @param WP_Post $entry
  777.                  * @return string
  778.                  */
  779.                 $image_link_title = apply_filters( 'avf_postslider_link_title_attr', esc_attr( avia_wp_get_the_title( $entry ) ), $entry );
  780.                
  781.                
  782.  
  783.                 if( $loop_counter == 1 )
  784.                 {
  785.                     $output .= "<div class='slide-entry-wrap'>";
  786.                 }
  787.                
  788.                 $post_format = get_post_format( $the_id ) ? get_post_format( $the_id ) : 'standard';
  789.  
  790.                 $markup = avia_markup_helper( array( 'context' => 'entry', 'echo' => false, 'id' => $the_id, 'custom_markup' => $custom_markup ) );
  791.                 $output .= "<article class='slide-entry flex_column {$style} {$post_class} {$grid} {$extraClass} {$thumb_class} post-format-{$post_format}' $markup>";
  792.                    
  793.                 if( $post_format == 'audio' )
  794.                 {  
  795.                     $current_post = array();
  796.                     $current_post['content'] = $entry->post_content;
  797.                     $current_post['title'] = avia_wp_get_the_title( $entry );
  798.                     $current_post['id'] = $entry->ID;
  799.  
  800.                     $current_post = apply_filters( 'post-format-' . $post_format, $current_post, $entry );
  801.  
  802.                     if( ! empty( $current_post['before_content'] ) )
  803.                     {
  804.                         $output .= '<div class="big-preview single-big audio-preview">' . $current_post['before_content'] . '</div>';
  805.                     }
  806.                 }
  807.                    
  808.                 $output .= "<div class='slide-content'>";
  809.  
  810.                 $markup = avia_markup_helper( array( 'context' => 'entry_title', 'echo' => false, 'id' => $the_id, 'custom_markup' => $custom_markup ) );
  811.                 $output .= '<header class="entry-content-header">';
  812.                 $meta_out = '';
  813.  
  814.                 if( ! empty( $title ) || in_array( $show_meta_data, array( 'always', 'on_empty_title' ) ) )
  815.                 {
  816.                     if( $show_meta )
  817.                     {
  818.                         $taxonomies  = get_object_taxonomies( get_post_type( $the_id ) );
  819.                         $cats = '';
  820.                         $excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array( 'post_tag', 'post_format' ) );
  821.                         $excluded_taxonomies = apply_filters( 'avf_exclude_taxonomies', $excluded_taxonomies, get_post_type( $the_id ), $the_id );
  822.  
  823.                         if( ! empty( $taxonomies ) )
  824.                         {
  825.                             foreach( $taxonomies as $taxonomy )
  826.                             {
  827.                                 if( ! in_array( $taxonomy, $excluded_taxonomies ) )
  828.                                 {
  829.                                     $cats .= get_the_term_list( $the_id, $taxonomy, '', ', ', '' ) . ' ';
  830.                                 }
  831.                             }
  832.                         }
  833.                        
  834.                         if( ! empty( $cats ) )
  835.                         {
  836.                             $meta_out .= '<span class="blog-categories minor-meta">';
  837.                             $meta_out .=    $cats;
  838.                             $meta_out .= '</span>';
  839.                         }
  840.                     }
  841.                        
  842.                     /**
  843.                      * Allow to change default output of categories - by default supressed for setting Default(Business) blog style
  844.                      *
  845.                      * @since 4.0.6
  846.                      * @param string $blogstyle                     '' | 'elegant-blog' | 'elegant-blog modern-blog'
  847.                      * @param avia_post_slider $this
  848.                      * @return string                               'show_elegant' | 'show_business' | 'use_theme_default' | 'no_show_cats'
  849.                      */
  850.                     $show_cats = apply_filters( 'avf_postslider_show_catergories', 'use_theme_default', $blogstyle, $this );
  851.                    
  852.                     switch( $show_cats )
  853.                     {
  854.                         case 'no_show_cats':
  855.                             $new_blogstyle = '';
  856.                             break;
  857.                         case 'show_elegant':
  858.                             $new_blogstyle = 'elegant-blog';
  859.                             break;
  860.                         case 'show_business':
  861.                             $new_blogstyle = 'elegant-blog modern-blog';
  862.                             break;
  863.                         case 'use_theme_default':
  864.                         default:
  865.                             $new_blogstyle = $blogstyle;
  866.                             break;
  867.                     }
  868.                        
  869.                     $output .= $meta_out;
  870.                     $output .= $thumbnail ? "<a href='{$link}' data-rel='slide-" . avia_post_slider::$slide . "' class='slide-image' title='{$image_link_title}'>{$thumbnail}</a>" : '';
  871.  
  872.                     $default_heading = 'h3';
  873.                     $args = array(
  874.                                 'heading'       => $default_heading,
  875.                                 'extra_class'   => ''
  876.                             );
  877.  
  878.                     $extra_args = array( $this, $index, $entry );
  879.  
  880.                     /**
  881.                      * @since 4.5.5
  882.                      * @return array
  883.                      */
  884.                     $args = apply_filters( 'avf_customize_heading_settings', $args, __CLASS__, $extra_args );
  885.  
  886.                     $heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  887.                     $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
  888.  
  889.                     $output .=  "<{$heading} class='slide-entry-title entry-title {$css}' $markup><a href='{$link}' title='" . esc_attr( strip_tags( $title ) ) . "'>{$title}</a></{$heading}>";
  890.                     $output .= '<span class="av-vertical-delimiter"></span>';
  891.                 }
  892.                    
  893.                 $output .= '</header>';
  894.  
  895.                 $meta = "<div class='slide-meta'>";
  896.                     $meta .= "<div class='slide-meta-author'>";
  897.                         $meta .= get_the_author_meta( 'display_name', $entry->post_author );
  898.                     $meta .= '</div>';
  899.                 $meta .= '</div>';
  900.                
  901.                 $output .= $meta;
  902.  
  903.                 $markup = avia_markup_helper( array( 'context' => 'entry_content', 'echo' => false, 'id' => $the_id, 'custom_markup' => $custom_markup ) );
  904.                 $excerpt = apply_filters( 'avf_post_slider_entry_excerpt', $excerpt, $prepare_excerpt, $permalink, $entry );
  905.                 $output .= ! empty( $excerpt ) ? "<div class='slide-entry-excerpt entry-content' {$markup}>{$excerpt}</div>" : '';
  906.  
  907.                 $output .= '</div>';
  908.  
  909.                 $output .= av_blog_entry_markup_helper( $the_id );
  910.  
  911.                 $output .= '</article>';
  912.  
  913.                 $loop_counter ++;
  914.                 $post_loop_count ++;
  915.                 $extraClass = '';
  916.  
  917.                 if( $loop_counter > $columns )
  918.                 {
  919.                     $loop_counter = 1;
  920.                     $extraClass = 'first';
  921.                 }
  922.  
  923.                 if( $loop_counter == 1 || ! empty( $last ) )
  924.                 {
  925.                     $output .= '</div>';
  926.                 }
  927.             }
  928.  
  929.             $output .=      '</div>';
  930.  
  931.             if( $post_loop_count -1 > $columns && $type == 'slider' )
  932.             {
  933.                 $output .= $this->slide_navigation_arrows();
  934.             }
  935.            
  936.             global $wp_query;
  937.            
  938.             $avia_pagination = '';
  939.            
  940.             if( $use_main_query_pagination == 'yes' && $paginate == 'yes' )
  941.             {
  942.                 $avia_pagination = avia_pagination( $wp_query->max_num_pages, 'nav' );
  943.             }
  944.             else if( $paginate == 'yes' )
  945.             {
  946.                 $avia_pagination = avia_pagination( $this->entries, 'nav', 'avia-element-paging', $this->current_page );
  947.             }
  948.  
  949.             if( ! empty( $avia_pagination ) )
  950.             {
  951.                 $output .= "<div class='pagination-wrap pagination-slider'>{$avia_pagination}</div>";
  952.             }
  953.  
  954.  
  955.             $output .= '</div>';
  956.  
  957.             $output = str_replace( '{{thumbnail}}', $thumb_fallback, $output );
  958.  
  959.             wp_reset_query();
  960.             return $output;
  961.         }
  962.  
  963.         /**
  964.          * @since < 4.0
  965.          * @return string
  966.          */
  967.         protected function slide_navigation_arrows()
  968.         {
  969.             $html  = '';
  970.             $html .= "<div class='avia-slideshow-arrows avia-slideshow-controls'>";
  971.             $html .=    "<a href='#prev' class='prev-slide' " . av_icon_string( 'prev_big' ) .'>' . __( 'Previous', 'avia_framework' ) . '</a>';
  972.             $html .=    "<a href='#next' class='next-slide' " . av_icon_string( 'next_big' ) . '>' . __( 'Next', 'avia_framework' ) . '</a>';
  973.             $html .= '</div>';
  974.  
  975.             return $html;
  976.         }
  977.  
  978.         /**
  979.          * Fetch new entries
  980.          *
  981.          * @since < 4.0
  982.          * @param array $params
  983.          */
  984.         public function query_entries( $params = array() )
  985.         {  
  986.             global $avia_config;
  987.  
  988.             if( empty( $params ) )
  989.             {
  990.                 $params = $this->atts;
  991.             }
  992.  
  993.             if( empty( $params['custom_query'] ) )
  994.             {
  995.                 $query = array();
  996.  
  997.                 if( ! empty( $params['categories'] ) )
  998.                 {
  999.                     //get the portfolio categories
  1000.                     $terms  = explode( ',', $params['categories'] );
  1001.                 }
  1002.                
  1003.                 if( $params['use_main_query_pagination'] == 'yes' )
  1004.                 {
  1005.                     $this->current_page = ( $params['paginate'] != 'no' ) ? avia_get_current_pagination_number() : 1;
  1006.                 }
  1007.                 else
  1008.                 {
  1009.                     $this->current_page = ( $params['paginate'] != 'no' ) ? avia_get_current_pagination_number( 'avia-element-paging' ) : 1;
  1010.                 }
  1011.  
  1012.                 //if we find no terms for the taxonomy fetch all taxonomy terms
  1013.                 if( empty( $terms[0] ) || is_null( $terms[0] ) || $terms[0] === 'null' )
  1014.                 {
  1015.                    
  1016.                     $term_args = array(
  1017.                                 'taxonomy'      => $params['taxonomy'],
  1018.                                 'hide_empty'    => true
  1019.                             );
  1020.                     /**
  1021.                      * To display private posts you need to set 'hide_empty' to false,
  1022.                      * otherwise a category with ONLY private posts will not be returned !!
  1023.                      *
  1024.                      * You also need to add post_status 'private' to the query params with filter avia_post_slide_query.
  1025.                      *
  1026.                      * @since 4.4.2
  1027.                      * @added_by Günter
  1028.                      * @param array $term_args
  1029.                      * @param array $params
  1030.                      * @return array
  1031.                      */
  1032.                     $term_args = apply_filters( 'avf_av_postslider_term_args', $term_args, $params );
  1033.  
  1034.                     $allTax = AviaHelper::get_terms( $term_args );
  1035.                    
  1036.                     $terms = array();
  1037.                     foreach( $allTax as $tax )
  1038.                     {
  1039.                         $terms[] = $tax->term_id;
  1040.                     }
  1041.  
  1042.                 }
  1043.  
  1044.                 if( $params['offset'] == 'no_duplicates' )
  1045.                 {
  1046.                     $params['offset'] = false;
  1047.                     $no_duplicates = true;
  1048.                 }
  1049.                
  1050.                
  1051.                 //wordpress 4.4 offset fix
  1052.                 if( $params['offset'] == 0 )
  1053.                 {
  1054.                     $params['offset'] = false;
  1055.                 }
  1056.                 else
  1057.                 {  
  1058.                     //if the offset is set the paged param is ignored. therefore we need to factor in the page number
  1059.                     $params['offset'] = $params['offset'] + ( ( $this->current_page - 1 ) * $params['items'] );
  1060.                 }
  1061.                
  1062.                
  1063.                 if( empty( $params['post_type'] ) )
  1064.                 {
  1065.                     $params['post_type'] = get_post_types();
  1066.                 }
  1067.                
  1068.                 if( is_string($params['post_type'] ) )
  1069.                 {
  1070.                     $params['post_type'] = explode( ',', $params['post_type'] );
  1071.                 }
  1072.  
  1073.                 $orderby = 'date';
  1074.                 $order = 'DESC';
  1075.                
  1076.                 $date_query = array();
  1077.                 if( 'date_filter' == $params['date_filter'] )
  1078.                 {
  1079.                     $date_query = AviaHelper::add_date_query( $date_query, $params['date_filter_start'], $params['date_filter_end'], $params['date_filter_format'] );
  1080.                 }
  1081.                
  1082.                 // Meta query - replaced by Tax query in WC 3.0.0
  1083.                 $meta_query = array();
  1084.                 $tax_query = array();
  1085.                
  1086.  
  1087.                 // check if taxonomy are set to product or product attributes
  1088.                 $tax = get_taxonomy( $params['taxonomy'] );
  1089.                
  1090.                 if( class_exists( 'WooCommerce' ) && is_object( $tax ) && isset( $tax->object_type ) && in_array( 'product', (array) $tax->object_type ) )
  1091.                 {
  1092.                     $avia_config['woocommerce']['disable_sorting_options'] = true;
  1093.                    
  1094.                     avia_wc_set_out_of_stock_query_params( $meta_query, $tax_query, $params['wc_prod_visible'] );
  1095.                     avia_wc_set_hidden_prod_query_params( $meta_query, $tax_query, $params['wc_prod_hidden'] );
  1096.                     avia_wc_set_featured_prod_query_params( $meta_query, $tax_query, $params['wc_prod_featured'] );
  1097.                    
  1098.                         //  sets filter hooks !!
  1099.                     $ordering_args = avia_wc_get_product_query_order_args( $params['prod_order_by'], $params['prod_order'] );
  1100.                            
  1101.                     $orderby = $ordering_args['orderby'];
  1102.                     $order = $ordering_args['order'];
  1103.                     $params['meta_key'] = $ordering_args['meta_key'];
  1104.                 }
  1105.  
  1106.                 if( ! empty( $terms ) )
  1107.                 {
  1108.                     $tax_query[] =  array(
  1109.                                         'taxonomy'  =>  $params['taxonomy'],
  1110.                                         'field'     =>  'id',
  1111.                                         'terms'     =>  $terms,
  1112.                                         'operator'  =>  'IN'
  1113.                                 );
  1114.                 }              
  1115.                
  1116.                 $query = array(
  1117.                                 'orderby'       => $orderby,
  1118.                                 'order'         => $order,
  1119.                                 'paged'         => $this->current_page,
  1120.                                 'post_type'     => $params['post_type'],
  1121. //                              'post_status'   => 'publish',
  1122.                                 'offset'        => $params['offset'],
  1123.                                 'posts_per_page' => $params['items'],
  1124.                                 'post__not_in'  => ( ! empty( $no_duplicates ) ) ? $avia_config['posts_on_current_page'] : array(),
  1125.                                 'meta_query'    => $meta_query,
  1126.                                 'tax_query'     => $tax_query,
  1127.                                 'date_query'    => $date_query
  1128.                             );
  1129.                                                                
  1130.             }
  1131.             else
  1132.             {
  1133.                 $query = $params['custom_query'];
  1134.             }
  1135.            
  1136.             if( ! empty( $params['meta_key'] ) )
  1137.             {
  1138.                 $query['meta_key'] = $params['meta_key'];
  1139.             }
  1140.  
  1141.             /**
  1142.              * @used_by             config-bbpress\config.php   avia_remove_bbpress_post_type_from_query()          10
  1143.              * @used_by             config-wpml\config.php      avia_translate_ids_from_query                       10
  1144.              *
  1145.              * @since < 4.0
  1146.              * @param array $query
  1147.              * @param array $params
  1148.              * @return array
  1149.              */
  1150.             $query = apply_filters( 'avia_post_slide_query', $query, $params );
  1151.  
  1152.             @$this->entries = new WP_Query( $query ); //@ is used to prevent errors caused by wpml
  1153.  
  1154.             // store the queried post ids in
  1155.             if( $this->entries->post_count > 0 )
  1156.             {
  1157.                 foreach( $this->entries->posts as $entry )
  1158.                 {
  1159.                     $avia_config['posts_on_current_page'][] = $entry->ID;
  1160.                 }
  1161.             }
  1162.            
  1163.             if( function_exists( 'WC' ) )
  1164.             {
  1165.                 avia_wc_clear_catalog_ordering_args_filters();
  1166.                 $avia_config['woocommerce']['disable_sorting_options'] = false;
  1167.             }
  1168.         }
  1169.     }
  1170. }
  1171.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement