class-evf-admin-form-panel.php
191 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Abstract form panel |
| 4 | * |
| 5 | * @package EverestForms\Abstracts |
| 6 | * @deprecated 1.2.0 |
| 7 | * @since 1.0.0 |
| 8 | */ |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | /** |
| 13 | * Abstract EVF_Admin_Form_Panel Class |
| 14 | * |
| 15 | * @deprecated 1.2.0 |
| 16 | */ |
| 17 | abstract class EVF_Admin_Form_Panel { |
| 18 | |
| 19 | /** |
| 20 | * Full name of the panel. |
| 21 | * |
| 22 | * @var string |
| 23 | */ |
| 24 | public $name; |
| 25 | |
| 26 | /** |
| 27 | * Slug. |
| 28 | * |
| 29 | * @var string |
| 30 | */ |
| 31 | public $slug; |
| 32 | |
| 33 | /** |
| 34 | * Font Awesome Icon used for the editor button. |
| 35 | * |
| 36 | * @var mixed |
| 37 | */ |
| 38 | protected $icon = false; |
| 39 | |
| 40 | /** |
| 41 | * Priority order the field button should show inside the "Add Fields" tab. |
| 42 | * |
| 43 | * @var integer |
| 44 | */ |
| 45 | public $order = 50; |
| 46 | |
| 47 | /** |
| 48 | * If panel contains a sidebar element or is full width. |
| 49 | * |
| 50 | * @var boolean |
| 51 | */ |
| 52 | protected $sidebar = false; |
| 53 | |
| 54 | /** |
| 55 | * Contains form object if we have one. |
| 56 | * |
| 57 | * @var object |
| 58 | */ |
| 59 | protected $form; |
| 60 | |
| 61 | /** |
| 62 | * Contains array of the form data (post_content). |
| 63 | * |
| 64 | * @var array |
| 65 | */ |
| 66 | protected $form_data; |
| 67 | |
| 68 | /** |
| 69 | * Form Settings. |
| 70 | * |
| 71 | * @var array |
| 72 | */ |
| 73 | public $form_setting; |
| 74 | |
| 75 | /** |
| 76 | * Class constructor. |
| 77 | */ |
| 78 | public function __construct() { |
| 79 | // Load form if found. |
| 80 | $form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0; |
| 81 | $this->form = evf()->form->get( $form_id ); |
| 82 | $this->form_data = is_object( $this->form ) ? evf_decode( $this->form->post_content ) : array(); |
| 83 | $this->form_setting = isset( $this->form_data['settings'] ) ? $this->form_data['settings'] : array(); |
| 84 | $this->init(); |
| 85 | |
| 86 | // Hooks. |
| 87 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueues' ), 15 ); |
| 88 | add_action( 'everest_forms_builder_tabs', array( $this, 'button' ), $this->order ); |
| 89 | add_action( 'everest_forms_builder_output', array( $this, 'panel_output' ), $this->order ); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Hook in tabs. |
| 94 | */ |
| 95 | public function init() {} |
| 96 | |
| 97 | /** |
| 98 | * Enqueue assets |
| 99 | */ |
| 100 | public function enqueues() {} |
| 101 | |
| 102 | /** |
| 103 | * Primary panel button in the left panel navigation. |
| 104 | */ |
| 105 | public function button() { |
| 106 | global $current_tab; |
| 107 | |
| 108 | $active = $current_tab === $this->slug ? 'nav-tab-active' : ''; |
| 109 | |
| 110 | printf( '<a href="#" class="evf-panel-%1$s-button nav-tab %2$s" data-panel="%1$s">', $this->slug, $active ); |
| 111 | printf( '<span class="%s"></span>', $this->icon ); |
| 112 | printf( '%s</a>', $this->name ); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Outputs the contents of the panel. |
| 117 | * |
| 118 | * @param object $form |
| 119 | * @param string $view |
| 120 | */ |
| 121 | public function panel_output() { |
| 122 | global $current_tab; |
| 123 | |
| 124 | $active = $current_tab == $this->slug ? 'active' : ''; |
| 125 | |
| 126 | $wrap = $this->sidebar ? 'everest-forms-panel-sidebar-content' : 'everest-forms-panel-full-content'; |
| 127 | |
| 128 | printf( '<div id="everest-forms-panel-%s" class="everest-forms-panel %s">', $this->slug, $active ); |
| 129 | |
| 130 | printf( '<div class="%s">', $wrap ); |
| 131 | |
| 132 | if ( true == $this->sidebar ) { |
| 133 | |
| 134 | echo '<div class="everest-forms-panel-sidebar">'; |
| 135 | |
| 136 | do_action( 'everest_forms_builder_before_panel_sidebar', $this->form, $this->slug ); |
| 137 | |
| 138 | $this->panel_sidebar(); |
| 139 | |
| 140 | do_action( 'everest_forms_builder_after_panel_sidebar', $this->form, $this->slug ); |
| 141 | |
| 142 | echo '</div>'; |
| 143 | } |
| 144 | |
| 145 | echo '<div class="everest-forms-panel-content-wrap">'; |
| 146 | echo '<div class="everest-forms-panel-content">'; |
| 147 | |
| 148 | do_action( 'everest_forms_builder_before_panel_content', $this->form, $this->slug ); |
| 149 | |
| 150 | $this->panel_content(); |
| 151 | |
| 152 | do_action( 'everest_forms_builder_after_panel_content', $this->form, $this->slug ); |
| 153 | |
| 154 | echo '</div></div></div></div>'; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Outputs the panel's sidebar if we have one. |
| 159 | */ |
| 160 | public function panel_sidebar() {} |
| 161 | |
| 162 | /** |
| 163 | * Outputs panel sidebar sections. |
| 164 | */ |
| 165 | public function panel_sidebar_section( $name, $slug, $icon = '' ) { |
| 166 | |
| 167 | $class = ''; |
| 168 | $class .= $slug == 'default' ? ' default' : ''; |
| 169 | $class .= ! empty( $icon ) ? ' icon' : ''; |
| 170 | |
| 171 | echo '<a href="#" class="evf-panel-tab evf-setting-panel everest-forms-panel-sidebar-section everest-forms-panel-sidebar-section-' . esc_attr( $slug ) . $class . '" data-section="' . esc_attr( $slug ) . '">'; |
| 172 | |
| 173 | if ( ! empty( $icon ) ) { |
| 174 | echo '<img src="' . esc_url( $icon ) . '">'; |
| 175 | } |
| 176 | |
| 177 | echo esc_html( $name ); |
| 178 | |
| 179 | echo '<i class="dashicons dashicons-arrow-right-alt2 everest-forms-toggle-arrow"></i>'; |
| 180 | |
| 181 | echo '</a>'; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Outputs the panel's primary content. |
| 186 | * |
| 187 | * @since 1.0.0 |
| 188 | */ |
| 189 | public function panel_content() {} |
| 190 | } |
| 191 |