| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | if ( ! defined( 'ABSPATH' ) ) { |
| 16: | exit; |
| 17: | } |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | class EPL_Render_Fields { |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | public $class_prefix = 'epl-form-field-'; |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | public $post; |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | public function __construct() { |
| 48: | |
| 49: | add_action( 'epl_render_field_select', array( $this, 'select' ), 10, 2 ); |
| 50: | add_action( 'epl_render_field_select_multiple', array( $this, 'select' ), 10, 2 ); |
| 51: | add_action( 'epl_render_field_checkbox', array( $this, 'checkbox' ), 10, 2 ); |
| 52: | add_action( 'epl_render_field_checkbox_option', array( $this, 'checkbox_option' ), 10, 2 ); |
| 53: | add_action( 'epl_render_field_checkbox_single', array( $this, 'checkbox_single' ), 10, 2 ); |
| 54: | add_action( 'epl_render_field_radio', array( $this, 'radio' ), 10, 2 ); |
| 55: | add_action( 'epl_render_field_file', array( $this, 'file' ), 10, 2 ); |
| 56: | add_action( 'epl_render_field_image', array( $this, 'file' ), 10, 2 ); |
| 57: | add_action( 'epl_render_field_editor', array( $this, 'editor' ), 10, 2 ); |
| 58: | add_action( 'epl_render_field_textarea', array( $this, 'textarea' ), 10, 2 ); |
| 59: | add_action( 'epl_render_field_textarea_html', array( $this, 'textarea_html' ), 10, 2 ); |
| 60: | add_action( 'epl_render_field_decimal', array( $this, 'render_default' ), 10, 2 ); |
| 61: | add_action( 'epl_render_field_number', array( $this, 'render_default' ), 10, 2 ); |
| 62: | add_action( 'epl_render_field_date', array( $this, 'render_default' ), 10, 2 ); |
| 63: | add_action( 'epl_render_field_auction-date', array( $this, 'render_default' ), 10, 2 ); |
| 64: | add_action( 'epl_render_field_sold-date', array( $this, 'render_default' ), 10, 2 ); |
| 65: | add_action( 'epl_render_field_email', array( $this, 'render_default' ), 10, 2 ); |
| 66: | add_action( 'epl_render_field_url', array( $this, 'render_default' ), 10, 2 ); |
| 67: | add_action( 'epl_render_field_button', array( $this, 'render_default' ), 10, 2 ); |
| 68: | add_action( 'epl_render_field_color', array( $this, 'render_default' ), 10, 2 ); |
| 69: | add_action( 'epl_render_field_text', array( $this, 'render_default' ), 10, 2 ); |
| 70: | add_action( 'epl_render_field_hidden', array( $this, 'render_default' ), 10, 2 ); |
| 71: | add_action( 'epl_render_field_submit', array( $this, 'render_default' ), 10, 2 ); |
| 72: | add_action( 'epl_render_field_password', array( $this, 'render_default' ), 10, 2 ); |
| 73: | add_action( 'epl_render_field_locked', array( $this, 'locked' ), 10, 2 ); |
| 74: | add_action( 'epl_render_field_help', array( $this, 'help' ), 10, 2 ); |
| 75: | add_action( 'epl_render_field_html', array( $this, 'html' ), 10, 2 ); |
| 76: | } |
| 77: | |
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | public function process_field_params( $field, $val ) { |
| 87: | |
| 88: | $field = apply_filters( 'pre_process_field_params', $field ); |
| 89: | |
| 90: | if ( 'date' === $field['type'] ) { |
| 91: | $field['data-format'] = isset( $field['format'] ) ? $field['format'] : 'Y-m-d'; |
| 92: | $field['data-timepicker'] = isset( $field['timepicker'] ) ? $field['timepicker'] : false; |
| 93: | } |
| 94: | |
| 95: | $field['id'] = $this->get_id( $field ); |
| 96: | $field['name'] = $this->get_name( $field ); |
| 97: | $field['class'] = $this->get_class( $field ); |
| 98: | $field['data'] = $this->get_data_attributes( $field ); |
| 99: | $field['min'] = $this->get_min( $field ); |
| 100: | $field['max'] = $this->get_max( $field ); |
| 101: | $field['maxlength'] = $this->get_maxlength( $field ); |
| 102: | $field['placeholder'] = $this->get_placeholder( $field ); |
| 103: | $field['autocomplete'] = $this->get_autocomplete( $field ); |
| 104: | $field['multiple'] = $this->is_multiple( $field ); |
| 105: | $field['required'] = $this->is_required( $field ); |
| 106: | $field['value'] = 'button' === $field['type'] ? $field['value'] : $val; |
| 107: | return apply_filters( 'post_process_field_params', $field ); |
| 108: | } |
| 109: | |
| 110: | |
| 111: | |
| 112: | |
| 113: | |
| 114: | |
| 115: | |
| 116: | |
| 117: | public function get_min( $field ) { |
| 118: | return isset( $field['min'] ) ? $field['min'] : ''; |
| 119: | } |
| 120: | |
| 121: | |
| 122: | |
| 123: | |
| 124: | |
| 125: | |
| 126: | |
| 127: | |
| 128: | public function is_multiple( $field ) { |
| 129: | return 'select_multiple' === $field['type'] ? ' multiple ' : ''; |
| 130: | } |
| 131: | |
| 132: | |
| 133: | |
| 134: | |
| 135: | |
| 136: | |
| 137: | |
| 138: | |
| 139: | public function get_max( $field ) { |
| 140: | return isset( $field['max'] ) ? $field['max'] : ''; |
| 141: | } |
| 142: | |
| 143: | |
| 144: | |
| 145: | |
| 146: | |
| 147: | |
| 148: | |
| 149: | |
| 150: | public function get_maxlength( $field ) { |
| 151: | return isset( $field['maxlength'] ) ? (int) $field['maxlength'] : ''; |
| 152: | } |
| 153: | |
| 154: | |
| 155: | |
| 156: | |
| 157: | |
| 158: | |
| 159: | |
| 160: | |
| 161: | public function get_placeholder( $field ) { |
| 162: | return isset( $field['placeholder'] ) ? $field['placeholder'] : ''; |
| 163: | } |
| 164: | |
| 165: | |
| 166: | |
| 167: | |
| 168: | |
| 169: | |
| 170: | |
| 171: | |
| 172: | public function get_autocomplete( $field ) { |
| 173: | return isset( $field['autocomplete'] ) ? $field['autocomplete'] : ''; |
| 174: | } |
| 175: | |
| 176: | |
| 177: | |
| 178: | |
| 179: | |
| 180: | |
| 181: | |
| 182: | |
| 183: | public function is_required( $field ) { |
| 184: | return ! empty( $field['required'] ) ? ' required ' : ''; |
| 185: | } |
| 186: | |
| 187: | |
| 188: | |
| 189: | |
| 190: | |
| 191: | |
| 192: | |
| 193: | |
| 194: | public function get_id( $field ) { |
| 195: | $id = isset( $field['id'] ) ? $field['id'] : ''; |
| 196: | |
| 197: | if ( empty( $id ) ) { |
| 198: | $id = isset( $field['name'] ) ? $field['name'] : ''; |
| 199: | } |
| 200: | |
| 201: | return $id; |
| 202: | } |
| 203: | |
| 204: | |
| 205: | |
| 206: | |
| 207: | |
| 208: | |
| 209: | |
| 210: | |
| 211: | public function get_name( $field ) { |
| 212: | return isset( $field['name'] ) ? $field['name'] : ''; |
| 213: | } |
| 214: | |
| 215: | |
| 216: | |
| 217: | |
| 218: | |
| 219: | |
| 220: | |
| 221: | |
| 222: | public function get_decimal_validation_class( $field = array() ) { |
| 223: | return apply_filters( 'epl_form_field_decimal_validation_class', 'validate[custom[onlyNumberWithDecimal]]', $field ); |
| 224: | } |
| 225: | |
| 226: | |
| 227: | |
| 228: | |
| 229: | |
| 230: | |
| 231: | |
| 232: | |
| 233: | public function get_number_validation_class( $field = array() ) { |
| 234: | return apply_filters( 'epl_form_field_number_validation_class', 'validate[custom[onlyNumber]]', $field ); |
| 235: | } |
| 236: | |
| 237: | |
| 238: | |
| 239: | |
| 240: | |
| 241: | |
| 242: | |
| 243: | |
| 244: | public function get_email_validation_class( $field = array() ) { |
| 245: | return apply_filters( 'epl_form_field_number_validation_class', 'validate[custom[email]]', $field ); |
| 246: | } |
| 247: | |
| 248: | |
| 249: | |
| 250: | |
| 251: | |
| 252: | |
| 253: | |
| 254: | |
| 255: | public function get_url_validation_class( $field = array() ) { |
| 256: | return apply_filters( 'epl_form_field_number_validation_class', 'validate[custom[url]]', $field ); |
| 257: | } |
| 258: | |
| 259: | |
| 260: | |
| 261: | |
| 262: | |
| 263: | |
| 264: | |
| 265: | |
| 266: | public function get_class( $field ) { |
| 267: | |
| 268: | $classes = isset( $field['class'] ) ? $field['class'] : ''; |
| 269: | |
| 270: | if ( ! is_array( $classes ) ) { |
| 271: | $classes = explode( ' ', $classes ); |
| 272: | } |
| 273: | $classes = implode( ' ', array_map( 'sanitize_html_class', $classes ) ); |
| 274: | |
| 275: | |
| 276: | if ( 'decimal' === $field['type'] ) { |
| 277: | $classes .= ' ' . $this->get_decimal_validation_class( $field ); |
| 278: | } elseif ( 'number' === $field['type'] ) { |
| 279: | $classes .= ' ' . $this->get_number_validation_class( $field ); |
| 280: | } elseif ( 'email' === $field['type'] ) { |
| 281: | $classes .= ' ' . $this->get_email_validation_class( $field ); |
| 282: | } elseif ( 'url' === $field['type'] ) { |
| 283: | $classes .= ' ' . $this->get_url_validation_class( $field ); |
| 284: | } elseif ( 'date' === $field['type'] ) { |
| 285: | $classes .= ' epldatepicker '; |
| 286: | } |
| 287: | |
| 288: | |
| 289: | $classes .= ' ' . $this->class_prefix . sanitize_text_field( $field['type'] ); |
| 290: | return $classes; |
| 291: | } |
| 292: | |
| 293: | |
| 294: | |
| 295: | |
| 296: | |
| 297: | |
| 298: | |
| 299: | |
| 300: | public function get_data_attributes( $field ) { |
| 301: | |
| 302: | $atts_html = ''; |
| 303: | if ( ! empty( $field['data'] ) ) { |
| 304: | foreach ( $field['data'] as $data_key => $data_value ) { |
| 305: | |
| 306: | if ( ! epl_starts_with( $data_key, 'data-' ) ) { |
| 307: | $data_key = 'data-' . $data_key; |
| 308: | } |
| 309: | |
| 310: | if ( ! is_array( $data_value ) && ! is_object( $data_value ) ) { |
| 311: | $atts_html .= $data_key . "='" . $data_value . "'"; |
| 312: | } else { |
| 313: | $atts_html .= $data_key . "='" . wp_json_encode( $data_value ) . "'"; |
| 314: | } |
| 315: | } |
| 316: | } |
| 317: | |
| 318: | foreach ( $field as $key => $value ) { |
| 319: | |
| 320: | if ( epl_starts_with( $key, 'data-' ) ) { |
| 321: | if ( ! is_array( $value ) && ! is_object( $value ) ) { |
| 322: | $atts_html .= $key . "='" . $value . "'"; |
| 323: | } else { |
| 324: | $atts_html .= $key . "='" . wp_json_encode( $value ) . "'"; |
| 325: | } |
| 326: | } |
| 327: | } |
| 328: | |
| 329: | return $atts_html; |
| 330: | } |
| 331: | |
| 332: | |
| 333: | |
| 334: | |
| 335: | |
| 336: | |
| 337: | |
| 338: | |
| 339: | public function is_name_array( $field ) { |
| 340: | |
| 341: | $name_arrays = apply_filters( 'epl_form_field_name_arrays', array( 'select_multiple', 'checkbox' ) ); |
| 342: | return in_array( $field['type'], $name_arrays, true ) ? true : false; |
| 343: | } |
| 344: | |
| 345: | |
| 346: | |
| 347: | |
| 348: | |
| 349: | |
| 350: | |
| 351: | |
| 352: | |
| 353: | |
| 354: | |
| 355: | |
| 356: | |
| 357: | |
| 358: | public function get_opening_field_tag( $tag = 'input', $field = array(), $self_close = false ) { |
| 359: | |
| 360: | $tag = sanitize_key( $tag ); |
| 361: | |
| 362: | $html = '<' . $tag . ' '; |
| 363: | |
| 364: | if ( ! empty( $field['type'] ) && ! in_array( $field['type'], array( 'select', 'select_multiple', 'textarea', 'help' ), true ) ) { |
| 365: | $html .= ' type ="' . esc_attr( $field['type'] ) . '" '; |
| 366: | $html .= ' value ="' . esc_attr( stripslashes( $field['value'] ) ) . '" '; |
| 367: | } |
| 368: | |
| 369: | if ( ! empty( $field['multiple'] ) ) { |
| 370: | $html .= esc_attr( $field['multiple'] ); |
| 371: | } |
| 372: | |
| 373: | if ( ! empty( $field['min'] ) ) { |
| 374: | $html .= ' min ="' . esc_attr( $field['min'] ) . '" '; |
| 375: | } |
| 376: | |
| 377: | if ( ! empty( $field['max'] ) ) { |
| 378: | $html .= ' max ="' . esc_attr( $field['max'] ) . '" '; |
| 379: | } |
| 380: | |
| 381: | if ( ! empty( $field['maxlength'] ) ) { |
| 382: | $html .= ' maxlength ="' . esc_attr( $field['maxlength'] ) . '" '; |
| 383: | } |
| 384: | |
| 385: | if ( ! empty( $field['class'] ) ) { |
| 386: | $html .= ' class ="' . esc_attr( $field['class'] ) . '" '; |
| 387: | } |
| 388: | |
| 389: | if ( ! empty( $field['name'] ) ) { |
| 390: | $name = esc_attr( $field['name'] ); |
| 391: | if ( $this->is_name_array( $field ) ) { |
| 392: | $name .= '[]'; |
| 393: | } |
| 394: | $html .= ' name ="' . $name . '" '; |
| 395: | } |
| 396: | |
| 397: | if ( ! empty( $field['id'] ) ) { |
| 398: | $html .= ' id ="' . esc_attr( $field['id'] ) . '" '; |
| 399: | } |
| 400: | |
| 401: | if ( ! empty( $field['placeholder'] ) ) { |
| 402: | $html .= ' placeholder ="' . esc_attr( $field['placeholder'] ) . '" '; |
| 403: | } |
| 404: | |
| 405: | if ( ! empty( $field['autocomplete'] ) ) { |
| 406: | $html .= ' autocomplete ="' . esc_attr( $field['autocomplete'] ) . '" '; |
| 407: | } |
| 408: | |
| 409: | if ( ! empty( $field['data'] ) ) { |
| 410: | $html .= ' ' . wp_kses_post( $field['data'] ); |
| 411: | } |
| 412: | |
| 413: | $html .= $self_close ? '/>' : '>'; |
| 414: | |
| 415: | return $html; |
| 416: | } |
| 417: | |
| 418: | |
| 419: | |
| 420: | |
| 421: | |
| 422: | |
| 423: | |
| 424: | public function render( $field = array(), $val = '' ) { |
| 425: | |
| 426: | global $post; |
| 427: | |
| 428: | if ( ! is_null( $post ) ) { |
| 429: | $this->post = $post; |
| 430: | } |
| 431: | |
| 432: | $type = sanitize_text_field( $field['type'] ); |
| 433: | $field = $this->process_field_params( $field, $val ); |
| 434: | do_action( 'epl_render_field_' . $type, $field, $val ); |
| 435: | |
| 436: | if ( isset( $field['geocoder'] ) ) { |
| 437: | if ( 'true' == $field['geocoder'] ) { |
| 438: | echo '<span class="epl-geocoder-button"></span>'; |
| 439: | } |
| 440: | |
| 441: | do_action( 'epl_admin_listing_map', esc_attr( stripslashes( $val ) ) ); |
| 442: | } |
| 443: | |
| 444: | if ( isset( $field['help'] ) ) { |
| 445: | $field['help'] = trim( $field['help'] ); |
| 446: | if ( ! empty( $field['help'] ) ) { |
| 447: | echo '<span class="epl-help-text">' . wp_kses_post( $field['help'] ) . '</span>'; |
| 448: | } |
| 449: | } |
| 450: | } |
| 451: | |
| 452: | |
| 453: | |
| 454: | |
| 455: | |
| 456: | |
| 457: | |
| 458: | public function select( $field, $val ) { |
| 459: | |
| 460: | if ( $this->is_multiple( $field ) ) { |
| 461: | $val = (array) $val; |
| 462: | } |
| 463: | |
| 464: | echo $this->get_opening_field_tag( 'select', $field ); |
| 465: | |
| 466: | if ( isset( $field['opts'] ) && ! empty( $field['opts'] ) ) { |
| 467: | |
| 468: | foreach ( $field['opts'] as $k => $v ) { |
| 469: | $selected = ''; |
| 470: | |
| 471: | if ( $this->is_multiple( $field ) ) { |
| 472: | if ( in_array( $k, $val ) ) { |
| 473: | $selected = 'selected'; |
| 474: | } |
| 475: | } else { |
| 476: | if ( $val == $k ) { |
| 477: | $selected = 'selected'; |
| 478: | } |
| 479: | } |
| 480: | |
| 481: | if ( is_array( $v ) ) { |
| 482: | if ( isset( $v['exclude'] ) && ! empty( $v['exclude'] ) ) { |
| 483: | if ( ! is_null( $this->post ) && in_array( $this->post->post_type, $v['exclude'], true ) ) { |
| 484: | continue; |
| 485: | } |
| 486: | } |
| 487: | |
| 488: | if ( isset( $v['include'] ) && ! empty( $v['include'] ) ) { |
| 489: | if ( ! is_null( $this->post ) && ! in_array( $this->post->post_type, $v['include'], true ) ) { |
| 490: | continue; |
| 491: | } |
| 492: | } |
| 493: | $v = $v['label']; |
| 494: | } |
| 495: | |
| 496: | echo '<option value="' . esc_attr( $k ) . '" ' . esc_attr( $selected ) . '>' . esc_html( $v ) . '</option>'; |
| 497: | } |
| 498: | } else { |
| 499: | echo '<option value=""> </option>'; |
| 500: | } |
| 501: | echo '</select>'; |
| 502: | } |
| 503: | |
| 504: | |
| 505: | |
| 506: | |
| 507: | |
| 508: | |
| 509: | |
| 510: | public function checkbox( $field, $val ) { |
| 511: | |
| 512: | if ( ! empty( $field['opts'] ) ) { |
| 513: | foreach ( $field['opts'] as $k => $v ) { |
| 514: | $checked = ''; |
| 515: | |
| 516: | if ( ! empty( $val ) ) { |
| 517: | |
| 518: | $val = (array) $val; |
| 519: | if ( in_array( $k, $val ) ) { |
| 520: | $checked = 'checked'; |
| 521: | } |
| 522: | } |
| 523: | echo '<span class="epl-field-row"> |
| 524: | <input type="checkbox" name="' . esc_attr( $field['name'] ) . '[]" |
| 525: | ' . wp_kses_post( $field['data'] ) . ' |
| 526: | class="' . esc_attr( $field['class'] ) . '" |
| 527: | id="' . esc_attr( $field['id'] ) . '_' . esc_attr( $k ) . '" |
| 528: | value="' . esc_attr( $k ) . '" ' . esc_attr( $checked ) . ' /> |
| 529: | <label for="' . esc_html( $field['id'] ) . '_' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label> |
| 530: | </span>'; |
| 531: | } |
| 532: | } |
| 533: | } |
| 534: | |
| 535: | |
| 536: | |
| 537: | |
| 538: | |
| 539: | |
| 540: | |
| 541: | |
| 542: | |
| 543: | public function checkbox_single( $field, $val ) { |
| 544: | |
| 545: | if ( ! empty( $field['opts'] ) ) { |
| 546: | foreach ( $field['opts'] as $k => $v ) { |
| 547: | $checked = ''; |
| 548: | if ( ! empty( $val ) ) { |
| 549: | $checkbox_single_options = apply_filters( 'epl_checkbox_single_check_options', array( 1, 'yes', 'on', 'true', '1' ) ); |
| 550: | if ( $k == $val || in_array( $val, $checkbox_single_options, true ) ) { |
| 551: | $checked = 'checked'; |
| 552: | } |
| 553: | } |
| 554: | if ( 1 === count( $field['opts'] ) ) { |
| 555: | $v = $field['label']; |
| 556: | } |
| 557: | echo '<span class="epl-field-row"> |
| 558: | <input type="hidden" name="' . esc_attr( $field['name'] ) . '" value="" /> |
| 559: | <input type="checkbox" name="' . esc_attr( $field['name'] ) . '" class="' . esc_attr( $field['class'] ) . '" ' . wp_kses_post( $field['data'] ) . ' id="' . esc_attr( $field['id'] ) . '_' . esc_attr( $k ) . '" value="' . esc_attr( $k ) . '" ' . esc_attr( $checked ) . ' /> <label for="' . esc_html( $field['id'] ) . '_' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label></span>'; |
| 560: | } |
| 561: | } |
| 562: | } |
| 563: | |
| 564: | |
| 565: | |
| 566: | |
| 567: | |
| 568: | |
| 569: | |
| 570: | |
| 571: | |
| 572: | public function checkbox_option( $field, $val ) { |
| 573: | |
| 574: | if ( ! empty( $field['opts'] ) ) { |
| 575: | foreach ( $field['opts'] as $k => $v ) { |
| 576: | $checked = ''; |
| 577: | if ( ! empty( $val ) ) { |
| 578: | if ( $k == $val ) { |
| 579: | $checked = 'checked'; |
| 580: | } |
| 581: | } |
| 582: | echo '<span class="epl-field-row"> |
| 583: | <input type="hidden" name="' . esc_attr( $field['name'] ) . '" value="" /> |
| 584: | <input type="checkbox" name="' . esc_attr( $field['name'] ) . '" ' . wp_kses_post( $field['data'] ) . ' id="' . esc_attr( $field['id'] ) . '_' . esc_attr( $k ) . '" class="' . esc_attr( $field['class'] ) . '" value="' . esc_attr( $k ) . '" ' . esc_attr( $checked ) . ' /> <label for="' . esc_html( $field['id'] ) . '_' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label></span>'; |
| 585: | } |
| 586: | } |
| 587: | } |
| 588: | |
| 589: | |
| 590: | |
| 591: | |
| 592: | |
| 593: | |
| 594: | |
| 595: | public function radio( $field, $val ) { |
| 596: | |
| 597: | if ( ! empty( $field['opts'] ) ) { |
| 598: | foreach ( $field['opts'] as $k => $v ) { |
| 599: | $checked = ''; |
| 600: | if ( $val == $k ) { |
| 601: | $checked = 'checked'; |
| 602: | } |
| 603: | echo '<span class="epl-field-row"><input type="radio" name="' . esc_attr( $field['name'] ) . '" ' . wp_kses_post( $field['data'] ) . ' class="' . esc_attr( $field['class'] ) . '" id="' . esc_attr( $field['id'] ) . '_' . esc_attr( $k ) . '" value="' . esc_attr( $k ) . '" ' . esc_attr( $checked ) . ' /> <label for="' . esc_html( $field['id'] ) . '_' . esc_attr( $k ) . '">' . esc_html( $v ) . '</label></span>'; |
| 604: | } |
| 605: | } |
| 606: | } |
| 607: | |
| 608: | |
| 609: | |
| 610: | |
| 611: | |
| 612: | |
| 613: | |
| 614: | public function file( $field, $val ) { |
| 615: | if ( is_array( $val ) ) { |
| 616: | $val = isset( $val['image_url_or_path'] ) ? $val['image_url_or_path'] : ''; |
| 617: | } |
| 618: | |
| 619: | if ( ! empty( $val ) ) { |
| 620: | $img = esc_attr( stripslashes( $val ) ); |
| 621: | } else { |
| 622: | $img = plugin_dir_url( __DIR__ ) . 'assets/images/no_image.png'; |
| 623: | } |
| 624: | |
| 625: | echo ' |
| 626: | <div class="epl-media-row"> |
| 627: | <input type="text" ' . wp_kses_post( $field['data'] ) . ' class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( stripslashes( $val ) ) . '" /> |
| 628: | <input type="button" name="epl_upload_button" class="button" value="' . esc_html__( 'Add File', 'easy-property-listings' ) . '" />'; |
| 629: | |
| 630: | if ( in_array( pathinfo( $img, PATHINFO_EXTENSION ), array( 'jpg', 'jpeg', 'png', 'gif' ), true ) ) { |
| 631: | echo ' <img src="' . esc_url( $img ) . '" alt="" />'; |
| 632: | } |
| 633: | echo '<div class="epl-clear"></div> |
| 634: | </div> |
| 635: | '; |
| 636: | } |
| 637: | |
| 638: | |
| 639: | |
| 640: | |
| 641: | |
| 642: | |
| 643: | |
| 644: | public function editor( $field, $val ) { |
| 645: | wp_editor( |
| 646: | stripslashes( $val ), |
| 647: | esc_attr( $field['id'] ), |
| 648: | $settings = array( |
| 649: | 'textarea_rows' => 5, |
| 650: | 'editor_class' => $field['class'], |
| 651: | ) |
| 652: | ); |
| 653: | } |
| 654: | |
| 655: | |
| 656: | |
| 657: | |
| 658: | |
| 659: | |
| 660: | |
| 661: | public function textarea( $field, $val ) { |
| 662: | echo $this->get_opening_field_tag( 'textarea', $field ); |
| 663: | echo wp_kses_post( stripslashes( $val ) ); |
| 664: | echo '</textarea>'; |
| 665: | } |
| 666: | |
| 667: | |
| 668: | |
| 669: | |
| 670: | |
| 671: | |
| 672: | |
| 673: | |
| 674: | |
| 675: | public function textarea_html( $field, $val ) { |
| 676: | echo $this->get_opening_field_tag( 'textarea', $field ); |
| 677: | echo esc_textarea( $val ); |
| 678: | echo '</textarea>'; |
| 679: | } |
| 680: | |
| 681: | |
| 682: | |
| 683: | |
| 684: | |
| 685: | |
| 686: | |
| 687: | public function locked( $field, $val ) { |
| 688: | echo '<span>' . esc_attr( stripslashes( $field['value'] ) ) . '</span>'; |
| 689: | } |
| 690: | |
| 691: | |
| 692: | |
| 693: | |
| 694: | |
| 695: | |
| 696: | |
| 697: | |
| 698: | |
| 699: | public function help( $field, $val ) { |
| 700: | |
| 701: | $content = isset( $field['content'] ) ? $field['content'] : ''; |
| 702: | $help_id = isset( $field['name'] ) ? sanitize_key( $field['name'] ) : ''; |
| 703: | echo '<div class="epl-help-container">'; |
| 704: | echo $this->get_opening_field_tag( 'div', $field ); |
| 705: | echo wp_kses_post( $content ); |
| 706: | echo '</div></div>'; |
| 707: | } |
| 708: | |
| 709: | |
| 710: | |
| 711: | |
| 712: | |
| 713: | |
| 714: | |
| 715: | |
| 716: | |
| 717: | public function html( $field, $val ) { |
| 718: | |
| 719: | $content = isset( $field['content'] ) ? $field['content'] : ''; |
| 720: | $help_id = isset( $field['name'] ) ? sanitize_key( $field['name'] ) : ''; |
| 721: | |
| 722: | echo '<div class="epl-html-container" id="' . esc_attr( $help_id ) . '"> |
| 723: | ' . wp_kses_post( $content ) . ' |
| 724: | </div>'; |
| 725: | } |
| 726: | |
| 727: | |
| 728: | |
| 729: | |
| 730: | |
| 731: | |
| 732: | |
| 733: | |
| 734: | public function render_default( $field, $val ) { |
| 735: | |
| 736: | if ( ! in_array( $field['type'], array( 'button', 'number', 'color', 'submit' ), true ) ) { |
| 737: | $field['type'] = 'text'; |
| 738: | } |
| 739: | echo $this->get_opening_field_tag( 'input', $field, true ); |
| 740: | } |
| 741: | } |
| 742: | |