Advertisement
Guest User

Untitled

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