Guest User

Untitled

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