PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/fields/FrmFieldUrl.php +29 -16 6.25.1 → trunk View file →
@@ -9,8 +9,9 @@
9 9 class FrmFieldUrl extends FrmFieldType {
10 10
11 11 /**
12 12 * @var string
13 + *
13 14 * @since 3.0
14 15 */
15 16 protected $type = 'url';
16 17
@@ -47,8 +48,10 @@
47 48 return __( 'Website', 'formidable' );
48 49 }
49 50
50 51 /**
52 + * @param array $atts
53 + *
51 54 * @return void
52 55 */
53 56 protected function fill_default_atts( &$atts ) {
54 57 $defaults = array(
@@ -61,11 +64,15 @@
61 64 $atts['sep'] = ' ';
62 65 }
63 66 }
64 67
68 + /**
69 + * @param array $args
70 + */
65 71 public function validate( $args ) {
66 72 $value = $args['value'];
67 - if ( trim( $value ) === 'http://' || empty( $value ) ) {
73 +
74 + if ( trim( $value ) === 'http://' || ! $value ) {
68 75 $value = '';
69 76 } else {
70 77 $value = esc_url_raw( $value );
71 78 $value = preg_match( '/^(https?|ftps?|mailto|news|feed|telnet):/is', $value ) ? $value : 'https://' . $value;
@@ -74,12 +81,13 @@
74 81 FrmEntriesHelper::set_posted_value( $this->field, $value, $args );
75 82
76 83 $errors = array();
77 84
78 - // validate the url format
79 - if ( ! empty( $value ) && ! preg_match( '/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value ) ) {
85 + // Validate the url format
86 + if ( $value && ! preg_match( '/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value ) ) {
80 87 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' );
81 - } elseif ( $this->field->required == '1' && empty( $value ) ) {
88 + // skipcq: PHP-W1067 -- $this->field is always a field object by the time validate() runs; FrmFieldType's constructor just accepts array|int|object for lazy construction elsewhere.
89 + } elseif ( $this->field->required == '1' && ! $value ) { // phpcs:ignore Universal.Operators.StrictComparisons
82 90 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'blank' );
83 91 }
84 92
85 93 return $errors;
@@ -85,27 +93,32 @@
85 93 return $errors;
86 94 }
87 95
88 96 protected function prepare_display_value( $value, $atts ) {
89 - if ( $atts['html'] ) {
90 - $images = '';
91 - foreach ( (array) $value as $url ) {
92 - $image_regex = '/(\.(?i)(jpg|jpeg|png|gif))$/';
93 - $is_image = preg_match( $image_regex, $url );
94 - if ( $is_image ) {
95 - $images .= '<img src="' . esc_url( $url ) . '" class="frm_image_from_url" alt="" /> ';
96 - } else {
97 - $images .= strip_tags( $url );
98 - }
97 + if ( ! $atts['html'] ) {
98 + return $value;
99 + }
100 +
101 + $images = '';
102 +
103 + foreach ( (array) $value as $url ) {
104 + $image_regex = '/(\.(?i)(jpg|jpeg|png|gif))$/';
105 + $is_image = preg_match( $image_regex, $url );
106 +
107 + if ( $is_image ) {
108 + $images .= '<img src="' . esc_url( $url ) . '" class="frm_image_from_url" alt="" /> ';
109 + } else {
110 + $images .= strip_tags( $url );
99 111 }
100 - $value = $images;
101 112 }
102 113
103 - return $value;
114 + return $images;
104 115 }
105 116
106 117 /**
107 118 * @since 4.0.04
119 + *
120 + * @param array|string $value
108 121 *
109 122 * @return void
110 123 */
111 124 public function sanitize_value( &$value ) {