PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5.4
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5.4
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.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 All 134 releases
jetformbuilder / includes / classes / regexp-tools.php

regexp-tools.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.5.4, at includes/classes/regexp-tools.php

78 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace Jet_Form_Builder\Classes;
5
6 // If this file is called directly, abort.
7 if ( ! defined( 'WPINC' ) ) {
8 die;
9 }
10
11 class Regexp_Tools {
12
13 private $field_names_regexp = array();
14 private $macro_exist = false;
15
16 public function has_macro( $value ): bool {
17 if ( ! is_scalar( $value ) || ! is_string( $value ) ) {
18 return false;
19 }
20
21 if ( preg_match( '/%[\w\-]+::.*?%/', $value ) ) {
22 return true;
23 }
24
25 $this->macro_exist = false;
26
27 preg_replace_callback_array(
28 $this->field_names_regexp,
29 $value
30 );
31
32 return $this->macro_exist;
33 }
34
35 public function set_field_names( array $names ) {
36 foreach ( $names as $name => $counter ) {
37 $this->field_names_regexp[ "/%({$name}).*?%/" ] = array( $this, 'regexp_replace_callback' );
38 }
39 }
40
41 /**
42 * @param array $matches
43 *
44 * @return mixed
45 */
46 private function regexp_replace_callback( array $matches ) {
47 $this->macro_exist = true;
48
49 return $matches[0];
50 }
51
52 /**
53 * @param string $content
54 *
55 * @return array
56 */
57 public function get_form_ids_from_shortcode( string $content ): array {
58 $matches = array();
59
60 preg_match_all( '/\[jet_fb_form.*?form_id="(\d+)"/', $content, $matches );
61
62 return $matches[1] ?? array();
63 }
64
65 public function get_form_ids_from_block( string $content ): array {
66 $matches = array();
67
68 preg_match_all(
69 '/<!-- wp:jet\-forms\/form\-block.*?"form_id":(\d+)/',
70 $content,
71 $matches
72 );
73
74 return $matches[1] ?? array();
75 }
76
77 }
78