PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.5.4
JetFormBuilder — Dynamic Blocks Form Builder v3.5.4
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / validation / advanced-rules / server-side-rule.php
jetformbuilder / modules / validation / advanced-rules Last commit date
interfaces 2 years ago traits 2 years ago match-not-regexp-rule.php 2 years ago match-regexp-rule.php 2 years ago must-contain-characters-rule.php 2 years ago must-equal-rule.php 2 years ago must-not-contain-characters-rule.php 2 years ago rule.php 2 years ago server-side-rule.php 1 year ago
server-side-rule.php
111 lines
1 <?php
2
3
4 namespace JFB_Modules\Validation\Advanced_Rules;
5
6 use JFB_Modules\Validation\Ssr;
7 use Jet_Form_Builder\Exceptions\Repository_Exception;
8 use JFB_Components\Repository\Repository_Pattern_Trait;
9 use JFB_Modules\Block_Parsers\Field_Data_Parser;
10
11 // If this file is called directly, abort.
12 if ( ! defined( 'WPINC' ) ) {
13 die;
14 }
15
16 class Server_Side_Rule extends Rule {
17
18 use Repository_Pattern_Trait;
19
20 const NOT_ALLOWED = array(
21 'var_dump',
22 'var_export',
23 'print_r',
24 'sprintf',
25 'printf',
26 'shell_exec',
27 'system',
28 'exec',
29 'unserialize',
30 'file_get_contents',
31 'maybe_unserialize',
32 );
33
34 public function __construct() {
35 $this->rep_install();
36 }
37
38 public function rep_instances(): array {
39 return apply_filters(
40 'jet-form-builder/validation-callbacks',
41 array(
42 new Ssr\Is_User_Login_Unique(),
43 new Ssr\Is_User_Email_Unique(),
44 new Ssr\Is_Field_Value_Unique(),
45 new Ssr\Is_User_Password_Valid(),
46 )
47 );
48 }
49
50 public function get_id(): string {
51 return 'ssr';
52 }
53
54 public function get_label(): string {
55 return __( 'Server-Side callback', 'jet-form-builder' );
56 }
57
58 public function validate_field( Field_Data_Parser $parser ) {
59 $function_name = $this->get_setting( 'value' );
60 $is_valid = $this->validate( $parser, $function_name );
61
62 if ( $is_valid ) {
63 return;
64 }
65
66 $parser->collect_error( 'rule:ssr:' . $function_name, $this->get_setting( 'message' ) );
67 }
68
69 /**
70 * @return Ssr\Base_Validation_Callback[]
71 */
72 public function get_callbacks(): array {
73 return $this->rep_get_items();
74 }
75
76 protected function validate( Field_Data_Parser $parser, string $function_name ): bool {
77 try {
78 /** @var Ssr\Base_Validation_Callback $callback */
79 $callback = $this->rep_get_item( $function_name );
80 } catch ( Repository_Exception $exception ) {
81 return $this->validate_custom( $parser, $function_name );
82 }
83
84 return $callback->is_valid( $parser->get_value(), $parser->get_context() );
85 }
86
87 protected function validate_custom( Field_Data_Parser $parser, string $function_name ): bool {
88 $name = $this->validate_callback( $function_name );
89
90 if ( ! $name ) {
91 return false;
92 }
93
94 return (bool) call_user_func( $name, $parser->get_value(), $parser->get_context() );
95 }
96
97 protected function validate_callback( string $function_name ): string {
98 $name = preg_replace( '/[^\w]/i', '', $function_name );
99
100 if ( $name !== $function_name ||
101 // not in the blacklist
102 in_array( $name, self::NOT_ALLOWED, true )
103 ) {
104 return '';
105 }
106
107 return function_exists( $name ) ? $name : '';
108 }
109
110 }
111