class-evf-builder-fields.php
2 years ago
class-evf-builder-page.php
3 years ago
class-evf-builder-settings.php
2 years ago
class-evf-builder-page.php
164 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Builder Page/Tab |
| 4 | * |
| 5 | * @package EverestForms\Admin |
| 6 | * @since 1.2.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | if ( ! class_exists( 'EVF_Admin_Form_Panel', false ) ) { |
| 12 | include_once dirname( EVF_PLUGIN_FILE ) . '/includes/abstracts/legacy/class-evf-admin-form-panel.php'; |
| 13 | } |
| 14 | |
| 15 | if ( ! class_exists( 'EVF_Builder_Page', false ) ) : |
| 16 | |
| 17 | /** |
| 18 | * EVF_Builder_Page Class. |
| 19 | */ |
| 20 | abstract class EVF_Builder_Page extends EVF_Admin_Form_Panel { |
| 21 | |
| 22 | /** |
| 23 | * Form object. |
| 24 | * |
| 25 | * @var object |
| 26 | */ |
| 27 | public $form; |
| 28 | |
| 29 | /** |
| 30 | * Builder page id. |
| 31 | * |
| 32 | * @var string |
| 33 | */ |
| 34 | protected $id = ''; |
| 35 | |
| 36 | /** |
| 37 | * Builder page label. |
| 38 | * |
| 39 | * @var string |
| 40 | */ |
| 41 | protected $label = ''; |
| 42 | |
| 43 | /** |
| 44 | * Is sidebar available? |
| 45 | * |
| 46 | * @var boolean |
| 47 | */ |
| 48 | protected $sidebar = false; |
| 49 | |
| 50 | /** |
| 51 | * Array of form data. |
| 52 | * |
| 53 | * @var array |
| 54 | */ |
| 55 | public $form_data = array(); |
| 56 | |
| 57 | /** |
| 58 | * Constructor. |
| 59 | */ |
| 60 | public function __construct() { |
| 61 | $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification |
| 62 | $this->form = evf()->form->get( $form_id ); |
| 63 | $this->form_data = is_object( $this->form ) ? evf_decode( $this->form->post_content ) : array(); |
| 64 | |
| 65 | // Init hooks. |
| 66 | $this->init_hooks(); |
| 67 | |
| 68 | // Hooks. |
| 69 | add_filter( 'everest_forms_builder_tabs_array', array( $this, 'add_builder_page' ), 20 ); |
| 70 | add_action( 'everest_forms_builder_sidebar_' . $this->id, array( $this, 'output_sidebar' ) ); |
| 71 | add_action( 'everest_forms_builder_content_' . $this->id, array( $this, 'output_content' ) ); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Get builder page ID. |
| 76 | * |
| 77 | * @return string |
| 78 | */ |
| 79 | public function get_id() { |
| 80 | return $this->id; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Get builder page label. |
| 85 | * |
| 86 | * @return string |
| 87 | */ |
| 88 | public function get_label() { |
| 89 | return $this->label; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Get builder page sidebar. |
| 94 | * |
| 95 | * @return string |
| 96 | */ |
| 97 | public function get_sidebar() { |
| 98 | return $this->sidebar; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Get builder page form data. |
| 103 | * |
| 104 | * @return string |
| 105 | */ |
| 106 | public function get_form_data() { |
| 107 | return $this->form_data; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Add this page to builder. |
| 112 | * |
| 113 | * @param array $pages Builder pages. |
| 114 | * @return mixed |
| 115 | */ |
| 116 | public function add_builder_page( $pages ) { |
| 117 | $pages[ $this->id ] = array( |
| 118 | 'label' => $this->label, |
| 119 | 'sidebar' => $this->sidebar, |
| 120 | ); |
| 121 | |
| 122 | return $pages; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Add sidebar tab sections. |
| 127 | * |
| 128 | * @param string $name Name of the section. |
| 129 | * @param string $slug Slug of the section. |
| 130 | * @param string $icon Icon of the section. |
| 131 | * @param string $container_name Name of that container. |
| 132 | */ |
| 133 | public function add_sidebar_tab( $name, $slug, $icon = '', $container_name = 'setting' ) { |
| 134 | $class = ''; |
| 135 | $class .= 'default' === $slug ? ' default' : ''; |
| 136 | $class .= ! empty( $icon ) ? ' icon' : ''; |
| 137 | |
| 138 | echo '<a href="#" class="evf-panel-tab evf-' . esc_attr( $container_name ) . '-panel everest-forms-panel-sidebar-section everest-forms-panel-sidebar-section-' . esc_attr( $slug ) . esc_attr( $class ) . '" data-section="' . esc_attr( $slug ) . '">'; |
| 139 | if ( ! empty( $icon ) ) { |
| 140 | echo '<figure class="logo"><img src="' . esc_url( $icon ) . '"></figure>'; |
| 141 | } |
| 142 | echo esc_html( $name ); |
| 143 | echo '<i class="dashicons dashicons-arrow-right-alt2 everest-forms-toggle-arrow"></i>'; |
| 144 | echo '</a>'; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Hook in tabs. |
| 149 | */ |
| 150 | public function init_hooks() {} |
| 151 | |
| 152 | /** |
| 153 | * Outputs the builder sidebar. |
| 154 | */ |
| 155 | public function output_sidebar() {} |
| 156 | |
| 157 | /** |
| 158 | * Outputs the builder content. |
| 159 | */ |
| 160 | public function output_content() {} |
| 161 | } |
| 162 | |
| 163 | endif; |
| 164 |