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