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