Guest User

Untitled

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