Advertisement
cipher87

Post Slider with aria-label

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