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