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