PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.2.5
JetFormBuilder — Dynamic Blocks Form Builder v1.2.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 / form-manager.php
jetformbuilder / includes Last commit date
actions 4 years ago admin 4 years ago blocks 4 years ago classes 4 years ago compatibility 4 years ago dev-mode 4 years ago exceptions 4 years ago form-actions 4 years ago form-messages 4 years ago form-patterns 4 years ago form-response 4 years ago gateways 4 years ago generators 4 years ago integrations 4 years ago license 4 years ago presets 4 years ago request 4 years ago shortcodes 4 years ago widgets 4 years ago autoloader.php 4 years ago file-upload.php 4 years ago form-handler.php 4 years ago form-manager.php 4 years ago live-form.php 4 years ago plugin.php 4 years ago post-type.php 4 years ago
form-manager.php
188 lines
1 <?php
2
3
4 namespace Jet_Form_Builder;
5
6 use Jet_Form_Builder\Gateways\Gateway_Manager;
7 use Jet_Form_Builder\Generators\Get_From_DB;
8 use Jet_Form_Builder\Generators\Get_From_Field;
9 use Jet_Form_Builder\Generators\Num_Range;
10 use Jet_Form_Builder\Generators\Num_Range_Manual;
11 use Jet_Form_Builder\Shortcodes\Manager;
12
13
14 // If this file is called directly, abort.
15 if ( ! defined( 'WPINC' ) ) {
16 die();
17 }
18
19 class Form_Manager {
20 public $generators = false;
21 public $builder;
22 private $result_fields = array();
23
24 const NAMESPACE_FIELDS = 'jet-forms/';
25
26 public function __construct() {
27 if ( Plugin::instance()->allow_gateways ) {
28 Gateway_Manager::instance();
29 }
30
31 Manager::instance();
32 }
33
34 /**
35 * Returns all instances of options generators classes
36 *
37 * @return [type] [description]
38 */
39 public function get_options_generators() {
40
41 if ( false === $this->generators ) {
42
43 $instances = array(
44 new Num_Range(),
45 //new Num_Range_Manual(),
46 new Get_From_DB(),
47 new Get_From_Field(),
48 );
49
50 $instances = apply_filters( 'jet-form-builder/forms/options-generators', $instances, $this );
51
52 foreach ( $instances as $instance ) {
53 if ( $instance->can_generate() ) {
54 $this->generators[ $instance->get_id() ] = $instance;
55 }
56 }
57
58 }
59
60 return $this->generators;
61 }
62
63 /**
64 * Returns form fields,
65 * parsed from post_content
66 *
67 * @param $content
68 *
69 * @return array[]
70 */
71 public function get_fields( $content ) {
72 return parse_blocks( $content );
73 }
74
75 public function is_not_field( $block_name ) {
76 return (
77 stripos(
78 $block_name,
79 self::NAMESPACE_FIELDS
80 ) === false
81 );
82 }
83
84 public function is_field( $block_name, $needle ) {
85 return stristr( $block_name, $needle );
86 }
87
88 public function get_form_blocks( $form_id ) {
89 return $this->get_fields( get_post( $form_id )->post_content );
90 }
91
92 public function prepare_fields_names( $block_name ) {
93 return "jet-forms/$block_name";
94 }
95
96 public function get_only_form_fields( $form_id, $exclude = array(), $recursive = true ) {
97 $content = $this->get_form_blocks( $form_id );
98
99 return $this->only_form_fields( $content, $exclude, $recursive );
100 }
101
102 public function only_form_fields( $content, $exclude = array(), $recursive = true ) {
103 $exclude = array_map( array( $this, 'prepare_fields_names' ), $exclude );
104
105 $this->result_fields = array();
106 $this->get_inner_fields( $content, $exclude, $recursive );
107
108 $response = $this->result_fields;
109 $this->result_fields = array();
110
111 return $response;
112 }
113
114
115 private function get_inner_fields( $source, $exclude, $recursive = true ) {
116 foreach ( $source as $block ) {
117
118 if ( ! $this->is_not_field( $block['blockName'] ) && ! in_array( $block['blockName'], $exclude ) ) {
119 $this->result_fields[] = $block;
120 }
121
122 if ( $recursive && ! empty( $block['innerBlocks'] ) ) {
123 $this->get_inner_fields( $block['innerBlocks'], $exclude, true );
124 }
125 }
126 }
127
128
129 /**
130 * Returns generators list
131 *
132 * @return [type] [description]
133 */
134 public function get_generators_list() {
135
136 $generators = $this->get_options_generators();
137 $result = array(
138 0 => __( 'Select function...', 'jet-form-builder' ),
139 );
140
141 foreach ( $generators as $id => $generator ) {
142 $result[ $id ] = $generator->get_name();
143 }
144
145 return $result;
146
147 }
148
149 public function field_name( $blockName ) {
150 return explode( self::NAMESPACE_FIELDS, $blockName )[1];
151 }
152
153 public function get_form_content( $form_id ) {
154 return get_post( $form_id )->post_content;
155 }
156
157 public function get_field_by_name( $form_id, $field_name, $blocks = array() ) {
158 if ( ! $blocks ) {
159 $blocks = $this->get_only_form_fields( $form_id );
160 }
161
162 return $this->_get_field_by_name( $field_name, $blocks );
163 }
164
165 private function _get_field_by_name( $field_name, $blocks ) {
166 foreach ( $blocks as $block ) {
167 $name = isset( $block['attrs']['name'] ) && $block['attrs']['name']
168 ? $block['attrs']['name']
169 : '';
170
171 if ( ! $name ) {
172 continue;
173 }
174
175 if ( $name === $field_name ) {
176 return $block;
177 }
178
179 if ( 0 < count( $block['innerBlocks'] ) ) {
180 return $this->_get_field_by_name( $field_name, $block['innerBlocks'] );
181 }
182 }
183
184 return array();
185 }
186
187
188 }