/template-admin.php

https://gitlab.com/presscodes/maera-page-builder-text-section · PHP · 174 lines · 104 code · 23 blank · 47 comment · 6 complexity · b953bfa37490406752bbff4b1852b522 MD5 · raw file

  1. <?php
  2. Maera_PB()->sections->load_header();
  3. global $maera_pb_section_data, $maera_pb_is_js_template;
  4. $section_id = ( isset( $maera_pb_section_data['data']['id'] ) ) ? $maera_pb_section_data['data']['id'] : '{{{ id }}}';
  5. $section_name = Maera_PB()->sections->get_section_name( $maera_pb_section_data, $maera_pb_is_js_template );
  6. $columns_number = ( isset( $maera_pb_section_data['data']['columns-number'] ) ) ? $maera_pb_section_data['data']['columns-number'] : 3;
  7. $section_order = ( ! empty( $maera_pb_section_data['data']['columns-order'] ) ) ? $maera_pb_section_data['data']['columns-order'] : range(1, 4);
  8. $columns_class = ( in_array( $columns_number, range( 1, 4 ) ) && true !== $maera_pb_is_js_template ) ? $columns_number : 3;
  9. do_action( 'maera_section_text_before_columns_select', $maera_pb_section_data );
  10. do_action( 'maera_section_text_after_columns_select', $maera_pb_section_data );
  11. do_action( 'maera_section_text_after_title', $maera_pb_section_data ); ?>
  12. <div class="maera_pb-text-columns-stage maera_pb-text-columns-<?php echo $columns_class; ?>">
  13. <?php $j = 1; foreach ( $section_order as $key => $i ) : ?>
  14. <?php
  15. $column_name = $section_name . '[columns][' . $i . ']';
  16. $iframe_id = 'maera_pb-iframe-' . $section_id . '-' . $i;
  17. $textarea_id = 'maera_pb-content-' . $section_id . '-' . $i;
  18. $overlay_id = 'maera_pb-overlay-' . $section_id . '-' . $i;
  19. $link = ( isset( $maera_pb_section_data['data']['columns'][ $i ]['image-link'] ) ) ? $maera_pb_section_data['data']['columns'][ $i ]['image-link'] : '';
  20. $image_id = ( isset( $maera_pb_section_data['data']['columns'][ $i ]['image-id'] ) ) ? $maera_pb_section_data['data']['columns'][ $i ]['image-id'] : 0;
  21. $title = ( isset( $maera_pb_section_data['data']['columns'][ $i ]['title'] ) ) ? $maera_pb_section_data['data']['columns'][ $i ]['title'] : '';
  22. $content = ( isset( $maera_pb_section_data['data']['columns'][ $i ]['content'] ) ) ? $maera_pb_section_data['data']['columns'][ $i ]['content'] : '';
  23. $item_has_content = ( ! empty( $content ) ) ? ' item-has-content' : '';
  24. $column_buttons = array(
  25. 100 => array(
  26. 'label' => __( 'Configure column', 'maera' ),
  27. 'href' => '#',
  28. 'class' => 'configure-column-link maera_pb-overlay-open',
  29. 'title' => __( 'Configure column', 'maera' ),
  30. 'other-a-attributes' => ' data-overlay="#' . $overlay_id .'"',
  31. ),
  32. 200 => array(
  33. 'label' => __( 'Edit text column', 'maera' ),
  34. 'href' => '#',
  35. 'class' => 'edit-content-link edit-text-column-link' . $item_has_content,
  36. 'title' => __( 'Edit content', 'maera' ),
  37. 'other-a-attributes' => 'data-textarea="' . esc_attr( $textarea_id ) . '" data-iframe="' . esc_attr( $iframe_id ) . '"',
  38. ),
  39. );
  40. /**
  41. * Filter the buttons added to a text column.
  42. *
  43. * @since 1.4.0.
  44. *
  45. * @param array $column_buttons The current list of buttons.
  46. * @param array $maera_pb_section_data All data for the section.
  47. */
  48. $column_buttons = apply_filters( 'maera_column_buttons', $column_buttons, $maera_pb_section_data );
  49. ksort( $column_buttons );
  50. /**
  51. * Filter the classes applied to each column in a Columns section.
  52. *
  53. * @since 1.2.0.
  54. *
  55. * @param string $column_classes The classes for the column.
  56. * @param int $i The column number.
  57. * @param array $maera_pb_section_data The array of data for the section.
  58. */
  59. $column_classes = apply_filters( 'maera_pb-text-column-classes', 'maera_pb-text-column maera_pb-text-column-position-' . $j, $i, $maera_pb_section_data );
  60. ?>
  61. <div class="<?php echo esc_attr( $column_classes ); ?>" data-id="<?php echo $i; ?>">
  62. <div title="<?php esc_attr_e( 'Drag-and-drop this column into place', 'maera' ); ?>" class="maera_pb-sortable-handle">
  63. <div class="sortable-background column-sortable-background"></div>
  64. </div>
  65. <?php
  66. /**
  67. * Execute code before an individual text column is displayed.
  68. *
  69. * @since 1.2.3.
  70. *
  71. * @param array $maera_pb_section_data The data for the section.
  72. */
  73. do_action( 'maera_section_text_before_column', $maera_pb_section_data, $i );
  74. ?>
  75. <?php foreach ( $column_buttons as $button ) : ?>
  76. <a href="<?php echo esc_url( $button['href'] ); ?>" class="column-buttons <?php echo esc_attr( $button['class'] ); ?>" title="<?php echo esc_attr( $button['title'] ); ?>" <?php if ( ! empty( $button['other-a-attributes'] ) ) echo $button['other-a-attributes']; ?>>
  77. <span>
  78. <?php echo esc_html( $button['label'] ); ?>
  79. </span>
  80. </a>
  81. <?php endforeach; ?>
  82. <?php echo maera_pb_get_builder_base()->add_uploader( $column_name, maera_pb_sanitize_image_id( $image_id ), __( 'Set image', 'maera' ) ); ?>
  83. <?php maera_pb_get_builder_base()->add_frame( $section_id . '-' . $i, $column_name . '[content]', $content ); ?>
  84. <?php
  85. /**
  86. * Execute code after an individual text column is displayed.
  87. *
  88. * @since 1.2.3.
  89. *
  90. * @param array $maera_pb_section_data The data for the section.
  91. */
  92. do_action( 'maera_section_text_after_column', $maera_pb_section_data, $i );
  93. ?>
  94. <?php
  95. global $maera_pb_overlay_class, $maera_pb_overlay_id, $maera_pb_overlay_title;
  96. $maera_pb_overlay_class = 'maera_pb-configuration-overlay';
  97. $maera_pb_overlay_id = $overlay_id;
  98. $maera_pb_overlay_title = __( 'Configure column', 'maera' );
  99. Maera_PB::get_template_part( '/includes/builder/core/templates/overlay', 'header' );
  100. /**
  101. * Filter the definitions of the Columns section's column configuration inputs.
  102. *
  103. * @since 1.4.0.
  104. *
  105. * @param array $inputs The input definition array.
  106. */
  107. $inputs = apply_filters( 'maera_column_configuration', array(
  108. 100 => array(
  109. 'type' => 'section_title',
  110. 'name' => 'title',
  111. 'label' => __( 'Enter column title', 'maera' ),
  112. 'default' => '',
  113. 'class' => 'maera_pb-configuration-title',
  114. ),
  115. 200 => array(
  116. 'type' => 'text',
  117. 'name' => 'image-link',
  118. 'label' => __( 'Image link URL', 'maera' ),
  119. 'default' => '',
  120. ),
  121. ) );
  122. // Sort the config in case 3rd party code added another input
  123. ksort( $inputs, SORT_NUMERIC );
  124. // Print the inputs
  125. $output = '';
  126. foreach ( $inputs as $input ) {
  127. if ( isset( $input['type'] ) && isset( $input['name'] ) ) {
  128. $section_data = ( isset( $maera_pb_section_data['data']['columns'][ $i ] ) ) ? $maera_pb_section_data['data']['columns'][ $i ] : array();
  129. $output .= Maera_PB_Config::create_input( $column_name, $input, $section_data );
  130. }
  131. }
  132. echo $output;
  133. Maera_PB::get_template_part( '/includes/builder/core/templates/overlay', 'footer' );
  134. ?>
  135. </div>
  136. <?php $j++; endforeach; ?>
  137. </div>
  138. <?php
  139. /**
  140. * Execute code after all columns are displayed.
  141. *
  142. * @since 1.2.3.
  143. *
  144. * @param array $maera_pb_section_data The data for the section.
  145. */
  146. do_action( 'maera_section_text_after_columns', $maera_pb_section_data );
  147. ?>
  148. <div class="clear"></div>
  149. <input type="hidden" value="<?php echo esc_attr( implode( ',', $section_order ) ); ?>" name="<?php echo $section_name; ?>[columns-order]" class="maera_pb-text-columns-order" />
  150. <input type="hidden" class="maera_pb-section-state" name="<?php echo $section_name; ?>[state]" value="<?php if ( isset( $maera_pb_section_data['data']['state'] ) ) echo esc_attr( $maera_pb_section_data['data']['state'] ); else echo 'open'; ?>" />
  151. <?php Maera_PB()->sections->load_footer();