PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.5.3
JetFormBuilder — Dynamic Blocks Form Builder v1.5.3
3.6.4.1 3.6.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 / live-form.php
jetformbuilder / includes Last commit date
actions 4 years ago addons 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 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-break.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
live-form.php
216 lines
1 <?php
2
3 namespace Jet_Form_Builder;
4
5 use Jet_Form_Builder\Blocks\Types\Base as Block_Type_Base;
6 use Jet_Form_Builder\Classes\Attributes_Trait;
7 use Jet_Form_Builder\Classes\Get_Template_Trait;
8 use Jet_Form_Builder\Classes\Instance_Trait;
9
10 // If this file is called directly, abort.
11 if ( ! defined( 'WPINC' ) ) {
12 die;
13 }
14
15
16 /**
17 * @method static Live_Form instance()
18 *
19 * Class Live_Form
20 * @package Jet_Form_Builder
21 */
22 class Live_Form {
23
24 use Attributes_Trait;
25 use Get_Template_Trait;
26 use Instance_Trait;
27
28 public $form_id = false;
29 public $spec_data;
30 public $post;
31 public $_conditional_blocks = array();
32 public $_repeaters = array();
33 public $blocks = array();
34
35 // for progress
36 public $form_break;
37
38 /**
39 * Create form instance
40 *
41 * @param [type] $form_id [description]
42 */
43 private function __construct() {
44 $this->post = $this->current_post();
45 }
46
47 public function set_form_id( $form_id ) {
48 $this->form_id = $form_id;
49
50 return $this;
51 }
52
53 /**
54 * It turns out the inheritance of such an image
55 * Incoming Form Attributes (from block/widget/shortcode)
56 * (if not) -> Individual Form Arguments
57 * (if not) -> Default PHP Values
58 *
59 * @param array $incoming_attributes
60 *
61 * @return $this
62 */
63 public function set_specific_data_for_render( $incoming_attributes = array() ) {
64 $jf_default_args = Plugin::instance()->post_type->get_default_args();
65 $jf_args = Plugin::instance()->post_type->get_args( $this->form_id );
66
67 $attributes_from_post_type = array_diff( $jf_args, $jf_default_args );
68 $form_block_or_widget = array_diff( $incoming_attributes, $jf_default_args );
69
70 $render_attributes = array_merge(
71 ...apply_filters(
72 'jet-form-builder/form-render/attributes',
73 array(
74 Plugin::instance()->post_type->get_default_args_on_render(),
75 $attributes_from_post_type,
76 $form_block_or_widget,
77 )
78 )
79 );
80
81 $this->spec_data = (object) $render_attributes;
82
83 return $this;
84 }
85
86 public function get_spec( $property, $default = '' ) {
87 return ( $this->spec_data->{$property} ?? $default ) ?: $default;
88 }
89
90 public function is_not_field( $block ) {
91 return Plugin::instance()->form->is_not_field( $block['blockName'] );
92 }
93
94 public function is_field( $block, $needle ) {
95 return Plugin::instance()->form->is_field( $block['blockName'], $needle );
96 }
97
98 public function get_fields( $content ) {
99 return Plugin::instance()->form->get_fields( $content );
100 }
101
102 /**
103 * Setup fields prop
104 *
105 * @param $content
106 *
107 * @return array[]
108 */
109 public function setup_fields( $content ) {
110 $blocks = parse_blocks( $content );
111 $this->blocks = $this->get_form_break()->set_pages( $blocks );
112
113 return $this->blocks;
114 }
115
116 public function maybe_progress_pages() {
117 if ( ! $this->spec_data->enable_progress || 0 === $this->get_form_break()->get_pages() ) {
118 return '';
119 }
120
121 return $this->get_form_break()->render_progress(
122 'default',
123 array(
124 'jet-form-builder-progress-pages--global',
125 )
126 );
127 }
128
129
130 public static function force_render_field( $name, $arguments = array() ) {
131 if ( empty( $name ) ) {
132 return '';
133 }
134 $field = jet_form_builder()->blocks->get_field_by_name( $name );
135
136 if ( ! $field instanceof Block_Type_Base ) {
137 return '';
138 }
139
140 $field->set_block_data( $arguments, null );
141
142 return $field->get_block_renderer();
143 }
144
145
146 /**
147 * Maybe start new page
148 *
149 * @param bool $force_first
150 *
151 * @return false|string|void
152 */
153 public function maybe_start_page( $force_first = false ) {
154 return $this->get_form_break()->maybe_start_page( $force_first );
155 }
156
157 /**
158 * Maybe start new page
159 *
160 * @param $is_last
161 * @param $field
162 *
163 * @return false|string|void [type] [description]
164 */
165 public function maybe_end_page( $is_last = false, $field = false ) {
166 return $this->get_form_break()->maybe_end_page( $is_last, $field );
167 }
168
169 public function get_nonce_id() {
170 return "jet-form-builder-wp-nonce-{$this->form_id}";
171 }
172
173 /**
174 * @param string $name
175 *
176 * @return Form_Break
177 */
178 public function get_form_break( $name = '' ) {
179 if ( ! $name && ! $this->form_break ) {
180 $this->form_break = new Form_Break();
181 }
182 if ( $name && ! $this->isset_form_break( $name ) ) {
183 $this->_conditional_blocks[ $name ] = array( 'break' => new Form_Break() );
184 }
185
186 return $name ? $this->_conditional_blocks[ $name ]['break'] : $this->form_break;
187 }
188
189 public function isset_form_break( $name ) {
190 return isset( $this->_conditional_blocks[ $name ] );
191 }
192
193 public function get_repeater( $name ) {
194 return $this->_repeaters[ $name ] ?? array();
195 }
196
197 public function set_repeater( $name, $attrs ) {
198 $this->_repeaters[ $name ] = array_merge( $this->get_repeater( $name ), $attrs );
199 }
200
201 private function current_post() {
202 global $post;
203
204 if ( wp_doing_ajax() && empty( $post->ID ) ) {
205 $url = wp_get_referer();
206 $post_id = url_to_postid( $url );
207
208 return get_post( $post_id );
209 } else {
210 return $post;
211 }
212 }
213
214
215 }
216