Guest User

Untitled

a guest
Oct 18th, 2021
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.11 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['img_scrset'] ) && 'disabled' == $atts['img_scrset'] )
  465. {
  466. Av_Responsive_Images()->force_disable( 'disabled' );
  467. }
  468.  
  469. if( isset( $atts['link'] ) )
  470. {
  471. $atts['link'] = explode(',', $atts['link'], 2 );
  472. $atts['taxonomy'] = $atts['link'][0];
  473.  
  474. if( isset( $atts['link'][1] ) )
  475. {
  476. $atts['categories'] = $atts['link'][1];
  477. }
  478. }
  479.  
  480. $atts['class'] = $meta['el_class'];
  481. $atts['el_id'] = $meta['custom_el_id'];
  482.  
  483. $atts = array_merge( $atts, $screen_sizes );
  484.  
  485. /**
  486. * @since 4.5.5
  487. * @return array
  488. */
  489. $atts = apply_filters( 'avf_post_slider_args', $atts, $this->config['shortcode'], $this );
  490.  
  491. $slider = new avia_post_slider( $atts );
  492. $slider->query_entries();
  493. $html = $slider->html();
  494.  
  495. Av_Responsive_Images()->force_disable( 'reset' );
  496.  
  497. return $html;
  498. }
  499.  
  500. }
  501. }
  502.  
  503.  
  504.  
  505.  
  506. if ( ! class_exists( 'avia_post_slider' ) )
  507. {
  508. class avia_post_slider
  509. {
  510. /**
  511. * @since < 4.0
  512. * @var int
  513. */
  514. static public $slide = 0;
  515.  
  516. /**
  517. *
  518. * @since < 4.0
  519. * @var array
  520. */
  521. protected $atts;
  522.  
  523. /**
  524. *
  525. * @since < 4.0
  526. * @var WP_Query
  527. */
  528. protected $entries;
  529.  
  530. /**
  531. *
  532. * @since 4.7.6.4
  533. * @var int
  534. */
  535. protected $current_page;
  536.  
  537. /**
  538. * @since < 4.0
  539. * @param array $atts
  540. */
  541. public function __construct( $atts = array() )
  542. {
  543. $this->entries = array();
  544. $this->current_page = 1;
  545.  
  546. $this->atts = shortcode_atts( avia_post_slider::get_defaults(), $atts, 'av_postslider' );
  547. }
  548.  
  549.  
  550. /**
  551. * @since 4.5.5
  552. */
  553. public function __destruct()
  554. {
  555. unset( $this->atts );
  556. unset( $this->entries );
  557. }
  558.  
  559. /**
  560. * Returns the defaults array
  561. *
  562. * @since 4.8
  563. * @return array
  564. */
  565. static public function get_defaults()
  566. {
  567. $defaults = array(
  568. 'type' => 'slider', // can also be used as grid
  569. 'style' => '', //no_margin
  570. 'columns' => '4',
  571. 'items' => '16',
  572. 'taxonomy' => 'category',
  573. 'wc_prod_visible' => '',
  574. 'wc_prod_hidden' => '',
  575. 'wc_prod_featured' => '',
  576. 'prod_order_by' => '',
  577. 'prod_order' => '',
  578. 'show_meta_data' => '', // '' | 'always' | 'on_empty_title' | 'on_empty_content' (use filter to change)
  579. 'post_type' => get_post_types(),
  580. 'contents' => 'excerpt',
  581. 'preview_mode' => 'auto',
  582. 'image_size' => 'portfolio',
  583. 'autoplay' => 'no',
  584. 'animation' => 'fade',
  585. 'paginate' => 'no',
  586. 'use_main_query_pagination' => 'no',
  587. 'interval' => 5,
  588. 'class' => '',
  589. 'el_id' => '',
  590. 'categories' => array(),
  591. 'custom_query' => array(),
  592. 'offset' => 0,
  593. 'custom_markup' => '',
  594. 'av_display_classes' => '',
  595. 'date_filter' => '',
  596. 'date_filter_start' => '',
  597. 'date_filter_end' => '',
  598. 'date_filter_format' => 'yy/mm/dd', // 'yy/mm/dd' | 'dd-mm-yy' | yyyymmdd
  599. 'lazy_loading' => 'disabled',
  600. 'img_scrset' => ''
  601. );
  602.  
  603. return $defaults;
  604. }
  605.  
  606. /**
  607. *
  608. * @since < 4.0
  609. * @return string
  610. */
  611. public function html()
  612. {
  613. $output = '';
  614.  
  615. if( empty( $this->entries ) || empty( $this->entries->posts ) )
  616. {
  617. return $output;
  618. }
  619.  
  620. avia_post_slider::$slide ++;
  621. extract( $this->atts );
  622.  
  623. if( $preview_mode == 'auto' )
  624. {
  625. $image_size = 'portfolio';
  626. }
  627.  
  628. $extraClass = 'first';
  629. $grid = 'one_third';
  630. $post_loop_count = 1;
  631. $loop_counter = 1;
  632. $autoplay = $autoplay == 'no' ? false : true;
  633. $total = $columns % 2 ? 'odd' : 'even';
  634. $blogstyle = function_exists( 'avia_get_option' ) ? avia_get_option( 'blog_global_style', '' ) : '';
  635. $excerpt_length = 60;
  636.  
  637.  
  638. if( $blogstyle !== '' )
  639. {
  640. $excerpt_length = 240;
  641. }
  642.  
  643. switch( $columns )
  644. {
  645. case '1':
  646. $grid = 'av_fullwidth';
  647. if( $preview_mode == 'auto' )
  648. {
  649. $image_size = 'large';
  650. }
  651. break;
  652. case '2':
  653. $grid = 'av_one_half';
  654. break;
  655. case '3':
  656. $grid = 'av_one_third';
  657. break;
  658. case '4':
  659. $grid = 'av_one_fourth';
  660. if( $preview_mode == 'auto' )
  661. {
  662. $image_size = 'portfolio_small';
  663. }
  664. break;
  665. case '5':
  666. $grid = 'av_one_fifth';
  667. if( $preview_mode == 'auto' )
  668. {
  669. $image_size = 'portfolio_small';
  670. }
  671. break;
  672. }
  673.  
  674.  
  675. $data = AviaHelper::create_data_string( array( 'autoplay' => $autoplay, 'interval' => $interval, 'animation' => $animation, 'show_slide_delay' => 90 ) );
  676.  
  677. $thumb_fallback = '';
  678. $markup = avia_markup_helper( array( 'context' => 'blog', 'echo' => false, 'custom_markup' => $custom_markup ) );
  679. $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>";
  680. $output .= "<div class='avia-content-slider-inner'>";
  681.  
  682. foreach( $this->entries->posts as $index => $entry )
  683. {
  684. $the_id = $entry->ID;
  685. $parity = $loop_counter % 2 ? 'odd' : 'even';
  686. $last = $this->entries->post_count == $post_loop_count ? ' post-entry-last ' : '';
  687. $post_class = "post-entry post-entry-{$the_id} slide-entry-overview slide-loop-{$post_loop_count} slide-parity-{$parity} {$last}";
  688. $link = get_post_meta( $the_id , '_portfolio_custom_link', true ) != '' ? get_post_meta( $the_id , '_portfolio_custom_link_url', true ) : get_permalink( $the_id );
  689. $excerpt = '';
  690. $title = '';
  691. $show_meta = ! is_post_type_hierarchical( $entry->post_type );
  692. $commentCount = get_comments_number( $the_id );
  693. $format = get_post_format( $the_id );
  694.  
  695. $post_thumbnail_id = get_post_thumbnail_id( $the_id );
  696. if( $lazy_loading != 'enabled' )
  697. {
  698. Av_Responsive_Images()->add_attachment_id_to_not_lazy_loading( $post_thumbnail_id );
  699. }
  700.  
  701. $thumbnail = get_the_post_thumbnail( $the_id, $image_size );
  702.  
  703. if( empty( $format ) )
  704. {
  705. $format = 'standard';
  706. }
  707.  
  708. if( $thumbnail )
  709. {
  710. $thumb_fallback = $thumbnail;
  711. $thumb_class = 'real-thumbnail';
  712. }
  713. else
  714. {
  715. $thumbnail = "<span class=' fallback-post-type-icon' " . av_icon_string($format). "></span><span class='slider-fallback-image'>{{thumbnail}}</span>";
  716. $thumb_class = 'fake-thumbnail';
  717. }
  718.  
  719.  
  720. $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>';
  721. $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, '' );
  722.  
  723. if( $format == 'link' )
  724. {
  725. $current_post = array();
  726. $current_post['content'] = $entry->post_content;
  727. $current_post['title'] = avia_wp_get_the_title( $entry );
  728.  
  729. if( function_exists( 'avia_link_content_filter' ) )
  730. {
  731. $current_post = avia_link_content_filter( $current_post );
  732. }
  733.  
  734. $link = $current_post['url'];
  735. }
  736.  
  737. switch( $contents )
  738. {
  739. case 'excerpt':
  740. $excerpt = $prepare_excerpt;
  741. $title = avia_wp_get_the_title( $entry );
  742. break;
  743. case 'excerpt_read_more':
  744. $excerpt = $prepare_excerpt;
  745. $excerpt .= $permalink;
  746. $title = avia_wp_get_the_title( $entry );
  747. break;
  748. case 'title':
  749. $excerpt = '';
  750. $title = avia_wp_get_the_title( $entry );
  751. break;
  752. case 'title_read_more':
  753. $excerpt = $permalink;
  754. $title = avia_wp_get_the_title( $entry );
  755. break;
  756. case 'only_excerpt':
  757. $excerpt = $prepare_excerpt;
  758. $title = '';
  759. break;
  760. case 'only_excerpt_read_more':
  761. $excerpt = $prepare_excerpt;
  762. $excerpt .= $permalink;
  763. $title = '';
  764. break;
  765. case 'no':
  766. $excerpt = '';
  767. $title = '';
  768. break;
  769. }
  770.  
  771. /**
  772. * @since < 4.0
  773. * @param string $title
  774. * @param WP_Post $entry
  775. * @return string
  776. */
  777. $title = apply_filters( 'avf_postslider_title', $title, $entry );
  778.  
  779.  
  780. /**
  781. * @since 4.7.3.1
  782. * @param string $image_link_title
  783. * @param WP_Post $entry
  784. * @return string
  785. */
  786. $image_link_title = apply_filters( 'avf_postslider_link_title_attr', esc_attr( avia_wp_get_the_title( $entry ) ), $entry );
  787.  
  788.  
  789.  
  790. if( $loop_counter == 1 )
  791. {
  792. $output .= "<div class='slide-entry-wrap'>";
  793. }
  794.  
  795. $post_format = get_post_format( $the_id ) ? get_post_format( $the_id ) : 'standard';
  796.  
  797. $markup = avia_markup_helper( array( 'context' => 'entry', 'echo' => false, 'id' => $the_id, 'custom_markup' => $custom_markup ) );
  798. $output .= "<article class='slide-entry flex_column {$style} {$post_class} {$grid} {$extraClass} {$thumb_class} post-format-{$post_format}' $markup>";
  799. $output .= $thumbnail ? "<a href='{$link}' data-rel='slide-" . avia_post_slider::$slide . "' class='slide-image' title='{$image_link_title}'>{$thumbnail}</a>" : '';
  800.  
  801. if( $post_format == 'audio' )
  802. {
  803. $current_post = array();
  804. $current_post['content'] = $entry->post_content;
  805. $current_post['title'] = avia_wp_get_the_title( $entry );
  806. $current_post['id'] = $entry->ID;
  807.  
  808. $current_post = apply_filters( 'post-format-' . $post_format, $current_post, $entry );
  809.  
  810. if( ! empty( $current_post['before_content'] ) )
  811. {
  812. $output .= '<div class="big-preview single-big audio-preview">' . $current_post['before_content'] . '</div>';
  813. }
  814. }
  815.  
  816. $output .= "<div class='slide-content'>";
  817.  
  818. $markup = avia_markup_helper( array( 'context' => 'entry_title', 'echo' => false, 'id' => $the_id, 'custom_markup' => $custom_markup ) );
  819. $output .= '<header class="entry-content-header">';
  820. $meta_out = '';
  821.  
  822. if( ! empty( $title ) || in_array( $show_meta_data, array( 'always', 'on_empty_title' ) ) )
  823. {
  824. if( $show_meta )
  825. {
  826. $taxonomies = get_object_taxonomies( get_post_type( $the_id ) );
  827. $cats = '';
  828. $excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array( 'post_tag', 'post_format' ) );
  829. $excluded_taxonomies = apply_filters( 'avf_exclude_taxonomies', $excluded_taxonomies, get_post_type( $the_id ), $the_id );
  830.  
  831. if( ! empty( $taxonomies ) )
  832. {
  833. foreach( $taxonomies as $taxonomy )
  834. {
  835. if( ! in_array( $taxonomy, $excluded_taxonomies ) )
  836. {
  837. $cats .= get_the_term_list( $the_id, $taxonomy, '', ', ', '' ) . ' ';
  838. }
  839. }
  840. }
  841.  
  842. if( ! empty( $cats ) )
  843. {
  844. $meta_out .= '<span class="blog-categories minor-meta">';
  845. $meta_out .= $cats;
  846. $meta_out .= '</span>';
  847. $meta_out .= "<time class='slide-meta-time updated' $markup>" . get_the_time( get_option( 'date_format' ), $the_id ) . '</time>';
  848. }
  849. }
  850.  
  851. /**
  852. * Allow to change default output of categories - by default supressed for setting Default(Business) blog style
  853. *
  854. * @since 4.0.6
  855. * @param string $blogstyle '' | 'elegant-blog' | 'elegant-blog modern-blog'
  856. * @param avia_post_slider $this
  857. * @return string 'show_elegant' | 'show_business' | 'use_theme_default' | 'no_show_cats'
  858. */
  859. $show_cats = apply_filters( 'avf_postslider_show_catergories', 'use_theme_default', $blogstyle, $this );
  860.  
  861. switch( $show_cats )
  862. {
  863. case 'no_show_cats':
  864. $new_blogstyle = '';
  865. break;
  866. case 'show_elegant':
  867. $new_blogstyle = 'elegant-blog';
  868. break;
  869. case 'show_business':
  870. $new_blogstyle = 'elegant-blog modern-blog';
  871. break;
  872. case 'use_theme_default':
  873. default:
  874. $new_blogstyle = $blogstyle;
  875. break;
  876. }
  877.  
  878. // elegant style
  879. if( ( strpos( $new_blogstyle, 'modern-blog' ) === false ) && ( $new_blogstyle != '' ) )
  880. {
  881. $output .= $meta_out;
  882. }
  883.  
  884. $default_heading = 'h3';
  885. $args = array(
  886. 'heading' => $default_heading,
  887. 'extra_class' => ''
  888. );
  889.  
  890. $extra_args = array( $this, $index, $entry );
  891.  
  892. /**
  893. * @since 4.5.5
  894. * @return array
  895. */
  896. $args = apply_filters( 'avf_customize_heading_settings', $args, __CLASS__, $extra_args );
  897.  
  898. $heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  899. $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
  900.  
  901.  
  902. $output .= "<{$heading} class='slide-entry-title entry-title {$css}' $markup><a href='{$link}' title='" . esc_attr( strip_tags( $title ) ) . "'>{$title}</a></{$heading}>";
  903.  
  904. // modern business style
  905. if( ( strpos( $new_blogstyle, 'modern-blog' ) !== false ) && ( $new_blogstyle != '' ) )
  906. {
  907. $output .= $meta_out;
  908. }
  909.  
  910. $output .= '<span class="av-vertical-delimiter"></span>';
  911. }
  912.  
  913. $output .= '</header>';
  914.  
  915. if( ( $show_meta && ! empty( $excerpt ) ) || in_array( $show_meta_data, array( 'always', 'on_empty_content' ) ) )
  916. {
  917. $meta = "<div class='slide-meta'>";
  918. if ( $commentCount != '0' || comments_open( $the_id ) && $entry->post_type != 'portfolio' )
  919. {
  920. $link_add = $commentCount === '0' ? '#respond' : '#comments';
  921. $text_add = $commentCount === '1' ? __( 'Comment', 'avia_framework' ) : __( 'Comments', 'avia_framework' );
  922.  
  923. $meta .= "<div class='slide-meta-comments'><a href='{$link}{$link_add}'>{$commentCount} {$text_add}</a></div><div class='slide-meta-del'>/</div>";
  924. }
  925. $markup = avia_markup_helper( array( 'context' => 'entry_time', 'echo' => false, 'id' => $the_id, 'custom_markup' => $custom_markup ) );
  926. $meta .= "<time class='slide-meta-time updated' $markup>" . get_the_time( get_option( 'date_format' ), $the_id ) . '</time>';
  927. $meta .= '</div>';
  928.  
  929. if( strpos( $blogstyle, 'elegant-blog' ) === false )
  930. {
  931. $output .= $meta;
  932. $meta = '';
  933. }
  934. }
  935.  
  936. $markup = avia_markup_helper( array( 'context' => 'entry_content', 'echo' => false, 'id' => $the_id, 'custom_markup' => $custom_markup ) );
  937. $excerpt = apply_filters( 'avf_post_slider_entry_excerpt', $excerpt, $prepare_excerpt, $permalink, $entry );
  938. $output .= ! empty( $excerpt ) ? "<div class='slide-entry-excerpt entry-content' {$markup}>{$excerpt}</div>" : '';
  939.  
  940. $output .= '</div>';
  941. $output .= '<footer class="entry-footer">';
  942. if( ! empty( $meta ) )
  943. {
  944. $output .= $meta;
  945. }
  946. $output .= '</footer>';
  947.  
  948. $output .= av_blog_entry_markup_helper( $the_id );
  949.  
  950. $output .= '</article>';
  951.  
  952. $loop_counter ++;
  953. $post_loop_count ++;
  954. $extraClass = '';
  955.  
  956. if( $loop_counter > $columns )
  957. {
  958. $loop_counter = 1;
  959. $extraClass = 'first';
  960. }
  961.  
  962. if( $loop_counter == 1 || ! empty( $last ) )
  963. {
  964. $output .= '</div>';
  965. }
  966. }
  967.  
  968. $output .= '</div>';
  969.  
  970. if( $post_loop_count -1 > $columns && $type == 'slider' )
  971. {
  972. $output .= $this->slide_navigation_arrows();
  973. }
  974.  
  975. global $wp_query;
  976.  
  977. $avia_pagination = '';
  978.  
  979. if( $use_main_query_pagination == 'yes' && $paginate == 'yes' )
  980. {
  981. $avia_pagination = avia_pagination( $wp_query->max_num_pages, 'nav' );
  982. }
  983. else if( $paginate == 'yes' )
  984. {
  985. $avia_pagination = avia_pagination( $this->entries, 'nav', 'avia-element-paging', $this->current_page );
  986. }
  987.  
  988. if( ! empty( $avia_pagination ) )
  989. {
  990. $output .= "<div class='pagination-wrap pagination-slider'>{$avia_pagination}</div>";
  991. }
  992.  
  993.  
  994. $output .= '</div>';
  995.  
  996. $output = str_replace( '{{thumbnail}}', $thumb_fallback, $output );
  997.  
  998. wp_reset_query();
  999. return $output;
  1000. }
  1001.  
  1002. /**
  1003. * Create arrows to scroll slides
  1004. *
  1005. * @since 4.8.3 reroute to aviaFrontTemplates
  1006. * @return string
  1007. */
  1008. protected function slide_navigation_arrows()
  1009. {
  1010. $args = array(
  1011. 'context' => get_class(),
  1012. 'params' => $this->atts
  1013. );
  1014.  
  1015. return aviaFrontTemplates::slide_navigation_arrows( $args );
  1016. }
  1017.  
  1018. /**
  1019. * Fetch new entries
  1020. *
  1021. * @since < 4.0
  1022. * @param array $params
  1023. */
  1024. public function query_entries( $params = array() )
  1025. {
  1026. global $avia_config;
  1027.  
  1028. if( empty( $params ) )
  1029. {
  1030. $params = $this->atts;
  1031. }
  1032.  
  1033. if( empty( $params['custom_query'] ) )
  1034. {
  1035. $query = array();
  1036.  
  1037. if( ! empty( $params['categories'] ) )
  1038. {
  1039. //get the portfolio categories
  1040. $terms = explode( ',', $params['categories'] );
  1041. }
  1042.  
  1043. if( $params['use_main_query_pagination'] == 'yes' )
  1044. {
  1045. $this->current_page = ( $params['paginate'] != 'no' ) ? avia_get_current_pagination_number() : 1;
  1046. }
  1047. else
  1048. {
  1049. $this->current_page = ( $params['paginate'] != 'no' ) ? avia_get_current_pagination_number( 'avia-element-paging' ) : 1;
  1050. }
  1051.  
  1052. //if we find no terms for the taxonomy fetch all taxonomy terms
  1053. if( empty( $terms[0] ) || is_null( $terms[0] ) || $terms[0] === 'null' )
  1054. {
  1055.  
  1056. $term_args = array(
  1057. 'taxonomy' => $params['taxonomy'],
  1058. 'hide_empty' => true
  1059. );
  1060. /**
  1061. * To display private posts you need to set 'hide_empty' to false,
  1062. * otherwise a category with ONLY private posts will not be returned !!
  1063. *
  1064. * You also need to add post_status 'private' to the query params with filter avia_post_slide_query.
  1065. *
  1066. * @since 4.4.2
  1067. * @added_by Günter
  1068. * @param array $term_args
  1069. * @param array $params
  1070. * @return array
  1071. */
  1072. $term_args = apply_filters( 'avf_av_postslider_term_args', $term_args, $params );
  1073.  
  1074. $allTax = AviaHelper::get_terms( $term_args );
  1075.  
  1076. $terms = array();
  1077. foreach( $allTax as $tax )
  1078. {
  1079. $terms[] = $tax->term_id;
  1080. }
  1081.  
  1082. }
  1083.  
  1084. if( $params['offset'] == 'no_duplicates' )
  1085. {
  1086. $params['offset'] = false;
  1087. $no_duplicates = true;
  1088. }
  1089.  
  1090.  
  1091. //wordpress 4.4 offset fix
  1092. if( $params['offset'] == 0 )
  1093. {
  1094. $params['offset'] = false;
  1095. }
  1096. else
  1097. {
  1098. //if the offset is set the paged param is ignored. therefore we need to factor in the page number
  1099. $params['offset'] = $params['offset'] + ( ( $this->current_page - 1 ) * $params['items'] );
  1100. }
  1101.  
  1102.  
  1103. if( empty( $params['post_type'] ) )
  1104. {
  1105. $params['post_type'] = get_post_types();
  1106. }
  1107.  
  1108. if( is_string($params['post_type'] ) )
  1109. {
  1110. $params['post_type'] = explode( ',', $params['post_type'] );
  1111. }
  1112.  
  1113. $orderby = 'date';
  1114. $order = 'DESC';
  1115.  
  1116. $date_query = array();
  1117. if( 'date_filter' == $params['date_filter'] )
  1118. {
  1119. $date_query = AviaHelper::add_date_query( $date_query, $params['date_filter_start'], $params['date_filter_end'], $params['date_filter_format'] );
  1120. }
  1121.  
  1122. // Meta query - replaced by Tax query in WC 3.0.0
  1123. $meta_query = array();
  1124. $tax_query = array();
  1125.  
  1126.  
  1127. // check if taxonomy are set to product or product attributes
  1128. $tax = get_taxonomy( $params['taxonomy'] );
  1129.  
  1130. if( class_exists( 'WooCommerce' ) && is_object( $tax ) && isset( $tax->object_type ) && in_array( 'product', (array) $tax->object_type ) )
  1131. {
  1132. $avia_config['woocommerce']['disable_sorting_options'] = true;
  1133.  
  1134. avia_wc_set_out_of_stock_query_params( $meta_query, $tax_query, $params['wc_prod_visible'] );
  1135. avia_wc_set_hidden_prod_query_params( $meta_query, $tax_query, $params['wc_prod_hidden'] );
  1136. avia_wc_set_featured_prod_query_params( $meta_query, $tax_query, $params['wc_prod_featured'] );
  1137.  
  1138. // sets filter hooks !!
  1139. $ordering_args = avia_wc_get_product_query_order_args( $params['prod_order_by'], $params['prod_order'] );
  1140.  
  1141. $orderby = $ordering_args['orderby'];
  1142. $order = $ordering_args['order'];
  1143. $params['meta_key'] = $ordering_args['meta_key'];
  1144. }
  1145.  
  1146. if( ! empty( $terms ) )
  1147. {
  1148. $tax_query[] = array(
  1149. 'taxonomy' => $params['taxonomy'],
  1150. 'field' => 'id',
  1151. 'terms' => $terms,
  1152. 'operator' => 'IN'
  1153. );
  1154. }
  1155.  
  1156. $query = array(
  1157. 'orderby' => $orderby,
  1158. 'order' => $order,
  1159. 'paged' => $this->current_page,
  1160. 'post_type' => $params['post_type'],
  1161. // 'post_status' => 'publish',
  1162. 'offset' => $params['offset'],
  1163. 'posts_per_page' => $params['items'],
  1164. 'post__not_in' => ( ! empty( $no_duplicates ) ) ? $avia_config['posts_on_current_page'] : array(),
  1165. 'meta_query' => $meta_query,
  1166. 'tax_query' => $tax_query,
  1167. 'date_query' => $date_query
  1168. );
  1169.  
  1170. }
  1171. else
  1172. {
  1173. $query = $params['custom_query'];
  1174. }
  1175.  
  1176. if( ! empty( $params['meta_key'] ) )
  1177. {
  1178. $query['meta_key'] = $params['meta_key'];
  1179. }
  1180.  
  1181. /**
  1182. * @used_by config-bbpress\config.php avia_remove_bbpress_post_type_from_query() 10
  1183. * @used_by config-wpml\config.php avia_translate_ids_from_query 10
  1184. *
  1185. * @since < 4.0
  1186. * @param array $query
  1187. * @param array $params
  1188. * @return array
  1189. */
  1190. $query = apply_filters( 'avia_post_slide_query', $query, $params );
  1191.  
  1192. @$this->entries = new WP_Query( $query ); //@ is used to prevent errors caused by wpml
  1193.  
  1194. // store the queried post ids in
  1195. if( $this->entries->post_count > 0 )
  1196. {
  1197. foreach( $this->entries->posts as $entry )
  1198. {
  1199. $avia_config['posts_on_current_page'][] = $entry->ID;
  1200. }
  1201. }
  1202.  
  1203. if( function_exists( 'WC' ) )
  1204. {
  1205. avia_wc_clear_catalog_ordering_args_filters();
  1206. $avia_config['woocommerce']['disable_sorting_options'] = false;
  1207. }
  1208. }
  1209. }
  1210. }
  1211.  
Advertisement
Add Comment
Please, Sign In to add comment