Guest User

Untitled

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