assets
1 year ago
class-thwcfd-admin-form-field.php
1 year ago
class-thwcfd-admin-form.php
1 year ago
class-thwcfd-admin-settings-advanced.php
1 year ago
class-thwcfd-admin-settings-general.php
1 year ago
class-thwcfd-admin-settings-pro.php
1 year ago
class-thwcfd-admin-settings-themehigh-plugins.php
1 year ago
class-thwcfd-admin-settings.php
1 year ago
class-thwcfd-admin.php
1 year ago
class-thwcfd-admin-form.php
431 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The admin settings page functionality of the plugin. |
| 4 | * |
| 5 | * @link https://themehigh.com |
| 6 | * |
| 7 | * @package woo-checkout-field-editor-pro |
| 8 | * @subpackage woo-checkout-field-editor-pro/admin |
| 9 | */ |
| 10 | |
| 11 | if(!defined('WPINC')){ die; } |
| 12 | |
| 13 | if(!class_exists('THWCFD_Admin_Form')): |
| 14 | |
| 15 | abstract class THWCFD_Admin_Form { |
| 16 | public $cell_props = array(); |
| 17 | public $cell_props_TA = array(); |
| 18 | public $cell_props_CP = array(); |
| 19 | public $cell_props_CB = array(); |
| 20 | |
| 21 | public function __construct() { |
| 22 | $this->init_constants(); |
| 23 | } |
| 24 | |
| 25 | private function init_constants(){ |
| 26 | $this->cell_props = array( |
| 27 | 'label_cell_props' => 'class="label"', |
| 28 | 'input_cell_props' => 'class="field"', |
| 29 | 'input_width' => '260px', |
| 30 | ); |
| 31 | $this->cell_props_TA = array( |
| 32 | 'label_cell_props' => 'class="label"', |
| 33 | 'input_cell_props' => 'class="field"', |
| 34 | 'input_width' => '260px', |
| 35 | 'rows' => 10, |
| 36 | 'cols' => 29, |
| 37 | ); |
| 38 | $this->cell_props_CP = array( |
| 39 | 'label_cell_props' => 'class="label"', |
| 40 | 'input_cell_props' => 'class="field"', |
| 41 | 'input_width' => '223px', |
| 42 | ); |
| 43 | |
| 44 | $this->cell_props_CB = array( |
| 45 | 'label_props' => 'style="margin-right: 40px;"', |
| 46 | ); |
| 47 | $this->cell_props_CBS = array( |
| 48 | 'label_props' => 'style="margin-right: 15px;"', |
| 49 | ); |
| 50 | $this->cell_props_CBL = array( |
| 51 | 'label_props' => 'style="margin-right: 52px;"', |
| 52 | ); |
| 53 | |
| 54 | $this->field_props = $this->get_field_form_props(); |
| 55 | $this->field_props_display = $this->get_field_form_props_display(); |
| 56 | } |
| 57 | |
| 58 | public function render_form_field_element($field, $args = array(), $render_cell = true){ |
| 59 | |
| 60 | if($field && is_array($field)){ |
| 61 | $defaults = array( |
| 62 | 'label_cell_props' => 'class="label"', |
| 63 | 'input_cell_props' => 'class="field"', |
| 64 | 'label_cell_colspan' => '', |
| 65 | 'input_cell_colspan' => '', |
| 66 | ); |
| 67 | $args = wp_parse_args( $args, $defaults ); |
| 68 | |
| 69 | $ftype = isset($field['type']) ? $field['type'] : 'text'; |
| 70 | $flabel = isset($field['label']) && !empty($field['label']) ? $field['label'] : ''; |
| 71 | $sub_label = isset($field['sub_label']) && !empty($field['sub_label']) ? $field['sub_label'] : ''; |
| 72 | $tooltip = isset($field['hint_text']) && !empty($field['hint_text']) ? $field['hint_text'] : ''; |
| 73 | |
| 74 | $field_html = ''; |
| 75 | |
| 76 | if($ftype == 'text'){ |
| 77 | $field_html = $this->render_form_field_element_inputtext($field, $args); |
| 78 | |
| 79 | }else if($ftype == 'textarea'){ |
| 80 | $field_html = $this->render_form_field_element_textarea($field, $args); |
| 81 | |
| 82 | }else if($ftype == 'select'){ |
| 83 | $field_html = $this->render_form_field_element_select($field, $args); |
| 84 | |
| 85 | }else if($ftype == 'multiselect'){ |
| 86 | $field_html = $this->render_form_field_element_multiselect($field, $args); |
| 87 | |
| 88 | }else if($ftype == 'colorpicker'){ |
| 89 | $field_html = $this->render_form_field_element_colorpicker($field, $args); |
| 90 | |
| 91 | }else if($ftype == 'checkbox'){ |
| 92 | $field_html = $this->render_form_field_element_checkbox($field, $args, $render_cell); |
| 93 | $flabel = ' '; |
| 94 | |
| 95 | }else if($ftype == 'number'){ |
| 96 | $field_html = $this->render_form_field_element_number($field, $args); |
| 97 | } |
| 98 | |
| 99 | if($render_cell){ |
| 100 | $required_html = isset($field['required']) && $field['required'] ? '<abbr class="required" title="required">*</abbr>' : ''; |
| 101 | |
| 102 | $label_cell_props = !empty($args['label_cell_props']) ? $args['label_cell_props'] : ''; |
| 103 | $input_cell_props = !empty($args['input_cell_props']) ? $args['input_cell_props'] : ''; |
| 104 | ?> |
| 105 | <td <?php echo wp_kses($label_cell_props, array('class' => true)) ?> > |
| 106 | <?php echo esc_html($flabel); echo wp_kses($required_html, array('abbr' => array('class' => true, 'title' => true)) ); |
| 107 | if($sub_label){ |
| 108 | ?> |
| 109 | <br/><span class="thpladmin-subtitle"><?php echo esc_html($sub_label); ?></span> |
| 110 | <?php |
| 111 | } |
| 112 | ?> |
| 113 | </td> |
| 114 | <?php $this->render_form_fragment_tooltip($tooltip); ?> |
| 115 | <td <?php echo wp_kses($input_cell_props, array('class' => true)) ?> ><?php echo wp_kses($field_html, THWCFD_Utils::get_allowed_html()); ?></td> |
| 116 | <?php |
| 117 | }else{ |
| 118 | echo wp_kses($field_html, THWCFD_Utils::get_allowed_html()); |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | private function prepare_form_field_props($field, $args = array()){ |
| 124 | $field_props = ''; |
| 125 | |
| 126 | $defaults = array( |
| 127 | 'input_width' => '', |
| 128 | 'input_name_prefix' => 'i_', |
| 129 | 'input_name_suffix' => '', |
| 130 | ); |
| 131 | $args = wp_parse_args( $args, $defaults ); |
| 132 | |
| 133 | $ftype = isset($field['type']) ? $field['type'] : 'text'; |
| 134 | |
| 135 | $input_class = ''; |
| 136 | if($ftype == 'text'){ |
| 137 | $input_class = 'thwcfd-inputtext'; |
| 138 | }else if($ftype == 'number'){ |
| 139 | $input_class = 'thwcfd-inputtext'; |
| 140 | }else if($ftype == 'select'){ |
| 141 | $input_class = 'thwcfd-select'; |
| 142 | }else if($ftype == 'multiselect' || $ftype == 'multiselect_grouped'){ |
| 143 | $input_class = 'thwcfd-select thwcfd-enhanced-multi-select'; |
| 144 | }else if($ftype == 'colorpicker'){ |
| 145 | $input_class = 'thwcfd-color thpladmin-colorpick'; |
| 146 | } |
| 147 | |
| 148 | if($ftype == 'multiselect' || $ftype == 'multiselect_grouped'){ |
| 149 | $args['input_name_suffix'] = $args['input_name_suffix'].'[]'; |
| 150 | } |
| 151 | |
| 152 | $fname = $args['input_name_prefix'].$field['name'].$args['input_name_suffix']; |
| 153 | $fvalue = isset($field['value']) ? esc_html($field['value']) : ''; |
| 154 | |
| 155 | $input_width = $args['input_width'] ? 'width:'.$args['input_width'].';' : ''; |
| 156 | $field_props = 'name="'. $fname .'" style="'. $input_width .'"'; |
| 157 | $field_props .= !empty($input_class) ? ' class="'. $input_class .'"' : ''; |
| 158 | $field_props .= $ftype == 'textarea' ? '' : ' value="'. $fvalue .'"'; |
| 159 | $field_props .= $ftype == 'multiselect_grouped' ? ' data-value="'. $fvalue .'"' : ''; |
| 160 | $field_props .= ( isset($field['placeholder']) && !empty($field['placeholder']) ) ? ' placeholder="'.$field['placeholder'].'"' : ''; |
| 161 | $field_props .= ( isset($field['onchange']) && !empty($field['onchange']) ) ? ' onchange="'.$field['onchange'].'"' : ''; |
| 162 | |
| 163 | if( $ftype == 'number' ){ |
| 164 | $min = isset( $field['min'] ) ? $field['min'] : ''; |
| 165 | $max = isset( $field['max'] ) ? $field['max'] : ''; |
| 166 | $field_props .= ' min="'.$min.'" max="'.$max.'"'; |
| 167 | } |
| 168 | |
| 169 | return $field_props; |
| 170 | } |
| 171 | |
| 172 | private function render_form_field_element_inputtext($field, $atts = array()){ |
| 173 | $field_html = ''; |
| 174 | if($field && is_array($field)){ |
| 175 | $field_props = $this->prepare_form_field_props($field, $atts); |
| 176 | $field_html = '<input type="text" '. wp_kses_post($field_props) .' />'; |
| 177 | } |
| 178 | return $field_html; |
| 179 | } |
| 180 | |
| 181 | private function render_form_field_element_textarea($field, $args = array()){ |
| 182 | $field_html = ''; |
| 183 | if($field && is_array($field)){ |
| 184 | $args = wp_parse_args( $args, array( |
| 185 | 'rows' => '5', |
| 186 | 'cols' => '29', |
| 187 | )); |
| 188 | |
| 189 | $fvalue = isset($field['value']) ? $field['value'] : ''; |
| 190 | $field_props = $this->prepare_form_field_props($field, $args); |
| 191 | $field_html = '<textarea '. wp_kses_post($field_props) .' rows="'.esc_attr($args['rows']).'" cols="'.esc_attr($args['cols']).'" >'.esc_html($fvalue).'</textarea>'; |
| 192 | } |
| 193 | return $field_html; |
| 194 | } |
| 195 | |
| 196 | private function render_form_field_element_select($field, $atts = array()){ |
| 197 | $field_html = ''; |
| 198 | if($field && is_array($field)){ |
| 199 | $fvalue = isset($field['value']) ? $field['value'] : ''; |
| 200 | $field_props = $this->prepare_form_field_props($field, $atts); |
| 201 | |
| 202 | $field_html = '<select '. wp_kses_post($field_props) .' >'; |
| 203 | foreach($field['options'] as $value => $label){ |
| 204 | $selected = $value === $fvalue ? 'selected' : ''; |
| 205 | $field_html .= '<option value="'. esc_attr(trim($value)) .'" '.esc_attr($selected).'>'. esc_html__($label, 'woo-checkout-field-editor-pro') .'</option>'; |
| 206 | } |
| 207 | $field_html .= '</select>'; |
| 208 | } |
| 209 | return $field_html; |
| 210 | } |
| 211 | |
| 212 | private function render_form_field_element_multiselect($field, $atts = array()){ |
| 213 | $field_html = ''; |
| 214 | if($field && is_array($field)){ |
| 215 | $field_props = $this->prepare_form_field_props($field, $atts); |
| 216 | |
| 217 | $field_html = '<select multiple="multiple" '. wp_kses_post($field_props) .'>'; |
| 218 | foreach($field['options'] as $value => $label){ |
| 219 | //$selected = $value === $fvalue ? 'selected' : ''; |
| 220 | $field_html .= '<option value="'. esc_attr(trim($value)) .'" >'. esc_html__($label, 'woo-checkout-field-editor-pro') .'</option>'; |
| 221 | } |
| 222 | $field_html .= '</select>'; |
| 223 | } |
| 224 | return $field_html; |
| 225 | } |
| 226 | |
| 227 | private function render_form_field_element_multiselect_grouped($field, $atts = array()){ |
| 228 | $field_html = ''; |
| 229 | if($field && is_array($field)){ |
| 230 | $field_props = $this->prepare_form_field_props($field, $atts); |
| 231 | |
| 232 | $field_html = '<select multiple="multiple" '. wp_kses_post($field_props) .'>'; |
| 233 | foreach($field['options'] as $group_label => $fields){ |
| 234 | $field_html .= '<optgroup label="'. esc_attr($group_label) .'">'; |
| 235 | |
| 236 | foreach($fields as $value => $label){ |
| 237 | $value = trim($value); |
| 238 | if(isset($field['glue']) && !empty($field['glue'])){ |
| 239 | $value = $value.$field['glue'].trim($label); |
| 240 | } |
| 241 | |
| 242 | $field_html .= '<option value="'. esc_attr($value) .'">'. esc_html__($label, 'woo-checkout-field-editor-pro') .'</option>'; |
| 243 | } |
| 244 | |
| 245 | $field_html .= '</optgroup>'; |
| 246 | } |
| 247 | $field_html .= '</select>'; |
| 248 | } |
| 249 | return $field_html; |
| 250 | } |
| 251 | |
| 252 | private function render_form_field_element_radio($field, $atts = array()){ |
| 253 | $field_html = ''; |
| 254 | /*if($field && is_array($field)){ |
| 255 | $field_props = $this->prepare_form_field_props($field, $atts); |
| 256 | |
| 257 | $field_html = '<select '. $field_props .' >'; |
| 258 | foreach($field['options'] as $value => $label){ |
| 259 | $selected = $value === $fvalue ? 'selected' : ''; |
| 260 | $field_html .= '<option value="'. trim($value) .'" '.$selected.'>'. __($label, 'woo-checkout-field-editor-pro') .'</option>'; |
| 261 | } |
| 262 | $field_html .= '</select>'; |
| 263 | }*/ |
| 264 | return $field_html; |
| 265 | } |
| 266 | |
| 267 | private function render_form_field_element_checkbox($field, $atts = array(), $render_cell = true){ |
| 268 | |
| 269 | $field_html = ''; |
| 270 | if($field && is_array($field)){ |
| 271 | $args = shortcode_atts( array( |
| 272 | 'label_props' => '', |
| 273 | 'cell_props' => '', |
| 274 | 'input_props' => '', |
| 275 | 'id_prefix' => 'a_f', |
| 276 | 'render_input_cell' => false, |
| 277 | ), $atts ); |
| 278 | |
| 279 | $fid = $args['id_prefix']. $field['name']; |
| 280 | $flabel = isset($field['label']) && !empty($field['label']) ? __($field['label'], 'woo-checkout-field-editor-pro') : ''; |
| 281 | |
| 282 | $field_props = $this->prepare_form_field_props($field, $atts); |
| 283 | $field_props .= isset($field['checked']) && $field['checked'] === 1 ? ' checked' : ''; |
| 284 | $field_props .= $args['input_props']; |
| 285 | |
| 286 | $field_html = '<input type="checkbox" id="'. esc_attr($fid).'" '. wp_kses_post($field_props) .' />'; |
| 287 | $field_html .= '<label for="'. esc_attr($fid) .'" '. wp_kses_post($args['label_props']) .' > '. esc_html($flabel) .'</label>'; |
| 288 | } |
| 289 | if(!$render_cell && $args['render_input_cell']){ |
| 290 | return '<td '.wp_kses_post($args['cell_props']) .' >'. wp_kses_post($field_html) .'</td>'; |
| 291 | }else{ |
| 292 | |
| 293 | return wp_kses($field_html, THWCFD_Utils::get_allowed_html()); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | private function render_form_field_element_colorpicker($field, $atts = array()){ |
| 298 | $field_html = ''; |
| 299 | if($field && is_array($field)){ |
| 300 | $field_props = $this->prepare_form_field_props($field, $atts); |
| 301 | |
| 302 | $field_html = '<span class="thpladmin-colorpickpreview '.esc_attr($field['name']).'_preview" style=""></span>'; |
| 303 | $field_html .= '<input type="text" '. wp_kses_post($field_props) .' >'; |
| 304 | } |
| 305 | return $field_html; |
| 306 | } |
| 307 | |
| 308 | private function render_form_field_element_number($field, $atts = array() ){ |
| 309 | $field_html = ''; |
| 310 | if($field && is_array($field)){ |
| 311 | $field_props = $this->prepare_form_field_props($field, $atts); |
| 312 | $field_html = '<input type="number" '. wp_kses_post($field_props) .' />'; |
| 313 | } |
| 314 | return $field_html; |
| 315 | } |
| 316 | |
| 317 | public function render_form_fragment_tooltip($tooltip = false){ |
| 318 | if($tooltip){ |
| 319 | ?> |
| 320 | <td class="tip" style="width: 26px; padding:0px;"> |
| 321 | <a href="javascript:void(0)" title="<?php echo esc_attr($tooltip); ?>" class="thwcfd_tooltip"> |
| 322 | <img src="<?php echo esc_url(THWCFD_ASSETS_URL_ADMIN . '/images/help.png'); ?>" title=""/> |
| 323 | </a> |
| 324 | </td> |
| 325 | <?php |
| 326 | }else{ |
| 327 | ?> |
| 328 | <td style="width: 26px; padding:0px;"></td> |
| 329 | <?php |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | public function render_form_fragment_h_spacing($padding = 5){ |
| 334 | $style = $padding ? 'padding-top:' . esc_attr($padding) . 'px;' : ''; |
| 335 | ?> |
| 336 | <tr><td colspan="3" style="<?php echo esc_attr($style); ?>"></td></tr> |
| 337 | <?php |
| 338 | } |
| 339 | |
| 340 | public function render_form_fragment_h_separator($atts = array()){ |
| 341 | $args = shortcode_atts( array( |
| 342 | 'colspan' => 6, |
| 343 | 'padding-top' => '5px', |
| 344 | 'border-style' => 'dashed', |
| 345 | 'border-width' => '1px', |
| 346 | 'border-color' => '#e6e6e6', |
| 347 | 'content' => '', |
| 348 | ), $atts ); |
| 349 | |
| 350 | $style = $args['padding-top'] ? 'padding-top:'.esc_attr($args['padding-top']).';' : ''; |
| 351 | $style .= $args['border-style'] ? ' border-bottom:'.esc_attr($args['border-width']).' '.esc_attr($args['border-style']).' '.esc_attr($args['border-color']).';' : ''; |
| 352 | |
| 353 | ?> |
| 354 | <tr><td colspan="<?php echo esc_attr($args['colspan']); ?>" style="<?php echo esc_attr($style); ?>"><?php echo esc_attr($args['content']); ?></td></tr> |
| 355 | <?php |
| 356 | } |
| 357 | |
| 358 | public function render_form_field_blank($colspan = 3){ |
| 359 | ?> |
| 360 | <td colspan="<?php echo esc_attr($colspan); ?>"> </td> |
| 361 | <?php |
| 362 | } |
| 363 | |
| 364 | public function render_form_section_separator($props, $atts=array()){ |
| 365 | ?> |
| 366 | <tr valign="top"><td colspan="<?php echo esc_attr($props['colspan']); ?>" style="height:10px;"></td></tr> |
| 367 | <tr valign="top"><td colspan="<?php echo esc_attr($props['colspan']); ?>" class="thpladmin-form-section-title" ><?php echo esc_html($props['title']); ?></td></tr> |
| 368 | <tr valign="top"><td colspan="<?php echo esc_attr($props['colspan']); ?>" style="height:0px;"></td></tr> |
| 369 | <?php |
| 370 | } |
| 371 | |
| 372 | /*----- Tab Title -----*/ |
| 373 | public function render_form_tab_main_title($title){ |
| 374 | ?> |
| 375 | <main-title classname="main-title"> |
| 376 | <button class="device-mobile btn--back Button"> |
| 377 | <i class="button-icon button-icon-before i-arrow-back"></i> |
| 378 | </button> |
| 379 | <span class="device-mobile main-title-icon text-primary"><i class="i-check drishy"></i><?php echo esc_html($title); ?></span> |
| 380 | <span class="device-desktop"><?php echo esc_html($title); ?></span> |
| 381 | </main-title> |
| 382 | <?php |
| 383 | } |
| 384 | |
| 385 | /*----- Form Element Row -----*/ |
| 386 | public function render_form_elm_row($field, $args=array()){ |
| 387 | $row_class = $this->prepare_settings_row_class( $field ); |
| 388 | ?> |
| 389 | <tr class="<?php echo esc_attr( $row_class ); ?>"> |
| 390 | <?php $this->render_form_field_element($field, $this->cell_props); ?> |
| 391 | </tr> |
| 392 | <?php |
| 393 | } |
| 394 | |
| 395 | public function render_form_elm_row_ta($field, $args=array()){ |
| 396 | $row_class = $this->prepare_settings_row_class( $field ); |
| 397 | ?> |
| 398 | <tr class="<?php echo esc_attr( $row_class ); ?>"> |
| 399 | <?php $this->render_form_field_element($field, $this->cell_props_TA); ?> |
| 400 | </tr> |
| 401 | <?php |
| 402 | } |
| 403 | |
| 404 | public function render_form_elm_row_cb($field, $args=array()){ |
| 405 | $row_class = $this->prepare_settings_row_class( $field ); |
| 406 | ?> |
| 407 | <tr class="<?php echo esc_attr( $row_class ); ?>"> |
| 408 | <td colspan="2"></td> |
| 409 | <td class="field"> |
| 410 | <?php $this->render_form_field_element($field, $this->cell_props_CB, false); ?> |
| 411 | </td> |
| 412 | </tr> |
| 413 | <?php |
| 414 | } |
| 415 | |
| 416 | public function render_form_elm_row_cp($field, $args=array()){ |
| 417 | ?> |
| 418 | <tr> |
| 419 | <?php $this->render_form_field_element($field, $this->cell_props_CP); ?> |
| 420 | </tr> |
| 421 | <?php |
| 422 | } |
| 423 | |
| 424 | public function prepare_settings_row_class( $field ){ |
| 425 | $name = isset($field['name']) ? $field['name'] : ''; |
| 426 | return 'form_field_'.$name; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | endif; |
| 431 |