Guenni007

postslider

Aug 31st, 2025 (edited)
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 34.39 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Post Slider
  4.  *
  5.  * Display a slideshow or grid of Post Entries
  6.  *
  7.  * 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
  8.  *
  9.  * This class does not support post css files
  10.  * ==========================================
  11.  */
  12. if( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  13.  
  14.  
  15. if( ! class_exists( 'avia_sc_postslider', false ) )
  16. {
  17.     class avia_sc_postslider extends aviaShortcodeTemplate
  18.     {
  19.         /**
  20.          * Create the config array for the shortcode button
  21.          */
  22.         protected function shortcode_insert_button()
  23.         {
  24.             $this->config['version']        = '1.0';
  25.             $this->config['self_closing']   = 'yes';
  26.             $this->config['base_element']   = 'yes';
  27.  
  28.             $this->config['name']           = __( 'Post Slider', 'avia_framework' );
  29.             $this->config['tab']            = __( 'Content Elements', 'avia_framework' );
  30.             $this->config['icon']           = AviaBuilder::$path['imagesURL'] . 'sc-postslider.png';
  31.             $this->config['order']          = 30;
  32.             $this->config['target']         = 'avia-target-insert';
  33.             $this->config['shortcode']      = 'av_postslider';
  34.             $this->config['tooltip']        = __( 'Display a Slideshow of Post Entries', 'avia_framework' );
  35.             $this->config['drag-level']     = 3;
  36.             $this->config['disabling_allowed'] = true;
  37.             $this->config['id_name']        = 'id';
  38.             $this->config['id_show']        = 'yes';
  39.             $this->config['alb_desc_id']    = 'alb_description';
  40.         }
  41.  
  42.         protected function extra_assets()
  43.         {
  44.             $ver = Avia_Builder()->get_theme_version();
  45.             $min_js = avia_minify_extension( 'js' );
  46.             $min_css = avia_minify_extension( 'css' );
  47.  
  48.             //load css
  49.             wp_enqueue_style( 'avia-module-slideshow', AviaBuilder::$path['pluginUrlRoot'] . "avia-shortcodes/slideshow/slideshow{$min_css}.css", array( 'avia-layout' ), $ver );
  50.             wp_enqueue_style( 'avia-module-postslider', AviaBuilder::$path['pluginUrlRoot'] . "avia-shortcodes/postslider/postslider{$min_css}.css", array( 'avia-module-slideshow' ), $ver );
  51.  
  52.                 //load js
  53.             wp_enqueue_script( 'avia-module-slideshow', AviaBuilder::$path['pluginUrlRoot'] . "avia-shortcodes/slideshow/slideshow{$min_js}.js", array( 'avia-shortcodes' ), $ver, true );
  54.         }
  55.  
  56.         /**
  57.          * Popup Elements
  58.          *
  59.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  60.          * opens a modal window that allows to edit the element properties
  61.          *
  62.          * @return void
  63.          */
  64.         protected function popup_elements()
  65.         {
  66.             $this->elements = array(
  67.  
  68.                 array(
  69.                         'type'  => 'tab_container',
  70.                         'nodescription' => true
  71.                     ),
  72.  
  73.                 array(
  74.                         'type'  => 'tab',
  75.                         'name'  => __( 'Content', 'avia_framework' ),
  76.                         'nodescription' => true
  77.                     ),
  78.  
  79.                     array(
  80.                             'type'          => 'template',
  81.                             'template_id'   => 'toggle_container',
  82.                             'templates_include' => array(
  83.                                                     $this->popup_key( 'content_slides' ),
  84.                                                     $this->popup_key( 'content_filter' ),
  85.                                                     $this->popup_key( 'content_excerpt' ),
  86.                                                 ),
  87.                             'nodescription' => true
  88.                         ),
  89.  
  90.                 array(
  91.                         'type'  => 'tab_close',
  92.                         'nodescription' => true
  93.                     ),
  94.  
  95.                 array(
  96.                         'type'  => 'tab',
  97.                         'name'  => __( 'Styling', 'avia_framework' ),
  98.                         'nodescription' => true
  99.                     ),
  100.  
  101.                     array(
  102.                             'type'          => 'template',
  103.                             'template_id'   => 'toggle_container',
  104.                             'templates_include' => array(
  105.                                                     $this->popup_key( 'styling_columns' ),
  106.                                                     $this->popup_key( 'styling_image' ),
  107.                                                     $this->popup_key( 'styling_navigation' )
  108.                                                 ),
  109.                             'nodescription' => true
  110.                         ),
  111.  
  112.                 array(
  113.                         'type'  => 'tab_close',
  114.                         'nodescription' => true
  115.                     ),
  116.  
  117.                 array(
  118.                         'type'  => 'tab',
  119.                         'name'  => __( 'Advanced', 'avia_framework' ),
  120.                         'nodescription' => true
  121.                     ),
  122.  
  123.                     array(
  124.                             'type'  => 'toggle_container',
  125.                             'nodescription' => true
  126.                         ),
  127.  
  128.                         array(
  129.                                 'type'          => 'template',
  130.                                 'template_id'   => $this->popup_key( 'advanced_animation_slider' ),
  131.                                 'nodescription' => true
  132.                             ),
  133.  
  134.                         array(
  135.                                 'type'          => 'template',
  136.                                 'template_id'   => 'lazy_loading_toggle',
  137.                                 'lockable'      => true
  138.                             ),
  139.  
  140.                         array(
  141.                                 'type'          => 'template',
  142.                                 'template_id'   => 'screen_options_toggle',
  143.                                 'lockable'      => true
  144.                             ),
  145.  
  146.                         array(
  147.                                 'type'          => 'template',
  148.                                 'template_id'   => 'developer_options_toggle',
  149.                                 'args'          => array( 'sc' => $this )
  150.                             ),
  151.  
  152.                     array(
  153.                             'type'  => 'toggle_container_close',
  154.                             'nodescription' => true
  155.                         ),
  156.  
  157.                 array(
  158.                         'type'  => 'tab_close',
  159.                         'nodescription' => true
  160.                     ),
  161.  
  162.                 array(
  163.                         'type'          => 'template',
  164.                         'template_id'   => 'element_template_selection_tab',
  165.                         'args'          => array( 'sc' => $this )
  166.                     ),
  167.  
  168.                 array(
  169.                         'type'  => 'tab_container_close',
  170.                         'nodescription' => true
  171.                     )
  172.  
  173.                 );
  174.  
  175.         }
  176.  
  177.         /**
  178.          * Create and register templates for easier maintainance
  179.          *
  180.          * @since 4.6.4
  181.          */
  182.         protected function register_dynamic_templates()
  183.         {
  184.  
  185.             /**
  186.              * Content Tab
  187.              * ===========
  188.              */
  189.  
  190.             $c = array(
  191.                         array(
  192.                             'name'      => __( 'Which Entries Should Be Used', 'avia_framework' ),
  193.                             'desc'      => __( 'Select which entries should be displayed by selecting a taxonomy', 'avia_framework' ),
  194.                             'id'        => 'link',
  195.                             'type'      => 'linkpicker',
  196.                             'fetchTMPL' => true,
  197.                             'multiple'  => 6,
  198.                             'std'       => 'category',
  199.                             'lockable'  => true,
  200.                             'subtype'   => array( __( 'Display Entries from:', 'avia_framework' ) => 'taxonomy' )
  201.                         ),
  202.  
  203.                         array(
  204.                             'name'      => __( 'Multiple Categories/Terms Relation', 'avia_framework' ),
  205.                             'desc'      => __( 'Select to use an OR or AND relation. In AND an entry must be in all selected categories/terms to be displayed. Defaults to OR', 'avia_framework' ),
  206.                             'id'        => 'term_rel',
  207.                             'type'      => 'select',
  208.                             'std'       => '',
  209.                             'lockable'  => true,
  210.                             'subtype'   => array(
  211.                                                 __( 'OR', 'avia_framework' )    => '',
  212.                                                 __( 'AND', 'avia_framework' )   => 'AND'
  213.                                             )
  214.                         )
  215.  
  216.                 );
  217.  
  218.             if( current_theme_supports( 'add_avia_builder_post_type_option' ) )
  219.             {
  220.                 $element = array(
  221.                                 'type'          => 'template',
  222.                                 'template_id'   => 'avia_builder_post_type_option',
  223.                                 'lockable'      => true,
  224.                             );
  225.  
  226.                 array_unshift( $c, $element );
  227.             }
  228.  
  229.             $template = array(
  230.                             array(
  231.                                 'type'          => 'template',
  232.                                 'template_id'   => 'toggle',
  233.                                 'title'         => __( 'Entries', 'avia_framework' ),
  234.                                 'content'       => $c
  235.                             ),
  236.                     );
  237.  
  238.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_slides' ), $template );
  239.  
  240.             $c = array(
  241.                         array(
  242.                             'type'          => 'template',
  243.                             'template_id'   => 'wc_options_non_products',
  244.                             'lockable'      => true
  245.                         ),
  246.  
  247.  
  248.                         array(
  249.                             'type'          => 'template',
  250.                             'template_id'   => 'date_query',
  251.                             'lockable'      => true,
  252.                             'period'        => true
  253.                         ),
  254.  
  255.                         array(
  256.                             'name'      => __( 'Entry Number', 'avia_framework' ),
  257.                             'desc'      => __( 'How many items should be displayed?', 'avia_framework' ),
  258.                             'id'        => 'items',
  259.                             'type'      => 'select',
  260.                             'std'       => '9',
  261.                             'lockable'  => true,
  262.                             'subtype'   => AviaHtmlHelper::number_array( 1, 100, 1, array( 'All' => '-1' ) )
  263.                         ),
  264.  
  265.                         array(
  266.                             'name'      => __( 'Offset Number', 'avia_framework' ),
  267.                             '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' ),
  268.                             'id'        => 'offset',
  269.                             'type'      => 'select',
  270.                             'std'       => '0',
  271.                             'lockable'  => true,
  272.                             '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' ) )
  273.                         ),
  274.  
  275.                         array(
  276.                             'type'          => 'template',
  277.                             'template_id'   => 'page_element_filter',
  278.                             'lockable'      => true
  279.                         )
  280.                 );
  281.  
  282.             $template = array(
  283.                             array(
  284.                                 'type'          => 'template',
  285.                                 'template_id'   => 'toggle',
  286.                                 'title'         => __( 'Filters', 'avia_framework' ),
  287.                                 'content'       => $c
  288.                             ),
  289.                     );
  290.  
  291.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_filter' ), $template );
  292.  
  293.             $c = array(
  294.                         array(
  295.                             'name'      => __( 'Slide Content', 'avia_framework' ),
  296.                             'desc'      => __( 'Select what information you want to display', 'avia_framework' ),
  297.                             'id'        => 'contents',
  298.                             'type'      => 'select',
  299.                             'std'       => 'excerpt',
  300.                             'lockable'  => true,
  301.                             'subtype'   => array(
  302.                                                 __( 'Title and Excerpt', 'avia_framework' )                 => 'excerpt',
  303.                                                 __( 'Title, Excerpt and Read More Link', 'avia_framework' ) => 'excerpt_read_more',
  304.                                                 __( 'Only Title', 'avia_framework' )                        => 'title',
  305.                                                 __( 'Title and Read More Link', 'avia_framework' )          => 'title_read_more',
  306.                                                 __( 'Only Excerpt', 'avia_framework' )                      => 'only_excerpt',
  307.                                                 __( 'Excerpt and Read More Link', 'avia_framework' )        => 'only_excerpt_read_more',
  308.                                                 __( 'No Title, no Excerpt', 'avia_framework' )              => 'no'
  309.                                             )
  310.                         ),
  311.  
  312.                 );
  313.  
  314.             $template = array(
  315.                             array(
  316.                                 'type'          => 'template',
  317.                                 'template_id'   => 'toggle',
  318.                                 'title'         => __( 'Content', 'avia_framework' ),
  319.                                 'content'       => $c
  320.                             ),
  321.                     );
  322.  
  323.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_excerpt' ), $template );
  324.  
  325.  
  326.             /**
  327.              * Styling Tab
  328.              * ===========
  329.              */
  330.  
  331.             $c = array(
  332.                         array(
  333.                             'name'      => __( 'Columns', 'avia_framework' ),
  334.                             'desc'      => __( 'How many columns should be displayed?', 'avia_framework' ),
  335.                             'id'        => 'columns',
  336.                             'type'      => 'select',
  337.                             'std'       => '3',
  338.                             'lockable'  => true,
  339.                             'subtype'   => array(
  340.                                                 __( '1 Columns', 'avia_framework' ) => '1',
  341.                                                 __( '2 Columns', 'avia_framework' ) => '2',
  342.                                                 __( '3 Columns', 'avia_framework' ) => '3',
  343.                                                 __( '4 Columns', 'avia_framework' ) => '4',
  344.                                                 __( '5 Columns', 'avia_framework' ) => '5',
  345.                                             )
  346.                         )
  347.  
  348.                 );
  349.  
  350.             $template = array(
  351.                             array(
  352.                                 'type'          => 'template',
  353.                                 'template_id'   => 'toggle',
  354.                                 'title'         => __( 'Columns', 'avia_framework' ),
  355.                                 'content'       => $c
  356.                             ),
  357.                     );
  358.  
  359.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_columns' ), $template );
  360.  
  361.             $c = array(
  362.                         array(
  363.                             'name'      => __( 'Preview Image Size', 'avia_framework' ),
  364.                             'desc'      => __( 'Set the image size of the preview images', 'avia_framework' ),
  365.                             'id'        => 'preview_mode',
  366.                             'type'      => 'select',
  367.                             'std'       => 'auto',
  368.                             'lockable'  => true,
  369.                             'subtype'   => array(
  370.                                                 __( 'Set the preview image size automatically based on column width', 'avia_framework' )    => 'auto',
  371.                                                 __( 'Choose the preview image size manually (select thumbnail size)', 'avia_framework' )    => 'custom'
  372.                                             )
  373.                         ),
  374.  
  375.                         array(
  376.                             'name'      => __( 'Select custom preview image size', 'avia_framework' ),
  377.                             'desc'      => __( 'Choose image size for Preview Image', 'avia_framework' ),
  378.                             'id'        => 'image_size',
  379.                             'type'      => 'select',
  380.                             'std'       => 'portfolio',
  381.                             'lockable'  => true,
  382.                             'required'  => array( 'preview_mode', 'equals', 'custom' ),
  383.                             'subtype'   =>  AviaHelper::get_registered_image_sizes( array( 'logo' ) )
  384.                         )
  385.                 );
  386.  
  387.             $template = array(
  388.                             array(
  389.                                 'type'          => 'template',
  390.                                 'template_id'   => 'toggle',
  391.                                 'title'         => __( 'Preview Image', 'avia_framework' ),
  392.                                 'content'       => $c
  393.                             ),
  394.                     );
  395.  
  396.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_image' ), $template );
  397.  
  398.  
  399.             $c = array(
  400.  
  401.                         array(
  402.                             'type'          => 'template',
  403.                             'template_id'   => 'slideshow_controls',
  404.                             'std_nav'       => 'av-navigate-arrows',
  405.                             'lockable'      => true
  406.                         )
  407.  
  408.                 );
  409.  
  410.             $template = array(
  411.                             array(
  412.                                 'type'          => 'template',
  413.                                 'template_id'   => 'toggle',
  414.                                 'title'         => __( 'Navigation Controls', 'avia_framework' ),
  415.                                 'content'       => $c
  416.                             ),
  417.                     );
  418.  
  419.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_navigation' ), $template );
  420.  
  421.             /**
  422.              * Advanced Tab
  423.              * ===========
  424.              */
  425.  
  426.             $c = array(
  427. /*
  428.                         array(
  429.                             'name'      => __( 'Post Slider Transition', 'avia_framework' ),
  430.                             'desc'      => __( 'Choose the transition for your Post Slider.', 'avia_framework' ),
  431.                             'id'        => 'animation',
  432.                             'type'      => 'select',
  433.                             'std'       => 'fade',
  434.                             'subtype'   => array(
  435.                                                 __( 'Slide', 'avia_framework' ) => 'slide',
  436.                                                 __( 'Fade', 'avia_framework' )  => 'fade'
  437.                                             ),
  438.                         ),
  439. */
  440.  
  441.                         array(
  442.                             'type'          => 'template',
  443.                             'template_id'   => 'slideshow_rotation',
  444.                             'select_vals'   => 'yes,no',
  445.                             'stop_id'       => 'autoplay_stopper',
  446.                             'lockable'      => true
  447.                         )
  448.  
  449.                 );
  450.  
  451.             $template = array(
  452.                             array(
  453.                                 'type'          => 'template',
  454.                                 'template_id'   => 'toggle',
  455.                                 'title'         => __( 'Slider Animation', 'avia_framework' ),
  456.                                 'content'       => $c
  457.                             ),
  458.                     );
  459.  
  460.             AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_animation_slider' ), $template );
  461.  
  462.         }
  463.  
  464.         /**
  465.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  466.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  467.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  468.          *
  469.          * @param array $params         holds the default values for $content and $args.
  470.          * @return array                usually holds an innerHtml key that holds item specific markup.
  471.          */
  472.         public function editor_element( $params )
  473.         {
  474.             $params = parent::editor_element( $params );
  475.             $params['content'] = null; //remove to allow content elements
  476.  
  477.             return $params;
  478.         }
  479.  
  480.         /**
  481.          * Frontend Shortcode Handler
  482.          *
  483.          * @param array $atts array of attributes
  484.          * @param string $content text within enclosing form of shortcode element
  485.          * @param string $shortcodename the shortcode found, when == callback name
  486.          * @return string $output returns the modified html string
  487.          */
  488.         public function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' )
  489.         {
  490.             $default = avia_post_slider::get_defaults();
  491.  
  492.             $locked = array();
  493.             Avia_Element_Templates()->set_locked_attributes( $atts, $this, $shortcodename, $default, $locked, $content );
  494.             Avia_Element_Templates()->add_template_class( $meta, $atts, $default );
  495.  
  496.             $screen_sizes = AviaHelper::av_mobile_sizes( $atts );
  497.  
  498.             if( isset( $atts['img_scrset'] ) && 'disabled' == $atts['img_scrset'] )
  499.             {
  500.                 Av_Responsive_Images()->force_disable( 'disabled' );
  501.             }
  502.  
  503.             if( isset( $atts['link'] ) )
  504.             {
  505.                 $atts['link'] = explode(',', $atts['link'], 2 );
  506.                 $atts['taxonomy'] = $atts['link'][0];
  507.  
  508.                 if( isset( $atts['link'][1] ) )
  509.                 {
  510.                     $atts['categories'] = $atts['link'][1];
  511.                 }
  512.             }
  513.  
  514.             $atts['class'] = $meta['el_class'];
  515.             $atts['el_id'] = $meta['custom_el_id'];
  516.  
  517.             $atts = array_merge( $atts, $screen_sizes );
  518.  
  519.             /**
  520.              * @since 4.5.5
  521.              * @return array
  522.              */
  523.             $atts = apply_filters( 'avf_post_slider_args', $atts, $this->config['shortcode'], $this );
  524.  
  525.             $slider = new avia_post_slider( $atts );
  526.             $slider->query_entries();
  527.             $html = $slider->html();
  528.  
  529.             Av_Responsive_Images()->force_disable( 'reset' );
  530.  
  531.             return $html;
  532.         }
  533.  
  534.     }
  535. }
  536.  
  537.  
  538. if ( ! class_exists( 'avia_post_slider', false ) )
  539. {
  540.     /**
  541.      * This class does not support post css files
  542.      * ==========================================
  543.      */
  544.     class avia_post_slider
  545.     {
  546.         /**
  547.          * @since < 4.0
  548.          * @var int
  549.          */
  550.         static public $slide = 0;
  551.  
  552.         /**
  553.          *
  554.          * @since < 4.0
  555.          * @var array
  556.          */
  557.         protected $atts;
  558.  
  559.         /**
  560.          *
  561.          * @since < 4.0
  562.          * @var WP_Query
  563.          */
  564.         protected $entries;
  565.  
  566.         /**
  567.          *
  568.          * @since 4.7.6.4
  569.          * @var int
  570.          */
  571.         protected $current_page;
  572.  
  573.         /**
  574.          * @since < 4.0
  575.          * @since 5.6           added to pass a WP_Query object
  576.          * @param array $atts
  577.          */
  578.         public function __construct( $atts = array() )
  579.         {
  580.             $this->entries = null;
  581.             $this->current_page = 1;
  582.  
  583.             if( isset( $atts['wp_query'] ) && $atts['wp_query'] instanceof WP_Query )
  584.             {
  585.                 $this->entries = $atts['wp_query'];
  586.                 $this->set_posts_on_current_page();
  587.             }
  588.  
  589.             $this->atts = shortcode_atts( avia_post_slider::get_defaults(), $atts, 'av_postslider' );
  590.  
  591.             if( ! in_array( $this->atts['slider_navigation'], array( 'av-navigate-arrows', 'av-navigate-dots', 'av-navigate-arrows av-navigate-dots' ) ) )
  592.             {
  593.                 $this->atts['slider_navigation'] = 'av-navigate-arrows';
  594.             }
  595.  
  596.             if( $this->atts['term_rel'] != 'AND' )
  597.             {
  598.                 $this->atts['term_rel'] = 'IN';
  599.             }
  600.         }
  601.  
  602.         /**
  603.          * @since 4.5.5
  604.          */
  605.         public function __destruct()
  606.         {
  607.             unset( $this->atts );
  608.             unset( $this->entries );
  609.         }
  610.  
  611.         /**
  612.          * Returns the defaults array
  613.          *
  614.          * @since 4.8
  615.          * @return array
  616.          */
  617.         static public function get_defaults()
  618.         {
  619.             $defaults = array(
  620.                             'type'                  => 'slider', // can also be used as grid
  621.                             'style'                 => '', //no_margin
  622.                             'columns'               => '4',
  623.                             'items'                 => '16',
  624.                             'taxonomy'              => 'category',
  625.                             'term_rel'              => 'IN',
  626.                             'control_layout'        => 'av-control-default',
  627.                             'slider_navigation'     => 'av-navigate-arrows',
  628.                             'nav_visibility_desktop'    => '',
  629.                             'wc_prod_visible'       => '',
  630.                             'wc_prod_hidden'        => '',
  631.                             'wc_prod_featured'      => '',
  632.                             'wc_prod_sale'          => '',
  633.                             'prod_order_by'         => '',
  634.                             'prod_order'            => '',
  635.                             'show_meta_data'        => '',      //  '' | 'always' | 'on_empty_title' | 'on_empty_content' (use filter to change)
  636.                             'post_type'             => get_post_types(),
  637.                             'contents'              => 'excerpt',
  638.                             'preview_mode'          => 'auto',
  639.                             'image_size'            => 'portfolio',
  640.                             'animation'             => 'fade',
  641.                             'transition_speed'      => '',
  642.                             'autoplay'              => 'no',
  643.                             'interval'              => 5,
  644.                             'autoplay_stopper'      => '',
  645.                             'manual_stopper'        => '',
  646.                             'paginate'              => 'no',
  647.                             'use_main_query_pagination' => 'no',
  648.                             'class'                 => '',
  649.                             'el_id'                 => '',
  650.                             'categories'            => array(),
  651.                             'custom_query'          => array(),
  652.                             'offset'                => 0,
  653.                             'custom_markup'         => '',
  654.                             'av_display_classes'    => '',
  655.                             'date_filter'           => '',
  656.                             'date_filter_start'     => '',
  657.                             'date_filter_end'       => '',
  658.                             'date_filter_format'    => 'yy/mm/dd',      //  'yy/mm/dd' | 'dd-mm-yy' | yyyymmdd
  659.                             'period_filter_unit_1'  => '',
  660.                             'period_filter_unit_2'  => '',
  661.                             'page_element_filter'   => '',
  662.                             'lazy_loading'          => 'disabled',
  663.                             'img_scrset'            => ''
  664.             );
  665.  
  666.             return $defaults;
  667.         }
  668.  
  669.         /**
  670.          * @since 5.4
  671.          * @return array
  672.          */
  673.         public function get_atts()
  674.         {
  675.             return $this->atts;
  676.         }
  677.  
  678.         /**
  679.          *
  680.          * @since < 4.0
  681.          * @return string
  682.          */
  683.  
  684.  
  685.  
  686.  
  687. // Umgestaltung der Ausgabe (Auszug, innerhalb der Klasse avia_post_slider)
  688.  
  689.       public function html()
  690.       {
  691.           $output = '';
  692.  
  693.           if( empty( $this->entries ) || ! $this->entries instanceof WP_Query || empty( $this->entries->posts ) )
  694.           {
  695.               return $output;
  696.           }
  697.  
  698.           avia_post_slider::$slide ++;
  699.           extract( $this->atts );
  700.  
  701.           if( $preview_mode == 'auto' )
  702.           {
  703.               $image_size = 'portfolio';
  704.           }
  705.  
  706.           $extraClass        = 'first';
  707.           $grid              = 'one_third';
  708.           $post_loop_count   = 1;
  709.           $loop_counter      = 1;
  710.           $autoplay            = $autoplay == 'no' ? false : true;
  711.           $total            = $columns % 2 ? 'odd' : 'even';
  712.           $blogstyle         = function_exists( 'avia_get_option' ) ? avia_get_option( 'blog_global_style', '' ) : '';
  713.           $excerpt_length    = 60;
  714.           $total_posts       = $this->entries->post_count;
  715.           $output_class      = 'avia-content-slider-wrap avia-content-slider-active ' . $style . ' ' . $class;
  716.           $data              = 'data-autoplay="' . $autoplay . '" data-interval="' . $interval . '" data-animation="' . $animation . '" ';
  717.           $data             .= 'data-manual_stopper="' . $manual_stopper . '" data-loop_once="' . $autoplay_stopper . '" ';
  718.           $total_thumb_count = 0;
  719.  
  720.  
  721.           if( ! in_array( $columns, array( 1, 2, 3, 4, 5 ) ) )
  722.           {
  723.               $columns = 3;
  724.           }
  725.  
  726.           switch( $columns )
  727.           {
  728.               case '1':
  729.                   $grid = 'no_margin';
  730.                   break;
  731.               case '2':
  732.                   $grid = 'one_half';
  733.                   break;
  734.               case '3':
  735.                   $grid = 'one_third';
  736.                   break;
  737.               case '4':
  738.                   $grid = 'one_fourth';
  739.                   break;
  740.               case '5':
  741.                   $grid = 'one_fifth';
  742.                   break;
  743.           }
  744.  
  745.           $this->set_posts_on_current_page();
  746.  
  747.           $output .= '<div ' . $data . ' class="' . $output_class . '">';
  748.           $output .= '<div class="avia-content-slider-inner">';
  749.  
  750. // Hier wird die neue Klasse hinzugefügt
  751.           $output .= '<div class="slide-entry-wrap av-postslider-columns-' . $columns . '">';
  752.  
  753.           while ( $this->entries->have_posts() ) : $this->entries->the_post();
  754.  
  755.               $current_post_data  = array();
  756.               $current_post_data['format'] = get_post_format();
  757.               if( empty( $current_post_data['format'] ) )
  758.               {
  759.                   $current_post_data['format'] = 'standard';
  760.               }
  761.              
  762.               $current_post_data['permalink'] = get_permalink();
  763.               $current_post_data['title'] = get_the_title();
  764.               $current_post_data['content'] = get_the_excerpt();
  765.               $current_post_data['author'] = get_the_author();
  766.               $current_post_data['date'] = get_the_time(get_option('date_format'));
  767.               $current_post_data['image'] = get_the_post_thumbnail(get_the_ID(), $image_size);
  768.  
  769.               $output .= '<article class="slide-entry flex_column ' . $grid . ' ' . $current_post_data['format'] . '">';
  770.               $output .= '<div class="slide-entry-inner">';
  771.              
  772. // Platzhalte falls kein featured image da ist
  773.  
  774.               $output .= '<a href="' . $current_post_data['permalink'] . '" data-rel="slide-'. avia_post_slider::$slide .'" class="slide-image">';
  775.               $output .= '    <span class="slide-overlay"></span>';
  776.  
  777.               // NEUER CODE FÜR DEN ENFOLD-STANDARD-PLATZHALTER
  778.               if( empty( $current_post_data['image'] ) )
  779.               {
  780.                   // Hier ist der von Ihnen bereitgestellte SVG-Code
  781.                   $output .= '<span class="fallback-post-type-icon avia-svg-icon avia-font-svg_entypo-fontello" data-av_svg_icon="link" data-av_iconset="svg_entypo-fontello"><svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="26" height="32" viewBox="0 0 26 32" preserveAspectRatio="xMidYMid meet" role="graphics-symbol" aria-hidden="true"><path d="M9.408 23.488q0.448-0.448 1.088-0.448t1.152 0.448q1.024 1.088 0 2.24l-1.344 1.28q-1.792 1.792-4.224 1.792-2.496 0-4.288-1.792t-1.792-4.224q0-2.496 1.792-4.288l4.736-4.736q2.24-2.176 4.608-2.464t4.096 1.376q0.512 0.512 0.512 1.152t-0.512 1.152q-1.152 1.024-2.24 0-1.6-1.536-4.224 1.088l-4.736 4.672q-0.832 0.832-0.832 2.048t0.832 1.984q0.832 0.832 2.016 0.832t2.016-0.832zM23.808 5.12q1.792 1.792 1.792 4.224 0 2.496-1.792 4.288l-5.056 5.056q-2.368 2.304-4.8 2.304-1.984 0-3.584-1.6-0.448-0.448-0.448-1.088t0.448-1.152q0.448-0.448 1.12-0.448t1.12 0.448q1.6 1.536 3.904-0.768l5.056-4.992q0.896-0.896 0.896-2.048 0-1.216-0.896-1.984-0.768-0.832-1.792-0.992t-1.92 0.672l-1.6 1.6q-0.512 0.448-1.152 0.448t-1.088-0.448q-1.088-1.088 0-2.24l1.6-1.6q1.728-1.728 4.064-1.632t4.128 1.952z"></path></svg></span>';
  782.               } else {
  783.                   $output .= $current_post_data['image'];
  784.               }
  785.               $output .= '</a>';
  786.  
  787.  
  788.  
  789.  
  790.  
  791.               $output .= '    <div class="slide-content">';
  792.               $output .= '        <header class="entry-content-header">';
  793.               $output .= '            <h3 class="slide-content-title">';
  794.               $output .= '                <a href="' . $current_post_data['permalink'] . '" title="' . $current_post_data['title'] . '">' . $current_post_data['title'] . '</a>';
  795.               $output .= '            </h3>';
  796.               $output .= '            <div class="slide-meta">';
  797.               $output .= '                <span class="blog-author minor-meta">' . $current_post_data['author'] . '</span>';
  798.               $output .= '                <span class="text-sep">|</span>';
  799.               $output .= '                <span class="blog-date minor-meta">' . $current_post_data['date'] . '</span>';
  800.               $output .= '            </div>';
  801.               $output .= '        </header>';
  802.               $output .= '        <div class="entry-content">';
  803.               $output .= '            ' . $current_post_data['content'];
  804.               $output .= '        </div>';
  805.               $output .= '    </div>';
  806.               $output .= '    <footer class="entry-footer">';
  807.               $output .= '         <a class="more-link" href="' . $current_post_data['permalink'] . '">' . __('Read more','avia_framework') . '<span class="avia_continue_reading_arrow"></span></a>';
  808.               $output .= '    </footer>';
  809.               $output .= '</div>';
  810.               $output .= '</article>';
  811.  
  812.               $post_loop_count++;
  813.               if($post_loop_count > $columns || $loop_counter == $total_posts)
  814.               {
  815.                   $post_loop_count = 1;
  816.                   $extraClass = '';
  817.               }
  818.  
  819.               $loop_counter++;
  820.  
  821.           endwhile;
  822.  
  823.           $output .= '</div>'; // Schließt den einzigen Wrapper div.slide-entry-wrap
  824.  
  825.  
  826.           $output .= '</div>';
  827.  
  828.           if( false !== strpos( $slider_navigation, 'av-navigate-arrows' ) )
  829.           {
  830.               $output .= '<div class="avia-slideshow-arrows avia-slideshow-controls">';
  831.               $output .= '    <a href="#prev" class="prev-slide">' . __('Previous','avia_framework') . '</a>';
  832.               $output .= '    <a href="#next" class="next-slide">' . __('Next','avia_framework') . '</a>';
  833.               $output .= '</div>';
  834.           }
  835.  
  836.  
  837.           if( false !== strpos( $slider_navigation, 'av-navigate-dots' ) && 'av-control-hidden' != $control_layout )
  838.           {
  839.               $output .= '<div class="avia-slideshow-dots avia-slideshow-controls">';
  840.               $output .= '    <a data-avia-slide-to="1" href="#1" class="active-slide">' . '1' . '</a>';
  841.  
  842.               $counter = 2;
  843.               while($counter <= $total_posts)
  844.               {
  845.                   $output .= '    <a data-avia-slide-to="' . $counter . '" href="#' . $counter . '">' . $counter . '</a>';
  846.                   $counter++;
  847.               }
  848.               $output .= '</div>';
  849.           }
  850.  
  851.           $output .= '</div>';
  852.  
  853.           wp_reset_query();
  854.  
  855.           return $output;
  856.       }
  857.  
  858.  
  859.  
  860. // public funciton html ende
  861.  
  862.  
  863.         /**
  864.          * Create arrows to scroll slides
  865.          *
  866.          * @since 4.8.3         reroute to aviaFrontTemplates
  867.          * @return string
  868.          */
  869.         protected function slide_navigation_arrows()
  870.         {
  871.             $args = array(
  872.                         'context'   => get_class( $this ),
  873.                         'params'    => $this->atts,
  874.                         'svg_icon'  => true
  875.                     );
  876.  
  877.             return aviaFrontTemplates::slide_navigation_arrows( $args );
  878.         }
  879.  
  880.         /**
  881.          * Create dots to scroll tabs
  882.          *
  883.          * @since 5.0           reroute to aviaFrontTemplates
  884.          * @return string
  885.          */
  886.         protected function slide_navigation_dots()
  887.         {
  888.             $args = array(
  889.                         'class_main'        => 'avia-slideshow-dots avia-slideshow-controls avia-post-slider fade-in',
  890.                         'total_entries'     => $this->entries->post_count,
  891.                         'container_entries' => $this->atts['columns'],
  892.                         'context'           => get_class( $this ),
  893.                         'params'            => $this->atts
  894.                     );
  895.  
  896.             return aviaFrontTemplates::slide_navigation_dots( $args );
  897.         }
  898.  
  899.         /**
  900.          * Fetch new entries
  901.          *
  902.          * @since < 4.0
  903.          * @param array $params
  904.          */
  905.         public function query_entries( $params = array() )
  906.         {
  907.             global $avia_config;
  908.  
  909.             if( empty( $params ) )
  910.             {
  911.                 $params = $this->atts;
  912.             }
  913.  
  914.             if( empty( $params['custom_query'] ) )
  915.             {
  916.                 $query = array();
  917.                 $terms = array();
  918.  
  919.                 if( ! empty( $params['categories'] ) )
  920.                 {
  921.                     //get the portfolio categories
  922.                     $terms = explode( ',', $params['categories'] );
  923.                 }
  924.  
  925.                 if( $params['use_main_query_pagination'] == 'yes' )
  926.                 {
  927.                     $this->current_page = ( $params['paginate'] != 'no' ) ? avia_get_current_pagination_number() : 1;
  928.                 }
  929.                 else
  930.                 {
  931.                     $this->current_page = ( $params['paginate'] != 'no' ) ? avia_get_current_pagination_number( 'avia-element-paging' ) : 1;
  932.                 }
  933.  
  934.                 //if we find no terms for the taxonomy fetch all taxonomy terms
  935.                 if( empty( $terms[0] ) || is_null( $terms[0] ) || $terms[0] === 'null' )
  936.                 {
  937.                     $term_args = array(
  938.                                 'taxonomy'      => $params['taxonomy'],
  939.                                 'hide_empty'    => true
  940.                             );
  941.                     /**
  942.                      * To display private posts you need to set 'hide_empty' to false,
  943.                      * otherwise a category with ONLY private posts will not be returned !!
  944.                      *
  945.                      * You also need to add post_status 'private' to the query params with filter avia_post_slide_query.
  946.                      *
  947.                      * @since 4.4.2
  948.                      * @added_by Günter
  949.                      * @param array $term_args
  950.                      * @param array $params
  951.                      * @return array
  952.                      */
  953.                     $term_args = apply_filters( 'avf_av_postslider_term_args', $term_args, $params );
  954.  
  955.                     $allTax = AviaHelper::get_terms( $term_args );
  956.  
  957.                     $terms = array();
  958.                     foreach( $allTax as $tax )
  959.                     {
  960.                         $terms[] = $tax->term_id;
  961.                     }
  962.                 }
  963.  
  964.                 if( $params['offset'] == 'no_duplicates' )
  965.                 {
  966.                     $params['offset'] = false;
  967.                     $no_duplicates = true;
  968.                 }
  969.  
  970.                 //wordpress 4.4 offset fix
  971.                 if( $params['offset'] == 0 )
  972.                 {
  973.                     $params['offset'] = false;
  974.                 }
  975.                 else
  976.                 {
  977.                     //if the offset is set the paged param is ignored. therefore we need to factor in the page number
  978.                     $params['offset'] = $params['offset'] + ( ( $this->current_page - 1 ) * $params['items'] );
  979.                 }
  980.  
  981.                 if( empty( $params['post_type'] ) )
  982.                 {
  983.                     $params['post_type'] = get_post_types();
  984.                 }
  985.  
  986.                 if( is_string($params['post_type'] ) )
  987.                 {
  988.                     $params['post_type'] = explode( ',', $params['post_type'] );
  989.                 }
  990.  
  991.                 $orderby = 'date';
  992.                 $order = 'DESC';
  993.  
  994.                 $date_query = AviaHelper::date_query( array(), $params );
  995.  
  996.                 // Meta query - replaced by Tax query in WC 3.0.0
  997.                 $meta_query = array();
  998.                 $tax_query = array();
  999.  
  1000.  
  1001.                 // check if taxonomy are set to product or product attributes
  1002.                 $tax = get_taxonomy( $params['taxonomy'] );
  1003.  
  1004.                 if( class_exists( 'WooCommerce', false ) && is_object( $tax ) && isset( $tax->object_type ) && in_array( 'product', (array) $tax->object_type ) )
  1005.                 {
  1006.                     $avia_config['woocommerce']['disable_sorting_options'] = true;
  1007.  
  1008.                     avia_wc_set_out_of_stock_query_params( $meta_query, $tax_query, $params['wc_prod_visible'] );
  1009.                     avia_wc_set_hidden_prod_query_params( $meta_query, $tax_query, $params['wc_prod_hidden'] );
  1010.                     avia_wc_set_featured_prod_query_params( $meta_query, $tax_query, $params['wc_prod_featured'] );
  1011.                     avia_wc_set_on_sale_prod_query_params( $meta_query, $tax_query, $params['wc_prod_sale'] );
  1012.  
  1013.                         //  sets filter hooks !!
  1014.                     $ordering_args = avia_wc_get_product_query_order_args( $params['prod_order_by'], $params['prod_order'] );
  1015.  
  1016.                     $orderby = $ordering_args['orderby'];
  1017.                     $order = $ordering_args['order'];
  1018.                     $params['meta_key'] = $ordering_args['meta_key'];
  1019.                 }
  1020.  
  1021.                 if( ! empty( $terms ) )
  1022.                 {
  1023.                     $tax_query[] = array(
  1024.                                         'taxonomy'  =>  $params['taxonomy'],
  1025.                                         'field'     =>  'id',
  1026.                                         'terms'     =>  $terms,
  1027.                                         'operator'  =>  count( $terms ) == 1 ? 'IN' : $params['term_rel']
  1028.                                 );
  1029.                 }
  1030.  
  1031.                 $query = array(
  1032.                                 'orderby'       => $orderby,
  1033.                                 'order'         => $order,
  1034.                                 'paged'         => $this->current_page,
  1035.                                 'post_type'     => $params['post_type'],
  1036. //                              'post_status'   => 'publish',
  1037.                                 'offset'        => $params['offset'],
  1038.                                 'posts_per_page' => $params['items'],
  1039.                                 'post__not_in'  => ( ! empty( $no_duplicates ) ) ? $avia_config['posts_on_current_page'] : array(),
  1040.                                 'meta_query'    => $meta_query,
  1041.                                 'tax_query'     => $tax_query,
  1042.                                 'date_query'    => $date_query
  1043.                             );
  1044.             }
  1045.             else
  1046.             {
  1047.                 $query = $params['custom_query'];
  1048.             }
  1049.  
  1050.             if( ! empty( $params['meta_key'] ) )
  1051.             {
  1052.                 $query['meta_key'] = $params['meta_key'];
  1053.             }
  1054.  
  1055.             if( 'skip_current' == $params['page_element_filter'] )
  1056.             {
  1057.                 $query['post__not_in'] = isset( $query['post__not_in'] ) ? $query['post__not_in'] : [];
  1058.                 $query['post__not_in'][] = get_the_ID();
  1059.             }
  1060.  
  1061.             /**
  1062.              * @used_by             config-bbpress\config.php   avia_remove_bbpress_post_type_from_query()          10
  1063.              * @used_by             config-wpml\config.php      avia_translate_ids_from_query                       10
  1064.              * @used_by             avia_WPML::handler_avia_post_slide_query                                        20
  1065.              *
  1066.              * @since < 4.0
  1067.              * @param array $query
  1068.              * @param array $params
  1069.              * @return array
  1070.              */
  1071.             $query = apply_filters( 'avia_post_slide_query', $query, $params );
  1072.  
  1073.             @$this->entries = new WP_Query( $query ); //@ is used to prevent errors caused by wpml
  1074.  
  1075.             $this->set_posts_on_current_page();
  1076.  
  1077.             if( function_exists( 'WC' ) )
  1078.             {
  1079.                 avia_wc_clear_catalog_ordering_args_filters();
  1080.                 $avia_config['woocommerce']['disable_sorting_options'] = false;
  1081.             }
  1082.         }
  1083.  
  1084.         /**
  1085.          * Store the queried post ids in $avia_config
  1086.          *
  1087.          * @since 5.6
  1088.          */
  1089.         protected function set_posts_on_current_page()
  1090.         {
  1091.             global $avia_config;
  1092.  
  1093.             if( ! $this->entries instanceof WP_Query )
  1094.             {
  1095.                 return;
  1096.             }
  1097.  
  1098.             if( $this->entries->post_count > 0 )
  1099.             {
  1100.                 foreach( $this->entries->posts as $entry )
  1101.                 {
  1102.                     $avia_config['posts_on_current_page'][] = $entry->ID;
  1103.                 }
  1104.             }
  1105.         }
  1106.     }
  1107. }
  1108.  
  1109.  
Advertisement
Add Comment
Please, Sign In to add comment