| 1 |
<?php |
| 2 |
if ( ! class_exists( 'GFForms' ) ) { |
| 3 |
die(); |
| 4 |
} |
| 5 |
GFForms::include_addon_framework(); |
| 6 |
class Superaddons_Grepeater_Field_Addon extends GFAddOn{ |
| 7 |
protected $_version = "1.0"; |
| 8 |
protected $_min_gravityforms_version = '1.9'; |
| 9 |
protected $_slug = 'repeater-for-gravity-forms'; |
| 10 |
protected $_path = 'repeater-for-gravity-forms/repeater-for-gravity-forms.php'; |
| 11 |
protected $_full_path = __FILE__; |
| 12 |
protected $_title = 'Gravity Forms Repeater Fields Add-On'; |
| 13 |
protected $_short_title = 'Gravity Repeater'; |
| 14 |
private static $_instance = null; |
| 15 |
public static function get_instance() { |
| 16 |
if ( self::$_instance == null ) { |
| 17 |
self::$_instance = new self(); |
| 18 |
} |
| 19 |
return self::$_instance; |
| 20 |
} |
| 21 |
public function init_admin() { |
| 22 |
parent::init_admin(); |
| 23 |
} |
| 24 |
public function init_frontend() { |
| 25 |
parent::init_frontend(); |
| 26 |
// add tasks or filters here that you want to perform only in the front end |
| 27 |
} |
| 28 |
function type( $position, $form_id ) { |
| 29 |
if ( $position == 1550 ) { |
| 30 |
?> |
| 31 |
<li class="field_field_repeater_title_setting field_setting"> |
| 32 |
<label class="section_label"> |
| 33 |
<?php esc_html_e('Title', 'repeater-for-gravity-forms'); ?> |
| 34 |
</label> |
| 35 |
<input type="text" id="repeater_title" placeholder="Person" value="" onchange="SetFieldProperty('repeater_title', this.value);"> |
| 36 |
<?php esc_html_e("An optional title before each row of the repeater",'repeater-for-gravity-forms') ?> |
| 37 |
</li> |
| 38 |
<?php do_action( "yeeaddons_gf_repeater_settings") ?> |
| 39 |
<li class="field_field_repeater_end_text_setting field_setting"> |
| 40 |
<label class="section_label"> |
| 41 |
<?php esc_html_e('Text button', 'repeater-for-gravity-forms'); ?> |
| 42 |
</label> |
| 43 |
<input type="text" id="field_repeater_end_text" placeholder="Add more" value="" onchange="SetFieldProperty('field_repeater_end_text', this.value);"> |
| 44 |
<?php esc_html_e("add button text",'repeater-for-gravity-forms') ?> |
| 45 |
</li> |
| 46 |
<?php |
| 47 |
} |
| 48 |
} |
| 49 |
function editor_script(){ |
| 50 |
?> |
| 51 |
<script type='text/javascript'> |
| 52 |
( function( $ ) { |
| 53 |
"use strict"; |
| 54 |
jQuery(document).ready(function($) { |
| 55 |
jQuery(document).on('gform_load_field_settings', function(event, field, form){ |
| 56 |
jQuery('#repeater_title').val( field.repeater_title); |
| 57 |
jQuery('#repeater_initial_rows').val( field.repeater_initial_rows); |
| 58 |
jQuery('#repeater_max').val( field.repeater_max); |
| 59 |
jQuery('#repeater_initial_rows_map').val( field.repeater_initial_rows_map); |
| 60 |
jQuery('#field_repeater_end_text').val( field.field_repeater_end_text); |
| 61 |
}); |
| 62 |
}); |
| 63 |
} )( jQuery ); |
| 64 |
</script> |
| 65 |
<?php |
| 66 |
} |
| 67 |
public function pre_init() { |
| 68 |
parent::pre_init(); |
| 69 |
add_filter( "gform_input_mask_script",array($this,"gform_input_mask_script"),10,4 ); |
| 70 |
add_action( 'gform_field_standard_settings', array($this,'type'), 10, 2 ); |
| 71 |
add_action( 'gform_editor_js', array($this,'editor_script') ); |
| 72 |
include SUPERADDONS_GF_REPEATER_PLUGIN_PATH."fields/repeater_field.php"; |
| 73 |
include SUPERADDONS_GF_REPEATER_PLUGIN_PATH."fields/repeater_start_field.php"; |
| 74 |
add_filter( 'gform_pre_validation', array( "Superaddons_GFRepeater_Field", 'remove_validation' ) ); |
| 75 |
add_filter( 'gform_admin_pre_render', array( 'Superaddons_GFRepeater_Field', 'remove_child_fields' ) ); |
| 76 |
add_filter( 'gform_form_post_get_meta', array( 'Superaddons_GFRepeater_Field', 'remove_child_fields' ) ); |
| 77 |
add_action( 'gform_enqueue_scripts', array($this,"add_data"),10,2 ); |
| 78 |
} |
| 79 |
function gform_input_mask_script($script_str,$form_id,$field_id,$mask){ |
| 80 |
$input_mask = get_option( "yeeaddons_gf_input_mask",array()); |
| 81 |
$input_mask["input_".$form_id."_".$field_id] = esc_js( $mask ); |
| 82 |
update_option( "yeeaddons_gf_input_mask",$input_mask ); |
| 83 |
return $script_str; |
| 84 |
} |
| 85 |
function add_data($form, $is_ajax ){ |
| 86 |
$input_mask = get_option( "yeeaddons_gf_input_mask",array()); |
| 87 |
if ( isset( $form['fields'] ) && is_array( $form['fields'] ) ) { |
| 88 |
foreach ( $form['fields'] as $field ) { |
| 89 |
// 1. Các trường Text / Field thường tick "Input Mask" |
| 90 |
if ( ! empty( $field->inputMask ) && ! empty( $field->inputMaskValue ) ) { |
| 91 |
$input_mask["input_" . $form['id'] . "_" . $field->id] = (string) $field->inputMaskValue; |
| 92 |
} |
| 93 |
// 2. Các trường Phone |
| 94 |
if ( isset( $field->type ) && $field->type === 'phone' ) { |
| 95 |
$phone_format = method_exists( $field, 'get_phone_format' ) ? $field->get_phone_format() : array(); |
| 96 |
$mask = isset( $phone_format['mask'] ) ? $phone_format['mask'] : ''; |
| 97 |
if ( empty( $mask ) && ( ! isset( $field->phoneFormat ) || $field->phoneFormat === 'standard' || empty( $field->phoneFormat ) ) ) { |
| 98 |
$mask = '(999) 999-9999'; |
| 99 |
} |
| 100 |
if ( ! empty( $mask ) ) { |
| 101 |
$input_mask["input_" . $form['id'] . "_" . $field->id] = (string) $mask; |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
if ( ! wp_script_is( 'gform_masked_input', 'registered' ) ) { |
| 107 |
wp_register_script( 'gform_masked_input', SUPERADDONS_GF_REPEATER_PLUGIN_URL . 'libs/jquery.maskedinput.min.js', array( 'jquery' ), '1.3.1', true ); |
| 108 |
} |
| 109 |
wp_enqueue_script( 'gf_repeater', SUPERADDONS_GF_REPEATER_PLUGIN_URL . "libs/wp_repeater.js", array( 'jquery', 'gform_masked_input' ), time() ); |
| 110 |
$check_pro = get_option( '_redmuber_item_1540' ); |
| 111 |
wp_localize_script( "gf_repeater", "yeeaddons_gf_repeater_data", array( "input_mask" => ( $input_mask ), "pro" => $check_pro ) ); |
| 112 |
} |
| 113 |
public function styles() { |
| 114 |
$styles = array( |
| 115 |
array( |
| 116 |
'handle' => 'repeater_icon', |
| 117 |
'src' => SUPERADDONS_GF_REPEATER_PLUGIN_URL."libs/css/repeatericons.css", |
| 118 |
'version' => time(), |
| 119 |
'enqueue' => array( |
| 120 |
array( 'field_types' => array( 'repeater_end' ) ) |
| 121 |
) |
| 122 |
), |
| 123 |
array( |
| 124 |
'handle' => 'gf_repeater', |
| 125 |
'src' => SUPERADDONS_GF_REPEATER_PLUGIN_URL."libs/wp_repeater.css", |
| 126 |
'version' => time(), |
| 127 |
'enqueue' => array( |
| 128 |
array( 'field_types' => array( 'repeater_end' ) ) |
| 129 |
) |
| 130 |
), |
| 131 |
); |
| 132 |
return array_merge( parent::styles(), $styles ); |
| 133 |
} |
| 134 |
} |