PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.6
JetFormBuilder — Dynamic Blocks Form Builder v2.1.6
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 / admin / editor.php
jetformbuilder / includes / admin Last commit date
buttons 3 years ago exceptions 3 years ago notices 3 years ago pages 3 years ago single-pages 3 years ago table-views 3 years ago tabs-handlers 3 years ago vui-boxes 3 years ago admin-page-interface.php 3 years ago admin-page-trait.php 3 years ago editor.php 3 years ago table-advanced-record-prepare-trait.php 3 years ago table-record-prepare-trait.php 3 years ago
editor.php
454 lines
1 <?php
2
3 namespace Jet_Form_Builder\Admin;
4
5 use Jet_Form_Builder\Actions\Conditions\Condition_Manager as Action_Condition_Manager;
6 use Jet_Form_Builder\Admin\Tabs_Handlers\Tab_Handler_Manager;
7 use Jet_Form_Builder\Classes\Arguments\Form_Arguments;
8 use Jet_Form_Builder\Classes\Http\Utm_Url;
9 use Jet_Form_Builder\Classes\Tools;
10 use Jet_Form_Builder\Gateways\Gateway_Manager;
11 use Jet_Form_Builder\Plugin;
12 use Jet_Form_Builder\Blocks\Conditional_Block\Condition_Manager as Block_Condition_Manager;
13
14 /**
15 * Form editor class
16 * Thanks Tom J Nowell for initial editor idea and inspiration!
17 */
18
19 // If this file is called directly, abort.
20 if ( ! defined( 'WPINC' ) ) {
21 die;
22 }
23
24 /**
25 * Define Editor class
26 */
27 class Editor {
28
29 const EDITOR_HANDLE = 'jet-form-builder-editor';
30 const EDITOR_PACKAGE_HANDLE = 'jet-form-builder-editor-package';
31
32 public function __construct() {
33 add_action( 'enqueue_block_editor_assets', array( $this, 'admin_assets' ) );
34 }
35
36 /**
37 * Register admin assets
38 *
39 * @return void [type] [description]
40 */
41 public function admin_assets() {
42 if ( jet_form_builder()->post_type->is_form_editor ) {
43 $this->enqueue_assets();
44 } else {
45 $this->enqueue_form_assets();
46 }
47 }
48
49 /**
50 * Returns taxonomies list for the config
51 *
52 * @return [type] [description]
53 */
54 public function get_taxonomies_list() {
55
56 $taxonomies = get_taxonomies( array(), 'objects' );
57
58 $result = array();
59
60 foreach ( $taxonomies as $tax ) {
61 $result[] = array(
62 'value' => $tax->name,
63 'label' => sprintf( '%1$s (%2$s)', $tax->label, $tax->name ),
64 );
65 }
66
67 return $result;
68
69 }
70
71 public function get_preset_config() {
72 return apply_filters(
73 'jet-form-builder/editor/preset-config',
74 array(
75 'global_fields' => array(
76 array(
77 'name' => 'from',
78 'label' => __( 'Source:', 'jet-form-builder' ),
79 'type' => 'select',
80 'options' => Tools::with_placeholder(
81 array(
82 array(
83 'value' => 'post',
84 'label' => __( 'Post', 'jet-form-builder' ),
85 ),
86 array(
87 'value' => 'user',
88 'label' => __( 'User', 'jet-form-builder' ),
89 ),
90 array(
91 'value' => 'query_var',
92 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
93 ),
94 )
95 ),
96 ),
97 array(
98 'name' => 'post_from',
99 'label' => __( 'Get post ID from:', 'jet-form-builder' ),
100 'type' => 'select',
101 'options' => Tools::with_placeholder(
102 array(
103 array(
104 'value' => 'current_post',
105 'label' => __( 'Current post', 'jet-form-builder' ),
106 ),
107 array(
108 'value' => 'query_var',
109 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
110 ),
111 )
112 ),
113 'condition' => array(
114 'field' => 'from',
115 'value' => 'post',
116 ),
117 ),
118 array(
119 'name' => 'user_from',
120 'label' => __( 'Get user ID from:', 'jet-form-builder' ),
121 'type' => 'select',
122 'options' => Tools::with_placeholder(
123 array(
124 array(
125 'value' => 'current_user',
126 'label' => __( 'Current user', 'jet-form-builder' ),
127 ),
128 array(
129 'value' => 'queried_user',
130 'label' => __( 'Queried user', 'jet-form-builder' ),
131 ),
132 array(
133 'value' => 'query_var',
134 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
135 ),
136 )
137 ),
138 'condition' => array(
139 'field' => 'from',
140 'value' => 'user',
141 ),
142 ),
143 array(
144 'name' => 'query_var',
145 'label' => __( 'Query variable name:', 'jet-form-builder' ),
146 'type' => 'text',
147 'custom_condition' => 'query_var',
148 'position' => 'dynamic',
149 ),
150 ),
151 'map_fields' => array(
152 array(
153 'name' => 'key',
154 'label' => __( 'Query variable key', 'jet-form-builder' ),
155 'type' => 'text',
156 'position' => 'general',
157 'parent_condition' => array(
158 'field' => 'from',
159 'value' => 'query_var',
160 ),
161 ),
162 array(
163 'name' => 'prop',
164 'label' => __( 'Post property', 'jet-form-builder' ),
165 'type' => 'select',
166 'options' => Tools::with_placeholder(
167 array(
168 array(
169 'value' => 'ID',
170 'label' => __( 'Post ID', 'jet-form-builder' ),
171 ),
172 array(
173 'value' => 'post_title',
174 'label' => __( 'Post Title', 'jet-form-builder' ),
175 ),
176 array(
177 'value' => 'post_content',
178 'label' => __( 'Post Content', 'jet-form-builder' ),
179 ),
180 array(
181 'value' => 'post_status',
182 'label' => __( 'Post Status', 'jet-form-builder' ),
183 ),
184 array(
185 'value' => 'post_author',
186 'label' => __( 'Post Author', 'jet-form-builder' ),
187 ),
188 array(
189 'value' => 'post_excerpt',
190 'label' => __( 'Post Excerpt', 'jet-form-builder' ),
191 ),
192 array(
193 'value' => 'post_date',
194 'label' => __( 'Post Date', 'jet-form-builder' ),
195 ),
196 array(
197 'value' => 'post_date_gmt',
198 'label' => __( 'Post Date GMT', 'jet-form-builder' ),
199 ),
200 array(
201 'value' => 'post_thumb',
202 'label' => __( 'Post Thumbnail', 'jet-form-builder' ),
203 ),
204 array(
205 'value' => 'post_meta',
206 'label' => __( 'Post Meta', 'jet-form-builder' ),
207 ),
208 array(
209 'value' => 'post_terms',
210 'label' => __( 'Post Terms', 'jet-form-builder' ),
211 ),
212 )
213 ),
214 'parent_condition' => array(
215 'field' => 'from',
216 'value' => 'post',
217 ),
218 ),
219 array(
220 'name' => 'key',
221 'label' => __( 'Taxonomy', 'jet-form-builder' ),
222 'type' => 'select',
223 'options' => Tools::with_placeholder( $this->get_taxonomies_list() ),
224 'parent_condition' => array(
225 'field' => 'from',
226 'value' => 'post',
227 ),
228 'condition' => array(
229 'field' => 'prop',
230 'value' => 'post_terms',
231 ),
232 ),
233 array(
234 'name' => 'key',
235 'label' => __( 'Meta field key', 'jet-form-builder' ),
236 'type' => 'text',
237 'parent_condition' => array(
238 'field' => 'from',
239 'value' => 'post',
240 ),
241 'condition' => array(
242 'field' => 'prop',
243 'value' => 'post_meta',
244 ),
245 ),
246 array(
247 'name' => 'prop',
248 'label' => __( 'User field', 'jet-form-builder' ),
249 'type' => 'select',
250 'options' => Tools::with_placeholder(
251 array(
252 array(
253 'value' => 'ID',
254 'label' => __( 'User ID', 'jet-form-builder' ),
255 ),
256 array(
257 'value' => 'user_login',
258 'label' => __( 'User Login', 'jet-form-builder' ),
259 ),
260 array(
261 'value' => 'user_email',
262 'label' => __( 'Email', 'jet-form-builder' ),
263 ),
264 array(
265 'value' => 'password',
266 'label' => __( 'Password', 'jet-form-builder' ),
267 ),
268 array(
269 'value' => 'first_name',
270 'label' => __( 'First Name', 'jet-form-builder' ),
271 ),
272 array(
273 'value' => 'last_name',
274 'label' => __( 'Last Name', 'jet-form-builder' ),
275 ),
276 array(
277 'value' => 'user_url',
278 'label' => __( 'User URL', 'jet-form-builder' ),
279 ),
280 array(
281 'value' => 'user_meta',
282 'label' => __( 'User Meta', 'jet-form-builder' ),
283 ),
284 )
285 ),
286 'parent_condition' => array(
287 'field' => 'from',
288 'value' => 'user',
289 ),
290 ),
291 array(
292 'name' => 'key',
293 'label' => __( 'Meta field key', 'jet-form-builder' ),
294 'type' => 'text',
295 'parent_condition' => array(
296 'field' => 'from',
297 'value' => 'user',
298 ),
299 'condition' => array(
300 'field' => 'prop',
301 'value' => 'user_meta',
302 ),
303 ),
304 ),
305 )
306 );
307 }
308
309 /**
310 * Enqueue editor assets
311 *
312 * @return void
313 */
314 public function enqueue_assets() {
315 do_action( 'jet-form-builder/editor-package/before', $this, self::EDITOR_PACKAGE_HANDLE );
316
317 wp_enqueue_script(
318 self::EDITOR_PACKAGE_HANDLE,
319 JET_FORM_BUILDER_URL . 'assets/js/package.js',
320 array(
321 'wp-editor',
322 'wp-core-data',
323 'wp-data',
324 'wp-block-library',
325 'wp-format-library',
326 'wp-api-fetch',
327 ),
328 JET_FORM_BUILDER_VERSION,
329 true
330 );
331
332 wp_localize_script(
333 self::EDITOR_PACKAGE_HANDLE,
334 'jetFormEvents',
335 jet_fb_events()->to_array()
336 );
337
338 wp_localize_script(
339 self::EDITOR_PACKAGE_HANDLE,
340 'jetFormBlockConditions',
341 Block_Condition_Manager::instance()->to_array()
342 );
343
344 wp_set_script_translations(
345 self::EDITOR_PACKAGE_HANDLE,
346 'jet-form-builder',
347 Plugin::instance()->plugin_dir( 'languages' )
348 );
349
350 do_action( 'jet-form-builder/editor-assets/before', $this, self::EDITOR_HANDLE );
351
352 wp_enqueue_script(
353 self::EDITOR_HANDLE,
354 JET_FORM_BUILDER_URL . 'assets/js/editor.js',
355 array(),
356 JET_FORM_BUILDER_VERSION,
357 true
358 );
359
360 wp_enqueue_style(
361 self::EDITOR_HANDLE,
362 JET_FORM_BUILDER_URL . 'assets/css/editor.css',
363 array(
364 'media',
365 'l10n',
366 'buttons',
367 'wp-edit-blocks',
368 'wp-editor',
369 ),
370 JET_FORM_BUILDER_VERSION,
371 'all'
372 );
373
374 $conditions_settings = ( new Action_Condition_Manager() )->get_settings();
375
376 $utm = new Utm_Url( 'wp-admin/editor-jet-form' );
377 $addons = JET_FORM_BUILDER_SITE . '/addons/';
378 $pricing = JET_FORM_BUILDER_SITE . '/pricing/';
379
380 wp_localize_script(
381 self::EDITOR_PACKAGE_HANDLE,
382 'JetFormEditorData',
383 array(
384 'presetConfig' => $this->get_preset_config(),
385 'messagesDefault' => Plugin::instance()->post_type->get_messages_default(),
386 'gateways' => Gateway_Manager::instance()->editor_data(),
387 'helpForRepeaters' => $this->get_help_for_repeaters(),
388 'global_settings' => Tab_Handler_Manager::instance()->all(),
389 'jetEngineVersion' => Tools::get_jet_engine_version(),
390 'actionConditionSettings' => $conditions_settings,
391 'argumentsSource' => Form_Arguments::get_options(),
392 'utmLinks' => array(
393 'allProActions' => $utm->set_campaign( 'pro-actions' )->add_query( $addons ),
394 'limitResponses' => $utm->set_campaign( 'responses-pricing' )->add_query( $pricing ),
395 'scheduleForm' => $utm->set_campaign( 'schedule-pricing' )->add_query( $pricing ),
396 ),
397 'isActivePro' => jet_form_builder()->addons_manager->is_active(),
398 )
399 );
400
401 do_action( 'jet-form-builder/editor-assets/after', $this, self::EDITOR_HANDLE );
402 }
403
404 private function get_help_for_repeaters() {
405 return array(
406 'conditional_block' => array(
407 'label' => __( 'With many conditions for the block, they are checked with the AND operator', 'jet-form-builder' ),
408 ),
409 'conditional_block_or' => array(
410 'label' => __( 'With many conditions for the block, they are checked with the OR operator', 'jet-form-builder' ),
411 ),
412 'conditional_action' => array(
413 'label' => __( 'With many conditions for the action, they are checked with the AND operator', 'jet-form-builder' ),
414 ),
415 'conditional_action_or' => array(
416 'label' => __( 'With many conditions for the action, they are checked with the OR operator', 'jet-form-builder' ),
417 ),
418 );
419 }
420
421 public function enqueue_form_assets() {
422
423 $handle = 'jet-form-builder/form';
424
425 do_action( 'jet-form-builder/other-editor-assets/before', $this, $handle );
426
427 wp_register_script(
428 $handle,
429 JET_FORM_BUILDER_URL . 'assets/js/form-block.js',
430 array(
431 'wp-editor',
432 'wp-core-data',
433 'wp-data',
434 'wp-block-library',
435 'wp-format-library',
436 'wp-api-fetch',
437 ),
438 JET_FORM_BUILDER_VERSION,
439 true
440 );
441
442 wp_register_style(
443 'jet-form-builder-others',
444 Plugin::instance()->plugin_url( 'assets/css/frontend.css' ),
445 array(),
446 Plugin::instance()->get_version()
447 );
448
449 do_action( 'jet-form-builder/other-editor-assets/after', $this, $handle );
450
451 }
452
453 }
454