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

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