PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.35
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.35
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
formidable / classes / models / fields / FrmFieldUrl.php

FrmFieldUrl.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.35, at classes/models/fields/FrmFieldUrl.php

128 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /**
7 * @since 3.0
8 */
9 class FrmFieldUrl extends FrmFieldType {
10
11 /**
12 * @var string
13 *
14 * @since 3.0
15 */
16 protected $type = 'url';
17
18 /**
19 * @var bool
20 */
21 protected $array_allowed = false;
22
23 /**
24 * @return bool[]
25 */
26 protected function field_settings_for_type() {
27 return array(
28 'size' => true,
29 'clear_on_focus' => true,
30 'invalid' => true,
31 'show_image' => true,
32 );
33 }
34
35 /**
36 * @return array
37 */
38 protected function extra_field_opts() {
39 return array(
40 'show_image' => 0,
41 );
42 }
43
44 /**
45 * @return string
46 */
47 protected function get_field_name() {
48 return __( 'Website', 'formidable' );
49 }
50
51 /**
52 * @param array $atts
53 *
54 * @return void
55 */
56 protected function fill_default_atts( &$atts ) {
57 $defaults = array(
58 'sep' => ', ',
59 'html' => false,
60 );
61 $atts = wp_parse_args( $atts, $defaults );
62
63 if ( $atts['html'] ) {
64 $atts['sep'] = ' ';
65 }
66 }
67
68 /**
69 * @param array $args
70 */
71 public function validate( $args ) {
72 $value = $args['value'];
73
74 if ( trim( $value ) === 'http://' || ! $value ) {
75 $value = '';
76 } else {
77 $value = esc_url_raw( $value );
78 $value = preg_match( '/^(https?|ftps?|mailto|news|feed|telnet):/is', $value ) ? $value : 'https://' . $value;
79 }
80
81 FrmEntriesHelper::set_posted_value( $this->field, $value, $args );
82
83 $errors = array();
84
85 // Validate the url format
86 if ( $value && ! preg_match( '/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value ) ) {
87 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' );
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
90 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'blank' );
91 }
92
93 return $errors;
94 }
95
96 protected function prepare_display_value( $value, $atts ) {
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 );
111 }
112 }
113
114 return $images;
115 }
116
117 /**
118 * @since 4.0.04
119 *
120 * @param array|string $value
121 *
122 * @return void
123 */
124 public function sanitize_value( &$value ) {
125 FrmAppHelper::sanitize_value( 'esc_url_raw', $value );
126 }
127 }
128