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

120 lines 2.4 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 * @since 3.0
14 */
15 protected $type = 'url';
16
17 /**
18 * @var string
19 */
20 protected $display_type = 'text';
21
22 /**
23 * @var bool
24 */
25 protected $array_allowed = false;
26
27 /**
28 * @return bool[]
29 */
30 protected function field_settings_for_type() {
31 return array(
32 'size' => true,
33 'clear_on_focus' => true,
34 'invalid' => true,
35 'show_image' => true,
36 );
37 }
38
39 /**
40 * @return array
41 */
42 protected function extra_field_opts() {
43 return array(
44 'show_image' => 0,
45 );
46 }
47
48 /**
49 * @return string
50 */
51 protected function get_field_name() {
52 return __( 'Website', 'formidable' );
53 }
54
55 /**
56 * @return void
57 */
58 protected function fill_default_atts( &$atts ) {
59 $defaults = array(
60 'sep' => ', ',
61 'html' => false,
62 );
63 $atts = wp_parse_args( $atts, $defaults );
64
65 if ( $atts['html'] ) {
66 $atts['sep'] = ' ';
67 }
68 }
69
70 public function validate( $args ) {
71 $value = $args['value'];
72 if ( trim( $value ) == 'http://' || empty( $value ) ) {
73 $value = '';
74 } else {
75 $value = esc_url_raw( $value );
76 $value = preg_match( '/^(https?|ftps?|mailto|news|feed|telnet):/is', $value ) ? $value : 'http://' . $value;
77 }
78
79 FrmEntriesHelper::set_posted_value( $this->field, $value, $args );
80
81 $errors = array();
82
83 // validate the url format
84 if ( ! empty( $value ) && ! preg_match( '/^http(s)?:\/\/(?:localhost|(?:[\da-z\.-]+\.[\da-z\.-]+))/i', $value ) ) {
85 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' );
86 } elseif ( $this->field->required == '1' && empty( $value ) ) {
87 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'blank' );
88 }
89
90 return $errors;
91 }
92
93 protected function prepare_display_value( $value, $atts ) {
94 if ( $atts['html'] ) {
95 $images = '';
96 foreach ( (array) $value as $url ) {
97 $image_regex = '/(\.(?i)(jpg|jpeg|png|gif))$/';
98 $is_image = preg_match( $image_regex, $url );
99 if ( $is_image ) {
100 $images .= '<img src="' . esc_attr( $url ) . '" class="frm_image_from_url" alt="" /> ';
101 } else {
102 $images .= strip_tags( $url );
103 }
104 }
105 $value = $images;
106 }
107
108 return $value;
109 }
110
111 /**
112 * @since 4.0.04
113 *
114 * @return void
115 */
116 public function sanitize_value( &$value ) {
117 FrmAppHelper::sanitize_value( 'esc_url_raw', $value );
118 }
119 }
120