Guest User

Untitled

a guest
Dec 2nd, 2021
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.77 KB | None | 0 0
  1. <?php
  2. /**
  3. * Magazine
  4. *
  5. * Display entries in a magazine like fashion
  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_magazine' ) )
  12. {
  13. class avia_sc_magazine 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'] = __( 'Magazine', 'avia_framework' );
  26. $this->config['tab'] = __( 'Content Elements', 'avia_framework' );
  27. $this->config['icon'] = AviaBuilder::$path['imagesURL'] . 'sc-magazine.png';
  28. $this->config['order'] = 39;
  29. $this->config['target'] = 'avia-target-insert';
  30. $this->config['shortcode'] = 'av_magazine';
  31. $this->config['tooltip'] = __( 'Display entries in a magazine like fashion', 'avia_framework' );
  32. $this->config['drag-level'] = 3;
  33. $this->config['preview'] = 1;
  34. $this->config['disabling_allowed'] = true;
  35. $this->config['id_name'] = 'id';
  36. $this->config['id_show'] = 'yes';
  37. $this->config['alb_desc_id'] = 'alb_description';
  38. }
  39.  
  40. function extra_assets()
  41. {
  42. //load css
  43. wp_enqueue_style( 'avia-module-magazine', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/magazine/magazine.css', array( 'avia-layout' ), false );
  44.  
  45. //load js
  46. wp_enqueue_script( 'avia-module-magazine', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/magazine/magazine.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_entries' ),
  77. $this->popup_key( 'content_filter' )
  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_general' ),
  98. $this->popup_key( 'styling_pagination' ),
  99. $this->popup_key( 'styling_colors' ),
  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_heading' ),
  123. 'nodescription' => true
  124. ),
  125.  
  126. array(
  127. 'type' => 'template',
  128. 'template_id' => $this->popup_key( 'advanced_link' ),
  129. 'nodescription' => true
  130. ),
  131.  
  132. array(
  133. 'type' => 'template',
  134. 'template_id' => 'lazy_loading_toggle',
  135. 'lockable' => true
  136. ),
  137.  
  138. array(
  139. 'type' => 'template',
  140. 'template_id' => 'screen_options_toggle',
  141. 'lockable' => true
  142. ),
  143.  
  144. array(
  145. 'type' => 'template',
  146. 'template_id' => 'developer_options_toggle',
  147. 'args' => array( 'sc' => $this )
  148. ),
  149.  
  150. array(
  151. 'type' => 'toggle_container_close',
  152. 'nodescription' => true
  153. ),
  154.  
  155. array(
  156. 'type' => 'tab_close',
  157. 'nodescription' => true
  158. ),
  159.  
  160. array(
  161. 'type' => 'template',
  162. 'template_id' => 'element_template_selection_tab',
  163. 'args' => array( 'sc' => $this )
  164. ),
  165.  
  166. array(
  167. 'type' => 'tab_container_close',
  168. 'nodescription' => true
  169. )
  170.  
  171. );
  172.  
  173. }
  174.  
  175. /**
  176. * Create and register templates for easier maintainance
  177. *
  178. * @since 4.6.4
  179. */
  180. protected function register_dynamic_templates()
  181. {
  182.  
  183. /**
  184. * Content Tab
  185. * ===========
  186. */
  187.  
  188. $c = array(
  189. array(
  190. 'name' => __( 'Which Entries?', 'avia_framework' ),
  191. 'desc' => __( 'Select which entries should be displayed by selecting a taxonomy', 'avia_framework' ),
  192. 'id' => 'link',
  193. 'type' => 'linkpicker',
  194. 'multiple' => 6,
  195. 'std' => 'category',
  196. 'fetchTMPL' => true,
  197. 'lockable' => true,
  198. 'subtype' => array( __( 'Display Entries from:', 'avia_framework' ) => 'taxonomy' )
  199. ),
  200.  
  201. array(
  202. 'name' => __( 'Display Tabs for each category selected above?', 'avia_framework' ),
  203. 'desc' => __( 'If checked and you have selected more than one taxonomy above, a tab will be displayed for each of them. Will be ignored when using Pagination.', 'avia_framework' ),
  204. 'id' => 'tabs',
  205. 'type' => 'checkbox',
  206. 'std' => 'true',
  207. 'lockable' => true
  208. ),
  209.  
  210. array(
  211. 'name' => __( 'Display Thumbnails?', 'avia_framework' ),
  212. 'desc' => __( 'If checked all entries that got a feature image will show it', 'avia_framework' ),
  213. 'id' => 'thumbnails',
  214. 'type' => 'checkbox',
  215. 'std' => 'true',
  216. 'container_class' => 'av_half av_half_first',
  217. 'lockable' => true
  218. ),
  219.  
  220. array(
  221. 'name' => __( 'Display Author?', 'avia_framework' ),
  222. 'desc' => __( 'If checked author of this entry will be shown', 'avia_framework' ),
  223. 'id' => 'meta_author',
  224. 'type' => 'checkbox',
  225. 'std' => 'false',
  226. 'container_class' => 'av_half',
  227. 'lockable' => true
  228. ),
  229.  
  230. array(
  231. 'name' => __( 'Display Categories?', 'avia_framework' ),
  232. 'desc' => __( 'If checked categories of this entry will be shown', 'avia_framework' ),
  233. 'id' => 'meta_cats',
  234. 'type' => 'checkbox',
  235. 'std' => 'false',
  236. 'container_class' => 'av_half av_half_first',
  237. 'lockable' => true
  238. ),
  239.  
  240. array(
  241. 'name' => __( 'Display Tags?', 'avia_framework' ),
  242. 'desc' => __( 'If checked tags of this entry will be shown', 'avia_framework' ),
  243. 'id' => 'meta_tags',
  244. 'type' => 'checkbox',
  245. 'std' => 'false',
  246. 'container_class' => 'av_half',
  247. 'lockable' => true
  248. ),
  249.  
  250. array(
  251. 'name' => __( 'Display Element Heading?', 'avia_framework' ),
  252. 'desc' => __( 'If checked you can enter a heading title with a link for this element', 'avia_framework' ),
  253. 'id' => 'heading_active',
  254. 'type' => 'checkbox',
  255. 'std' => '',
  256. 'lockable' => true
  257. ),
  258.  
  259. array(
  260. 'name' => __( 'Heading Text', 'avia_framework' ),
  261. 'desc' => __( 'Enter a custom heading text here. Options to customize heading tag and link are located in the &quot;Advanced&quot; tab.', 'avia_framework' ),
  262. 'id' => 'heading',
  263. 'type' => 'input',
  264. 'std' => '',
  265. 'required' => array( 'heading_active', 'not', '' ),
  266. 'lockable' => true,
  267. 'tmpl_set_default' => false
  268. )
  269. );
  270.  
  271. if( current_theme_supports( 'add_avia_builder_post_type_option' ) )
  272. {
  273. $element = array(
  274. 'type' => 'template',
  275. 'template_id' => 'avia_builder_post_type_option',
  276. 'lockable' => true
  277. );
  278.  
  279. array_unshift( $c, $element );
  280. }
  281.  
  282. $template = array(
  283. array(
  284. 'type' => 'template',
  285. 'template_id' => 'toggle',
  286. 'title' => __( 'Select Entries', 'avia_framework' ),
  287. 'content' => $c
  288. ),
  289. );
  290.  
  291. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_entries' ), $template );
  292.  
  293. $c = array(
  294. array(
  295. 'type' => 'template',
  296. 'template_id' => 'date_query',
  297. 'lockable' => true,
  298. 'period' => true
  299. )
  300.  
  301. );
  302.  
  303. $template = array(
  304. array(
  305. 'type' => 'template',
  306. 'template_id' => 'toggle',
  307. 'title' => __( 'Filter', 'avia_framework' ),
  308. 'content' => $c
  309. ),
  310. );
  311.  
  312. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_filter' ), $template );
  313.  
  314. /**
  315. * Styling Tab
  316. * ===========
  317. */
  318.  
  319. $c = array(
  320. array(
  321. 'name' => __( 'Number of entries per page', 'avia_framework' ),
  322. 'desc' => __( 'How many entries should be displayed?', 'avia_framework' ),
  323. 'id' => 'items',
  324. 'type' => 'select',
  325. 'std' => '5',
  326. 'lockable' => true,
  327. 'subtype' => AviaHtmlHelper::number_array( 1, 100, 1, array( 'All' => '-1' ) ) ),
  328.  
  329. array(
  330. 'name' => __( 'Pagination', 'avia_framework' ),
  331. 'desc' => __( 'Should a pagination be displayed to view additional entries? This disables &quot;Display Tabs for each category&quot;.', 'avia_framework' ),
  332. 'id' => 'paginate',
  333. 'type' => 'select',
  334. 'std' => '',
  335. 'lockable' => true,
  336. 'required' => array( 'items', 'not', '-1' ),
  337. 'subtype' => array(
  338. __( 'Display Pagination', 'avia_framework' ) => 'pagination',
  339. __( 'No Pagination', 'avia_framework' ) => ''
  340. )
  341. ),
  342.  
  343. array(
  344. 'name' => __( 'Offset Number', 'avia_framework' ),
  345. '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 blog or magazine element.', 'avia_framework' ),
  346. 'id' => 'offset',
  347. 'type' => 'select',
  348. 'std' => '0',
  349. 'lockable' => true,
  350. 'required' => array( 'paginate', 'equals', '' ),
  351. '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' ) )
  352. )
  353. );
  354.  
  355. $template = array(
  356. array(
  357. 'type' => 'template',
  358. 'template_id' => 'toggle',
  359. 'title' => __( 'Pagination', 'avia_framework' ),
  360. 'content' => $c
  361. ),
  362. );
  363.  
  364. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_pagination' ), $template );
  365.  
  366. $c = array(
  367. array(
  368. 'name' => __( 'Should the first entry be displayed bigger?', 'avia_framework' ),
  369. 'desc' => __( 'If checked the first entry will stand out with big image', 'avia_framework' ),
  370. 'id' => 'first_big',
  371. 'type' => 'checkbox',
  372. 'std' => '',
  373. 'lockable' => true
  374. ),
  375.  
  376. array(
  377. 'name' => __( 'First entry position', 'avia_framework' ),
  378. 'desc' => __( 'Where do you want to display the first entry?', 'avia_framework' ),
  379. 'id' => 'first_big_pos',
  380. 'type' => 'select',
  381. 'std' => 'top',
  382. 'lockable' => true,
  383. 'required' => array( 'first_big', 'not', '' ),
  384. 'subtype' => array(
  385. __( 'Display the first entry at the top of the others', 'avia_framework' ) => 'top',
  386. __( 'Display the first entry beside the others', 'avia_framework' ) => 'left'
  387. )
  388. ),
  389.  
  390. array(
  391. 'type' => 'template',
  392. 'template_id' => 'image_size_select',
  393. 'name' => __( 'Big Image Size', 'avia_framework' ),
  394. 'id' => 'image_big',
  395. 'std' => 'magazine',
  396. 'lockable' => true,
  397. 'required' => array( 'first_big', 'not', '' )
  398. ),
  399. );
  400.  
  401. $template = array(
  402. array(
  403. 'type' => 'template',
  404. 'template_id' => 'toggle',
  405. 'title' => __( 'General Styling', 'avia_framework' ),
  406. 'content' => $c
  407. ),
  408. );
  409.  
  410. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_general' ), $template );
  411.  
  412. $c = array(
  413. array(
  414. 'type' => 'template',
  415. 'template_id' => 'named_colors',
  416. 'name' => __( 'Heading Area Color', 'avia_framework' ),
  417. 'desc' => __( 'Choose a color for your heading area here', 'avia_framework' ),
  418. 'id' => 'heading_color',
  419. 'std' => 'theme-color',
  420. 'lockable' => true,
  421. 'required' => array( 'heading_active', 'not','' ),
  422. 'custom' => true,
  423. 'translucent' => array()
  424. ),
  425.  
  426. array(
  427. 'name' => __( 'Custom Font Color', 'avia_framework' ),
  428. 'desc' => __( 'Select a custom font color for your Heading area here', 'avia_framework' ),
  429. 'id' => 'heading_custom_color',
  430. 'type' => 'colorpicker',
  431. 'std' => '#ffffff',
  432. 'lockable' => true,
  433. 'required' => array( 'heading_color', 'equals', 'custom' )
  434. ),
  435.  
  436. );
  437.  
  438. $template = array(
  439. array(
  440. 'type' => 'template',
  441. 'template_id' => 'toggle',
  442. 'title' => __( 'Colors', 'avia_framework' ),
  443. 'content' => $c
  444. ),
  445. );
  446.  
  447. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_colors' ), $template );
  448.  
  449.  
  450. /**
  451. * Advanced Tab
  452. * ===========
  453. */
  454.  
  455. $c = array(
  456. array(
  457. 'type' => 'template',
  458. 'template_id' => 'heading_tag',
  459. 'theme_default' => 'a',
  460. 'context' => __CLASS__,
  461. 'lockable' => true,
  462. 'required' => array( 'heading_active', 'not', '' )
  463. ),
  464.  
  465. );
  466.  
  467. $template = array(
  468. array(
  469. 'type' => 'template',
  470. 'template_id' => 'toggle',
  471. 'title' => __( 'Heading Tag', 'avia_framework' ),
  472. 'content' => $c
  473. ),
  474. );
  475.  
  476. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_heading' ), $template );
  477.  
  478. $c = array(
  479. array(
  480. 'name' => __( 'Heading Link?', 'avia_framework' ),
  481. 'desc' => __( 'Where should the heading link to?', 'avia_framework' ),
  482. 'id' => 'heading_link',
  483. 'type' => 'linkpicker',
  484. 'fetchTMPL' => true,
  485. 'std' => '',
  486. 'lockable' => true,
  487. 'required' => array( 'heading_active', 'not', '' ),
  488. 'subtype' => array(
  489. __( 'Set Manually', 'avia_framework' ) => 'manually',
  490. __( 'Single Entry', 'avia_framework' ) => 'single',
  491. __( 'Taxonomy Overview Page', 'avia_framework' ) => 'taxonomy',
  492. ),
  493. ),
  494.  
  495. );
  496.  
  497. $template = array(
  498. array(
  499. 'type' => 'template',
  500. 'template_id' => 'toggle',
  501. 'title' => __( 'Link Settings', 'avia_framework' ),
  502. 'content' => $c
  503. ),
  504. );
  505.  
  506. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_link' ), $template );
  507.  
  508.  
  509. }
  510.  
  511. /**
  512. * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  513. * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  514. * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  515. *
  516. *
  517. * @param array $params this array holds the default values for $content and $args.
  518. * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  519. */
  520. function editor_element( $params )
  521. {
  522. $params = parent::editor_element( $params );
  523. $params['content'] = null; //remove to allow content elements
  524.  
  525. return $params;
  526. }
  527.  
  528. /**
  529. * Frontend Shortcode Handler
  530. *
  531. * @param array $atts array of attributes
  532. * @param string $content text within enclosing form of shortcode element
  533. * @param string $shortcodename the shortcode found, when == callback name
  534. * @return string $output returns the modified html string
  535. */
  536. function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' )
  537. {
  538. $default = avia_magazine::get_defaults();
  539.  
  540. $locked = array();
  541. Avia_Element_Templates()->set_locked_attributes( $atts, $this, $shortcodename, $default, $locked, $content );
  542. Avia_Element_Templates()->add_template_class( $meta, $atts, $default );
  543. $meta = aviaShortcodeTemplate::set_frontend_developer_heading_tag( $atts, $meta );
  544.  
  545. if( isset( $atts['img_scrset'] ) && 'disabled' == $atts['img_scrset'] )
  546. {
  547. Av_Responsive_Images()->force_disable( 'disabled' );
  548. }
  549.  
  550. $atts['class'] = $meta['el_class'];
  551. $atts['custom_markup'] = $meta['custom_markup'];
  552. $atts['custom_el_id'] = ! empty( $meta['custom_el_id'] ) ? $meta['custom_el_id'] : '';
  553. $atts['heading_tag'] = ! empty( $meta['heading_tag'] ) ? $meta['heading_tag'] : '';
  554. $atts['heading_class'] = ! empty( $meta['heading_class'] ) ? $meta['heading_class'] : '';
  555.  
  556. $mag = new avia_magazine( $atts );
  557. $mag->query_entries();
  558. $html = $mag->html();
  559.  
  560. Av_Responsive_Images()->force_disable( 'reset' );
  561.  
  562. return $html;
  563. }
  564. }
  565. }
  566.  
  567.  
  568. if( ! class_exists( 'avia_magazine' ) )
  569. {
  570. class avia_magazine
  571. {
  572. /**
  573. * @since < 4.0
  574. * @var int
  575. */
  576. static protected $magazine = 0;
  577.  
  578. /**
  579. * @since < 4.0
  580. * @var array
  581. */
  582. protected $atts;
  583.  
  584. /**
  585. * @since < 4.0
  586. * @var WP_Query
  587. */
  588. protected $entries;
  589.  
  590. /**
  591. * @since < 4.5.6
  592. * @var array
  593. */
  594. protected $screen_options;
  595.  
  596. /**
  597. *
  598. * @since 4.7.6.4
  599. * @var int
  600. */
  601. protected $current_page;
  602.  
  603. /**
  604. * @since < 4.0
  605. * @param array $atts
  606. */
  607. public function __construct( $atts = array() )
  608. {
  609. $this->atts = shortcode_atts( avia_magazine::get_defaults(), $atts, 'av_magazine' );
  610.  
  611. // @since 4.8.6.3
  612. if( 'no scaling' == $this->atts['image_big'] )
  613. {
  614. $this->atts['image_big'] = 'full';
  615. }
  616.  
  617. if( ! empty( $this->atts['image_big'] ) )
  618. {
  619. $this->atts['image_size']['big'] = $this->atts['image_big'];
  620. }
  621.  
  622. $this->entries = null;
  623. $this->screen_options = AviaHelper::av_mobile_sizes( $atts );
  624. $this->current_page = 1;
  625. self::$magazine++;
  626.  
  627. /**
  628. * When pagination, tabs are not possible
  629. */
  630. if( ! empty( $this->atts['paginate'] ) )
  631. {
  632. $this->atts['tabs'] = false;
  633. $this->atts['offset'] = 0;
  634. }
  635.  
  636. // fetch the taxonomy and the taxonomy ids
  637. $this->extract_terms();
  638.  
  639. //convert checkbox to true/false
  640. $this->atts['tabs'] = $this->atts['tabs'] === 'aviaTBtabs' ? true : false;
  641. $this->atts['thumbnails'] = $this->atts['thumbnails'] === 'aviaTBthumbnails' ? true : false;
  642.  
  643.  
  644. //filter the attributes
  645. $this->atts = apply_filters( 'avf_magazine_settings', $this->atts, self::$magazine );
  646.  
  647. //set small or big
  648. if( empty( $this->atts['first_big'] ) )
  649. {
  650. $this->atts['first_big_pos'] = '';
  651. }
  652.  
  653. //set heading text
  654. if( empty( $this->atts['heading_active'] ) )
  655. {
  656. $this->atts['heading'] = '';
  657. }
  658.  
  659. //set if top bar is active
  660. $this->atts['top_bar'] = ! empty( $this->atts['heading'] ) || ! empty( $this->atts['tabs'] ) ? 'av-magazine-top-bar-active' : '';
  661. }
  662.  
  663. /**
  664. *
  665. * @since 4.5.6
  666. */
  667. public function __destruct()
  668. {
  669. unset( $this->screen_options );
  670. unset( $this->atts );
  671. unset( $this->entries );
  672. }
  673.  
  674. /**
  675. * Returns the defaults array for this class
  676. *
  677. * @since 4.8
  678. * @return array
  679. */
  680. static public function get_defaults()
  681. {
  682. $default = array(
  683. 'class' => '',
  684. 'custom_markup' => '',
  685. 'items' => '16',
  686. 'paginate' => '',
  687. 'tabs' => false,
  688. 'thumbnails' => true,
  689. 'meta_author' => false,
  690. 'meta_cats' => false,
  691. 'meta_tags' => false,
  692. 'heading_active' => false,
  693. 'heading' => '',
  694. 'heading_link' => '',
  695. 'heading_color' => '',
  696. 'heading_custom_color' => '',
  697. 'first_big' => false,
  698. 'first_big_pos' => 'top',
  699. 'taxonomy' => 'category',
  700. 'link' => '',
  701. 'categories' => array(),
  702. 'extra_categories' => array(),
  703. 'post_type' => array(),
  704. 'offset' => 0,
  705. 'image_size' => array( 'small' => 'thumbnail', 'big' => 'magazine' ),
  706. 'image_big' => 'magazine',
  707. 'date_filter' => '',
  708. 'date_filter_start' => '',
  709. 'date_filter_end' => '',
  710. 'date_filter_format' => 'yy/mm/dd', // 'yy/mm/dd' | 'dd-mm-yy' | yyyymmdd
  711. 'period_filter_unit_1' => '',
  712. 'period_filter_unit_2' => '',
  713. 'custom_el_id' => '',
  714. 'heading_tag' => '',
  715. 'heading_class' => '',
  716. 'lazy_loading' => 'enabled',
  717. 'img_scrset' => ''
  718. );
  719.  
  720. return $default;
  721. }
  722.  
  723.  
  724. /**
  725. *
  726. * @since < 4.0
  727. */
  728. protected function extract_terms()
  729. {
  730. if( isset($this->atts['link'] ) )
  731. {
  732. $this->atts['link'] = explode( ',', $this->atts['link'], 2 );
  733. $this->atts['taxonomy'] = $this->atts['link'][0];
  734.  
  735. if( isset( $this->atts['link'][1] ) )
  736. {
  737. $this->atts['categories'] = $this->atts['link'][1];
  738. }
  739. else
  740. {
  741. $this->atts['categories'] = array();
  742. }
  743. }
  744. }
  745.  
  746. /**
  747. *
  748. * @since < 4.0
  749. * @return string
  750. */
  751. protected function sort_buttons()
  752. {
  753. $term_args = array(
  754. 'taxonomy' => $this->atts['taxonomy'],
  755. 'hide_empty' => true
  756. );
  757. /**
  758. * To display private posts you need to set 'hide_empty' to false,
  759. * otherwise a category with ONLY private posts will not be returned !!
  760. *
  761. * You also need to add post_status 'private' to the query params with filter avf_magazine_entries_query.
  762. *
  763. * @since 4.4.2
  764. * @added_by Günter
  765. * @param array $term_args
  766. * @param string $context
  767. * @return array
  768. */
  769. $term_args = apply_filters( 'avf_av_magazine_term_args', $term_args, 'sort_button' );
  770.  
  771. $sort_terms = AviaHelper::get_terms( $term_args );
  772.  
  773. $current_page_terms = array();
  774. $term_count = array();
  775. $display_terms = is_array( $this->atts['categories'] ) ? $this->atts['categories'] : array_filter( explode( ',', $this->atts['categories'] ) );
  776.  
  777. $output = '<div class="av-magazine-sort" data-magazine-id="' . self::$magazine . '" >';
  778.  
  779. $first_item_name = apply_filters( 'avf_magazine_sort_first_label', __( 'All', 'avia_framework' ), $this->atts );
  780.  
  781. $output .= '<div class="av-sort-by-term">';
  782. $output .= '<a href="#" data-filter="sort_all" class="all_sort_button active_sort"><span class="inner_sort_button"><span>' . $first_item_name . '</span></span></a>';
  783.  
  784. foreach( $sort_terms as $term )
  785. {
  786. if ( ! in_array( $term->term_id, $display_terms ) )
  787. {
  788. continue;
  789. }
  790.  
  791. if( ! isset( $term_count[ $term->term_id ] ) )
  792. {
  793. $term_count[ $term->term_id ] = 0;
  794. }
  795.  
  796. $term->slug = str_replace( '%', '', $term->slug );
  797.  
  798. $output .= "<span class='text-sep {$term->slug}_sort_sep'>/</span>";
  799. $output .= '<a href="#" data-filter="sort_' . $term->term_id . '" class="' . $term->slug . '_sort_button " ><span class="inner_sort_button">';
  800. $output .= '<span>' . esc_html( trim( $term->name ) ) . '</span>';
  801. $output .= '</span>';
  802. $output .= '</a>';
  803.  
  804. $this->atts['extra_categories'][] = $term->term_id;
  805. }
  806.  
  807. $output .= '</div></div>';
  808.  
  809. if( count( $this->atts['extra_categories'] ) <= 1 )
  810. {
  811. return '';
  812. }
  813.  
  814. return $output;
  815. }
  816.  
  817. /**
  818. * Fetch new entries
  819. *
  820. * @since < 4.0
  821. * @param array $params
  822. * @param boolean $return
  823. * @return WP_Query
  824. */
  825. public function query_entries( $params = array(), $return = false )
  826. {
  827. global $avia_config;
  828.  
  829. if( empty( $params ) )
  830. {
  831. $params = $this->atts;
  832. }
  833.  
  834. if( empty( $params['custom_query'] ) )
  835. {
  836. $query = array();
  837.  
  838. if( ! empty( $params['categories'] ) )
  839. {
  840. //get the portfolio categories
  841. $terms = explode( ',', $params['categories'] );
  842. }
  843.  
  844. $this->current_page = ( $params['paginate'] != '' ) ? avia_get_current_pagination_number( 'avia-element-paging' ) : 1;
  845.  
  846. //if we find no terms for the taxonomy fetch all taxonomy terms
  847. if( empty( $terms[0] ) || is_null( $terms[0] ) || $terms[0] == 'null' )
  848. {
  849. $term_args = array(
  850. 'taxonomy' => $params['taxonomy'],
  851. 'hide_empty' => true
  852. );
  853. /**
  854. * To display private posts you need to set 'hide_empty' to false,
  855. * otherwise a category with ONLY private posts will not be returned !!
  856. *
  857. * You also need to add post_status 'private' to the query params with filter avf_magazine_entries_query.
  858. *
  859. * @since 4.4.2
  860. * @added_by Günter
  861. * @param array $term_args
  862. * @param string $context
  863. * @return array
  864. */
  865. $term_args = apply_filters( 'avf_av_magazine_term_args', $term_args, 'query_entries' );
  866.  
  867. $allTax = AviaHelper::get_terms( $term_args );
  868.  
  869. $terms = array();
  870. foreach( $allTax as $tax )
  871. {
  872. $terms[] = $tax->term_id;
  873. }
  874. }
  875.  
  876. if( $params['offset'] == 'no_duplicates' )
  877. {
  878. $params['offset'] = 0;
  879. if( empty($params['ignore_duplicate_rule'] ) )
  880. {
  881. $no_duplicates = true;
  882. }
  883. }
  884.  
  885. if( empty( $params['post_type'] ) )
  886. {
  887. $params['post_type'] = get_post_types();
  888. }
  889.  
  890. if( is_string( $params['post_type'] ) )
  891. {
  892. $params['post_type'] = explode( ',', $params['post_type'] );
  893. }
  894.  
  895. $date_query = AviaHelper::date_query( array(), $params );
  896.  
  897. $query = array(
  898. 'orderby' => 'date',
  899. 'order' => 'DESC',
  900. 'paged' => $this->current_page,
  901. 'post_type' => $params['post_type'],
  902. 'post__not_in' => ( ! empty($no_duplicates ) ) ? $avia_config['posts_on_current_page'] : array(),
  903. 'offset' => $params['offset'] != 0 ? $params['offset'] : false,
  904. 'posts_per_page' => $params['items'],
  905. 'date_query' => $date_query,
  906. 'tax_query' => array( array(
  907. 'taxonomy' => $params['taxonomy'],
  908. 'field' => 'id',
  909. 'terms' => $terms,
  910. 'operator' => 'IN'
  911. )
  912. )
  913. );
  914.  
  915. }
  916. else
  917. {
  918. $query = $params['custom_query'];
  919. }
  920.  
  921. /**
  922. *
  923. * @since < 4.0
  924. * @param array $query
  925. * @param array $params
  926. * @return array
  927. */
  928. $query = apply_filters( 'avf_magazine_entries_query', $query, $params );
  929.  
  930. $entries = new WP_Query( $query );
  931.  
  932. if( ( $entries->post_count > 0 ) && empty( $params['ignore_duplicate_rule'] ) )
  933. {
  934. foreach( $entries->posts as $entry )
  935. {
  936. $avia_config['posts_on_current_page'][] = $entry->ID;
  937. }
  938. }
  939.  
  940. if( $return )
  941. {
  942. return $entries;
  943. }
  944. else
  945. {
  946. $this->entries = $entries;
  947. }
  948. }
  949.  
  950. /**
  951. *
  952. * @since < 4.0
  953. * @return string
  954. */
  955. public function html()
  956. {
  957. if( empty( $this->entries->posts ) )
  958. {
  959. return '';
  960. }
  961.  
  962. $output = '';
  963. $class = ! empty( $this->atts['first_big_pos'] ) ? ' av-magazine-hero-' . $this->atts['first_big_pos'] : '';
  964. $class .= ' ' . $this->atts['top_bar'];
  965. if( ! empty( $this->atts['tabs'] ) )
  966. {
  967. $class .= ' av-magazine-tabs-active';
  968. }
  969.  
  970. extract( $this->screen_options ); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  971.  
  972. $id = ! empty( $this->atts['custom_el_id'] ) ? $this->atts['custom_el_id'] : ' id="' . self::$magazine . '" ';
  973.  
  974. $output .= "<div {$id} class='av-magazine {$av_display_classes} {$this->atts['class']} {$class}' >";
  975.  
  976. if( $this->atts['top_bar'] )
  977. {
  978. $link = AviaHelper::get_url( $this->atts['heading_link'] );
  979. $heading = $this->atts['heading'];
  980. $b_class = '';
  981. $b_style = '';
  982.  
  983. if( $this->atts['heading_color'] != 'theme-color' )
  984. {
  985. if( $this->atts['heading_color'] == 'custom' )
  986. {
  987. $b_style = "style='color: ".$this->atts['heading_custom_color'].";'";
  988. }
  989.  
  990. $b_class .= "avia-font-color-{$this->atts['heading_color']} avia-inherit-font-color";
  991. }
  992.  
  993. $output .= "<div class='av-magazine-top-bar {$b_class}' {$b_style}>";
  994.  
  995. if( $heading )
  996. {
  997. $heading_tag = ( ! in_array( $this->atts['heading_tag'], array( '', 'a' ) ) ) ? $this->atts['heading_tag'] : '';
  998. $heading_class = $this->atts['heading_class'];
  999.  
  1000. if( ! empty( $heading_tag ) )
  1001. {
  1002. $output .= "<{$heading_tag} class='{$heading_class}'>";
  1003. $heading_class = '';
  1004. }
  1005.  
  1006. $output .= "<a href='{$link}' class='av-magazine-top-heading {$heading_class}'>{$heading}</a>";
  1007.  
  1008. if( ! empty( $heading_tag ) )
  1009. {
  1010. $output .= "</{$heading_tag}>";
  1011. $heading_class = '';
  1012. }
  1013. }
  1014.  
  1015. if(!empty($this->atts['tabs']))
  1016. {
  1017. $output .= $this->sort_buttons();
  1018. }
  1019.  
  1020. $output .= '</div>';
  1021. }
  1022.  
  1023.  
  1024. //magazine main loop
  1025. $output .= $this->magazine_loop( $this->entries->posts );
  1026.  
  1027.  
  1028. //magazine sub loops
  1029. $output .= $this->magazine_sub_loop();
  1030.  
  1031. //append pagination
  1032. if( $this->atts['paginate'] == 'pagination' && $avia_pagination = avia_pagination( $this->entries->max_num_pages, 'nav', 'avia-element-paging', $this->current_page ) )
  1033. {
  1034. $output .= "<div class='av-masonry-pagination av-masonry-pagination-{$this->atts['paginate']}'>{$avia_pagination}</div>";
  1035. }
  1036.  
  1037. $output .= '</div>';
  1038. return $output;
  1039. }
  1040.  
  1041. /**
  1042. *
  1043. * @since < 4.0
  1044. * @return string
  1045. */
  1046. protected function magazine_sub_loop()
  1047. {
  1048. $output = '';
  1049.  
  1050. if( ! empty( $this->atts['extra_categories'] ) && count( $this->atts['extra_categories'] ) > 1 )
  1051. {
  1052. foreach( $this->atts['extra_categories'] as $category )
  1053. {
  1054. $params = $this->atts;
  1055. $params['ignore_duplicate_rule'] = true;
  1056. $params['categories'] = $category;
  1057. $params['sort_var'] = $category;
  1058.  
  1059. $entries = $this->query_entries( $params, true );
  1060. $output .= $this->magazine_loop( $entries->posts, $params );
  1061.  
  1062. }
  1063. }
  1064.  
  1065. return $output;
  1066. }
  1067.  
  1068.  
  1069.  
  1070. /**
  1071. *
  1072. * @since < 4.0
  1073. * @param array $entries WP_Post objects
  1074. * @param array $params
  1075. * @return string
  1076. */
  1077. protected function magazine_loop( array $entries, $params = array() )
  1078. {
  1079. $output = '';
  1080. $loop = 0;
  1081. $grid = $this->atts['first_big_pos'] == 'left' ? 'flex_column av_one_half ' : '';
  1082. $html = ! empty( $this->atts['first_big_pos'] ) ? array( 'before' => "<div class='av-magazine-hero first {$grid}'>", 'after' => '</div>' ) : array( 'before' => '', 'after' => '' );
  1083. $css = empty( $params['sort_var'] ) ? 'sort_all' : 'av-hidden-mag sort_' . $params['sort_var'];
  1084.  
  1085. if( ! empty( $entries ) )
  1086. {
  1087. $output .= "<div class='av-magazine-group {$css}'>";
  1088.  
  1089. foreach( $entries as $entry )
  1090. {
  1091. $loop ++;
  1092. $entry->loop = $loop;
  1093.  
  1094. $style = ( $loop == 1 && ! empty( $this->atts['first_big'] ) ) ? 'big' : 'small';
  1095.  
  1096. if( $loop == 2 && ! empty( $html['before'] ) )
  1097. {
  1098. $html = array( 'before' => "<div class='av-magazine-sideshow {$grid}'>" , 'after' => '' );
  1099. }
  1100.  
  1101. if( $loop == 3 )
  1102. {
  1103. $html = array( 'before' => '', 'after' => '' );
  1104. }
  1105.  
  1106. $output .= $html['before'];
  1107. $output .= $this->render_entry( $entry, $style );
  1108. $output .= $html['after'];
  1109. }
  1110.  
  1111. if( $loop != 1 && ! empty( $this->atts['first_big_pos'] ) )
  1112. {
  1113. $output .= '</div>';
  1114. }
  1115.  
  1116. $output .= '</div>';
  1117. }
  1118. else
  1119. {
  1120. // output empty container - otherwise frontend sort breaks
  1121. $output .= "<div class='av-magazine-group {$css}'></div>";
  1122. }
  1123.  
  1124. return $output;
  1125. }
  1126.  
  1127.  
  1128. /**
  1129. *
  1130. * @since < 4.0
  1131. * @param WP_Post $entry
  1132. * @param string $style
  1133. * @return string
  1134. */
  1135. protected function render_entry( WP_Post $entry, $style )
  1136. {
  1137. $output = '';
  1138.  
  1139. $post_thumbnail_id = get_post_thumbnail_id( $entry->ID );
  1140.  
  1141. if( $this->atts['lazy_loading'] != 'enabled' )
  1142. {
  1143. Av_Responsive_Images()->add_attachment_id_to_not_lazy_loading( $post_thumbnail_id );
  1144. }
  1145.  
  1146. $image = get_the_post_thumbnail( $entry->ID, $this->atts['image_size'][ $style ] );
  1147.  
  1148. $link = get_permalink( $entry->ID );
  1149. $titleAttr = the_title_attribute( array( 'echo' => false, 'post' => $entry->ID ) );
  1150.  
  1151. /**
  1152. * Allow post-format link same behaviour as on single post
  1153. *
  1154. * @since 4.7.3
  1155. */
  1156. if( get_post_meta( $entry->ID , '_portfolio_custom_link', true ) != '' )
  1157. {
  1158. $link = get_post_meta( $entry->ID ,'_portfolio_custom_link_url', true );
  1159. }
  1160. else
  1161. {
  1162. $post_format = get_post_format( $entry );
  1163. if( ( $post_format == 'link' ) && function_exists( 'avia_link_content_filter' ) )
  1164. {
  1165. $post['title'] = $entry->post_title;
  1166. $post['content'] = $entry->post_content;
  1167. $post = avia_link_content_filter( $post );
  1168. if( ! empty( $post['url'] ) )
  1169. {
  1170. $link = $post['url'];
  1171. }
  1172. }
  1173. }
  1174.  
  1175. $titleAttr = "title='" . __( 'Link to:', 'avia_framework' ) . " {$titleAttr}'";
  1176. $title = "<a href='{$link}' {$titleAttr}>". apply_filters( 'avf_magazine_title', get_the_title( $entry->ID ), $entry ) . '</a>';
  1177. $excerpt = '';
  1178. $time = get_the_time( get_option('date_format'), $entry->ID );
  1179. $separator = '';
  1180.  
  1181. $default_heading = 'h3';
  1182. $args = array(
  1183. 'heading' => $default_heading,
  1184. 'extra_class' => ''
  1185. );
  1186.  
  1187. $extra_args = array( $this, $entry, $style );
  1188.  
  1189. /**
  1190. * @since 4.5.7.1
  1191. * @return array
  1192. */
  1193. $args = apply_filters( 'avf_customize_heading_settings', $args, __CLASS__, $extra_args );
  1194.  
  1195. $titleTag = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  1196. $titleCss = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
  1197.  
  1198. $author = '';
  1199. if( ! empty( $this->atts['meta_author'] ) )
  1200. {
  1201. $author_link = get_author_posts_url( $entry->post_author );
  1202. $author_name = apply_filters( 'avf_author_name', get_the_author_meta( 'display_name', $entry->post_author ), $entry->post_author );
  1203. $author_link = '<a href="' . $author_link . '" title="' . __( 'by', 'avia_framework' ) . ' ' . $author_name . '" rel="author">' . $author_name . '</a>';
  1204.  
  1205. $author_output = '<span class="av-magazine-author minor-meta">' . __( 'by', 'avia_framework' ) . ' ';
  1206. $author_output .= '<span class="av-magazine-author-link" ' . avia_markup_helper( array( 'context' => 'author_name', 'echo' => false ) ) . '>';
  1207. $author_output .= "<span class='av-magazine-author meta-color author'><span class='fn'>";
  1208. $author_output .= $author_link;
  1209. $author_output .= '</span></span>';
  1210. $author_output .= '</span>';
  1211. $author_output .= '</span>';
  1212.  
  1213. $author .= '<span class="av-magazine-author-wrap">';
  1214. $author .= '<span class="av-magazine-text-sep text-sep-date">/</span>';
  1215. $author .= $author_output;
  1216. $author .= '</span>';
  1217. }
  1218.  
  1219. $cats = '';
  1220. if( ! empty( $this->atts['meta_cats'] ) )
  1221. {
  1222. $taxonomies = get_object_taxonomies( $entry->post_type );
  1223.  
  1224. $excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array( 'post_tag', 'post_format' ) );
  1225.  
  1226. /**
  1227. * @since 4.5.7.1
  1228. * @param array
  1229. * @param string $entry->post_type
  1230. * @param int $entry->ID
  1231. * @return array
  1232. */
  1233. $excluded_taxonomies = apply_filters( 'avf_exclude_taxonomies_magazine', $excluded_taxonomies, $entry->post_type, $entry->ID );
  1234.  
  1235. if( ! empty( $taxonomies ) )
  1236. {
  1237. foreach( $taxonomies as $taxonomy )
  1238. {
  1239. if( ! in_array( $taxonomy, $excluded_taxonomies ) )
  1240. {
  1241. $cats .= get_the_term_list( $entry->ID, $taxonomy, '', ', ','') . ' ';
  1242. }
  1243. }
  1244. }
  1245.  
  1246. if( ! empty( $cats ) )
  1247. {
  1248. $cats_html = '<span class="av-magazine-cats-wrap">';
  1249. $cats_html .= '<span class="av-magazine-text-sep text-sep-cats">In</span>';
  1250. $cats_html .= '<span class="av-magazine-cats minor-meta">';
  1251. $cats_html .= $cats;
  1252. $cats_html .= '</span>';
  1253. $cats_html .= '</span>';
  1254.  
  1255. $cats = $cats_html;
  1256. }
  1257. }
  1258.  
  1259. $tags = '';
  1260. if( ! empty( $this->atts['meta_tags'] ) )
  1261. {
  1262. $tag_list = get_the_term_list( $entry->ID, 'post_tag', '<span class="av-magazine-text-sep text-sep-tags">' . __( 'Tags:', 'avia_framework' ) . '</span><span class="av-magazine-tags minor-meta">', ', ', '' );
  1263.  
  1264. if( ! empty( $tag_list ) )
  1265. {
  1266. $tags_html = '<span class="av-magazine-tags-wrap">';
  1267. $tags_html .= $tag_list;
  1268. $tags_html .= '</span></span>';
  1269.  
  1270. $tags = $tags_html;
  1271. }
  1272. }
  1273.  
  1274.  
  1275. $markupEntry = avia_markup_helper( array( 'context' => 'entry', 'echo' => false, 'id' => $entry->ID, 'custom_markup' => $this->atts['custom_markup'] ) );
  1276. $markupTitle = avia_markup_helper( array( 'context' => 'entry_title', 'echo' => false, 'id' => $entry->ID, 'custom_markup' => $this->atts['custom_markup'] ) );
  1277. $markupContent = avia_markup_helper( array( 'context' => 'entry_content', 'echo' => false, 'id' => $entry->ID, 'custom_markup' => $this->atts['custom_markup'] ) );
  1278. $markupTime = avia_markup_helper( array( 'context' => 'entry_time', 'echo' => false, 'id' => $entry->ID, 'custom_markup' => $this->atts['custom_markup'] ) );
  1279.  
  1280. $format = get_post_format( $entry->ID ) ? get_post_format( $entry->ID ) : 'standard';
  1281. $type = get_post_type( $entry->ID );
  1282. $icontype = $type == 'post' ? $format : $type;
  1283. $icon = "<a href='{$link}' {$titleAttr} class='iconfont av-magazine-entry-icon' " . av_icon_string( $icontype ) . '></a>';
  1284. $extraClass = '';
  1285.  
  1286. if( $style == 'small' )
  1287. {
  1288. if( empty( $this->atts['thumbnails'] ) )
  1289. {
  1290. $image = '';
  1291. $extraClass = 'av-magazine-no-thumb';
  1292. }
  1293. }
  1294. else
  1295. {
  1296. $excerpt = ! empty( $entry->post_excerpt ) ? $entry->post_excerpt : avia_backend_truncate( $entry->post_content, apply_filters( 'avf_magazine_excerpt_length', 60 ), apply_filters( 'avf_magazine_excerpt_delimiter', ' ' ), '…', true, '' );
  1297. }
  1298.  
  1299.  
  1300. $output .= "<article class='av-magazine-entry av-magazine-entry-id-{$entry->ID} av-magazine-format-{$format} av-magazine-type-{$type} av-magazine-entry-{$entry->loop} av-magazine-entry-{$style} {$extraClass}' {$markupEntry}>";
  1301.  
  1302. if( $this->atts['thumbnails'] || ( $style == 'big' && $image ) )
  1303. {
  1304. $output .= '<div class="av-magazine-thumbnail">';
  1305.  
  1306. if( $image )
  1307. {
  1308. $output .= "<a href='{$link}' {$titleAttr} class='av-magazine-thumbnail-link'>{$image}</a>";
  1309. }
  1310. else
  1311. {
  1312. $output .= $icon;
  1313. }
  1314.  
  1315. $output .="</div>";
  1316. }
  1317.  
  1318. $header_content = array(
  1319. 'time' => "<time class='av-magazine-time updated' {$markupTime}>{$time}</time>",
  1320. 'author' => $author,
  1321. 'cats' => $cats,
  1322. 'tags' => $tags,
  1323. 'title' => "<{$titleTag} class='av-magazine-title entry-title {$titleCss}' {$markupTitle}>{$title}</{$titleTag}>"
  1324. );
  1325.  
  1326. /**
  1327. * @since 4.8.7.2
  1328. * @param array $header_content
  1329. * @param WP_Post $entry
  1330. * @return array
  1331. */
  1332. $header_content = apply_filters( 'avf_magazine_header_content', $header_content, $entry );
  1333.  
  1334. $output .= '<div class="av-magazine-content-wrap">';
  1335. $output .= '<header class="entry-content-header">';
  1336. $output .= implode( '', $header_content );
  1337. $output .= '</header>';
  1338. if( $excerpt )
  1339. {
  1340. $output .= "<div class='av-magazine-content entry-content' {$markupContent}>{$excerpt}</div>";
  1341. }
  1342. $output .= '</div>';
  1343. $output .= '<footer class="entry-footer"></footer>';
  1344. $output .= '</article>';
  1345.  
  1346. return $output;
  1347. }
  1348. }
  1349. }
  1350.  
  1351.  
Advertisement
Add Comment
Please, Sign In to add comment