Advertisement
Guest User

Untitled

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