PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 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 All 134 releases
jetformbuilder / includes / admin / editor.php

editor.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.6, at includes/admin/editor.php

578 lines 16.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\Pages\Pages_Manager;
7 use Jet_Form_Builder\Admin\Tabs_Handlers\Tab_Handler_Manager;
8 use Jet_Form_Builder\Classes\Arguments\Form_Arguments;
9 use Jet_Form_Builder\Classes\Http\Utm_Url;
10 use Jet_Form_Builder\Classes\Tools;
11 use Jet_Form_Builder\Exceptions\Repository_Exception;
12 use Jet_Form_Builder\Plugin;
13 use Jet_Form_Builder\Blocks\Conditional_Block\Condition_Manager as Block_Condition_Manager;
14 use JFB_Modules\Post_Type\Module;
15
16 // If this file is called directly, abort.
17 if ( ! defined( 'WPINC' ) ) {
18 die;
19 }
20
21 /**
22 * Define Editor class
23 */
24 class Editor {
25
26 const EDITOR_HANDLE = 'jet-form-builder-editor';
27 const EDITOR_PACKAGE_HANDLE = 'jet-form-builder-editor-package';
28
29 public function __construct() {
30 add_action( 'enqueue_block_editor_assets', array( $this, 'admin_assets' ) );
31 }
32
33 /**
34 * Register admin assets
35 *
36 * @return void [type] [description]
37 */
38 public function admin_assets() {
39 if ( jet_form_builder()->post_type->is_form_editor ) {
40 $this->enqueue_assets();
41 } else {
42 $this->enqueue_form_assets();
43 }
44 }
45
46 /**
47 * Returns taxonomies list for the config
48 *
49 * @return [type] [description]
50 */
51 public function get_taxonomies_list() {
52
53 $taxonomies = get_taxonomies( array(), 'objects' );
54
55 $result = array();
56
57 foreach ( $taxonomies as $tax ) {
58 $result[] = array(
59 'value' => $tax->name,
60 'label' => sprintf( '%1$s (%2$s)', $tax->label, $tax->name ),
61 );
62 }
63
64 return $result;
65 }
66
67 public function get_preset_config() {
68 return apply_filters(
69 'jet-form-builder/editor/preset-config',
70 array(
71 'global_fields' => array(
72 array(
73 'name' => 'from',
74 'label' => __( 'Source:', 'jet-form-builder' ),
75 'type' => 'select',
76 'options' => Tools::with_placeholder(
77 array(
78 array(
79 'value' => 'post',
80 'label' => __( 'Post', 'jet-form-builder' ),
81 ),
82 array(
83 'value' => 'user',
84 'label' => __( 'User', 'jet-form-builder' ),
85 ),
86 array(
87 'value' => 'query_var',
88 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
89 ),
90 array(
91 'value' => 'term',
92 'label' => __( 'Term', 'jet-form-builder' ),
93 ),
94 array(
95 'value' => 'form_record',
96 'label' => __( 'JetFormBuilder Record', 'jet-form-builder' ),
97 ),
98 )
99 ),
100 ),
101 array(
102 'name' => 'record_query_var',
103 'label' => __( 'Record ID query variable:', 'jet-form-builder' ),
104 'type' => 'text',
105 'condition' => array(
106 'field' => 'from',
107 'value' => 'form_record',
108 ),
109 ),
110 array(
111 'name' => 'post_from',
112 'label' => __( 'Get post ID from:', 'jet-form-builder' ),
113 'type' => 'select',
114 'options' => Tools::with_placeholder(
115 array(
116 array(
117 'value' => 'current_post',
118 'label' => __( 'Current post', 'jet-form-builder' ),
119 ),
120 array(
121 'value' => 'query_var',
122 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
123 ),
124 )
125 ),
126 'condition' => array(
127 'field' => 'from',
128 'value' => 'post',
129 ),
130 ),
131 array(
132 'name' => 'user_from',
133 'label' => __( 'Get user ID from:', 'jet-form-builder' ),
134 'type' => 'select',
135 'options' => Tools::with_placeholder(
136 array(
137 array(
138 'value' => 'current_user',
139 'label' => __( 'Current user', 'jet-form-builder' ),
140 ),
141 array(
142 'value' => 'queried_user',
143 'label' => __( 'Queried user', 'jet-form-builder' ),
144 ),
145 array(
146 'value' => 'query_var',
147 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
148 ),
149 )
150 ),
151 'condition' => array(
152 'field' => 'from',
153 'value' => 'user',
154 ),
155 ),
156 array(
157 'name' => 'term_from',
158 'label' => __( 'Get term from:', 'jet-form-builder' ),
159 'type' => 'select',
160 'options' => Tools::with_placeholder(
161 array(
162 array(
163 'value' => 'current_term',
164 'label' => __( 'Current term', 'jet-form-builder' ),
165 ),
166 array(
167 'value' => 'query_var',
168 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
169 ),
170 )
171 ),
172 'condition' => array(
173 'field' => 'from',
174 'value' => 'term',
175 ),
176 ),
177 array(
178 'name' => 'term_taxonomy',
179 'label' => __( 'Term taxonomy', 'jet-form-builder' ),
180 'type' => 'select',
181 'options' => Tools::with_placeholder( $this->get_taxonomies_list() ),
182 'parent_condition' => array(
183 'field' => 'from',
184 'value' => 'term',
185 ),
186 'condition' => array(
187 'field' => 'term_from',
188 'value' => 'query_var',
189 ),
190 ),
191 array(
192 'name' => 'query_var',
193 'label' => __( 'Query variable name:', 'jet-form-builder' ),
194 'type' => 'text',
195 'custom_condition' => 'query_var',
196 'position' => 'dynamic',
197 ),
198 ),
199 'map_fields' => array(
200 array(
201 'name' => 'key',
202 'label' => __( 'Query variable key', 'jet-form-builder' ),
203 'type' => 'text',
204 'position' => 'general',
205 'parent_condition' => array(
206 'field' => 'from',
207 'value' => 'query_var',
208 ),
209 ),
210 array(
211 'name' => 'prop',
212 'label' => __( 'Post property', 'jet-form-builder' ),
213 'type' => 'select',
214 'options' => Tools::with_placeholder(
215 array(
216 array(
217 'value' => 'ID',
218 'label' => __( 'Post ID', 'jet-form-builder' ),
219 ),
220 array(
221 'value' => 'post_title',
222 'label' => __( 'Post Title', 'jet-form-builder' ),
223 ),
224 array(
225 'value' => 'post_content',
226 'label' => __( 'Post Content', 'jet-form-builder' ),
227 ),
228 array(
229 'value' => 'post_status',
230 'label' => __( 'Post Status', 'jet-form-builder' ),
231 ),
232 array(
233 'value' => 'post_author',
234 'label' => __( 'Post Author', 'jet-form-builder' ),
235 ),
236 array(
237 'value' => 'post_excerpt',
238 'label' => __( 'Post Excerpt', 'jet-form-builder' ),
239 ),
240 array(
241 'value' => 'post_date',
242 'label' => __( 'Post Date', 'jet-form-builder' ),
243 ),
244 array(
245 'value' => 'post_date_gmt',
246 'label' => __( 'Post Date GMT', 'jet-form-builder' ),
247 ),
248 array(
249 'value' => 'post_thumb',
250 'label' => __( 'Post Thumbnail', 'jet-form-builder' ),
251 ),
252 array(
253 'value' => 'post_meta',
254 'label' => __( 'Post Meta', 'jet-form-builder' ),
255 ),
256 array(
257 'value' => 'post_terms',
258 'label' => __( 'Post Terms', 'jet-form-builder' ),
259 ),
260 )
261 ),
262 'parent_condition' => array(
263 'field' => 'from',
264 'value' => 'post',
265 ),
266 ),
267 array(
268 'name' => 'key',
269 'label' => __( 'Taxonomy', 'jet-form-builder' ),
270 'type' => 'select',
271 'options' => Tools::with_placeholder( $this->get_taxonomies_list() ),
272 'parent_condition' => array(
273 'field' => 'from',
274 'value' => 'post',
275 ),
276 'condition' => array(
277 'field' => 'prop',
278 'value' => 'post_terms',
279 ),
280 ),
281 array(
282 'name' => 'key',
283 'label' => __( 'Meta field key', 'jet-form-builder' ),
284 'type' => 'text',
285 'parent_condition' => array(
286 'field' => 'from',
287 'value' => 'post',
288 ),
289 'condition' => array(
290 'field' => 'prop',
291 'value' => 'post_meta',
292 ),
293 ),
294 array(
295 'name' => 'prop',
296 'label' => __( 'User field', 'jet-form-builder' ),
297 'type' => 'select',
298 'options' => Tools::with_placeholder(
299 array(
300 array(
301 'value' => 'ID',
302 'label' => __( 'User ID', 'jet-form-builder' ),
303 ),
304 array(
305 'value' => 'user_login',
306 'label' => __( 'User Login', 'jet-form-builder' ),
307 ),
308 array(
309 'value' => 'user_email',
310 'label' => __( 'Email', 'jet-form-builder' ),
311 ),
312 array(
313 'value' => 'password',
314 'label' => __( 'Password', 'jet-form-builder' ),
315 ),
316 array(
317 'value' => 'first_name',
318 'label' => __( 'First Name', 'jet-form-builder' ),
319 ),
320 array(
321 'value' => 'last_name',
322 'label' => __( 'Last Name', 'jet-form-builder' ),
323 ),
324 array(
325 'value' => 'display_name',
326 'label' => __( 'Display Name', 'jet-form-builder' ),
327 ),
328 array(
329 'value' => 'user_url',
330 'label' => __( 'User URL', 'jet-form-builder' ),
331 ),
332 array(
333 'value' => 'user_meta',
334 'label' => __( 'User Meta', 'jet-form-builder' ),
335 ),
336 )
337 ),
338 'parent_condition' => array(
339 'field' => 'from',
340 'value' => 'user',
341 ),
342 ),
343 array(
344 'name' => 'key',
345 'label' => __( 'Meta field key', 'jet-form-builder' ),
346 'type' => 'text',
347 'parent_condition' => array(
348 'field' => 'from',
349 'value' => 'user',
350 ),
351 'condition' => array(
352 'field' => 'prop',
353 'value' => 'user_meta',
354 ),
355 ),
356 array(
357 'name' => 'prop',
358 'label' => __( 'Term property', 'jet-form-builder' ),
359 'type' => 'select',
360 'options' => Tools::with_placeholder(
361 array(
362 array(
363 'value' => 'term_id',
364 'label' => __( 'Term ID', 'jet-form-builder' ),
365 ),
366 array(
367 'value' => 'name',
368 'label' => __( 'Name', 'jet-form-builder' ),
369 ),
370 array(
371 'value' => 'slug',
372 'label' => __( 'Slug', 'jet-form-builder' ),
373 ),
374 array(
375 'value' => 'parent',
376 'label' => __( 'Parent', 'jet-form-builder' ),
377 ),
378 array(
379 'value' => 'term_meta',
380 'label' => __( 'Term Meta', 'jet-form-builder' ),
381 ),
382 )
383 ),
384 'parent_condition' => array(
385 'field' => 'from',
386 'value' => 'term',
387 ),
388 ),
389 array(
390 'name' => 'key',
391 'label' => __( 'Meta field key', 'jet-form-builder' ),
392 'type' => 'text',
393 'parent_condition' => array(
394 'field' => 'from',
395 'value' => 'term',
396 ),
397 'condition' => array(
398 'field' => 'prop',
399 'value' => 'term_meta',
400 ),
401 ),
402 ),
403 )
404 );
405 }
406
407 /**
408 * Enqueue editor assets
409 *
410 * @return void
411 * @throws Repository_Exception
412 */
413 public function enqueue_assets() {
414 $script_asset = require_once jet_form_builder()->plugin_dir( 'assets/build/editor/package.asset.php' );
415
416 if ( true === $script_asset ) {
417 return;
418 }
419
420 do_action( 'jet-form-builder/editor-package/before', $this, self::EDITOR_PACKAGE_HANDLE );
421
422 array_push(
423 $script_asset['dependencies'],
424 'jet-fb-components',
425 'jet-fb-data',
426 'jet-fb-actions-v2',
427 'jet-fb-blocks-v2-to-actions-v2'
428 );
429 wp_enqueue_style( 'jet-fb-components' );
430
431 wp_enqueue_script(
432 self::EDITOR_PACKAGE_HANDLE,
433 Plugin::instance()->plugin_url( 'assets/build/editor/package.js' ),
434 $script_asset['dependencies'],
435 $script_asset['version'],
436 true
437 );
438
439 wp_localize_script(
440 self::EDITOR_PACKAGE_HANDLE,
441 'jetFormEvents',
442 jet_fb_events()->to_array()
443 );
444
445 wp_localize_script(
446 self::EDITOR_PACKAGE_HANDLE,
447 'jetFormBlockConditions',
448 Block_Condition_Manager::instance()->to_array()
449 );
450
451 wp_set_script_translations(
452 self::EDITOR_PACKAGE_HANDLE,
453 'jet-form-builder',
454 Plugin::instance()->plugin_dir( 'languages' )
455 );
456
457 $script_asset = require_once jet_form_builder()->plugin_dir( 'assets/build/editor/form.builder.asset.php' );
458
459 do_action( 'jet-form-builder/editor-assets/before', $this, self::EDITOR_HANDLE );
460
461 wp_enqueue_script(
462 self::EDITOR_HANDLE,
463 Plugin::instance()->plugin_url( 'assets/build/editor/form.builder.js' ),
464 $script_asset['dependencies'],
465 $script_asset['version'],
466 true
467 );
468
469 wp_enqueue_style(
470 self::EDITOR_HANDLE,
471 Plugin::instance()->plugin_url( 'assets/build/editor/form.builder.css' ),
472 array(
473 'media',
474 'l10n',
475 'buttons',
476 'wp-edit-blocks',
477 'wp-editor',
478 ),
479 $script_asset['version']
480 );
481
482 $conditions_settings = ( new Action_Condition_Manager() )->get_settings();
483 $exclude_events = array(
484 'redirect_to_page' => array( 'WC.ORDER.COMPLETE', 'WC.CHECKOUT.COMPLETE' ),
485 );
486
487 /** @var Module $post_type */
488 /** @noinspection PhpUnhandledExceptionInspection */
489 $post_type = jet_form_builder()->module( 'post-type' );
490
491 $utm = new Utm_Url( 'plugin' );
492 $utm->set_medium( 'editor' );
493 $utm->set_content( $utm->get_license_and_theme() );
494
495 $addons = JET_FORM_BUILDER_SITE . '/addons/';
496 $pricing = JET_FORM_BUILDER_SITE . '/pricing/';
497
498 wp_localize_script(
499 self::EDITOR_PACKAGE_HANDLE,
500 'JetFormEditorData',
501 apply_filters(
502 'jet-form-builder/editor/config',
503 array(
504 'presetConfig' => $this->get_preset_config(),
505 'messagesDefault' => $post_type->get_messages(),
506 'helpForRepeaters' => $this->get_help_for_repeaters(),
507 'global_settings' => Tab_Handler_Manager::instance()->all(),
508 'global_settings_url' => Pages_Manager::instance()->get_stable_url( 'jfb-settings' ),
509 'jetEngineVersion' => Tools::get_jet_engine_version(),
510 'actionConditionSettings' => $conditions_settings,
511 'actionConditionExcludeEvents' => $exclude_events,
512 'argumentsSource' => Form_Arguments::get_options(),
513 'utmLinks' => array(
514 'allProActions' => $utm->set_campaign( 'jetform-settings/pro-actions' )->add_query( $addons ),
515 'limitResponses' => $utm->set_campaign( 'jetform-settings/limit-form-responses' )->add_query( $pricing ),
516 'scheduleForm' => $utm->set_campaign( 'jetform-settings/schedule-forms' )->add_query( $pricing ),
517 'userLoginPattern' => $utm->set_campaign( 'welcome-block/user-login' )->add_query( $addons . 'user-login/' ),
518 'resetPassPattern' => $utm->set_campaign( 'welcome-block/reset-password' )->add_query( $addons . 'user-login/' ),
519 ),
520 'isActivePro' => jet_form_builder()->addons_manager->is_active(),
521 'assetsUrl' => jet_form_builder()->plugin_url( 'assets/' ),
522 )
523 )
524 );
525
526 do_action( 'jet-form-builder/editor-assets/after', $this, self::EDITOR_HANDLE );
527 }
528
529 private function get_help_for_repeaters() {
530 return array(
531 'conditional_block' => array(
532 'label' => __( 'With many conditions for the block, they are checked with the AND operator', 'jet-form-builder' ),
533 ),
534 'conditional_block_or' => array(
535 'label' => __( 'With many conditions for the block, they are checked with the OR operator', 'jet-form-builder' ),
536 ),
537 'conditional_action' => array(
538 'label' => __( 'With many conditions for the action, they are checked with the AND operator', 'jet-form-builder' ),
539 ),
540 'conditional_action_or' => array(
541 'label' => __( 'With many conditions for the action, they are checked with the OR operator', 'jet-form-builder' ),
542 ),
543 );
544 }
545
546 public function enqueue_form_assets() {
547
548 $handle = 'jet-form-builder/form';
549
550 do_action( 'jet-form-builder/other-editor-assets/before', $this, $handle );
551
552 // todo: refactor with new way of assets loading
553 wp_register_script(
554 $handle,
555 Plugin::instance()->plugin_url( 'assets/build/editor/default.builder.js' ),
556 array(
557 'wp-core-data',
558 'wp-data',
559 'wp-block-library',
560 'wp-format-library',
561 'wp-api-fetch',
562 ),
563 JET_FORM_BUILDER_VERSION,
564 true
565 );
566
567 wp_register_style(
568 'jet-form-builder-others',
569 Plugin::instance()->plugin_url( 'assets/build/frontend/main.css' ),
570 array(),
571 Plugin::instance()->get_version()
572 );
573
574 do_action( 'jet-form-builder/other-editor-assets/after', $this, $handle );
575 }
576
577 }
578