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

127 lines 2.5 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 } elseif ( $this->field->required == '1' && ! $value ) { // phpcs:ignore Universal.Operators.StrictComparisons
89 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'blank' );
90 }
91
92 return $errors;
93 }
94
95 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 );
110 }
111 }
112
113 return $images;
114 }
115
116 /**
117 * @since 4.0.04
118 *
119 * @param array|string $value
120 *
121 * @return void
122 */
123 public function sanitize_value( &$value ) {
124 FrmAppHelper::sanitize_value( 'esc_url_raw', $value );
125 }
126 }
127