arguments
3 years ago
arrayable
3 years ago
filters
3 years ago
http
3 years ago
macro-constants
3 years ago
post
3 years ago
repository
3 years ago
resources
3 years ago
security
3 years ago
theme
3 years ago
attributes-trait.php
3 years ago
base-attributes-trait.php
3 years ago
builder-helper.php
3 years ago
compatibility.php
3 years ago
date-tools.php
3 years ago
gallery.php
3 years ago
get-icon-trait.php
3 years ago
get-template-trait.php
3 years ago
html-attributes-trait.php
3 years ago
instance-trait.php
3 years ago
macros-parser.php
3 years ago
regexp-tools.php
3 years ago
tools.php
3 years ago
regexp-tools.php
73 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Classes; |
| 5 | |
| 6 | class Regexp_Tools { |
| 7 | |
| 8 | private $field_names_regexp = array(); |
| 9 | private $macro_exist = false; |
| 10 | |
| 11 | public function has_macro( $value ): bool { |
| 12 | if ( ! is_scalar( $value ) || ! is_string( $value ) ) { |
| 13 | return false; |
| 14 | } |
| 15 | |
| 16 | if ( preg_match( '/%[\w\-]+::.*?%/', $value ) ) { |
| 17 | return true; |
| 18 | } |
| 19 | |
| 20 | $this->macro_exist = false; |
| 21 | |
| 22 | preg_replace_callback_array( |
| 23 | $this->field_names_regexp, |
| 24 | $value |
| 25 | ); |
| 26 | |
| 27 | return $this->macro_exist; |
| 28 | } |
| 29 | |
| 30 | public function set_field_names( array $names ) { |
| 31 | foreach ( $names as $name => $counter ) { |
| 32 | $this->field_names_regexp[ "/%({$name}).*?%/" ] = array( $this, 'regexp_replace_callback' ); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @param array $matches |
| 38 | * |
| 39 | * @return mixed |
| 40 | */ |
| 41 | private function regexp_replace_callback( array $matches ) { |
| 42 | $this->macro_exist = true; |
| 43 | |
| 44 | return $matches[0]; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @param string $content |
| 49 | * |
| 50 | * @return array |
| 51 | */ |
| 52 | public function get_form_ids_from_shortcode( string $content ): array { |
| 53 | $matches = array(); |
| 54 | |
| 55 | preg_match_all( '/\[jet_fb_form.*?form_id="(\d+)"/', $content, $matches ); |
| 56 | |
| 57 | return $matches[1] ?? array(); |
| 58 | } |
| 59 | |
| 60 | public function get_form_ids_from_block( string $content ): array { |
| 61 | $matches = array(); |
| 62 | |
| 63 | preg_match_all( |
| 64 | '/<!-- wp:jet\-forms\/form\-block.*?"form_id":(\d+)/', |
| 65 | $content, |
| 66 | $matches |
| 67 | ); |
| 68 | |
| 69 | return $matches[1] ?? array(); |
| 70 | } |
| 71 | |
| 72 | } |
| 73 |