PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.2
JetFormBuilder — Dynamic Blocks Form Builder v3.1.2
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
462 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' => 'user_url',
275 'label' => __( 'User URL', 'jet-form-builder' ),
276 ),
277 array(
278 'value' => 'user_meta',
279 'label' => __( 'User Meta', 'jet-form-builder' ),
280 ),
281 )
282 ),
283 'parent_condition' => array(
284 'field' => 'from',
285 'value' => 'user',
286 ),
287 ),
288 array(
289 'name' => 'key',
290 'label' => __( 'Meta field key', 'jet-form-builder' ),
291 'type' => 'text',
292 'parent_condition' => array(
293 'field' => 'from',
294 'value' => 'user',
295 ),
296 'condition' => array(
297 'field' => 'prop',
298 'value' => 'user_meta',
299 ),
300 ),
301 ),
302 )
303 );
304 }
305
306 /**
307 * Enqueue editor assets
308 *
309 * @return void
310 */
311 public function enqueue_assets() {
312 do_action( 'jet-form-builder/editor-package/before', $this, self::EDITOR_PACKAGE_HANDLE );
313
314 wp_enqueue_script(
315 self::EDITOR_PACKAGE_HANDLE,
316 Plugin::instance()->plugin_url( 'assets/js/editor/package.js' ),
317 array(
318 'wp-editor',
319 'wp-core-data',
320 'wp-data',
321 'wp-block-library',
322 'wp-format-library',
323 'wp-api-fetch',
324 ),
325 JET_FORM_BUILDER_VERSION,
326 true
327 );
328
329 wp_localize_script(
330 self::EDITOR_PACKAGE_HANDLE,
331 'jetFormEvents',
332 jet_fb_events()->to_array()
333 );
334
335 wp_localize_script(
336 self::EDITOR_PACKAGE_HANDLE,
337 'jetFormValidation',
338 Validation::instance()->to_array()
339 );
340
341 wp_localize_script(
342 self::EDITOR_PACKAGE_HANDLE,
343 'jetFormBlockConditions',
344 Block_Condition_Manager::instance()->to_array()
345 );
346
347 wp_set_script_translations(
348 self::EDITOR_PACKAGE_HANDLE,
349 'jet-form-builder',
350 Plugin::instance()->plugin_dir( 'languages' )
351 );
352
353 do_action( 'jet-form-builder/editor-assets/before', $this, self::EDITOR_HANDLE );
354
355 wp_enqueue_script(
356 self::EDITOR_HANDLE,
357 Plugin::instance()->plugin_url( 'assets/js/editor/form.builder.js' ),
358 array(),
359 JET_FORM_BUILDER_VERSION,
360 true
361 );
362
363 wp_enqueue_style(
364 self::EDITOR_HANDLE,
365 JET_FORM_BUILDER_URL . 'assets/css/editor.css',
366 array(
367 'media',
368 'l10n',
369 'buttons',
370 'wp-edit-blocks',
371 'wp-editor',
372 ),
373 JET_FORM_BUILDER_VERSION,
374 'all'
375 );
376
377 $conditions_settings = ( new Action_Condition_Manager() )->get_settings();
378
379 /** @var Messages_Meta $messages_meta */
380 $messages_meta = jet_form_builder()->post_type->get_meta( Messages_Meta::class );
381
382 $utm = new Utm_Url( 'wp-admin/editor-jet-form' );
383 $addons = JET_FORM_BUILDER_SITE . '/addons/';
384 $pricing = JET_FORM_BUILDER_SITE . '/pricing/';
385
386 wp_localize_script(
387 self::EDITOR_PACKAGE_HANDLE,
388 'JetFormEditorData',
389 apply_filters(
390 'jet-form-builder/editor/config',
391 array(
392 'presetConfig' => $this->get_preset_config(),
393 'messagesDefault' => $messages_meta->messages(),
394 'helpForRepeaters' => $this->get_help_for_repeaters(),
395 'global_settings' => Tab_Handler_Manager::instance()->all(),
396 'global_settings_url' => Pages_Manager::instance()->get_stable_url( 'jfb-settings' ),
397 'jetEngineVersion' => Tools::get_jet_engine_version(),
398 'actionConditionSettings' => $conditions_settings,
399 'argumentsSource' => Form_Arguments::get_options(),
400 'utmLinks' => array(
401 'allProActions' => $utm->set_campaign( 'pro-actions' )->add_query( $addons ),
402 'limitResponses' => $utm->set_campaign( 'responses-pricing' )->add_query( $pricing ),
403 'scheduleForm' => $utm->set_campaign( 'schedule-pricing' )->add_query( $pricing ),
404 ),
405 'isActivePro' => jet_form_builder()->addons_manager->is_active(),
406 'assetsUrl' => jet_form_builder()->plugin_url( 'assets/' ),
407 )
408 )
409 );
410
411 do_action( 'jet-form-builder/editor-assets/after', $this, self::EDITOR_HANDLE );
412 }
413
414 private function get_help_for_repeaters() {
415 return array(
416 'conditional_block' => array(
417 'label' => __( 'With many conditions for the block, they are checked with the AND operator', 'jet-form-builder' ),
418 ),
419 'conditional_block_or' => array(
420 'label' => __( 'With many conditions for the block, they are checked with the OR operator', 'jet-form-builder' ),
421 ),
422 'conditional_action' => array(
423 'label' => __( 'With many conditions for the action, they are checked with the AND operator', 'jet-form-builder' ),
424 ),
425 'conditional_action_or' => array(
426 'label' => __( 'With many conditions for the action, they are checked with the OR operator', 'jet-form-builder' ),
427 ),
428 );
429 }
430
431 public function enqueue_form_assets() {
432
433 $handle = 'jet-form-builder/form';
434
435 do_action( 'jet-form-builder/other-editor-assets/before', $this, $handle );
436
437 wp_register_script(
438 $handle,
439 Plugin::instance()->plugin_url( 'assets/js/editor/default.builder.js' ),
440 array(
441 'wp-core-data',
442 'wp-data',
443 'wp-block-library',
444 'wp-format-library',
445 'wp-api-fetch',
446 ),
447 JET_FORM_BUILDER_VERSION,
448 true
449 );
450
451 wp_register_style(
452 'jet-form-builder-others',
453 Plugin::instance()->plugin_url( 'assets/css/frontend.css' ),
454 array(),
455 Plugin::instance()->get_version()
456 );
457
458 do_action( 'jet-form-builder/other-editor-assets/after', $this, $handle );
459 }
460
461 }
462