| @@ -9,14 +9,18 @@ | ||
| 9 | 9 | class FrmFieldUrl extends FrmFieldType { |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * @var string |
| 13 | - * | |
| 14 | 13 | * @since 3.0 |
| 15 | 14 | */ |
| 16 | 15 | protected $type = 'url'; |
| 17 | 16 | |
| 18 | 17 | /** |
| 18 | + * @var string | |
| 19 | + */ | |
| 20 | + protected $display_type = 'text'; | |
| 21 | + | |
| 22 | + /** | |
| 19 | 23 | * @var bool |
| 20 | 24 | */ |
| 21 | 25 | protected $array_allowed = false; |
| 22 | 26 | |
| @@ -48,10 +52,8 @@ | ||
| 48 | 52 | return __( 'Website', 'formidable' ); |
| 49 | 53 | } |
| 50 | 54 | |
| 51 | 55 | /** |
| 52 | - * @param array $atts | |
| 53 | - * | |
| 54 | 56 | * @return void |
| 55 | 57 | */ |
| 56 | 58 | protected function fill_default_atts( &$atts ) { |
| 57 | 59 | $defaults = array( |
| @@ -64,19 +66,15 @@ | ||
| 64 | 66 | $atts['sep'] = ' '; |
| 65 | 67 | } |
| 66 | 68 | } |
| 67 | 69 | |
| 68 | - /** | |
| 69 | - * @param array $args | |
| 70 | - */ | |
| 71 | 70 | public function validate( $args ) { |
| 72 | 71 | $value = $args['value']; |
| 73 | - | |
| 74 | - if ( trim( $value ) === 'http://' || ! $value ) { | |
| 72 | + if ( trim( $value ) == 'http://' || empty( $value ) ) { | |
| 75 | 73 | $value = ''; |
| 76 | 74 | } else { |
| 77 | 75 | $value = esc_url_raw( $value ); |
| 78 | - $value = preg_match( '/^(https?|ftps?|mailto|news|feed|telnet):/is', $value ) ? $value : 'https://' . $value; | |
| 76 | + $value = preg_match( '/^(https?|ftps?|mailto|news|feed|telnet):/is', $value ) ? $value : 'http://' . $value; | |
| 79 | 77 | } |
| 80 | 78 | |
| 81 | 79 | FrmEntriesHelper::set_posted_value( $this->field, $value, $args ); |
| 82 | 80 | |
| @@ -81,12 +79,12 @@ | ||
| 81 | 79 | FrmEntriesHelper::set_posted_value( $this->field, $value, $args ); |
| 82 | 80 | |
| 83 | 81 | $errors = array(); |
| 84 | 82 | |
| 85 | - // Validate the url format | |
| 86 | - if ( $value && ! preg_match( '/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value ) ) { | |
| 83 | + // validate the url format | |
| 84 | + if ( ! empty( $value ) && ! preg_match( '/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value ) ) { | |
| 87 | 85 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' ); |
| 88 | - } elseif ( $this->field->required == '1' && ! $value ) { // phpcs:ignore Universal.Operators.StrictComparisons | |
| 86 | + } elseif ( $this->field->required == '1' && empty( $value ) ) { | |
| 89 | 87 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'blank' ); |
| 90 | 88 | } |
| 91 | 89 | |
| 92 | 90 | return $errors; |
| @@ -92,32 +90,27 @@ | ||
| 92 | 90 | return $errors; |
| 93 | 91 | } |
| 94 | 92 | |
| 95 | 93 | protected function prepare_display_value( $value, $atts ) { |
| 96 | - if ( ! $atts['html'] ) { | |
| 97 | - return $value; | |
| 98 | - } | |
| 99 | - | |
| 100 | - $images = ''; | |
| 101 | - | |
| 102 | - foreach ( (array) $value as $url ) { | |
| 103 | - $image_regex = '/(\.(?i)(jpg|jpeg|png|gif))$/'; | |
| 104 | - $is_image = preg_match( $image_regex, $url ); | |
| 105 | - | |
| 106 | - if ( $is_image ) { | |
| 107 | - $images .= '<img src="' . esc_url( $url ) . '" class="frm_image_from_url" alt="" /> '; | |
| 108 | - } else { | |
| 109 | - $images .= strip_tags( $url ); | |
| 94 | + if ( $atts['html'] ) { | |
| 95 | + $images = ''; | |
| 96 | + foreach ( (array) $value as $url ) { | |
| 97 | + $image_regex = '/(\.(?i)(jpg|jpeg|png|gif))$/'; | |
| 98 | + $is_image = preg_match( $image_regex, $url ); | |
| 99 | + if ( $is_image ) { | |
| 100 | + $images .= '<img src="' . esc_attr( $url ) . '" class="frm_image_from_url" alt="" /> '; | |
| 101 | + } else { | |
| 102 | + $images .= strip_tags( $url ); | |
| 103 | + } | |
| 110 | 104 | } |
| 105 | + $value = $images; | |
| 111 | 106 | } |
| 112 | 107 | |
| 113 | - return $images; | |
| 108 | + return $value; | |
| 114 | 109 | } |
| 115 | 110 | |
| 116 | 111 | /** |
| 117 | 112 | * @since 4.0.04 |
| 118 | - * | |
| 119 | - * @param array|string $value | |
| 120 | 113 | * |
| 121 | 114 | * @return void |
| 122 | 115 | */ |
| 123 | 116 | public function sanitize_value( &$value ) { |