PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.8
JetFormBuilder — Dynamic Blocks Form Builder v3.1.8
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\Gateways\Gateway_Manager;
13 use Jet_Form_Builder\Plugin;
14 use Jet_Form_Builder\Blocks\Conditional_Block\Condition_Manager as Block_Condition_Manager;
15 use Jet_Form_Builder\Post_Meta\Messages_Meta;
16
17 // If this file is called directly, abort.
18 if ( ! defined( 'WPINC' ) ) {
19 die;
20 }
21
22 /**
23 * Define Editor class
24 */
25 class Editor {
26
27 const EDITOR_HANDLE = 'jet-form-builder-editor';
28 const EDITOR_PACKAGE_HANDLE = 'jet-form-builder-editor-package';
29
30 public function __construct() {
31 add_action( 'enqueue_block_editor_assets', array( $this, 'admin_assets' ) );
32 }
33
34 /**
35 * Register admin assets
36 *
37 * @return void [type] [description]
38 */
39 public function admin_assets() {
40 if ( jet_form_builder()->post_type->is_form_editor ) {
41 $this->enqueue_assets();
42 } else {
43 $this->enqueue_form_assets();
44 }
45 }
46
47 /**
48 * Returns taxonomies list for the config
49 *
50 * @return [type] [description]
51 */
52 public function get_taxonomies_list() {
53
54 $taxonomies = get_taxonomies( array(), 'objects' );
55
56 $result = array();
57
58 foreach ( $taxonomies as $tax ) {
59 $result[] = array(
60 'value' => $tax->name,
61 'label' => sprintf( '%1$s (%2$s)', $tax->label, $tax->name ),
62 );
63 }
64
65 return $result;
66 }
67
68 public function get_preset_config() {
69 return apply_filters(
70 'jet-form-builder/editor/preset-config',
71 array(
72 'global_fields' => array(
73 array(
74 'name' => 'from',
75 'label' => __( 'Source:', 'jet-form-builder' ),
76 'type' => 'select',
77 'options' => Tools::with_placeholder(
78 array(
79 array(
80 'value' => 'post',
81 'label' => __( 'Post', 'jet-form-builder' ),
82 ),
83 array(
84 'value' => 'user',
85 'label' => __( 'User', 'jet-form-builder' ),
86 ),
87 array(
88 'value' => 'query_var',
89 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
90 ),
91 )
92 ),
93 ),
94 array(
95 'name' => 'post_from',
96 'label' => __( 'Get post ID from:', 'jet-form-builder' ),
97 'type' => 'select',
98 'options' => Tools::with_placeholder(
99 array(
100 array(
101 'value' => 'current_post',
102 'label' => __( 'Current post', 'jet-form-builder' ),
103 ),
104 array(
105 'value' => 'query_var',
106 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
107 ),
108 )
109 ),
110 'condition' => array(
111 'field' => 'from',
112 'value' => 'post',
113 ),
114 ),
115 array(
116 'name' => 'user_from',
117 'label' => __( 'Get user ID from:', 'jet-form-builder' ),
118 'type' => 'select',
119 'options' => Tools::with_placeholder(
120 array(
121 array(
122 'value' => 'current_user',
123 'label' => __( 'Current user', 'jet-form-builder' ),
124 ),
125 array(
126 'value' => 'queried_user',
127 'label' => __( 'Queried user', 'jet-form-builder' ),
128 ),
129 array(
130 'value' => 'query_var',
131 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
132 ),
133 )
134 ),
135 'condition' => array(
136 'field' => 'from',
137 'value' => 'user',
138 ),
139 ),
140 array(
141 'name' => 'query_var',
142 'label' => __( 'Query variable name:', 'jet-form-builder' ),
143 'type' => 'text',
144 'custom_condition' => 'query_var',
145 'position' => 'dynamic',
146 ),
147 ),
148 'map_fields' => array(
149 array(
150 'name' => 'key',
151 'label' => __( 'Query variable key', 'jet-form-builder' ),
152 'type' => 'text',
153 'position' => 'general',
154 'parent_condition' => array(
155 'field' => 'from',
156 'value' => 'query_var',
157 ),
158 ),
159 array(
160 'name' => 'prop',
161 'label' => __( 'Post property', 'jet-form-builder' ),
162 'type' => 'select',
163 'options' => Tools::with_placeholder(
164 array(
165 array(
166 'value' => 'ID',
167 'label' => __( 'Post ID', 'jet-form-builder' ),
168 ),
169 array(
170 'value' => 'post_title',
171 'label' => __( 'Post Title', 'jet-form-builder' ),
172 ),
173 array(
174 'value' => 'post_content',
175 'label' => __( 'Post Content', 'jet-form-builder' ),
176 ),
177 array(
178 'value' => 'post_status',
179 'label' => __( 'Post Status', 'jet-form-builder' ),
180 ),
181 array(
182 'value' => 'post_author',
183 'label' => __( 'Post Author', 'jet-form-builder' ),
184 ),
185 array(
186 'value' => 'post_excerpt',
187 'label' => __( 'Post Excerpt', 'jet-form-builder' ),
188 ),
189 array(
190 'value' => 'post_date',
191 'label' => __( 'Post Date', 'jet-form-builder' ),
192 ),
193 array(
194 'value' => 'post_date_gmt',
195 'label' => __( 'Post Date GMT', 'jet-form-builder' ),
196 ),
197 array(
198 'value' => 'post_thumb',
199 'label' => __( 'Post Thumbnail', 'jet-form-builder' ),
200 ),
201 array(
202 'value' => 'post_meta',
203 'label' => __( 'Post Meta', 'jet-form-builder' ),
204 ),
205 array(
206 'value' => 'post_terms',
207 'label' => __( 'Post Terms', 'jet-form-builder' ),
208 ),
209 )
210 ),
211 'parent_condition' => array(
212 'field' => 'from',
213 'value' => 'post',
214 ),
215 ),
216 array(
217 'name' => 'key',
218 'label' => __( 'Taxonomy', 'jet-form-builder' ),
219 'type' => 'select',
220 'options' => Tools::with_placeholder( $this->get_taxonomies_list() ),
221 'parent_condition' => array(
222 'field' => 'from',
223 'value' => 'post',
224 ),
225 'condition' => array(
226 'field' => 'prop',
227 'value' => 'post_terms',
228 ),
229 ),
230 array(
231 'name' => 'key',
232 'label' => __( 'Meta field key', 'jet-form-builder' ),
233 'type' => 'text',
234 'parent_condition' => array(
235 'field' => 'from',
236 'value' => 'post',
237 ),
238 'condition' => array(
239 'field' => 'prop',
240 'value' => 'post_meta',
241 ),
242 ),
243 array(
244 'name' => 'prop',
245 'label' => __( 'User field', 'jet-form-builder' ),
246 'type' => 'select',
247 'options' => Tools::with_placeholder(
248 array(
249 array(
250 'value' => 'ID',
251 'label' => __( 'User ID', 'jet-form-builder' ),
252 ),
253 array(
254 'value' => 'user_login',
255 'label' => __( 'User Login', 'jet-form-builder' ),
256 ),
257 array(
258 'value' => 'user_email',
259 'label' => __( 'Email', 'jet-form-builder' ),
260 ),
261 array(
262 'value' => 'password',
263 'label' => __( 'Password', 'jet-form-builder' ),
264 ),
265 array(
266 'value' => 'first_name',
267 'label' => __( 'First Name', 'jet-form-builder' ),
268 ),
269 array(
270 'value' => 'last_name',
271 'label' => __( 'Last Name', 'jet-form-builder' ),
272 ),
273 array(
274 'value' => 'display_name',
275 'label' => __( 'Display Name', 'jet-form-builder' ),
276 ),
277 array(
278 'value' => 'user_url',
279 'label' => __( 'User URL', 'jet-form-builder' ),
280 ),
281 array(
282 'value' => 'user_meta',
283 'label' => __( 'User Meta', 'jet-form-builder' ),
284 ),
285 )
286 ),
287 'parent_condition' => array(
288 'field' => 'from',
289 'value' => 'user',
290 ),
291 ),
292 array(
293 'name' => 'key',
294 'label' => __( 'Meta field key', 'jet-form-builder' ),
295 'type' => 'text',
296 'parent_condition' => array(
297 'field' => 'from',
298 'value' => 'user',
299 ),
300 'condition' => array(
301 'field' => 'prop',
302 'value' => 'user_meta',
303 ),
304 ),
305 ),
306 )
307 );
308 }
309
310 /**
311 * Enqueue editor assets
312 *
313 * @return void
314 */
315 public function enqueue_assets() {
316 do_action( 'jet-form-builder/editor-package/before', $this, self::EDITOR_PACKAGE_HANDLE );
317
318 wp_enqueue_script(
319 self::EDITOR_PACKAGE_HANDLE,
320 Plugin::instance()->plugin_url( 'assets/js/editor/package.js' ),
321 array(
322 'wp-editor',
323 'wp-core-data',
324 'wp-data',
325 'wp-block-library',
326 'wp-format-library',
327 'wp-api-fetch',
328 ),
329 JET_FORM_BUILDER_VERSION,
330 true
331 );
332
333 wp_localize_script(
334 self::EDITOR_PACKAGE_HANDLE,
335 'jetFormEvents',
336 jet_fb_events()->to_array()
337 );
338
339 wp_localize_script(
340 self::EDITOR_PACKAGE_HANDLE,
341 'jetFormValidation',
342 Validation::instance()->to_array()
343 );
344
345 wp_localize_script(
346 self::EDITOR_PACKAGE_HANDLE,
347 'jetFormBlockConditions',
348 Block_Condition_Manager::instance()->to_array()
349 );
350
351 wp_set_script_translations(
352 self::EDITOR_PACKAGE_HANDLE,
353 'jet-form-builder',
354 Plugin::instance()->plugin_dir( 'languages' )
355 );
356
357 do_action( 'jet-form-builder/editor-assets/before', $this, self::EDITOR_HANDLE );
358
359 wp_enqueue_script(
360 self::EDITOR_HANDLE,
361 Plugin::instance()->plugin_url( 'assets/js/editor/form.builder.js' ),
362 array(),
363 JET_FORM_BUILDER_VERSION,
364 true
365 );
366
367 wp_enqueue_style(
368 self::EDITOR_HANDLE,
369 JET_FORM_BUILDER_URL . 'assets/css/editor.css',
370 array(
371 'media',
372 'l10n',
373 'buttons',
374 'wp-edit-blocks',
375 'wp-editor',
376 ),
377 JET_FORM_BUILDER_VERSION,
378 'all'
379 );
380
381 $conditions_settings = ( new Action_Condition_Manager() )->get_settings();
382
383 /** @var Messages_Meta $messages_meta */
384 $messages_meta = jet_form_builder()->post_type->get_meta( Messages_Meta::class );
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' => $messages_meta->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