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