D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
everqlsh
/
www
/
wp-admin
/
user
/
577040
/
Filename :
fields.zip
back
Copy
PK u~\����8 �8 multivalue.phpnu �[��� <?php /** * The Forminator_MultiValue class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_MultiValue * * @since 1.0 */ class Forminator_MultiValue extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'checkbox'; /** * Type * * @var string */ public $type = 'checkbox'; /** * Position * * @var int */ public $position = 10; /** * Options * * @var array */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon-element-checkbox'; /** * Is calculable * * @var bool */ public $is_calculable = true; /** * Forminator_MultiValue constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Checkbox', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'value_type' => 'checkbox', 'field_label' => esc_html__( 'Checkbox', 'forminator' ), 'layout' => 'vertical', 'options' => array( array( 'label' => esc_html__( 'Option 1', 'forminator' ), 'value' => 'one', 'key' => forminator_unique_key(), ), array( 'label' => esc_html__( 'Option 2', 'forminator' ), 'value' => 'two', 'key' => forminator_unique_key(), ), ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $providers = apply_filters( 'forminator_field_' . $this->slug . '_autofill', array(), $this->slug ); $autofill_settings = array( 'checkbox' => array( 'values' => forminator_build_autofill_providers( $providers ), ), ); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $i = 1; $html = ''; $id = self::get_property( 'element_id', $field ); $name = $id; $id = 'forminator-field-' . $id; $uniq_id = Forminator_CForm_Front::$uid; $post_value = self::get_post_data( $name, self::FIELD_PROPERTY_VALUE_NOT_EXIST ); $name = $name . '[]'; $required = self::get_property( 'required', $field, false ); $options = self::get_options( $field ); $value_type = trim( isset( $field['value_type'] ) ? $field['value_type'] : 'multiselect' ); $description = self::get_property( 'description', $field, '' ); $label = esc_html( self::get_property( 'field_label', $field, '' ) ); $design = $this->get_form_style( $settings ); $descr_id = $id . '-' . $uniq_id; $calc_enabled = self::get_property( 'calculations', $field, false, 'bool' ); $images_enabled = self::get_property( 'enable_images', $field, false ); $images_enabled = filter_var( $images_enabled, FILTER_VALIDATE_BOOLEAN ); $input_visibility = self::get_property( 'input_visibility', $field, 'true' ); $input_visibility = filter_var( $input_visibility, FILTER_VALIDATE_BOOLEAN ); $draft_value = isset( $draft_value['value'] ) && ! empty( $draft_value['value'] ) ? array_map( 'trim', $draft_value['value'] ) : ''; $hidden_behavior = self::get_property( 'hidden_behavior', $field ); $descr_position = self::get_description_position( $field, $settings ); $draft_valid = false; $prefil_valid = false; $default_arr = array(); $html .= sprintf( '<div role="group" class="%s" aria-labelledby="%s">', esc_attr( $required ? 'forminator-field required' : 'forminator-field' ), esc_attr( 'forminator-checkbox-group-' . $id . '-' . $uniq_id . '-label' ) ); if ( $label ) { $label .= $required ? ' ' . forminator_get_required_icon() : ''; $html .= sprintf( '<span id="%s" class="forminator-label">%s</span>', 'forminator-checkbox-group-' . $id . '-' . $uniq_id . '-label', $label ); } if ( 'above' === $descr_position ) { $html .= self::get_description( $description, $descr_id, $descr_position ); } $hidden_calc_behavior = ''; if ( $hidden_behavior && 'zero' === $hidden_behavior ) { $hidden_calc_behavior = ' data-hidden-behavior="' . $hidden_behavior . '"'; } foreach ( $options as $option ) { $pref_value = $option['value'] ? esc_html( $option['value'] ) : esc_html( $option['label'] ); if ( ! empty( $draft_value ) ) { if ( in_array( trim( $pref_value ), $draft_value ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict $draft_valid = true; $default_arr[] = $pref_value; } } if ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $prefill = $this->get_prefill( $field, false ); $prefill_values = explode( ',', $prefill ); $prefill_values = array_map( 'trim', $prefill_values ); if ( in_array( $pref_value, $prefill_values ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict $prefil_valid = true; $default_arr[] = $pref_value; } } } foreach ( $options as $option ) { $value = '' !== $option['value'] ? $option['value'] : $option['label']; $input_id = $id . '-' . $i . '-' . $uniq_id; $option_default = isset( $option['default'] ) ? filter_var( $option['default'], FILTER_VALIDATE_BOOLEAN ) : false; $calculation_value = $calc_enabled && isset( $option['calculation'] ) ? $option['calculation'] : 0.0; $option_image_url = array_key_exists( 'image', $option ) ? $option['image'] : ''; $option_label = '<span class="forminator-checkbox-label">' . wp_kses_post( $option['label'] ) . '</span>'; $aria_label = '<span class="forminator-screen-reader-only">' . wp_kses_post( $option['label'] ) . '</span>'; $class = 'forminator-checkbox'; if ( $images_enabled && ! empty( $option_image_url ) ) { $class .= ' forminator-has_image'; if ( $input_visibility ) { $class .= ' forminator-has_box'; } } if ( 'horizontal' === self::get_property( 'layout', $field, '' ) ) { $class .= ' forminator-checkbox-inline'; } $selected = false; if ( self::FIELD_PROPERTY_VALUE_NOT_EXIST !== $post_value ) { if ( is_array( $post_value ) ) { $selected = in_array( $value, $post_value );// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict } } elseif ( $draft_valid ) { if ( in_array( strval( $value ), array_map( 'strval', $default_arr ), true ) ) { $selected = true; } } elseif ( $prefil_valid ) { if ( in_array( strval( $value ), array_map( 'strval', $default_arr ), true ) ) { $selected = true; } } else { $selected = $option_default; } $selected = $selected ? 'checked="checked"' : ''; $label_id = $input_id . '-label'; $html .= sprintf( '<label id="%s" for="%s" class="%s" title="%s">', esc_attr( $label_id ), esc_attr( $input_id ), esc_attr( $class ), esc_attr( $option['label'] ) ); $html .= sprintf( '<input type="checkbox" name="%s" value="%s" id="%s" aria-labelledby="%s" data-calculation="%s" %s %s%s/>', $name, esc_html( $value ), $input_id, $label_id, $calculation_value, $selected, $hidden_calc_behavior, ( ! empty( $description ) ? ' aria-describedby="' . esc_attr( $id . '-' . $uniq_id . '-description' ) . '"' : '' ) ); if ( $input_visibility && ( $images_enabled && ! empty( $option_image_url ) ) ) { // Bullet + Label. $html .= '<span class="forminator-checkbox-box" aria-hidden="true"></span>'; $html .= $option_label; // Image. if ( 'none' === $design ) { $html .= '<img class="forminator-checkbox-image" src="' . esc_url( $option_image_url ) . '" aria-hidden="true" />'; } else { $html .= '<span class="forminator-checkbox-image" aria-hidden="true">'; $html .= '<span style="background-image: url(' . esc_url( $option_image_url ) . ');"></span>'; $html .= '</span>'; } } elseif ( ! $input_visibility && ( $images_enabled && ! empty( $option_image_url ) ) ) { // Image. if ( 'none' === $design ) { $html .= '<img class="forminator-checkbox-image" src="' . esc_url( $option_image_url ) . '" aria-hidden="true" />'; } else { $html .= '<span class="forminator-checkbox-image" aria-hidden="true">'; $html .= '<span style="background-image: url(' . esc_url( $option_image_url ) . ');"></span>'; $html .= '</span>'; } // Aria Label. $html .= $aria_label; } else { // Bullet + Label. $html .= '<span class="forminator-checkbox-box" aria-hidden="true"></span>'; $html .= $option_label; } $html .= '</label>'; ++$i; } if ( 'above' !== $descr_position ) { $html .= self::get_description( $description, $descr_id, $descr_position ); } $html .= '</div>'; return apply_filters( 'forminator_field_multiple_markup', $html, $id, $required, $options, $value_type ); } /** * Return field inline validation rules * * @since 1.0 * @return string */ public function get_validation_rules() { $rules = ''; $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); if ( $is_required ) { $rules .= '"' . $this->get_id( $field ) . '[]": "required",'; } return apply_filters( 'forminator_field_multiple_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @return string */ public function get_validation_messages() { $messages = ''; $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); if ( $is_required ) { $required_message = self::get_property( 'required_message', $field ); if ( empty( $required_message ) ) { $required_message = __( 'This field is required. Please select a value.', 'forminator' ); } $required_message = apply_filters( 'forminator_multi_field_required_validation_message', $required_message, $id, $field ); $messages .= '"' . $this->get_id( $field ) . '[]": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } return $messages; } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); foreach ( $data as $value ) { if ( false === array_search( strval( htmlspecialchars_decode( $value ) ), array_map( 'strval', array_column( $field['options'], 'value' ) ), true ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_checkbox_field_nonexistent_validation_message', esc_html__( 'Selected value does not exist.', 'forminator' ), $id, $field ); break; } } if ( $this->is_required( $field ) ) { $required_message = self::get_property( 'required_message', $field, esc_html__( 'This field is required. Please select a value', 'forminator' ) ); if ( empty( $data ) ) { $slug = ! empty( $field['original_id'] ) ? $field['original_id'] : $id; $this->validation_message[ $slug ] = apply_filters( 'forminator_multi_field_required_validation_message', $required_message, $id, $field ); } } } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. if ( is_array( $data ) ) { foreach ( $data as $key => $val ) { $data[ $key ] = trim( wp_kses_post( $val ) ); } } else { $data = trim( wp_kses_post( $data ) ); } return apply_filters( 'forminator_field_multi_sanitize', $data, $field, $original_data ); } /** * Internal calculable value * * @since 1.7 * * @param array $submitted_field Submitted field. * @param array $field_settings Field settings. * * @return float|string */ private static function calculable_value( $submitted_field, $field_settings ) { $enabled = self::get_property( 'calculations', $field_settings, false, 'bool' ); if ( ! $enabled ) { return self::FIELD_NOT_CALCULABLE; } $sums = 0.0; $options = self::get_property( 'options', $field_settings, array() ); if ( ! is_array( $submitted_field ) ) { return $sums; } foreach ( $options as $option ) { $option_value = ( isset( $option['value'] ) && ! empty( $option['value'] ) ) ? $option['value'] : ( isset( $option['label'] ) ? $option['label'] : '' ); $calculation_value = isset( $option['calculation'] ) ? $option['calculation'] : 0.0; forminator_maybe_log( __METHOD__, $option_value, $submitted_field ); // strict array compare disabled to allow non-coercion type compare. if ( in_array( $option_value, $submitted_field ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict // this one is selected. $sums += floatval( $calculation_value ); } } return floatval( $sums ); } /** * Get calculable value * * @since 1.7 * @inheritdoc * * @param array $submitted_field_data Submitted field data. * @param array $field_settings Field settings. */ public static function get_calculable_value( $submitted_field_data, $field_settings ) { $calculable_value = self::calculable_value( $submitted_field_data, $field_settings ); /** * Filter formula being used on calculable value on multi-value / checkbox field * * @since 1.7 * * @param float $calculable_value * @param array $submitted_field_data * @param array $field_settings * * @return string|int|float */ $calculable_value = apply_filters( 'forminator_field_multi_calculable_value', $calculable_value, $submitted_field_data, $field_settings ); return $calculable_value; } } PK v~\���or or time.phpnu �[��� <?php /** * The Forminator_Time class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Time * * @property array field * @since 1.0 */ class Forminator_Time extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'time'; /** * Type * * @var string */ public $type = 'time'; /** * Position * * @var int */ public $position = 13; /** * Options * * @var array */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon-clock'; /** * Forminator_Time constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Timepicker', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'field_type' => 'input', 'time_type' => 'twelve', 'field_label' => esc_html__( 'Time', 'forminator' ), 'hh_label' => esc_html__( 'Hours', 'forminator' ), 'hh_placeholder' => esc_html__( 'E.g. 08', 'forminator' ), 'mm_label' => esc_html__( 'Minutes', 'forminator' ), 'mm_placeholder' => esc_html__( 'E.g. 00', 'forminator' ), 'am_pm_label' => esc_html__( 'AM/PM', 'forminator' ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $hours_providers = apply_filters( 'forminator_field_' . $this->slug . '_hours_autofill', array(), $this->slug . '_hours' ); $minutes_providers = apply_filters( 'forminator_field_' . $this->slug . '_minutes_autofill', array(), $this->slug . '_minutes' ); $ampm_providers = apply_filters( 'forminator_field_' . $this->slug . '_ampm_autofill', array(), $this->slug . '_ampm' ); $autofill_settings = array( 'time-hours' => array( 'values' => forminator_build_autofill_providers( $hours_providers ), ), 'time-minutes' => array( 'values' => forminator_build_autofill_providers( $minutes_providers ), ), 'time-ampm' => array( 'values' => forminator_build_autofill_providers( $ampm_providers ), ), ); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $html = ''; $name = self::get_property( 'element_id', $field ); $id = self::get_field_id( $name ); $hour_id = self::get_subfield_id( $name, '-hours' ); $min_id = self::get_subfield_id( $name, '-minutes' ); $ampm_id = self::get_subfield_id( $name, '-ampm' ); $required = self::get_property( 'required', $field, false, 'bool' ); $design = $this->get_form_style( $settings ); // backward compatibilty when time doesnt have field_type. $field_type = trim( self::get_property( 'field_type', $field, 'input' ) ); $type = trim( self::get_property( 'time_type', $field ) ); $field_label = esc_html( self::get_property( 'field_label', $field ) ); $description = self::get_property( 'description', $field, '' ); $default_time = esc_html( self::get_property( 'default_time', $field, '' ) ); $increment_hour = self::get_property( 'increment_hour', $field, 0 ); $increment_minute = self::get_property( 'increment_minute', $field, 0 ); $restrict_time = self::get_property( 'restrict_time', $field, 'none' ); $has_limiter = 'specific' === $restrict_time ? 'has-time-limiter' : ''; $required_origin = $required; $draft_value = isset( $draft_value['value'] ) ? $draft_value['value'] : ''; $descr_position = self::get_description_position( $field, $settings ); $default_time_hour = ''; $default_time_minute = ''; $default_time_ampm = ''; $is_basic = 'basic' === $design; if ( 'default' === $default_time ) { $default_time_hour = self::get_property( 'default_time_hour', $field, '0' ); $default_time_minute = self::get_property( 'default_time_minute', $field, '0' ); $default_time_ampm = self::get_property( 'default_time_ampm', $field, '' ); } // Parse prefill settings. $prefill = $this->parse_prefill( $field ); if ( ! empty( $draft_value ) ) { if ( isset( $draft_value['hours'] ) ) { $default_time_hour = trim( $draft_value['hours'] ); } if ( isset( $draft_value['minutes'] ) ) { $default_time_minute = trim( $draft_value['minutes'] ); } if ( isset( $draft_value['ampm'] ) ) { $default_time_ampm = strtolower( trim( $draft_value['ampm'] ) ); } } elseif ( ! empty( $prefill ) ) { if ( isset( $prefill['hour'] ) ) { $default_time_hour = $prefill['hour']; } if ( isset( $prefill['minutes'] ) ) { $default_time_minute = $prefill['minutes']; } if ( isset( $prefill['suffix'] ) ) { $default_time_ampm = strtolower( $prefill['suffix'] ); } } $html .= self::get_field_label( $field_label, 'forminator-field-' . $name, $required ); if ( ! empty( $field_label ) ) { // mark hours and minutes required markup as false. $required = false; } if ( 'above' === $descr_position ) { $html .= self::get_description( $description, $id, $descr_position ); } $html .= '<div class="forminator-timepicker" '; if ( 'twelve' === $type && 'specific' === $restrict_time ) { $is_12_hr = 'twelve' === $type ? true : false; $html .= 'data-start-limit="' . esc_attr( $this->get_time_limiter( $field, 'start', $is_12_hr ) ) . '" '; $html .= 'data-end-limit="' . esc_attr( $this->get_time_limiter( $field, 'end', $is_12_hr ) ) . '"'; } $html .= '>'; $html .= '<div class="forminator-row" data-multiple="true">'; // Determinate field cols. $cols = ( 'twelve' === $type ) ? 4 : 6; /** * Create hours field */ $hours = array( 'type' => 'number', 'name' => $hour_id, 'min' => '0', 'max' => ( 'twelve' === $type ) ? '12' : '23', 'placeholder' => $this->sanitize_value( self::get_property( 'hh_placeholder', $field ) ), 'id' => self::get_field_id( $hour_id ), 'class' => 'forminator-input time-hours ' . $has_limiter, 'data-field' => 'hours', ); if ( ! empty( $description ) ) { $hours['aria-describedby'] = esc_attr( $id . '-description' ); } $hours ['value'] = '0'; if ( isset( $default_time_hour ) ) { $hours ['value'] = $default_time_hour; } if ( ! empty( $increment_hour ) ) { $hours ['step'] = (int) $increment_hour; $hours ['min'] = '0'; } $html .= sprintf( '<div id="%s" class="forminator-col forminator-col-%s">', $hours['name'], $cols ); $html .= '<div class="forminator-field">'; if ( 'select' === $field_type ) { $hours_data = array( 'name' => $hour_id, 'id' => self::get_field_id( $settings['form_id'] . '__field--' . $hour_id ), 'class' => $is_basic ? 'time-hours ' : 'forminator-select2 time-hours ' . $has_limiter, 'data-field' => 'hours', 'data-placeholder' => esc_attr__( 'Select', 'forminator' ), ); if ( ! empty( $description ) ) { $hours_data['aria-describedby'] = esc_attr( $id . '-description' ); } $limits = array(); if ( 'twentyfour' === $type && 'specific' === $restrict_time ) { $limits = array( 'start' => self::get_property( 'restrict_start_hour', $field, 0 ), 'end' => self::get_property( 'restrict_end_hour', $field, 0 ), ); } $html .= self::create_select( $hours_data, self::get_property( 'hh_label', $field ), $this->get_hours( $type, $increment_hour, $default_time_hour, $limits ), $default_time_hour, '', $required, $descr_position, ); } else { $html .= self::create_input( $hours, self::get_property( 'hh_label', $field ), '', $required, ); } $html .= '</div>'; $html .= '</div>'; /** * Create mintues field */ $minutes = array( 'type' => 'number', 'min' => 0, 'max' => 59, 'name' => $min_id, 'placeholder' => $this->sanitize_value( self::get_property( 'mm_placeholder', $field ) ), 'id' => self::get_field_id( $min_id ), 'class' => 'forminator-input time-minutes ' . $has_limiter, 'data-field' => 'minutes', ); if ( ! empty( $description ) ) { $minutes['aria-describedby'] = esc_attr( $id . '-description' ); } $minutes ['value'] = '0'; if ( isset( $default_time_minute ) ) { $minutes ['value'] = $default_time_minute; } if ( ! empty( $increment_minute ) ) { $minutes ['step'] = (int) $increment_minute; } $html .= sprintf( '<div id="%s" class="forminator-col forminator-col-%s">', $minutes['name'], $cols ); $html .= sprintf( '<div class="forminator-field">', $cols ); if ( 'select' === $field_type ) { $minutes_data = array( 'name' => $min_id, 'id' => self::get_field_id( $settings['form_id'] . '__field--' . $min_id ), 'class' => $is_basic ? 'time-minutes ' : 'forminator-select2 time-minutes ' . $has_limiter, 'data-field' => 'minutes', 'data-placeholder' => esc_attr__( 'Select', 'forminator' ), ); if ( ! empty( $description ) ) { $minutes_data['aria-describedby'] = esc_attr( $id . '-description' ); } $html .= self::create_select( $minutes_data, self::get_property( 'mm_label', $field ), $this->get_minutes( $type, $increment_minute, $default_time_minute, $required_origin ), $default_time_minute, '', $required, $descr_position, ); } else { $html .= self::create_input( $minutes, self::get_property( 'mm_label', $field ), '', $required, ); } $html .= '</div>'; $html .= '</div>'; if ( 'twelve' === $type ) { /** * Create AM/PM field */ $ampm = array( 'name' => $ampm_id, 'id' => self::get_field_id( $settings['form_id'] . '__field--' . $ampm_id ), 'class' => $is_basic ? 'time-ampm ' : 'forminator-select2 time-ampm ' . $has_limiter, 'data-field' => 'ampm', ); if ( ! empty( $description ) ) { $ampm['aria-describedby'] = esc_attr( $id . '-description' ); } $options = array( array( 'value' => 'am', 'label' => esc_html__( 'AM', 'forminator' ), ), array( 'value' => 'pm', 'label' => esc_html__( 'PM', 'forminator' ), ), ); $ampm_value = ''; if ( ! empty( $default_time_ampm ) ) { $ampm_value = $default_time_ampm; } $html .= sprintf( '<div class="forminator-col forminator-col-%s">', $cols ); $html .= '<div class="forminator-field">'; $html .= self::create_select( $ampm, self::get_property( 'am_pm_label', $field ), $options, $ampm_value ); $html .= '</div>'; $html .= '</div>'; } $html .= '</div>'; $html .= '</div>'; if ( 'above' !== $descr_position ) { $html .= self::get_description( $description, $id, $descr_position ); } return apply_filters( 'forminator_field_time_markup', $html, $field ); } /** * Return hours * * @since 1.0.5 * * @param string $type Type. * @param int $increment_hour Increment hour. * @param string|int $default_value Default value. * @param array $limits - The limits for 24hr format, 12hr limits are handled in the FE. * * TO DO: Placeholder bug can be fixed here and in get_minutes. * * @return array */ public function get_hours( $type, $increment_hour, $default_value, $limits = array() ) { $array = array(); if ( 'twelve' === $type ) { $min = 1; $max = 12; } elseif ( ! empty( $limits ) ) { $min = (int) $limits['start']; $max = (int) $limits['end']; } else { $min = 0; $max = 23; } for ( $i = $min; $i <= $max; $i++ ) { $array[] = array( 'label' => sprintf( '%02d', $i ), 'value' => $i, ); if ( ! empty( $increment_hour ) ) { $i += $increment_hour - 1; } } // 12th option should be the first one for 12h format. if ( 'twelve' === $type ) { $last = array_pop( $array ); array_unshift( $array, $last ); } // Add hyphen option to the beginning of the list. if ( '' === $default_value ) { array_unshift( $array, array( 'label' => '-', 'value' => '', ) ); } return apply_filters( 'forminator_field_time_get_hours', $array, $this ); } /** * Return minutes * * @param string $type twelve|twentyfour Format type. * @param int $increment_minutes Increment minute. * @param string|int $default_value Default value. * @param bool $required Is required or not. * * @since 1.0.5 * @return array */ public function get_minutes( $type, $increment_minutes, $default_value, $required ) { $array = array(); for ( $i = 0; $i < 60; $i++ ) { $array[] = array( 'label' => sprintf( '%02d', $i ), 'value' => $i, ); if ( ! empty( $increment_minutes ) ) { $i += ( $increment_minutes % 60 ) - 1; } } // Add hyphen option to the beginning of the list. if ( '' === $default_value ) { array_unshift( $array, array( 'label' => '-', 'value' => '', ) ); } return apply_filters( 'forminator_field_time_get_minutes', $array, $this ); } /** * Return field inline validation rules * * @since 1.0 * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); $type = self::get_property( 'time_type', $field, 'twelve' ); $restrict_time = self::get_property( 'restrict_time', $field, 'none' ); $rules = ''; if ( 'specific' === $restrict_time || $is_required ) { $components = array( 'hours', 'minutes' ); $start_limit = 'twelve' === $type ? $this->get_time_limiter( $field ) : $this->get_time_limiter( $field, 'start', false ); $end_limit = 'twelve' === $type ? $this->get_time_limiter( $field, 'end' ) : $this->get_time_limiter( $field, 'end', false ); $time_limit = array( 'start_limit' => $start_limit, 'end_limit' => $end_limit, ); foreach ( $components as $part ) { $rules .= '"' . $this->get_id( $field ) . '-' . $part . '": {'; if ( $is_required ) { $rules .= '"required": true,'; } if ( 'specific' === $restrict_time && 'minutes' !== $part ) { $rules .= '"timeLimit": ' . wp_json_encode( $time_limit ) . ','; } $rules .= '},'; } } return apply_filters( 'forminator_field_time_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @return string */ public function get_validation_messages() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $required_message = self::get_property( 'required_message', $field, '' ); $type = trim( self::get_property( 'time_type', $field, 'twelve' ) ); $messages = ''; $hours_label = self::get_property( 'hh_label', $field, 'Hours' ); $minutes_label = self::get_property( 'mm_label', $field, 'Minutes' ); $restrict_time = self::get_property( 'restrict_time', $field, 'none' ); $start_limit = 'twelve' === $type ? $this->get_time_limiter( $field ) : $this->get_time_limiter( $field, 'start', false ); $end_limit = 'twelve' === $type ? $this->get_time_limiter( $field, 'end' ) : $this->get_time_limiter( $field, 'end', false ); $default_restrict_message = $this->get_default_restrict_message( $start_limit, $end_limit ); $restrict_message = self::get_property( 'restrict_message', $field, $default_restrict_message ); $restrict_message = apply_filters( 'forminator_time_field_limit_validation_message', forminator_addcslashes( $restrict_message ), $id, $field ); $messages .= '"' . $this->get_id( $field ) . '-hours": {' . "\n"; $min_hour = ( 'twelve' === $type ) ? '1' : '0'; $max_hour = ( 'twelve' === $type ) ? '12' : '23'; $messages .= '"min": "' . sprintf( apply_filters( 'forminator_time_field_hours_min_validation_message', /* translators: 1. Minimum hour, 2. Hours label. */ esc_html__( 'Please enter a value greater than or equal to %1$s for %2$s.', 'forminator' ) ), $min_hour, forminator_addcslashes( $hours_label ) ) . '",' . "\n"; $messages .= '"max": "' . sprintf(/* translators: ... */ apply_filters( 'forminator_time_field_hours_max_validation_message', esc_html__( 'Please enter a value less than or equal to %1$s for %2$s.', 'forminator' ) ), $max_hour, forminator_addcslashes( $hours_label ) ) . '",' . "\n"; $messages .= '"number": "' . sprintf( apply_filters( 'forminator_time_field_hours_number_validation_message', /* translators: 1. Hours label. */ esc_html__( 'Please enter a valid number for %1$s.', 'forminator' ) ), forminator_addcslashes( $hours_label ) ) . '",' . "\n"; if ( $this->is_required( $field ) ) { // Hours validation. $hours_message = apply_filters( 'forminator_time_field_hours_required_validation_message', ( ! empty( $required_message ) ? '<strong>' . forminator_addcslashes( $hours_label ) . '</strong>: ' . forminator_addcslashes( $required_message ) : esc_html__( 'This field is required. Please input a valid hour.', 'forminator' ) ), $id, $field ); $messages .= '"required": "' . $hours_message . '",' . "\n"; } if ( 'specific' === $restrict_time ) { $messages .= '"timeLimit": "' . $restrict_message . '",' . "\n"; } $messages .= '},' . "\n"; // minutes. $messages .= '"' . $this->get_id( $field ) . '-minutes": {' . "\n"; $messages .= '"min": "' . sprintf(/* translators: ... */ apply_filters( 'forminator_time_field_minutes_min_validation_message', esc_html__( 'Please enter a value greater than or equal to 0 for %1$s.', 'forminator' ) ), forminator_addcslashes( $minutes_label ) ) . '",' . "\n"; $messages .= '"max": "' . sprintf( apply_filters( 'forminator_time_field_minutes_max_validation_message', /* translators: 1. Minutes label. */ esc_html__( 'Please enter a value less than or equal to 59 for %1$s.', 'forminator' ) ), forminator_addcslashes( $minutes_label ) ) . '",' . "\n"; $messages .= '"number": "' . sprintf( apply_filters( 'forminator_time_field_minutes_number_validation_message', /* translators: 1. Minutes label. */ esc_html__( 'Please enter a valid number for %1$s.', 'forminator' ) ), forminator_addcslashes( $minutes_label ) ) . '",' . "\n"; if ( $this->is_required( $field ) ) { // Minutes validation. $minutes_message = apply_filters( 'forminator_time_field_minutes_required_validation_message', ( ! empty( $required_message ) ? '<strong>' . forminator_addcslashes( $minutes_label ) . '</strong>: ' . forminator_addcslashes( $required_message ) : esc_html__( 'This field is required. Please input a valid minute.', 'forminator' ) ), $id, $field ); $messages .= '"required": "' . $minutes_message . '",' . "\n"; } $messages .= '},' . "\n"; return $messages; } /** * Check if time is valid * * @since 1.10 * * @param int $hour Hour. * @param int $minute Minute. * @param int $format Time format. * * @return bool */ public function is_valid_time( $hour, $minute, $format = 24 ) { // Check if numeric values. if ( is_numeric( $hour ) && is_numeric( $minute ) ) { if ( 24 === $format ) { if ( ( $hour >= 0 && $hour < 24 ) && ( $minute >= 0 && $minute < 60 ) ) { return true; } } elseif ( ( $hour >= 0 && $hour < 13 ) && ( $minute >= 0 && $minute < 60 ) ) { return true; } } return false; } /** * Parse prefill value * * @since 1.10 * * @param array $field Field. * * @return array */ public function parse_prefill( $field ) { $value = array(); $type = trim( self::get_property( 'time_type', $field, 'twelve' ) ); // Check if Pre-fill parameter used. if ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $prefill = $this->get_prefill( $field, '' ); if ( $prefill ) { // Check value length. $length = strlen( $prefill ); // We have 24h format. if ( 5 === $length && 'twentyfour' === $type ) { $time = explode( ':', $prefill ); if ( isset( $time[0] ) && isset( $time[1] ) ) { // Check if valid values. if ( $this->is_valid_time( $time[0], $time[1], 24 ) ) { $value = array( 'hour' => $time[0], 'minutes' => $time[1], ); } } } if ( 7 === $length && 'twelve' === $type ) { $time = explode( ':', $prefill ); if ( isset( $time[0] ) && isset( $time[1] ) ) { if ( $this->is_valid_time( $time[0], substr( $time[1], 0, 2 ), 12 ) ) { $value = array( 'hour' => $time[0], 'minutes' => substr( $time[1], 0, 2 ), 'suffix' => substr( $prefill, - 2 ), ); } } } } } return $value; } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $is_valid = true; $type = self::get_property( 'time_type', $field, 'twelve' ); $restrict_time = self::get_property( 'restrict_time', $field, 'none' ); $id = self::get_property( 'element_id', $field ); if ( $this->is_required( $field ) ) { $required_message = self::get_property( 'required_message', $field, '' ); if ( empty( $data ) || ( ! empty( $data ) && '' === $data['hours'] ) ) { $is_valid = false; $this->validation_message[ $id . '-hours' ] = apply_filters( 'forminator_time_field_hours_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please input a valid hour.', 'forminator' ) ), $id, $field ); } if ( empty( $data ) || ( ! empty( $data ) && '' === $data['minutes'] ) ) { $is_valid = false; $this->validation_message[ $id . '-minutes' ] = apply_filters( 'forminator_time_field_minutes_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please input a valid minute.', 'forminator' ) ), $id, $field ); } // If required, hours and minutes cannot be both 0. if ( ! empty( $data ) && 'twelve' === $type && empty( $data['hours'] ) && empty( $data['minutes'] ) ) { $is_valid = false; $this->validation_message[ $id . '-hours' ] = apply_filters( 'forminator_time_field_hours_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Hours and Minutes cannot be both 0.', 'forminator' ) ), $id, $field ); } if ( ! $is_valid ) { return; } } $hour = isset( $data['hours'] ) ? $data['hours'] : ''; $minute = isset( $data['minutes'] ) ? $data['minutes'] : ''; $hours_error_message = apply_filters( 'forminator_time_field_minutes_validation_message', esc_html__( 'Please enter a valid hour.', 'forminator' ), $id, $field ); $minutes_error_message = apply_filters( 'forminator_time_field_minutes_validation_message', esc_html__( 'Please enter a valid minute.', 'forminator' ), $id, $field ); if ( ( ! is_numeric( $hour ) && '' !== $hour ) || ( ! is_numeric( $minute ) && '' !== $minute ) ) { if ( ! is_numeric( $hour ) ) { $this->validation_message[ $id . '-hours' ] = $hours_error_message; } if ( ! is_numeric( $minute ) ) { $this->validation_message[ $id . '-minutes' ] = $minutes_error_message; } } else { // possible hour is string, because its sent from form data. $hour = (int) $hour; $min_hour = 0; $max_hour = 'twelve' === $type ? 12 : 23; $max_minute = $hour > 23 ? 0 : 59; if ( $hour < $min_hour || $hour > $max_hour ) { $this->validation_message[ $id . '-hours' ] = $hours_error_message; } // In 12-hour format, hours cannot be 0 when minutes is not empty. if ( 'twelve' === $type ) { if ( 0 === $hour ) { $max_minute = 0; } if ( $minute > $max_minute && $max_minute > 0 ) { $this->validation_message[ $id . '-minutes' ] = $minutes_error_message; } if ( empty( $hour ) && $minute > 0 ) { $this->validation_message[ $id . '-hours' ] = $hours_error_message; } if ( 0 === $minute && 0 === $hour ) { $this->validation_message[ $id . '-minutes' ] = $minutes_error_message; $this->validation_message[ $id . '-hours' ] = $hours_error_message; } } // In military time, hours and minutes can be 0. if ( 'twentyfour' === $type && $minute > $max_minute ) { $this->validation_message[ $id . '-minutes' ] = $minutes_error_message; } } // Reset $hour and $minute here. $hour = isset( $data['hours'] ) ? $data['hours'] : ''; $minute = isset( $data['minutes'] ) ? $data['minutes'] : ''; if ( 'specific' === $restrict_time && ( ( '' !== $hour && '' !== $minute ) || ( '' !== $hour && '' === $minute ) || ( '' === $hour && '' !== $minute ) ) ) { if ( 'twelve' === $type ) { $data_time = sprintf( '%02d', $hour ) . ':' . sprintf( '%02d', $minute ) . ' ' . $data['ampm']; $start_limit_time = $this->get_time_limiter( $field, 'start' ); $end_limit_time = $this->get_time_limiter( $field, 'end' ); } else { $data_time = sprintf( '%02d', $hour ) . ':' . sprintf( '%02d', $minute ); $start_limit_time = $this->get_time_limiter( $field, 'start', false ); $end_limit_time = $this->get_time_limiter( $field, 'end', false ); } if ( ( '' !== $hour && '' === $minute ) || ( '' === $hour && '' !== $minute ) || strtotime( $data_time ) < strtotime( $start_limit_time ) || strtotime( $data_time ) > strtotime( $end_limit_time ) ) { $default_restrict_message = $this->get_default_restrict_message( $start_limit_time, $end_limit_time ); $this->validation_message[ $id . '-hours' ] = apply_filters( 'forminator_time_field_limit_validation_message', self::get_property( 'restrict_message', $field, $default_restrict_message ), $id, $field ); $this->validation_message[ $id . '-minutes' ] = ''; $this->validation_message[ $id . '-ampm' ] = ''; } } } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. if ( is_array( $data ) ) { $data = forminator_sanitize_array_field( $data ); } else { $data = forminator_sanitize_field( $data ); } return apply_filters( 'forminator_field_time_sanitize', $data, $field, $original_data ); } /** * Get the limiters for time * * @since 1.18.0 * * @param array $field - The field settings. * @param string $type - Either start or end. * @param bool $is_12_hr Is 12 hour?. * * @return string $time - the start of time limit */ public function get_time_limiter( $field, $type = 'start', $is_12_hr = true ) { $restrict_hour = self::get_property( 'restrict_' . $type . '_hour', $field, 0 ); $restrict_minute = self::get_property( 'restrict_' . $type . '_minute', $field, 0 ); $meridiem = self::get_property( 'restrict_' . $type . '_ampm', $field, 'am' ); $meridiem = $is_12_hr ? ' ' . $meridiem : ''; return sprintf( '%02d', $restrict_hour ) . ':' . sprintf( '%02d', $restrict_minute ) . $meridiem; } /** * Get the default message for Time limits * * @since 1.18.0 * * @param string $start_limit Limit start. * @param string $end_limit Limit start. * * @return string */ public function get_default_restrict_message( $start_limit, $end_limit ) { return esc_html__( 'Please select a time within the specified time limits.', 'forminator' ) . ' (' . str_replace( ' ', '', $start_limit ) . ' - ' . str_replace( ' ', '', $end_limit ) . ')'; } } PK v~\�|�"� "� stripe.phpnu �[��� <?php /** * The Forminator_Stripe class. * It uses Stripe Card Element to process payment. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Stripe * * @since 1.7 */ class Forminator_Stripe extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'stripe'; /** * Type * * @var string */ public $type = 'stripe'; /** * Position * * @var int */ public $position = 23; /** * Options * * @var array */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon forminator-icon-stripe'; /** * Is connected * * @var bool */ public $is_connected = false; /** * Mode * * @var string */ public $mode = 'test'; /** * Payment plan * * @var array */ public $payment_plan = array(); /** * Payment plan hash * * @var string */ public string $payment_plan_hash = ''; /** * Forminator_Stripe constructor. */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Stripe', 'forminator' ); try { $stripe = new Forminator_Gateway_Stripe(); if ( $stripe->is_test_ready() && $stripe->is_live_ready() ) { $this->is_connected = true; } } catch ( Forminator_Gateway_Exception $e ) { $this->is_connected = false; } } /** * Field defaults * * @return array */ public function defaults() { $default_currency = 'USD'; try { $stripe = new Forminator_Gateway_Stripe(); $default_currency = $stripe->get_default_currency(); } catch ( Forminator_Gateway_Exception $e ) { forminator_maybe_log( __METHOD__, $e->getMessage() ); } return array( 'field_label' => esc_html__( 'Credit / Debit Card', 'forminator' ), 'mode' => 'test', 'currency' => $default_currency, 'amount_type' => 'fixed', 'logo' => '', 'company_name' => '', 'product_description' => '', 'customer_email' => '', 'receipt' => 'false', 'billing' => 'false', 'verify_zip' => 'false', 'card_icon' => 'true', 'language' => 'auto', 'options' => array(), 'base_class' => 'StripeElement', 'complete_class' => 'StripeElement--complete', 'empty_class' => 'StripeElement--empty', 'focused_class' => 'StripeElement--focus', 'invalid_class' => 'StripeElement--invalid', 'autofilled_class' => 'StripeElement--webkit-autofill', 'subscription_amount_type' => 'fixed', 'quantity_type' => 'fixed', 'payments' => array( array( 'plan_name' => esc_html__( 'Plan 1', 'forminator' ), 'payment_method' => 'single', 'amount_type' => 'fixed', 'amount' => '', 'subscription_amount_type' => 'fixed', 'quantity_type' => 'fixed', 'quantity' => '1', 'bill_input' => '1', ), ), ); } /** * Field front-end markup * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $settings = $views_obj->model->settings; $this->field = $field; $this->form_settings = $settings; $is_ocs = 'stripe-ocs' === $field['type']; // Don't render stripe field if there is stripe-ocs field in the form. if ( ! $is_ocs && $views_obj->has_field_type( 'stripe-ocs' ) ) { return ''; } $id = self::get_property( 'element_id', $field ); $description = self::get_property( 'description', $field, '' ); $descr_position = self::get_description_position( $field, $settings ); $label = esc_html( self::get_property( 'field_label', $field, '' ) ); $element_name = $id; $field_id = $id . '-field'; $mode = self::get_property( 'mode', $field, 'test' ); $currency = self::get_property( 'currency', $field, $this->get_default_currency() ); $amount = self::get_property( 'amount', $field, 1 ); $amount_variable = self::get_property( 'variable', $field, '' ); $card_icon = self::get_property( 'card_icon', $field, true ); $verify_zip = self::get_property( 'verify_zip', $field, false ); $zip_field = self::get_property( 'zip_field', $field, '' ); $language = self::get_property( 'language', $field, 'auto' ); $base_class = self::get_property( 'base_class', $field, 'StripeElement' ); $complete_class = self::get_property( 'complete_class', $field, 'StripeElement--complete' ); $empty_class = self::get_property( 'empty_class', $field, 'StripeElement--empty' ); $focused_class = self::get_property( 'focused_class', $field, 'StripeElement--focus' ); $invalid_class = self::get_property( 'invalid_class', $field, 'StripeElement--invalid' ); $autofilled_class = self::get_property( 'autofilled_class', $field, 'StripeElement--webkit-autofill' ); $billing = self::get_property( 'billing', $field, false ); $billing_name = self::get_property( 'billing_name', $field, '' ); $billing_email = self::get_property( 'billing_email', $field, '' ); $billing_address = self::get_property( 'billing_address', $field, '' ); $receipt = self::get_property( 'receipt', $field, false ); $customer_email = self::get_property( 'customer_email', $field, '' ); $metadata = self::get_property( 'options', $field, array() ); $desc = self::get_property( 'product_description', $field, '' ); $company = self::get_property( 'company_name', $field, '' ); $uniqid = Forminator_CForm_Front::$uid; $id_prefix = $is_ocs ? 'payment-element' : 'card-element'; $full_id = $id_prefix . '-' . $uniqid; $prefix = 'basic' === $settings['form-style'] ? 'basic-' : ''; if ( mb_strlen( $company ) > 22 ) { $company = mb_substr( $company, 0, 19 ) . '...'; } $customer_email = forminator_clear_field_id( $customer_email ); $custom_fonts = false; // Generate payment intent object. $this->mode = $mode; if ( isset( $settings[ $prefix . 'form-font-family' ] ) && 'custom' === $settings[ $prefix . 'form-font-family' ] ) { $custom_fonts = true; } if ( ! isset( $settings['form-substyle'] ) ) { $settings['form-substyle'] = 'default'; } $data_font_family = 'inherit'; $data_font_size = '16px'; $data_font_weight = '400'; if ( ! empty( $settings[ $prefix . 'form-font-family' ] ) ) { $field_font_family = $this->get_form_setting( $prefix . 'cform-input-font-family', $settings, $data_font_family ); $data_font_size = $this->get_form_setting( $prefix . 'cform-input-font-size', $settings, '16' ) . 'px'; $data_font_weight = $this->get_form_setting( $prefix . 'cform-input-font-weight', $settings, $data_font_weight ); if ( 'custom' === $field_font_family ) { $data_font_family = $this->get_form_setting( $prefix . 'cform-input-custom-family', $settings, $data_font_family ); } else { $data_font_family = $field_font_family; } } $data_placeholder = '#888888'; $data_font_color = '#000000'; $data_font_color_focus = '#000000'; $data_font_color_error = '#000000'; $data_icon_color = '#777771'; $data_icon_color_hover = '#17A8E3'; $data_icon_color_focus = '#17A8E3'; $data_icon_color_error = '#E04562'; if ( ! empty( $settings[ $prefix . 'cform-color-settings' ] ) ) { $data_placeholder = $this->get_form_setting( $prefix . 'input-placeholder', $settings, $data_placeholder ); $data_font_color = $this->get_form_setting( $prefix . 'input-color', $settings, $data_font_color ); $data_font_color_focus = $this->get_form_setting( $prefix . 'input-color', $settings, $data_font_color_focus ); $data_font_color_error = $this->get_form_setting( $prefix . 'input-color', $settings, $data_font_color_error ); $data_icon_color = $this->get_form_setting( $prefix . 'input-icon', $settings, $data_icon_color ); $data_icon_color_hover = $this->get_form_setting( $prefix . 'input-icon-hover', $settings, $data_icon_color_hover ); $data_icon_color_focus = $this->get_form_setting( $prefix . 'input-icon-focus', $settings, $data_icon_color_focus ); $data_icon_color_error = $this->get_form_setting( $prefix . 'label-validation-color', $settings, $data_icon_color_error ); } $attr = array( 'data-field-id' => $uniqid, 'data-is-payment' => 'true', 'data-payment-type' => $this->type, 'data-is-ocs' => $is_ocs, 'data-secret' => '', 'data-paymentid' => '', 'data-currency' => strtolower( $currency ), 'data-key' => esc_html( $this->get_publishable_key( 'test' !== $mode ) ), 'data-card-icon' => filter_var( $card_icon, FILTER_VALIDATE_BOOLEAN ), 'data-veify-zip' => filter_var( $verify_zip, FILTER_VALIDATE_BOOLEAN ), 'data-zip-field' => esc_html( $zip_field ), 'data-language' => esc_html( $language ), 'data-base-class' => esc_html( $base_class ), 'data-complete-class' => esc_html( $complete_class ), 'data-empty-class' => esc_html( $empty_class ), 'data-focused-class' => esc_html( $focused_class ), 'data-invalid-class' => esc_html( $invalid_class ), 'data-autofilled-class' => esc_html( $autofilled_class ), 'data-billing' => filter_var( $billing, FILTER_VALIDATE_BOOLEAN ), 'data-billing-name' => esc_html( $billing_name ), 'data-billing-email' => esc_html( $billing_email ), 'data-billing-address' => esc_html( $billing_address ), 'data-receipt' => filter_var( $receipt, FILTER_VALIDATE_BOOLEAN ), 'data-receipt-email' => esc_html( $customer_email ), 'data-custom-fonts' => $custom_fonts, 'data-placeholder' => $data_placeholder, 'data-font-color' => $data_font_color, 'data-font-color-focus' => $data_font_color_focus, 'data-font-color-error' => $data_font_color_error, 'data-font-size' => $data_font_size, 'data-font-family' => $data_font_family, 'data-font-weight' => $data_font_weight, 'data-icon-color' => $data_icon_color, 'data-icon-color-hover' => $data_icon_color_hover, 'data-icon-color-focus' => $data_icon_color_focus, 'data-icon-color-error' => $data_icon_color_error, ); if ( $is_ocs ) { $elements_options = array( 'loader' => 'always', 'locale' => $language, 'paymentMethodCreation' => 'manual', ); $variables = array( 'fontWeightNormal' => $data_font_weight, 'fontSizeBase' => $data_font_size, 'iconColor' => $data_icon_color, 'iconHoverColor' => $data_icon_color_hover, 'iconCardErrorColor' => $data_icon_color_error, 'iconCardCvcErrorColor' => $data_icon_color_error, 'colorTextPlaceholder' => $data_placeholder, ); $custom_appearance = self::get_property( 'custom_appearance', $field, false ); if ( $custom_appearance ) { $spacing = self::get_property( 'spacing_unit', $field, '' ); if ( $spacing ) { $variables['spacingUnit'] = $spacing . 'px'; } $border_radius = self::get_property( 'border_radius', $field, '' ); if ( $border_radius ) { $variables['borderRadius'] = $border_radius . 'px'; } $variables['colorPrimary'] = self::get_property( 'primary_color', $field, '' ); $variables['colorBackground'] = self::get_property( 'background_color', $field, '' ); $variables['colorText'] = self::get_property( 'text_color', $field, '' ); $variables['colorDanger'] = self::get_property( 'error', $field, '' ); } // Remove empty values. $variables = array_filter( $variables ); $appearance = array( 'theme' => self::get_property( 'theme', $field, 'stripe' ), 'variables' => $variables, ); if ( $custom_fonts && $data_font_family ) { $appearance['variables']['fontFamily'] = $data_font_family; $elements_options['fonts'][] = array( 'family' => $data_font_family, 'cssSrc' => 'https://fonts.bunny.net/css?family=' . $data_font_family, ); } $elements_options['appearance'] = $appearance; $dynamic_methods = self::get_property( 'automatic_payment_methods', $field, 'true' ); // If Only card is enabled, disable other payment methods. if ( 'false' === $dynamic_methods ) { $elements_options['paymentMethodTypes'] = array( 'card' ); } /** * Filter Stripe OCS Elements options * * @since 1.38 * * @param array $elements_options Elements options. * @param array $field Field. */ $elements_options = apply_filters( 'forminator_field_stripe_ocs_elements_options', $elements_options, $field ); $payment_options = array( 'layout' => self::get_layout( $field ), ); if ( 'false' === $dynamic_methods ) { $payment_options['wallets'] = array( 'applePay' => 'never', 'googlePay' => 'never', ); } /** * Filter Stripe OCS Payment options * * @since 1.38 * * @param array $payment_options Payment options. * @param array $field Field. */ $payment_options = apply_filters( 'forminator_field_stripe_ocs_elements_options', $payment_options, $field ); $billing_phone = self::get_property( 'billing_phone', $field, '' ); $attr = array( 'data-elements-options' => wp_json_encode( $elements_options, JSON_PRETTY_PRINT ), 'data-payment-options' => wp_json_encode( $payment_options, JSON_PRETTY_PRINT ), 'data-field-id' => $uniqid, 'data-is-payment' => 'true', 'data-payment-type' => $this->type, 'data-is-ocs' => $is_ocs, 'data-secret' => '', 'data-paymentid' => '', 'data-currency' => strtolower( $currency ), 'data-key' => esc_html( $this->get_publishable_key( 'test' !== $mode ) ), 'data-receipt' => filter_var( $receipt, FILTER_VALIDATE_BOOLEAN ), 'data-receipt-email' => esc_html( $customer_email ), 'data-billing' => filter_var( $billing, FILTER_VALIDATE_BOOLEAN ), 'data-billing-name' => esc_html( $billing_name ), 'data-billing-email' => esc_html( $billing_email ), 'data-billing-phone' => esc_html( $billing_phone ), 'data-billing-address' => esc_html( $billing_address ), 'data-return-url' => esc_url( self::get_return_url() ), ); } if ( ! empty( $description ) ) { $attr['aria-describedby'] = esc_attr( $full_id . '-description' ); } $attributes = self::implode_attr( $attr ); $html = '<div class="forminator-field">'; $html .= self::get_field_label( $label, $id . '-field', true ); if ( 'above' === $descr_position ) { $html .= self::get_description( $description, $full_id, $descr_position ); } if ( 'material' === $settings['form-substyle'] ) { $classes = 'forminator-input--wrap forminator-input--stripe'; if ( empty( $label ) ) { $classes .= ' forminator--no_label'; } $html .= '<div class="' . $classes . '">'; } $html .= sprintf( '<div id="%s" %s class="forminator-stripe-element%s"></div>', $full_id, $attributes, ( $is_ocs ? ' forminator-stripe-payment-element' : '' ) ); $html .= sprintf( '<input type="hidden" name="paymentid" value="%s" id="forminator-stripe-paymentid"/>', '' ); $html .= sprintf( '<input type="hidden" name="paymentmethod" value="%s" id="forminator-stripe-paymentmethod"/>', '' ); $html .= sprintf( '<input type="hidden" name="subscriptionid" value="%s" id="forminator-stripe-subscriptionid"/>', '' ); if ( 'material' === $settings['form-substyle'] ) { $html .= '</div>'; } $html .= '<span class="forminator-card-message"><span class="forminator-error-message" aria-hidden="true"></span></span>'; if ( 'above' !== $descr_position ) { $html .= self::get_description( $description, $full_id, $descr_position ); } $html .= '</div>'; return apply_filters( 'forminator_field_stripe_markup', $html, $attr, $field ); } /** * Get layout Stripe settings * * @param array $field Field. * @return array */ private static function get_layout( $field ) { $layout = self::get_property( 'layout', $field, 'tabs' ); if ( 'accordion+radio' === $layout ) { $radios = true; $layout = 'accordion'; } $data = array( 'type' => $layout, 'defaultCollapsed' => false, ); if ( 'accordion' === $layout ) { $data['spacedAccordionItems'] = false; $data['radios'] = ! empty( $radios ); } return $data; } /** * Generate Payment Intent object * * @since 1.7.3 * * @param int|float $amount Amount. * @param array $field Field. * * @return mixed */ public function generate_paymentIntent( $amount, $field ) { $currency = self::get_property( 'currency', $field, $this->get_default_currency() ); $mode = self::get_property( 'mode', $field, 'test' ); $metadata = self::get_property( 'options', $field, array() ); $description = esc_html( self::get_property( 'product_description', $field, '' ) ); $company = esc_html( self::get_property( 'company_name', $field, '' ) ); if ( mb_strlen( $company ) > 22 ) { $company = mb_substr( $company, 0, 19 ) . '...'; } $key = $this->get_secret_key( 'test' !== $mode ); \Forminator\Stripe\Stripe::setApiKey( $key ); Forminator_Gateway_Stripe::set_stripe_app_info(); $metadata_object = array(); foreach ( $metadata as $meta ) { $label = esc_html( $meta['label'] ); $value = esc_html( $meta['value'] ); // Payment doesn't work with empty meta labels. if ( '' === $label && '' === $value ) { continue; } if ( '' === $label ) { $label = $value; } $metadata_object[ $label ] = $value; } // Default options. $options = array( 'amount' => (int) $this->calculate_amount( $amount, $currency ), 'currency' => $currency, 'confirm' => false, ); $dynamic_methods = self::get_property( 'automatic_payment_methods', $field, 'true' ); if ( 'false' === $dynamic_methods ) { $options['payment_method_types'] = array( 'card' ); } else { $options['automatic_payment_methods'] = array( 'enabled' => true, ); $options['payment_method_options'] = array( 'wechat_pay' => array( 'client' => 'web', // Specify the client type. ), ); } if ( ! empty( Forminator_CForm_Front_Action::$prepared_data['paymentmethod'] ) ) { $options['payment_method'] = Forminator_CForm_Front_Action::$prepared_data['paymentmethod']; } // Check if metadata is not empty and add it to the options. if ( ! empty( $metadata_object ) ) { $options['metadata'] = $metadata_object; } // Check if statement_description is not empty and add it to the options. if ( ! empty( $company ) ) { $options['statement_descriptor_suffix'] = $company; } // Check if description is not empty and add it to the options. if ( ! empty( $description ) ) { $options['description'] = $description; } $options = apply_filters( 'forminator_stripe_payment_intent_options', $options, $field ); try { // Create Payment Intent object. $intent = \Forminator\Stripe\PaymentIntent::create( $options ); } catch ( Exception $e ) { $response = array( 'message' => $e->getMessage(), 'errors' => array(), 'paymentPlan' => $this->payment_plan_hash, ); wp_send_json_error( $response ); } return $intent; } /** * Calculate Stripe amount * * @since 1.11 * * @param int|float $amount Amount. * @param string $currency Currency. * * @return float|int */ public function calculate_amount( $amount, $currency ) { $zero_decimal_currencies = $this->get_zero_decimal_currencies(); // Check if currency is zero decimal, then return original amount. if ( in_array( $currency, $zero_decimal_currencies, true ) ) { return $amount; } // If JOD, amount needs to have 3 decimals and multiplied to 1000. if ( 'JOD' === $currency ) { $amount = number_format( $amount, 3, '.', '' ); return $amount * 1000; } $amount = number_format( $amount, 2, '.', '' ); // Currency has decimals, multiply by 100. return $amount * 100; } /** * Return currencies without decimal * * @since 1.11 * * @return array */ public function get_zero_decimal_currencies() { return array( 'MGA', 'BIF', 'CLP', 'PYG', 'DJF', 'RWF', 'GNF', 'UGX', 'VND', 'JPY', 'VUV', 'XAF', 'KMF', 'XOF', 'KRW', 'XPF', ); } /** * Update amount * * @since 1.7.3 * * @param array $submitted_data Submitted data. * @param array $field Field. * @throws Exception When there is an error. */ public function update_paymentIntent( $submitted_data, $field ) { $mode = self::get_property( 'mode', $field, 'test' ); $currency = self::get_property( 'currency', $field, $this->get_default_currency() ); $is_multi = self::get_property( 'automatic_payment_methods', $field, 'true' ); if ( ! empty( $this->payment_plan['payment_method'] ) && 'subscription' === $this->payment_plan['payment_method'] ) { $response_data = array( 'paymentid' => 'subscription', 'paymentsecret' => 'subscription', 'paymentPlan' => $this->payment_plan_hash, ); if ( 'false' === $is_multi && class_exists( 'Forminator_Stripe_Subscription' ) ) { try { $stripe_addon = Forminator_Stripe_Subscription::get_instance(); $field_object = Forminator_Core::get_field_object( 'stripe' ); $payment_plan = $field_object->get_payment_plan( $field ); $payment_intent = $stripe_addon->create_payment_intent( $field_object, Forminator_Front_Action::$module_object, Forminator_Front_Action::$prepared_data, $field, $payment_plan ); $response_data['paymentid'] = $payment_intent->id; $response_data['paymentsecret'] = $payment_intent->client_secret; } catch ( Exception $e ) { $response_data['paymentmethod_failed'] = '1'; } } wp_send_json_success( $response_data ); } // apply merge tags to payment description. $product_description = isset( $field['product_description'] ) ? $field['product_description'] : ''; if ( ! empty( $product_description ) ) { $product_description = forminator_replace_form_data( $product_description, Forminator_Front_Action::$module_object ); $field['product_description'] = $product_description; } // Get Stripe key. $key = $this->get_secret_key( 'test' !== $mode ); // Set Stripe key. \Forminator\Stripe\Stripe::setApiKey( $key ); Forminator_Gateway_Stripe::set_stripe_app_info(); $field_id = Forminator_Field::get_property( 'element_id', $field ); $amount = $submitted_data[ $field_id ] ?? 0; $id = $submitted_data['paymentid']; if ( ! $amount && ! empty( $submitted_data['stripe_first_payment_intent'] ) ) { // If amount is empty, set it to 1 for payment intent. Anyway, it will be updated during actual payment. $amount = 1; // Filter amount. It can be used to modify amount before creating payment intent for low-value currency // to achieve minimum Stripe charge amount .5 euro. Use $field['currency'] to get currency code. $amount = apply_filters( 'forminator_stripe_default_payment_intent_amount', $amount, $field ); } $payment_intent_key = $mode . '_' . $currency . '_' . $amount . '_' . substr( $key, -5 ); $is_intent = ! empty( $submitted_data['stripe-intent'] ); // Check if we already have payment ID, if not generate new one. if ( empty( $id ) ) { $generate_new = ! $is_intent; $id = $this->get_payment_intent_id( $amount, $field, $payment_intent_key, $generate_new ); } try { // Retrieve PI object. $intent = \Forminator\Stripe\PaymentIntent::retrieve( $id ); if ( 'succeeded' === $intent->status ) { // throw error if payment intent already succeeded. throw new Exception( esc_html__( 'Payment already succeeded.', 'forminator' ) ); } } catch ( Exception $e ) { $id = $this->get_payment_intent_id( $amount, $field, $payment_intent_key, true ); $intent = \Forminator\Stripe\PaymentIntent::retrieve( $id ); } // Convert object to array. $metadata_key = $intent->metadata->keys(); $metadata_value = $intent->metadata->values(); $stored_metadata = array_combine( $metadata_key, $metadata_value ); // New metadata array. $metadata = array(); if ( ! empty( $stored_metadata ) ) { foreach ( (array) $stored_metadata as $key => $meta ) { $metadata[ $key ] = forminator_replace_form_data( '{' . $meta . '}', Forminator_Front_Action::$module_object ); } } // Throw error if payment ID is empty. if ( empty( $id ) ) { $response = array( 'paymentPlan' => $this->payment_plan_hash, 'message' => esc_html__( 'Your Payment ID is empty, please reload the page and try again!', 'forminator' ), 'errors' => array(), ); wp_send_json_error( $response ); } if ( $is_intent ) { wp_send_json_success( array( 'paymentid' => $id, 'paymentsecret' => $intent->client_secret, 'paymentPlan' => $this->payment_plan_hash, ) ); } elseif ( 'succeeded' === $intent->status ) { // Check if the PaymentIntent already succeeded and continue. wp_send_json_success( array( 'paymentid' => $id, 'paymentsecret' => $intent->client_secret, ) ); } else { try { // Check payment method. if ( ! empty( $submitted_data['payment_method_type'] ) && in_array( $submitted_data['payment_method_type'], self::get_unsupported_payment_methods(), true ) ) { throw new Exception( esc_html__( 'The selected Payment Method is not supported.', 'forminator' ) ); } // Check payment amount. if ( 0 > $amount ) { throw new Exception( esc_html__( 'Payment amount should be larger than 0.', 'forminator' ) ); } // Check payment ID. if ( empty( $id ) ) { throw new Exception( esc_html__( 'Your Payment ID is empty!', 'forminator' ) ); } // Check payment method. if ( empty( $submitted_data['payment_method'] ) ) { throw new Exception( esc_html__( 'Your Payment Method is empty!', 'forminator' ) ); } $options = array( 'amount' => $this->calculate_amount( $amount, $currency ), 'payment_method' => $submitted_data['payment_method'], ); // Update receipt email if set on front-end. if ( isset( $submitted_data['receipt_email'] ) && ! empty( $submitted_data['receipt_email'] ) ) { $options['receipt_email'] = $submitted_data['receipt_email']; } if ( ! empty( $metadata ) ) { $options['metadata'] = $metadata; } // Update Payment Intent amount. \Forminator\Stripe\PaymentIntent::update( $id, $options ); // Return success. wp_send_json_success( array( 'paymentid' => $id, 'paymentsecret' => $intent->client_secret, 'paymentPlan' => $this->payment_plan_hash, ) ); } catch ( Exception $e ) { $response = array( 'message' => $e->getMessage(), 'errors' => array(), 'paymentPlan' => $this->payment_plan_hash, ); wp_send_json_error( $response ); } } } /** * Get payment intent ID * * @param int|float $amount Amount. * @param array $field Field. * @param string $payment_intent_key Payment intent key. * @param bool $force Use saved payment intents or not. * * @return string */ private function get_payment_intent_id( $amount, $field, $payment_intent_key, $force = false ): string { $saved_payment_intents = get_option( 'forminator_stripe_payment_intents', array() ); /** * Filter to force payment intent generation * * @param bool $force Force payment intent generation. * @param array $field Field. */ $force = apply_filters( 'forminator_stripe_force_payment_intent', $force, $field ); if ( ! $force && ! empty( $saved_payment_intents[ $payment_intent_key ] ) ) { $id = $saved_payment_intents[ $payment_intent_key ]; } else { $payment_intent = $this->generate_paymentIntent( $amount, $field ); $id = $payment_intent->id; $saved_payment_intents[ $payment_intent_key ] = $id; update_option( 'forminator_stripe_payment_intents', $saved_payment_intents ); } return $id; } /** * Get unsupported payment methods * * @return array */ private static function get_unsupported_payment_methods() { return apply_filters( 'forminator_stripe_unsupported_payment_methods', // All Stripe dynamic payment methods without immediate confirmation. array( 'sepa_debit', 'multibanco', 'boleto', 'ach_credit_transfer', 'ach_debit', 'sofort', 'funded', ) ); } /** * Get form setting * * @since 1.9 * * @param int $id Id. * @param array $settings Settings. * @param mixed $fallback Fallback method. * * @return mixed */ public function get_form_setting( $id, $settings, $fallback ) { // Check if user settings exist. if ( isset( $settings[ $id ] ) ) { return $settings[ $id ]; } // Return fallback. return $fallback; } /** * Field back-end validation * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); } /** * Sanitize data * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. $data = forminator_sanitize_field( $data ); return apply_filters( 'forminator_field_stripe_sanitize', $data, $field, $original_data ); } /** * Is available * * @since 1.7 * @inheritdoc * @param array $field Field. */ public function is_available( $field ) { $mode = self::get_property( 'mode', $field, 'test' ); try { $stripe = new Forminator_Gateway_Stripe(); if ( 'test' !== $mode ) { $stripe->set_live( true ); } if ( $stripe->is_ready() ) { return true; } } catch ( Forminator_Gateway_Exception $e ) { return false; } } /** * Get publishable key * * @since 1.7 * * @param bool $live Live?. * * @return bool|string */ private function get_publishable_key( $live = false ) { try { $stripe = new Forminator_Gateway_Stripe(); if ( $live ) { return $stripe->get_live_key(); } return $stripe->get_test_key(); } catch ( Forminator_Gateway_Exception $e ) { return false; } } /** * Get publishable key * * @since 1.7 * * @param bool $live Live?. * * @return bool|string */ private function get_secret_key( $live = false ) { try { $stripe = new Forminator_Gateway_Stripe(); if ( $live ) { return $stripe->get_live_secret( true ); } return $stripe->get_test_secret( true ); } catch ( Forminator_Gateway_Exception $e ) { return false; } } /** * Get default currency * * @return string */ private function get_default_currency() { try { $stripe = new Forminator_Gateway_Stripe(); return $stripe->get_default_currency(); } catch ( Forminator_Gateway_Exception $e ) { return 'USD'; } } /** * Process to entry data * * @param array $field Field. * * @return array|WP_Error * @throws Exception When there is an error. */ public function process_to_entry_data( $field ) { $entry_data = array( 'mode' => '', 'product_name' => '', 'payment_type' => '', 'amount' => '', 'quantity' => '', 'currency' => '', 'transaction_id' => '', 'transaction_link' => '', ); $mode = self::get_property( 'mode', $field, 'test' ); $currency = self::get_property( 'currency', $field, $this->get_default_currency() ); try { // Get Payment intent. $intent = $this->get_paymentIntent( $field ); if ( is_wp_error( $intent ) ) { throw new Exception( $intent->get_error_message() ); } elseif ( ! is_object( $intent ) ) { // Make sure Payment Intent is object. throw new Exception( esc_html__( 'Payment Intent object is not valid Payment object.', 'forminator' ) ); } // Check if the PaymentIntent is set or empty. if ( empty( $intent->id ) ) { throw new Exception( esc_html__( 'Payment Intent ID is not valid!', 'forminator' ) ); } // Check if the PaymentIntent is valid. if ( ! self::is_valid_payment_intent( $intent->id ) ) { return new WP_Error( 'forminator_stripe_payment_intent_already_handled', esc_html__( 'Payment Intent ID is not valid', 'forminator' ) ); } $charge_amount = $this->get_payment_amount( $field ); $entry_data['mode'] = $mode; $entry_data['currency'] = $currency; $entry_data['amount'] = number_format( $charge_amount, 2, '.', '' ); if ( ! empty( $this->payment_plan ) ) { $entry_data['product_name'] = $this->payment_plan['plan_name']; $entry_data['payment_type'] = $this->payment_method( $this->payment_plan['payment_method'] ); $entry_data['quantity'] = $this->payment_plan['quantity']; } $entry_data['transaction_link'] = self::get_transanction_link( $mode, $intent->id ); $entry_data['transaction_id'] = $intent->id; } catch ( Exception $e ) { $entry_data['error'] = $e->getMessage(); } /** * Filter stripe entry data that will be stored * * @since 1.7 * * @param array $entry_data Entry data. * @param array $field Field properties. * @param Forminator_Form_Model $module_object Forminator_Form_Model. * @param array $submitted_data Submitted data. * @param array $field_data_array current entry meta. * * @return array */ $entry_data = apply_filters( 'forminator_field_stripe_process_to_entry_data', $entry_data, $field, Forminator_Front_Action::$module_object, Forminator_CForm_Front_Action::$prepared_data, Forminator_CForm_Front_Action::$info['field_data_array'] ); return $entry_data; } /** * Check if payment intent is valid * * @param string $intent_id Payment Intent ID. * * @return bool */ private static function is_valid_payment_intent( $intent_id ): bool { if ( empty( Forminator_CForm_Front_Action::$info['stripe_field']['type'] ) || 'stripe-ocs' !== Forminator_CForm_Front_Action::$info['stripe_field']['type'] ) { return true; } $payment_intents = get_option( 'forminator_stripe_payment_intents', array() ); if ( is_array( $payment_intents ) && in_array( $intent_id, $payment_intents, true ) ) { // Remove payment intent after handling it. add_action( 'forminator_custom_form_mail_before_send_mail', function () use ( $intent_id ) { $option_key = 'forminator_stripe_payment_intents'; $payment_intents = get_option( $option_key, array() ); $payment_intents = array_diff( $payment_intents, array( $intent_id ) ); update_option( $option_key, $payment_intents ); } ); return true; } return false; } /** * Make linkify transaction_id * * @param string $transaction_id Transaction Id. * @param array $meta_value Meta value. * * @return string */ public static function linkify_transaction_id( $transaction_id, $meta_value ) { $transaction_link = $transaction_id; if ( isset( $meta_value['transaction_link'] ) && ! empty( $meta_value['transaction_link'] ) ) { $url = $meta_value['transaction_link']; $transaction_link = '<a href="' . $url . '" target="_blank" rel="noopener noreferrer" title="' . $transaction_id . '">' . $transaction_id . '</a>'; } /** * Filter link to Stripe transaction id * * @since 1.7 * * @param string $transaction_link * @param string $transaction_id * @param array $meta_value * * @return string */ $transaction_link = apply_filters( 'forminator_field_stripe_linkify_transaction_id', $transaction_link, $transaction_id, $meta_value ); return $transaction_link; } /** * Retrieve PaymentIntent object * * @param array $field Field. * * @return mixed object|string * @throws Exception When there is an error. */ public function get_paymentIntent( $field ) { $mode = self::get_property( 'mode', $field, 'test' ); $currency = self::get_property( 'currency', $field, $this->get_default_currency() ); // Check Stripe key. $key = $this->get_secret_key( 'test' !== $mode ); // Set Stripe key. \Forminator\Stripe\Stripe::setApiKey( $key ); Forminator_Gateway_Stripe::set_stripe_app_info(); try { // Makue sure payment ID exist. if ( empty( Forminator_CForm_Front_Action::$prepared_data['paymentid'] ) ) { throw new Exception( esc_html__( 'Stripe Payment ID does not exist.', 'forminator' ) ); } // Check payment amount. $intent = \Forminator\Stripe\PaymentIntent::retrieve( Forminator_CForm_Front_Action::$prepared_data['paymentid'] ); return $intent; } catch ( Exception $e ) { return $this->get_error( $e ); } } /** * Retrieve PaymentMethod object * * @since 1.15 * * @param array $field Field. * @param array $submitted_data Submitted data. * * @return mixed object|string * @throws Exception When there is an error. */ public function get_paymentMethod( $field, $submitted_data ) { $mode = self::get_property( 'mode', $field, 'test' ); $currency = self::get_property( 'currency', $field, $this->get_default_currency() ); // Check Stripe key. $key = $this->get_secret_key( 'test' !== $mode ); // Set Stripe key. \Forminator\Stripe\Stripe::setApiKey( $key ); Forminator_Gateway_Stripe::set_stripe_app_info(); try { // Makue sure payment ID exist. if ( ! isset( $submitted_data['paymentid'] ) ) { throw new Exception( esc_html__( 'Stripe Payment ID does not exist.', 'forminator' ) ); } // Check payment amount. $intent = \Forminator\Stripe\PaymentMethod::retrieve( $submitted_data['paymentmethod'] ); return $intent; } catch ( Exception $e ) { return $this->get_error( $e ); } } /** * Get Stripe return URL to pass it in API calls * * @return string */ public static function get_return_url() { return apply_filters( 'forminator_stripe_return_url', 'https://stripe.com' ); } /** * Confirm paymentIntent * * @param mixed $intent Payment Intent. * * @since 1.14.9 * * @return object|WP_Error */ public function confirm_paymentIntent( $intent ) { try { return $intent->confirm( array( 'return_url' => self::get_return_url() ) ); } catch ( Exception $e ) { return $this->get_error( $e ); } } /** * Get the exception error and return WP_Error * * @param mixed $e Exception. * * @since 1.14.9 * * @return WP_Error */ private function get_error( $e ) { $code = $e->getCode(); if ( is_int( $code ) ) { $code = ( 0 === $code ) ? 'zero' : $code; return new WP_Error( $code, $e->getMessage() ); } else { return new WP_Error( $e->getError()->code, $e->getMessage() ); } } /** * Get ALL fields that payment amount depends on * * @param array $field_settings Field settings. * @return array */ public function get_amount_dependent_fields_all( $field_settings ) { $depend_field = self::get_conditions_dependent_fields( $field_settings ); $plans = self::get_property( 'payments', $field_settings, array() ); foreach ( $plans as $plan ) { $plan_depends = self::get_plan_dependent_fields( $plan ); $depend_field = array_merge( $depend_field, $plan_depends ); } return array_values( array_unique( $depend_field ) ); } /** * Get the fields that an amount depends on * * @param array $field_settings Field settings. * @return array */ public function get_amount_dependent_fields( $field_settings ) { $this->payment_plan = $this->get_payment_plan( $field_settings ); $plan = $this->payment_plan; $amount = $this->get_payment_amount( $field_settings ); $this->payment_plan_hash = md5( wp_json_encode( $plan ) . $amount ); $conditions_depends = self::get_conditions_dependent_fields( $field_settings ); $plan_depends = self::get_plan_dependent_fields( $plan ); $depend_field = array_merge( $conditions_depends, $plan_depends ); return array_unique( $depend_field ); } /** * Get the fields that conditions based on * * @param array $field_settings Field settings. * * @return array */ private static function get_conditions_dependent_fields( $field_settings ) { $depend_field = array(); $all_conditions = self::get_property( 'conditions', $field_settings, array() ); $payments = self::get_property( 'payments', $field_settings, array() ); foreach ( $payments as $payment ) { $conditions = $payment['conditions'] ?? array(); if ( empty( $conditions ) || ! is_array( $conditions ) ) { continue; } $all_conditions = array_merge( $all_conditions, $conditions ); } foreach ( $all_conditions as $condition ) { if ( ! empty( $condition['element_id'] ) ) { $depend_field[] = $condition['element_id']; } } return $depend_field; } /** * Get the fields that a plan depends on * * @param array $plan Plan. * @return array */ private static function get_plan_dependent_fields( $plan ) { $depend_field = array(); if ( empty( $plan['payment_method'] ) ) { return $depend_field; } if ( 'single' === $plan['payment_method'] && ! empty( $plan['amount_type'] ) && 'variable' === $plan['amount_type'] && ! empty( $plan['variable'] ) ) { $depend_field[] = $plan['variable']; } if ( 'subscription' === $plan['payment_method'] && ! empty( $plan['subscription_amount_type'] ) && 'variable' === $plan['subscription_amount_type'] && ! empty( $plan['subscription_variable'] ) ) { $depend_field[] = $plan['subscription_variable']; } return $depend_field; } /** * Get payment amount * * @since 1.7 * * @param array $field Field. * * @return double */ public function get_payment_amount( $field ) { $payment_amount = 0.0; $amount_type = self::get_property( 'amount_type', $field, 'fixed' ); $amount = self::get_property( 'amount', $field, '0' ); $amount_variable = self::get_property( 'variable', $field, '' ); $submitted_data = Forminator_CForm_Front_Action::$prepared_data; if ( ! empty( $this->payment_plan ) ) { $amount_type = isset( $this->payment_plan['amount_type'] ) ? $this->payment_plan['amount_type'] : $amount_type; $amount = isset( $this->payment_plan['amount'] ) ? $this->payment_plan['amount'] : $amount; $amount_variable = isset( $this->payment_plan['variable'] ) ? $this->payment_plan['variable'] : $amount_variable; } if ( 'fixed' === $amount_type ) { $payment_amount = $amount; } else { $amount_var = $amount_variable; $form_field = Forminator_Front_Action::$module_object->get_field( $amount_var, false ); if ( $form_field ) { $form_field = $form_field->to_formatted_array(); if ( isset( $form_field['type'] ) ) { if ( 'calculation' === $form_field['type'] ) { // Calculation field get the amount from pseudo_submit_data. if ( isset( Forminator_CForm_Front_Action::$prepared_data[ $amount_var ] ) ) { $payment_amount = Forminator_CForm_Front_Action::$prepared_data[ $amount_var ]; } } elseif ( 'currency' === $form_field['type'] ) { // Currency field get the amount from submitted_data. $field_id = $form_field['element_id']; if ( isset( $submitted_data[ $field_id ] ) ) { $payment_amount = self::forminator_replace_number( $form_field, $submitted_data[ $field_id ] ); } } else { $field_object = Forminator_Core::get_field_object( $form_field['type'] ); if ( $field_object ) { $field_id = $form_field['element_id']; $submitted_field_data = isset( $submitted_data[ $field_id ] ) ? $submitted_data[ $field_id ] : null; $payment_amount = $field_object::get_calculable_value( $submitted_field_data, $form_field ); } } } } } if ( ! is_numeric( $payment_amount ) ) { $payment_amount = 0.0; } /** * Filter payment amount of stripe * * @since 1.7 * * @param double $payment_amount * @param array $field field settings. * @param Forminator_Form_Model $module_object * @param array $prepared_data */ $payment_amount = apply_filters( 'forminator_field_stripe_payment_amount', $payment_amount, $field, Forminator_Front_Action::$module_object, Forminator_CForm_Front_Action::$prepared_data ); return $payment_amount; } /** * Get Payment plan * * @param array $field Field. * * @return array */ public function get_payment_plan( $field ) { $payments = self::get_property( 'payments', $field, array() ); if ( ! empty( $payments ) ) { foreach ( $payments as $payment_settings ) { $payment_settings['condition_rule'] = ! empty( $payment_settings['condition_rule'] ) ? $payment_settings['condition_rule'] : 'all'; $payment_settings['condition_action'] = 'show'; if ( ! Forminator_Field::is_hidden( $field, $payment_settings ) ) { return $payment_settings; } } } return array(); } /** * Get transaction link * * @param string $mode Payment mode. * @param string $transaction_id Transaction id. * @return string */ public static function get_transanction_link( $mode, $transaction_id ) { if ( 'test' === $mode ) { $link_base = 'https://dashboard.stripe.com/test/payments/'; } else { $link_base = 'https://dashboard.stripe.com/payments/'; } $transaction_link = $link_base . rawurlencode( $transaction_id ); return $transaction_link; } /** * Payment method * * @param string $method Payment method. * * @return string|void */ public function payment_method( $method ) { switch ( $method ) { case 'single': $method = esc_html__( 'One Time', 'forminator' ); break; case 'subscription': $method = esc_html__( 'Subscription', 'forminator' ); break; default: $method = ''; } return $method; } } PK v~\���3� � date.phpnu �[��� <?php /** * The Forminator_Date class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Date * * @since 1.0 */ class Forminator_Date extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'date'; /** * Position * * @var int */ public $position = 12; /** * Type * * @var string */ public $type = 'date'; /** * Options * * @var string */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon-calendar'; /** * Forminator_Date constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Datepicker', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'field_type' => 'picker', 'date_format' => 'mm/dd/yy', 'default_date' => 'none', 'field_label' => esc_html__( 'Date', 'forminator' ), 'placeholder' => esc_html__( 'Choose Date', 'forminator' ), 'icon' => 'true', 'day_label' => esc_html__( 'Day', 'forminator' ), 'day_placeholder' => esc_html__( 'E.g. 01', 'forminator' ), 'month_label' => esc_html__( 'Month', 'forminator' ), 'month_placeholder' => esc_html__( 'E.g. 01', 'forminator' ), 'year_label' => esc_html__( 'Year', 'forminator' ), 'year_placeholder' => esc_html__( 'E.g. 2000', 'forminator' ), 'restrict_message' => esc_html__( 'Please select one of the available dates.', 'forminator' ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $providers = apply_filters( 'forminator_field_' . $this->slug . '_autofill', array(), $this->slug ); // TODO: support for multiple field date. $autofill_settings = array( 'date' => array( 'values' => forminator_build_autofill_providers( $providers ), ), ); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $html = ''; $design = $this->get_form_style( $settings ); $name = self::get_property( 'element_id', $field ); $required = self::get_property( 'required', $field, false ); $placeholder = $this->sanitize_value( self::get_property( 'placeholder', $field ) ); $label = $this->sanitize_value( self::get_property( 'field_label', $field ) ); $description = self::get_property( 'description', $field ); $type = trim( self::get_property( 'field_type', $field ) ); $has_icon = self::get_property( 'icon', $field, false, 'bool' ); $has_icon = filter_var( $has_icon, FILTER_VALIDATE_BOOLEAN ); $date_format = esc_html( self::get_property( 'date_format', $field, 'm/d/Y' ) ); $start_date_type = self::get_property( 'start-date', $field, '' ); $end_date_type = self::get_property( 'end-date', $field, '' ); $start_of_week = self::get_property( 'start_of_week', $field, get_option( 'start_of_week' ) ); $disabled_dates = self::get_property( 'disabled-dates', $field, array() ); $disabled_range = self::get_property( 'disable-date-range', $field, array() ); $id = self::get_field_id( $name ); $describedby = esc_attr( $id . '-description' ); $is_basic = 'basic' === $design; $descr_position = self::get_description_position( $field, $settings ); if ( false !== strpos( $date_format, '-' ) ) { $sep = '-'; } elseif ( false !== strpos( $date_format, '.' ) ) { $sep = '.'; } else { $sep = '/'; } $formats = explode( $sep, $date_format ); $min_year = esc_html( self::get_property( 'min_year', $field, gmdate( 'Y' ) - 100 ) ); $max_year = esc_html( self::get_property( 'max_year', $field, gmdate( 'Y' ) + 100 ) ); $prefill = false; $is_prefil_valid = false; // Check if Pre-fill parameter used. if ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $prefill = $this->get_prefill( $field, $prefill ); } $parsed_date = self::parse_date( $prefill, $date_format ); if ( $parsed_date && $this->check_date( $parsed_date['month'], $parsed_date['day'], $parsed_date['year'] ) ) { $is_prefil_valid = true; } if ( 'picker' === $type ) { $html .= '<div class="forminator-field">'; } if ( 'picker' === $type ) { $restrict = array(); $restrict_type = self::get_property( 'howto-restrict', $field ); if ( 'week' === $restrict_type ) { $days = forminator_week_days(); $i = 0; foreach ( $days as $k => $day ) { if ( ! self::get_property( $k, $field ) ) { $restrict[] = $i; } ++$i; } } elseif ( 'custom' === $restrict_type ) { $dates = self::get_property( 'date_multiple', $field ); $default_value = ''; $default_date = esc_html( self::get_property( 'default_date', $field, false ) ); if ( ! empty( $dates ) ) { foreach ( $dates as $k => $date ) { $restrict[] = $date['value']; } } if ( 'custom' === $default_date ) { $default_date_value = esc_html( self::get_property( 'date', $field, '' ) ); $default_value = $default_date_value; } } $default_value = ''; $default_date = self::get_property( 'default_date', $field, false ); if ( 'today' === $default_date ) { $datepicker_format = $this->normalize_date_format( $date_format ); $default_value = current_time( $datepicker_format ); } if ( 'custom' === $default_date ) { $default_date_value = self::get_property( 'date', $field, '' ); $default_value = $default_date_value; } if ( $is_prefil_valid ) { $default_value = $prefill; } $past_dates = self::get_property( 'past_dates', $field ); $past_dates = '' !== $default_value && 'disable' === $past_dates ? 'disable' : 'enable'; $start_date = ''; $end_date = ''; $start_date_field = ''; $end_date_field = ''; $start_offset = ''; $end_offset = ''; if ( ! empty( $start_date_type ) ) { if ( 'specific' === $start_date_type ) { $start_date = self::get_property( 'start-specific-date', $field, '' ); } else { $start_offset_operator = self::get_property( 'start-offset-operator', $field, '+' ); $start_offset_value = self::get_property( 'start-offset-value', $field, '0' ); $start_offset_duration = self::get_property( 'start-offset-duration', $field, 'days' ); if ( 'today' === $start_date_type ) { $start_date = date_i18n( 'Y-m-d', strtotime( $start_offset_operator . $start_offset_value . ' ' . $start_offset_duration, current_time( 'U' ) ) ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested -- We are using the current timestamp based on the site's timezone. } else { $start_date_field = $start_date_type; $start_offset = $start_offset_operator . '_' . $start_offset_value . '_' . $start_offset_duration; } } } if ( ! empty( $end_date_type ) ) { if ( 'specific' === $end_date_type ) { $end_date = self::get_property( 'end-specific-date', $field, '' ); } else { $end_offset_operator = self::get_property( 'end-offset-operator', $field, '+' ); $end_offset_value = self::get_property( 'end-offset-value', $field, '0' ); $end_offset_duration = self::get_property( 'end-offset-duration', $field, 'days' ); if ( 'today' === $end_date_type ) { $end_date = date_i18n( 'Y-m-d', strtotime( $end_offset_operator . $end_offset_value . ' ' . $end_offset_duration, current_time( 'U' ) ) ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested -- We are using the current timestamp based on the site's timezone. } else { $end_date_field = $end_date_type; $end_offset = $end_offset_operator . '_' . $end_offset_value . '_' . $end_offset_duration; } } } $icon_markup = array( '<div class="forminator-input-with-icon">', '</div>', 'calendar', ); if ( ! empty( $start_date ) ) { $min_year = gmdate( 'Y', strtotime( $start_date ) ); } if ( ! empty( $end_date ) ) { $max_year = gmdate( 'Y', strtotime( $end_date ) ); } if ( isset( $draft_value['value'] ) ) { $default_value = $draft_value['value']; } $html .= self::create_input( array( 'autocomplete' => 'off', 'type' => 'text', 'size' => 1, 'name' => $name, 'value' => $default_value, 'placeholder' => $placeholder, 'id' => self::get_field_id( $name . '-picker' ), 'class' => 'forminator-input forminator-datepicker', 'data-required' => $required, 'data-format' => $date_format, 'data-restrict-type' => $restrict_type, 'data-restrict' => implode( ',', $restrict ), 'data-start-year' => $min_year, 'data-end-year' => $max_year, 'data-past-dates' => $past_dates, 'data-start-of-week' => $start_of_week, 'data-start-date' => $start_date, 'data-end-date' => $end_date, 'data-start-field' => $start_date_field, 'data-end-field' => $end_date_field, 'data-start-offset' => $start_offset, 'data-end-offset' => $end_offset, 'data-disable-date' => implode( ',', $disabled_dates ), 'data-disable-range' => implode( ',', $disabled_range ), ), $label, $description, $required, $descr_position, $has_icon ? $icon_markup : '' ); } elseif ( 'select' === $type ) { if ( ! empty( $label ) ) { $html .= self::get_field_label( $label, 'forminator-field-' . $name, $required ); // Mark day, month and year required markup as false. $required = false; } if ( 'above' === $descr_position ) { $html .= self::get_description( $description, $id, $descr_position ); } $default_date = esc_html( self::get_property( 'default_date', $field, false ) ); $default_date_value = esc_html( self::get_property( 'date', $field, '' ) ); if ( $is_prefil_valid ) { $default_value = $prefill; } if ( isset( $draft_value['value'] ) ) { $parsed_date = $draft_value['value']; $day = $parsed_date['day']; $month = $parsed_date['month']; $year = $parsed_date['year']; } elseif ( $is_prefil_valid ) { $day = $parsed_date['day']; $month = $parsed_date['month']; $year = $parsed_date['year']; } elseif ( 'today' === $default_date ) { list( $day, $month, $year ) = explode( ' ', current_time( 'j n Y' ) ); } elseif ( 'custom' === $default_date && ! empty( $default_date_value ) ) { if ( empty( strtotime( $default_date_value ) ) ) { if ( false !== strpos( $date_format, '-' ) || false !== strpos( $date_format, '.' ) ) { $default_date_value = str_replace( array( '.', '-' ), '/', $default_date_value ); } elseif ( false !== strpos( $date_format, '/' ) ) { $default_date_value = str_replace( '/', '-', $default_date_value ); } } $day = gmdate( 'j', strtotime( $default_date_value ) ); $month = gmdate( 'n', strtotime( $default_date_value ) ); $year = gmdate( 'Y', strtotime( $default_date_value ) ); } else { $day = ''; $month = ''; $max_selected_year = esc_html( self::get_property( 'max_year', $field ) ); if ( $max_selected_year ) { $year = ''; } else { $year = gmdate( 'Y' ); } } // START: Row. $html .= '<div class="forminator-date-select">'; $html .= '<div class="forminator-row" data-multiple="true">'; foreach ( $formats as $format ) { switch ( $format ) { case 'dd': $day_id = self::get_subfield_id( $name, '-day' ); $html .= '<div id="' . $day_id . '" class="forminator-col">'; $html .= '<div class="forminator-field">'; $day_data = array( 'name' => $day_id, 'id' => self::get_field_id( $settings['form_id'] . '__field--' . $day_id ), 'class' => $is_basic ? '' : 'forminator-select2', 'data-format' => $date_format, 'data-parent' => $name, ); if ( ! empty( $description ) ) { $day_data['aria-describedby'] = $describedby; } if ( $required ) { $label = self::get_property( 'day_label', $field ); if ( ! empty( $label ) ) { $html .= sprintf( '<label for="%s" class="forminator-label">%s %s</label>', $day_data['id'], $this->sanitize_value( $label ), '<span class="forminator-required">*</span>' ); } $html .= self::create_select( $day_data, false, $this->get_day(), $day ); } else { $html .= self::create_select( $day_data, $this->sanitize_value( self::get_property( 'day_label', $field ) ), $this->get_day(), $day ); } $html .= '</div>'; $html .= '</div>'; break; case 'mm': $month_id = self::get_subfield_id( $name, '-month' ); $html .= '<div id="' . $month_id . '" class="forminator-col">'; $html .= '<div class="forminator-field">'; $month_data = array( 'name' => $month_id, 'id' => self::get_field_id( $settings['form_id'] . '__field--' . $month_id ), 'class' => $is_basic ? '' : 'forminator-select2', 'data-format' => $date_format, 'data-parent' => $name, ); if ( ! empty( $description ) ) { $month_data['aria-describedby'] = $describedby; } if ( $required ) { $label = self::get_property( 'month_label', $field ); if ( ! empty( $label ) ) { $html .= sprintf( '<label for="%s" class="forminator-label">%s %s</label>', $month_data['id'], $this->sanitize_value( $label ), '<span class="forminator-required">*</span>' ); } $html .= self::create_select( $month_data, false, $this->get_months(), $month ); } else { $html .= self::create_select( $month_data, $this->sanitize_value( self::get_property( 'month_label', $field ) ), $this->get_months(), $month ); } $html .= '</div>'; $html .= '</div>'; break; case 'yy': $year_id = self::get_subfield_id( $name, '-year' ); $html .= '<div id="' . $year_id . '" class="forminator-col">'; $html .= '<div class="forminator-field">'; $year_data = array( 'name' => $year_id, 'id' => self::get_field_id( $settings['form_id'] . '__field--' . $year_id ), 'class' => $is_basic ? '' : 'forminator-select2', 'data-format' => $date_format, 'data-parent' => $name, ); if ( ! empty( $description ) ) { $year_data['aria-describedby'] = $describedby; } if ( $required ) { $label = self::get_property( 'year_label', $field ); if ( ! empty( $label ) ) { $html .= sprintf( '<label for="%s" class="forminator-label">%s %s</label>', $year_data['id'], $this->sanitize_value( $label ), '<span class="forminator-required">*</span>' ); } $html .= self::create_select( $year_data, false, $this->get_years( $min_year, $max_year ), $year ); } else { $html .= self::create_select( $year_data, $this->sanitize_value( self::get_property( 'year_label', $field ) ), $this->get_years( $min_year, $max_year ), $year ); } $html .= '</div>'; $html .= '</div>'; break; default: break; } } $html .= '</div>'; // END: Row. $html .= '</div>'; if ( 'above' !== $descr_position ) { $html .= self::get_description( $description, $id, $descr_position ); } } elseif ( 'input' === $type ) { $day_value = ''; $month_value = ''; $year_value = ''; if ( isset( $draft_value['value'] ) ) { $parsed_date = $draft_value['value']; $day_value = $parsed_date['day']; $month_value = $parsed_date['month']; $year_value = $parsed_date['year']; } elseif ( $is_prefil_valid ) { $day_value = $parsed_date['day']; $month_value = $parsed_date['month']; $year_value = $parsed_date['year']; } $html .= self::get_field_label( $label, 'forminator-field-' . $name, $required ); if ( 'above' === $descr_position ) { $html .= self::get_description( $description, $id, $descr_position ); } // START: Row. $html .= '<div class="forminator-date-input">'; $html .= '<div class="forminator-row" data-multiple="true">'; foreach ( $formats as $format ) { switch ( $format ) { case 'dd': $day = self::get_subfield_id( $name, '-day' ); $html .= '<div id="' . $day . '" class="forminator-col">'; $html .= '<div class="forminator-field">'; $day_data = array( 'type' => 'number', 'min' => 1, 'max' => 31, 'name' => $day, 'value' => esc_attr( $day_value ), 'placeholder' => $this->sanitize_value( self::get_property( 'day_placeholder', $field ) ), 'id' => self::get_field_id( $day ), 'class' => 'forminator-input', 'data-field' => 'day', 'data-format' => $date_format, 'data-parent' => $name, ); if ( ! empty( $description ) ) { $day_data['aria-describedby'] = $describedby; } if ( $required ) { $label = self::get_property( 'day_label', $field ); if ( ! empty( $label ) ) { $html .= sprintf( '<label for="%s" class="forminator-label">%s %s</label>', $day_data['id'], $this->sanitize_value( $label ), '<span class="forminator-required">*</span>' ); } $html .= self::create_input( $day_data, false, '', $required, ); } else { $html .= self::create_input( $day_data, $this->sanitize_value( self::get_property( 'day_label', $field ) ), '', $required, ); } $html .= '</div>'; $html .= '</div>'; break; case 'mm': $month = self::get_subfield_id( $name, '-month' ); $html .= '<div id="' . $month . '" class="forminator-col">'; $html .= '<div class="forminator-field">'; $month_data = array( 'type' => 'number', 'min' => 1, 'max' => 12, 'name' => $month, 'value' => esc_attr( $month_value ), 'placeholder' => $this->sanitize_value( self::get_property( 'month_placeholder', $field ) ), 'id' => self::get_field_id( $month ), 'class' => 'forminator-input', 'data-field' => 'month', 'data-format' => $date_format, 'data-parent' => $name, ); if ( ! empty( $description ) ) { $month_data['aria-describedby'] = $describedby; } if ( $required ) { $label = self::get_property( 'month_label', $field ); if ( ! empty( $label ) ) { $html .= sprintf( '<label for="%s" class="forminator-label">%s %s</label>', $month_data['id'], $this->sanitize_value( $label ), '<span class="forminator-required">*</span>' ); } $html .= self::create_input( $month_data, false, '', $required, ); } else { $html .= self::create_input( $month_data, $this->sanitize_value( self::get_property( 'month_label', $field ) ), '', $required, ); } $html .= '</div>'; $html .= '</div>'; break; case 'yy': $year = self::get_subfield_id( $name, '-year' ); $html .= '<div id="' . $year . '" class="forminator-col">'; $html .= '<div class="forminator-field">'; $year_data = array( 'type' => 'number', 'min' => 1, 'name' => $year, 'placeholder' => $this->sanitize_value( self::get_property( 'year_placeholder', $field ) ), 'id' => self::get_field_id( $year ), 'class' => 'forminator-input', 'data-field' => 'year', 'value' => esc_attr( $year_value ), 'data-format' => $date_format, 'data-parent' => $name, ); if ( ! empty( $description ) ) { $year_data['aria-describedby'] = $describedby; } if ( $required ) { $label = self::get_property( 'year_label', $field ); if ( ! empty( $label ) ) { $html .= sprintf( '<label for="%s" class="forminator-label">%s %s</label>', $year_data['id'], $this->sanitize_value( $label ), '<span class="forminator-required">*</span>' ); } $html .= self::create_input( $year_data, false, '', $required, ); } else { $html .= self::create_input( $year_data, $this->sanitize_value( self::get_property( 'year_label', $field ) ), '', $required, ); } $html .= '</div>'; $html .= '</div>'; break; default: break; } } $html .= '</div>'; // END: Row. $html .= '</div>'; if ( 'above' !== $descr_position ) { $html .= self::get_description( $description, $id, $descr_position ); } } if ( 'picker' === $type ) { $html .= '</div>'; } return apply_filters( 'forminator_field_date_markup', $html, $field, $this ); } /** * Return modified date format * * @since 1.7.0.1 * * @param string $date_format Date format. * * @return string */ public function normalize_date_format( $date_format ) { $date_format = str_replace( 'dd', 'd', $date_format ); $date_format = str_replace( 'mm', 'm', $date_format ); $date_format = str_replace( 'yy', 'Y', $date_format ); return $date_format; } /** * Return all years between two dates * * @since 1.0 * * @param string $min_year Minimum year. * @param string $max_year Maximum year. * * @return array */ public function get_years( $min_year = '', $max_year = '' ) { $array = array(); $year = intval( gmdate( 'Y' ) ); $end = empty( $min_year ) ? $year - 100 : intval( $min_year ) - 1; $start = empty( $max_year ) ? $year + 100 : intval( $max_year ); for ( $i = $start; $i > $end; $i-- ) { $array[] = array( 'label' => $i, 'value' => $i, ); } array_unshift( $array, array( 'label' => esc_html__( 'Select Year', 'forminator' ), 'value' => '', ) ); return apply_filters( 'forminator_field_date_get_years', $array, $min_year, $max_year, $year, $start, $end, $this ); } /** * Return monts * * @since 1.0 * @return array */ public function get_months() { $array = array(); for ( $i = 1; $i < 13; $i++ ) { $array[] = array( 'label' => $i, 'value' => $i, ); } array_unshift( $array, array( 'label' => esc_html__( 'Select month', 'forminator' ), 'value' => '', ) ); return apply_filters( 'forminator_field_date_get_months', $array, $this ); } /** * Return days * * @since 1.0 * @return array */ public function get_day() { $array = array(); for ( $i = 1; $i < 32; $i++ ) { $array[] = array( 'label' => $i, 'value' => $i, ); } array_unshift( $array, array( 'label' => esc_html__( 'Select day', 'forminator' ), 'value' => '', ) ); return apply_filters( 'forminator_field_date_get_day', $array, $this ); } /** * Parse date * * @since 1.0 * * @param string|array $date - the date to be parsed. * @param string $format - the data format. * * @return array */ public static function parse_date( $date, $format = 'yy-mm-dd' ) { $date_info = array( 'year' => 0, 'month' => 0, 'day' => 0, ); $position = substr( $format, 0, 8 ); if ( is_array( $date ) ) { switch ( $position ) { case 'mm/dd/yy': case 'mm-dd-yy': case 'mm.dd.yy': $date_info['month'] = isset( $date['month'] ) ? $date['month'] : 0; $date_info['day'] = isset( $date['day'] ) ? $date['day'] : 0; $date_info['year'] = isset( $date['year'] ) ? $date['year'] : 0; break; case 'dd/mm/yy': case 'dd-mm-yy': case 'dd.mm.yy': $date_info['day'] = isset( $date['day'] ) ? $date['day'] : 0; $date_info['month'] = isset( $date['month'] ) ? $date['month'] : 0; $date_info['year'] = isset( $date['year'] ) ? $date['year'] : 0; break; case 'yy-mm-dd': case 'yy/mm/dd': case 'yy.mm.dd': $date_info['year'] = isset( $date['year'] ) ? $date['year'] : 0; $date_info['month'] = isset( $date['month'] ) ? $date['month'] : 0; $date_info['day'] = isset( $date['day'] ) ? $date['day'] : 0; break; default: break; } return apply_filters( 'forminator_field_date_parse_dates', $date_info, $date, $format ); } $date = preg_replace( '|[/\.]|', '-', $date ); if ( 'mm/dd/yy' === $position || 'mm-dd-yy' === $position || 'mm.dd.yy' === $position ) { if ( preg_match( '/^(\d{1,2})-(\d{1,2})-(\d{1,4})$/', $date, $matches ) ) { $date_info['month'] = $matches[1]; $date_info['day'] = $matches[2]; $date_info['year'] = $matches[3]; } } elseif ( 'dd/mm/yy' === $position || 'dd-mm-yy' === $position || 'dd.mm.yy' === $position ) { if ( preg_match( '/^(\d{1,2})-(\d{1,2})-(\d{1,4})$/', $date, $matches ) ) { $date_info['day'] = $matches[1]; $date_info['month'] = $matches[2]; $date_info['year'] = $matches[3]; } } elseif ( 'yy-mm-dd' === $position || 'yy/mm/dd' === $position || 'yy.mm.dd' === $position ) { if ( preg_match( '/^(\d{1,4})-(\d{1,2})-(\d{1,2})$/', $date, $matches ) ) { $date_info['year'] = $matches[1]; $date_info['month'] = $matches[2]; $date_info['day'] = $matches[3]; } } return apply_filters( 'forminator_field_date_parse_dates', $date_info, $date, $format ); } /** * Check data * * @since 1.0 * * @param int $month - the month. * @param int $day - the day. * @param int $year - the year. * * @return bool */ public function check_date( $month, $day, $year ) { if ( empty( $month ) || ! is_numeric( $month ) || empty( $day ) || ! is_numeric( $day ) || empty( $year ) || ! is_numeric( $year ) || 4 !== strlen( $year ) ) { return false; } return checkdate( $month, $day, $year ); } /** * Return field inline validation rules * * @since 1.0 * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $type = trim( self::get_property( 'field_type', $field ) ); $date_format = self::get_property( 'date_format', $field ); $rules = ''; if ( 'picker' === $type ) { $rules .= '"' . $this->get_id( $field ) . '": {' . "\n"; if ( $this->is_required( $field ) ) { $rules .= '"required": true,'; } $rules .= '"dateformat": "' . $date_format . '",'; $rules .= '},' . "\n"; } elseif ( $this->is_required( $field ) ) { $rules .= '"' . $this->get_id( $field ) . '-day": "required",'; $rules .= '"' . $this->get_id( $field ) . '-month": "required",'; $rules .= '"' . $this->get_id( $field ) . '-year": "required",'; } return apply_filters( 'forminator_field_date_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @return string */ public function get_validation_messages() { $field = $this->field; $type = trim( self::get_property( 'field_type', $field ) ); $date_format = self::get_property( 'date_format', $field ); $required_validation_message = self::get_property( 'required_message', $field, '' ); $month_label = self::get_property( 'month_label', $field, '' ); $day_label = self::get_property( 'day_label', $field, '' ); $year_label = self::get_property( 'year_label', $field, '' ); if ( empty( $required_validation_message ) ) { if ( 'picker' === $type ) { $required_validation_message = esc_html__( 'This field is required.', 'forminator' ); } else { $required_validation_message = ' ' . esc_html__( 'field is required.', 'forminator' ); } } $messages = ''; if ( 'picker' === $type ) { $messages = '"' . $this->get_id( $field ) . '": {' . "\n"; if ( $this->is_required( $field ) ) { $required_validation_message = apply_filters( 'forminator_field_date_required_validation_message', $required_validation_message, $field, $type, $date_format, $this ); $messages .= '"required": "' . forminator_addcslashes( $required_validation_message ) . '",' . "\n"; } $format_validation_message = apply_filters( 'forminator_field_date_format_validation_message', esc_html__( 'Not valid date', 'forminator' ), $field, $type, $date_format, $this ); $messages .= '"dateformat": "' . forminator_addcslashes( $format_validation_message ) . '",' . "\n"; $messages .= '},' . "\n"; } elseif ( $this->is_required( $field ) ) { $day_validation_message = apply_filters( 'forminator_field_date_day_validation_message', $required_validation_message, $field, $type, $date_format, $this ); $messages = '"' . $this->get_id( $field ) . '-day": "<strong>' . $day_label . '</strong> ' . forminator_addcslashes( $day_validation_message ) . '",' . "\n"; $month_validation_message = apply_filters( 'forminator_field_date_month_validation_message', $required_validation_message, $field, $type, $date_format, $this ); $messages .= '"' . $this->get_id( $field ) . '-month": "<strong>' . $month_label . '</strong> ' . forminator_addcslashes( $month_validation_message ) . '",' . "\n"; $year_validation_message = apply_filters( 'forminator_field_date_year_validation_message', $required_validation_message, $field, $type, $date_format, $this ); $messages .= '"' . $this->get_id( $field ) . '-year": "<strong>' . $year_label . '</strong> ' . forminator_addcslashes( $year_validation_message ) . '",' . "\n"; } return apply_filters( 'forminator_field_date_validation_message', $messages, $field, $type, $date_format, $this ); } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); $start_date_type = self::get_property( 'start-date', $field, '' ); $end_date_type = self::get_property( 'end-date', $field, '' ); $date_type = self::get_property( 'field_type', $field, 'picker' ); $disabled_dates = self::get_property( 'disabled-dates', $field, array() ); $disabled_range = self::get_property( 'disable-date-range', $field, array() ); $restrict_type = self::get_property( 'howto-restrict', $field ); if ( $this->is_required( $field ) ) { $required_validation_message = self::get_property( 'required_message', $field, esc_html__( 'This field is required. Please enter a valid date.', 'forminator' ) ); if ( empty( $data ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_field_date_required_field_validation_message', $required_validation_message, $id, $data, $this ); return; } elseif ( 'picker' !== $date_type ) { $month = $data['month']; $day = $data['day']; $year = $data['year']; if ( empty( $month ) ) { $month_id = $id . '-month'; $this->validation_message[ $month_id ] = apply_filters( 'forminator_field_date_required_field_validation_message', esc_html__( 'Month field is required.', 'forminator' ), $month_id, $data, $this ); } if ( empty( $day ) ) { $day_id = $id . '-day'; $this->validation_message[ $day_id ] = apply_filters( 'forminator_field_date_required_field_validation_message', esc_html__( 'Day field is required.', 'forminator' ), $day_id, $data, $this ); } if ( empty( $year ) ) { $year_id = $id . '-year'; $this->validation_message[ $year_id ] = apply_filters( 'forminator_field_date_required_field_validation_message', esc_html__( 'Year field is required.', 'forminator' ), $year_id, $data, $this ); } } } if ( empty( $data ) ) { return; } if ( isset( $data['year'] ) && isset( $data['day'] ) && isset( $data['month'] ) && empty( $data['year'] ) && empty( $data['day'] ) && empty( $data['month'] ) ) { return; } // Always! (we dont have validate flag on builder) validate date_format. $date_format = self::get_property( 'date_format', $field ); $date = self::parse_date( $data, $date_format ); $month = $date['month']; $day = $date['day']; $year = $date['year']; // strtotime does not recognize all of our date formats so we need to convert all dates to 1 accepted format before processing. if ( 'Y-m-d' !== datepicker_default_format( $date_format ) && ! is_array( $data ) ) { $format_date = date_create_from_format( datepicker_default_format( $date_format ), $data ); if ( $format_date ) { $data = date_format( $format_date, 'Y-m-d' ); } else { $this->validation_message[ $id ] = apply_filters( 'forminator_field_date_valid_date_validation_message', esc_html__( 'Please enter a valid date.', 'forminator' ), $id, $data, $date_format, $this ); return; } } if ( 'select' !== $date_type && ! $this->check_date( $date['month'], $date['day'], $date['year'] ) ) { $year_id = $id . '-year'; if ( strlen( $date['year'] ) !== 4 && 'picker' !== $date_type ) { $this->validation_message[ $year_id ] = apply_filters( 'forminator_field_date_valid_year_validation_message', esc_html__( 'Year field is invalid.', 'forminator' ), $year_id, $data, $date_format, $this ); } else { $this->validation_message[ $id ] = apply_filters( 'forminator_field_date_valid_date_validation_message', esc_html__( 'Please enter a valid date.', 'forminator' ), $id, $data, $date_format, $this ); } } else { if ( 'select' === $date_type ) { // For year limits. $min_year = self::get_property( 'min_year', $field, gmdate( 'Y' ) - 100 ); $max_year = self::get_property( 'max_year', $field, gmdate( 'Y' ) + 100 ); $year = intval( $date['year'] ); if ( ! empty( $min_year ) && ! empty( $max_year ) ) { if ( $year < $min_year || $year > $max_year ) { $this->validation_message[ $id ] = apply_filters( 'forminator_field_date_valid_maxmin_year_validation_message', esc_html__( 'Please select a valid year.', 'forminator' ) ); } } else { if ( ! empty( $min_year ) ) { if ( $year < $min_year ) { $this->validation_message[ $id ] = apply_filters( 'forminator_field_date_valid_maxmin_year_validation_message', esc_html__( 'Please select a valid year.', 'forminator' ) ); } } if ( ! empty( $max_year ) ) { if ( $year > $max_year ) { $this->validation_message[ $id ] = apply_filters( 'forminator_field_date_valid_maxmin_year_validation_message', esc_html__( 'Please select a valid year.', 'forminator' ) ); } } } /* * For empty day or month. * We are allowing year to be filled because it defaults to current year. * In front-action.php (get_fields_info), we will remove the date submission data if only year has value coz its the default value. */ if ( ( ! empty( $date['month'] ) || ! empty( $date['day'] ) ) && ! $this->check_date( $date['month'], $date['day'], $date['year'] ) ) { if ( empty( $month ) ) { $month_id = $id . '-month'; $this->validation_message[ $month_id ] = apply_filters( 'forminator_field_date_required_field_validation_message', esc_html__( 'Month field is invalid.', 'forminator' ), $month_id, $data, $this ); } if ( empty( $day ) ) { $day_id = $id . '-day'; $this->validation_message[ $day_id ] = apply_filters( 'forminator_field_date_required_field_validation_message', esc_html__( 'Day field is invalid.', 'forminator' ), $day_id, $data, $this ); } if ( empty( $year ) ) { $year_id = $id . '-year'; $this->validation_message[ $year_id ] = apply_filters( 'forminator_field_date_required_field_validation_message', esc_html__( 'Year field is invalid.', 'forminator' ), $year_id, $data, $this ); } } } if ( 'picker' === $date_type ) { $custom_form = forminator_get_model_from_id( Forminator_Front_Action::$module_id ); $selected_date = preg_replace( '/(\d+)\D+(\d+)\D+(\d+)/', '$1/$2/$3', $data ); if ( 'week' === $restrict_type ) { $restrict = array(); $days = forminator_week_days(); foreach ( $days as $k => $day ) { if ( ! self::get_property( $k, $field ) ) { $restrict[] = $k; } } if ( ! empty( $restrict ) ) { $current_day = gmdate( 'l', strtotime( $selected_date ) ); if ( in_array( strtolower( $current_day ), $restrict, true ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_field_date_valid_between_date_validation_message', self::get_property( 'restrict_message', $field, esc_html__( 'Please select one of the available dates.', 'forminator' ) ) ); } } } if ( ! empty( $start_date_type ) ) { if ( 'specific' === $start_date_type ) { $start_date = self::get_property( 'start-specific-date', $field, '' ); } else { $start_offset_operator = self::get_property( 'start-offset-operator', $field, '+' ); $start_offset_value = self::get_property( 'start-offset-value', $field, '0' ); $start_offset_duration = self::get_property( 'start-offset-duration', $field, 'days' ); if ( 'today' === $start_date_type ) { $start_date = date_i18n( 'Y-m-d', strtotime( $start_offset_operator . $start_offset_value . ' ' . $start_offset_duration, current_time( 'U' ) ) ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested -- We are using the current timestamp based on the site's timezone. } else { $start_date_value = isset( Forminator_CForm_Front_Action::$prepared_data[ $start_date_type ] ) ? Forminator_CForm_Front_Action::$prepared_data[ $start_date_type ] : ''; $start_date = ''; if ( ! empty( $start_date_value ) ) { $start_date_field = $custom_form->get_field( $start_date_type, true ); $start_date_format = self::get_property( 'date_format', $start_date_field ); $start_date_format = date_create_from_format( datepicker_default_format( $start_date_format ), $start_date_value ); $start_date_value = date_format( $start_date_format, 'Y-m-d' ); $start_date = date_i18n( 'Y-m-d', strtotime( $start_date_value . ' ' . $start_offset_operator . $start_offset_value . ' ' . $start_offset_duration ) ); } } } if ( ! empty( $start_date ) && strtotime( $selected_date ) < strtotime( $start_date ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_field_date_valid_between_date_validation_message', self::get_property( 'restrict_message', $field, esc_html__( 'Please select one of the available dates.', 'forminator' ) ) ); } } if ( ! empty( $end_date_type ) ) { if ( 'specific' === $end_date_type ) { $end_date = self::get_property( 'end-specific-date', $field, '' ); } else { $end_offset_operator = self::get_property( 'end-offset-operator', $field, '+' ); $end_offset_value = self::get_property( 'end-offset-value', $field, '0' ); $end_offset_duration = self::get_property( 'end-offset-duration', $field, 'days' ); if ( 'today' === $end_date_type ) { $end_date = date_i18n( 'Y-m-d', strtotime( $end_offset_operator . $end_offset_value . ' ' . $end_offset_duration, current_time( 'U' ) ) ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested -- We are using the current timestamp based on the site's timezone. } else { $end_date_value = isset( Forminator_CForm_Front_Action::$prepared_data[ $end_date_type ] ) ? Forminator_CForm_Front_Action::$prepared_data[ $end_date_type ] : ''; $end_date = ''; if ( ! empty( $end_date_value ) ) { $end_date_field = $custom_form->get_field( $end_date_type, true ); $end_date_format = self::get_property( 'date_format', $end_date_field ); $end_date_format = date_create_from_format( datepicker_default_format( $end_date_format ), $end_date_value ); $end_date_value = date_format( $end_date_format, 'Y-m-d' ); $end_date = date_i18n( 'Y-m-d', strtotime( $end_date_value . ' ' . $end_offset_operator . $end_offset_value . ' ' . $end_offset_duration ) ); } } } if ( ! empty( $end_date ) && strtotime( $selected_date ) > strtotime( $end_date ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_field_date_valid_between_date_validation_message', self::get_property( 'restrict_message', $field, esc_html__( 'Please select one of the available dates.', 'forminator' ) ) ); } } // Change selected date format to the disabled-date format which is m/d/Y. $selected_date_format = date_create_from_format( 'Y/m/d', $selected_date ); $formatted_selected_date = date_format( $selected_date_format, 'm/d/Y' ); if ( ! empty( $disabled_dates ) && in_array( $formatted_selected_date, $disabled_dates, true ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_field_date_valid_disabled_validation_message', self::get_property( 'restrict_message', $field, esc_html__( 'Please select one of the available dates.', 'forminator' ) ) ); } if ( ! empty( $disabled_range ) ) { $has_range = true; foreach ( $disabled_range as $range ) { $range_arr = array_map( 'trim', explode( '-', $range ) ); if ( ! empty( $range_arr ) ) { $start_date = isset( $range_arr[0] ) ? $range_arr[0] : ''; $end_date = isset( $range_arr[1] ) ? $range_arr[1] : ''; if ( strtotime( $selected_date ) >= strtotime( $start_date ) && strtotime( $selected_date ) <= strtotime( $end_date ) ) { $has_range = false; continue; } } } if ( ! $has_range ) { $this->validation_message[ $id ] = apply_filters( 'forminator_field_date_valid_disabled_validation_message', self::get_property( 'restrict_message', $field, esc_html__( 'Please select one of the available dates.', 'forminator' ) ) ); } } } } } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. if ( is_array( $data ) ) { $data = forminator_sanitize_array_field( $data ); } else { $data = forminator_sanitize_field( $data ); } return apply_filters( 'forminator_field_date_sanitize', $data, $field, $original_data ); } /** * Convert condition date to timestamp * * @param string $conditions_date Date from conditions. * @return string|false Timestamp */ public static function prepare_condition_date( $conditions_date ) { if ( is_numeric( $conditions_date ) ) { // Timestamp is in milliseconds. $compare_to = $conditions_date / 1000; } else { // Backward compatibility. $compare_to = strtotime( $conditions_date ); } return $compare_to; } } PK w~\��+0AY AY name.phpnu �[��� <?php /** * The Forminator_Name class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Name * * @since 1.0 */ class Forminator_Name extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'name'; /** * Type * * @var string */ public $type = 'name'; /** * Position * * @var int */ public $position = 1; /** * Options * * @var array */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon-profile-male'; /** * Forminator_Name constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Name', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'field_label' => esc_html__( 'Name', 'forminator' ), 'prefix_label' => esc_html__( 'Prefix', 'forminator' ), 'fname_label' => esc_html__( 'First Name', 'forminator' ), 'mname_label' => esc_html__( 'Middle Name', 'forminator' ), 'lname_label' => esc_html__( 'Last Name', 'forminator' ), 'prefix' => 'true', 'fname' => 'true', 'mname' => 'true', 'lname' => 'true', 'required_message' => esc_html__( 'Name is required.', 'forminator' ), 'prefix_required_message' => esc_html__( 'Prefix is required.', 'forminator' ), 'fname_required_message' => esc_html__( 'First Name is required.', 'forminator' ), 'mname_required_message' => esc_html__( 'Middle Name is required.', 'forminator' ), 'lname_required_message' => esc_html__( 'Last Name is required.', 'forminator' ), 'layout_columns' => '2', ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { // single name. $name_providers = apply_filters( 'forminator_field_' . $this->slug . '_autofill', array(), $this->slug ); // multi name. $prefix_providers = apply_filters( 'forminator_field_' . $this->slug . '_prefix_autofill', array(), $this->slug . '_prefix' ); $fname_providers = apply_filters( 'forminator_field_' . $this->slug . '_first_name_autofill', array(), $this->slug . '_first_name' ); $mname_providers = apply_filters( 'forminator_field_' . $this->slug . '_middle_name_autofill', array(), $this->slug . '_middle_name' ); $lname_providers = apply_filters( 'forminator_field_' . $this->slug . '_last_name_autofill', array(), $this->slug . '_last_name' ); $autofill_settings = array( 'name' => array( 'values' => forminator_build_autofill_providers( $name_providers ), ), 'name-prefix' => array( 'values' => forminator_build_autofill_providers( $prefix_providers ), ), 'name-first-name' => array( 'values' => forminator_build_autofill_providers( $fname_providers ), ), 'name-middle-name' => array( 'values' => forminator_build_autofill_providers( $mname_providers ), ), 'name-last-name' => array( 'values' => forminator_build_autofill_providers( $lname_providers ), ), ); return $autofill_settings; } /** * Return simple field markup * * @since 1.0 * * @param array $field Field. * @param string $design Design. * @param array $draft_value Draft value. * * @return string */ public function get_simple( $field, $design, $draft_value = null ) { $html = ''; $name = self::get_property( 'element_id', $field ); $id = self::get_field_id( $name ); $required = self::get_property( 'required', $field, false ); $ariareq = 'false'; $label = esc_html( self::get_property( 'field_label', $field, '' ) ); $description = self::get_property( 'description', $field, '' ); $placeholder = $this->sanitize_value( self::get_property( 'placeholder', $field ) ); $descr_position = self::get_property( 'descr_position', $field ); if ( (bool) $required ) { $ariareq = 'true'; } $value = ''; if ( isset( $draft_value['value'] ) ) { $value = esc_attr( $draft_value['value'] ); } elseif ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $value = $this->get_prefill( $field, $value ); } $name_attr = array( 'type' => 'text', 'name' => $name, 'value' => $value, 'placeholder' => $placeholder, 'id' => $id, 'class' => 'forminator-input forminator-name--field', 'aria-required' => $ariareq, ); $autofill_markup = $this->get_element_autofill_markup_attr( $name ); $name_attr = array_merge( $name_attr, $autofill_markup ); $html .= '<div class="forminator-field">'; $html .= self::create_input( $name_attr, $label, $description, $required, $descr_position ); $html .= '</div>'; return $html; } /** * Return multi field first row markup * * @since 1.0 * * @param array $field Field. * @param string $design Design. * @param array $draft_value Draft value. * * @return string */ public function get_multi_first_row( $field, $design, $draft_value = null ) { $html = ''; $cols = 12; $id = self::get_property( 'element_id', $field ); $name = $id; $required = self::get_property( 'required', $field, false ); $prefix = self::get_property( 'prefix', $field, false ); $fname = self::get_property( 'fname', $field, false ); $mname = self::get_property( 'mname', $field, false ); $lname = self::get_property( 'lname', $field, false ); $columns = self::get_property( 'layout_columns', $field, false ); $draft_value = isset( $draft_value['value'] ) ? $draft_value['value'] : ''; $descr_position = self::get_property( 'descr_position', $field ); // Return If prefix and first name, middle name and last name is not enabled. if ( empty( $prefix ) && empty( $fname ) && empty( $mname ) && empty( $lname ) ) { return ''; } /** * Backward compat, we dont have separate required configuration per fields * Fallback value from global `required` * * @since 1.6 */ $prefix_required = self::get_property( 'prefix_required', $field, false, 'bool' ); $fname_required = self::get_property( 'fname_required', $field, false, 'bool' ); $fname_ariareq = 'false'; $mname_required = self::get_property( 'mname_required', $field, false, 'bool' ); $mname_ariareq = 'false'; $lname_required = self::get_property( 'lname_required', $field, false, 'bool' ); $lname_ariareq = 'false'; if ( (bool) self::get_property( 'fname_required', $field, false ) ) { $fname_ariareq = 'true'; } if ( (bool) self::get_property( 'mname_required', $field, false ) ) { $mname_ariareq = 'true'; } if ( (bool) self::get_property( 'lname_required', $field, false ) ) { $lname_ariareq = 'true'; } // Columns in name field. switch ( $columns ) { case 1: $cols = 12; break; case 3: $cols = 4; break; case 4: $cols = 3; break; default: $cols = 6; } if ( 'default' === self::get_property( 'default_layout', $field, false ) ) { $cols = 6; } // START: Row. $html .= '<div class="forminator-row forminator-no-margin" data-multiple="true">'; // FIELD: Prefix. if ( $prefix ) { $prefix_data = array( 'name' => self::get_subfield_id( $id, '-prefix' ), 'id' => self::get_field_id( $this->form_settings['form_id'] . '__field--' . $id ), 'class' => 'basic' === $design ? '' : 'forminator-select2', 'data-multi' => true, ); $options = array(); $value = false; $prefix_options = forminator_get_name_prefixes(); if ( isset( $draft_value['prefix'] ) ) { $value = esc_attr( $draft_value['prefix'] ); } elseif ( $this->has_prefill( $field, 'prefix' ) ) { // We have pre-fill parameter, use its value or $value. $value = $this->get_prefill( $field, false, 'prefix' ); } foreach ( $prefix_options as $key => $pfx ) { $selected = false; if ( strtolower( $key ) === strtolower( $value ) ) { $selected = true; } $options[] = array( 'value' => esc_html( $key ), 'label' => esc_html( $pfx ), 'selected' => $selected, ); } $html .= sprintf( '<div class="forminator-col forminator-col-md-%s">', $cols ); $html .= '<div class="forminator-field">'; $html .= self::create_select( $prefix_data, self::get_property( 'prefix_label', $field ), $options, self::get_property( 'prefix_placeholder', $field ), self::get_property( 'prefix_description', $field ), $prefix_required, $descr_position, ); $html .= '</div>'; $html .= '</div>'; } // FIELD: First Name. if ( $fname ) { $first_name = array( 'type' => 'text', 'name' => self::get_subfield_id( $id, '-first-name' ), 'placeholder' => $this->sanitize_value( self::get_property( 'fname_placeholder', $field ) ), 'id' => self::get_field_id( 'first-' . $id ), 'class' => 'forminator-input', 'aria-required' => $fname_ariareq, 'data-multi' => true, ); $autofill_markup = $this->get_element_autofill_markup_attr( self::get_subfield_id( $id, '-first-name' ) ); $first_name = array_merge( $first_name, $autofill_markup ); if ( isset( $draft_value['first-name'] ) ) { $first_name['value'] = $draft_value['first-name']; } elseif ( $this->has_prefill( $field, 'fname' ) ) { $first_name = $this->replace_from_prefill( $field, $first_name, 'fname' ); } $html .= sprintf( '<div class="forminator-col forminator-col-md-%s">', $cols ); $html .= '<div class="forminator-field">'; $html .= self::create_input( $first_name, esc_html( self::get_property( 'fname_label', $field ) ), esc_html( self::get_property( 'fname_description', $field ) ), $fname_required, $descr_position, ); $html .= '</div>'; $html .= '</div>'; } // FIELD: Middle Name. if ( $mname ) { $middle_name = array( 'type' => 'text', 'name' => self::get_subfield_id( $id, '-middle-name' ), 'placeholder' => $this->sanitize_value( self::get_property( 'mname_placeholder', $field ) ), 'id' => self::get_field_id( 'middle-' . $id ), 'class' => 'forminator-input', 'aria-required' => $mname_ariareq, 'data-multi' => true, ); if ( isset( $draft_value['middle-name'] ) ) { $middle_name['value'] = $draft_value['middle-name']; } elseif ( $this->has_prefill( $field, 'mname' ) ) { $middle_name = $this->replace_from_prefill( $field, $middle_name, 'mname' ); } $html .= sprintf( '<div class="forminator-col forminator-col-md-%s">', $cols ); $html .= '<div class="forminator-field">'; $html .= self::create_input( $middle_name, esc_html( self::get_property( 'mname_label', $field ) ), esc_html( self::get_property( 'mname_description', $field ) ), $mname_required, $descr_position, ); $html .= '</div>'; $html .= '</div>'; } // FIELD: Last Name. if ( $lname ) { $last_name = array( 'type' => 'text', 'name' => self::get_subfield_id( $id, '-last-name' ), 'placeholder' => $this->sanitize_value( self::get_property( 'lname_placeholder', $field ) ), 'id' => self::get_field_id( 'last-' . $id ), 'class' => 'forminator-input', 'aria-required' => $lname_ariareq, 'data-multi' => true, ); $autofill_markup = $this->get_element_autofill_markup_attr( self::get_subfield_id( $id, '-last-name' ) ); $last_name = array_merge( $last_name, $autofill_markup ); if ( isset( $draft_value['last-name'] ) ) { $last_name['value'] = $draft_value['last-name']; } elseif ( $this->has_prefill( $field, 'lname' ) ) { $last_name = $this->replace_from_prefill( $field, $last_name, 'lname' ); } $html .= sprintf( '<div class="forminator-col forminator-col-md-%s">', $cols ); $html .= '<div class="forminator-field">'; $html .= self::create_input( $last_name, esc_html( self::get_property( 'lname_label', $field ) ), esc_html( self::get_property( 'lname_description', $field ) ), $lname_required, $descr_position, ); $html .= '</div>'; $html .= '</div>'; } // END: Row. $html .= '</div>'; return $html; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $this->form_settings = $settings; $field['descr_position'] = self::get_description_position( $field, $settings ); $multiple = self::get_property( 'multiple_name', $field, false, 'bool' ); $design = $this->get_form_style( $settings ); // Check we use multi fields. if ( ! $multiple ) { // Only one field. $html = $this->get_simple( $field, $design, $draft_value ); } else { // Multiple fields. $html = $this->get_multi_first_row( $field, $design, $draft_value ); } return apply_filters( 'forminator_field_name_markup', $html, $field ); } /** * Return field inline validation rules * * @since 1.0 * @return string */ public function get_validation_rules() { $rules = ''; $field = $this->field; $id = self::get_property( 'element_id', $field ); $multiple = self::get_property( 'multiple_name', $field, false, 'bool' ); $required = $this->is_required( $field ); if ( $multiple ) { $prefix = self::get_property( 'prefix', $field, false, 'bool' ); $fname = self::get_property( 'fname', $field, false, 'bool' ); $mname = self::get_property( 'mname', $field, false, 'bool' ); $lname = self::get_property( 'lname', $field, false, 'bool' ); $prefix_required = self::get_property( 'prefix_required', $field, false, 'bool' ); $fname_required = self::get_property( 'fname_required', $field, false, 'bool' ); $mname_required = self::get_property( 'mname_required', $field, false, 'bool' ); $lname_required = self::get_property( 'lname_required', $field, false, 'bool' ); if ( $prefix ) { if ( $prefix_required ) { $rules .= '"' . $this->get_id( $field ) . '-prefix": "trim",'; $rules .= '"' . $this->get_id( $field ) . '-prefix": "required",'; } } if ( $fname ) { if ( $fname_required ) { $rules .= '"' . $this->get_id( $field ) . '-first-name": "trim",'; $rules .= '"' . $this->get_id( $field ) . '-first-name": "required",'; } } if ( $mname ) { if ( $mname_required ) { $rules .= '"' . $this->get_id( $field ) . '-middle-name": "trim",'; $rules .= '"' . $this->get_id( $field ) . '-middle-name": "required",'; } } if ( $lname ) { if ( $lname_required ) { $rules .= '"' . $this->get_id( $field ) . '-last-name": "trim",'; $rules .= '"' . $this->get_id( $field ) . '-last-name": "required",'; } } } elseif ( $required ) { $rules .= '"' . $this->get_id( $field ) . '": "required",'; $rules .= '"' . $this->get_id( $field ) . '": "trim",'; } return apply_filters( 'forminator_field_name_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @return string */ public function get_validation_messages() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $multiple = self::get_property( 'multiple_name', $field, false, 'bool' ); $messages = ''; $required = $this->is_required( $field ); if ( $multiple ) { $prefix = self::get_property( 'prefix', $field, false, 'bool' ); $fname = self::get_property( 'fname', $field, false, 'bool' ); $mname = self::get_property( 'mname', $field, false, 'bool' ); $lname = self::get_property( 'lname', $field, false, 'bool' ); $prefix_required = self::get_property( 'prefix_required', $field, false, 'bool' ); $fname_required = self::get_property( 'fname_required', $field, false, 'bool' ); $mname_required = self::get_property( 'mname_required', $field, false, 'bool' ); $lname_required = self::get_property( 'lname_required', $field, false, 'bool' ); if ( $prefix && $prefix_required ) { $required_message = $this->get_field_multiple_required_message( $id, $field, 'prefix_required_message', 'prefix', esc_html__( 'Prefix is required.', 'forminator' ) ); $messages .= '"' . $this->get_id( $field ) . '-prefix": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } if ( $fname && $fname_required ) { $required_message = $this->get_field_multiple_required_message( $id, $field, 'fname_required_message', 'first', esc_html__( 'This field is required. Please input your first name.', 'forminator' ) ); $messages .= '"' . $this->get_id( $field ) . '-first-name": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } if ( $mname && $mname_required ) { $required_message = $this->get_field_multiple_required_message( $id, $field, 'mname_required_message', 'middle', esc_html__( 'This field is required. Please input your middle name.', 'forminator' ) ); $messages .= '"' . $this->get_id( $field ) . '-middle-name": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } if ( $lname && $lname_required ) { $required_message = $this->get_field_multiple_required_message( $id, $field, 'lname_required_message', 'last', esc_html__( 'This field is required. Please input your last name.', 'forminator' ) ); $messages .= '"' . $this->get_id( $field ) . '-last-name": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } } elseif ( $required ) { // backward compat. $required_message = self::get_property( 'required_message', $field, self::FIELD_PROPERTY_VALUE_NOT_EXIST, 'string' ); if ( self::FIELD_PROPERTY_VALUE_NOT_EXIST === $required_message || empty( $required_message ) ) { $required_message = esc_html__( 'This field is required. Please input your name.', 'forminator' ); } $required_message = apply_filters( 'forminator_name_field_required_validation_message', $required_message, $id, $field ); $messages .= '"' . $this->get_id( $field ) . '": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } return $messages; } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); $is_multiple = self::get_property( 'multiple_name', $field, false, 'bool' ); $required = $this->is_required( $field ); if ( $is_multiple ) { $prefix = self::get_property( 'prefix', $field, false, 'bool' ); $fname = self::get_property( 'fname', $field, false, 'bool' ); $mname = self::get_property( 'mname', $field, false, 'bool' ); $lname = self::get_property( 'lname', $field, false, 'bool' ); $prefix_required = self::get_property( 'prefix_required', $field, false, 'bool' ); $fname_required = self::get_property( 'fname_required', $field, false, 'bool' ); $mname_required = self::get_property( 'mname_required', $field, false, 'bool' ); $lname_required = self::get_property( 'lname_required', $field, false, 'bool' ); $prefix_data = isset( $data['prefix'] ) ? $data['prefix'] : ''; $fname_data = isset( $data['first-name'] ) ? $data['first-name'] : ''; $mname_data = isset( $data['middle-name'] ) ? $data['middle-name'] : ''; $lname_data = isset( $data['last-name'] ) ? $data['last-name'] : ''; if ( is_array( $data ) ) { if ( $prefix && $prefix_required && empty( $prefix_data ) ) { $this->validation_message[ $id . '-prefix' ] = $this->get_field_multiple_required_message( $id, $field, 'prefix_required_message', 'prefix', esc_html__( 'Prefix is required.', 'forminator' ) ); } if ( $fname && $fname_required && empty( $fname_data ) ) { $this->validation_message[ $id . '-first-name' ] = $this->get_field_multiple_required_message( $id, $field, 'fname_required_message', 'first', esc_html__( 'This field is required. Please input your first name.', 'forminator' ) ); } if ( $mname && $mname_required && empty( $mname_data ) ) { $this->validation_message[ $id . '-middle-name' ] = $this->get_field_multiple_required_message( $id, $field, 'mname_required_message', 'middle', esc_html__( 'This field is required. Please input your middle name.', 'forminator' ) ); } if ( $lname && $lname_required && empty( $lname_data ) ) { $this->validation_message[ $id . '-last-name' ] = $this->get_field_multiple_required_message( $id, $field, 'lname_required_message', 'last', esc_html__( 'This field is required. Please input your last name.', 'forminator' ) ); } } } elseif ( $required ) { if ( empty( $data ) ) { // backward compat. $required_message = self::get_property( 'required_message', $field, self::FIELD_PROPERTY_VALUE_NOT_EXIST, 'string' ); if ( self::FIELD_PROPERTY_VALUE_NOT_EXIST === $required_message ) { $required_message = esc_html__( 'This field is required. Please input your name.', 'forminator' ); } $required_message = apply_filters( 'forminator_name_field_required_validation_message', $required_message, $id, $field ); $this->validation_message[ $id ] = $required_message; } } } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; if ( is_array( $data ) ) { $data = forminator_sanitize_array_field( $data ); } else { $data = forminator_sanitize_field( $data ); } return apply_filters( 'forminator_field_name_sanitize', $data, $field, $original_data ); } } PK w~\��0b� � consent.phpnu �[��� <?php /** * The Forminator_Consent class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Consent * * @since 1.0.5 */ class Forminator_Consent extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'consent'; /** * Type * * @var string */ public $type = 'consent'; /** * Position * * @var int */ public $position = 21; /** * Options * * @var array */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon-gdpr'; /** * Forminator_Consent constructor. * * @since 1.0.5 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Consent', 'forminator' ); } /** * Field defaults * * @since 1.0.5 * @return array */ public function defaults() { $privacy_url = get_privacy_policy_url(); $privacy_url = ! empty( $privacy_url ) ? $privacy_url : '#'; return array( 'required' => 'true', 'field_label' => 'Consent', 'consent_description' => sprintf( /* Translators: 1. Opening <a> tag with link to the privacy url, 2. closing <a> tag 3. Opening <a> tag with # href, 4. closing <a> tag. */ esc_html__( 'Yes, I agree with the %1$sprivacy policy%2$s and %3$sterms and conditions%4$s.', 'forminator' ), '<a href="' . esc_url( $privacy_url ) . '" target="_blank">', '</a>', '<a href="#" target="_blank">', '</a>' ), 'required_message' => esc_html__( 'This field is required. Please check it.', 'forminator' ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { // Unsupported Autofill. $autofill_settings = array(); return $autofill_settings; } /** * Field front-end markup * * @since 1.0.5 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $settings = $views_obj->model->settings; $this->field = $field; $html = ''; $id = self::get_property( 'element_id', $field ); $name = $id; $form_id = isset( $settings['form_id'] ) ? $settings['form_id'] : false; $description = wp_kses_post( forminator_replace_variables( self::get_property( 'consent_description', $field ), $form_id ) ); $id = self::get_field_id( $id ); $label = esc_html( self::get_property( 'field_label', $field ) ); $required = self::get_property( 'required', $field, true ); $ariareq = $required ? 'true' : 'false'; $html .= '<div class="forminator-field">'; $html .= self::get_field_label( $label, $id, $required ); $html .= '<div class="forminator-checkbox__wrapper">'; $html .= sprintf( '<label id="%s__label" class="forminator-checkbox forminator-consent" aria-labelledby="%s" aria-hidden="true">', $id, $id . '-label' ); $html .= sprintf( '<input type="checkbox" name="%1$s" id="%2$s" value="%3$s" aria-labelledby="%4$s"%5$s data-required="%6$s" aria-required="%7$s" />', $name, $id, 'checked', $id . '-label', ( ! empty( $description ) ? ' aria-describedby="' . esc_attr( $id . '__description' ) . '"' : '' ), $ariareq, $ariareq ); $html .= '<span class="forminator-checkbox-box" aria-hidden="true"></span>'; $html .= '</label>'; $html .= sprintf( '<div id="%s__description" class="forminator-checkbox__label forminator-consent__label">%s</div>', $id, $description ); $html .= '</div>'; $html .= '</div>'; return apply_filters( 'forminator_field_consent_markup', $html, $id, $description ); } /** * Return field inline validation rules * * @since 1.0.5 * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); $rules = $is_required ? '"' . $this->get_id( $field ) . '":{"required":true},' : ''; return apply_filters( 'forminator_field_consent_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0.5 * @return string */ public function get_validation_messages() { $field = $this->field; $id = $this->get_id( $field ); $is_required = $this->is_required( $field ); $required_message = self::get_property( 'required_message', $field, '' ); $required_message = apply_filters( 'forminator_consent_field_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please check it.', 'forminator' ) ), $id, $field ); $messages = $is_required ? '"' . $this->get_id( $field ) . '": {"required":"' . forminator_addcslashes( $required_message ) . '"},' . "\n" : ''; return $messages; } /** * Field back-end validation * * @since 1.15.3 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { // value of consent checkbox is `string` *checked*. $id = $this->get_id( $field ); if ( $this->is_required( $field ) && ( empty( $data ) || 'checked' !== $data ) ) { $required_message = self::get_property( 'required_message', $field, '' ); $this->validation_message[ $id ] = apply_filters( 'forminator_consent_field_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please check it.', 'forminator' ) ), $id, $field ); } } /** * Sanitize data * * @since 1.0.5 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. $data = forminator_sanitize_field( $data ); return apply_filters( 'forminator_field_consent_sanitize', $data, $field, $original_data ); } } PK w~\�{T�� � page-break.phpnu �[��� <?php /** * The Forminator_Page_Break class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_PageBreak * * @since 1.0 */ class Forminator_Page_Break extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'page-break'; /** * Type * * @var string */ public $type = 'page-break'; /** * Position * * @var int */ public $position = 18; /** * Options * * @var array */ public $options = array(); /** * Hide advanced * * @var string */ public $hide_advanced = 'true'; /** * Icon * * @var string */ public $icon = 'sui-icon forminator-icon-pagination'; /** * Forminator_Pagination constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Page Break', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return apply_filters( 'forminator_page_break_btn_label', array( 'btn_left' => esc_html__( '« Previous Step', 'forminator' ), 'btn_right' => esc_html__( 'Next Step »', 'forminator' ), ) ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { // Unsupported Autofill. $autofill_settings = array(); return $autofill_settings; } } PK x~\b�W(�4 �4 number.phpnu �[��� <?php /** * The Forminator_Number class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Number * * @since 1.0 */ class Forminator_Number extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'number'; /** * Type * * @var string */ public $type = 'number'; /** * Position * * @var int */ public $position = 8; /** * Options * * @var array */ public $options = array(); /** * Is input * * @var bool */ public $is_input = true; /** * Icon * * @var string */ public $icon = 'sui-icon-element-number'; /** * Is calculable * * @var bool */ public $is_calculable = true; /** * Forminator_Number constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Number', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return apply_filters( 'forminator_number_defaults_settings', array( 'calculations' => 'true', 'limit_min' => 1, 'limit_max' => 150, 'field_label' => esc_html__( 'Number', 'forminator' ), ) ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $providers = apply_filters( 'forminator_field_' . $this->slug . '_autofill', array(), $this->slug ); $autofill_settings = array( 'number' => array( 'values' => forminator_build_autofill_providers( $providers ), ), ); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $this->form_settings = $settings; $hidden_behavior = self::get_property( 'hidden_behavior', $field ); $descr_position = self::get_description_position( $field, $settings ); $html = ''; $min = 0; $max = ''; $id = self::get_property( 'element_id', $field ); $name = $id; $id = self::get_field_id( $id ); $required = self::get_property( 'required', $field, false ); $ariareq = 'false'; $placeholder = $this->sanitize_value( self::get_property( 'placeholder', $field ) ); $value = esc_html( self::get_post_data( $name, self::get_property( 'default_value', $field ) ) ); $label = esc_html( self::get_property( 'field_label', $field, '' ) ); $description = self::get_property( 'description', $field, '' ); // wp_kses_data already applied in get_description. $min = esc_html( self::get_property( 'limit_min', $field, false ) ); $max = esc_html( self::get_property( 'limit_max', $field, false ) ); $precision = self::get_calculable_precision( $field ); $separator = self::get_property( 'separators', $field, 'blank' ); $separators = $this->forminator_separators( $separator, $field ); if ( (bool) $required ) { $ariareq = 'true'; } if ( isset( $draft_value['value'] ) ) { $value = esc_attr( $draft_value['value'] ); } elseif ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $value = $this->get_prefill( $field, $value ); } if ( 'comma_dot' === $separator && false !== strpos( $value, ',' ) ) { $value = str_replace( ',', '', $value ); } $point = ! empty( $precision ) ? $separators['point'] : ''; $number_attr = array( 'name' => $name, 'value' => $value, 'placeholder' => $placeholder, 'id' => $id, 'class' => 'forminator-input forminator-number--field', 'inputmode' => 'decimal', 'data-required' => $required, 'data-decimals' => $precision, 'aria-required' => $ariareq, 'data-inputmask' => "'groupSeparator': '" . $separators['separator'] . "', 'radixPoint': '" . $point . "', 'digits': '" . $precision . "'", ); if ( $hidden_behavior && 'zero' === $hidden_behavior ) { $number_attr['data-hidden-behavior'] = $hidden_behavior; } if ( 'blank' === $separator ) { $number_attr['type'] = 'number'; $number_attr['step'] = 'any'; if ( false !== $min ) { $number_attr['min'] = $min; } if ( $max ) { $number_attr['max'] = $max; } } $autofill_markup = $this->get_element_autofill_markup_attr( self::get_property( 'element_id', $field ) ); $number_attr = array_merge( $number_attr, $autofill_markup ); $html .= '<div class="forminator-field">'; $html .= self::create_input( $number_attr, $label, $description, $required, $descr_position, ); $html .= '</div>'; return apply_filters( 'forminator_field_number_markup', $html, $id, $required, $placeholder, $value ); } /** * Return field inline validation rules * * @since 1.0 * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $min = self::get_property( 'limit_min', $field, false ); $max = self::get_property( 'limit_max', $field, false ); $rules = '"' . $this->get_id( $field ) . '": {'; if ( $this->is_required( $field ) ) { $rules .= '"required": true,'; } if ( false !== $min && is_numeric( $min ) ) { $rules .= '"minNumber": ' . (float) $min . ','; } if ( false !== $max && is_numeric( $max ) ) { $rules .= '"maxNumber": ' . (float) $max . ','; } $rules .= '},'; return apply_filters( 'forminator_field_number_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @return string */ public function get_validation_messages() { $field = $this->field; $min = self::get_property( 'limit_min', $field, null ); $max = self::get_property( 'limit_max', $field, null ); $custom_message = self::get_property( 'limit_message', $field, false, 'bool' ); $separator = self::get_property( 'separators', $field, 'blank' ); $messages = '"' . $this->get_id( $field ) . '": {' . "\n"; if ( $this->is_required( $field ) ) { $required_validation_message = self::get_property( 'required_message', $field ); if ( empty( $required_validation_message ) ) { $required_validation_message = esc_html__( 'This field is required. Please enter number.', 'forminator' ); } $required_validation_message = apply_filters( 'forminator_field_number_required_validation_message', $required_validation_message, $field ); $messages .= '"required": "' . forminator_addcslashes( $required_validation_message ) . '",' . "\n"; } $number_validation_message = apply_filters( 'forminator_field_number_number_validation_message', esc_html__( 'This is not valid number.', 'forminator' ), $field ); $messages .= '"number": "' . forminator_addcslashes( $number_validation_message ) . '",' . "\n"; if ( ! is_null( $min ) ) { $min_validation_message = self::get_property( 'limit_min_message', $field ); $min_validation_message = apply_filters( 'forminator_field_number_min_validation_message', $custom_message && $min_validation_message ? $min_validation_message : esc_html__( 'Please enter a value greater than or equal to {0}.', 'forminator' ), $field ); $validator = 'minNumber'; if ( 'blank' === $separator ) { $validator = 'min'; } $messages .= '"' . $validator . '": "' . forminator_addcslashes( $min_validation_message ) . '",' . "\n"; } if ( ! is_null( $max ) ) { $max_validation_message = self::get_property( 'limit_max_message', $field ); $max_validation_message = apply_filters( 'forminator_field_number_max_validation_message', $custom_message && $max_validation_message ? $max_validation_message : esc_html__( 'Please enter a value less than or equal to {0}.', 'forminator' ), $field ); $validator = 'maxNumber'; if ( 'blank' === $separator ) { $validator = 'max'; } $messages .= '"' . $validator . '": "' . forminator_addcslashes( $max_validation_message ) . '",' . "\n"; } $messages .= '},' . "\n"; return apply_filters( 'forminator_field_number_validation_message', $messages, $field ); } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); $max = self::get_property( 'limit_max', $field, $data ); $min = self::get_property( 'limit_min', $field, $data ); $custom_message = self::get_property( 'limit_message', $field, false, 'bool' ); $precision = self::get_calculable_precision( $field ); $separator = self::get_property( 'separators', $field, 'blank' ); $max = trim( $max ); $min = trim( $min ); $max_len = strlen( $max ); $min_len = strlen( $min ); if ( $this->is_required( $field ) ) { if ( empty( $data ) && '0' !== $data ) { $require_message = self::get_property( 'required_message', $field, '' ); $required_validation_message = ! empty( $require_message ) ? $require_message : esc_html__( 'This field is required. Please enter number.', 'forminator' ); $this->validation_message[ $id ] = apply_filters( 'forminator_field_number_required_field_validation_message', $required_validation_message, $id, $field, $data, $this ); } } elseif ( ! empty( $data ) ) { $separators = $this->forminator_separators( $separator, $field ); $point = ! empty( $precision ) ? $separators['point'] : ''; $data = str_replace( array( $separators['separator'], $point ), array( '', '.' ), $data ); $data = floatval( $data ); $min = floatval( $min ); $max = floatval( $max ); // Note : do not compare max or min if that settings field is blank string ( not zero ). if ( 0 !== $min_len && $data < $min ) { $min_validation_message = self::get_property( 'limit_min_message', $field ); $min_validation_message = $custom_message && $min_validation_message ? $min_validation_message : /* translators: 1: Minimum value, 2: Maximum value */ sprintf( esc_html__( 'The number should be less than %1$d and greater than %2$d.', 'forminator' ), $min, $max ); $this->validation_message[ $id ] = sprintf( apply_filters( 'forminator_field_number_max_min_validation_message', /* translators: ... */ $min_validation_message, $id, $field, $data ), $max, $min ); } elseif ( 0 !== $max_len && $data > $max ) { $max_validation_message = self::get_property( 'limit_max_message', $field ); $max_validation_message = $custom_message && $max_validation_message ? $max_validation_message : /* translators: 1: Minimum value, 2: Maximum value */ sprintf( esc_html__( 'The number should be less than %1$d and greater than %2$d.', 'forminator' ), $min, $max ); $this->validation_message[ $id ] = sprintf( apply_filters( 'forminator_field_number_max_min_validation_message', /* translators: ... */ $max_validation_message, $id, $field, $data ), $max, $min ); } } } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. $data = forminator_sanitize_field( $data ); return apply_filters( 'forminator_field_number_sanitize', $data, $field, $original_data ); } /** * Internal calculable value * * @since 1.7 * * @param array|mixed $submitted_field Submitted field. * @param array $field_settings Field settings. * * @return float */ private static function calculable_value( $submitted_field, $field_settings ) { $enabled = self::get_property( 'calculations', $field_settings, false, 'bool' ); if ( ! $enabled ) { return self::FIELD_NOT_CALCULABLE; } return floatval( $submitted_field ); } /** * Get calculable value * * @since 1.7 * @inheritdoc * @param array $submitted_field_data Submitted field data. * @param array $field_settings Field settings. */ public static function get_calculable_value( $submitted_field_data, $field_settings ) { $formatting_value = self::forminator_replace_number( $field_settings, $submitted_field_data ); $calculable_value = self::calculable_value( $formatting_value, $field_settings ); /** * Filter formula being used on calculable value on number field * * @since 1.7 * * @param float $calculable_value * @param array $submitted_field_data * @param array $field_settings * * @return string|int|float */ $calculable_value = apply_filters( 'forminator_field_number_calculable_value', $calculable_value, $submitted_field_data, $field_settings ); return $calculable_value; } } PK x~\t,�5 �5 slider.phpnu �[��� <?php /** * Slider field. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Slider */ class Forminator_Slider extends Forminator_Field { /** * Module ID * * @var int */ private static int $module_id; /** * Field constructor. */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Slider', 'forminator' ); $this->slug = 'slider'; $this->type = 'slider'; $this->icon = 'sui-icon-settings-slider-control'; $this->position = 27; add_filter( 'forminator_is_subfield_enabled', array( __CLASS__, 'is_subfield_enabled' ), 10, 3 ); } /** * Checks whether the subfield is enabled * * @param bool $is_enabled Is subfield enabled. * @param string $subfield_name Subfield name. * @param object $obj Forminator_Field object. * @return bool */ public static function is_subfield_enabled( $is_enabled, $subfield_name, $obj ) { if ( ! empty( $obj->raw['type'] ) && 'slider' === $obj->raw['type'] ) { $is_enabled = ! empty( $obj->raw['slider_type'] ) && 'range' === $obj->raw['slider_type']; } return $is_enabled; } /** * Field defaults * * @return array */ public function defaults(): array { return array( 'calculations' => 'true', 'slider_type' => 'single', 'field_label' => esc_html__( 'Slider', 'forminator' ), ); } /** * Field front-end markup * * @param array $field Field. * @param Forminator_CForm_Front $views_obj Forminator_CForm_Front object. * @param array|null $draft_value Draft value(s). * * @return mixed */ public function markup( $field, $views_obj, $draft_value = array() ) { self::$module_id = $views_obj->get_module_id(); $settings = $views_obj->model->settings; $descr_position = self::get_description_position( $field, $settings ); $name = self::get_property( 'element_id', $field ); $required = self::get_property( 'required', $field ); $label = self::get_property( 'field_label', $field ); $description = self::get_property( 'description', $field ); $id = self::get_field_id( $name ); $slider = self::create_slider( $field, $draft_value ); $full_slider = self::add_slider_value( $slider, $field ); $html = '<div class="forminator-field">'; $html .= self::get_field_label( $label, $id, $required ); if ( 'above' === $descr_position ) { $html .= self::get_description( $description, $name, $descr_position ); } $html .= $full_slider; if ( 'above' !== $descr_position ) { $html .= self::get_description( $description, $name, $descr_position ); } $html .= '</div>'; /** * Filter slider markup * * @param string $html HTML markup. * @param array $field Field settings. * @param int $module_id Module ID. */ return apply_filters( 'forminator_field_slider_markup', $html, $field, self::$module_id ); } /** * Add slider value HTML to slider * * @param string $slider Basic slider HTML. * @param array $field Field settings. * @return string */ private static function add_slider_value( string $slider, array $field ): string { $name = self::get_property( 'element_id', $field ); $value_block = self::get_value_block( $field ); $width = self::get_property( 'slider_width', $field, 'full' ); $limit_block = self::get_limit_block( $field ); $slider_scale = self::get_property( 'slider_scale', $field, 'small' ); // Build class attribute. $classes = array( 'forminator-slider', 'forminator-slider-' . esc_attr( $width ), 'forminator-slider-size-' . esc_attr( $slider_scale ), ); $html = '<div class="' . implode( ' ', $classes ) . '">' . '<input type="text" id="' . esc_attr( self::get_field_id( $name ) ) . '" class="forminator-hidden-input" style="display:none;"/>' . $slider . $limit_block . $value_block . '</div>'; return $html; } /** * Get slider value template * * @param array $field Field settings. */ private static function get_value_template( array $field ): string { $prefix = self::get_property( 'prefix', $field ); $suffix = self::get_property( 'suffix', $field ); $value_template = $prefix . '{slider-value}' . $suffix; /** * Filter slider value template * * @param string $value_template Value template. * @param array $field Field settings. * @param int $module_id Module ID. */ return apply_filters( 'forminator_slider_value_template', $value_template, $field, self::$module_id ); } /** * Get value block HTML * * @param array $field Field settings. * @return string */ private static function get_value_block( array $field ): string { $value_template = self::get_value_template( $field ); $position = self::get_property( 'value_position', $field ); $position = 'top' !== $position ? 'bottom' : 'top'; $name = self::get_property( 'element_id', $field ); $is_range = self::is_range_slider( $field ); $attrs = ' type="hidden" value=""'; $display_value = self::get_property( 'display_selected_value', $field, null ); $hidden_behavior = self::get_property( 'hidden_behavior', $field ); if ( 'zero' === $hidden_behavior ) { $attrs .= ' data-hidden-behavior="' . esc_attr( $hidden_behavior ) . '"'; } $html = '<div class="forminator-slider-amount forminator-slider-amount-' . esc_attr( $position ) . '"' . ' data-value-template="' . esc_attr( $value_template ) . '">'; if ( is_null( $display_value ) || $display_value ) { $html .= '<span class="forminator-slider-value-min"></span>'; } $html .= '<input' . $attrs . ' id="' . esc_attr( self::get_field_id( $name . '-input' . ( $is_range ? '-min' : '' ) ) ) . '"' . ' name="' . esc_attr( $name ) . ( $is_range ? '-min' : '' ) . '"' . ' class="forminator-slider-hidden-min" />'; if ( $is_range ) { if ( is_null( $display_value ) || $display_value ) { $html .= '<span class="forminator-slider-separator">-</span>'; $html .= '<span class="forminator-slider-value-max"></span>'; } $html .= '<input' . $attrs . ' id="' . esc_attr( self::get_field_id( $name . '-input-max' ) ) . '"' . ' name="' . esc_attr( $name ) . '-max"' . ' class="forminator-slider-hidden-max" />'; } $html .= '</div>'; return $html; } /** * Get limit block HTML * * @param array $field Field settings. * @return string */ private static function get_limit_block( array $field ): string { $display_step_value = self::get_property( 'display_step_value', $field, null ); $display_step_type = self::get_property( 'display_step_type', $field ); // If $display_step_value is undefined, fall back to 'slider_limits'. if ( is_null( $display_step_value ) || $display_step_value ) { $display_step_value = 'hide' !== self::get_property( 'slider_limits', $field ); } if ( ! $display_step_value ) { return ''; } // Add data-step-type if $display_step_type is not empty. $data_attr = ! empty( $display_step_type ) ? ' data-step-type="' . esc_attr( $display_step_type ) . '"' : ''; return '<div class="forminator-slider-limit"' . $data_attr . '></div>'; } /** * Create slider HTML * * @param array $field Field settings. * @param array|null $draft_value Draft value(s). * @return string */ private static function create_slider( array $field, $draft_value ): string { $name = self::get_property( 'element_id', $field ); $required = self::get_property( 'required', $field ); $min = self::get_min_limit( $field ); $max = self::get_max_limit( $field ); $step = self::get_property( 'slider_step', $field, 1 ); $value = self::get_property( 'slider_default', $field, $min ); $is_range = self::is_range_slider( $field ); $slider_handle = self::get_property( 'show_slider_handle', $field, true ); if ( isset( $draft_value['value'] ) && is_numeric( $draft_value['value'] ) ) { $value = $draft_value['value']; } // Initialize class array. $classes = array( 'forminator-slide' ); // Add forminator-slide-handle-icon if $slider_handle is true. if ( 'false' !== $slider_handle ) { $classes[] = 'forminator-slide-handle-icon'; } $attr = array( 'class' => implode( ' ', $classes ), 'aria-required' => $required ? 'true' : 'false', 'data-is-range' => $is_range, 'data-min' => $min, 'data-max' => $max, 'data-step' => $step, ); if ( self::get_property( 'description', $field ) ) { $attr['aria-describedby'] = $name . '-description'; } if ( $is_range ) { $value_2 = self::get_property( 'slider_default_2', $field, $max ); if ( isset( $draft_value['value']['min'] ) && is_numeric( $draft_value['value']['min'] ) ) { $value = $draft_value['value']['min']; } if ( isset( $draft_value['value']['max'] ) && is_numeric( $draft_value['value']['max'] ) ) { $value_2 = $draft_value['value']['max']; } $value_2 = self::get_post_data( $name . '-max', $value_2 ); $value_2 = $value_2 > $max || $value_2 < $min ? $max : $value_2; $attr['data-value-max'] = $value_2; } // Override value by the posted value. $value = self::get_post_data( $name, $value ); $value = $value > $max || $value < $min ? $min : $value; if ( $is_range ) { $value = $value > $value_2 ? $value_2 : $value; } $attr['data-value'] = $value; $markup = self::implode_attr( $attr ); $slider = sprintf( '<div %s></div>', $markup ); /** * Filter slider HTML * * @param string $slider HTML markup. * @param array $field Field settings. * @param array $attr Slider attributes. * @param int $module_id Module ID. */ return apply_filters( 'forminator_field_create_slider', $slider, $field, $attr, self::$module_id ); } /** * Is range slider? * * @param array $field Field settings. * @return bool */ private static function is_range_slider( array $field ): bool { $slider_type = self::get_property( 'slider_type', $field ); return 'range' === $slider_type; } /** * Get slider max limit * * @param array $field Field settings. * @return int */ private static function get_max_limit( array $field ): int { $slider_max = self::get_property( 'slider_max', $field ); if ( ! is_numeric( $slider_max ) ) { $slider_max = 10; } return intval( $slider_max ); } /** * Get slider min limit * * @param array $field Field settings. * @return int */ private static function get_min_limit( array $field ): int { return self::get_property( 'slider_min', $field, 1, 'num' ); } /** * Field back-end validation * * @param array $field Field settings. * @param array|string $data Data to validate. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); $is_empty = ! isset( $data ) || '' === $data; $sub_id = $id; if ( self::is_range_slider( $field ) ) { $sub_id .= '-max'; if ( ! isset( $data['min'] ) || '' === $data['min'] ) { $is_empty = true; } elseif ( ! isset( $data['max'] ) || '' === $data['max'] ) { $is_empty = true; } } if ( ! $is_empty ) { $max = self::get_max_limit( $field ); $min = self::get_min_limit( $field ); if ( self::is_range_slider( $field ) && ( ( $min > $data['min'] || $max < $data['min'] || $min > $data['max'] || $max < $data['max'] || $data['min'] > $data['max'] ) || ( ! is_array( $data ) && ( ( $min > $data ) || ( $max < $data ) ) ) ) ) { $validation_message = /* translators: 1: Minimum value, 2: Maximum value */ sprintf( esc_html__( 'The slider should be less than %1$d and greater than %2$d.', 'forminator' ), $min, $max ); $this->validation_message[ $sub_id ] = sprintf( apply_filters( 'forminator_field_slider_max_min_validation_message', $validation_message, $id, $field, $data ), $max, $min ); } } if ( $this->is_required( $field ) && $is_empty ) { $require_message = self::get_property( 'required_message', $field ); $required_validation_message = ! empty( $require_message ) ? $require_message : esc_html__( 'This field is required.', 'forminator' ); $this->validation_message[ $sub_id ] = apply_filters( 'forminator_field_slider_required_field_validation_message', $required_validation_message, $id, $field, $data, $this ); } } /** * Internal calculable value * * @param array|string $submitted_field The field value. * @param array $field_settings The field settings. * * @return float */ private static function calculable_value( $submitted_field, $field_settings ) { $enabled = self::get_property( 'calculations', $field_settings, false, 'bool' ); if ( ! $enabled ) { return self::FIELD_NOT_CALCULABLE; } return intval( $submitted_field ); } /** * Get calculable * * @param array $submitted_field_data Original field value. * @param array $field_settings Field settings. * @return int|string */ public static function get_calculable_value( $submitted_field_data, $field_settings ) { $calculable_value = self::calculable_value( $submitted_field_data, $field_settings ); /** * Filter formula being used on calculable value on slider field * * @param int $calculable_value Calculable value, * @param array $submitted_field_data Original field value. * @param array $field_settings Field settings. * * @return string|int */ return apply_filters( 'forminator_field_slider_calculable_value', $calculable_value, $submitted_field_data, $field_settings ); } } PK x~\\�3 �3 currency.phpnu �[��� <?php /** * The Forminator_Currency class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Currency * * @since 1.7 */ class Forminator_Currency extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'currency'; /** * Type * * @var string */ public $type = 'currency'; /** * Position * * @var int */ public $position = 22; /** * Options * * @var array */ public $options = array(); /** * Is input * * @var bool */ public $is_input = true; /** * Icon * * @var string */ public $icon = 'sui-icon forminator-icon-currency'; /** * Is calculable * * @var bool */ public $is_calculable = true; /** * Forminator_Currency constructor. * * @since 1.7 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Currency', 'forminator' ); } /** * Field defaults * * @since 1.7 * @return array */ public function defaults() { return apply_filters( 'forminator_currency_defaults_settings', array( 'calculations' => 'true', 'limit_min' => 1, 'limit_max' => 150, 'currency' => 'USD', 'field_label' => esc_html__( 'Currency', 'forminator' ), ) ); } /** * Autofill Setting * * @since 1.7 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $providers = apply_filters( 'forminator_field_' . $this->slug . '_autofill', array(), $this->slug ); $autofill_settings = array( 'currency' => array( 'values' => forminator_build_autofill_providers( $providers ), ), ); return $autofill_settings; } /** * Field front-end markup * * @since 1.7 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $this->form_settings = $settings; $hidden_behavior = self::get_property( 'hidden_behavior', $field ); $descr_position = self::get_description_position( $field, $settings ); $html = ''; $min = 0; $max = ''; $id = self::get_property( 'element_id', $field ); $name = $id; $id = self::get_field_id( $id ); $required = self::get_property( 'required', $field, false ); $placeholder = $this->sanitize_value( self::get_property( 'placeholder', $field ) ); $value = esc_html( self::get_post_data( $name, self::get_property( 'default_value', $field ) ) ); $label = esc_html( self::get_property( 'field_label', $field, '' ) ); $description = self::get_property( 'description', $field, '' ); $min = esc_html( self::get_property( 'limit_min', $field, false ) ); $max = esc_html( self::get_property( 'limit_max', $field, false ) ); $currency = self::get_property( 'currency', $field, 'USD' ); $precision = self::get_calculable_precision( $field ); $separator = self::get_property( 'separators', $field, 'blank' ); $separators = $this->forminator_separators( $separator, $field ); if ( isset( $draft_value['value'] ) ) { $value = esc_attr( $draft_value['value'] ); } elseif ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $value = $this->get_prefill( $field, $value ); } if ( 'comma_dot' === $separator && false !== strpos( $value, ',' ) ) { $value = str_replace( ',', '', $value ); } $point = ! empty( $precision ) ? $separators['point'] : ''; $number_attr = array( 'name' => $name, 'value' => $value, 'placeholder' => $placeholder, 'id' => $id, 'class' => 'forminator-input forminator-currency', 'data-required' => $required, 'aria-required' => $required, 'data-decimals' => $precision, 'data-inputmask' => "'groupSeparator': '" . $separators['separator'] . "', 'radixPoint': '" . $point . "', 'digits': '" . $precision . "'", ); if ( $hidden_behavior && 'zero' === $hidden_behavior ) { $number_attr['data-hidden-behavior'] = $hidden_behavior; } if ( 'blank' === $separator ) { $number_attr['type'] = 'number'; $number_attr['step'] = 'any'; } $autofill_markup = $this->get_element_autofill_markup_attr( self::get_property( 'element_id', $field ) ); $number_attr = array_merge( $number_attr, $autofill_markup ); $html .= '<div class="forminator-field">'; $html .= self::create_input( $number_attr, $label, $description, $required, $descr_position, array( '<div class="forminator-input-with-suffix">', sprintf( '<span class="forminator-suffix">%s</span></div>', $currency ), '', ) ); $html .= '</div>'; return apply_filters( 'forminator_field_currency_markup', $html, $id, $required, $placeholder, $value ); } /** * Return field inline validation rules * * @since 1.7 * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $min = esc_html( self::get_property( 'limit_min', $field, false ) ); $max = esc_html( self::get_property( 'limit_max', $field, false ) ); $rules = '"' . $this->get_id( $field ) . '": {'; if ( $this->is_required( $field ) ) { $rules .= '"required": true,'; } if ( false !== $min && is_numeric( $min ) ) { $rules .= '"minNumber": ' . (float) $min . ','; } if ( false !== $max && is_numeric( $max ) ) { $rules .= '"maxNumber": ' . (float) $max . ','; } $rules .= '},'; return apply_filters( 'forminator_field_currency_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.7 * @return string */ public function get_validation_messages() { $field = $this->field; $min = esc_html( self::get_property( 'limit_min', $field, false ) ); $max = esc_html( self::get_property( 'limit_max', $field, false ) ); $custom_message = self::get_property( 'limit_message', $field, false, 'bool' ); $messages = '"' . $this->get_id( $field ) . '": {' . "\n"; if ( $this->is_required( $field ) ) { $required_validation_message = self::get_property( 'required_message', $field ); if ( empty( $required_validation_message ) ) { $required_validation_message = esc_html__( 'This field is required. Please enter number.', 'forminator' ); } $required_validation_message = apply_filters( 'forminator_field_currency_required_validation_message', $required_validation_message, $field ); $messages .= '"required": "' . forminator_addcslashes( $required_validation_message ) . '",' . "\n"; } $number_validation_message = apply_filters( 'forminator_field_currency_number_validation_message', esc_html__( 'This is not valid number.', 'forminator' ), $field ); $messages .= '"number": "' . forminator_addcslashes( $number_validation_message ) . '",' . "\n"; if ( $min ) { $min_validation_message = self::get_property( 'limit_min_message', $field ); $min_validation_message = apply_filters( 'forminator_field_currency_min_validation_message', $custom_message && $min_validation_message ? $min_validation_message : esc_html__( 'Please enter a value greater than or equal to {0}.', 'forminator' ), $field ); $messages .= '"minNumber": "' . forminator_addcslashes( $min_validation_message ) . '",' . "\n"; } if ( $max ) { $max_validation_message = self::get_property( 'limit_max_message', $field ); $max_validation_message = apply_filters( 'forminator_field_currency_max_validation_message', $custom_message && $max_validation_message ? $max_validation_message : esc_html__( 'Please enter a value less than or equal to {0}.', 'forminator' ), $field ); $messages .= '"maxNumber": "' . forminator_addcslashes( $max_validation_message ) . '",' . "\n"; } $messages .= '},' . "\n"; return apply_filters( 'forminator_field_currency_validation_message', $messages, $field ); } /** * Field back-end validation * * @since 1.7 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); $max = self::get_property( 'limit_max', $field, $data ); $min = self::get_property( 'limit_min', $field, $data ); $custom_message = self::get_property( 'limit_message', $field, false, 'bool' ); $precision = self::get_calculable_precision( $field ); $separator = self::get_property( 'separators', $field, 'blank' ); $max = trim( $max ); $min = trim( $min ); $max_len = strlen( $max ); $min_len = strlen( $min ); if ( $this->is_required( $field ) ) { if ( empty( $data ) && '0' !== $data ) { $required_validation_message = self::get_property( 'required_message', $field, esc_html__( 'This field is required. Please enter number.', 'forminator' ) ); $this->validation_message[ $id ] = apply_filters( 'forminator_field_currency_required_field_validation_message', $required_validation_message, $id, $field, $data, $this ); } } elseif ( ! empty( $data ) ) { $separators = $this->forminator_separators( $separator, $field ); $point = ! empty( $precision ) ? $separators['point'] : ''; $data = str_replace( array( $separators['separator'], $point ), array( '', '.' ), $data ); $min = floatval( $min ); $max = floatval( $max ); // Note : do not compare max or min if that settings field is blank string ( not zero ). if ( 0 !== $min_len && $data < $min ) { $min_validation_message = self::get_property( 'limit_min_message', $field ); $min_validation_message = $custom_message && $min_validation_message ? $min_validation_message : /* translators: 1: Minimum value, 2: Maximum value */ sprintf( esc_html__( 'The number should be less than %1$d and greater than %2$d.', 'forminator' ), $min, $max ); $this->validation_message[ $id ] = sprintf( apply_filters( 'forminator_field_currency_max_min_validation_message', /* translators: ... */ $min_validation_message, $id, $field, $data ), $max, $min ); } elseif ( 0 !== $max_len && $data > $max ) { $max_validation_message = self::get_property( 'limit_max_message', $field ); $max_validation_message = $custom_message && $max_validation_message ? $max_validation_message : /* translators: 1: Minimum value, 2: Maximum value */ sprintf( esc_html__( 'The number should be less than %1$d and greater than %2$d.', 'forminator' ), $min, $max ); $this->validation_message[ $id ] = sprintf( apply_filters( 'forminator_field_currency_max_min_validation_message', /* translators: ... */ $max_validation_message, $id, $field, $data ), $max, $min ); } } } /** * Sanitize data * * @since 1.7 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. $data = forminator_sanitize_field( $data ); return apply_filters( 'forminator_field_currency_sanitize', $data, $field, $original_data ); } /** * Internal calculable value * * @since 1.7 * * @param array|mixed $submitted_field Submitted field. * @param array $field_settings Field settings. * * @return float */ private static function calculable_value( $submitted_field, $field_settings ) { $enabled = self::get_property( 'calculations', $field_settings, false, 'bool' ); if ( ! $enabled ) { return self::FIELD_NOT_CALCULABLE; } return floatval( $submitted_field ); } /** * Get calculable value * * @since 1.7 * @inheritdoc * * @param array $submitted_field_data Submitted field data. * @param array $field_settings Field settings. */ public static function get_calculable_value( $submitted_field_data, $field_settings ) { $formatting_value = self::forminator_replace_number( $field_settings, $submitted_field_data ); $calculable_value = self::calculable_value( $formatting_value, $field_settings ); /** * Filter formula being used on calculable value on number field * * @since 1.7 * * @param float $calculable_value * @param array $submitted_field_data * @param array $field_settings * * @return string|int|float */ $calculable_value = apply_filters( 'forminator_field_currency_calculable_value', $calculable_value, $submitted_field_data, $field_settings ); return $calculable_value; } } PK y~\�Ek� � upload.phpnu �[��� <?php /** * The Forminator_Upload class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Upload * * @since 1.0 */ class Forminator_Upload extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'upload'; /** * Type * * @var string */ public $type = 'upload'; /** * Position * * @var int */ public $position = 14; /** * Options * * @var array */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon-download'; /** * Additional MIME type * * @var array */ private static $additional_mime_types = array(); /** * Forminator_Upload constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'File Upload', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { $default_all = array( 'all-image', 'all-video', 'all-document', 'all-audio', 'all-archive', 'all-text', 'all-spreadsheet', 'all-interactive', ); $mimes = forminator_allowed_mime_types( array(), false ); $file_type = array_merge( $default_all, array_keys( $mimes ) ); return array( 'field_label' => esc_html__( 'Upload file', 'forminator' ), 'filetypes' => $file_type, 'file-type' => 'single', 'file-limit' => 'unlimited', 'upload-limit' => 8, 'filesize' => 'MB', ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { // Unsupported Autofill. $autofill_settings = array(); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $settings = $views_obj->model->settings; $this->field = $field; self::$description_position = self::get_description_position( $field, $settings ); $html = ''; $id = self::get_property( 'element_id', $field ); $name = $id; $required = self::get_property( 'required', $field, false ); $design = $this->get_form_style( $settings ); $label = esc_html( self::get_property( 'field_label', $field, '' ) ); $description = self::get_property( 'description', $field, '' ); $file_type = self::get_property( 'file-type', $field, 'single' ); $form_id = isset( $settings['form_id'] ) ? $settings['form_id'] : 0; $uniq_id = $id . '_' . Forminator_CForm_Front::$uid; if ( 'multiple' === $file_type ) { $name = $name . '[]'; } $html .= '<div class="forminator-field">'; $html .= self::get_field_label( $label, 'forminator-field-' . $uniq_id, $required ); $file_limit_type = self::get_property( 'file-limit', $field, 'unlimited' ); $custom_file_type = self::get_property( 'custom-files', $field, false ); $custom_file_type = filter_var( $custom_file_type, FILTER_VALIDATE_BOOLEAN ); $file_mime_types = $this->file_mime_type( $field ); $mime_types = array_filter( $file_mime_types ); if ( 'multiple' === $file_type ) { $upload_method = self::get_property( 'upload-method', $field, 'ajax' ); $upload_attr = array( 'multiple' => 'multiple', 'data-method' => $upload_method, ); if ( $custom_file_type ) { $upload_attr['accept'] = str_replace( '|', ',.', implode( ',', preg_filter( '/^/', '.', $mime_types ) ) ); } if ( 'custom' === $file_limit_type ) { $file_limit = self::get_property( 'file-limit-input', $field, 5 ); $upload_attr['data-limit'] = $file_limit; $upload_attr['data-limit-message'] = /* translators: %d: File limit */ sprintf( esc_html__( 'You can upload a maximum of %d files.', 'forminator' ), $file_limit ); } $upload_limit = self::get_property( 'upload-limit', $field, self::FIELD_PROPERTY_VALUE_NOT_EXIST ); $max_size = wp_max_upload_size(); if ( ! empty( $upload_limit ) ) { $filesize = self::get_property( 'filesize', $field, 'MB' ); $file_size = $this->file_size( $filesize ); $max_size = $upload_limit * $file_size; } $upload_attr['data-size'] = $max_size; $rounded_max_size = $this->byte_to_size( $max_size ); $upload_attr['data-size-message'] = /* translators: %s: Maximum size */ sprintf( esc_html__( 'Maximum file size allowed is %s. ', 'forminator' ), $rounded_max_size ); if ( $custom_file_type ) { $upload_attr['data-filetype'] = implode( '|', array_values( $mime_types ) ); $upload_attr['data-filetype-message'] = esc_html__( 'file extension is not allowed.', 'forminator' ); } $html .= self::create_file_upload( $uniq_id, $name, $description, $required, $design, $file_type, $form_id, $upload_attr ); } else { $upload_attr = array(); if ( ! empty( $mime_types ) ) { $upload_attr['accept'] = str_replace( '|', ',.', implode( ',', preg_filter( '/^/', '.', $mime_types ) ) ); } $html .= self::create_file_upload( $uniq_id, $name, $description, $required, $design, $file_type, $form_id, $upload_attr ); } if ( 'multiple' === $file_type ) { $html .= sprintf( '<ul class="forminator-uploaded-files upload-container-%s"></ul>', $uniq_id ); } $html .= '</div>'; return apply_filters( 'forminator_field_file_markup', $html, $field ); } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { if ( $this->is_required( $field ) ) { $id = self::get_property( 'element_id', $field ); $required_message = self::get_property( 'required_message', $field, '' ); if ( empty( $data ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_upload_field_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please upload a file.', 'forminator' ) ), $id, $field ); } } } /** * Return field inline validation rules * Workaround for actually input file is hidden, so its not accessible via standar html5 `required` attribute * * @since 1.1 * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $file_type = self::get_property( 'file-type', $field, 'single' ); $custom_file_type = self::get_property( 'custom-files', $field, false ); $custom_file_type = filter_var( $custom_file_type, FILTER_VALIDATE_BOOLEAN ); $element_id = $this->get_id( $field ); if ( 'multiple' === $file_type ) { $element_id .= '[]'; } $rules = '"' . $element_id . '": {' . "\n"; $mime_type = $this->file_mime_type( $field ); $allowed_mime_types = ! empty( $mime_type ) ? implode( '|', array_values( $mime_type ) ) : ''; if ( $this->is_required( $field ) ) { $rules .= '"required": true,'; } if ( 'multiple' !== $file_type && $custom_file_type ) { $rules .= '"extension": "' . $allowed_mime_types . '",'; } $rules .= '},' . "\n"; return apply_filters( 'forminator_field_file_validation_rules', $rules, $id, $field ); } /** * Return field inline validation messages * * @since 1.1 * @return string */ public function get_validation_messages() { $field = $this->field; $id = $this->get_id( $field ); $is_required = $this->is_required( $field ); $file_type = self::get_property( 'file-type', $field, 'single' ); if ( 'multiple' === $file_type ) { $id .= '[]'; } $messages = '"' . $id . '": {' . "\n"; if ( $is_required ) { $settings_required_message = self::get_property( 'required_message', $field, '' ); $required_message = apply_filters( 'forminator_upload_field_required_validation_message', ( ! empty( $settings_required_message ) ? $settings_required_message : esc_html__( 'This field is required. Please upload a file.', 'forminator' ) ), $id, $field ); $messages = $messages . '"required": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } $extension_message = esc_html__( 'Error saving form. Uploaded file extension is not allowed.', 'forminator' ); $messages .= '"extension": "' . $extension_message . '",' . "\n"; $messages .= '},' . "\n"; return $messages; } /** * Handle file upload * * @since 1.6 copied from Forminator_Front_Action * * @param int $form_id Form Id. * @param array $field Settings. * @param array $post_data Submitted data. * @param string $upload_type Upload type. * @param array $file_input Input file. * * @return bool|array */ public function handle_file_upload( $form_id, $field, $post_data = array(), $upload_type = 'submit', $file_input = array() ) { $this->field = $field; $id = self::get_property( 'element_id', $field ); $field_name = $id; $custom_limit_size = true; $upload_limit = self::get_property( 'upload-limit', $field, self::FIELD_PROPERTY_VALUE_NOT_EXIST ); $filesize = self::get_property( 'filesize', $field, 'MB' ); $custom_file_type = self::get_property( 'custom-files', $field, false ); $use_library = self::get_property( 'use_library', $field, false ); $file_type = self::get_property( 'file-type', $field, 'single' ); $use_library = filter_var( $use_library, FILTER_VALIDATE_BOOLEAN ); $mime_types = array(); $additional_mime_types = array(); if ( self::FIELD_PROPERTY_VALUE_NOT_EXIST === $upload_limit || empty( $upload_limit ) ) { $custom_limit_size = false; } $custom_file_type = filter_var( $custom_file_type, FILTER_VALIDATE_BOOLEAN ); if ( $custom_file_type ) { // check custom mime. $filetypes = self::get_property( 'filetypes', $field, array(), 'array' ); $additional = str_replace( '.', '', self::get_property( 'additional-type', $field, '', 'string' ) ); $additional_filetype = array_map( 'trim', explode( ',', $additional ) ); $additional_filetypes = $this->get_additional_file_types( $additional_filetype ); $additional_mime_types = $this->get_additional_file_mime_types( $additional_filetype ); $all_file_type = array_merge( $filetypes, $additional_filetypes ); foreach ( $all_file_type as $filetype ) { // Mime type format = Key is the file extension with value as the mime type. $mime_types[ $filetype ] = $filetype; } } $file_object = array(); if ( ! empty( $file_input ) ) { $file_object = $file_input; } elseif ( isset( $_FILES[ $field_name ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing $file_object = $_FILES[ $field_name ]; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput } if ( ! empty( $file_object ) ) { if ( isset( $file_object['name'] ) && ! empty( $file_object['name'] ) ) { $file_name = wp_generate_password( 12, false, false ) . '-' . sanitize_file_name( $file_object['name'] ); $mime_types = forminator_allowed_mime_types( $mime_types, false ); /** * Filter mime types to be used as validation * * @since 1.6 * * @param array $mime_types return null/empty array to use default WP file types @see https://codex.wordpress.org/Plugin_API/Filter_Reference/upload_mimes. * @param array $field */ $mime_types = apply_filters( 'forminator_upload_field_mime_types', $mime_types, $field ); $valid = wp_check_filetype( $file_name, $mime_types ); $ext = pathinfo( $file_name, PATHINFO_EXTENSION ); $file_base_name = pathinfo( $file_name, PATHINFO_FILENAME ); $i = 1; $original_file_name = $file_base_name; $upload_temp_path = forminator_upload_root_temp(); if ( 'upload' === $upload_type && is_wp_error( $upload_temp_path ) ) { return array( 'success' => false, 'message' => $upload_temp_path->get_error_message(), ); } if ( ! is_wp_error( $upload_temp_path ) ) { while ( file_exists( $upload_temp_path . '/' . $file_base_name . '.' . $ext ) ) { $file_base_name = (string) $original_file_name . $i; $file_name = $file_base_name . '.' . $ext; ++$i; } } if ( false === $valid['ext'] ) { if ( 'multiple' === $file_type ) { return array( 'success' => false, 'message' => /* translators: %s: Extension */ sprintf( esc_html__( '.%s file extension is not allowed.', 'forminator' ), $ext ), ); } else { return array( 'success' => false, 'message' => esc_html__( 'Error saving form. Uploaded file extension is not allowed.', 'forminator' ), ); } } $allow = apply_filters( 'forminator_file_upload_allow', true, $field_name, $file_name, $valid ); if ( false === $allow ) { return array( 'success' => false, 'message' => esc_html__( 'Error saving form. Uploaded file extension is not allowed.', 'forminator' ), ); } if ( ! is_uploaded_file( $file_object['tmp_name'] ) ) { return array( 'success' => false, 'message' => esc_html__( 'Error saving form. Failed to read uploaded file.', 'forminator' ), ); } $valid_mime = self::check_mime_type( $file_object['tmp_name'], $file_object['name'], $additional_mime_types ); if ( ! $valid_mime ) { return array( 'success' => false, 'message' => esc_html__( 'Sorry, you are not allowed to upload this file type.', 'forminator' ), ); } $upload_dir = wp_upload_dir(); // Set upload folder. $file_path = 'upload' === $upload_type ? $upload_temp_path : forminator_get_upload_path( $form_id, 'uploads' ); $file_url = forminator_get_upload_url( $form_id, 'uploads' ); $unique_file_name = wp_unique_filename( $file_path, $file_name ); $exploded_name = explode( '/', $unique_file_name ); $filename = end( $exploded_name ); // Create base file name. $max_size = wp_max_upload_size(); $file_size = $this->file_size( $filesize ); if ( $custom_limit_size ) { $max_size = $upload_limit * $file_size; // convert to byte. } if ( 0 === $file_object['size'] ) { return array( 'success' => false, 'message' => esc_html__( 'The attached file is empty and can\'t be uploaded.', 'forminator' ), ); } if ( $file_object['size'] > $max_size ) { $rounded_max_size = $this->byte_to_size( $max_size ); return array( 'success' => false, 'message' => sprintf( /* translators: %s: Maximum size */ esc_html__( 'Maximum file size allowed is %s. ', 'forminator' ), $rounded_max_size ), ); } if ( UPLOAD_ERR_OK !== $file_object['error'] ) { return array( 'success' => false, 'message' => esc_html__( 'Error saving form. Upload error.', 'forminator' ), ); } if ( ! is_dir( $file_path ) ) { wp_mkdir_p( $file_path ); } // Create Index file. self::forminator_upload_index_file( $form_id, $file_path ); if ( wp_is_writable( $file_path ) ) { $file_path = $file_path . '/' . $filename; $file_url = $file_url . '/' . $filename; } else { $file_path = $upload_dir['basedir'] . '/' . $filename; $file_url = $upload_dir['baseurl'] . '/' . $filename; } if ( 'multiple' === $file_type ) { $file_limit_type = self::get_property( 'file-limit', $field, 'unlimited' ); if ( 'custom' === $file_limit_type ) { $file_limit = self::get_property( 'file-limit-input', $field, 5 ); if ( isset( $post_data['totalFiles'] ) && $post_data['totalFiles'] > $file_limit ) { if ( 'upload' === $upload_type ) { move_uploaded_file( $file_object['tmp_name'], $file_path ); } return array( 'error_type' => 'limit', 'success' => false, 'message' => /* translators: %d: File limit */ sprintf( esc_html__( 'You can upload a maximum of %d files.', 'forminator' ), $file_limit ), ); } } } $file_mime = $this->get_mime_type( $file_object['tmp_name'] ); // use move_uploaded_file instead of $wp_filesystem->put_contents. // increase performance, and avoid permission issues. if ( false !== move_uploaded_file( $file_object['tmp_name'], $file_path ) ) { if ( $use_library && ( 'multiple' !== $file_type || ( 'multiple' === $file_type && 'submit' === $upload_type ) ) ) { $upload_id = wp_insert_attachment( array( 'guid' => $file_path, 'post_mime_type' => $file_mime, 'post_title' => preg_replace( '/\.[^.]+$/', '', $filename ), 'post_content' => '', 'post_status' => 'inherit', ), $file_path ); self::generate_upload_metadata( $upload_id, $file_path ); } return array( 'success' => true, 'file_name' => $filename, 'file_url' => $file_url, 'message' => '', 'file_path' => wp_normalize_path( $file_path ), ); } else { return array( 'success' => false, 'message' => esc_html__( 'Error saving form. Upload error.', 'forminator' ), ); } } } return false; } /** * Check if content mime type is relevant to passed mime type * * @param string $file Full path to the file. * @param string $file_name The name of the file. * @param array $additional_mime_types Additional MIME type. * @return bool */ private static function check_mime_type( string $file, string $file_name, $additional_mime_types ): bool { if ( ! empty( $additional_mime_types ) ) { self::$additional_mime_types = $additional_mime_types; // Add additional MIME types through the upload_mimes event to support extra file types. add_filter( 'upload_mimes', array( __CLASS__, 'add_additional_mime_type_for_validation' ), 10 ); } $wp_filetype = wp_check_filetype_and_ext( $file, $file_name ); if ( ! empty( $additional_mime_types ) ) { // Remove the upload_mimes event after file type checks to avoid conflicts with other forms/fields. remove_filter( 'upload_mimes', array( __CLASS__, 'add_additional_mime_type_for_validation' ), 10 ); self::$additional_mime_types = array(); } return ! empty( $wp_filetype['ext'] ) && ! empty( $wp_filetype['type'] ); } /** * Add additional MIME types through the upload_mimes event to validate file uploads. * * @param array $mime_types File MIME types. * @return array */ public static function add_additional_mime_type_for_validation( $mime_types ) { $mime_types = array_merge( $mime_types, self::$additional_mime_types ); return $mime_types; } /** * Handle multiple file upload with ajax * * @since 1.6 copied from Forminator_Front_Action * * @param int $form_id Form Id. * @param array $upload_data settings. * @param array $field_array field array. * * @return bool|array */ public function handle_ajax_multifile_upload( $form_id, $upload_data, $field_array = array() ) { $file_path_arr = array(); $file_url_arr = array(); $use_library = self::get_property( 'use_library', $field_array, false ); $file_type = self::get_property( 'file-type', $field_array, 'single' ); if ( ! empty( $upload_data ) && ! empty( $upload_data['file'] ) ) { if ( false !== array_search( false, array_column( $upload_data['file'], 'success' ), true ) ) { return array( 'success' => false, ); } $upload_dir = wp_upload_dir(); $upload_path = forminator_get_upload_path( $form_id, 'uploads' ); $upload_url = forminator_get_upload_url( $form_id, 'uploads' ); if ( ! is_dir( $upload_path ) ) { wp_mkdir_p( $upload_path ); } // Create Index file. self::forminator_upload_index_file( $form_id, $upload_path ); foreach ( $upload_data['file'] as $upload ) { $upload_temp_path = forminator_upload_root_temp(); if ( ! empty( $upload ) && ! is_wp_error( $upload_temp_path ) ) { $file_name = trim( sanitize_file_name( $upload['file_name'] ) ); $temp_path = $upload_temp_path . '/' . $file_name; $unique_file_name = wp_unique_filename( $upload_path, $file_name ); $exploded_name = explode( '/', $unique_file_name ); $filename = end( $exploded_name ); if ( wp_is_writable( $upload_path ) ) { $file_path = $upload_path . '/' . trim( sanitize_file_name( $filename ) ); $file_url = $upload_url . '/' . trim( sanitize_file_name( $filename ) ); } else { $file_path = wp_normalize_path( $upload_dir['basedir'] . '/' . trim( sanitize_file_name( $filename ) ) ); $file_url = $upload_dir['baseurl'] . '/' . trim( sanitize_file_name( $filename ) ); } if ( file_exists( $temp_path ) ) { if ( $this->move_file( $temp_path, $file_path ) ) { if ( $use_library && 'multiple' === $file_type ) { $upload_id = wp_insert_attachment( array( 'guid' => $file_path, 'post_mime_type' => $upload['mime_type'], 'post_title' => preg_replace( '/\.[^.]+$/', '', $filename ), 'post_content' => '', 'post_status' => 'inherit', ), $file_path ); self::generate_upload_metadata( $upload_id, $file_path ); } $file_path_arr[] = $file_path; $file_url_arr[] = $file_url; } } else { // Check maybe it was already saved on previous submission but it had other fields validation issues. preg_match( '/(\-([0-9]+))\.[^.]+$/', $file_path, $matches ); if ( ! empty( $matches[0] ) ) { if ( '-1' === $matches[1] ) { $replace = ''; } else { $replace = '-' . ( --$matches[2] ); } $ext = str_replace( $matches[1], $replace, $matches[0] ); $file_path = substr( $file_path, 0, -strlen( $matches[0] ) ) . $ext; $file_url = substr( $file_url, 0, -strlen( $matches[0] ) ) . $ext; if ( file_exists( $file_path ) ) { $file_path_arr[] = $file_path; $file_url_arr[] = $file_url; } } } } } if ( ! empty( $file_url_arr ) && ! empty( $file_path_arr ) ) { return array( 'success' => true, 'file_url' => $file_url_arr, 'file_path' => $file_path_arr, ); } else { return array( 'success' => false, 'message' => esc_html__( 'Error saving form. Upload error.', 'forminator' ), ); } } return false; } /** * Move/Rename the file * * @param string $source Source file path. * @param string $destination Destination file path. * @return bool */ private function move_file( $source, $destination ) { if ( ! function_exists( 'wp_filesystem' ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; } global $wp_filesystem; if ( ! WP_Filesystem() ) { return false; // Could not initialize the filesystem. } if ( $wp_filesystem->move( $source, $destination ) ) { return true; } else { return false; } } /** * Handle multiple file upload with submission * * @since 1.6 copied from Forminator_Front_Action * * @param int $form_id Form Id. * @param array $field Field. * @param array $upload_data settings. * @param bool $temporary - Upload to temp folder first before payments are verified. * * @return bool|array */ public function handle_submission_multifile_upload( $form_id, $field, $upload_data, $temporary = false ) { $file_name_arr = array(); $file_path_arr = array(); $file_url_arr = array(); $to_temp = $temporary ? 'upload' : 'submit'; if ( ! empty( $upload_data ) ) { $upload_file = $this->arrange_files( $upload_data ); $i = 1; foreach ( $upload_file as $upload ) { $response = $this->handle_file_upload( $form_id, $field, array( 'totalFiles' => $i ), $to_temp, $upload ); if ( isset( $response['success'] ) && $response['success'] ) { $file_name_arr[] = $response['file_name']; $file_path_arr[] = wp_normalize_path( $response['file_path'] ); $file_url_arr[] = $response['file_url']; } else { return $response; } ++$i; } if ( ! empty( $file_url_arr ) && ! empty( $file_path_arr ) ) { return array( 'success' => true, 'file_name' => $file_name_arr, 'file_url' => $file_url_arr, 'file_path' => $file_path_arr, ); } else { return array( 'success' => false, 'message' => esc_html__( 'Error saving form. Upload error.', 'forminator' ), ); } } return false; } /** * Transfer the uploaded files * * @since 1.19.0 * * @param int $form_id Form Id. * @param array $upload_data Settings. * @param array $field_array Field array. * * @return bool|array */ public function transfer_upload( $form_id, $upload_data, $field_array = array() ) { $file_path = null; $file_url = null; $use_library = self::get_property( 'use_library', $field_array, false ); $file_type = self::get_property( 'file-type', $field_array, 'single' ); if ( ! empty( $upload_data ) && ! empty( $upload_data['file'] ) ) { if ( false !== array_search( false, array_column( $upload_data['file'], 'success' ), true ) ) { return array( 'success' => false, ); } $upload_path = forminator_get_upload_path( $form_id, 'uploads' ); $upload_url = forminator_get_upload_url( $form_id, 'uploads' ); $upload_dir = wp_upload_dir(); if ( 'multiple' === $file_type ) { foreach ( $upload_data['file']['file_name'] as $key => $upload ) { $files = $this->move_upload( array( 'file_name' => $upload, 'file_path' => $upload_data['file']['file_path'][ $key ], 'file_url' => $upload_data['file']['file_url'][ $key ], ), $upload_dir, $upload_path, $upload_url, $use_library, $file_type ); $file_path[] = $files['file_path']; $file_url[] = $files['file_url']; } } else { $file = $this->move_upload( $upload_data['file'], $upload_dir, $upload_path, $upload_url, $use_library, $file_type ); $file_path = $file['file_path']; $file_url = $file['file_url']; } if ( ! empty( $file_url ) && ! empty( $file_path ) ) { return array( 'success' => true, 'file_url' => $file_url, 'file_path' => $file_path, ); } else { return array( 'success' => false, 'message' => esc_html__( 'Error saving form. Upload error.', 'forminator' ), ); } } return false; } /** * Move the uploaded files from forminator_temp to WP uploads. * TODO: Refactor this. Similar to handle_ajax_multifile_upload. * * @since 1.19.0 * * @param array $upload - The upload data. * @param array $upload_dir - Upload directory. * @param string $upload_path - Upload path. * @param string $upload_url - Upload URL. * @param bool $use_library - Upload directory. * @param string $file_type - Single/Multiple. * * @return bool|array */ public function move_upload( $upload, $upload_dir, $upload_path, $upload_url, $use_library, $file_type ) { $file_name = trim( sanitize_file_name( $upload['file_name'] ) ); $unique_file_name = wp_unique_filename( $upload_path, $file_name ); $exploded_name = explode( '/', $unique_file_name ); $filename = end( $exploded_name ); if ( ! is_dir( $upload_path ) ) { wp_mkdir_p( $upload_path ); } if ( wp_is_writable( $upload_path ) ) { $file_path = wp_normalize_path( $upload_path . '/' . trim( sanitize_file_name( $filename ) ) ); $file_url = $upload_url . '/' . trim( sanitize_file_name( $filename ) ); } else { $file_path = wp_normalize_path( $upload_dir['basedir'] . '/' . trim( sanitize_file_name( $filename ) ) ); $file_url = $upload_dir['baseurl'] . '/' . trim( sanitize_file_name( $filename ) ); } $temp_path = forminator_upload_root_temp(); if ( ! is_wp_error( $temp_path ) ) { $temp_path = $temp_path . '/' . $file_name; } if ( ! is_wp_error( $temp_path ) && file_exists( $temp_path ) ) { if ( $this->move_file( $temp_path, $file_path ) ) { if ( $use_library && 'multiple' === $file_type ) { $upload_id = wp_insert_attachment( array( 'guid' => $file_path, 'post_mime_type' => $upload['mime_type'], 'post_title' => preg_replace( '/\.[^.]+$/', '', $filename ), 'post_content' => '', 'post_status' => 'inherit', ), $file_path ); self::generate_upload_metadata( $upload_id, $file_path ); } } } else { // Check maybe it was already saved on previous submission but it had other fields validation issues. preg_match( '/(\-([0-9]+))\.[^.]+$/', $file_path, $matches ); if ( ! empty( $matches[0] ) ) { if ( '-1' === $matches[1] ) { $replace = ''; } else { $replace = '-' . ( --$matches[2] ); } $ext = str_replace( $matches[1], $replace, $matches[0] ); $file_path_new = substr( $file_path, 0, -strlen( $matches[0] ) ) . $ext; $file_url_new = substr( $file_url, 0, -strlen( $matches[0] ) ) . $ext; if ( file_exists( $file_path_new ) ) { $file_path = $file_path_new; $file_url = $file_url_new; } } } return array( 'file_path' => $file_path, 'file_url' => $file_url, ); } /** * File size * * @param string $file_size File size. * * @return mixed */ public function file_size( $file_size ) { switch ( $file_size ) { case 'KB': $size = 1000; break; case 'B': $size = 1; break; default: $size = 1000000; break; } return $size; } /** * Arrange files * * @param array $files Files. * * @return array */ public function arrange_files( $files ) { $new = array(); foreach ( $files as $key => $file ) { foreach ( $file as $i => $val ) { $new[ $i ][ $key ] = $val; } } return $new; } /** * Byte to size * * @param int $size Size. * * @return float|string */ public function byte_to_size( $size ) { $rounded_max_size = round( $size / 1000000 ); if ( $rounded_max_size <= 0 ) { // go to KB. $rounded_max_size = round( $size / 1000 ); if ( $rounded_max_size <= 0 ) { // go to B. $rounded_max_size = round( $size ) . ' B'; } else { $rounded_max_size .= ' KB'; } } else { $rounded_max_size .= ' MB'; } return $rounded_max_size; } /** * Get all Filetypes * * @param array $field Field. * * @return array */ public function file_mime_type( $field ) { $mime_types = array(); $default_all = array( 'all-image', 'all-video', 'all-document', 'all-audio', 'all-archive', 'all-text', 'all-spreadsheet', 'all-interactive', ); $filetypes = self::get_property( 'filetypes', $field, array(), 'array' ); $file_types = array_diff( array_merge( $default_all, $filetypes ), $default_all ); $additional = str_replace( '.', '', self::get_property( 'additional-type', $field, '', 'string' ) ); $additional_filetype = array_map( 'trim', explode( ',', $additional ) ); $additional_filetypes = $this->get_additional_file_types( $additional_filetype ); $all_filetype = array_merge( $file_types, $additional_filetypes ); if ( ! empty( $all_filetype ) ) { foreach ( $all_filetype as $filetype ) { $mime_types[ $filetype ] = $filetype; } } // Backward compatibility: allow only the allowed file types. $mime_types = forminator_allowed_mime_types( $mime_types, false ); return $mime_types; } /** * Get additional file types. * * @param array $custom_filetypes Custom file types. * @return string[] */ private function get_additional_file_types( $custom_filetypes ) { $file_types = array(); foreach ( $custom_filetypes as $custom_filetype ) { $custom_type = array_map( 'trim', explode( '|', $custom_filetype ) ); $file_types[] = $custom_type[0]; } return $file_types; } /** * Get additional file MIME types. * * @param array $custom_filetypes Custom file types. * @return string[] */ private function get_additional_file_mime_types( $custom_filetypes ) { $mime_types = array(); foreach ( $custom_filetypes as $custom_filetype ) { $custom_type = array_map( 'trim', explode( '|', $custom_filetype ) ); if ( ! empty( $custom_type[1] ) ) { $mime_types[ $custom_type[0] ] = $custom_type[1]; } } return $mime_types; } /** * Get mime type, provide alternative if function is not available * * @param string $file File. * * @return string */ public function get_mime_type( $file ) { if ( function_exists( 'mime_content_type' ) ) { $mime_type = mime_content_type( $file ); } else { $file_type = wp_check_filetype( $file ); $mime_type = $file_type['type']; } return $mime_type; } /** * Set permission * * @param string $path Path. */ public function set_permissions( $path ) { $permission = apply_filters( 'forminator_file_permission', 0755, $path ); if ( $permission ) { if ( ! function_exists( 'wp_filesystem' ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; } global $wp_filesystem; if ( ! WP_Filesystem() ) { return false; // Could not initialize the filesystem. } if ( $wp_filesystem->chmod( $path, $permission ) ) { return true; } else { return false; } } } } PK y~\�H�, �, text.phpnu �[��� <?php /** * The Forminator_Text class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Text * * @since 1.0 */ class Forminator_Text extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'text'; /** * Type * * @var string */ public $type = 'text'; /** * Position * * @var int */ public $position = 6; /** * Options * * @var array */ public $options = array(); /** * Is input * * @var bool */ public $is_input = true; /** * Has counter * * @var bool */ public $has_counter = true; /** * Icon * * @var string */ public $icon = 'sui-icon-style-type'; /** * Forminator_Text constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Input', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'input_type' => 'line', 'limit_type' => 'characters', 'field_label' => esc_html__( 'Text', 'forminator' ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $providers = apply_filters( 'forminator_field_' . $this->slug . '_autofill', array(), $this->slug ); $autofill_settings = array( 'text' => array( 'values' => forminator_build_autofill_providers( $providers ), ), ); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $this->form_settings = $settings; $descr_position = self::get_description_position( $field, $settings ); $html = ''; $name = self::get_property( 'element_id', $field ); $id = self::get_field_id( $name ); $required = self::get_property( 'required', $field, false ); $ariareq = 'false'; $default = esc_html( self::get_property( 'default', $field, false ) ); $placeholder = $this->sanitize_value( self::get_property( 'placeholder', $field ) ); $field_type = trim( self::get_property( 'input_type', $field ) ); $label = esc_html( self::get_property( 'field_label', $field, '' ) ); $description = self::get_property( 'description', $field, '' ); $limit = self::get_property( 'limit', $field, 0, 'num' ); $limit_type = self::get_property( 'limit_type', $field, '', 'str' ); $autofill_markup = $this->get_element_autofill_markup_attr( self::get_property( 'element_id', $field ) ); if ( (bool) $required ) { $ariareq = 'true'; } $description_block = ''; if ( ! empty( $description ) || ( ! empty( $limit ) && ! empty( $limit_type ) ) ) { $description_block .= sprintf( '<span id="%s" class="forminator-description">', esc_attr( $id . '-description' ) ); if ( ! empty( $description ) ) { $description_block .= self::esc_description( $description, $name ); } // Counter. if ( ( ! empty( $limit ) && ! empty( $limit_type ) ) ) { $description_block .= sprintf( '<span data-limit="%s" data-type="%s">0 / %s</span>', $limit, $limit_type, $limit ); } $description_block .= '</span>'; } $description_block = apply_filters( 'forminator_field_description', $description_block, $description, $id, $descr_position ); if ( 'paragraph' === $field_type ) { $textarea = array( 'name' => $name, 'placeholder' => $placeholder, 'id' => $id, 'class' => 'forminator-textarea', 'aria-required' => $ariareq, ); // Add maxlength attribute if limit_type is characters. if ( ! empty( $limit ) && 'characters' === $limit_type ) { $textarea['maxlength'] = $limit; } if ( isset( $draft_value['value'] ) ) { $default = wp_kses_post( $draft_value['value'] ); } elseif ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $default = $this->get_prefill( $field, $default ); } if ( ! empty( $default ) ) { $textarea['content'] = $default; } elseif ( isset( $autofill_markup['value'] ) ) { $textarea['content'] = $autofill_markup['value']; unset( $autofill_markup['value'] ); } if ( ! empty( $description ) ) { $textarea['aria-describedby'] = $id . '-description'; } $textarea = array_merge( $textarea, $autofill_markup ); $html .= '<div class="forminator-field">'; $html .= self::get_field_label( $label, $id, $required ); if ( 'above' === $descr_position ) { $html .= $description_block; } $html .= self::create_textarea( $textarea, '', '', $required, ); $html .= '</div>'; if ( 'above' !== $descr_position ) { $html .= $description_block; } } else { $input_text = array( 'type' => 'text', 'name' => $name, 'value' => $default, 'placeholder' => $placeholder, 'id' => $id, 'class' => 'forminator-input forminator-name--field', 'data-required' => $required, ); // Add maxlength attribute if limit_type is characters. if ( ! empty( $limit ) && 'characters' === $limit_type ) { $input_text['maxlength'] = $limit; } if ( isset( $draft_value['value'] ) ) { $default = wp_kses_post( $draft_value['value'] ); } elseif ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $default = $this->get_prefill( $field, $default ); } if ( ! empty( $default ) ) { $input_text['value'] = $default; } if ( ! empty( $description ) ) { $input_text['aria-describedby'] = $id . '-description'; } $input_text = array_merge( $input_text, $autofill_markup ); $html .= '<div class="forminator-field">'; $html .= self::get_field_label( $label, $id, $required ); if ( 'above' === $descr_position ) { $html .= $description_block; } $html .= self::create_input( $input_text, '', '', $required, ); if ( 'above' !== $descr_position ) { $html .= $description_block; } $html .= '</div>'; } return apply_filters( 'forminator_field_text_markup', $html, $field ); } /** * Return field inline validation rules * * @since 1.0 * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); $has_limit = $this->has_limit( $field ); $rules = ''; if ( ! isset( $field['limit'] ) ) { $field['limit'] = 0; } if ( $is_required || $has_limit ) { $rules = '"' . $this->get_id( $field ) . '": {'; if ( $is_required ) { $rules .= '"required": true,'; } if ( $has_limit ) { if ( isset( $field['limit_type'] ) && 'characters' === trim( $field['limit_type'] ) ) { $rules .= '"maxlength": ' . $field['limit'] . ','; } else { $rules .= '"maxwords": ' . $field['limit'] . ','; } } $rules .= '},'; } return apply_filters( 'forminator_field_text_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @return string */ public function get_validation_messages() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); $has_limit = $this->has_limit( $field ); $messages = ''; $required_message = self::get_property( 'required_message', $field, '' ); if ( $is_required || $has_limit ) { $messages .= '"' . $this->get_id( $field ) . '": {'; if ( $is_required ) { $required_error = apply_filters( 'forminator_text_field_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please enter text.', 'forminator' ) ), $id, $field ); $messages .= '"required": "' . forminator_addcslashes( $required_error ) . '",' . "\n"; } if ( $has_limit ) { if ( isset( $field['limit_type'] ) && 'characters' === trim( $field['limit_type'] ) ) { $max_length_error = apply_filters( 'forminator_text_field_characters_validation_message', esc_html__( 'You exceeded the allowed amount of characters. Please check again.', 'forminator' ), $id, $field ); $messages .= '"maxlength": "' . forminator_addcslashes( $max_length_error ) . '",' . "\n"; } else { $max_words_error = apply_filters( 'forminator_text_field_words_validation_message', esc_html__( 'You exceeded the allowed amount of words. Please check again.', 'forminator' ), $id, $field ); $messages .= '"maxwords": "' . forminator_addcslashes( $max_words_error ) . '",' . "\n"; } } $messages .= '},'; } return $messages; } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); if ( ! isset( $field['limit'] ) ) { $field['limit'] = 0; } if ( $this->is_required( $field ) && '' === $data ) { $required_message = self::get_property( 'required_message', $field, '' ); $this->validation_message[ $id ] = apply_filters( 'forminator_text_field_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please enter text.', 'forminator' ) ), $id, $field ); } if ( $this->has_limit( $field ) ) { $data = html_entity_decode( $data ); if ( ( isset( $field['limit_type'] ) && 'characters' === trim( $field['limit_type'] ) ) && ( mb_strlen( $data ) > $field['limit'] ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_text_field_characters_validation_message', esc_html__( 'You exceeded the allowed amount of characters. Please check again.', 'forminator' ), $id, $field ); } elseif ( ( isset( $field['limit_type'] ) && 'words' === trim( $field['limit_type'] ) ) ) { $words = preg_split( '/\s+/', $data ); if ( is_array( $words ) && count( $words ) > $field['limit'] ) { $this->validation_message[ $id ] = apply_filters( 'forminator_text_field_words_validation_message', esc_html__( 'You exceeded the allowed amount of words. Please check again.', 'forminator' ), $id, $field ); } } } } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. $data = forminator_sanitize_field( $data ); return apply_filters( 'forminator_field_text_sanitize', $data, $field, $original_data ); } } PK y~\XT�2� 2� postdata.phpnu �[��� <?php /** * The Forminator_Postdata class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Postdata * * @since 1.0 */ class Forminator_Postdata extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'postdata'; /** * Type * * @var string */ public $type = 'postdata'; /** * Position * * @var int */ public $position = 15; /** * Options * * @var array */ public $options = array(); /** * Category * * @var string */ public $category = 'posts'; /** * Icon * * @var string */ public $icon = 'sui-icon-post-pin'; /** * Draft values * * @var array */ public $draft_values = array(); /** * Image extensions * * @var array */ public $image_extensions = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp' ); /** * Forminator_Postdata constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Post Data', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return apply_filters( 'forminator_post_data_defaults_settings', array( 'data_status' => 'pending', 'post_title_label' => esc_attr__( 'Post Title', 'forminator' ), 'post_content_label' => esc_attr__( 'Post Content', 'forminator' ), 'post_excerpt_label' => esc_attr__( 'Post Excerpt', 'forminator' ), 'post_image_label' => esc_attr__( 'Featured Image', 'forminator' ), 'category_label' => esc_attr__( 'Category', 'forminator' ), 'post_tag_label' => esc_attr__( 'Tags', 'forminator' ), 'select_author' => 1, 'category_multiple' => '0', 'post_tag_multiple' => '0', 'post_type' => 'post', 'options' => array( array( 'label' => '', 'value' => '', ), ), ) ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { return $settings; /* // TODO: support autofill-for-postdata. // $title_providers = apply_filters( 'forminator_field_' . $this->slug . '_post_titlle_autofill', array(), $this->slug . '_post_titlle' );. // $content_providers = apply_filters( 'forminator_field_' . $this->slug . '_post_content_autofill', array(), $this->slug . '_post_content' );. // $excerpt_providers = apply_filters( 'forminator_field_' . $this->slug . '_post_excerpt_autofill', array(), $this->slug . '_post_excerpt' );. // // $autofill_settings = array(. // 'postdata-post-title' => array(. // 'values' => forminator_build_autofill_providers( $title_providers ),. // ),. // 'postdata-post-content' => array(. // 'values' => forminator_build_autofill_providers( $content_providers ),. // ),. // 'postdata-post-excerpt' => array(. // 'values' => forminator_build_autofill_providers( $excerpt_providers ),. // ),. // );. // // return $autofill_settings;. */ } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $this->draft_values = ! empty( $draft_value['value'] ) ? $draft_value['value'] : array(); self::$description_position = self::get_description_position( $field, $settings ); $html = ''; $required = self::get_property( 'required', $field, false ); $id = self::get_property( 'element_id', $field ); $name = $id; $design = $this->get_form_style( $settings ); $ajax = ! empty( $settings['use_ajax_load'] ); $html .= $this->get_post_title( $id, $name, $field, $required, $design ); $html .= $this->get_post_content( $id, $name, $field, $required, $ajax ); $html .= $this->get_post_excerpt( $id, $name, $field, $required, $design ); $html .= $this->get_post_image( $id, $name, $field, $required, $design ); $html .= $this->get_post_categories( $id, $name, $field, $required ); $html .= $this->render_custom_fields( $id, $name, $field, $required ); return apply_filters( 'forminator_field_postdata_markup', $html, $field, $required, $id, $this ); } /** * Return post title * * @since 1.0 * * @param int $id Id. * @param string $name Name. * @param array $field Field. * @param bool $required Required. * @param string $design Design. * * @return string */ public function get_post_title( $id, $name, $field, $required, $design ) { return apply_filters( 'forminator_field_postdata_post_title', $this->_get_post_field( $id, $name, $field, $required, 'post_title', 'text', 'forminator-input', 'post-title', array(), '', $design ) ); } /** * Return post content * * @since 1.0 * * @param int $id Id. * @param string $name Name. * @param array $field Field. * @param bool $required Required. * @param bool $ajax Ajax. * * @return string */ public function get_post_content( $id, $name, $field, $required, $ajax ) { return apply_filters( 'forminator_field_postdata_post_content', $this->_get_post_field( $id, $name, $field, $required, 'post_content', 'wp_editor', 'forminator-textarea', 'post-content', array( 'ajax' => $ajax ) ) ); } /** * Return post excerpt * * @since 1.0 * * @param int $id Id. * @param string $name Name. * @param array $field Field. * @param bool $required Required. * @param string $design Design. * * @return string */ public function get_post_excerpt( $id, $name, $field, $required, $design ) { return apply_filters( 'forminator_field_postdata_post_excerpt', $this->_get_post_field( $id, $name, $field, $required, 'post_excerpt', 'textarea', 'forminator-textarea', 'post-excerpt', array(), '', $design ) ); } /** * Return post featured image * * @since 1.0 * * @param int $id Id. * @param string $name Name. * @param array $field Field. * @param bool $required Required. * @param string $design Design. * * @return string */ public function get_post_image( $id, $name, $field, $required, $design ) { return apply_filters( 'forminator_field_postdata_post_image', $this->_get_post_field( $id, $name, $field, $required, 'post_image', 'file', 'forminator-upload', 'post-image', array(), '', $design ) ); } /** * Return categories * * @since 1.0 * * @param int $id Id. * @param string $name Name. * @param array $field Field. * @param bool $required Required. * * @return string */ public function get_post_categories( $id, $name, $field, $required ) { $html = ''; $post_type = self::get_property( 'post_type', $field, 'post' ); $category_list = forminator_post_categories( $post_type ); if ( ! empty( $category_list ) ) { foreach ( $category_list as $category ) { $options = array(); $categories = get_categories( array( 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false, 'taxonomy' => $category['value'], ) ); $categories = apply_filters( 'forminator_field_postdata_' . $category['value'] . '_list', $categories ); foreach ( $categories as $cat ) { $options[] = array( 'value' => $cat->term_id, 'label' => $cat->name, ); } $value = ''; $design = ''; $multiple = self::get_property( $category['value'] . '_multiple', $field, false ); $allow_multiple = $multiple ? 'multiple' : ''; $select_type = $multiple ? 'multiselect' : 'select'; $html .= apply_filters( 'forminator_field_postdata_' . $category['value'], $this->_get_post_field( $id, $name, $field, $required, $category['value'], $select_type, 'forminator-select2', $category['value'], $options, $value, $design, $allow_multiple ) ); } } return $html; } /** * Return post field * * @since 1.0 * * @param int $id Id. * @param string $name Name. * @param array $field Field. * @param bool $required Required. * @param string $field_name Field name. * @param string $type Field type. * @param string $class_name Class name. * @param string $input_suffix Input suffix. * @param array $options Options. * @param string $value Field value. * @param string $design Design. * @param string $multiple Multiple. * * @return string */ public function _get_post_field( $id, $name, $field, $required, $field_name, $type, $class_name, $input_suffix, $options = array(), $value = '', $design = '', $multiple = '' ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore $html = ''; $field_enabled = self::get_property( $field_name, $field, '' ); $type = trim( $type ); $full_id = self::get_field_id( $input_suffix . '-' . $id ); $is_preview = filter_input( INPUT_POST, 'is_preview', FILTER_VALIDATE_BOOLEAN ); $draft_value = isset( $this->draft_values[ $input_suffix ] ) ? $this->draft_values[ $input_suffix ] : ''; if ( ! empty( $field_enabled ) ) { $cols = 12; $placeholder = esc_html( self::get_property( $field_name . '_placeholder', $field ) ); $label = esc_html( self::get_property( $field_name . '_label', $field ) ); $description = esc_html( self::get_property( $field_name . '_description', $field ) ); $field_markup = array( 'type' => $type, 'name' => $id . '-' . $input_suffix, 'placeholder' => $placeholder, 'id' => $full_id, 'class' => $class_name, ); if ( $required ) { $field_markup['required'] = $required; } if ( ! empty( $multiple ) ) { $field_markup['multiple'] = $multiple; $field_markup['name'] = $field_markup['name'] . '[]'; } $html .= '<div class="forminator-row">'; $html .= sprintf( '<div class="forminator-col forminator-col-%s">', $cols ); $html .= '<div class="forminator-field">'; $ajax = ! empty( $options['ajax'] ); if ( 'wp_editor' === $type ) { // multiple wp_editor support. $field_markup['id'] = $field_markup['id']; } if ( 'wp_editor' === $type && ! $is_preview && ! $ajax ) { if ( ! empty( $draft_value ) ) { $field_markup['content'] = $draft_value; } $html .= self::create_wp_editor( $field_markup, $label, $description, $required ); } elseif ( ( 'textarea' === $type || 'wp_editor' === $type ) && ( $ajax || $is_preview ) ) { if ( ! empty( $draft_value ) ) { $field_markup['content'] = $draft_value; } $html .= self::create_textarea( $field_markup, $label, $description, $required, self::$description_position, ); if ( 'wp_editor' === $type ) { $_id = $field_markup['id']; $args = self::get_tinymce_args( $_id ); $html .= '<script>wp.editor.initialize("' . esc_attr( $_id ) . '", ' . $args . ');</script>'; } } elseif ( 'select' === $type ) { if ( empty( $options ) ) { unset( $field_markup['required'] ); } if ( ! empty( $draft_value ) ) { // Users might switch from multi select. $value = is_array( $draft_value ) ? $draft_value[0] : $draft_value; } $html .= self::create_select( $field_markup, $label, $options, $value, $description, $required, self::$description_position, ); } elseif ( 'multiselect' === $type ) { $html .= self::get_field_label( $label, $id . '-field', $required ); if ( ! empty( $draft_value ) ) { // Users might switch from single select. $post_value = is_array( $draft_value ) ? $draft_value : array( $draft_value ); } else { $post_value = self::get_post_data( $name, self::FIELD_PROPERTY_VALUE_NOT_EXIST ); } $name = $id . '-' . $field_name . '[]'; $get_id = $id . '-' . $field_name; $i = 1; if ( 'above' === self::$description_position ) { $html .= self::get_description( $description, $get_id, self::$description_position ); } $html .= '<div class="forminator-multiselect">'; foreach ( $options as $option ) { $value = $option['value'] ? $option['value'] : $option['label']; $input_id = $id . '-' . $i . '-' . $field_name; $selected = false; if ( self::FIELD_PROPERTY_VALUE_NOT_EXIST !== $post_value || ! empty( $draft_value ) ) { if ( is_array( $post_value ) ) { $selected = in_array( $value, $post_value ); // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict } } if ( $selected ) { $selected = esc_attr( 'checked="checked"' ); $selected_class = esc_attr( 'forminator-option forminator-is_checked' ); } else { $selected = ''; $selected_class = esc_attr( 'forminator-option' ); } $html .= sprintf( '<label for="%s" class="%s">', $input_id, $selected_class ); $html .= sprintf( '<input type="checkbox" name="%s" value="%s" id="%s" %s />', $name, $value, $input_id, $selected ); $html .= $option['label']; $html .= '</label>'; ++$i; } $html .= '</div>'; if ( 'above' !== self::$description_position ) { $html .= self::get_description( $description, $get_id, self::$description_position ); } } elseif ( 'file' === $type ) { $label_id = $full_id; $html .= self::get_field_label( $label, $label_id, $required ); $html .= self::create_file_upload( $input_suffix . '-' . $id . '_' . Forminator_CForm_Front::$uid, $name . '-' . $input_suffix, $description, $required, $design, 'single', 0, array( 'accept' => '.' . implode( ',.', $this->image_extensions ), ) ); } else { if ( ! empty( $draft_value ) ) { $field_markup['value'] = $draft_value; } $html .= self::create_input( $field_markup, $label, $description, $required, self::$description_position, ); } $html .= '</div>'; $html .= '</div>'; $html .= '</div>'; } return $html; } /** * Render custom fields * * @since 1.0 * * @param int $id Id. * @param string $name Name. * @param array $field Field. * @param bool $required Required. * * @return string */ private function render_custom_fields( $id, $name, $field, $required ) { $html = ''; $cols = 12; $has_custom_fields = self::get_property( 'post_custom', $field, false ); if ( $has_custom_fields ) { $custom_vars = self::get_property( 'options', $field ); if ( ! empty( $custom_vars ) ) { $html .= '<div class="forminator-row forminator-row--inner">'; $i = 1; foreach ( $custom_vars as $variable ) { $html .= sprintf( '<div class="forminator-col forminator-col-%s">', $cols ); $value = ''; if ( ! empty( $variable['value'] ) ) { $value = $variable['value']; } $input_id = $id . '-post_meta-' . $i; $label = $variable['label']; $field_markup = array( 'type' => 'text', 'class' => 'forminator-input', 'name' => $input_id, 'id' => $input_id, 'placeholder' => $label, 'value' => $value, ); $html .= self::create_input( $field_markup, $label, '' ); $html .= '</div>'; ++$i; } } $html .= '</div>'; } return $html; } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); $post_title = self::get_property( 'post_title', $field, '' ); $post_content = self::get_property( 'post_content', $field, '' ); $post_excerpt = self::get_property( 'post_excerpt', $field, '' ); $setting_required_message = self::get_property( 'required_message', $field, '' ); $post_type = self::get_property( 'post_type', $field, 'post' ); $post_image = self::get_property( 'post_image', $field, '' ); $title = isset( $data['post-title'] ) ? $data['post-title'] : ''; $content = isset( $data['post-content'] ) ? $data['post-content'] : ''; $excerpt = isset( $data['post-excerpt'] ) ? $data['post-excerpt'] : ''; $image = isset( $data['post-image'] ) ? $data['post-image'] : ''; $category_list = forminator_post_categories( $post_type ); if ( $this->is_required( $field ) ) { if ( empty( $data ) ) { $postdata_validation_message = apply_filters( 'forminator_postdata_field_validation_message', ( ! empty( $setting_required_message ) ? $setting_required_message : esc_html__( 'This field is required. Please fill in post data.', 'forminator' ) ), $id ); $this->validation_message[ $id ] = $postdata_validation_message; } elseif ( is_array( $data ) ) { if ( ! empty( $post_title ) && empty( $title ) ) { $postdata_post_title_validation_message = apply_filters( 'forminator_postdata_field_post_title_validation_message', ( ! empty( $setting_required_message ) ? $setting_required_message : esc_html__( 'This field is required. Please enter the post title.', 'forminator' ) ), $id ); $this->validation_message[ $id . '-post-title' ] = $postdata_post_title_validation_message; } if ( ! empty( $post_content ) && empty( $content ) ) { $postdata_post_content_validation_message = apply_filters( 'forminator_postdata_field_post_content_validation_message', ( ! empty( $setting_required_message ) ? $setting_required_message : esc_html__( 'This field is required. Please enter the post content.', 'forminator' ) ), $id ); $this->validation_message[ $id . '-post-content' ] = $postdata_post_content_validation_message; } if ( ! empty( $post_excerpt ) && empty( $excerpt ) ) { $postdata_post_excerpt_validation_message = apply_filters( 'forminator_postdata_field_post_excerpt_validation_message', ( ! empty( $setting_required_message ) ? $setting_required_message : esc_html__( 'This field is required. Please enter the post excerpt.', 'forminator' ) ), $id ); $this->validation_message[ $id . '-post-excerpt' ] = $postdata_post_excerpt_validation_message; } if ( ! empty( $post_image ) && empty( $image ) ) { $postdata_post_image_validation_message = apply_filters( 'forminator_postdata_field_post_image_validation_message', ( ! empty( $setting_required_message ) ? $setting_required_message : esc_html__( 'This field is required. Please upload a post image.', 'forminator' ) ), $id ); $this->validation_message[ $id . '-post-image' ] = $postdata_post_image_validation_message; } if ( ! empty( $category_list ) ) { foreach ( $category_list as $cat ) { $post_category = self::get_property( $cat['value'], $field, '' ); $category = isset( $data[ $cat['value'] ] ) ? $data[ $cat['value'] ] : ''; if ( ! empty( $post_category ) && empty( $category ) ) { $postdata_post_category_validation_message = apply_filters( 'forminator_postdata_field_' . $cat['value'] . '_validation_message', ( ! empty( $setting_required_message ) ? $setting_required_message : sprintf( /* translators: %s: Category Label */ esc_html__( 'This field is required. Please select a %s.', 'forminator' ), $cat['label'] ) ), $id ); $this->validation_message[ $id . '-' . $cat['value'] ] = $postdata_post_category_validation_message; } } } } } else { // validation for postdata when its not required. // `wp_insert_post` required at least ONE OF THESE to be available title / content / excerpt. // check only when user send some data. if ( ! empty( $data ) && is_array( $data ) ) { if ( ! $title && ! $content && ! $excerpt ) { // check if there is any field with content. $is_content_available = false; foreach ( $data as $datum ) { if ( ! empty( $datum ) ) { $is_content_available = true; break; } } // when $is_content_available false means, field not required, and user didnt put any content on form. if ( $is_content_available ) { // check if on postdata these sub field is avail available. if ( ! empty( $post_title ) ) { $this->validation_message[ $id . '-post-title' ] = apply_filters( // nr = not required. 'forminator_postdata_field_post_title_nr_validation_message', esc_html__( 'At least one of these fields is required: Post Title, Post Excerpt or Post Content.', 'forminator' ), $id ); } if ( ! empty( $post_content ) ) { $this->validation_message[ $id . '-post-content' ] = apply_filters( // nr = not required. 'forminator_postdata_field_post_content_nr_validation_message', esc_html__( 'At least one of these fields is required: Post Title, Post Excerpt or Post Content.', 'forminator' ), $id ); } if ( ! empty( $post_excerpt ) ) { $this->validation_message[ $id . '-post-excerpt' ] = apply_filters( // nr = not required. 'forminator_postdata_field_post_excerpt_nr_validation_message', esc_html__( 'At least one of these fields is required: Post Title, Post Excerpt or Post Content.', 'forminator' ), $id ); } } } } $image_field_name = $id . '-post-image'; if ( ! empty( $post_image ) && isset( $_FILES[ $image_field_name ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( isset( $_FILES[ $image_field_name ]['name'] ) && ! empty( $_FILES[ $image_field_name ]['name'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing $file_name = sanitize_file_name( $_FILES[ $image_field_name ]['name'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing $valid = wp_check_filetype( $file_name ); if ( false === $valid['ext'] || ! in_array( $valid['ext'], $this->image_extensions, true ) ) { $this->validation_message[ $image_field_name ] = apply_filters( 'forminator_postdata_field_post_image_nr_validation_message', esc_html__( 'Uploaded file\'s extension is not allowed.', 'forminator' ), $id ); } } } } } /** * Upload post image * * @since 1.0 * * @param array $field - the field. * @param string $field_name - the field name. * * @return array|bool - if success, return an array */ public function upload_post_image( $field, $field_name ) { $post_image = self::get_property( 'post_image', $field, '' ); if ( empty( $post_image ) ) { return true; } if ( ! empty( $_FILES[ $field_name ]['name'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing $file_name = sanitize_file_name( $_FILES[ $field_name ]['name'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( ! function_exists( 'wp_filesystem' ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; } global $wp_filesystem; if ( ! WP_Filesystem() ) { // Could not initialize the filesystem. return array( 'attachment_id' => 0, 'uploaded_file' => 0, ); } $file_data = $wp_filesystem->get_contents( $_FILES[ $field_name ]['tmp_name'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput $upload_dir = wp_upload_dir(); // Set upload folder. $unique_file_name = wp_unique_filename( $upload_dir['path'], $file_name ); $filename = basename( $unique_file_name ); // Create base file name. if ( wp_mkdir_p( $upload_dir['path'] ) ) { $file = $upload_dir['path'] . '/' . $filename; } else { $file = $upload_dir['basedir'] . '/' . $filename; } // Check image file type. $wp_filetype = wp_check_filetype( $filename, null ); $image_exts = apply_filters( 'forminator_field_postdata_image_file_types', $this->image_extensions ); if ( in_array( (string) $wp_filetype['ext'], $image_exts, true ) ) { // Create the file on the server. if ( $wp_filesystem->put_contents( $file, $file_data, FS_CHMOD_FILE ) ) { // Set attachment data. $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name( $filename ), 'post_content' => '', 'post_status' => 'inherit', ); // Create the attachment. $attachment_id = wp_insert_attachment( $attachment, $file ); self::generate_upload_metadata( $attachment_id, $file ); $uploaded_file = wp_get_attachment_image_src( $attachment_id, 'large', false ); if ( $uploaded_file && is_array( $uploaded_file ) ) { return array( 'attachment_id' => $attachment_id, 'uploaded_file' => $uploaded_file, ); } } } } return array( 'attachment_id' => 0, 'uploaded_file' => 0, ); } /** * Save post * * @since 1.0 * * @param array $field - field array. * @param array $data - post data. * * @return bool|int - success is post id */ public function save_post( $field, $data ) { $post_type = self::get_property( 'post_type', $field, 'post' ); $force_default_author = self::get_property( 'default_author', $field, false ); $force_default_author = filter_var( $force_default_author, FILTER_VALIDATE_BOOLEAN ); // default behavior. if ( is_user_logged_in() ) { $post_author = get_current_user_id(); } else { $post_author = self::get_property( 'select_author', $field, 1 ); if ( empty( $post_author ) || ! get_user_by( 'ID', $post_author ) ) { $post_author = $this->set_anonymous_author(); } } // force to selected author. if ( $force_default_author ) { $post_author = self::get_property( 'select_author', $field, 1 ); } $post_status = self::get_property( 'data_status', $field, 'draft' ); $title = isset( $data['post-title'] ) ? $data['post-title'] : ''; $content = isset( $data['post-content'] ) ? $data['post-content'] : ''; $excerpt = isset( $data['post-excerpt'] ) ? $data['post-excerpt'] : ''; $image = isset( $data['post-image'] ) ? $data['post-image'] : ''; $post_meta = isset( $data['post-custom'] ) ? $data['post-custom'] : ''; $post = array( 'post_author' => $post_author, 'post_content' => wp_kses_post( $content ), 'post_excerpt' => $excerpt, 'post_name' => sanitize_text_field( $title ), 'post_status' => $post_status, 'post_title' => $title, 'post_type' => $post_type, ); $category_list = forminator_post_categories( $post_type ); if ( ! empty( $category_list ) ) { $taxonomy = array(); foreach ( $category_list as $cat ) { $cat_value = $cat['value']; $category = isset( $data[ $cat_value ] ) ? $data[ $cat_value ] : ''; if ( ! empty( $category ) ) { if ( is_array( $category ) ) { $taxonomy[ $cat_value ] = array_map( 'intval', $category ); } else { $taxonomy[ $cat_value ] = array( intval( $category ) ); } } } $post['tax_input'] = $taxonomy; } $post = apply_filters( 'forminator_post_data_post_info', $post, $field, $data ); // trigger wp_error for is_wp_error to be correctly identified. $post_id = wp_insert_post( $post, true ); if ( ! is_wp_error( $post_id ) ) { $category_list = forminator_post_categories( $post_type ); if ( ! empty( $category_list ) ) { foreach ( $category_list as $cat ) { $cat_value = $cat['value']; $category = isset( $data[ $cat_value ] ) ? $data[ $cat_value ] : ''; if ( ! empty( $category ) ) { if ( is_array( $category ) ) { $taxonomy_tags = array_map( 'intval', $category ); } else { $taxonomy_tags = array( intval( $category ) ); } wp_set_post_terms( $post_id, $taxonomy_tags, $cat_value ); } } } $post_image = self::get_property( 'post_image', $field, '' ); if ( ! empty( $post_image ) && ! empty( $image ) && is_array( $image ) ) { set_post_thumbnail( $post_id, $image['attachment_id'] ); } if ( ! empty( $post_meta ) ) { foreach ( $post_meta as $meta ) { add_post_meta( $post_id, $meta['key'], $meta['value'] ); } add_post_meta( $post_id, '_has_forminator_meta', true ); } do_action( 'forminator_post_data_field_post_saved', $post_id, $field, $data, $this ); return $post_id; } return false; } /** * Set anonymous author * * @return int|mixed|WP_Error */ private function set_anonymous_author() { $user = get_user_by( 'login', 'anonymous_user' ); if ( $user ) { return $user->ID; } else { $userdata = array( 'user_login' => 'anonymous_user', // Set different user_nicename and display_name for security. 'user_nicename' => 'anonymous', 'display_name' => 'Anonymous', 'role' => 'author', 'user_pass' => null, ); $new_user = wp_insert_user( $userdata ); if ( ! is_wp_error( $new_user ) ) { return $new_user; } return 1; } } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; $image = ''; $content = ''; // Do not sanitize image URL. if ( isset( $data['post-image'] ) ) { $image = $data['post-image']; } // Do not sanitize post content. if ( isset( $data['post-content'] ) ) { $content = wp_kses_post( $data['post-content'] ); } // Sanitize. $data = forminator_sanitize_array_field( $data ); // Return image url original value. if ( isset( $data['post-image'] ) ) { $data['post-image'] = $image; } // Return post content original value. if ( isset( $data['post-content'] ) ) { $data['post-content'] = $content; } return apply_filters( 'forminator_field_postdata_sanitize', $data, $field, $original_data ); } /** * Return field inline validation rules * Workaround for actually input file is hidden, so its not accessible via standar html5 `required` attribute * * @since 1.1 * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); $post_image = self::get_property( 'post_image', $field, '' ); $post_type = self::get_property( 'post_type', $field, 'post' ); $post_image_enabled = ! empty( $post_image ); $rules = ''; if ( $post_image_enabled ) { $rules .= '"' . $this->get_id( $field ) . '-post-image": {'; if ( $is_required ) { $rules .= '"required": true,'; } $rules .= '},'; } $category_list = forminator_post_categories( $post_type ); if ( ! empty( $category_list ) ) { foreach ( $category_list as $category ) { $post_category_enabled = self::get_property( $category['value'], $field, '' ); if ( $is_required && $post_category_enabled ) { $rules .= '"' . $this->get_id( $field ) . '-' . $category['value'] . '[]": {'; if ( $is_required ) { $rules .= '"required": true,'; } $rules .= '},'; } } } return apply_filters( 'forminator_field_postdata_validation_rules', $rules, $id, $field ); } /** * Return field inline validation messages * * @since 1.1 * @return string */ public function get_validation_messages() { $field = $this->field; $id = $this->get_id( $field ); $is_required = $this->is_required( $field ); $messages = ''; $post_title = self::get_property( 'post_title', $field, '' ); $post_content = self::get_property( 'post_content', $field, '' ); $post_excerpt = self::get_property( 'post_excerpt', $field, '' ); $post_image = self::get_property( 'post_image', $field, '' ); $setting_required_message = self::get_property( 'required_message', $field, '' ); $post_type = self::get_property( 'post_type', $field, 'post' ); $post_title_enabled = ! empty( $post_title ); $post_content_enabled = ! empty( $post_content ); $post_excerpt_enabled = ! empty( $post_excerpt ); $post_image_enabled = ! empty( $post_image ); $category_list = forminator_post_categories( $post_type ); if ( $is_required ) { if ( $post_title_enabled ) { $messages .= '"' . $id . '-post-title": {' . "\n"; $required_message = apply_filters( 'forminator_postdata_field_post_title_validation_message', ( ! empty( $setting_required_message ) ? $setting_required_message : esc_html__( 'This field is required. Please enter the post title.', 'forminator' ) ), $id, $field ); $messages = $messages . '"required": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; $messages .= '},' . "\n"; } if ( $post_content_enabled ) { $messages .= '"' . $id . '-post-content": {' . "\n"; $required_message = apply_filters( 'forminator_postdata_field_post_content_validation_message', ( ! empty( $setting_required_message ) ? $setting_required_message : esc_html__( 'This field is required. Please enter the post content.', 'forminator' ) ), $id, $field ); $messages = $messages . '"required": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; $messages .= '},' . "\n"; } if ( $post_excerpt_enabled ) { $messages .= '"' . $id . '-post-excerpt": {' . "\n"; $required_message = apply_filters( 'forminator_postdata_field_post_excerpt_validation_message', ( ! empty( $setting_required_message ) ? $setting_required_message : esc_html__( 'This field is required. Please enter the post excerpt.', 'forminator' ) ), $id, $field ); $messages = $messages . '"required": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; $messages .= '},' . "\n"; } if ( $post_image_enabled ) { $messages .= '"' . $id . '-post-image": {' . "\n"; $required_message = apply_filters( 'forminator_postdata_field_post_image_validation_message', ( ! empty( $setting_required_message ) ? $setting_required_message : esc_html__( 'This field is required. Please upload a post image.', 'forminator' ) ), $id, $field ); $messages = $messages . '"required": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; $messages .= '},' . "\n"; } if ( ! empty( $category_list ) ) { foreach ( $category_list as $category ) { $post_category_enabled = self::get_property( $category['value'], $field, '' ); if ( $post_category_enabled ) { $post_category_multiple = self::get_property( $category['value'] . '_multiple', $field, '' ); if ( $post_category_multiple ) { $messages .= '"' . $id . '-' . $category['value'] . '[]": {' . "\n"; } else { $messages .= '"' . $id . '-' . $category['value'] . '": {' . "\n"; } $required_message = apply_filters( 'forminator_postdata_field_' . $category['value'] . '_validation_message', ( ! empty( $setting_required_message ) ? $setting_required_message : sprintf( /* translators: %s: Category singular */ esc_html__( 'This field is required. Please select a %s.', 'forminator' ), $category['singular'] ) ), $id, $field ); $messages = $messages . '"required": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; $messages .= '},' . "\n"; } } } } if ( $post_image_enabled ) { $messages .= '"' . $id . '-post-image": {' . "\n"; $messages .= '"extension": "' . forminator_addcslashes( esc_html__( 'Uploaded file\'s extension is not allowed.', 'forminator' ) ) . '",' . "\n"; $messages .= '},' . "\n"; } return $messages; } } PK z~\�d�` ` website.phpnu �[��� <?php /** * The Forminator_Website class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Website * * @since 1.0 */ class Forminator_Website extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'url'; /** * Position * * @var int */ public $position = 5; /** * Type * * @var string */ public $type = 'url'; /** * Options * * @var array */ public $options = array(); /** * Is input * * @var bool */ public $is_input = true; /** * Icon * * @var string */ public $icon = 'sui-icon-web-globe-world'; /** * Forminator_Website constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Website', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'field_label' => esc_html__( 'Website', 'forminator' ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $providers = apply_filters( 'forminator_field_' . $this->slug . '_autofill', array(), $this->slug ); $autofill_settings = array( 'website' => array( 'values' => forminator_build_autofill_providers( $providers ), ), ); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $html = ''; $id = self::get_property( 'element_id', $field ); $name = $id; $id = self::get_field_id( $id ); $required = $this->get_property( 'required', $field, false ); $ariareq = 'false'; $placeholder = $this->sanitize_value( $this->get_property( 'placeholder', $field ) ); $value = esc_html( self::get_post_data( $name, $this->get_property( 'default', $field ) ) ); $label = esc_html( $this->get_property( 'field_label', $field, '' ) ); $description = $this->get_property( 'description', $field, '' ); $design = $this->get_form_style( $settings ); $descr_position = self::get_description_position( $field, $settings ); if ( (bool) $required ) { $ariareq = 'true'; } if ( isset( $draft_value['value'] ) ) { $value = esc_attr( $draft_value['value'] ); } elseif ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $value = $this->get_prefill( $field, $value ); } $website = array( 'type' => 'url', 'name' => $name, 'value' => $value, 'placeholder' => $placeholder, 'id' => $id, 'class' => 'forminator-input forminator-website--field' . ( 'basic' === $design ? ' input-text s' : '' ), 'data-required' => $required, 'aria-required' => $ariareq, ); $html .= '<div class="forminator-field">'; $html .= self::create_input( $website, $label, $description, $required, $descr_position, ); $html .= '</div>'; return apply_filters( 'forminator_field_website_markup', $html, $id, $required, $placeholder, $value ); } /** * Return string with scheme part if needed * * @since 1.1 * * @param string $url URL. * * @return string */ public function add_scheme_url( $url ) { if ( empty( $url ) ) { return $url; } $parts = wp_parse_url( $url ); if ( false !== $parts ) { if ( ! isset( $parts['scheme'] ) ) { $url = 'http://' . $url; } } return $url; } /** * Return field inline validation rules * * @since 1.0 * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $rules = '"' . $this->get_id( $field ) . '": {' . "\n"; $validation_enabled = self::get_property( 'validation', $field, false, 'bool' ); if ( $this->is_required( $field ) ) { $rules .= '"required": true,'; } if ( $validation_enabled ) { $rules .= '"validurl": true,'; } $rules .= '"url": false,'; $rules .= '},' . "\n"; return apply_filters( 'forminator_field_website_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @return string */ public function get_validation_messages() { $field = $this->field; $id = $this->get_id( $field ); $validation_enabled = self::get_property( 'validation', $field, false, 'bool' ); $validation_message = self::get_property( 'validation_message', $field, self::FIELD_PROPERTY_VALUE_NOT_EXIST ); $required_message = self::get_property( 'required_message', $field ); if ( empty( $required_message ) ) { $required_message = esc_html__( 'This field is required. Please input a valid URL', 'forminator' ); } if ( self::FIELD_PROPERTY_VALUE_NOT_EXIST === $validation_message ) { $validation_message = self::get_property( 'validation_text', $field, '' ); } $validation_message = htmlentities( $validation_message ); $messages = '"' . $id . '": {' . "\n"; if ( $this->is_required( $field ) ) { $required_message = apply_filters( 'forminator_website_field_required_validation_message', $required_message, $field, $id ); $messages .= '"required": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } $validation_message = ! empty( $validation_message ) ? $validation_message : esc_html__( 'Please enter a valid Website URL (e.g. https://wpmudev.com/).', 'forminator' ); if ( $validation_enabled ) { $validation_message = apply_filters( 'forminator_website_field_custom_validation_message', $validation_message, $id, $field, $validation_enabled ); } $messages .= '"validurl": "' . forminator_addcslashes( $validation_message ) . '",' . "\n"; $messages .= '},' . "\n"; $messages = apply_filters( 'forminator_website_field_validation_message', $messages, $id, $field, $validation_enabled ); return $messages; } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); $validation_enabled = self::get_property( 'validation', $field, false, 'bool' ); $validation_message = self::get_property( 'validation_message', $field, self::FIELD_PROPERTY_VALUE_NOT_EXIST ); $required_message = self::get_property( 'required_message', $field, esc_html__( 'This field is required. Please input a valid URL.', 'forminator' ) ); if ( self::FIELD_PROPERTY_VALUE_NOT_EXIST === $validation_message ) { $validation_message = self::get_property( 'validation_text', $field, '' ); } $validation_message = htmlentities( $validation_message ); if ( $this->is_required( $field ) ) { if ( empty( $data ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_website_field_required_validation_message', $required_message, $id, $field ); } } if ( $validation_enabled && ! empty( $data ) ) { if ( ! filter_var( $data, FILTER_VALIDATE_URL ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_website_field_custom_validation_message', $validation_message, $id, $field ); } } } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. $data = esc_url_raw( $data ); return apply_filters( 'forminator_field_website_sanitize', $data, $field, $original_data ); } } PK z~\��s�S S gdprcheckbox.phpnu �[��� <?php /** * The Forminator_GdprCheckbox class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_GdprCheckbox * * @since 1.0.5 */ class Forminator_GdprCheckbox extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'gdprcheckbox'; /** * Type * * @var string */ public $type = 'gdprcheckbox'; /** * Position * * @var int */ public $position = 21; /** * Options * * @var array */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon-gdpr'; /** * Forminator_GdprChecbox constructor. * * @since 1.0.5 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'GDPR Approval', 'forminator' ); } /** * Field defaults * * @since 1.0.5 * @return array */ public function defaults() { $privacy_url = get_privacy_policy_url(); $privacy_url = ! empty( $privacy_url ) ? $privacy_url : '#'; return array( 'required' => 'true', 'field_label' => 'GDPR', 'gdpr_description' => sprintf( /* Translators: 1. Opening <a> tag with link to privacy policy, 2. closing <a> tag, 3. Opening <a> tag with #href, 4. closing <a> tag. */ esc_html__( 'Yes, I agree with the %1$sprivacy policy%2$s and %3$sterms and conditions%4$s.', 'forminator' ), '<a href="' . esc_url( $privacy_url ) . '" target="_blank">', '</a>', '<a href="#" target="_blank">', '</a>' ), 'required_message' => esc_html__( 'This field is required. Please check it.', 'forminator' ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { // Unsupported Autofill. $autofill_settings = array(); return $autofill_settings; } /** * Field front-end markup * * @since 1.0.5 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $settings = $views_obj->model->settings; $this->field = $field; $html = ''; $id = self::get_property( 'element_id', $field ); $name = $id; $form_id = isset( $settings['form_id'] ) ? $settings['form_id'] : false; $description = wp_kses_post( forminator_replace_variables( self::get_property( 'gdpr_description', $field ), $form_id ) ); $id = self::get_field_id( $id ); $label = esc_html( self::get_property( 'field_label', $field ) ); $html .= '<div class="forminator-field">'; $html .= self::get_field_label( $label, $id, true ); $html .= sprintf( '<label for="%s" class="forminator-checkbox">', $id ); $html .= sprintf( '<input type="checkbox" name="%s" value="true" id="%s" data-required="true" aria-required="true" />', $name, $id ); $html .= '<span class="forminator-checkbox-box" aria-hidden="true"></span>'; $html .= sprintf( '<span class="forminator-checkbox-label">%s</span>', $description ); $html .= '</label>'; $html .= '</div>'; return apply_filters( 'forminator_field_gdprcheckbox_markup', $html, $id, $description ); } /** * Return field inline validation rules * * @since 1.0.5 * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $rules = '"' . $this->get_id( $field ) . '":{"required":true},'; return apply_filters( 'forminator_field_gdprcheckbox_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0.5 * @return string */ public function get_validation_messages() { $messages = ''; $field = $this->field; $id = $this->get_id( $field ); $required_message = self::get_property( 'required_message', $field, '' ); $required_message = apply_filters( 'forminator_gdprcheckbox_field_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please check it.', 'forminator' ) ), $id, $field ); $messages .= '"' . $this->get_id( $field ) . '": {"required":"' . forminator_addcslashes( $required_message ) . '"},' . "\n"; return $messages; } /** * Field back-end validation * * @since 1.0.5 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { // value of gdpr checkbox is `string` *true*. $id = $this->get_id( $field ); if ( empty( $data ) || 'true' !== $data ) { $this->validation_message[ $id ] = apply_filters( 'forminator_gdprcheckbox_field_required_validation_message', esc_html__( 'This field is required. Please check it.', 'forminator' ), $id, $field ); } } /** * Sanitize data * * @since 1.0.5 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. $data = forminator_sanitize_field( $data ); return apply_filters( 'forminator_field_gdprcheckbox_sanitize', $data, $field, $original_data ); } } PK {~\�Q(�$ �$ captcha.phpnu �[��� <?php /** * The Forminator_Captcha class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Captcha * * @since 1.0 */ class Forminator_Captcha extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'captcha'; /** * Type * * @var string */ public $type = 'captcha'; /** * Position * * @var int */ public $position = 16; /** * Options * * @var array */ public $options = array(); /** * Hide advanced * * @var string */ public $hide_advanced = 'true'; /** * Icon * * @var string */ public $icon = 'sui-icon-recaptcha'; /** * Forminator_Captcha constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Captcha', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'captcha_provider' => 'recaptcha', 'captcha_alignment' => 'left', 'captcha_type' => 'v2_checkbox', 'hcaptcha_type' => 'hc_checkbox', 'score_threshold' => '0.5', 'captcha_badge' => 'bottomright', 'hc_invisible_notice' => sprintf( /* translators: 1. Open <a> tag for Privacy policy, 2. Close </a>, 3. Open <a> tag for Terms of Service, 4. Close </a>. */ esc_html__( 'This site is protected by hCaptcha and its %1$sPrivacy Policy%2$s and %3$sTerms of Service%4$s apply.', 'forminator' ), '<a href="https://hcaptcha.com/privacy">', '</a>', '<a href="https://hcaptcha.com/terms">', '</a>' ), 'recaptcha_error_message' => esc_html__( 'reCAPTCHA verification failed. Please try again.', 'forminator' ), 'hcaptcha_error_message' => esc_html__( 'hCaptcha verification failed. Please try again.', 'forminator' ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { // Unsupported Autofill. $autofill_settings = array(); return $autofill_settings; } /** * Invisible recaptcha * * @param mixed $field Field. * @return mixed */ public function is_invisible_recaptcha( $field ) { // backward. $is_invisible = self::get_property( 'invisible_captcha', $field ); $is_invisible = filter_var( $is_invisible, FILTER_VALIDATE_BOOLEAN ); if ( ! $is_invisible ) { $type = self::get_property( 'captcha_type', $field, '' ); if ( 'invisible' === $type || 'v3_recaptcha' === $type || 'v2_invisible' === $type ) { $is_invisible = true; } } return $is_invisible; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $extra_attrs = ''; $hcaptcha_notice = ''; $provider = self::get_property( 'captcha_provider', $field, 'recaptcha' ); $alignment = self::get_property( 'captcha_alignment', $field, 'left' ); if ( 'recaptcha' === $provider ) { $captcha_type = self::get_property( 'captcha_type', $field, 'v3_recaptcha' ); $captcha_theme = self::get_property( 'captcha_theme', $field, 'light' ); $captcha_size = self::get_property( 'captcha_size', $field, 'normal' ); $captcha_class = 'forminator-captcha-' . $alignment . ' forminator-g-recaptcha'; if ( $this->is_invisible_recaptcha( $field ) ) { $extra_attrs = 'data-badge="' . esc_attr( self::get_property( 'captcha_badge', $field, 'inline' ) ) . '"'; $captcha_size = 'invisible'; $captcha_class .= ' recaptcha-invisible'; } switch ( $captcha_type ) { case 'v2_checkbox': $key = get_option( 'forminator_captcha_key', '' ); break; case 'v2_invisible': $key = get_option( 'forminator_v2_invisible_captcha_key', '' ); break; case 'v3_recaptcha': $key = get_option( 'forminator_v3_captcha_key', '' ); break; } } elseif ( 'turnstile' === $provider ) { $captcha_class = 'forminator-captcha-' . $alignment . ' forminator-turnstile'; $key = get_option( 'forminator_turnstile_key', '' ); $captcha_theme = self::get_property( 'turnstile_theme', $field, 'auto' ); $captcha_size = self::get_property( 'turnstile_size', $field, 'normal' ); $extra_attrs = 'data-language="' . esc_attr( self::get_captcha_language( $field, 'turnstile' ) ) . '"'; } else { $key = get_option( 'forminator_hcaptcha_key', '' ); $captcha_type = self::get_property( 'hcaptcha_type', $field, 'hc_checkbox' ); $captcha_theme = self::get_property( 'hcaptcha_theme', $field, 'light' ); $captcha_size = self::get_property( 'hcaptcha_size', $field, 'normal' ); $captcha_class = 'forminator-captcha-' . $alignment . ' forminator-hcaptcha'; if ( 'hc_invisible' === $captcha_type ) { $captcha_size = 'invisible'; $hcaptcha_notice = self::get_property( 'hc_invisible_notice', $field, '' ); $hcaptcha_notice = sprintf( '<div class="forminator-checkbox__label">%s</div>', wp_kses_post( $hcaptcha_notice ) ); } } // don't use .g-recaptcha class as it will render automatically when other plugin load recaptcha with default render. return sprintf( '<div class="%s" data-theme="%s" %s data-sitekey="%s" data-size="%s"></div> %s', esc_attr( $captcha_class ), esc_attr( $captcha_theme ), $extra_attrs, esc_attr( $key ), esc_attr( $captcha_size ), $hcaptcha_notice ); } /** * Get captcha language * * @param array $field Field settings. * @param string $provider Captcha provider. * * @return string */ public static function get_captcha_language( $field, $provider = '' ) { $site_language = get_locale(); $captcha_language = get_option( 'forminator_captcha_language', '' ); $global_language = ! empty( $captcha_language ) ? $captcha_language : $site_language; $language = self::get_property( 'language', $field ); $language = ! empty( $language ) ? $language : $global_language; if ( 'turnstile' === $provider ) { $language = strtolower( str_replace( '_', '-', $language ) ); } return $language; } /** * Mark Captcha unavailable when captcha key not available * * @since 1.0.3 * * @param array $field Field. * * @return bool */ public function is_available( $field ) { $provider = self::get_property( 'captcha_provider', $field, 'recaptcha' ); $captcha_type = self::get_property( 'captcha_type', $field, '' ); if ( 'recaptcha' === $provider ) { switch ( $captcha_type ) { case 'v2_invisible': $key = get_option( 'forminator_v2_invisible_captcha_key', '' ); break; case 'v3_recaptcha': $key = get_option( 'forminator_v3_captcha_key', '' ); break; default: $key = get_option( 'forminator_captcha_key', '' ); } } elseif ( 'turnstile' === $provider ) { $key = get_option( 'forminator_turnstile_key', '' ); } else { $key = get_option( 'forminator_hcaptcha_key', '' ); } if ( ! $key ) { return false; } return true; } /** * Validate captcha * * @since 1.5.3 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $element_id = self::get_property( 'element_id', $field ); $provider = self::get_property( 'captcha_provider', $field, 'recaptcha' ); $captcha_type = self::get_property( 'captcha_type', $field, '' ); $score = ''; if ( 'recaptcha' === $provider ) { if ( 'v2_checkbox' === $captcha_type ) { $secret = get_option( 'forminator_captcha_secret', '' ); } elseif ( 'v2_invisible' === $captcha_type ) { $secret = get_option( 'forminator_v2_invisible_captcha_secret', '' ); } elseif ( 'v3_recaptcha' === $captcha_type ) { $secret = get_option( 'forminator_v3_captcha_secret', '' ); $score = self::get_property( 'score_threshold', $field, '' ); } $error_message = self::get_property( 'recaptcha_error_message', $field, '' ); } elseif ( 'turnstile' === $provider ) { $secret = get_option( 'forminator_turnstile_secret', '' ); $error_message = self::get_property( 'turnstile_error_message', $field, '' ); } else { // hcaptcha. $secret = get_option( 'forminator_hcaptcha_secret', '' ); $error_message = self::get_property( 'hcaptcha_error_message', $field, '' ); } $captcha = new Forminator_Captcha_Verification( $secret, $provider ); $verify = $captcha->verify( $data, null, $score ); if ( is_wp_error( $verify ) ) { $invalid_captcha_message = ( ! empty( $error_message ) ? $error_message : esc_html__( 'Captcha verification failed. Please try again.', 'forminator' ) ); /** * Filter message displayed for invalid captcha * * @since 1.5.3 * * @param string $invalid_captcha_message * @param string $element_id * @param array $field * @param WP_Error $verify */ $invalid_captcha_message = apply_filters( 'forminator_invalid_captcha_message', $invalid_captcha_message, $element_id, $field, $verify ); $this->validation_message[ $element_id ] = $invalid_captcha_message; } } } PK {~\�L�R group.phpnu �[��� <?php /** * The Forminator_Group class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Group */ class Forminator_Group extends Forminator_Field { /** * Default field title * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'group'; /** * Type * * @var string */ public $type = 'group'; /** * Position this field type on Add Field popup * * @var int */ public $position = 26; /** * Options * * @var array */ public $options = array(); /** * Icon CSS class * * @var string */ public $icon = 'sui-icon forminator-icon-group'; /** * Forminator_Group constructor. */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Field Group', 'forminator' ); } /** * Field defaults * * @return array */ public function defaults() { return array( 'field_label' => esc_html__( 'Field Group', 'forminator' ), 'is_repeater' => 'true', ); } /** * Autofill Setting * * @param array $settings Field settings. * * @return array */ public function autofill_settings( $settings = array() ) { // Unsupported Autofill. $autofill_settings = array(); return $autofill_settings; } /** * Field front-end markup * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $name = self::get_property( 'element_id', $field ); $wrappers = $views_obj::get_grouped_wrappers( $name ); $options = self::prepare_field_options( $field ); $settings = $views_obj->model->settings; $html = ''; if ( ! empty( $field['field_label'] ) ) { $html .= sprintf( '<label class="forminator-label forminator-repeater-label">%s</label>', esc_html( $field['field_label'] ) ); } $description = self::get_property( 'description', $field ); $descr_position = self::get_description_position( $field, $settings ); if ( ! empty( $description ) && 'above' === $descr_position ) { $html .= apply_filters( 'forminator_field_description', sprintf( '<span class="forminator-description forminator-repeater-description">%s</span>', self::esc_description( $description, $name ) ), $description, $name, $descr_position ); } $html .= '<div class="forminator-all-group-copies' . ( ! empty( $field['group_styles'] ) && 'custom' === $field['group_styles'] ? '' : ' forminator-repeater-field' ) . '">'; $i = 1; do { $html .= '<div class="forminator-grouped-fields" data-options="' . esc_attr( wp_json_encode( $options ) ) . '">'; if ( 1 < $i ) { $wrappers = array_map( function ( $wrapper ) use ( $i ) { if ( empty( $wrapper['fields'] ) ) { return $wrapper; } $wrapper['fields'] = array_map( function ( $field ) use ( $i ) { $field['group_suffix'] = '-' . $i; return $field; }, $wrapper['fields'] ); return $wrapper; }, $wrappers ); $html .= '<input name="' . esc_attr( $name ) . '-copies[]" type="hidden" value="' . intval( $i ) . '" />'; } $html .= $views_obj->render_wrappers( $wrappers ); if ( $options['is_repeater'] && ( 'custom' !== $options['min_type'] || 'custom' !== $options['max_type'] || $options['max'] > $options['min'] ) ) { $html .= self::render_action_buttons( $options ); } $html .= '</div>'; } while ( ! empty( $views_obj->draft_data[ $name . '-copies' ] ) && $views_obj->draft_data[ $name . '-copies' ]['value'] >= ( ++$i ) ); $html .= '</div>'; if ( 'above' !== $descr_position ) { $html .= apply_filters( 'forminator_field_description', self::get_description( $description, $name, $descr_position ), $description, $name, $descr_position ); } return $html; } /** * Prepare field options * * @param array $field Field options. * @return array */ private static function prepare_field_options( $field ) { $min_limit_type = empty( $field['min_limit_type'] ) || 'variable' !== $field['min_limit_type'] ? 'custom' : $field['min_limit_type']; $max_limit_type = empty( $field['max_limit_type'] ) || 'variable' !== $field['max_limit_type'] ? 'custom' : $field['max_limit_type']; if ( 'custom' === $min_limit_type ) { $min = empty( $field['min_limit'] ) || 1 > intval( $field['min_limit'] ) ? 1 : intval( $field['min_limit'] ); } else { $min = empty( $field['min_limit_field'] ) ? 1 : $field['min_limit_field']; } if ( 'custom' === $max_limit_type ) { $max = empty( $field['max_limit'] ) || 1 > intval( $field['max_limit'] ) ? PHP_INT_MAX : intval( $field['max_limit'] ); } else { $max = empty( $field['max_limit_field'] ) ? PHP_INT_MAX : $field['max_limit_field']; } return array( 'is_repeater' => empty( $field['is_repeater'] ) || 'true' === $field['is_repeater'], 'min_type' => $min_limit_type, 'max_type' => $max_limit_type, 'min' => $min, 'max' => $max, 'add_text' => empty( $field['add_action_text'] ) ? esc_html__( 'Add item', 'forminator' ) : $field['add_action_text'], 'remove_text' => empty( $field['remove_action_text'] ) ? esc_html__( 'Remove item', 'forminator' ) : $field['remove_action_text'], 'action_element_type' => empty( $field['action_element_type'] ) ? 'button' : $field['action_element_type'], ); } /** * Get Repeater actions * * @param array $options Field options. * @return string */ private static function render_action_buttons( $options ) { $html = '<div class="forminator-row forminator-action-buttons">'; $html .= '<div class="forminator-col forminator-col-12">'; if ( 'icon' === $options['action_element_type'] ) { // Icons. $html .= '<button class="forminator-repeater-action-icon forminator-repeater-add"><span class="forminator-icon-add" aria-hidden="true"></span><span class="sui-screen-reader-text">' . esc_html( $options['add_text'] ) . '</span></button>'; $html .= '<button class="forminator-repeater-action-icon forminator-repeater-remove"><span class="forminator-icon-remove" aria-hidden="true"></span><span class="sui-screen-reader-text">' . esc_html( $options['remove_text'] ) . '</span></button>'; } elseif ( 'link' === $options['action_element_type'] ) { // Links. $html .= '<a href="#" class="forminator-repeater-action-link forminator-repeater-add">' . esc_html( $options['add_text'] ) . '</a>'; $html .= '<a href="#" class="forminator-repeater-action-link forminator-repeater-remove">' . esc_html( $options['remove_text'] ) . '</a>'; } else { // Buttons. $html .= '<input type="button" value="' . esc_attr( $options['add_text'] ) . '" class="forminator-repeater-action-button forminator-repeater-add" />'; $html .= '<input type="button" value="' . esc_attr( $options['remove_text'] ) . '" class="forminator-repeater-action-button forminator-repeater-remove" />'; } $html .= '</div>'; $html .= '</div>'; return $html; } } PK |~\�� :� � stripe-payment-element.phpnu �[��� <?php /** * The Forminator_Stripe_Payment_Element class. * It uses Stripe Payment Element to process payment. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Stripe_Payment_Element * * @since 1.37 */ class Forminator_Stripe_Payment_Element extends Forminator_Field { /** * Slug * * @var string */ public $slug = 'stripe-ocs'; /** * Type * * @var string */ public $type = 'stripe-ocs'; /** * Position * * @var int */ public $position = 23; /** * Icon * * @var string */ public $icon = 'sui-icon forminator-icon-stripe'; /** * Is connected * * @var bool */ public $is_connected = false; /** * Mode * * @var string */ public $mode = 'test'; /** * Payment plan * * @var array */ public $payment_plan = array(); /** * Forminator_Stripe constructor. */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Stripe', 'forminator' ); try { $stripe = new Forminator_Gateway_Stripe(); if ( $stripe->is_test_ready() && $stripe->is_live_ready() ) { $this->is_connected = true; } } catch ( Forminator_Gateway_Exception $e ) { $this->is_connected = false; } } /** * Field defaults * * @return array */ public function defaults() { $default_currency = 'USD'; try { $stripe = new Forminator_Gateway_Stripe(); $default_currency = $stripe->get_default_currency(); } catch ( Forminator_Gateway_Exception $e ) { forminator_maybe_log( __METHOD__, $e->getMessage() ); } return array( 'field_label' => esc_html__( 'Credit / Debit Card', 'forminator' ), 'mode' => 'test', 'currency' => $default_currency, 'company_name' => '', 'product_description' => '', 'customer_email' => '', 'receipt' => '', 'billing' => '', 'language' => 'auto', 'options' => array(), 'payments' => array( array( 'plan_name' => esc_html__( 'Plan 1', 'forminator' ), 'payment_method' => 'single', 'amount_type' => 'fixed', 'amount' => '', 'subscription_amount_type' => 'fixed', 'quantity_type' => 'fixed', 'quantity' => '1', 'bill_input' => '1', ), ), 'primary_color' => '#0570DE', 'background_color' => '#FFFFFF', 'text_color' => '#30313D', 'error' => '#DF1B41', 'automatic_payment_methods' => 'true', ); } /** * Migrate stripe settings * * @param array $stripe_field Old stripe field. * * @return array */ public function migrate_stripe_settings( $stripe_field ) { // Merge default settings with old stripe field. $new_stripe_field = array_merge( $this->defaults(), $stripe_field ); // Update stripe-ocs settings. $new_stripe_field['id'] = 'stripe-ocs-1'; $new_stripe_field['element_id'] = 'stripe-ocs-1'; $new_stripe_field['type'] = 'stripe-ocs'; $new_stripe_field['automatic_payment_methods'] = 'false'; $new_stripe_field['form_id'] = 'wrapper-0000-0000'; $new_stripe_field['wrapper_id'] = 'wrapper-0000-0000'; $new_stripe_field['receipt'] = 'true' === $new_stripe_field['receipt'] ? '1' : ''; $new_stripe_field['billing'] = 'true' === $new_stripe_field['billing'] ? '1' : ''; // Remove unused settings. unset( $new_stripe_field['card_icon'], $new_stripe_field['verify_zip'], $new_stripe_field['zip_field'], $new_stripe_field['base_class'], $new_stripe_field['complete_class'], $new_stripe_field['empty_class'], $new_stripe_field['focused_class'], $new_stripe_field['invalid_class'], $new_stripe_field['autofilled_class'], ); return $new_stripe_field; } } PK |~\1��=`= `= phone.phpnu �[��� <?php /** * The Forminator_Phone class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Phone * * @since 1.0 */ class Forminator_Phone extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'phone'; /** * Position * * @var int */ public $position = 3; /** * Type * * @var string */ public $type = 'phone'; /** * Options * * @var array */ public $options = array(); /** * Is input * * @var bool */ public $is_input = true; /** * Has counter * * @var bool */ public $has_counter = true; /** * Icon * * @var string */ public $icon = 'sui-icon-phone'; /** * Forminator_Phone constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Phone', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return apply_filters( 'forminator_phone_defaults_settings', array( 'required' => false, 'limit' => 10, 'limit_type' => 'characters', 'validation' => 'none', 'field_label' => esc_html__( 'Phone', 'forminator' ), ) ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $providers = apply_filters( 'forminator_field_' . $this->slug . '_autofill', array(), $this->slug ); $autofill_settings = array( 'phone' => array( 'values' => forminator_build_autofill_providers( $providers ), ), ); return $autofill_settings; } /** * Phone formats * * @since 1.0 * @since 1.5.1 add regex for international phone number * @return array */ public function get_phone_formats() { $phone_formats = array( 'standard' => array( 'label' => '(###) ###-####', 'mask' => '(999) 999-9999', /** * Match jquery-validation phoneUS validation * https://github.com/jquery-validation/jquery-validation/blob/1.17.0/src/additional/phoneUS.js#L20 */ 'regex' => '/^(\d|\s|\(|\)|\-|\.|\+){5,20}$/', 'instruction' => esc_html__( 'Please make sure the number has a national format.', 'forminator' ), ), 'international' => array( 'label' => esc_html__( 'International', 'forminator' ), 'mask' => '(123) 456-789', /** * Allowed `+`, but only on first character * allowed `{`, `)`, `_space_`, `-` and `digits` * allowed 10-20 in total characters */ 'regex' => '/^(\+){0,1}(\d|\s|\(|\)|\-){10,20}$/', 'instruction' => esc_html__( 'Please make sure the number has an international format.', 'forminator' ), ), ); return apply_filters( 'forminator_phone_formats', $phone_formats ); } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $descr_position = self::get_description_position( $field, $settings ); $html = ''; $id = self::get_property( 'element_id', $field ); $name = $id; $id = self::get_field_id( $id ); $required = self::get_property( 'required', $field, false, 'bool' ); $ariareq = 'false'; $placeholder = $this->sanitize_value( self::get_property( 'placeholder', $field ) ); $value = esc_html( self::get_property( 'value', $field ) ); $national_country = self::get_property( 'phone_national_country', $field, 'AF' ); $international_country = self::get_property( 'phone_international_country', $field, 'US' ); $limit = esc_html( self::get_property( 'limit', $field, 10 ) ); $label = esc_html( self::get_property( 'field_label', $field, '' ) ); $description = self::get_property( 'description', $field, '' ); $format_check = self::get_property( 'validation', $field, self::FIELD_PROPERTY_VALUE_NOT_EXIST ); $description_block = ''; if ( ! empty( $description ) || ( 'character_limit' === $format_check && 0 < $limit ) ) { $description_block .= sprintf( '<span id="' . esc_attr( $id . '-description' ) . '" class="forminator-description" id="%s">', $id . '-description' ); if ( ! empty( $description ) ) { $description_block .= wp_kses_data( $description ); } if ( 'character_limit' === $format_check && 0 < $limit ) { $description_block .= sprintf( '<span data-limit="%s" data-type="%s">0 / %s</span>', $limit, '', $limit ); } $description_block .= '</span>'; } $description_block = apply_filters( 'forminator_field_description', $description_block, $description, $id, $descr_position ); if ( (bool) $required ) { $ariareq = 'true'; } if ( self::FIELD_PROPERTY_VALUE_NOT_EXIST === $format_check ) { // read old attribute. $phone_check = self::get_property( 'phone_validation', $field, false, 'bool' ); $format_check = false === $phone_check ? 'none' : ''; } if ( isset( $draft_value['value'] ) ) { $value = esc_attr( $draft_value['value'] ); } elseif ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $value = $this->get_prefill( $field, $value ); // If validation is not international, replace 1st space with plus. if ( 'international' !== $format_check ) { $value = 0 === strpos( $value, ' ' ) ? str_replace( ' ', '+', $value ) : trim( $value ); } } $phone_attr = array( 'type' => 'text', 'name' => $name, 'value' => $value, 'placeholder' => $placeholder, 'id' => $id, 'class' => 'forminator-input forminator-field--phone', 'data-required' => $required, 'aria-required' => $ariareq, 'autocomplete' => 'off', ); if ( wp_is_mobile() ) { $phone_attr['inputmode'] = 'numeric'; } if ( 'none' !== $format_check ) { if ( 'character_limit' === $format_check && 0 < $limit ) { $phone_attr['maxlength'] = $limit; } elseif ( 'standard' === $format_check ) { $phone_attr['data-national_mode'] = 'enabled'; if ( $national_country ) { $phone_attr['data-country'] = $national_country; } } elseif ( 'international' === $format_check ) { $phone_attr['data-national_mode'] = 'disabled'; if ( $international_country ) { $phone_attr['data-country'] = $international_country; } } $phone_attr['data-validation'] = $format_check; } if ( ! empty( $description ) ) { $phone_attr['aria-describedby'] = esc_attr( $id . '-description' ); } $html .= '<div class="forminator-field">'; $html .= self::get_field_label( $label, $id, $required ); if ( 'above' === $descr_position ) { $html .= $description_block; } $html .= self::create_input( $phone_attr, '', '', $required ); if ( 'above' !== $descr_position ) { $html .= $description_block; } $html .= '</div>'; return apply_filters( 'forminator_field_phone_markup', $html, $id, $required, $placeholder, $value ); } /** * Return field inline validation rules * * @since 1.0 * @since 1.5.1 add forminatorPhoneInternational for jQueryValidation * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $limit = self::get_property( 'limit', $field, 10 ); $format_check = self::get_property( 'validation', $field, self::FIELD_PROPERTY_VALUE_NOT_EXIST ); if ( self::FIELD_PROPERTY_VALUE_NOT_EXIST === $format_check ) { // read old attribute. $phone_check = self::get_property( 'phone_validation', $field, false, 'bool' ); $format_check = false === $phone_check ? 'none' : ''; } $rules = '"' . $this->get_id( $field ) . '": {'; if ( $this->is_required( $field ) ) { $rules .= '"required": true,'; $rules .= '"trim": true,'; } // standard means phoneUS. if ( 'none' !== $format_check ) { if ( 'standard' === $format_check ) { $rules .= '"forminatorPhoneNational": true,'; } elseif ( 'character_limit' === $format_check ) { $rules .= '"maxlength": ' . $limit . ','; } elseif ( 'international' === $format_check ) { $rules .= '"forminatorPhoneInternational": true,'; } } $rules .= '},'; return apply_filters( 'forminator_field_phone_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @since 1.5.1 add `international` phone * @return string */ public function get_validation_messages() { $field = $this->field; $format_check = self::get_property( 'validation', $field, self::FIELD_PROPERTY_VALUE_NOT_EXIST ); if ( self::FIELD_PROPERTY_VALUE_NOT_EXIST === $format_check ) { // read old attribute. $phone_check = self::get_property( 'phone_validation', $field, false, 'bool' ); $format_check = false === $phone_check ? 'none' : ''; } $validation_message = self::get_property( 'validation_message', $field, '' ); $messages = '"' . $this->get_id( $field ) . '": {' . "\n"; if ( $this->is_required( $field ) ) { $required_message = self::get_property( 'required_message', $field ); if ( empty( $required_message ) ) { $required_message = esc_html__( 'This field is required. Please input a phone number.', 'forminator' ); } $required_message = apply_filters( 'forminator_field_phone_required_validation_message', $required_message, $field, $format_check, $this ); $messages .= '"required": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; $required_message = apply_filters( 'forminator_field_phone_trim_validation_message', $required_message, $field, $format_check, $this ); $messages .= '"trim": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } if ( 'none' !== $format_check ) { if ( 'standard' === $format_check ) { $validation_message = apply_filters( 'forminator_field_phone_phoneUS_validation_message', // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase ( ! empty( $validation_message ) ? $validation_message : esc_html__( 'Please input a valid phone number.', 'forminator' ) ), $field, $format_check, $this ); $messages .= '"forminatorPhoneNational": "' . forminator_addcslashes( $validation_message ) . '",' . "\n"; } elseif ( 'character_limit' === $format_check ) { $validation_message = apply_filters( 'forminator_field_phone_maxlength_validation_message', ( ! empty( $validation_message ) ? $validation_message : esc_html__( 'You exceeded the allowed amount of numbers. Please check again.', 'forminator' ) ), $field, $format_check, $this ); $messages .= '"maxlength": "' . forminator_addcslashes( $validation_message ) . '",' . "\n"; } elseif ( 'international' === $format_check ) { $validation_message = apply_filters( 'forminator_field_phone_internation_validation_message', ( ! empty( $validation_message ) ? $validation_message : esc_html__( 'Please input a valid international phone number.', 'forminator' ) ), $field, $format_check, $this ); $messages .= '"forminatorPhoneInternational": "' . forminator_addcslashes( $validation_message ) . '",' . "\n"; } } $phone_message = apply_filters( 'forminator_field_phone_invalid_validation_message', ( ! empty( $validation_message ) ? $validation_message : esc_html__( 'Please enter a valid phone number.', 'forminator' ) ), $field, $format_check, $this ); $messages .= '"phone": "' . forminator_addcslashes( $phone_message ) . '",' . "\n"; $messages .= '},' . "\n"; return $messages; } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. * * @return bool */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); if ( $this->is_required( $field ) ) { if ( empty( $data ) ) { $required_message = self::get_property( 'required_message', $field, esc_html__( 'This field is required. Please input a phone number.', 'forminator' ) ); $this->validation_message[ $id ] = apply_filters( 'forminator_field_phone_required_field_validation_message', $required_message, $id, $field, $data, $this ); return false; } } // if data is empty, no need to `$format_check`. if ( empty( $data ) ) { return true; } // enable phone validation if `phone_validation` property enabled and data not empty, even the field is not required. $format_check = self::get_property( 'validation', $field, self::FIELD_PROPERTY_VALUE_NOT_EXIST ); if ( self::FIELD_PROPERTY_VALUE_NOT_EXIST === $format_check ) { // read old attribute. $phone_check = self::get_property( 'phone_validation', $field, false, 'bool' ); $format_check = false === $phone_check ? 'none' : ''; } $validation_message = self::get_property( 'validation_message', $field, '' ); if ( 'none' !== $format_check ) { if ( 'character_limit' === $format_check ) { $limit = isset( $field['limit'] ) ? intval( $field['limit'] ) : 10; if ( strlen( $data ) > $limit ) { $this->validation_message[ $id ] = apply_filters( 'forminator_field_phone_limit_validation_message', ( ! empty( $validation_message ) ? $validation_message : esc_html__( 'You exceeded the allowed amount of numbers. Please check again.', 'forminator' ) ), $id, $field, $data, $this ); return false; } } else { $formats = $this->get_phone_formats(); if ( isset( $formats[ $format_check ] ) ) { $validation_type = $formats[ $format_check ]; if ( $validation_type['regex'] && ! preg_match( $validation_type['regex'], $data ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_field_phone_format_validation_message', ( ! empty( $validation_message ) ? $validation_message : sprintf( /* translators: %s: Validate instruction */ esc_html__( 'Invalid phone number. %s', 'forminator' ), $validation_type['instruction'] ) ), $validation_type['instruction'] ); return false; } } } if ( preg_match( '/[a-z]|[^\w\-()+. ]|[\-()+.]{2,}/i', $data ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_field_phone_invalid_validation_message', ( ! empty( $validation_message ) ? $validation_message : esc_html__( 'Please enter a valid phone number.', 'forminator' ) ), $id, $field, $data, $this ); return false; } } return true; } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. $data = forminator_sanitize_field( $data ); return apply_filters( 'forminator_field_phone_sanitize', $data, $field, $original_data ); } } PK }~\cvX�z z section.phpnu �[��� <?php /** * The Forminator_Section class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Section * * @since 1.0 */ class Forminator_Section extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'section'; /** * Type * * @var string */ public $type = 'section'; /** * Position * * @var int */ public $position = 20; /** * Options * * @var string */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon-inlinecss'; /** * Forminator_Section constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Section', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'section_title' => esc_html__( 'Form Section', 'forminator' ), 'cform-section-border-style' => 'none', ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { // Unsupported Autofill. $autofill_settings = array(); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $this->field = $field; $html = ''; $id = self::get_property( 'element_id', $field ); $id = $id . '-field'; $title = esc_html( self::get_property( 'section_title', $field ) ); $subtitle = esc_html( self::get_property( 'section_subtitle', $field ) ); $border = self::get_property( 'section_border', $field, 'none' ); $border_width = self::get_property( 'cform-section-border-width', $field, 1 ); $border_color = self::get_property( 'cform-section-border-color', $field, 1 ); $html .= '<div class="forminator-field">'; if ( ! empty( $title ) ) { $title = wp_specialchars_decode( $title ); $html .= sprintf( '<h2 class="forminator-title">%s</h2>', $this->sanitize_output( $title ) ); } if ( ! empty( $subtitle ) ) { $subtitle = wp_specialchars_decode( $subtitle ); $html .= sprintf( '<h3 class="forminator-subtitle">%s</h3>', $this->sanitize_output( $subtitle ) ); } if ( 'none' !== $border ) { $border_width = self::get_property( 'cform-section-border-width', $field, 1 ); $border_color = self::get_property( 'cform-section-border-color', $field, 1 ); $html .= sprintf( '<hr class="forminator-border" style="border: %s %s %s;" />', $border_width . 'px', $border, $border_color ); } $html .= '</div>'; return apply_filters( 'forminator_field_section_markup', $html, $field ); } /** * Return sanitized form data * * @since 1.0 * * @param string $content Content. * * @return mixed */ public function sanitize_output( $content ) { return esc_html( $content ); } } PK }~\^�<F6 6 rating.phpnu �[��� <?php /** * The Forminator_Rating class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Rating * * @property array field * @since 1.32 */ class Forminator_Rating extends Forminator_Field { /** * Slug * * @var string */ public $slug = 'rating'; /** * Type * * @var string */ public $type = 'rating'; /** * Position * * @var int */ public $position = 28; /** * Options * * @var string */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon-star'; /** * Forminator_Rating constructor. */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Rating', 'forminator' ); } /** * Field defaults * * @return array * @since 1.32.0 */ public function defaults(): array { return array( 'validation' => false, 'field_label' => esc_html__( 'Rating', 'forminator' ), 'max_rating' => 5, 'suffix' => true, 'icon' => 'star', 'size' => 'md', ); } /** * Autofill Setting * * @param array $settings Settings. * * @return array * @since 1.32.0 */ public function autofill_settings( $settings = array() ): array { return array(); } /** * Field front-end markup * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array|null $draft_value Draft value(s). * * @return string * @since 1.32 */ public function markup( $field, $views_obj, $draft_value = array() ): string { $this->field = $field; $name = self::get_property( 'element_id', $field ); $id = self::get_field_id( $name ); $required = self::get_property( 'required', $field, false ); $label = self::get_property( 'field_label', $field ); $description = self::get_property( 'description', $field ); $icon = self::get_property( 'icon', $field, 'star' ); $size = self::get_property( 'size', $field, 'md' ); $max_rating = self::get_property( 'max_rating', $field, 5 ); $suffix = self::get_property( 'suffix', $field, true ); $settings = $views_obj->model->settings; $descr_position = self::get_description_position( $field, $settings ); $value = 0; if ( isset( $draft_value['value'] ) ) { $rating_value = explode( '/', $draft_value['value'] )[0] ?? 0; $value = esc_html( $rating_value ); } $attributes = array( 'name' => $name, 'id' => $id, 'class' => 'forminator-rating', 'aria-errormessage' => $id . '-error', 'data-type' => $icon, 'data-size' => $size, 'data-suffix' => $suffix ? 'true' : 'false', ); if ( ! empty( $description ) ) { $attributes['aria-describedby'] = $id . '-description'; } $options = array( array( 'value' => 0, 'label' => 0, 'disabled' => true, ), ); $maximum_rating = max( 0, min( $max_rating, 50 ) ); for ( $rating = 1; $rating <= $maximum_rating; $rating++ ) { $options[] = array( 'value' => $rating, 'label' => $rating, 'disabled' => false, ); } $html = '<div class="forminator-field">'; $html .= self::create_select( $attributes, $label, $options, $value, $description, $required, $descr_position, ); $html .= '</div>'; return apply_filters( 'forminator_field_rating_markup', $html, $field ); } /** * Return field inline validation rules * * @return string * @since 1.32 */ public function get_validation_rules(): string { $field = $this->field; $rules = '"' . $this->get_id( $field ) . '": {' . "\n"; if ( $this->is_required( $field ) ) { $rules .= '"required": true,'; } $rules .= '},' . "\n"; return apply_filters( 'forminator_field_rating_validation_rules', $rules, $this->get_id( $field ), $field ); } /** * Return field inline validation errors * * @return string * @since 1.32 */ public function get_validation_messages(): string { $message = ''; $field = $this->field; if ( $this->is_required( $field ) ) { $required_message = self::get_property( 'required_message', $field, '' ); $required_message = apply_filters( 'forminator_rating_field_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please select a rating.', 'forminator' ) ), $this->get_id( $field ), $field ); $message = '"' . $this->get_id( $field ) . '": {"required":"' . forminator_addcslashes( $required_message ) . '"},' . "\n"; } return $message; } /** * Field back-end validation * * @param array $field Field settings. * @param array|string $data Data to validate. * * @return bool */ public function validate( $field, $data ): bool { $id = self::get_property( 'element_id', $field ); $rating_value = explode( '/', $data )[0] ?? 0; if ( $this->is_required( $field ) ) { $required_error_message = $this->get_field_multiple_required_message( $id, $field, 'required_message', '', esc_html__( 'This field is required. Please select a rating.', 'forminator' ) ); if ( empty( $rating_value ) ) { $this->validation_message[ $id ] = $required_error_message; return false; } } return true; } /** * Sanitize field value * * @param array $field Field settings. * @param array|string $data Data to sanitize. * * @return string */ public function sanitize( $field, $data ): string { // Sanitize. return esc_html( $data ); } } PK ~\�}���: �: radio.phpnu �[��� <?php /** * The Forminator_Radio class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_SingleValue * * @property array field * @since 1.0 */ class Forminator_Radio extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'radio'; /** * Type * * @var string */ public $type = 'radio'; /** * Position * * @var int */ public $position = 9; /** * Options * * @var array */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon-element-radio'; /** * Is calculable * * @var bool */ public $is_calculable = true; /** * Forminator_SingleValue constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Radio', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'value_type' => 'radio', 'field_label' => esc_html__( 'Radio', 'forminator' ), 'layout' => 'vertical', 'options' => array( array( 'label' => esc_html__( 'Option 1', 'forminator' ), 'value' => 'one', 'key' => forminator_unique_key(), ), array( 'label' => esc_html__( 'Option 2', 'forminator' ), 'value' => 'two', 'key' => forminator_unique_key(), ), ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $providers = apply_filters( 'forminator_field_' . $this->slug . '_autofill', array(), $this->slug ); $autofill_settings = array( 'select' => array( 'values' => forminator_build_autofill_providers( $providers ), ), ); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $i = 1; $html = ''; $id = self::get_property( 'element_id', $field ); $name = $id; $id = 'forminator-field-' . $id; $required = self::get_property( 'required', $field, false ); $ariareq = 'false'; $options = self::get_options( $field ); $value_type = isset( $field['value_type'] ) ? trim( $field['value_type'] ) : 'multiselect'; $post_value = self::get_post_data( $name, false ); $description = self::get_property( 'description', $field, '' ); $label = esc_html( self::get_property( 'field_label', $field, '' ) ); $design = $this->get_form_style( $settings ); $calc_enabled = self::get_property( 'calculations', $field, false, 'bool' ); $images_enabled = self::get_property( 'enable_images', $field, false ); $images_enabled = filter_var( $images_enabled, FILTER_VALIDATE_BOOLEAN ); $input_visibility = self::get_property( 'input_visibility', $field, 'true' ); $input_visibility = filter_var( $input_visibility, FILTER_VALIDATE_BOOLEAN ); $hidden_behavior = self::get_property( 'hidden_behavior', $field ); $descr_position = self::get_description_position( $field, $settings ); $prefil_valid = false; $draft_valid = false; $post_valid = false; $default = ''; $uniq_id = Forminator_CForm_Front::$uid; $descr_id = 'forminator-radiogroup-' . $name . '-' . $uniq_id; if ( (bool) $required ) { $ariareq = 'true'; } $hidden_calc_behavior = ''; if ( $hidden_behavior && 'zero' === $hidden_behavior ) { $hidden_calc_behavior = ' data-hidden-behavior="' . $hidden_behavior . '"'; } $html .= sprintf( '<div role="radiogroup" class="forminator-field" aria-labelledby="%s"%s>', esc_attr( $descr_id . '-label' ), ( ! empty( $description ) ? ' aria-describedby="' . esc_attr( $descr_id . '-description' ) . '"' : '' ) ); if ( $label ) { if ( $required ) { $html .= sprintf( '<span id="%s" class="forminator-label">%s %s</span>', $descr_id . '-label', $label, forminator_get_required_icon() ); } else { $html .= sprintf( '<span id="%s" class="forminator-label">%s</span>', $descr_id . '-label', $label ); } } if ( 'above' === $descr_position ) { $html .= self::get_description( $description, $descr_id, $descr_position ); } foreach ( $options as $option ) { $pref_value = ( $option['value'] || is_numeric( $option['value'] ) ? esc_html( $option['value'] ) : esc_html( $option['label'] ) ); if ( isset( $draft_value['value'] ) ) { if ( trim( $draft_value['value'] ) === trim( $pref_value ) ) { $draft_valid = true; $default = $pref_value; } } if ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $prefill = $this->get_prefill( $field, false ); if ( $prefill === $pref_value ) { $prefil_valid = true; $default = $pref_value; } } if ( $pref_value === $post_value ) { $default = $pref_value; $post_valid = true; } } foreach ( $options as $option ) { $input_id = $id . '-' . $i . '-' . $uniq_id; $value = ( $option['value'] || is_numeric( $option['value'] ) ? esc_html( $option['value'] ) : esc_html( $option['label'] ) ); $option_default = isset( $option['default'] ) ? filter_var( $option['default'], FILTER_VALIDATE_BOOLEAN ) : false; $calculation_value = $calc_enabled && isset( $option['calculation'] ) ? $option['calculation'] : 0.0; $option_image_url = array_key_exists( 'image', $option ) ? $option['image'] : ''; $option_selected = false; $option_label = sprintf( '<span class="forminator-radio-label">%s</span>', wp_kses( $option['label'], array( 'a' => array( 'href' => array(), 'title' => array(), ), 'span' => array( 'class' => array(), ), 'b' => array(), 'i' => array(), 'br' => array(), 'em' => array(), 'strong' => array(), ) ) ); $aria_label = sprintf( '<span class="forminator-screen-reader-only">%s</span>', wp_kses( $option['label'], array( 'a' => array( 'href' => array(), 'title' => array(), ), 'span' => array( 'class' => array(), ), 'b' => array(), 'i' => array(), 'br' => array(), 'em' => array(), 'strong' => array(), ) ) ); $class = 'forminator-radio'; if ( $images_enabled && ! empty( $option_image_url ) ) { $class .= ' forminator-has_image'; if ( $input_visibility ) { $class .= ' forminator-has_bullet'; } } if ( 'horizontal' === self::get_property( 'layout', $field, '' ) ) { $class .= ' forminator-radio-inline'; } if ( $post_valid ) { if ( $value === $post_value ) { $option_selected = true; } } elseif ( $draft_valid ) { if ( $value === $default ) { $option_selected = true; } } elseif ( $prefil_valid ) { if ( $value === $default ) { $option_selected = true; } } elseif ( $option_default ) { $option_selected = true; } $selected = $option_selected ? 'checked="checked"' : ''; $label_id = $id . '-label-' . $i; $html .= '<label id="' . esc_attr( $label_id ) . '" for="' . esc_attr( $input_id ) . '" class="' . esc_attr( $class ) . '" title="' . esc_attr( $option['label'] ) . '">'; $html .= sprintf( '<input type="radio" name="%s" value="%s" id="%s" aria-labelledby="%s" data-calculation="%s" %s %s%s/>', $name, $value, $input_id, $label_id, $calculation_value, $selected, $hidden_calc_behavior, ( ! empty( $description ) ? ' aria-describedby="' . esc_attr( $id . '-' . $uniq_id . '-description' ) . '"' : '' ) ); if ( $input_visibility && ( $images_enabled && ! empty( $option_image_url ) ) ) { // Bullet + Label. $html .= '<span class="forminator-radio-bullet" aria-hidden="true"></span>'; $html .= $option_label; // Image. if ( 'none' === $design ) { $html .= '<img class="forminator-radio-image" src="' . esc_url( $option_image_url ) . '" aria-hidden="true" />'; } else { $html .= '<span class="forminator-radio-image" aria-hidden="true">'; $html .= '<span style="background-image: url(' . esc_url( $option_image_url ) . ');"></span>'; $html .= '</span>'; } } elseif ( ! $input_visibility && ( $images_enabled && ! empty( $option_image_url ) ) ) { // Image. if ( 'none' === $design ) { $html .= '<img class="forminator-radio-image" src="' . esc_url( $option_image_url ) . '" aria-hidden="true" />'; } else { $html .= '<span class="forminator-radio-image" aria-hidden="true">'; $html .= '<span style="background-image: url(' . esc_url( $option_image_url ) . ');"></span>'; $html .= '</span>'; } // Aria Label. $html .= $aria_label; } else { // Bullet + Label. $html .= '<span class="forminator-radio-bullet" aria-hidden="true"></span>'; $html .= $option_label; } $html .= '</label>'; ++$i; } if ( 'above' !== $descr_position ) { $html .= self::get_description( $description, $descr_id, $descr_position ); } $html .= '</div>'; return apply_filters( 'forminator_field_single_markup', $html, $id, $required, $options, $value_type ); } /** * Return field inline validation rules * * @since 1.0 * @return string */ public function get_validation_rules() { $rules = ''; $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); if ( $is_required ) { $rules .= '"' . $this->get_id( $field ) . '": "required",'; } return apply_filters( 'forminator_field_single_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @return string */ public function get_validation_messages() { $messages = ''; $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); if ( $is_required ) { $required_message = self::get_property( 'required_message', $field, '' ); $required_message = apply_filters( 'forminator_single_field_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please select a value.', 'forminator' ) ), $id, $field ); $messages .= '"' . $this->get_id( $field ) . '": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } return $messages; } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); if ( ! empty( $data ) && false === array_search( strval( htmlspecialchars_decode( $data ) ), array_map( 'strval', array_column( $field['options'], 'value' ) ), true ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_radio_field_nonexistent_validation_message', esc_html__( 'Selected value does not exist.', 'forminator' ), $id, $field ); } if ( $this->is_required( $field ) ) { $required_message = self::get_property( 'required_message', $field, '' ); if ( empty( $data ) && '0' !== $data ) { $this->validation_message[ $id ] = apply_filters( 'forminator_single_field_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please select a value.', 'forminator' ) ), $id, $field ); } } } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; /* * Field sanitization has been moved to library\abstracts\abstract-class-front-action.php > get_post_data > Forminator_Core::sanitize_array * Due to members' request to allow html, we now use wp_kses_post for sanitization of this field // Sanitize. if ( is_array( $data ) ) { $data = forminator_sanitize_array_field( $data ); } else { $data = forminator_sanitize_field( $data ); } */ return apply_filters( 'forminator_field_single_sanitize', $data, $field, $original_data ); } /** * Internal Calculable value * * @since 1.7 * * @param array $submitted_field Submitted field. * @param array $field_settings Field settings. * * @return float|string */ private static function calculable_value( $submitted_field, $field_settings ) { $enabled = self::get_property( 'calculations', $field_settings, false, 'bool' ); if ( ! $enabled ) { return self::FIELD_NOT_CALCULABLE; } $sums = 0.0; $options = self::get_property( 'options', $field_settings, array() ); if ( ! is_array( $submitted_field ) ) { // process as array. $submitted_field = array( $submitted_field ); } if ( ! is_array( $submitted_field ) ) { return $sums; } foreach ( $options as $option ) { $option_value = isset( $option['value'] ) ? $option['value'] : ( isset( $option['label'] ) ? $option['label'] : '' ); $calculation_value = isset( $option['calculation'] ) ? $option['calculation'] : 0.0; // strict array compare disabled to allow non-coercion type compare. if ( in_array( $option_value, $submitted_field ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict // this one is selected. $sums += floatval( $calculation_value ); } } return floatval( $sums ); } /** * Get calculable value * * @since 1.7 * @inheritdoc * @param array $submitted_field_data Submitted field data. * @param array $field_settings Field settings. */ public static function get_calculable_value( $submitted_field_data, $field_settings ) { $calculable_value = self::calculable_value( $submitted_field_data, $field_settings ); /** * Filter formula being used on calculable value on radio field * * @since 1.7 * * @param float $calculable_value * @param array $submitted_field_data * @param array $field_settings * * @return string|int|float */ $calculable_value = apply_filters( 'forminator_field_radio_calculable_value', $calculable_value, $submitted_field_data, $field_settings ); return $calculable_value; } } PK ~\`� � hidden.phpnu �[��� <?php /** * The Forminator_Hidden class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Hidden * * @since 1.0 */ class Forminator_Hidden extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'hidden'; /** * Type * * @var string */ public $type = 'hidden'; /** * Position * * @var int */ public $position = 19; /** * Options * * @var array */ public $options = array(); /** * Hide advanced * * @var string */ public $hide_advanced = 'true'; /** * Icon * * @var string */ public $icon = 'sui-icon-eye-hide'; /** * Forminator_Hidden constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Hidden Field', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'field_label' => '', 'default_value' => 'user_ip', ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { // Unsupported Autofill. $autofill_settings = array(); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $id = self::get_property( 'element_id', $field ); $name = $id; $value = esc_html( $this->get_value( $field, true ) ); return sprintf( '<input type="hidden" id="%s" name="%s" value="%s" />', $id . '_' . Forminator_CForm_Front::$uid, $name, $value ); } /** * Return replaced value * * @since 1.0 * @since 1.5 add user_id value getter * @param array $field Field. * @param boolean $is_markup For front-end markup. * * @return mixed|string */ public function get_value( $field, $is_markup = false ) { $value = ''; $saved_value = self::get_property( 'default_value', $field ); $embed_url = forminator_get_current_url(); switch ( $saved_value ) { case 'embed_id': $value = forminator_get_post_data( 'ID' ); break; case 'embed_title': $value = forminator_get_post_data( 'post_title' ); break; case 'refer_url': if ( true === $is_markup ) { $value = forminator_get_referer_url( $embed_url ); } else { $element_id = self::get_property( 'element_id', $field ); $post_value = self::get_post_data( $element_id ); $value = empty( $post_value ) ? $embed_url : $this->sanitize( $field, $post_value ); } break; case 'submission_id': $value = 'submission_id'; break; case 'custom_value': $value = self::get_property( 'custom_value', $field ); break; case 'query': $value = $this->replace_prefill( $field ); break; default: $placeholder = '{' . $saved_value . '}'; $placeholder_value = forminator_replace_variables( $placeholder ); if ( $placeholder_value !== $placeholder ) { $value = $placeholder_value; } break; } return apply_filters( 'forminator_field_hidden_field_value', $value, $saved_value, $field, $this ); } /** * Get prefill value * * @since 1.10 * * @param array $field Field. * @return mixed|string */ public function replace_prefill( $field ) { $value = ''; if ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $value = $this->get_prefill( $field, $value ); } return $value; } /** * Get calculable value * * @param string $submitted_field_data Submitted data. * @param array $field_settings Field settings. * @return string */ public static function get_calculable_value( $submitted_field_data, $field_settings ) { $calculable_value = $submitted_field_data; /** * Filter formula being used on calculable value on hidden field * * @param float $calculable_value * @param array $submitted_field_data * @param array $field_settings * * @return string|int|float */ $calculable_value = apply_filters( 'forminator_field_hidden_calculable_value', $calculable_value, $submitted_field_data, $field_settings ); return $calculable_value; } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. if ( in_array( $field['default_value'], array( 'refer_url', 'embed_url' ), true ) ) { $data = urldecode_deep( $data ); } $data = forminator_sanitize_field( $data ); return apply_filters( 'forminator_field_hidden_sanitize', $data, $field, $original_data ); } } PK ~\t�K��5 �5 paypal.phpnu �[��� <?php /** * The Forminator_PayPal class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_PayPal * * @since 1.7 */ class Forminator_PayPal extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'paypal'; /** * Type * * @var string */ public $type = 'paypal'; /** * Position * * @var int */ public $position = 24; /** * Options * * @var array */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon forminator-icon-paypal'; /** * Is calculable * * @var bool */ public $is_connected = false; /** * Forminator_PayPal constructor. */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'PayPal', 'forminator' ); } /** * Field defaults * * @return array */ public function defaults() { $default_currency = 'USD'; try { $paypal = new Forminator_PayPal_Express(); $default_currency = $paypal->get_default_currency(); } catch ( Forminator_Gateway_Exception $e ) { forminator_maybe_log( __METHOD__, $e->getMessage() ); } return array( 'mode' => 'sandbox', 'currency' => $default_currency, 'amount_type' => 'fixed', 'label' => 'checkout', 'color' => 'gold', 'shape' => 'rect', 'layout' => 'vertical', 'tagline' => 'true', 'shipping_address' => 'disable', 'locale' => 'en_US', 'debug_mode' => 'disable', 'height' => '40', 'options' => array(), ); } /** * Field front-end markup * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $settings = $views_obj->model->settings; $this->field = $field; $this->form_settings = $settings; $element_name = self::get_property( 'element_id', $field ); $field_id = $element_name . '-field'; $mode = self::get_property( 'mode', $field, 'sandbox' ); $currency = self::get_property( 'currency', $field, $this->get_default_currency() ); $amount_type = self::get_property( 'amount_type', $field, 'fixed' ); $amount = self::get_property( 'amount', $field, '0' ); $amount_variable = self::get_property( 'variable', $field, '' ); $logo = self::get_property( 'logo', $field, '' ); $company_name = esc_html( self::get_property( 'company_name', $field, '' ) ); $product_description = esc_html( self::get_property( 'product_description', $field, '' ) ); $customer_email = self::get_property( 'customer_email', $field, '' ); $checkout_label = esc_html( self::get_property( 'checkout_label', $field, '' ) ); $collect_address = esc_html( self::get_property( 'collect_address', $field, 'none', 'string' ) ); $verify_zip = esc_html( self::get_property( 'verify_zip', $field, false, 'bool' ) ); $language = self::get_property( 'language', $field, 'en' ); $attr = array( 'type' => 'hidden', 'name' => $element_name, 'id' => 'forminator-' . $field_id . '_' . Forminator_CForm_Front::$uid, 'class' => 'forminator-paypal-input', 'data-is-payment' => 'true', 'data-payment-type' => $this->type, 'data-currency' => esc_html( strtolower( $currency ) ), 'data-amount-type' => esc_html( $amount_type ), 'data-amount' => ( 'fixed' === $amount_type ? esc_html( $amount ) : $amount_variable ), 'data-label' => esc_html( $checkout_label ), 'data-locale' => esc_html( $language ), ); if ( ! empty( $logo ) ) { $attr['data-image'] = esc_url( $logo ); } if ( ! empty( $company_name ) ) { $attr['data-name'] = esc_html( $company_name ); } if ( ! empty( $company_name ) ) { $attr['data-description'] = esc_html( $product_description ); } if ( ! empty( $customer_email ) ) { $attr['data-email'] = esc_html( $customer_email ); } if ( 'billing' === $collect_address || 'billing_shipping' === $collect_address ) { $attr['data-billing-address'] = 'true'; } if ( 'billing_shipping' === $collect_address ) { $attr['data-shipping-address'] = 'true'; } if ( $verify_zip ) { $attr['data-zip-code'] = 'true'; } $html = self::create_input( $attr ); return apply_filters( 'forminator_field_paypal_markup', $html, $attr, $field ); } /** * Field back-end validation * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); } /** * Sanitize data * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. $data = forminator_sanitize_field( $data ); return apply_filters( 'forminator_field_paypal_sanitize', $data, $field, $original_data ); } /** * Is available * * @since 1.7 * @inheritdoc * @param mixed $field Field. */ public function is_available( $field ) { $mode = self::get_property( 'mode', $field, 'sandbox' ); try { $paypal = new Forminator_PayPal_Express(); if ( 'sandbox' !== $mode ) { $paypal->set_live( true ); } if ( $paypal->is_ready() ) { return true; } } catch ( Forminator_Gateway_Exception $e ) { return false; } } /** * Get publishable key * * @since 1.7 * * @param bool $live Is live?. * * @return bool|string */ private function get_publishable_key( $live = false ) { try { $paypal = new Forminator_PayPal_Express(); if ( $live ) { return $paypal->get_live_id(); } return $paypal->get_sandbox_id(); } catch ( Forminator_Gateway_Exception $e ) { return false; } } /** * Get default currency * * @return string */ private function get_default_currency() { try { $paypal = new Forminator_PayPal_Express(); return $paypal->get_default_currency(); } catch ( Forminator_Gateway_Exception $e ) { return 'USD'; } } /** * Process entry data * * @param array $field Field. * * @return array */ public function process_to_entry_data( $field ) { $entry_data = array( 'mode' => '', 'status' => '', 'amount' => '', 'currency' => '', 'transaction_id' => '', 'transaction_link' => '', ); $element_id = self::get_property( 'element_id', $field ); $mode = self::get_property( 'mode', $field, 'sandbox' ); $currency = self::get_property( 'currency', $field, $this->get_default_currency() ); $entry_data['mode'] = $mode; $entry_data['currency'] = $currency; $charge_amount = $this->get_payment_amount( $field ); $charge_amount = number_format( $charge_amount, 2, '.', '' ); $transaction_id = Forminator_CForm_Front_Action::$prepared_data['payment_transaction_id']; $paypal = new Forminator_PayPal_Express(); $order = $paypal->get_order( $transaction_id, $mode ); // Validate intent. if ( ! isset( $order->intent ) || 'CAPTURE' !== $order->intent ) { return array( 'error' => esc_html__( 'Error! Something went wrong during checkout and payment couldn\'t be approved.', 'forminator' ), ); } // Validate status. if ( ! isset( $order->status ) || 'APPROVED' !== $order->status ) { return array( 'error' => esc_html__( 'Error! Something went wrong during checkout and payment couldn\'t be approved.', 'forminator' ), ); } // Validate amount. if ( ! isset( $order->purchase_units[0]->amount->value ) || floatval( $order->purchase_units[0]->amount->value ) !== floatval( $charge_amount ) ) { return array( 'error' => esc_html__( 'Error! Invalid payment amount!', 'forminator' ), ); } // Validate currency. if ( ! isset( $order->purchase_units[0]->amount->currency_code ) || $order->purchase_units[0]->amount->currency_code !== $currency ) { return array( 'error' => esc_html__( 'Error! Invalid currency code!', 'forminator' ), ); } $entry_data['amount'] = $charge_amount; $entry_data['status'] = $order->status; $entry_data['transaction_id'] = $transaction_id; $entry_data['transaction_link'] = self::get_transanction_link( $mode, $transaction_id ); /** * Filter PayPal entry data that will be stored * * @since 1.7 * * @param array $entry_data * @param array $field field properties. * @param Forminator_Form_Model $module_object * @param array $submitted_data * @param array $field_data_array current entry meta. * * @return array */ $entry_data = apply_filters( 'forminator_field_paypal_process_to_entry_data', $entry_data, $field, Forminator_Front_Action::$module_object, Forminator_CForm_Front_Action::$prepared_data, Forminator_CForm_Front_Action::$info['field_data_array'] ); return $entry_data; } /** * Get transaction link * * @param string $mode Payment mode. * @param string $transaction_id Transaction id. * @return string */ public static function get_transanction_link( $mode, $transaction_id ) { if ( 'sandbox' === $mode ) { $link_base = 'https://www.sandbox.paypal.com/activity/payment/'; } else { $link_base = 'https://www.paypal.com/activity/payment/'; } $transaction_link = $link_base . rawurlencode( $transaction_id ); return $transaction_link; } /** * Make linkify transaction_id * * @param string $transaction_id Transaction Id. * @param array $meta_value Meta value. * * @return string */ public static function linkify_transaction_id( $transaction_id, $meta_value ) { $transaction_link = $transaction_id; if ( isset( $meta_value['transaction_link'] ) && ! empty( $meta_value['transaction_link'] ) ) { $url = $meta_value['transaction_link']; $transaction_link = '<a href="' . $url . '" target="_blank" rel="noopener noreferrer" title="' . $transaction_id . '">' . $transaction_id . '</a>'; } /** * Filter link to PayPal transaction id * * @since 1.7 * * @param string $transaction_link * @param string $transaction_id * @param array $meta_value * * @return string */ $transaction_link = apply_filters( 'forminator_field_paypal_linkify_transaction_id', $transaction_link, $transaction_id, $meta_value ); return $transaction_link; } /** * Get payment amount * * @since 1.7 * * @param array $field Field. * * @return double */ public function get_payment_amount( $field ) { $payment_amount = 0.0; $amount_type = self::get_property( 'amount_type', $field, 'fixed' ); $amount = self::get_property( 'amount', $field, '0' ); $amount_var = self::get_property( 'variable', $field, '' ); if ( 'fixed' === $amount_type ) { $payment_amount = $amount; } else { $form_field = Forminator_Front_Action::$module_object->get_field( $amount_var, false ); if ( $form_field ) { $form_field = $form_field->to_formatted_array(); if ( isset( $form_field['type'] ) ) { $field_id = $form_field['element_id']; $submitted_field_data = isset( Forminator_CForm_Front_Action::$prepared_data[ $field_id ] ) ? Forminator_CForm_Front_Action::$prepared_data[ $field_id ] : null; if ( 'calculation' === $form_field['type'] ) { // Calculation field get the amount from pseudo_submit_data. if ( isset( Forminator_CForm_Front_Action::$prepared_data[ $amount_var ] ) ) { $payment_amount = Forminator_CForm_Front_Action::$prepared_data[ $amount_var ]; } } elseif ( 'currency' === $form_field['type'] ) { // Currency field get the amount from submitted_data. if ( ! is_null( $submitted_field_data ) ) { $payment_amount = self::forminator_replace_number( $form_field, $submitted_field_data ); } } else { $field_object = Forminator_Core::get_field_object( $form_field['type'] ); if ( $field_object ) { $payment_amount = $field_object::get_calculable_value( $submitted_field_data, $form_field ); } } } } } if ( ! is_numeric( $payment_amount ) ) { $payment_amount = 0.0; } /** * Filter payment amount of PayPal * * @since 1.7 * * @param double $payment_amount * @param array $field field settings. * @param Forminator_Form_Model $module_object * @param array $prepared_data */ $payment_amount = apply_filters( 'forminator_field_paypal_payment_amount', $payment_amount, $field, Forminator_Front_Action::$module_object, Forminator_CForm_Front_Action::$prepared_data ); return $payment_amount; } /** * Get the fields that an amount depends on * * @param array $field_settings Field settings. * @return array */ public function get_amount_dependent_fields( $field_settings ) { $depend_field = array(); $amount_type = self::get_property( 'amount_type', $field_settings, 'fixed' ); $amount_var = self::get_property( 'variable', $field_settings, '' ); if ( 'variable' === $amount_type && ! empty( $amount_var ) ) { $depend_field[] = $amount_var; } return $depend_field; } } PK ~\�y�� � custom.phpnu �[��� <?php /** * The Forminator_Custom class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Custom * * @since 1.0 */ class Forminator_Custom extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'custom'; /** * Type * * @var string */ public $type = 'custom'; /** * Options * * @var array */ public $options = array(); /** * Category * * @var string */ public $category = ''; /** * Category * * @var string */ // public $category = 'posts';. // Disable for now until we know what to do with this. /** * Forminator_Custom constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Custom Field', 'forminator' ); } /** * Load settings * * @param array $settings Settings. * * @return array */ public function load_settings( $settings = array() ) { return array( array( 'id' => 'required', 'type' => 'Toggle', 'name' => 'required', 'className' => 'required-field', 'hide_label' => true, 'values' => array( array( 'value' => 'true', 'label' => esc_html__( 'Required', 'forminator' ), 'labelSmall' => 'true', ), ), ), array( 'id' => 'separator-1', 'type' => 'Separator', 'hide_label' => true, ), array( 'id' => 'field-label', 'type' => 'Text', 'name' => 'field_label', 'hide_label' => false, 'label' => esc_html__( 'Field Label', 'forminator' ), 'className' => 'text-field', ), array( 'id' => 'field-type', 'type' => 'Select', 'name' => 'field_type', 'className' => 'select-field', 'label_hidden' => false, 'label' => esc_html__( 'Field type', 'forminator' ), 'values' => array( array( 'value' => 'text', 'label' => esc_html__( 'Single line text', 'forminator' ), ), array( 'value' => 'textarea', 'label' => esc_html__( 'Multi line text', 'forminator' ), ), array( 'value' => 'dropdown', 'label' => esc_html__( 'Dropdown', 'forminator' ), ), array( 'value' => 'multiselect', 'label' => esc_html__( 'Multi Select', 'forminator' ), ), array( 'value' => 'number', 'label' => esc_html__( 'Number', 'forminator' ), ), array( 'value' => 'checkbox', 'label' => esc_html__( 'Checkboxes', 'forminator' ), ), array( 'value' => 'radio', 'label' => esc_html__( 'Radio Buttons', 'forminator' ), ), array( 'value' => 'hidden', 'label' => esc_html__( 'Hidden', 'forminator' ), ), ), ), array( 'id' => 'custom-field-name', 'type' => 'RadioContainer', 'name' => 'custom_field_name', 'className' => 'custom-field-name-field', 'containerClass' => 'wpmudev-is_gray', 'label' => esc_html__( 'Custom field name', 'forminator' ), 'values' => array( array( 'value' => 'existing', 'label' => esc_html__( 'Existing field', 'forminator' ), ), array( 'value' => 'new', 'label' => esc_html__( 'New field', 'forminator' ), ), ), 'fields' => array( array( 'id' => 'existing-field', 'type' => 'Select', 'name' => 'existing_field', 'className' => 'existing-field', 'label' => esc_html__( 'Pick existing field', 'forminator' ), 'tab' => 'existing', 'values' => array(), ), ), ), ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'value_type' => 'select', 'field_label' => '', ); } /** * Field front-end markup * * @since 1.0 * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $required = self::get_property( 'required', $field, false ); $id = self::get_property( 'element_id', $field ); $name = $id; $field_type = self::get_property( 'field_type', $field ); $placeholder = esc_html( self::get_property( 'placeholder', $field ) ); $description = self::get_property( 'description', $field ); $label = esc_html( self::get_property( 'field_label', $field ) ); $id = $id . '-field'; $html = ''; $default_value = esc_html( self::get_property( 'default_value', $field ) ); $post_value = self::get_post_data( $name, false ); $settings = $views_obj->model->settings; $descr_position = self::get_description_position( $field, $settings ); switch ( $field_type ) { case 'text': $html .= sprintf( '<input class="forminator-name--field forminator-input" type="text" data-required="%s" name="%s" placeholder="%s" id="%s" %s/>', $required, $name, $placeholder, $id, ( $post_value ? 'value= "' . $post_value . '"' : '' ) ); break; case 'textarea': $field_markup = array( 'type' => 'textarea', 'class' => 'forminator-textarea', 'name' => $name, 'id' => $id, 'placeholder' => $placeholder, 'required' => $required, ); $html .= self::create_textarea( $field_markup, $label, $description, $required, $descr_position ); break; case 'dropdown': break; case 'multiselect': break; case 'number': $html .= sprintf( '<input class="forminator-number--field forminator-input" type="number" data-required="%s" name="%s" placeholder="%s" value="%s" id="%s" />', $required, $name, $placeholder, ( $post_value ? $post_value : $default_value ), $id ); break; case 'checkbox': break; case 'radio': break; case 'hidden': $html .= sprintf( '<input class="forminator-hidden--field" type="hidden" id="%s" name="%s" value="%s" />', $id, $name, $default_value ); break; default: break; } return apply_filters( 'forminator_field_custom_markup', $html, $id, $required, $field_type, $placeholder ); } /** * Field back-end validation * * @since 1.0 * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { if ( $this->is_required( $field ) ) { $id = self::get_property( 'element_id', $field ); $name = self::get_property( 'custom_field_name', $field, esc_html__( 'field name', 'forminator' ) ); if ( empty( $data ) ) { /* translators: %s: Field name */ $this->validation_message[ $id ] = sprintf( esc_html__( 'This field is required. Please enter the %s.', 'forminator' ), $name ); } } } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { return $data; } } PK ~\����l l address.phpnu �[��� <?php /** * The Forminator_Address class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Address * * @since 1.0 */ class Forminator_Address extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'address'; /** * Position * * @var int */ public $position = 4; /** * Type * * @var string */ public $type = 'address'; /** * Options * * @var array */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon-pin'; /** * Forminator_Address constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Address', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'street_address' => 'true', 'address_city' => 'true', 'address_state' => 'true', 'address_zip' => 'true', 'address_country' => 'true', 'address_line' => 'true', 'field_label' => esc_html__( 'Address', 'forminator' ), 'street_address_label' => esc_html__( 'Street Address', 'forminator' ), 'address_city_label' => esc_html__( 'City', 'forminator' ), 'address_state_label' => esc_html__( 'State/Province', 'forminator' ), 'address_zip_label' => esc_html__( 'ZIP / Postal Code', 'forminator' ), 'address_country_label' => esc_html__( 'Country', 'forminator' ), 'address_line_label' => esc_html__( 'Apartment, suite, etc', 'forminator' ), 'street_address_required_message' => esc_html__( 'This field is required. Please enter the street address.', 'forminator' ), 'address_zip_required_message' => esc_html__( 'This field is required. Please enter the zip code.', 'forminator' ), 'address_country_required_message' => esc_html__( 'This field is required. Please select the country.', 'forminator' ), 'address_city_required_message' => esc_html__( 'This field is required. Please enter the city.', 'forminator' ), 'address_state_required_message' => esc_html__( 'This field is required. Please enter the state.', 'forminator' ), 'address_line_required_message' => esc_html__( 'This field is required. Please enter address line.', 'forminator' ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $street_address_providers = apply_filters( 'forminator_field_' . $this->slug . '_street_address_autofill', array(), $this->slug . '_street_address' ); $address_line_providers = apply_filters( 'forminator_field_' . $this->slug . '_address_line_autofill', array(), $this->slug . '_address_line' ); $city_providers = apply_filters( 'forminator_field_' . $this->slug . '_city_autofill', array(), $this->slug . '_city' ); $state_providers = apply_filters( 'forminator_field_' . $this->slug . '_state_autofill', array(), $this->slug . '_state' ); $zip_providers = apply_filters( 'forminator_field_' . $this->slug . '_zip_autofill', array(), $this->slug . '_zip' ); $autofill_settings = array( 'address-street_address' => array( 'values' => forminator_build_autofill_providers( $street_address_providers ), ), 'address-address_line' => array( 'values' => forminator_build_autofill_providers( $address_line_providers ), ), 'address-city' => array( 'values' => forminator_build_autofill_providers( $city_providers ), ), 'address-state' => array( 'values' => forminator_build_autofill_providers( $state_providers ), ), 'address-zip' => array( 'values' => forminator_build_autofill_providers( $zip_providers ), ), ); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param string $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $this->form_settings = $settings; $draft_value = isset( $draft_value['value'] ) ? $draft_value['value'] : ''; $field['descr_position'] = self::get_description_position( $field, $settings ); // Address. $html = $this->get_address( $field, 'street_address', $draft_value ); // Second Address. $html .= $this->get_address( $field, 'address_line', $draft_value ); // City & State fields. $html .= $this->get_city_state( $field, $draft_value ); // ZIP & Country fields. $html .= $this->get_zip_country( $field, $draft_value ); return apply_filters( 'forminator_field_address_markup', $html, $field ); } /** * Return address input markup * * @since 1.0 * * @param array $field Field. * @param string $slug Field slug. * @param string $draft_value Draft value. * * @return string */ public function get_address( $field, $slug, $draft_value = null ) { $html = ''; $cols = 12; $id = self::get_property( 'element_id', $field ); $address_id = self::get_subfield_id( $id, '-' . $slug ); $required = self::get_property( $slug . '_required', $field, false, 'bool' ); $ariareq = 'false'; $enabled = self::get_property( $slug, $field ); $description = self::get_property( $slug . '_description', $field ); $descr_position = self::get_property( 'descr_position', $field ); if ( (bool) self::get_property( $slug . '_required', $field, false ) ) { $ariareq = 'true'; } $address = array( 'type' => 'text', 'name' => $address_id, 'placeholder' => $this->sanitize_value( self::get_property( $slug . '_placeholder', $field ) ), 'id' => self::get_field_id( $address_id ), 'class' => 'forminator-input', 'data-required' => $required, 'aria-required' => $ariareq, ); if ( empty( $draft_value ) ) { $address = $this->replace_from_prefill( $field, $address, $slug ); } elseif ( isset( $draft_value[ $slug ] ) ) { $address['value'] = esc_attr( $draft_value[ $slug ] ); } if ( $enabled ) { $html .= '<div class="forminator-row">'; $html .= sprintf( '<div id="%s" class="forminator-col">', $address['name'] ); $html .= '<div class="forminator-field">'; $html .= self::create_input( $address, self::get_property( $slug . '_label', $field ), $description, $required, $descr_position, ); $html .= '</div>'; $html .= '</div>'; $html .= '</div>'; } return $html; } /** * Return City and State fields markup * * @since 1.0 * * @param array $field Field. * @param string $draft_value Draft value. * * @return string */ public function get_city_state( $field, $draft_value = null ) { $html = ''; $cols = 12; $id = self::get_property( 'element_id', $field ); $city_id = self::get_subfield_id( $id, '-city' ); $state_id = self::get_subfield_id( $id, '-state' ); $city = self::get_property( 'address_city', $field, false ); $state = self::get_property( 'address_state', $field, false ); $city_desc = self::get_property( 'address_city_description', $field ); $state_desc = self::get_property( 'address_state_description', $field ); $city_required = self::get_property( 'address_city_required', $field, false, 'bool' ); $city_ariareq = 'false'; $state_required = self::get_property( 'address_state_required', $field, false, 'bool' ); $state_ariareq = 'false'; $multirow = 'false'; $descr_position = self::get_property( 'descr_position', $field ); if ( (bool) self::get_property( 'address_city_required', $field, false ) ) { $city_ariareq = 'true'; } if ( (bool) self::get_property( 'address_state_required', $field, false ) ) { $state_ariareq = 'true'; } // If both prefix & first name are enabled, change cols. if ( $city && $state ) { $cols = 6; $multirow = 'true'; } if ( $city || $state ) { $html .= sprintf( '<div class="forminator-row" data-multiple="%s">', $multirow ); if ( $city ) { $city_data = array( 'type' => 'text', 'name' => $city_id, 'placeholder' => $this->sanitize_value( self::get_property( 'address_city_placeholder', $field ) ), 'id' => self::get_field_id( $city_id ), 'class' => 'forminator-input', 'data-required' => $city_required, 'aria-required' => $city_ariareq, ); if ( isset( $draft_value['city'] ) ) { $city_data['value'] = esc_attr( $draft_value['city'] ); } else { $city_data = $this->replace_from_prefill( $field, $city_data, 'address_city' ); } $html .= sprintf( '<div id="%s" class="forminator-col forminator-col-%s">', $city_data['name'], $cols ); $html .= '<div class="forminator-field">'; $html .= self::create_input( $city_data, self::get_property( 'address_city_label', $field ), $city_desc, $city_required, $descr_position, ); $html .= '</div>'; $html .= '</div>'; } if ( $state ) { $state_data = array( 'type' => 'text', 'name' => $state_id, 'placeholder' => $this->sanitize_value( self::get_property( 'address_state_placeholder', $field ) ), 'id' => self::get_field_id( $state_id ), 'class' => 'forminator-input', 'data-required' => $state_required, 'aria-required' => $state_ariareq, ); if ( isset( $draft_value['state'] ) ) { $state_data['value'] = esc_attr( $draft_value['state'] ); } else { $state_data = $this->replace_from_prefill( $field, $state_data, 'address_state' ); } $html .= sprintf( '<div id="%s" class="forminator-col forminator-col-%s">', $state_data['name'], $cols ); $html .= '<div class="forminator-field">'; $html .= self::create_input( $state_data, self::get_property( 'address_state_label', $field ), $state_desc, $state_required, $descr_position, ); $html .= '</div>'; $html .= '</div>'; } $html .= '</div>'; } return $html; } /** * Return Zip and County inputs * * @since 1.0 * * @param array $field Field. * @param string $draft_value Draft value. * * @return string */ public function get_zip_country( $field, $draft_value = null ) { $html = ''; $cols = 12; $id = self::get_property( 'element_id', $field ); $zip_id = self::get_subfield_id( $id, '-zip' ); $country_id = self::get_subfield_id( $id, '-country' ); $address_zip = self::get_property( 'address_zip', $field, false ); $address_country = self::get_property( 'address_country', $field, false ); $zip_desc = self::get_property( 'address_zip_description', $field ); $country_desc = self::get_property( 'address_country_description', $field ); $descr_position = self::get_property( 'descr_position', $field ); $zip_required = self::get_property( 'address_zip_required', $field, false, 'bool' ); $country_required = self::get_property( 'address_country_required', $field, false, 'bool' ); $zip_ariareq = 'false'; if ( (bool) self::get_property( 'address_zip_required', $field, false ) ) { $zip_ariareq = 'true'; } $multirow = 'false'; // If both prefix & first name are enabled, change cols. if ( $address_zip && $address_country ) { $cols = 6; $multirow = 'true'; } if ( $address_zip || $address_country ) { $html .= sprintf( '<div class="forminator-row" data-multiple="%s">', $multirow ); if ( $address_zip ) { $zip_data = array( 'type' => 'text', 'name' => $zip_id, 'placeholder' => $this->sanitize_value( self::get_property( 'address_zip_placeholder', $field ) ), 'id' => self::get_field_id( $zip_id ), 'class' => 'forminator-input', ); if ( isset( $draft_value['zip'] ) ) { $zip_data['value'] = esc_attr( $draft_value['zip'] ); } else { $zip_data = $this->replace_from_prefill( $field, $zip_data, 'address_zip' ); } $html .= sprintf( '<div id="%s" class="forminator-col forminator-col-%s">', $zip_data['name'], $cols ); $html .= '<div class="forminator-field">'; $html .= self::create_input( $zip_data, self::get_property( 'address_zip_label', $field ), $zip_desc, $zip_required, $descr_position, ); $html .= '</div>'; $html .= '</div>'; } if ( $address_country ) { $country_data = array( 'name' => $country_id, 'id' => self::get_field_id( $this->form_settings['form_id'] . '__field--' . $country_id ), 'class' => 'forminator-select2', 'data-search' => 'true', 'data-placeholder' => esc_html__( 'Select country', 'forminator' ), ); $countries = array( array( 'value' => '', 'label' => '', ), ); $options = forminator_to_field_array( forminator_get_countries_list() ); $countries = array_merge( $countries, $options ); $country = false; if ( isset( $draft_value['country'] ) ) { $country = esc_attr( $draft_value['country'] ); } elseif ( $this->has_prefill( $field, 'address_country' ) ) { // We have pre-fill parameter, use its value or $value. $country = $this->get_prefill( $field, false, 'address_country' ); } $new_countries = array(); foreach ( $countries as $option ) { $selected = false; // Should use label here. Option values are 2-letter country codes. if ( strtolower( $option['label'] ) === strtolower( $country ) ) { $selected = true; } $new_countries[] = array( 'value' => $option['value'], 'label' => $option['label'], 'selected' => $selected, ); } /** * Filter countries for <options> on <select> field * * @since 1.5.2 * @param array $countries */ $countries = apply_filters( 'forminator_countries_field', $new_countries ); $html .= sprintf( '<div id="%s" class="forminator-col forminator-col-%s">', $country_data['name'], $cols ); $html .= '<div class="forminator-field">'; $html .= self::create_country_select( $country_data, self::get_property( 'address_country_label', $field ), $countries, self::get_property( 'address_country_placeholder', $field ), $country_desc, $country_required, $descr_position, ); $html .= '</div>'; $html .= '</div>'; } $html .= '</div>'; } return $html; } /** * Return new select field * * @since 1.7.3 * * @param array $attr Attributes. * @param string $label Text for label. * @param array $options Options. * @param string $value Value. * @param string $description Description content. * @param bool $required Is required. * @param string $descr_position Description position. * * @return mixed */ public static function create_country_select( $attr = array(), $label = '', $options = array(), $value = '', $description = '', $required = false, $descr_position = 'above' ) { $html = ''; if ( ! empty( $description ) ) { $attr['aria-describedby'] = $attr['id'] . '-description'; } $markup = self::implode_attr( $attr ); if ( isset( $attr['id'] ) ) { $get_id = $attr['id']; } else { $get_id = uniqid( 'forminator-select-' ); } if ( self::get_post_data( $attr['name'], false ) ) { $value = self::get_post_data( $attr['name'] ); } $html .= self::get_field_label( $label, $get_id, $required ); if ( 'above' === $descr_position ) { $html .= self::get_description( $description, $get_id, $descr_position ); } $markup .= ' data-default-value="' . esc_attr( $value ) . '"'; $html .= sprintf( '<select %s>', $markup ); foreach ( $options as $option ) { $selected = ''; if ( ( $option['label'] == $value ) || ( isset( $option['selected'] ) && $option['selected'] ) ) { // phpcs:ignore -- loose comparison ok : possible compare '1' and 1. $selected = 'selected="selected"'; } if ( 'Select country' === $option['label'] ) { $html .= sprintf( '<option value="" data-country-code="%s" %s>%s</option>', $option['value'], $selected, $option['label'] ); } else { $html .= sprintf( '<option value="%s" data-country-code="%s" %s>%s</option>', $option['label'], $option['value'], $selected, $option['label'] ); } } $html .= '</select>'; if ( 'above' !== $descr_position ) { $html .= self::get_description( $description, $get_id, $descr_position ); } return apply_filters( 'forminator_field_create_select', $html, $attr, $label, $options, $value, $description ); } /** * Return field inline validation rules * * @since 1.0 * @return string */ public function get_validation_rules() { $field = $this->field; $rules = ''; $id = self::get_property( 'element_id', $field ); $street = self::get_property( 'street_address', $field, false ); $line = self::get_property( 'address_line', $field, false ); $city = self::get_property( 'address_city', $field, false ); $state = self::get_property( 'address_state', $field, false ); $zip = self::get_property( 'address_zip', $field, false ); $country = self::get_property( 'address_country', $field, false ); $street_required = self::get_property( 'street_address_required', $field, false, 'bool' ); $line_required = self::get_property( 'address_line_required', $field, false, 'bool' ); $city_required = self::get_property( 'address_city_required', $field, false, 'bool' ); $state_required = self::get_property( 'address_state_required', $field, false, 'bool' ); $zip_required = self::get_property( 'address_zip_required', $field, false, 'bool' ); $country_required = self::get_property( 'address_country_required', $field, false, 'bool' ); if ( $street ) { if ( $street_required ) { $rules .= '"' . $this->get_id( $field ) . '-street_address": "trim",'; $rules .= '"' . $this->get_id( $field ) . '-street_address": "required",'; } } if ( $line ) { if ( $line_required ) { $rules .= '"' . $this->get_id( $field ) . '-address_line": "trim",'; $rules .= '"' . $this->get_id( $field ) . '-address_line": "required",'; } } if ( $city ) { if ( $city_required ) { $rules .= '"' . $this->get_id( $field ) . '-city": "trim",'; $rules .= '"' . $this->get_id( $field ) . '-city": "required",'; } } if ( $state ) { if ( $state_required ) { $rules .= '"' . $this->get_id( $field ) . '-state": "trim",'; $rules .= '"' . $this->get_id( $field ) . '-state": "required",'; } } if ( $zip ) { if ( $zip_required ) { $rules .= '"' . $this->get_id( $field ) . '-zip": "trim",'; $rules .= '"' . $this->get_id( $field ) . '-zip": "required",'; } } if ( $country ) { if ( $country_required ) { $rules .= '"' . $this->get_id( $field ) . '-country": "trim",'; $rules .= '"' . $this->get_id( $field ) . '-country": "required",'; } } return apply_filters( 'forminator_field_address_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @return string */ public function get_validation_messages() { $field = $this->field; $id = $this->get_id( $field ); $messages = ''; $street = self::get_property( 'street_address', $field, false ); $line = self::get_property( 'address_line', $field, false ); $city = self::get_property( 'address_city', $field, false ); $state = self::get_property( 'address_state', $field, false ); $zip = self::get_property( 'address_zip', $field, false ); $country = self::get_property( 'address_country', $field, false ); $street_required = self::get_property( 'street_address_required', $field, false, 'bool' ); $line_required = self::get_property( 'address_line_required', $field, false, 'bool' ); $city_required = self::get_property( 'address_city_required', $field, false, 'bool' ); $state_required = self::get_property( 'address_state_required', $field, false, 'bool' ); $zip_required = self::get_property( 'address_zip_required', $field, false, 'bool' ); $country_required = self::get_property( 'address_country_required', $field, false, 'bool' ); if ( $street && $street_required ) { $required_message = $this->get_field_multiple_required_message( $id, $field, 'street_address_required_message', 'street_address', esc_html__( 'This field is required. Please enter the street address.', 'forminator' ) ); $messages .= '"' . $this->get_id( $field ) . '-street_address": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } if ( $line && $line_required ) { $required_message = $this->get_field_multiple_required_message( $id, $field, 'address_line_required_message', 'address_line', esc_html__( 'This field is required. Please enter address line.', 'forminator' ) ); $messages .= '"' . $this->get_id( $field ) . '-address_line": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } if ( $city && $city_required ) { $required_message = $this->get_field_multiple_required_message( $id, $field, 'address_city_required_message', 'address_city', esc_html__( 'This field is required. Please enter the city.', 'forminator' ) ); $messages .= '"' . $this->get_id( $field ) . '-city": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } if ( $state && $state_required ) { $required_message = $this->get_field_multiple_required_message( $id, $field, 'address_state_required_message', 'address_state', esc_html__( 'This field is required. Please enter the state.', 'forminator' ) ); $messages .= '"' . $this->get_id( $field ) . '-state": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } if ( $zip && $zip_required ) { $required_message = $this->get_field_multiple_required_message( $id, $field, 'address_zip_required_message', 'address_zip', esc_html__( 'This field is required. Please enter the zip code.', 'forminator' ) ); $messages .= '"' . $this->get_id( $field ) . '-zip": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } if ( $country && $country_required ) { $required_message = $this->get_field_multiple_required_message( $id, $field, 'address_country_required_message', 'address_country', esc_html__( 'This field is required. Please select the country.', 'forminator' ) ); $messages .= '"' . $this->get_id( $field ) . '-country": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } return $messages; } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); $street = self::get_property( 'street_address', $field, false ); $line = self::get_property( 'address_line', $field, false ); $city = self::get_property( 'address_city', $field, false ); $state = self::get_property( 'address_state', $field, false ); $zip = self::get_property( 'address_zip', $field, false ); $country = self::get_property( 'address_country', $field, false ); $street_required = self::get_property( 'street_address_required', $field, false, 'bool' ); $line_required = self::get_property( 'address_line_required', $field, false, 'bool' ); $city_required = self::get_property( 'address_city_required', $field, false, 'bool' ); $state_required = self::get_property( 'address_state_required', $field, false, 'bool' ); $zip_required = self::get_property( 'address_zip_required', $field, false, 'bool' ); $country_required = self::get_property( 'address_country_required', $field, false, 'bool' ); $street_data = isset( $data['street_address'] ) ? $data['street_address'] : ''; $line_data = isset( $data['address_line'] ) ? $data['address_line'] : ''; $zip_data = isset( $data['zip'] ) ? $data['zip'] : ''; $country_data = isset( $data['country'] ) ? $data['country'] : ''; $city_data = isset( $data['city'] ) ? $data['city'] : ''; $state_data = isset( $data['state'] ) ? $data['state'] : ''; if ( $street && $street_required && empty( $street_data ) ) { $this->validation_message[ $id . '-street_address' ] = $this->get_field_multiple_required_message( $id, $field, 'street_address_required_message', 'street_address', esc_html__( 'This field is required. Please enter the street address.', 'forminator' ) ); } if ( $line && $line_required && empty( $line_data ) ) { $this->validation_message[ $id . '-address_line' ] = $this->get_field_multiple_required_message( $id, $field, 'address_line_required_message', 'address_line', esc_html__( 'This field is required. Please enter address line.', 'forminator' ) ); } if ( $city && $city_required && empty( $city_data ) ) { $this->validation_message[ $id . '-city' ] = $this->get_field_multiple_required_message( $id, $field, 'address_city_required_message', 'address_city', esc_html__( 'This field is required. Please enter the city.', 'forminator' ) ); } if ( $state && $state_required && empty( $state_data ) ) { $this->validation_message[ $id . '-state' ] = $this->get_field_multiple_required_message( $id, $field, 'address_state_required_message', 'address_state', esc_html__( 'This field is required. Please enter the state.', 'forminator' ) ); } if ( $zip && $zip_required && empty( $zip_data ) ) { $this->validation_message[ $id . '-zip' ] = $this->get_field_multiple_required_message( $id, $field, 'address_zip_required_message', 'address_zip', esc_html__( 'This field is required. Please enter the zip code.', 'forminator' ) ); } if ( $country && $country_required && empty( $country_data ) ) { $this->validation_message[ $id . '-country' ] = $this->get_field_multiple_required_message( $id, $field, 'address_country_required_message', 'address_country', esc_html__( 'This field is required. Please select the country.', 'forminator' ) ); } } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. if ( is_array( $data ) ) { $data = forminator_sanitize_array_field( $data ); } else { $data = forminator_sanitize_field( $data ); } return apply_filters( 'forminator_field_address_sanitize', $data, $field, $original_data ); } } PK ~\<�N N calculation.phpnu �[��� <?php /** * The Forminator_Calculation class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Calculation * * @since 1.7 */ class Forminator_Calculation extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'calculation'; /** * Type * * @var string */ public $type = 'calculation'; /** * Position * * @var int */ public $position = 11; /** * Options * * @var array */ public $options = array(); /** * Is input * * @var bool */ public $is_input = false; /** * Has counter * * @var bool */ public $has_counter = false; /** * Icon * * @var string */ public $icon = 'sui-icon-calculator'; /** * Is calculable * * @var bool */ public $is_calculable = true; /** * Forminator_Text constructor. * * @since 1.7 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Calculations', 'forminator' ); } /** * Field defaults * * @since 1.7 * @return array */ public function defaults() { return array( 'field_label' => esc_html__( 'Calculations', 'forminator' ), ); } /** * Field front-end markup * * @since 1.7 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $settings = $views_obj->model->settings; $this->field = $field; $this->form_settings = $settings; $hidden_behavior = self::get_property( 'hidden_behavior', $field ); $descr_position = self::get_description_position( $field, $settings ); $html = ''; $wrapper = array(); $id = self::get_property( 'element_id', $field ); $name = $id; $id = $id . '-field_' . Forminator_CForm_Front::$uid; $required = self::get_property( 'required', $field, false ); $value = esc_html( self::get_post_data( $name, self::get_property( 'default_value', $field ) ) ); $label = esc_html( self::get_property( 'field_label', $field, '' ) ); $description = self::get_property( 'description', $field, '' ); $formula = self::get_property( 'formula', $field, '', 'str' ); $is_hidden = self::get_property( 'hidden', $field, false, 'bool' ); $suffix = self::get_property( 'suffix', $field ); $prefix = self::get_property( 'prefix', $field ); $precision = self::get_calculable_precision( $field ); $separator = self::get_property( 'separators', $field, 'blank' ); $separators = $this->forminator_separators( $separator, $field ); $point = ! empty( $precision ) ? $separators['point'] : ''; if ( is_numeric( $formula ) ) { $formula = $formula . '*1'; } $fields_in_formula = Forminator_CForm_Front_Action::calculator_pull_fields( $formula ); $full_matches = $fields_in_formula[0]; foreach ( $fields_in_formula[1] as $key => $field_id ) { if ( ! isset( $full_matches[ $key ] ) ) { continue; } $form_id = isset( $this->form_settings['form_id'] ) ? $this->form_settings['form_id'] : 0; if ( ! empty( $form_id ) ) { if ( false !== strpos( $field_id, 'number-' ) || false !== strpos( $field_id, 'currency-' ) || false !== strpos( $field_id, 'slider-' ) ) { $field_form = Forminator_Form_Model::model()->load( $form_id ); $formula_field = $field_form->get_field( $field_id, true ); $calc_enabled = self::get_property( 'calculations', $formula_field, true, 'bool' ); if ( ! $calc_enabled ) { $field_val = Forminator_CForm_Front_Action::replace_to( $field_id, $formula ); $find_str = $full_matches[ $key ]; $replace_with = '(' . ( $field_val ) . ')'; $formula = implode( $replace_with, explode( $find_str, $formula, 2 ) ); } } } } $number_attr = array( 'type' => 'text', 'name' => $name, 'value' => $value, 'id' => $id, 'class' => 'forminator-calculation', 'data-formula' => $formula, 'data-required' => $required, 'data-decimal-point' => $point, 'data-precision' => $precision, 'data-is-hidden' => $is_hidden, 'disabled' => 'disabled', // mark as disabled so this value won't send to backend later. 'data-decimals' => $precision, 'data-inputmask' => "'groupSeparator': '" . $separators['separator'] . "', 'radixPoint': '" . $point . "', 'digits': '" . $precision . "'", ); if ( $hidden_behavior && 'zero' === $hidden_behavior ) { $number_attr['data-hidden-behavior'] = $hidden_behavior; } if ( empty( $prefix ) && empty( $suffix ) ) { $number_attr['class'] .= ' forminator-input'; } if ( ! empty( $prefix ) || ! empty( $suffix ) ) { $wrapper = array( '<div class="forminator-input forminator-input-with-prefix">', sprintf( '<span class="forminator-suffix">%s</span></div>', esc_html( $suffix ) ), '', esc_html( $prefix ), ); } $html .= '<div class="forminator-field">'; $html .= self::create_input( $number_attr, $label, $description, $required, $descr_position, $wrapper ); $html .= '</div>'; return apply_filters( 'forminator_field_calculation_markup', $html, $id, $required, $value ); } /** * Return field inline validation rules * * @since 1.7 * @return string */ public function get_validation_rules() { return ''; } /** * Return field inline validation errors * * @since 1.7 * @return string */ public function get_validation_messages() { return ''; } /** * Sanitize data * * @since 1.7 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { // Sanitize. $data = forminator_sanitize_field( $data ); return apply_filters( 'forminator_field_calculation_sanitize', $data, $field ); } /** * Get calculable value for repeted item in Group fields * * @param array $submitted_field_data Submitted data. * @param array $field_settings Field settings. * @param string $group_suffix Group suffix. * @param array $grouped_fields Fields in the same group. * @return string Formula */ public static function get_calculable_repeater_value( $submitted_field_data, $field_settings, $group_suffix, $grouped_fields ) { $calculable_value = self::get_calculable_value( $submitted_field_data, $field_settings ); if ( ! $group_suffix ) { return $calculable_value; } foreach ( $grouped_fields as $group_field_slug ) { $calculable_value = str_replace( '{' . $group_field_slug . '}', '{' . $group_field_slug . $group_suffix . '}', $calculable_value ); } return $calculable_value; } /** * Get calculable value * * @since 1.7 * @inheritdoc * @param mixed $submitted_field_data Submitted field data. * @param array $field_settings Field settings. */ public static function get_calculable_value( $submitted_field_data, $field_settings ) { $formula = self::get_property( 'formula', $field_settings, '', 'str' ); /** * Filter formula being used on calculable value of calculation field * * @since 1.7 * * @param string $formula * @param array $submitted_data * @param array $field_settings * * @return string|int|float formula, or hardcoded value */ $formula = apply_filters( 'forminator_field_calculation_calculable_value', $formula, Forminator_CForm_Front_Action::$prepared_data, $field_settings ); if ( empty( $formula ) ) { return 0.0; } return $formula; } /** * Get default error message * * @since 1.7 * * @return string */ public static function default_error_message() { $message = esc_html__( 'Failed to calculate field.', 'forminator' ); /** * Filter default error message * * @since 1.7 * * @param string $message * * @return string */ $message = apply_filters( 'forminator_field_calculation_default_error_message', $message ); return $message; } } PK ~\�݇24R 4R select.phpnu �[��� <?php /** * The Forminator_Select class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_SingleValue * * @property array field * @since 1.0 */ class Forminator_Select extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'select'; /** * Type * * @var string */ public $type = 'select'; /** * Position * * @var int */ public $position = 11; /** * Options * * @var array */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon-element-select'; /** * Is calculable * * @var bool */ public $is_calculable = true; /** * Forminator_SingleValue constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Select', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'value_type' => 'single', 'field_label' => esc_html__( 'Select', 'forminator' ), 'options' => array( array( 'label' => esc_html__( 'Option 1', 'forminator' ), 'value' => 'one', 'limit' => '', 'key' => forminator_unique_key(), ), array( 'label' => esc_html__( 'Option 2', 'forminator' ), 'value' => 'two', 'limit' => '', 'key' => forminator_unique_key(), ), ), 'multiselect_style' => 'modern', ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $providers = apply_filters( 'forminator_field_' . $this->slug . '_autofill', array(), $this->slug ); $autofill_settings = array( 'select' => array( 'values' => forminator_build_autofill_providers( $providers ), ), ); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $i = 1; $html = ''; $id = self::get_property( 'element_id', $field ); $name = $id; $uniq_id = Forminator_CForm_Front::$uid; $form_id = $settings['form_id']; $id = 'forminator-form-' . $form_id . '__field--' . $id . '_' . $uniq_id; $required = self::get_property( 'required', $field, false, 'bool' ); $options = self::get_options( $field ); $post_value = self::get_post_data( $name, false ); $description = self::get_property( 'description', $field, '' ); $label = esc_html( self::get_property( 'field_label', $field, '' ) ); $design = $this->get_form_style( $settings ); $field_type = self::get_property( 'value_type', $field, '' ); $search_status = self::get_property( 'search_status', $field, '' ); $is_limit = self::get_property( 'limit_status', $field, '' ); $placeholder = esc_html( self::get_property( 'placeholder', $field, '' ) ); $calc_enabled = self::get_property( 'calculations', $field, false, 'bool' ); $field_style = self::get_property( 'multiselect_style', $field, 'standard' ); $hidden_behavior = self::get_property( 'hidden_behavior', $field ); $checkbox_in_dropdown = self::get_property( 'checkbox_in_dropdown', $field, 'hide' ); $descr_position = self::get_description_position( $field, $settings ); $html .= '<div class="forminator-field">'; $html .= self::get_field_label( $label, $id, $required ); if ( 'above' === $descr_position ) { $html .= self::get_description( $description, $id, $descr_position ); } if ( $required && empty( $placeholder ) ) { $placeholder = esc_html__( 'Please select an option', 'forminator' ); } $hidden_calc_behavior = ''; if ( $hidden_behavior && 'zero' === $hidden_behavior ) { $hidden_calc_behavior = ' data-hidden-behavior="' . $hidden_behavior . '"'; } if ( 'multiselect' === $field_type && 'standard' === $field_style ) { $post_value = self::get_post_data( $name, self::FIELD_PROPERTY_VALUE_NOT_EXIST ); $field_name = $name; $name = $name . '[]'; $draft_value = isset( $draft_value['value'] ) ? (array) $draft_value['value'] : array(); $draft_value = array_map( 'trim', $draft_value ); $html .= sprintf( '<div class="forminator-multiselect" aria-labelledby="%s"%s>', esc_attr( $id . '-label' ), ( ! empty( $description ) ? ' aria-describedby="' . esc_attr( $id . '-description' ) . '"' : '' ) ); // Multi values. $default_arr = array(); $default = ''; $prefill = false; $prefil_valid = false; $draft_valid = false; // Check if Pre-fill parameter used. if ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $prefill = $this->get_prefill( $field, $prefill ); } foreach ( $options as $key => $option ) { $pref_value = $option['value'] ? esc_html( wp_strip_all_tags( $option['value'] ) ) : wp_kses_post( wp_strip_all_tags( $option['label'] ) ); $pref_values = explode( ',', $prefill ); if ( in_array( strval( $pref_value ), array_map( 'strval', $pref_values ), true ) ) { $prefil_valid = true; $default_arr[] = $pref_value; } if ( ! empty( $draft_value ) ) { if ( in_array( trim( $pref_value ), $draft_value ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict $draft_valid = true; $default_arr[] = $pref_value; } } } foreach ( $options as $key => $option ) { $value = $option['value'] ? esc_html( wp_strip_all_tags( $option['value'] ) ) : ''; $input_id = $id . '-' . $i; $option_default = isset( $option['default'] ) ? filter_var( $option['default'], FILTER_VALIDATE_BOOLEAN ) : false; $calculation_value = $calc_enabled && isset( $option['calculation'] ) ? $option['calculation'] : 0.0; $selected = false; // Skip options with empty values. if ( '' === $value ) { continue; } if ( isset( $is_limit ) && 'enable' === $is_limit && Forminator_Form_Entry_Model::is_option_limit_reached( $form_id, $field_name, $field_type, $option ) ) { continue; } if ( self::FIELD_PROPERTY_VALUE_NOT_EXIST !== $post_value ) { if ( is_array( $post_value ) ) { $selected = in_array( $value, $post_value ); // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict } } elseif ( $draft_valid ) { if ( in_array( strval( $value ), array_map( 'strval', $default_arr ), true ) ) { $selected = true; } } elseif ( $prefil_valid ) { if ( in_array( strval( $value ), array_map( 'strval', $default_arr ), true ) ) { $selected = true; } } else { $selected = $option_default; } if ( $option_default && ! $prefil_valid && ! $draft_valid ) { $default_arr[] = $value; } $selected = $selected ? 'checked="checked"' : ''; $extra_class = $selected ? ' forminator-is_checked' : ''; $class = 'forminator-option' . $extra_class; $label_id = $input_id . '-label'; $html .= sprintf( '<label id="' . $label_id . '" for="%s" class="' . $class . '">', $input_id ); $html .= sprintf( '<input type="checkbox" name="%s" value="%s" id="%s" aria-labelledby="%s" data-calculation="%s" %s %s />', $name, $value, $input_id, $label_id, $calculation_value, $hidden_calc_behavior, $selected ); $html .= wp_kses_post( wp_strip_all_tags( $option['label'] ) ); $html .= '</label>'; ++$i; } if ( ! empty( $default_arr ) ) { $default = wp_json_encode( $default_arr, JSON_FORCE_OBJECT ); } $html .= sprintf( "<input type='hidden' name='%s' class='%s' value='%s' />", $field_name . '-multiselect-default-values', 'multiselect-default-values', $default ); $html .= '</div>'; } else { $default_arr = array(); $options_markup = ''; $default = ''; $search = 'false'; $draft_valid = false; $post_valid = false; $prefil_valid = false; if ( 'enable' === $search_status ) { $search = 'true'; } if ( ! empty( $placeholder ) ) { switch ( $field_type ) { case 'multiselect': if ( 'none' !== $design ) { break; } $options_markup = sprintf( '<option value="" disabled>%s</option>', $placeholder ); break; default: $selected = ( 'none' === $design ) ? 'selected' : ''; $disabled = ( 'none' === $design ) ? 'disabled' : ''; $options_markup = sprintf( '<option value="" %s %s>%s</option>', $disabled, $selected, $placeholder ); break; } } foreach ( $options as $key => $option ) { $pref_value = ( $option['value'] || is_numeric( $option['value'] ) ? esc_html( wp_strip_all_tags( $option['value'] ) ) : '' ); if ( isset( $draft_value['value'] ) ) { if ( is_array( $draft_value['value'] ) ) { if ( in_array( trim( $pref_value ), $draft_value['value'], true ) ) { $draft_valid = true; $default_arr[] = $pref_value; } } elseif ( trim( $draft_value['value'] ) === trim( $pref_value ) ) { $draft_valid = true; $default = $pref_value; } } if ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $prefill = $this->get_prefill( $field, false ); $prefill_values = explode( ',', $prefill ); if ( in_array( $pref_value, $prefill_values ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict $default = $pref_value; $prefil_valid = true; } } if ( $pref_value === $post_value ) { $default = $pref_value; $post_valid = true; } } foreach ( $options as $key => $option ) { $value = ( $option['value'] || is_numeric( $option['value'] ) ? esc_html( wp_strip_all_tags( $option['value'] ) ) : '' ); $option_default = isset( $option['default'] ) ? filter_var( $option['default'], FILTER_VALIDATE_BOOLEAN ) : false; $calculation_value = $calc_enabled && isset( $option['calculation'] ) ? esc_html( $option['calculation'] ) : 0.0; $option_selected = false; // Skip options with empty values. if ( '' === $value ) { continue; } if ( isset( $is_limit ) && 'enable' === $is_limit && Forminator_Form_Entry_Model::is_option_limit_reached( $form_id, $name, $field_type, $option ) ) { continue; } if ( $option_default && ! $draft_valid && ! $prefil_valid && ! $post_valid ) { $default = $value; } if ( $post_valid ) { if ( $value === $post_value ) { $option_selected = true; } } elseif ( $draft_valid ) { if ( ! empty( $default_arr ) && in_array( $value, $default_arr, true ) ) { $option_selected = true; } elseif ( $value === $default ) { $option_selected = true; } } elseif ( $prefil_valid ) { if ( $value === $default ) { $option_selected = true; } } elseif ( $option_default ) { $option_selected = true; } $selected = $option_selected ? 'selected="selected"' : ''; $options_markup .= sprintf( '<option value="%s" %s data-calculation="%s">%s</option>', esc_html( $value ), $selected, esc_html( $calculation_value ), wp_kses_post( wp_strip_all_tags( $option['label'] ) ) ); } $select_type = ''; $has_checkbox = 'false'; $allow_clear = 'false'; $search_placeholder = $placeholder; if ( 'multiselect' === $field_type && 'modern' === $field_style ) { $select_type = 'multiple'; $name = $name . '[]'; $allow_clear = 'true'; $search_placeholder = 'Search'; if ( 'show' === $checkbox_in_dropdown ) { $has_checkbox = 'true'; } } $html .= sprintf( '<select %s id="%s" class="%s" data-required="%s" name="%s" data-default-value="%s"%s data-placeholder="%s" data-search="%s" data-search-placeholder="%s" data-checkbox="%s" data-allow-clear="%s" aria-labelledby="%s"%s>', $select_type, $id, 'forminator-select--field forminator-select2 forminator-select2-multiple', // class. $required, $name, $default, $hidden_calc_behavior, esc_attr( wp_strip_all_tags( html_entity_decode( $placeholder ) ) ), $search, $search_placeholder, $has_checkbox, $allow_clear, esc_attr( $id . '-label' ), ( ! empty( $description ) ? ' aria-describedby="' . esc_attr( $id . '-description' ) . '"' : '' ) ); $html .= $options_markup; $html .= sprintf( '</select>' ); } if ( 'above' !== $descr_position ) { $html .= self::get_description( $description, $id, $descr_position ); } $html .= '</div>'; return apply_filters( 'forminator_field_single_markup', $html, $id, $required, $options ); } /** * Return field inline validation rules * * @since 1.0 * @return string */ public function get_validation_rules() { $rules = ''; $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); $field_type = self::get_property( 'value_type', $field, '' ); if ( $is_required && 'multiselect' !== $field_type ) { $rules .= '"' . $this->get_id( $field ) . '": "required",'; } if ( $is_required && 'multiselect' === $field_type ) { $rules .= '"' . $this->get_id( $field ) . '[]": "required",'; } return apply_filters( 'forminator_field_single_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @return string */ public function get_validation_messages() { $messages = ''; $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); $field_type = self::get_property( 'value_type', $field, '' ); if ( $is_required ) { $required_message = self::get_property( 'required_message', $field, esc_html__( 'This field is required. Please select a value.', 'forminator' ) ); $required_message = apply_filters( 'forminator_single_field_required_validation_message', $required_message, $id, $field ); if ( 'multiselect' === $field_type ) { $messages .= '"' . $this->get_id( $field ) . '[]": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } else { $messages .= '"' . $this->get_id( $field ) . '": "' . forminator_addcslashes( $required_message ) . '",' . "\n"; } } return $messages; } /** * Are submitted options reached limit * * @param array $field Field settings. * @param array $selected_options Submitted select options. * @return bool */ private static function options_reached_limit( $field, $selected_options ) { $is_limit = self::get_property( 'limit_status', $field ); // Skip if this field is not limitted. if ( ! isset( $is_limit ) || 'enable' !== $is_limit ) { return false; } $field_name = self::get_property( 'element_id', $field ); $field_type = self::get_property( 'value_type', $field ); $form_id = Forminator_CForm_Front_Action::$module_id; foreach ( $field['options'] as $option ) { // Ski if this option was not selected. if ( ! in_array( $option['value'], $selected_options, true ) ) { continue; } if ( Forminator_Form_Entry_Model::is_option_limit_reached( $form_id, $field_name, $field_type, $option, true ) ) { return true; } } return false; } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $select_type = isset( $field['value_type'] ) ? $field['value_type'] : 'single'; $id = self::get_property( 'element_id', $field ); $value_exists = true; if ( is_array( $data ) ) { foreach ( $data as $value ) { if ( false === array_search( strval( htmlspecialchars_decode( $value ) ), array_map( 'strval', array_column( $field['options'], 'value' ) ), true ) ) { $value_exists = false; break; } } } elseif ( ! empty( $data ) && false === array_search( strval( htmlspecialchars_decode( $data ) ), array_map( 'strval', array_column( $field['options'], 'value' ) ), true ) ) { $value_exists = false; } if ( ! $value_exists ) { $this->validation_message[ $id ] = apply_filters( 'forminator_select_field_nonexistent_validation_message', esc_html__( 'Selected value does not exist.', 'forminator' ), $id, $field ); } // Check if select options is reached limit. $value_limited = self::options_reached_limit( $field, (array) $data ); if ( $value_limited ) { $this->validation_message[ $id ] = apply_filters( 'forminator_select_field_nonavailable_validation_message', esc_html__( 'The selected option is no longer available.', 'forminator' ), $id, $field ); } if ( $this->is_required( $field ) ) { if ( ! isset( $data ) || ( 'single' === $select_type && $this->is_single_select_empty( $data ) ) || ( 'multiselect' === $select_type && empty( $data ) ) ) { $required_message = self::get_property( 'required_message', $field, esc_html__( 'This field is required. Please select a value.', 'forminator' ) ); $this->validation_message[ $id ] = apply_filters( 'forminator_single_field_required_validation_message', $required_message, $id, $field ); } } } /** * Check is simple select empty. * * @param mixed $data Value. * @return bool */ private function is_single_select_empty( $data ) { if ( is_array( $data ) ) { $data = implode( '', $data ); } if ( is_string( $data ) && ! strlen( $data ) ) { return true; } return false; } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; // Sanitize. if ( is_array( $data ) ) { foreach ( $data as $key => $val ) { $data[ $key ] = trim( wp_kses_post( $val ) ); } } else { $data = trim( wp_kses_post( $data ) ); } return apply_filters( 'forminator_field_single_sanitize', $data, $field, $original_data ); } /** * Internal calculable value * * @since 1.7 * * @param array $submitted_field Submitted field. * @param array $field_settings Field settings. * * @return float|string */ private static function calculable_value( $submitted_field, $field_settings ) { $enabled = self::get_property( 'calculations', $field_settings, false, 'bool' ); if ( ! $enabled ) { return self::FIELD_NOT_CALCULABLE; } $sums = 0.0; $field_type = self::get_property( 'value_type', $field_settings, '' ); $options = self::get_property( 'options', $field_settings, array() ); $is_single = 'multiselect' !== $field_type; if ( $is_single ) { // process as array. $submitted_field = array( $submitted_field ); } if ( ! is_array( $submitted_field ) ) { return $sums; } foreach ( $options as $option ) { $option_value = isset( $option['value'] ) ? $option['value'] : ( isset( $option['label'] ) ? $option['label'] : '' ); $option_value = trim( $option_value ); $calculation_value = isset( $option['calculation'] ) ? $option['calculation'] : 0.0; // strict array compare disabled to allow non-coercion type compare. $first_key = array_search( $option_value, $submitted_field, true ); if ( false !== $first_key ) { // this one is selected. $sums += floatval( $calculation_value ); unset( $submitted_field[ $first_key ] ); } } return floatval( $sums ); } /** * Get calculable value * * @since 1.7 * @inheritdoc * @param array $submitted_field_data Submitted field data. * @param array $field_settings Field settings. */ public static function get_calculable_value( $submitted_field_data, $field_settings ) { $calculable_value = self::calculable_value( $submitted_field_data, $field_settings ); /** * Filter formula being used on calculable value on select field * * @since 1.7 * * @param float $calculable_value * @param array $submitted_field_data * @param array $field_settings * * @return string|int|float */ $calculable_value = apply_filters( 'forminator_field_select_calculable_value', $calculable_value, $submitted_field_data, $field_settings ); return $calculable_value; } } PK ~\��)9. 9. textarea.phpnu �[��� <?php /** * The Forminator_Textarea class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Text * * @since 1.6 */ class Forminator_Textarea extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'textarea'; /** * Type * * @var string */ public $type = 'textarea'; /** * Position * * @var int */ public $position = 7; /** * Options * * @var array */ public $options = array(); /** * Is input * * @var bool */ public $is_input = true; /** * Has counter * * @var bool */ public $has_counter = true; /** * Icon * * @var string */ public $icon = 'sui-icon-blog'; /** * Forminator_Text constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Textarea', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'input_type' => 'line', 'limit_type' => 'characters', 'field_label' => esc_html__( 'Text', 'forminator' ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $providers = apply_filters( 'forminator_field_' . $this->slug . '_autofill', array(), $this->slug ); $autofill_settings = array( 'text' => array( 'values' => forminator_build_autofill_providers( $providers ), ), ); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $use_ajax_load = ! empty( $settings['use_ajax_load'] ) || ! empty( $field['parent_group'] ); $this->field = $field; $this->form_settings = $settings; $descr_position = self::get_description_position( $field, $settings ); $html = ''; $name = self::get_property( 'element_id', $field ); $id = self::get_field_id( $name ); $required = self::get_property( 'required', $field, false, 'bool' ); $default = esc_html( self::get_property( 'default', $field, false ) ); $placeholder = $this->sanitize_value( self::get_property( 'placeholder', $field ) ); $label = esc_html( self::get_property( 'field_label', $field, '' ) ); $description = self::get_property( 'description', $field, '' ); $limit = self::get_property( 'limit', $field, 0, 'num' ); $limit_type = self::get_property( 'limit_type', $field, '', 'str' ); $editor_type = self::get_property( 'editor-type', $field, false, 'bool' ); $default_height = self::get_property( 'default-height', $field, 140 ); $is_wp_editor = true === $editor_type && ! $use_ajax_load; $desc_id = $is_wp_editor ? 'forminator-wp-editor-' . $id . '-description' : $id . '-description'; $autofill_markup = $this->get_element_autofill_markup_attr( self::get_property( 'element_id', $field ) ); $textarea = array( 'name' => $name, 'placeholder' => $placeholder, 'id' => $id, 'class' => 'forminator-textarea', 'rows' => 6, 'style' => 'min-height:' . $default_height . 'px;', ); // Add maxlength attribute if limit_type is characters. if ( ! empty( $limit ) && 'characters' === $limit_type ) { $textarea['maxlength'] = $limit; } if ( isset( $draft_value['value'] ) ) { $default = wp_kses_post( $draft_value['value'] ); } elseif ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $default = $this->get_prefill( $field, $default ); } if ( ! empty( $default ) ) { $textarea['content'] = $default; } elseif ( isset( $autofill_markup['value'] ) ) { $textarea['content'] = $autofill_markup['value']; unset( $autofill_markup['value'] ); } // Add required class if form ajax load is enabled. if ( $required && true === $editor_type && $use_ajax_load ) { $textarea['class'] .= esc_attr( ' do-validate forminator-wp-editor-required' ); } if ( ! empty( $description ) ) { $textarea['aria-describedby'] = $id . '-description'; } $textarea = array_merge( $textarea, $autofill_markup ); $description_block = ''; if ( ! empty( $description ) || ( ! empty( $limit ) && ! empty( $limit_type ) ) ) { $description_block .= sprintf( '<span id="%s" class="forminator-description">', esc_attr( $desc_id ) ); if ( ! empty( $description ) ) { $description_block .= self::esc_description( $description, $name ); } // Counter. if ( ( ! empty( $limit ) && ! empty( $limit_type ) ) ) { $description_block .= sprintf( '<span data-limit="%s" data-type="%s" data-editor="%s">0 / %s</span>', $limit, $limit_type, $editor_type, $limit ); } $description_block .= '</span>'; } $description_block = apply_filters( 'forminator_field_description', $description_block, $description, $id, $descr_position ); $html .= '<div class="forminator-field">'; $html .= self::get_field_label( $label, $id, $required ); if ( 'above' === $descr_position ) { $html .= $description_block; } if ( $is_wp_editor ) { $html .= self::create_wp_editor( $textarea, '', '', $required, $default_height, $limit ); } else { $html .= self::create_textarea( $textarea, '', '', $required ); if ( true === $editor_type && $use_ajax_load ) { $args = self::get_tinymce_args( $id ); $script = '<script>wp.editor.initialize("' . esc_attr( $id ) . '", ' . $args . ');</script>'; // if it's inside group field and 'Load form using AJAX' option is disabled. if ( empty( $settings['use_ajax_load'] ) && ! empty( $field['parent_group'] ) ) { // wrap into document ready. $script = str_replace( array( '<script>', '</script>' ), array( '<script>jQuery(function() {', '});</script>' ), $script ); } $html .= $script; Forminator_CForm_Front::$load_wp_enqueue_editor = true; } } if ( 'above' !== $descr_position ) { $html .= $description_block; } $html .= '</div>'; return apply_filters( 'forminator_field_text_markup', $html, $field ); } /** * Return field inline validation rules * * @since 1.0 * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); $has_limit = $this->has_limit( $field ); $rules = ''; if ( ! isset( $field['limit'] ) ) { $field['limit'] = 0; } if ( $is_required || $has_limit ) { $rules = '"' . $this->get_id( $field ) . '": {'; if ( $is_required ) { $rules .= '"required": true,'; } if ( $has_limit ) { if ( isset( $field['limit_type'] ) && 'characters' === trim( $field['limit_type'] ) ) { $rules .= '"maxlength": ' . $field['limit'] . ','; } else { $rules .= '"maxwords": ' . $field['limit'] . ','; } } $rules .= '},'; } return apply_filters( 'forminator_field_text_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @return string */ public function get_validation_messages() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); $has_limit = $this->has_limit( $field ); $messages = ''; $required_message = self::get_property( 'required_message', $field, '' ); if ( $is_required || $has_limit ) { $messages .= '"' . $this->get_id( $field ) . '": {'; if ( $is_required ) { $required_error = apply_filters( 'forminator_text_field_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please enter text.', 'forminator' ) ), $id, $field ); $messages .= '"required": "' . forminator_addcslashes( $required_error ) . '",' . "\n"; } if ( $has_limit ) { if ( isset( $field['limit_type'] ) && 'characters' === trim( $field['limit_type'] ) ) { $max_length_error = apply_filters( 'forminator_text_field_characters_validation_message', esc_html__( 'You exceeded the allowed amount of characters. Please check again.', 'forminator' ), $id, $field ); $messages .= '"maxlength": "' . forminator_addcslashes( $max_length_error ) . '",' . "\n"; } else { $max_words_error = apply_filters( 'forminator_text_field_words_validation_message', esc_html__( 'You exceeded the allowed amount of words. Please check again.', 'forminator' ), $id, $field ); $messages .= '"maxwords": "' . forminator_addcslashes( $max_words_error ) . '",' . "\n"; } } $messages .= '},'; } return $messages; } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); $data = html_entity_decode( $data ); if ( ! isset( $field['limit'] ) ) { $field['limit'] = 0; } if ( $this->is_required( $field ) ) { $required_message = self::get_property( 'required_message', $field, '' ); if ( empty( $data ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_text_field_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please enter text.', 'forminator' ) ), $id, $field ); } } if ( $this->has_limit( $field ) ) { // Remove newline character. $data = str_replace( "\r", '', $data ); if ( ( isset( $field['limit_type'] ) && 'characters' === trim( $field['limit_type'] ) ) && ( mb_strlen( wp_strip_all_tags( $data ) ) > $field['limit'] ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_text_field_characters_validation_message', esc_html__( 'You exceeded the allowed amount of characters. Please check again.', 'forminator' ), $id, $field ); } elseif ( ( isset( $field['limit_type'] ) && 'words' === trim( $field['limit_type'] ) ) ) { if ( ! empty( $data ) && ! empty( $field['editor-type'] ) && 'true' === $field['editor-type'] ) { $data = wp_strip_all_tags( $data ); } $words = preg_split( '/[\s]+/', $data ); if ( is_array( $words ) && count( $words ) > $field['limit'] ) { $this->validation_message[ $id ] = apply_filters( 'forminator_text_field_words_validation_message', esc_html__( 'You exceeded the allowed amount of words. Please check again.', 'forminator' ), $id, $field ); } } } } /** * Sanitization was improved and moved to class-core.php - sanitize_array * * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; $editor_type = self::get_property( 'editor-type', $field, false, 'bool' ); // Sanitize. if ( true === $editor_type ) { $data = wp_kses_post( $data ); } else { $data = forminator_sanitize_textarea( $data ); } return apply_filters( 'forminator_field_text_sanitize', $data, $field, $original_data ); } } PK ~\�.B�I �I password.phpnu �[��� <?php /** * The Forminator_Password class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Password * * @since 1.0 */ class Forminator_Password extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'password'; /** * Type * * @var string */ public $type = 'password'; /** * Position * * @var int */ public $position = 6; /** * Options * * @var array */ public $options = array(); /** * Is input * * @var bool */ public $is_input = true; /** * Has Counter * * @var bool */ public $has_counter = false; /** * Icon * * @var string */ public $icon = 'sui-icon-key'; /** * Confirm prefix * * @var string * @since 1.11 */ public $confirm_prefix = 'confirm'; /** * Forminator_Text constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Password', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'field_label' => esc_html__( 'Password', 'forminator' ), 'placeholder' => esc_html__( 'Enter your password', 'forminator' ), 'confirm-password-label' => esc_html__( 'Confirm Password', 'forminator' ), 'confirm-password-placeholder' => esc_html__( 'Confirm new password', 'forminator' ), 'strength' => 'none', ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $providers = apply_filters( 'forminator_field_' . $this->slug . '_autofill', array(), $this->slug ); $autofill_settings = array( 'text' => array( 'values' => forminator_build_autofill_providers( $providers ), ), ); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $settings = $views_obj->model->settings; $this->field = $field; $this->form_settings = $settings; $html = ''; $id = self::get_property( 'element_id', $field ); $name = $id; $id = self::get_field_id( $id ); $required = self::get_property( 'required', $field, false ); $ariareq = 'false'; $default = self::get_property( 'default', $field, false ); $placeholder = $this->sanitize_value( self::get_property( 'placeholder', $field ) ); $field_type = trim( self::get_property( 'input_type', $field ) ); $label = self::get_property( 'field_label', $field, '' ); $description = self::get_property( 'description', $field, '' ); $limit = self::get_property( 'limit', $field, 0, 'num' ); $limit_type = self::get_property( 'limit_type', $field, '', 'str' ); $is_confirm = self::get_property( 'confirm-password', $field, '', 'bool' ); $autofill_markup = $this->get_element_autofill_markup_attr( self::get_property( 'element_id', $field ) ); if ( (bool) $required ) { $ariareq = 'true'; } $input_text = array( 'name' => $name, 'value' => $default, 'placeholder' => $placeholder, 'id' => $id, 'class' => 'forminator-input forminator-name--field', 'data-required' => $required, 'type' => 'password', ); if ( ! empty( $default ) ) { $input_text['value'] = $default; } if ( ! empty( $description ) ) { $input_text['aria-describedby'] = $id . '-description'; } $input_text = array_merge( $input_text, $autofill_markup ); $html .= '<div class="forminator-field">'; $html .= self::create_input( $input_text, $label, '', $required, ); $html .= '</div>'; // Counter. if ( ! empty( $description ) || ( ! empty( $limit ) && ! empty( $limit_type ) ) ) { $html .= sprintf( '<div class="forminator-description forminator-description-password" id="%s">', $id . '-description' ); $description = str_replace( '{lostpassword_url}', wp_lostpassword_url( get_permalink() ), $description ); if ( ! empty( $description ) ) { $html .= wp_kses_post( $description ); } if ( ( ! empty( $limit ) && ! empty( $limit_type ) ) ) { $html .= sprintf( '<span data-limit="%s" data-type="%s">0 / %s</span>', $limit, $limit_type, $limit ); } $html .= '</div>'; } // Confirm password. if ( $is_confirm ) { $id = $this->confirm_prefix . '_' . self::get_property( 'element_id', $field ); $name = $id; $id = self::get_field_id( $id ); $confirm_password_label = self::get_property( 'confirm-password-label', $field, '' ); $confirm_password_placeholder = self::get_property( 'confirm-password-placeholder', $field ); $confirm_password_description = self::get_property( 'confirm-password-description', $field, '' ); $confirm_input_text = array( 'name' => $name, 'value' => $default, 'placeholder' => $confirm_password_placeholder, 'id' => $id, 'class' => 'forminator-input forminator-name--field', 'data-required' => $required, 'type' => 'password', ); if ( ! empty( $confirm_password_description ) ) { $input_text['aria-describedby'] = $id . '-description'; } if ( ! empty( $default ) ) { $confirm_input_text['value'] = $default; } $confirm_input_text = array_merge( $confirm_input_text, $autofill_markup ); // Field 'Confirm password' is inside the separated 'forminator row'. $html_prev_field = '</div></div>';// because there are '.forminator-row' and '.forminator-col' classes for Password field. $html .= apply_filters( 'forminator_prev_last_tag_before_conf_password_field_markup', $html_prev_field, $field ); $html .= '<div class="forminator-row">'; $cols = 12; $html_before_conf_password_field = sprintf( '<div class="forminator-col forminator-col-%s">', $cols ); $html .= apply_filters( 'forminator_before_conf_password_field_markup', $html_before_conf_password_field ); $html .= '<div class="forminator-field">'; $html .= self::create_input( $confirm_input_text, $confirm_password_label, '', $required, ); $html .= '</div>'; // Counter. if ( ! empty( $confirm_password_description ) || ( ! empty( $limit ) && ! empty( $limit_type ) ) ) { $html .= sprintf( '<span class="forminator-description" id="%s">', $id . '-description' ); if ( ! empty( $confirm_password_description ) ) { $html .= wp_kses_post( $confirm_password_description ); } if ( ( ! empty( $limit ) && ! empty( $limit_type ) ) ) { $html .= sprintf( '<span data-limit="%s" data-type="%s">0 / %s</span>', $limit, $limit_type, $limit ); } $html .= '</span>'; } } return apply_filters( 'forminator_field_password_markup', $html, $field ); } /** * Calculate the password score * * @since 1.11 * * @param string $password Password. * * @return bool */ private function get_password_strength( $password = '' ) { $symbol_size = 0; $strlen = mb_strlen( $password ); // Password is optional and empty so don't check strength. if ( 0 === $strlen ) { return true; } if ( $strlen < 8 ) { return false; } if ( preg_match( '/[0-9]/', $password ) ) { $symbol_size += 10; } if ( preg_match( '/[a-z]/', $password ) ) { $symbol_size += 20; } if ( preg_match( '/[A-Z]/', $password ) ) { $symbol_size += 20; } if ( preg_match( '/[^a-zA-Z0-9]/', $password ) ) { $symbol_size += 30; } if ( preg_match( '/[=!\-@.,_*#&?^`%$+\/{\[\]|}^?~]/', $password ) ) { $symbol_size += 30; } $nat_log = log( pow( $symbol_size, $strlen ) ); $score = $nat_log / log( 2 ); return $score >= 54; } /** * Return field inline validation rules * * @since 1.0 * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); $has_limit = $this->has_limit( $field ); $rules = ''; $is_confirm = self::get_property( 'confirm-password', $field, '', 'bool' ); $min_password_strength = self::get_property( 'strength', $field ); $module_id = isset( $this->form_settings['form_id'] ) ? $this->form_settings['form_id'] : ''; $module_selector = ''; if ( ! empty( $module_id ) ) { $module_selector = "#forminator-module-{$module_id}"; $render_id = Forminator_Render_Form::get_render_id( $module_id ); $module_selector .= "[data-forminator-render='{$render_id}']"; } if ( ! isset( $field['limit'] ) ) { $field['limit'] = 0; } $rules = '"' . $this->get_id( $field ) . '": {'; if ( $is_required || $has_limit ) { if ( $is_required ) { $rules .= '"required": true,'; } if ( $has_limit ) { if ( isset( $field['limit_type'] ) && 'characters' === trim( $field['limit_type'] ) ) { $rules .= '"maxlength": ' . $field['limit'] . ','; } else { $rules .= '"maxwords": ' . $field['limit'] . ','; } } } // Min password strength. if ( isset( $min_password_strength ) && '' !== $min_password_strength && 'none' !== $min_password_strength ) { $rules .= '"forminatorPasswordStrength": true,'; } $rules .= '},'; if ( $is_confirm ) { $rules .= '"' . $this->confirm_prefix . '_' . $this->get_id( $field ) . '": {'; if ( $is_required ) { $rules .= '"required": true,'; } $rules .= '"equalTo": "' . $module_selector . ' #' . self::get_field_id( $this->get_id( $field ) ) . '",' . "\n"; $rules .= '},'; } return apply_filters( 'forminator_field_text_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @return string */ public function get_validation_messages() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $is_required = $this->is_required( $field ); $has_limit = $this->has_limit( $field ); $messages = ''; $required_message = self::get_property( 'required_message', $field, '' ); $is_confirm = self::get_property( 'confirm-password', $field, '', 'bool' ); $min_password_strength = self::get_property( 'strength', $field ); $messages .= '"' . $this->get_id( $field ) . '": {'; if ( $is_required || $has_limit ) { if ( $is_required ) { $required_error = apply_filters( 'forminator_text_field_required_validation_message', ! empty( $required_message ) ? $required_message : esc_html__( 'Your password is required.', 'forminator' ), $id, $field ); $messages .= '"required": "' . $required_error . '",' . "\n"; } if ( $has_limit ) { if ( isset( $field['limit_type'] ) && 'characters' === trim( $field['limit_type'] ) ) { $max_length_error = apply_filters( 'forminator_text_field_characters_validation_message', esc_html__( 'You exceeded the allowed amount of characters. Please check again.', 'forminator' ), $id, $field ); $messages .= '"maxlength": "' . $max_length_error . '",' . "\n"; } else { $max_words_error = apply_filters( 'forminator_text_field_words_validation_message', esc_html__( 'You exceeded the allowed amount of words. Please check again.', 'forminator' ), $id, $field ); $messages .= '"maxwords": "' . $max_words_error . '",' . "\n"; } } } // Min password strength. if ( isset( $min_password_strength ) && '' !== $min_password_strength && 'none' !== $min_password_strength ) { $strength_validation_message = self::get_property( 'strength_validation_message', $field, '' ); $min_strength_error = apply_filters( 'forminator_text_field_min_password_strength_validation_message', ! empty( $strength_validation_message ) ? $strength_validation_message : __( 'Your password doesn\'t meet the minimum strength requirement. We recommend using 8 or more characters with a mix of letters, numbers & symbols.', 'forminator' ), $id, $field ); $messages .= '"forminatorPasswordStrength": "' . esc_html( $min_strength_error ) . '",' . "\n"; } $messages .= '},'; if ( $is_confirm ) { $required_confirm_message = self::get_property( 'required_confirm_message', $field, '' ); $messages .= '"' . $this->confirm_prefix . '_' . $this->get_id( $field ) . '": {'; if ( $is_required ) { $required_error = apply_filters( 'forminator_confirm_password_field_required_validation_message', ! empty( $required_confirm_message ) ? $required_confirm_message : esc_html__( 'You must confirm your chosen password.', 'forminator' ), $id, $field ); $messages .= '"required": "' . $required_error . '",' . "\n"; } $validation_message_not_match = self::get_property( 'validation_message', $field, '' ); $not_match_error = apply_filters( 'forminator_confirm_password_field_not_match_validation_message', ! empty( $validation_message_not_match ) ? $validation_message_not_match : esc_html__( 'Your passwords don\'t match.', 'forminator' ), $id, $field ); $messages .= '"equalTo": "' . $not_match_error . '",' . "\n"; $messages .= '},'; } return $messages; } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); $min_password_strength = self::get_property( 'strength', $field ); $is_confirm = self::get_property( 'confirm-password', $field, '', 'bool' ); // TODO: Remove old property "validation". if ( ! isset( $field['limit'] ) ) { $field['limit'] = 0; } if ( $this->is_required( $field ) ) { $required_message = self::get_property( 'required_message', $field, '' ); if ( empty( $data ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_text_field_required_validation_message', ( ! empty( $required_message ) ? $required_message : esc_html__( 'This field is required. Please enter text.', 'forminator' ) ), $id, $field ); } } if ( $this->has_limit( $field ) ) { if ( ( isset( $field['limit_type'] ) && 'characters' === trim( $field['limit_type'] ) ) && ( strlen( $data ) > $field['limit'] ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_text_field_characters_validation_message', esc_html__( 'You exceeded the allowed amount of characters. Please check again.', 'forminator' ), $id, $field ); } elseif ( ( isset( $field['limit_type'] ) && 'words' === trim( $field['limit_type'] ) ) ) { $words = preg_split( '/\s+/', $data ); if ( is_array( $words ) && count( $words ) > $field['limit'] ) { $this->validation_message[ $id ] = apply_filters( 'forminator_text_field_words_validation_message', esc_html__( 'You exceeded the allowed amount of words. Please check again.', 'forminator' ), $id, $field ); } } } if ( isset( $min_password_strength ) && '' !== $min_password_strength && 'none' !== $min_password_strength ) { $strength_validation_message = self::get_property( 'strength_validation_message', $field, '' ); if ( ! $this->get_password_strength( $data ) ) { $this->validation_message[ $id ] = apply_filters( 'forminator_text_field_min_password_strength_validation_message', ! empty( $strength_validation_message ) ? $strength_validation_message : __( 'Your password doesn\'t meet the minimum strength requirement. We recommend using 8 or more characters with a mix of letters, numbers & symbols.', 'forminator' ), $id, $field ); } } $password = Forminator_CForm_Front_Action::$prepared_data[ $id ]; $confirm_password = ! empty( Forminator_CForm_Front_Action::$prepared_data[ 'confirm_' . $id ] ) ? Forminator_CForm_Front_Action::$prepared_data[ 'confirm_' . $id ] : ''; if ( $is_confirm && ! empty( $data ) && $password !== $confirm_password ) { $validation_message_not_match = self::get_property( 'validation_message', $field, '' ); $validation_message_not_match_message = apply_filters( 'forminator_confirm_password_field_not_match_validation_message', ! empty( $validation_message_not_match ) ? $validation_message_not_match : esc_html__( 'Your passwords don\'t match.', 'forminator' ), $id, $field ); $this->validation_message[ $id ] = $validation_message_not_match_message; $this->validation_message[ 'confirm_' . $id ] = $validation_message_not_match_message; } } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; if ( is_array( $data ) ) { $data = $this->sanitize_array_field( $data ); } else { $data = $this->sanitize_field( $data ); } return apply_filters( 'forminator_field_text_sanitize', $data, $field, $original_data ); } /** * Sanitize password array field. * * @param array $data Array values. * * @return mixed */ private function sanitize_array_field( $data ) { foreach ( $data as &$value ) { if ( is_array( $value ) ) { $value = $this->sanitize_array_field( $value ); } else { $value = $this->sanitize_field( $value ); } } return $data; } /** * Sanitize password field. * * @param string $data Password value. * * @return string */ private function sanitize_field( $data ) { // Password doesn't required sanitize as it is hashed while processing/save. Also it fails to support tags and characters like %1d, %20. // Add slashes as we removed from original post while sanitize post data (It fails to support quotation marks). return wp_slash( $data ); } /** * Remove password-N fields * * @param array $data Submitted data. * @return array */ public static function remove_password_field_values( $data ) { foreach ( $data as $key => $value ) { if ( false !== stripos( $key, 'password-' ) ) { unset( $data[ $key ] ); } } return $data; } } PK ~\��*܌ � html.phpnu �[��� <?php /** * The Forminator_Html class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Html * * @since 1.0 */ class Forminator_Html extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'html'; /** * Type * * @var string */ public $type = 'html'; /** * Position * * @var int */ public $position = 17; /** * Options * * @var array */ public $options = array(); /** * Icon * * @var string */ public $icon = 'sui-icon-code'; /** * Forminator_Html constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'HTML', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'field_label' => esc_html__( 'HTML', 'forminator' ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { // Unsupported Autofill. $autofill_settings = array(); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * * @return mixed */ public function markup( $field, $views_obj ) { $settings = $views_obj->model->settings; $html = ''; $label = esc_html( self::get_property( 'field_label', $field ) ); $id = self::get_property( 'element_id', $field ); $form_id = false; $html .= '<div class="forminator-field forminator-merge-tags" data-field="' . $id . '">'; if ( $label ) { $html .= sprintf( '<label class="forminator-label">%s</label>', $label ); } // Check if form_id exist. if ( isset( $settings['form_id'] ) ) { $form_id = $settings['form_id']; } // To allow iframes in content. add_filter( 'wp_kses_allowed_html', array( 'Forminator_Core', 'add_iframe_to_kses_allowed_html' ) ); $content = wp_kses_post( self::get_property( 'variations', $field ) ); remove_filter( 'wp_kses_allowed_html', array( 'Forminator_Core', 'add_iframe_to_kses_allowed_html' ) ); $html .= forminator_replace_variables( $content, $form_id ); $html .= '</div>'; return $html; } } PK ~\��(G�7 �7 email.phpnu �[��� <?php /** * The Forminator_Email class. * * @package Forminator */ if ( ! defined( 'ABSPATH' ) ) { die(); } /** * Class Forminator_Email * * @since 1.0 */ class Forminator_Email extends Forminator_Field { /** * Name * * @var string */ public $name = ''; /** * Slug * * @var string */ public $slug = 'email'; /** * Position * * @var int */ public $position = 2; /** * Type * * @var string */ public $type = 'email'; /** * Options * * @var array */ public $options = array(); /** * Is input * * @var bool */ public $is_input = true; /** * Icon * * @var string */ public $icon = 'sui-icon-mail'; /** * Forminator_Email constructor. * * @since 1.0 */ public function __construct() { parent::__construct(); $this->name = esc_html__( 'Email', 'forminator' ); } /** * Field defaults * * @since 1.0 * @return array */ public function defaults() { return array( 'validation' => false, 'field_label' => esc_html__( 'Email Address', 'forminator' ), 'confirm-email-label' => esc_html__( 'Confirm Email Address', 'forminator' ), 'confirm-email-placeholder' => esc_html__( 'Re-type Email Address', 'forminator' ), 'confirm-email-mismatch' => esc_html__( 'Your email addresses do not match', 'forminator' ), 'required_confirm_message' => esc_html__( 'You must confirm your email address', 'forminator' ), ); } /** * Autofill Setting * * @since 1.0.5 * * @param array $settings Settings. * * @return array */ public function autofill_settings( $settings = array() ) { $providers = apply_filters( 'forminator_field_' . $this->slug . '_autofill', array(), $this->slug ); $autofill_settings = array( 'email' => array( 'values' => forminator_build_autofill_providers( $providers ), ), ); return $autofill_settings; } /** * Field front-end markup * * @since 1.0 * * @param array $field Field. * @param Forminator_Render_Form $views_obj Forminator_Render_Form object. * @param array $draft_value Draft value. * * @return mixed */ public function markup( $field, $views_obj, $draft_value = null ) { $settings = $views_obj->model->settings; $this->field = $field; $this->form_settings = $settings; $id = self::get_property( 'element_id', $field ); $name = $id; $id = self::get_field_id( $id ); $required = self::get_property( 'required', $field, false ); $ariareq = 'false'; $placeholder = $this->sanitize_value( self::get_property( 'placeholder', $field ) ); $value = esc_html( self::get_property( 'value', $field ) ); $label = esc_html( self::get_property( 'field_label', $field ) ); $description = self::get_property( 'description', $field ); $is_confirm = self::get_property( 'confirm-email', $field, '', 'bool' ); $descr_position = self::get_description_position( $field, $settings ); if ( (bool) $required ) { $ariareq = 'true'; } if ( isset( $draft_value['value'] ) ) { $value = esc_attr( $draft_value['value'] ); } elseif ( $this->has_prefill( $field ) ) { // We have pre-fill parameter, use its value or $value. $value = $this->get_prefill( $field, $value ); } $email_attr = array( 'type' => 'email', 'name' => $name, 'value' => $value, 'placeholder' => $placeholder, 'id' => $id, 'class' => 'forminator-input forminator-email--field', 'data-required' => $required, 'aria-required' => $ariareq, ); $autofill_markup = $this->get_element_autofill_markup_attr( self::get_property( 'element_id', $field ) ); $email_attr = array_merge( $email_attr, $autofill_markup ); $html = '<div class="forminator-field">'; $html .= self::create_input( $email_attr, $label, $description, $required, $descr_position ); $html .= '</div>'; // Confirm email. if ( $is_confirm ) { $name = 'confirm_' . self::get_property( 'element_id', $field ); $id = self::get_field_id( $name ); $confirm_email_label = self::get_property( 'confirm-email-label', $field, __( 'Confirm Email Address', 'forminator' ) ); $confirm_email_placeholder = self::get_property( 'confirm-email-placeholder', $field, __( 'Re-type Email Address', 'forminator' ) ); $confirm_email_description = self::get_property( 'confirm-email-description', $field ); $confirm_input_text = array( 'type' => 'email', 'name' => $name, 'value' => $value, 'placeholder' => $confirm_email_placeholder, 'id' => $id, 'class' => 'forminator-input forminator-name--field', 'data-required' => $required, 'aria-required' => $ariareq, ); if ( ! empty( $confirm_email_description ) ) { $confirm_input_text['aria-describedby'] = $id . '-description'; } $confirm_input_text = array_merge( $confirm_input_text, $autofill_markup ); $confirm_input = '<div class="forminator-field">'; $confirm_input .= self::create_input( $confirm_input_text, $confirm_email_label, $confirm_email_description, $required, $descr_position ); $confirm_input .= '</div>'; $html = '<div class="forminator-row-inside forminator-row-with-confirmation-email">' . '<div class="forminator-col forminator-col-6">' . $html . '</div>' . '<div class="forminator-col forminator-col-6">' . $confirm_input . '</div>' . '</div>'; } return apply_filters( 'forminator_field_email_markup', $html, $id, $required, $placeholder, $value ); } /** * Return field inline validation rules * * @since 1.0 * @return string */ public function get_validation_rules() { $field = $this->field; $id = self::get_property( 'element_id', $field ); $rules = '"' . $this->get_id( $field ) . '": {' . "\n"; $is_validate = self::get_property( 'validation', $field, false ); $is_confirm = self::get_property( 'confirm-email', $field, '', 'bool' ); $filter_type = self::get_property( 'filter_type', $field ); $email_list = 'deny' === $filter_type ? self::get_property( 'denylist', $field ) : self::get_property( 'allowlist', $field ); if ( $this->is_required( $field ) ) { $rules .= '"required": true,'; } if ( $is_validate ) { $rules .= '"emailWP": true,'; } else { $rules .= '"email": false,'; } if ( $email_list && in_array( $filter_type, array( 'allow', 'deny' ), true ) ) { $email_list = str_replace( ',', '|', $email_list ); $rules .= '"emailFilter": {"filter_type":"' . $filter_type . '","email_list":"' . $email_list . '"},'; } $rules .= '},' . "\n"; if ( $is_confirm ) { $rules .= '"confirm_' . $this->get_id( $field ) . '": {' . "\n"; if ( $this->is_required( $field ) ) { $rules .= '"required": true,'; } $rules .= $is_validate ? '"emailWP": true,' : '"email": false,'; $rules .= '"equalToClosestEmail": true,'; $rules .= '},' . "\n"; } return apply_filters( 'forminator_field_email_validation_rules', $rules, $id, $field ); } /** * Return field inline validation errors * * @since 1.0 * @return string */ public function get_validation_messages() { $field = $this->field; $id = $this->get_id( $field ); $is_validate = self::get_property( 'validation', $field ); $validation_message = self::get_property( 'validation_message', $field, esc_html__( 'This is not a valid email.', 'forminator' ) ); $is_confirm = self::get_property( 'confirm-email', $field, '', 'bool' ); $filter_type = self::get_property( 'filter_type', $field ); $filter_error = self::get_filter_error( $field ); $is_required = $this->is_required( $field ); $validation_message = htmlentities( $validation_message ); $messages = '"' . $id . '": {' . "\n"; if ( $this->is_required( $field ) ) { $default_required_error_message = $this->get_field_multiple_required_message( $id, $field, 'required_message', '', esc_html__( 'This field is required. Please input a valid email.', 'forminator' ) ); $messages .= '"required": "' . forminator_addcslashes( $default_required_error_message ) . '",' . "\n"; } if ( $is_validate ) { $messages .= '"emailWP": "' . forminator_addcslashes( $validation_message ) . '",' . "\n"; $messages .= '"email": "' . forminator_addcslashes( $validation_message ) . '",' . "\n"; } if ( 'deny' === $filter_type || 'allow' === $filter_type ) { $messages .= '"emailFilter": "' . forminator_addcslashes( $filter_error ) . '",' . "\n"; } $messages .= '},' . "\n"; if ( $is_confirm ) { $required_confirm_message = self::get_property( 'required_confirm_message', $field ); $messages .= '"confirm_' . $id . '": {' . "\n"; if ( $is_required ) { $required_error = apply_filters( 'forminator_confirm_email_field_required_validation_message', ! empty( $required_confirm_message ) ? $required_confirm_message : esc_html__( 'You must confirm your email address', 'forminator' ), $id, $field ); $messages .= '"required": "' . $required_error . '",' . "\n"; } $validation_message_not_match = self::get_property( 'confirm-email-mismatch', $field ); $not_match_error = apply_filters( 'forminator_confirm_email_field_not_match_validation_message', ! empty( $validation_message_not_match ) ? $validation_message_not_match : esc_html__( 'Your email addresses do not match', 'forminator' ), $id, $field ); $messages .= '"equalToClosestEmail": "' . $not_match_error . '",' . "\n"; $messages .= '},' . "\n"; } $messages = apply_filters( 'forminator_email_field_validation_message', $messages, $id, $field, $validation_message ); return $messages; } /** * Field back-end validation * * @since 1.0 * * @param array $field Field. * @param array|string $data Data. * * @return bool|void */ public function validate( $field, $data ) { $id = self::get_property( 'element_id', $field ); $is_validate = self::get_property( 'validation', $field ); $validation_message = self::get_property( 'validation_message', $field, esc_html__( 'This is not a valid email.', 'forminator' ) ); $is_confirm = self::get_property( 'confirm-email', $field, '', 'bool' ); if ( $this->is_required( $field ) ) { $required_error_message = $this->get_field_multiple_required_message( $id, $field, 'required_message', '', esc_html__( 'This field is required. Please input a valid email.', 'forminator' ) ); if ( empty( $data ) ) { $this->validation_message[ $id ] = $required_error_message; return false; } } if ( $is_validate && ! empty( $data ) ) { $validation_message = htmlentities( $validation_message ); if ( 320 < strlen( $data ) || ! is_email( $data ) || ! filter_var( $data, FILTER_VALIDATE_EMAIL ) ) { $this->validation_message[ $id ] = $validation_message; } } if ( ! empty( $data ) ) { $filter_type = self::get_property( 'filter_type', $field ); $error = self::get_filter_error( $field ); if ( 'deny' === $filter_type ) { $denylist = self::get_property( 'denylist', $field ); $found = self::filter_email( $data, $denylist ); if ( $found ) { $this->validation_message[ $id ] = $error; } } elseif ( 'allow' === $filter_type ) { $allowlist = self::get_property( 'allowlist', $field ); $found = self::filter_email( $data, $allowlist ); if ( false === $found ) { $this->validation_message[ $id ] = $error; } } } $confirm_email = Forminator_CForm_Front_Action::$prepared_data[ 'confirm_' . $id ] ?? ''; if ( $is_confirm && ! empty( $data ) && $data !== $confirm_email ) { $validation_message_not_match = self::get_property( 'confirm-email-mismatch', $field ); $validation_message_not_match_message = apply_filters( 'forminator_confirm_email_field_not_match_validation_message', ! empty( $validation_message_not_match ) ? $validation_message_not_match : esc_html__( 'Your email addresses do not match', 'forminator' ), $id, $field ); $this->validation_message[ 'confirm_' . $id ] = $validation_message_not_match_message; } } /** * Get filter error * * @param array $field Field. * * @return string */ public static function get_filter_error( array $field ): string { $error = self::get_property( 'filter-error', $field ); if ( empty( $error ) ) { $error = esc_html__( 'This email is not allowed. Please use a different one.', 'forminator' ); } return $error; } /** * Filter email * * @param string $email Email. * @param string $email_list List. * * @return bool|null */ public static function filter_email( $email, $email_list ): ?bool { if ( empty( $email_list ) ) { return null; } $email_list = explode( ',', $email_list ); foreach ( $email_list as $item ) { // Remove spaces in email addresses. $item = str_replace( array( ' ', "\n", "\r", "\t" ), '', $item ); // Escape special characters. $item = preg_quote( $item, '/' ); // Support * as wildcard. $item = str_replace( '\*', '.*', $item ); // Add start and end delimiters. $item = '/' . $item . '$/'; if ( preg_match( $item, $email ) ) { return true; } } return false; } /** * Sanitize data * * @since 1.0.2 * * @param array $field Field. * @param array|string $data - the data to be sanitized. * * @return array|string $data - the data after sanitization */ public function sanitize( $field, $data ) { $original_data = $data; $is_validate = self::get_property( 'validation', $field ); // Sanitize email. if ( is_string( $data ) ) { if ( $is_validate ) { $data = sanitize_email( $data ); } else { $data = sanitize_text_field( $data ); } } return apply_filters( 'forminator_field_email_sanitize', $data, $field, $original_data ); } } PK u~\����8 �8 multivalue.phpnu �[��� PK v~\���or or �8 time.phpnu �[��� PK v~\�|�"� "� p� stripe.phpnu �[��� PK v~\���3� � �b date.phpnu �[��� PK w~\��+0AY AY � name.phpnu �[��� PK w~\��0b� � ^m consent.phpnu �[��� PK w~\�{T�� � ,� page-break.phpnu �[��� PK x~\b�W(�4 �4 T� number.phpnu �[��� PK x~\t,�5 �5 �� slider.phpnu �[��� PK x~\\�3 �3 S� currency.phpnu �[��� PK y~\�Ek� � E+ upload.phpnu �[��� PK y~\�H�, �, �� text.phpnu �[��� PK y~\XT�2� 2� i� postdata.phpnu �[��� PK z~\�d�` ` �l website.phpnu �[��� PK z~\��s�S S r� gdprcheckbox.phpnu �[��� PK {~\�Q(�$ �$ � captcha.phpnu �[��� PK {~\�L�R �� group.phpnu �[��� PK |~\�� :� � )� stripe-payment-element.phpnu �[��� PK |~\1��=`= `= _� phone.phpnu �[��� PK }~\cvX�z z �1 section.phpnu �[��� PK }~\^�<F6 6 �> rating.phpnu �[��� PK ~\�}���: �: U radio.phpnu �[��� PK ~\`� � -� hidden.phpnu �[��� PK ~\t�K��5 �5 �� paypal.phpnu �[��� PK ~\�y�� � �� custom.phpnu �[��� PK ~\����l l �� address.phpnu �[��� PK ~\<�N N �b calculation.phpnu �[��� PK ~\�݇24R 4R W� select.phpnu �[��� PK ~\��)9. 9. �� textarea.phpnu �[��� PK ~\�.B�I �I : password.phpnu �[��� PK ~\��*܌ � N html.phpnu �[��� PK ~\��(G�7 �7 �W email.phpnu �[��� PK b ��