PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.2.1
JetFormBuilder — Dynamic Blocks Form Builder v3.2.1
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
exceptions 2 years ago pages 2 years ago single-pages 2 years ago table-views 2 years ago tabs-handlers 2 years ago editor.php 2 years ago
editor.php
466 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\Pages\Pages_Manager;
7 use Jet_Form_Builder\Admin\Tabs_Handlers\Tab_Handler_Manager;
8 use Jet_Form_Builder\Blocks\Validation;
9 use Jet_Form_Builder\Classes\Arguments\Form_Arguments;
10 use Jet_Form_Builder\Classes\Http\Utm_Url;
11 use Jet_Form_Builder\Classes\Tools;
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 )
91 ),
92 ),
93 array(
94 'name' => 'post_from',
95 'label' => __( 'Get post ID from:', 'jet-form-builder' ),
96 'type' => 'select',
97 'options' => Tools::with_placeholder(
98 array(
99 array(
100 'value' => 'current_post',
101 'label' => __( 'Current post', 'jet-form-builder' ),
102 ),
103 array(
104 'value' => 'query_var',
105 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
106 ),
107 )
108 ),
109 'condition' => array(
110 'field' => 'from',
111 'value' => 'post',
112 ),
113 ),
114 array(
115 'name' => 'user_from',
116 'label' => __( 'Get user ID from:', 'jet-form-builder' ),
117 'type' => 'select',
118 'options' => Tools::with_placeholder(
119 array(
120 array(
121 'value' => 'current_user',
122 'label' => __( 'Current user', 'jet-form-builder' ),
123 ),
124 array(
125 'value' => 'queried_user',
126 'label' => __( 'Queried user', 'jet-form-builder' ),
127 ),
128 array(
129 'value' => 'query_var',
130 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
131 ),
132 )
133 ),
134 'condition' => array(
135 'field' => 'from',
136 'value' => 'user',
137 ),
138 ),
139 array(
140 'name' => 'query_var',
141 'label' => __( 'Query variable name:', 'jet-form-builder' ),
142 'type' => 'text',
143 'custom_condition' => 'query_var',
144 'position' => 'dynamic',
145 ),
146 ),
147 'map_fields' => array(
148 array(
149 'name' => 'key',
150 'label' => __( 'Query variable key', 'jet-form-builder' ),
151 'type' => 'text',
152 'position' => 'general',
153 'parent_condition' => array(
154 'field' => 'from',
155 'value' => 'query_var',
156 ),
157 ),
158 array(
159 'name' => 'prop',
160 'label' => __( 'Post property', 'jet-form-builder' ),
161 'type' => 'select',
162 'options' => Tools::with_placeholder(
163 array(
164 array(
165 'value' => 'ID',
166 'label' => __( 'Post ID', 'jet-form-builder' ),
167 ),
168 array(
169 'value' => 'post_title',
170 'label' => __( 'Post Title', 'jet-form-builder' ),
171 ),
172 array(
173 'value' => 'post_content',
174 'label' => __( 'Post Content', 'jet-form-builder' ),
175 ),
176 array(
177 'value' => 'post_status',
178 'label' => __( 'Post Status', 'jet-form-builder' ),
179 ),
180 array(
181 'value' => 'post_author',
182 'label' => __( 'Post Author', 'jet-form-builder' ),
183 ),
184 array(
185 'value' => 'post_excerpt',
186 'label' => __( 'Post Excerpt', 'jet-form-builder' ),
187 ),
188 array(
189 'value' => 'post_date',
190 'label' => __( 'Post Date', 'jet-form-builder' ),
191 ),
192 array(
193 'value' => 'post_date_gmt',
194 'label' => __( 'Post Date GMT', 'jet-form-builder' ),
195 ),
196 array(
197 'value' => 'post_thumb',
198 'label' => __( 'Post Thumbnail', 'jet-form-builder' ),
199 ),
200 array(
201 'value' => 'post_meta',
202 'label' => __( 'Post Meta', 'jet-form-builder' ),
203 ),
204 array(
205 'value' => 'post_terms',
206 'label' => __( 'Post Terms', 'jet-form-builder' ),
207 ),
208 )
209 ),
210 'parent_condition' => array(
211 'field' => 'from',
212 'value' => 'post',
213 ),
214 ),
215 array(
216 'name' => 'key',
217 'label' => __( 'Taxonomy', 'jet-form-builder' ),
218 'type' => 'select',
219 'options' => Tools::with_placeholder( $this->get_taxonomies_list() ),
220 'parent_condition' => array(
221 'field' => 'from',
222 'value' => 'post',
223 ),
224 'condition' => array(
225 'field' => 'prop',
226 'value' => 'post_terms',
227 ),
228 ),
229 array(
230 'name' => 'key',
231 'label' => __( 'Meta field key', 'jet-form-builder' ),
232 'type' => 'text',
233 'parent_condition' => array(
234 'field' => 'from',
235 'value' => 'post',
236 ),
237 'condition' => array(
238 'field' => 'prop',
239 'value' => 'post_meta',
240 ),
241 ),
242 array(
243 'name' => 'prop',
244 'label' => __( 'User field', 'jet-form-builder' ),
245 'type' => 'select',
246 'options' => Tools::with_placeholder(
247 array(
248 array(
249 'value' => 'ID',
250 'label' => __( 'User ID', 'jet-form-builder' ),
251 ),
252 array(
253 'value' => 'user_login',
254 'label' => __( 'User Login', 'jet-form-builder' ),
255 ),
256 array(
257 'value' => 'user_email',
258 'label' => __( 'Email', 'jet-form-builder' ),
259 ),
260 array(
261 'value' => 'password',
262 'label' => __( 'Password', 'jet-form-builder' ),
263 ),
264 array(
265 'value' => 'first_name',
266 'label' => __( 'First Name', 'jet-form-builder' ),
267 ),
268 array(
269 'value' => 'last_name',
270 'label' => __( 'Last Name', 'jet-form-builder' ),
271 ),
272 array(
273 'value' => 'display_name',
274 'label' => __( 'Display 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 Plugin::instance()->plugin_url( 'assets/js/editor/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 'jetFormValidation',
341 Validation::instance()->to_array()
342 );
343
344 wp_localize_script(
345 self::EDITOR_PACKAGE_HANDLE,
346 'jetFormBlockConditions',
347 Block_Condition_Manager::instance()->to_array()
348 );
349
350 wp_set_script_translations(
351 self::EDITOR_PACKAGE_HANDLE,
352 'jet-form-builder',
353 Plugin::instance()->plugin_dir( 'languages' )
354 );
355
356 do_action( 'jet-form-builder/editor-assets/before', $this, self::EDITOR_HANDLE );
357
358 wp_enqueue_script(
359 self::EDITOR_HANDLE,
360 Plugin::instance()->plugin_url( 'assets/js/editor/form.builder.js' ),
361 array(),
362 JET_FORM_BUILDER_VERSION,
363 true
364 );
365
366 wp_enqueue_style(
367 self::EDITOR_HANDLE,
368 JET_FORM_BUILDER_URL . 'assets/css/editor.css',
369 array(
370 'media',
371 'l10n',
372 'buttons',
373 'wp-edit-blocks',
374 'wp-editor',
375 ),
376 JET_FORM_BUILDER_VERSION,
377 'all'
378 );
379
380 $conditions_settings = ( new Action_Condition_Manager() )->get_settings();
381
382 /** @var Module $post_type */
383 /** @noinspection PhpUnhandledExceptionInspection */
384 $post_type = jet_form_builder()->module( 'post-type' );
385
386 $utm = new Utm_Url( 'wp-admin/editor-jet-form' );
387 $addons = JET_FORM_BUILDER_SITE . '/addons/';
388 $pricing = JET_FORM_BUILDER_SITE . '/pricing/';
389
390 wp_localize_script(
391 self::EDITOR_PACKAGE_HANDLE,
392 'JetFormEditorData',
393 apply_filters(
394 'jet-form-builder/editor/config',
395 array(
396 'presetConfig' => $this->get_preset_config(),
397 'messagesDefault' => $post_type->get_messages(),
398 'helpForRepeaters' => $this->get_help_for_repeaters(),
399 'global_settings' => Tab_Handler_Manager::instance()->all(),
400 'global_settings_url' => Pages_Manager::instance()->get_stable_url( 'jfb-settings' ),
401 'jetEngineVersion' => Tools::get_jet_engine_version(),
402 'actionConditionSettings' => $conditions_settings,
403 'argumentsSource' => Form_Arguments::get_options(),
404 'utmLinks' => array(
405 'allProActions' => $utm->set_campaign( 'pro-actions' )->add_query( $addons ),
406 'limitResponses' => $utm->set_campaign( 'responses-pricing' )->add_query( $pricing ),
407 'scheduleForm' => $utm->set_campaign( 'schedule-pricing' )->add_query( $pricing ),
408 ),
409 'isActivePro' => jet_form_builder()->addons_manager->is_active(),
410 'assetsUrl' => jet_form_builder()->plugin_url( 'assets/' ),
411 )
412 )
413 );
414
415 do_action( 'jet-form-builder/editor-assets/after', $this, self::EDITOR_HANDLE );
416 }
417
418 private function get_help_for_repeaters() {
419 return array(
420 'conditional_block' => array(
421 'label' => __( 'With many conditions for the block, they are checked with the AND operator', 'jet-form-builder' ),
422 ),
423 'conditional_block_or' => array(
424 'label' => __( 'With many conditions for the block, they are checked with the OR operator', 'jet-form-builder' ),
425 ),
426 'conditional_action' => array(
427 'label' => __( 'With many conditions for the action, they are checked with the AND operator', 'jet-form-builder' ),
428 ),
429 'conditional_action_or' => array(
430 'label' => __( 'With many conditions for the action, they are checked with the OR operator', 'jet-form-builder' ),
431 ),
432 );
433 }
434
435 public function enqueue_form_assets() {
436
437 $handle = 'jet-form-builder/form';
438
439 do_action( 'jet-form-builder/other-editor-assets/before', $this, $handle );
440
441 wp_register_script(
442 $handle,
443 Plugin::instance()->plugin_url( 'assets/js/editor/default.builder.js' ),
444 array(
445 'wp-core-data',
446 'wp-data',
447 'wp-block-library',
448 'wp-format-library',
449 'wp-api-fetch',
450 ),
451 JET_FORM_BUILDER_VERSION,
452 true
453 );
454
455 wp_register_style(
456 'jet-form-builder-others',
457 Plugin::instance()->plugin_url( 'assets/css/frontend.css' ),
458 array(),
459 Plugin::instance()->get_version()
460 );
461
462 do_action( 'jet-form-builder/other-editor-assets/after', $this, $handle );
463 }
464
465 }
466