PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.3
JetFormBuilder — Dynamic Blocks Form Builder v3.0.3
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 / includes / classes / macros-parser.php
jetformbuilder / includes / classes Last commit date
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
macros-parser.php
140 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Classes;
5
6 use Jet_Form_Builder\Classes\Filters\Filters_Manager;
7 use Jet_Form_Builder\Classes\Macro_Constants\Constants_Manager;
8
9 class Macros_Parser {
10
11 private $content = '';
12 private $replacements = array();
13
14 public function set_content( $content ): Macros_Parser {
15 if ( is_array( $content ) ) {
16 $content = $content[0] ?? '';
17 }
18
19 if ( ! $content || ! is_string( $content ) ) {
20 return $this;
21 }
22 $this->content = $content;
23
24 return $this;
25 }
26
27 public function set_replacements( $replacements ): Macros_Parser {
28 if ( ! $replacements ) {
29 return $this;
30 }
31 $this->replacements = $replacements;
32
33 return $this;
34 }
35
36 public function parse_macros( $content = false, $replacements = false ): string {
37 $this->set_content( $content )->set_replacements( $replacements );
38
39 if ( ! $this->content || ! $this->replacements ) {
40 return $this->content ?: '';
41 }
42
43 return $this->macros_replace();
44 }
45
46 /**
47 * Parse macros in content
48 *
49 * @return string
50 */
51 public function macros_replace(): string {
52 Constants_Manager::instance();
53
54 $content = preg_replace_callback(
55 '/%(.+?)%/',
56 function ( $match ) {
57 $filters = explode( '|', $match[1] );
58 $name = $filters[0];
59 array_shift( $filters );
60
61 if ( false !== strpos( $name, '::' ) ) {
62 $value = apply_filters(
63 'jet-form-builder/custom-macro',
64 null,
65 $name,
66 $this
67 );
68
69 if ( is_null( $value ) ) {
70 return $match[0];
71 }
72
73 return Filters_Manager::instance()->apply( $value, $filters );
74 }
75
76 if ( ! isset( $this->replacements[ $name ] ) ) {
77 return $match[0];
78 }
79
80 $value = $this->replacements[ $name ];
81
82 if ( ! empty( $filters ) ) {
83 return Filters_Manager::instance()->apply( $value, $filters );
84 }
85
86 if ( ! is_array( $value ) ) {
87 return $value;
88 }
89
90 if ( jet_fb_request_handler()->is_type( $name, 'repeater-field' ) ) {
91 return $this->verbose_repeater( $value );
92 } else {
93 return implode( ', ', $value );
94 }
95 },
96 $this->content
97 );
98
99 return is_string( $content ) ? $content : '';
100 }
101
102 /**
103 * Verbose repeater items array
104 *
105 * @param array $items
106 *
107 * @return string
108 */
109 public function verbose_repeater( $items = array() ) {
110
111 $result = apply_filters( 'jet-form-builder/send-email/template-repeater', '', $items, $this );
112 $index = 1;
113
114 if ( $result ) {
115 return $result;
116 }
117
118 foreach ( $items as $item ) {
119 $item_data = array();
120
121 foreach ( $item as $key => $value ) {
122 $item_data[] = sprintf( '%1$s: %2$s', $key, $this->maybe_parse_if_array( $value ) );
123 }
124 $result .= $index ++ . ') ' . implode( ', ', $item_data ) . ';<br>';
125 }
126
127 return $result;
128
129 }
130
131 private function maybe_parse_if_array( $value ) {
132 if ( is_array( $value ) ) {
133 return implode( ', ', $value );
134 }
135
136 return $value;
137 }
138
139 }
140