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

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