Guest User

Untitled

a guest
Dec 21st, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.09 KB | None | 0 0
  1. <?php
  2. /**
  3. * Masonry Gallery
  4. *
  5. * Shortcode that allows to display a fullwidth masonry of any post type
  6. */
  7. if( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly
  8.  
  9.  
  10. if( ! class_exists( 'avia_sc_masonry_gallery', false ) )
  11. {
  12. class avia_sc_masonry_gallery extends aviaShortcodeTemplate
  13. {
  14. /**
  15. * @since 4.5.7.2
  16. * @var int
  17. */
  18. static protected $gallery_count = 0;
  19.  
  20. /**
  21. * Save avia_masonry objects for reuse. As we need to access the same object when creating the post css file in header,
  22. * create the styles and HTML creation. Makes sure to get the same id.
  23. *
  24. * $element_id => avia_masonry
  25. *
  26. * @since 4.8.4
  27. * @var array
  28. */
  29. protected $obj_masonry = array();
  30.  
  31. /**
  32. * @since 4.8.9
  33. * @param AviaBuilder $builder
  34. */
  35. public function __construct( AviaBuilder $builder )
  36. {
  37. parent::__construct( $builder );
  38.  
  39. $this->obj_masonry = array();
  40. }
  41.  
  42. /**
  43. * @since 4.8.9
  44. */
  45. public function __destruct()
  46. {
  47. unset( $this->obj_masonry );
  48.  
  49. parent::__destruct();
  50. }
  51.  
  52. /**
  53. * Create the config array for the shortcode button
  54. */
  55. protected function shortcode_insert_button()
  56. {
  57. $this->config['version'] = '1.0';
  58. $this->config['is_fullwidth'] = 'yes';
  59. $this->config['base_element'] = 'yes';
  60.  
  61. /**
  62. * inconsistent behaviour up to 4.2: a new element was created with a close tag, after editing it was self closing !!!
  63. * @since 4.2.1: We make new element self closing now because no id='content' exists.
  64. */
  65. $this->config['self_closing'] = 'yes';
  66.  
  67. $this->config['name'] = __( 'Masonry Gallery', 'avia_framework' );
  68. $this->config['tab'] = __( 'Media Elements', 'avia_framework' );
  69. $this->config['icon'] = AviaBuilder::$path['imagesURL'] . 'sc-masonry-gallery.png';
  70. $this->config['order'] = 5;
  71. $this->config['target'] = 'avia-target-insert';
  72. $this->config['shortcode'] = 'av_masonry_gallery';
  73. $this->config['tooltip'] = __( 'Display a fullwidth masonry/grid gallery', 'avia_framework' );
  74. $this->config['drag-level'] = 3;
  75. $this->config['preview'] = false;
  76. $this->config['disabling_allowed'] = true;
  77. $this->config['id_name'] = 'id';
  78. $this->config['id_show'] = 'always';
  79. $this->config['alb_desc_id'] = 'alb_description';
  80. }
  81.  
  82. protected function admin_assets()
  83. {
  84. add_action( 'wp_ajax_avia_ajax_masonry_more', array( 'avia_masonry', 'handler_ajax_load_more' ) );
  85. add_action( 'wp_ajax_nopriv_avia_ajax_masonry_more', array( 'avia_masonry', 'handler_ajax_load_more' ) );
  86. }
  87.  
  88.  
  89. protected function extra_assets()
  90. {
  91. $ver = Avia_Builder()->get_theme_version();
  92. $min_js = avia_minify_extension( 'js' );
  93. $min_css = avia_minify_extension( 'css' );
  94.  
  95. wp_enqueue_style( 'avia-module-masonry', AviaBuilder::$path['pluginUrlRoot'] . "avia-shortcodes/masonry_entries/masonry_entries{$min_css}.css", array( 'avia-layout' ), $ver );
  96.  
  97. //loading icon
  98. wp_enqueue_style( 'avia-siteloader', get_template_directory_uri() . "/css/avia-snippet-site-preloader{$min_css}.css", array( 'avia-layout' ), $ver );
  99.  
  100. wp_enqueue_script( 'avia-module-isotope', AviaBuilder::$path['pluginUrlRoot'] . 'avia-shortcodes/portfolio/isotope.min.js', array( 'avia-shortcodes' ), $ver , true );
  101. wp_enqueue_script( 'avia-module-masonry', AviaBuilder::$path['pluginUrlRoot'] . "avia-shortcodes/masonry_entries/masonry_entries{$min_js}.js", array( 'avia-module-isotope' ), $ver, true );
  102. }
  103.  
  104. /**
  105. * Popup Elements
  106. *
  107. * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  108. * opens a modal window that allows to edit the element properties
  109. *
  110. * @return void
  111. */
  112. protected function popup_elements()
  113. {
  114. $this->elements = array(
  115.  
  116. array(
  117. 'type' => 'tab_container',
  118. 'nodescription' => true
  119. ),
  120.  
  121. array(
  122. 'type' => 'tab',
  123. 'name' => __( 'Content', 'avia_framework' ),
  124. 'nodescription' => true
  125. ),
  126.  
  127. array(
  128. 'type' => 'template',
  129. 'template_id' => 'toggle_container',
  130. 'templates_include' => array(
  131. $this->popup_key( 'content_entries' ),
  132. $this->popup_key( 'content_captions' ),
  133. $this->popup_key( 'content_copyright' )
  134. ),
  135. 'nodescription' => true
  136. ),
  137.  
  138. array(
  139. 'type' => 'tab_close',
  140. 'nodescription' => true
  141. ),
  142.  
  143. array(
  144. 'type' => 'tab',
  145. 'name' => __( 'Styling', 'avia_framework' ),
  146. 'nodescription' => true
  147. ),
  148.  
  149. array(
  150. 'type' => 'template',
  151. 'template_id' => 'toggle_container',
  152. 'templates_include' => array(
  153. $this->popup_key( 'styling_masonry' ),
  154. $this->popup_key( 'styling_columns' ),
  155. $this->popup_key( 'styling_pagination' ),
  156. $this->popup_key( 'styling_colors' ),
  157. $this->popup_key( 'styling_copyright' )
  158. ),
  159. 'nodescription' => true
  160. ),
  161.  
  162. array(
  163. 'type' => 'tab_close',
  164. 'nodescription' => true
  165. ),
  166.  
  167. array(
  168. 'type' => 'tab',
  169. 'name' => __( 'Advanced', 'avia_framework' ),
  170. 'nodescription' => true
  171. ),
  172.  
  173. array(
  174. 'type' => 'toggle_container',
  175. 'nodescription' => true
  176. ),
  177.  
  178. array(
  179. 'type' => 'template',
  180. 'template_id' => $this->popup_key( 'advanced_animation' )
  181. ),
  182.  
  183. array(
  184. 'type' => 'template',
  185. 'template_id' => $this->popup_key( 'advanced_link' )
  186. ),
  187.  
  188. array(
  189. 'type' => 'template',
  190. 'template_id' => 'lazy_loading_toggle',
  191. 'lockable' => true
  192. ),
  193.  
  194. array(
  195. 'type' => 'template',
  196. 'template_id' => 'screen_options_toggle',
  197. 'lockable' => true
  198. ),
  199.  
  200. array(
  201. 'type' => 'template',
  202. 'template_id' => 'developer_options_toggle',
  203. 'args' => array( 'sc' => $this )
  204. ),
  205.  
  206. array(
  207. 'type' => 'toggle_container_close',
  208. 'nodescription' => true
  209. ),
  210.  
  211. array(
  212. 'type' => 'tab_close',
  213. 'nodescription' => true
  214. ),
  215.  
  216. array(
  217. 'type' => 'template',
  218. 'template_id' => 'element_template_selection_tab',
  219. 'args' => array( 'sc' => $this )
  220. ),
  221.  
  222. array(
  223. 'type' => 'tab_container_close',
  224. 'nodescription' => true
  225. )
  226.  
  227. );
  228. }
  229.  
  230. /**
  231. * Create and register templates for easier maintainance
  232. *
  233. * @since 4.6.4
  234. */
  235. protected function register_dynamic_templates()
  236. {
  237.  
  238. /**
  239. * Content Tab
  240. * ===========
  241. */
  242.  
  243. $c = array(
  244. array(
  245. 'name' => __( 'Edit Gallery', 'avia_framework' ),
  246. 'desc' => __( 'Create a new Gallery by selecting existing or uploading new images', 'avia_framework' ),
  247. 'id' => 'ids',
  248. 'type' => 'gallery',
  249. 'title' => __( 'Add/Edit Gallery', 'avia_framework' ),
  250. 'button' => __( 'Insert Images', 'avia_framework' ),
  251. 'std' => '',
  252. 'modal_class' => 'av-show-image-custom-link',
  253. 'lockable' => true
  254. )
  255. );
  256.  
  257. $template = array(
  258. array(
  259. 'type' => 'template',
  260. 'template_id' => 'toggle',
  261. 'title' => __( 'Select Images', 'avia_framework' ),
  262. 'content' => $c
  263. )
  264. );
  265.  
  266. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_entries' ), $template );
  267.  
  268. $c = array(
  269. array(
  270. 'type' => 'template',
  271. 'template_id' => 'masonry_captions',
  272. 'lockable' => true,
  273. )
  274.  
  275. );
  276.  
  277. $template = array(
  278. array(
  279. 'type' => 'template',
  280. 'template_id' => 'toggle',
  281. 'title' => __( 'Captions', 'avia_framework' ),
  282. 'content' => $c
  283. )
  284. );
  285.  
  286. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_captions' ), $template );
  287.  
  288. $desc = __( 'Select to show the image copyright info added to the media library.', 'avia_framework' ) . ' ';
  289. $desc .= __( 'Due to layout restrictions &quot;Caption at bottom of image&quot; might hide this info. Please check the frontend.', 'avia_framework' );
  290.  
  291. $c = array(
  292. array(
  293. 'type' => 'template',
  294. 'template_id' => 'image_copyright_toggle',
  295. 'desc' => $desc,
  296. 'lockable' => true
  297. )
  298.  
  299. );
  300.  
  301. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'content_copyright' ), $c );
  302.  
  303.  
  304. /**
  305. * Styling Tab
  306. * ===========
  307. */
  308.  
  309. $c = array(
  310. array(
  311. 'name' => __( 'Size Settings', 'avia_framework' ),
  312. 'desc' => __( 'Here you can select how the masonry should behave and handle the images', 'avia_framework' ),
  313. 'id' => 'size',
  314. 'type' => 'radio',
  315. 'std' => 'flex',
  316. 'lockable' => true,
  317. 'options' => array(
  318. 'flex' => __( 'Flexible Masonry: All images get the same width but are displayed with their original height and width ratio', 'avia_framework' ),
  319. 'fixed' => __( 'Perfect Grid: Display a perfect grid where each image has exactly the same size. Images get cropped/stretched if they don\'t fit', 'avia_framework' ),
  320. 'fixed masonry' => __( 'Perfect Automatic Masonry: Display a grid where most images get the same size, only very wide images get twice the width and very high images get twice the height. To qualify for &quot;very wide&quot; or &quot;very high&quot; the image must have a aspect ratio of 16:9 or higher', 'avia_framework' ),
  321. )
  322. ),
  323.  
  324. array(
  325. 'name' => __( 'Orientation', 'avia_framework' ),
  326. 'desc' => __( 'Set the orientation of the cropped preview images', 'avia_framework' ),
  327. 'id' => 'orientation',
  328. 'type' => 'select',
  329. 'std' => '',
  330. 'lockable' => true,
  331. 'required' => array( 'size', 'equals', 'fixed' ),
  332. 'subtype' => array(
  333. __( 'Wide Landscape', 'avia_framework' ) => 'av-orientation-landscape-large',
  334. __( 'Landscape', 'avia_framework' ) => '',
  335. __( 'Square', 'avia_framework' ) => 'av-orientation-square',
  336. __( 'Portrait', 'avia_framework' ) => 'av-orientation-portrait',
  337. __( 'High Portrait', 'avia_framework' ) => 'av-orientation-portrait-large',
  338. )
  339. ),
  340.  
  341. array(
  342. 'type' => 'template',
  343. 'template_id' => 'image_size_select',
  344. 'std' => 'masonry',
  345. 'lockable' => true,
  346. 'multi' => true
  347. ),
  348.  
  349. array(
  350. 'name' => __( 'Gap between elements', 'avia_framework' ),
  351. 'desc' => __( 'Select the gap between the elements', 'avia_framework' ),
  352. 'id' => 'gap',
  353. 'type' => 'select',
  354. 'std' => 'large',
  355. 'lockable' => true,
  356. 'subtype' => array(
  357. __( 'No Gap', 'avia_framework' ) => 'no',
  358. __( '1 Pixel Gap', 'avia_framework' ) => '1px',
  359. __( 'Large Gap', 'avia_framework' ) => 'large',
  360. )
  361. ),
  362.  
  363.  
  364. );
  365.  
  366. $template = array(
  367. array(
  368. 'type' => 'template',
  369. 'template_id' => 'toggle',
  370. 'title' => __( 'Masonry Settings', 'avia_framework' ),
  371. 'content' => $c
  372. ),
  373. );
  374.  
  375. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_masonry' ), $template );
  376.  
  377. $c = array(
  378.  
  379. array(
  380. 'type' => 'template',
  381. 'template_id' => 'columns_count_icon_switcher',
  382. 'lockable' => true
  383. )
  384. );
  385.  
  386. $template = array(
  387. array(
  388. 'type' => 'template',
  389. 'template_id' => 'toggle',
  390. 'title' => __( 'Columns', 'avia_framework' ),
  391. 'content' => $c
  392. ),
  393. );
  394.  
  395. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_columns' ), $template );
  396.  
  397. $c = array(
  398. array(
  399. 'name' => __( 'Image Number', 'avia_framework' ),
  400. 'desc' => __( 'How many images should be displayed per page?', 'avia_framework' ),
  401. 'id' => 'items',
  402. 'type' => 'select',
  403. 'std' => '24',
  404. 'lockable' => true,
  405. 'subtype' => AviaHtmlHelper::number_array( 1, 100, 1, array( __( 'All', 'avia_framework' ) => '-1' ) )
  406. ),
  407.  
  408. array(
  409. 'name' => __( 'Pagination', 'avia_framework' ),
  410. 'desc' => __( 'Should a pagination or load more option be displayed to view additional images?', 'avia_framework' ),
  411. 'id' => 'paginate',
  412. 'type' => 'select',
  413. 'std' => 'none',
  414. 'lockable' => true,
  415. 'required' => array( 'items', 'not', '-1' ),
  416. 'subtype' => array(
  417. __( 'Display Pagination', 'avia_framework' ) => 'pagination',
  418. __( 'Display "Load More" Button', 'avia_framework' ) => 'load_more',
  419. __( 'No option to view additional images', 'avia_framework' ) => 'none'
  420. )
  421. ),
  422.  
  423. );
  424.  
  425. $template = array(
  426. array(
  427. 'type' => 'template',
  428. 'template_id' => 'toggle',
  429. 'title' => __( 'Pagination', 'avia_framework' ),
  430. 'content' => $c
  431. ),
  432. );
  433.  
  434. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_pagination' ), $template );
  435.  
  436. $c = array(
  437. array(
  438. 'name' => __( 'Custom Colors', 'avia_framework' ),
  439. 'desc' => __( 'Either use the themes default colors or apply some custom ones', 'avia_framework' ),
  440. 'id' => 'color',
  441. 'type' => 'select',
  442. 'std' => '',
  443. 'lockable' => true,
  444. 'subtype' => array(
  445. __( 'Default', 'avia_framework' ) => '',
  446. __( 'Define Custom Colors', 'avia_framework' ) => 'custom'
  447. )
  448. ),
  449.  
  450. array(
  451. 'name' => __( 'Custom Background Color', 'avia_framework' ),
  452. 'desc' => __( 'Select a custom background color. Leave empty to use the default', 'avia_framework' ),
  453. 'id' => 'custom_bg',
  454. 'type' => 'colorpicker',
  455. 'std' => '',
  456. 'rgba' => true,
  457. //'container_class' => 'av_third av_third_first',
  458. 'lockable' => true,
  459. 'required' => array( 'color', 'equals', 'custom' )
  460. )
  461. );
  462.  
  463. $template = array(
  464. array(
  465. 'type' => 'template',
  466. 'template_id' => 'toggle',
  467. 'title' => __( 'Colors', 'avia_framework' ),
  468. 'content' => $c
  469. ),
  470. );
  471.  
  472. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_colors' ), $template );
  473.  
  474.  
  475. $c = array(
  476. array(
  477. 'type' => 'template',
  478. 'template_id' => 'image_copyright_styling_toggle',
  479. 'lockable' => true
  480. )
  481.  
  482. );
  483.  
  484. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'styling_copyright' ), $c );
  485.  
  486. /**
  487. * Animation Tab
  488. * =============
  489. */
  490.  
  491. $c = array(
  492.  
  493. array(
  494. 'type' => 'template',
  495. 'template_id' => 'animation',
  496. 'lockable' => true,
  497. 'std' => 'active',
  498. 'std_none' => '',
  499. 'name' => __( 'Masonry Images Animation', 'avia_framework' ),
  500. 'desc' => __( 'Add a small animation to the masonry items when the user first scrolls to the masonry element. This is only to add some &quot;spice&quot; to the site and only works in modern browsers.', 'avia_framework' ),
  501. 'groups' => array( 'default', 'curtain' ),
  502. 'multicolor' => true
  503. ),
  504.  
  505. array(
  506. 'type' => 'template',
  507. 'template_id' => 'image_hover',
  508. 'id' => 'overlay_fx',
  509. 'std' => 'active',
  510. 'lockable' => true
  511. )
  512.  
  513. );
  514.  
  515. $template = array(
  516. array(
  517. 'type' => 'template',
  518. 'template_id' => 'toggle',
  519. 'title' => __( 'Animation', 'avia_framework' ),
  520. 'content' => $c
  521. ),
  522. );
  523.  
  524. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_animation' ), $template );
  525.  
  526. $c = array(
  527. array(
  528. 'name' => __( 'Image Link', 'avia_framework' ),
  529. 'desc' => __( 'By default images link to a larger image version in a lightbox. You can change this here. A custom link can be added when editing the images in the gallery.', 'avia_framework' ),
  530. 'id' => 'container_links',
  531. 'type' => 'select',
  532. 'std' => 'active',
  533. 'lockable' => true,
  534. 'subtype' => array(
  535. __( 'Lightbox linking active', 'avia_framework' ) => 'active',
  536. __( 'Use custom link (fallback is no link)', 'avia_framework' ) => '',
  537. __( 'Use custom link (fallback is image link)', 'avia_framework' ) => 'custom_image',
  538. __( 'No, don\'t add a link to the images at all', 'avia_framework' ) => 'no_links',
  539. )
  540. ),
  541.  
  542. array(
  543. 'name' => __( 'Custom link destination', 'avia_framework' ),
  544. 'desc' => __( 'Select where an existing custom link should be opened.', 'avia_framework' ),
  545. 'id' => 'link_dest',
  546. 'type' => 'select',
  547. 'std' => '',
  548. 'lockable' => true,
  549. 'required' => array( 'container_links', 'parent_in_array', ',custom_image' ),
  550. 'subtype' => array(
  551. __( 'Open in same window', 'avia_framework' ) => '',
  552. __( 'Open in a new window', 'avia_framework' ) => '_blank'
  553. )
  554. ),
  555.  
  556. array(
  557. 'name' => __( 'Lightbox image description text', 'avia_framework' ),
  558. 'desc' => __( 'Select which text defined in the media gallery is displayed below the lightbox image.', 'avia_framework' ),
  559. 'id' => 'lightbox_text',
  560. 'type' => 'select',
  561. 'std' => '',
  562. 'lockable' => true,
  563. 'required' => array( 'container_links', 'equals', 'active' ),
  564. 'subtype' => array(
  565. __( 'No text', 'avia_framework' ) => 'no_text',
  566. __( 'Image title', 'avia_framework' ) => '',
  567. __ ('Image description (or image title if empty)', 'avia_framework' ) => 'description',
  568. __( 'Image caption (or image title if empty)', 'avia_framework' ) => 'caption'
  569. )
  570. )
  571.  
  572. );
  573.  
  574. $template = array(
  575. array(
  576. 'type' => 'template',
  577. 'template_id' => 'toggle',
  578. 'title' => __( 'Link Settings', 'avia_framework' ),
  579. 'content' => $c
  580. ),
  581. );
  582.  
  583. AviaPopupTemplates()->register_dynamic_template( $this->popup_key( 'advanced_link' ), $template );
  584.  
  585. }
  586.  
  587. /**
  588. * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  589. * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  590. * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  591. *
  592. * @param array $params holds the default values for $content and $args.
  593. * @return array usually holds an innerHtml key that holds item specific markup.
  594. */
  595. public function editor_element( $params )
  596. {
  597. $params = parent::editor_element( $params );
  598. $params['innerHtml'] .= AviaPopupTemplates()->get_html_template( 'alb_element_fullwidth_stretch' );
  599.  
  600. return $params;
  601. }
  602.  
  603. /**
  604. * Editor Sub Element - this function defines the visual appearance of an element that is displayed within a modal window and on click opens its own modal window
  605. * Works in the same way as Editor Element
  606. *
  607. * @param array $params holds the default values for $content and $args.
  608. * @return array usually holds an innerHtml key that holds item specific markup.
  609. */
  610. public function editor_sub_element( $params )
  611. {
  612. /**
  613. * Currently not used because we have no modal_group defined for this element
  614. */
  615.  
  616. // $img_template = $this->update_template( 'img_fakeArg', '{{img_fakeArg}}' );
  617. // $template = $this->update_template( 'title', '{{title}}' );
  618. // $content = $this->update_template( 'content', '{{content}}' );
  619. //
  620. // $thumbnail = isset( $params['args']['id'] ) ? wp_get_attachment_image( $params['args']['id'] ) : '';
  621. //
  622. //
  623. // $params['innerHtml'] = '';
  624. // $params['innerHtml'] .= "<div class='avia_title_container' data-update_element_template='yes'>";
  625. // $params['innerHtml'] .= "<span class='avia_slideshow_image' {$img_template} >{$thumbnail}</span>";
  626. // $params['innerHtml'] .= "<div class='avia_slideshow_content'>";
  627. // $params['innerHtml'] .= "<h4 class='avia_title_container_inner' {$template} >{$params['args']['title']}</h4>";
  628. // $params['innerHtml'] .= "<p class='avia_content_container' {$content}>" . stripslashes( $params['content'] ) . '</p>';
  629. // $params['innerHtml'] .= '</div>';
  630. // $params['innerHtml'] .= '</div>';
  631.  
  632. return $params;
  633. }
  634.  
  635. /**
  636. * Create custom stylings
  637. *
  638. * @since 4.8.4
  639. * @since 4.8.9.1 added $ajax
  640. * @param array $args
  641. * @param boolean $ajax
  642. * @return array
  643. */
  644. protected function get_element_styles( array $args, $ajax = false )
  645. {
  646. $result = parent::get_element_styles( $args );
  647.  
  648. extract( $result );
  649.  
  650. // Backwards comp. - make sure to provide "old" defaults for options not set
  651. $default = avia_masonry::default_args( $this->get_default_sc_args() );
  652.  
  653. $locked = array();
  654.  
  655. // on ajax callback we need to load 1 item more than a locked value would be -> we need to reset later
  656. $items_ajax = $atts['items'];
  657.  
  658. Avia_Element_Templates()->set_locked_attributes( $atts, $this, $shortcodename, $default, $locked, $content );
  659. Avia_Element_Templates()->add_template_class( $meta, $atts, $default );
  660.  
  661. if( $ajax === true )
  662. {
  663. $atts['items'] = $items_ajax;
  664. }
  665.  
  666. $atts = shortcode_atts( $default, $atts, $this->config['shortcode'] );
  667.  
  668. $atts['container_class'] = 'av-masonry-gallery' . trim( " {$atts['container_class']}" );
  669.  
  670. if( ! isset( $this->obj_masonry[ $element_id ] ) )
  671. {
  672. $this->obj_masonry[ $element_id ] = new avia_masonry( $atts, $this );
  673. }
  674.  
  675. $masonry = $this->obj_masonry[ $element_id ];
  676. $masonry->query_entries_by_id( array(), $ajax );
  677.  
  678. $result['default'] = $default;
  679. $result['atts'] = $atts;
  680. $result['content'] = $content;
  681. $result['element_styling'] = $element_styling;
  682. $result['meta'] = $meta;
  683.  
  684. $result = $masonry->get_element_styles( $result, $this );
  685.  
  686. return $result;
  687. }
  688.  
  689. /**
  690. * Returns output for ajax callback "Load More" button.
  691. * Called as callback from class avia_masonry
  692. *
  693. * @since 4.8.5.1
  694. * @param array $atts
  695. * @return string
  696. */
  697. public function ajax_load_more( array $atts )
  698. {
  699. $args = array(
  700. 'atts' => $atts,
  701. 'content' => '',
  702. 'shortcodename' => $this->config['shortcode']
  703. );
  704.  
  705. $ajax = true;
  706. $result = $this->get_element_styles( $args, $ajax );
  707.  
  708. extract( $result );
  709.  
  710. if( 'disabled' == $atts['img_scrset'] )
  711. {
  712. Av_Responsive_Images()->force_disable( 'disabled' );
  713. }
  714.  
  715. $masonry = $this->obj_masonry[ $element_id ];
  716. $output = $masonry->html( true );
  717.  
  718. Av_Responsive_Images()->force_disable( 'reset' );
  719.  
  720. return $output;
  721. }
  722.  
  723. /**
  724. * Frontend Shortcode Handler
  725. *
  726. * @param array $atts array of attributes
  727. * @param string $content text within enclosing form of shortcode element
  728. * @param string $shortcodename the shortcode found, when == callback name
  729. * @return string $output returns the modified html string
  730. */
  731. public function shortcode_handler( $atts, $content = '', $shortcodename = '', $meta = '' )
  732. {
  733. $result = $this->get_element_styles( compact( array( 'atts', 'content', 'shortcodename', 'meta' ) ) );
  734.  
  735. extract( $result );
  736. extract( $atts );
  737.  
  738. if( 'disabled' == $atts['img_scrset'] )
  739. {
  740. Av_Responsive_Images()->force_disable( 'disabled' );
  741. }
  742.  
  743. // Needed to add to surrounding section
  744. $av_display_classes = $element_styling->responsive_classes_string( 'hide_element', $atts );
  745.  
  746. avia_sc_masonry_gallery::$gallery_count ++;
  747. $skipSecond = false;
  748.  
  749. $params['class'] = "main_color {$av_display_classes} {$meta['el_class']}";
  750. $params['open_structure'] = false;
  751. $params['id'] = AviaHelper::save_string( $meta['custom_id_val'] , '-', 'av-sc-masonry-gallery-' . avia_sc_masonry_gallery::$gallery_count );
  752.  
  753. //we dont need a closing structure if the element is the first one or if a previous fullwidth element was displayed before
  754. if( $meta['index'] == 0 )
  755. {
  756. $params['close'] = false;
  757. }
  758.  
  759. if( ! empty( $meta['siblings']['prev']['tag']) && in_array( $meta['siblings']['prev']['tag'], AviaBuilder::$full_el_no_section ) )
  760. {
  761. $params['close'] = false;
  762. }
  763.  
  764. if( $meta['index'] > 0 )
  765. {
  766. $params['class'] .= ' masonry-not-first';
  767. }
  768.  
  769. if( $meta['index'] == 0 && get_post_meta( get_the_ID(), 'header', true ) != 'no' )
  770. {
  771. $params['class'] .= ' masonry-not-first';
  772. }
  773.  
  774. if( $atts['gap'] == 'no' )
  775. {
  776. $params['class'] .= ' avia-no-border-styling';
  777. }
  778.  
  779. $masonry = $this->obj_masonry[ $element_id ];
  780.  
  781. /**
  782. * Remove custom CSS from element if it is top level (otherwise added twice - $meta['el_class'] )
  783. */
  784. if( ShortcodeHelper::is_top_level() )
  785. {
  786. $update = array(
  787. 'custom_class' => '',
  788. 'id' => ''
  789. );
  790.  
  791. $masonry->update_config( $update );
  792. }
  793.  
  794. $masonry_html = $masonry->html();
  795.  
  796. Av_Responsive_Images()->force_disable( 'reset' );
  797.  
  798. if( ! ShortcodeHelper::is_top_level() )
  799. {
  800. return $masonry_html;
  801. }
  802.  
  803. if( ! empty( $atts['color'] ) && ! empty( $atts['custom_bg'] ) )
  804. {
  805. $params['class'] .= ' masonry-no-border';
  806. }
  807.  
  808. $output = '';
  809. $output .= avia_new_section( $params );
  810. $output .= $masonry_html;
  811. $output .= '</div><!-- close section -->'; //close section
  812.  
  813.  
  814. //if the next tag is a section dont create a new section from this shortcode
  815. if( ! empty( $meta['siblings']['next']['tag'] ) && in_array( $meta['siblings']['next']['tag'], AviaBuilder::$full_el ) )
  816. {
  817. $skipSecond = true;
  818. }
  819.  
  820. //if there is no next element dont create a new section.
  821. if( empty( $meta['siblings']['next']['tag'] ) )
  822. {
  823. $skipSecond = true;
  824. }
  825.  
  826. if( empty( $skipSecond ) )
  827. {
  828. $output .= avia_new_section( array( 'close' => false, 'id' => 'after_masonry' ) );
  829. }
  830.  
  831. return $output;
  832. }
  833.  
  834. }
  835. }
Advertisement
Add Comment
Please, Sign In to add comment