PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.1
JetFormBuilder — Dynamic Blocks Form Builder v2.1.1
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 condition-helper.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 listing-filter-manager.php 3 years ago listing-filter.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
119 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 '/%(.*?)(\|([a-zA-Z0-9\(\)\.\,\:\/\s_-]+))?%/',
52 function ( $match ) {
53
54 if ( isset( $this->replacements[ $match[1] ] ) ) {
55
56 if ( ! empty( $match[3] ) ) {
57 return Filters_Manager::instance()->apply(
58 $this->replacements[ $match[1] ],
59 $match[3]
60 );
61 } else {
62 if ( is_array( $this->replacements[ $match[1] ] ) ) {
63 if ( jet_fb_request_handler()->is_type( $match[1], 'repeater-field' ) ) {
64 return $this->verbose_repeater( $this->replacements[ $match[1] ] );
65 } else {
66 return implode( ', ', $this->replacements[ $match[1] ] );
67 }
68 } else {
69 return $this->replacements[ $match[1] ];
70 }
71 }
72 } else {
73 return $match[0];
74 }
75 },
76 $this->content
77 );
78
79 }
80
81 /**
82 * Verbose repeater items array
83 *
84 * @param array $items
85 *
86 * @return string
87 */
88 public function verbose_repeater( $items = array() ) {
89
90 $result = apply_filters( 'jet-form-builder/send-email/template-repeater', '', $items, $this );
91 $index = 1;
92
93 if ( $result ) {
94 return $result;
95 }
96
97 foreach ( $items as $item ) {
98 $item_data = array();
99
100 foreach ( $item as $key => $value ) {
101 $item_data[] = sprintf( '%1$s: %2$s', $key, $this->maybe_parse_if_array( $value ) );
102 }
103 $result .= $index ++ . ') ' . implode( ', ', $item_data ) . ';<br>';
104 }
105
106 return $result;
107
108 }
109
110 private function maybe_parse_if_array( $value ) {
111 if ( is_array( $value ) ) {
112 return implode( ', ', $value );
113 }
114
115 return $value;
116 }
117
118 }
119