PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.2
JetFormBuilder — Dynamic Blocks Form Builder v2.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
buttons 3 years ago exceptions 3 years ago notices 3 years ago pages 3 years ago single-pages 3 years ago table-views 3 years ago tabs-handlers 3 years ago vui-boxes 3 years ago admin-page-interface.php 3 years ago admin-page-trait.php 3 years ago editor.php 3 years ago table-advanced-record-prepare-trait.php 3 years ago table-record-prepare-trait.php 3 years ago
editor.php
450 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\Tabs_Handlers\Tab_Handler_Manager;
7 use Jet_Form_Builder\Classes\Arguments\Form_Arguments;
8 use Jet_Form_Builder\Classes\Http\Utm_Url;
9 use Jet_Form_Builder\Classes\Tools;
10 use Jet_Form_Builder\Gateways\Gateway_Manager;
11 use Jet_Form_Builder\Plugin;
12 use Jet_Form_Builder\Blocks\Conditional_Block\Condition_Manager as Block_Condition_Manager;
13
14 /**
15 * Form editor class
16 * Thanks Tom J Nowell for initial editor idea and inspiration!
17 */
18
19 // If this file is called directly, abort.
20 if ( ! defined( 'WPINC' ) ) {
21 die;
22 }
23
24 /**
25 * Define Editor class
26 */
27 class Editor {
28
29 const EDITOR_HANDLE = 'jet-form-builder-editor';
30 const EDITOR_PACKAGE_HANDLE = 'jet-form-builder-editor-package';
31
32 public function __construct() {
33 add_action( 'enqueue_block_editor_assets', array( $this, 'admin_assets' ) );
34 }
35
36 /**
37 * Register admin assets
38 *
39 * @return void [type] [description]
40 */
41 public function admin_assets() {
42 if ( jet_form_builder()->post_type->is_form_editor ) {
43 $this->enqueue_assets();
44 } else {
45 $this->enqueue_form_assets();
46 }
47 }
48
49 /**
50 * Returns taxonomies list for the config
51 *
52 * @return [type] [description]
53 */
54 public function get_taxonomies_list() {
55
56 $taxonomies = get_taxonomies( array(), 'objects' );
57
58 $result = array();
59
60 foreach ( $taxonomies as $tax ) {
61 $result[] = array(
62 'value' => $tax->name,
63 'label' => sprintf( '%1$s (%2$s)', $tax->label, $tax->name ),
64 );
65 }
66
67 return $result;
68
69 }
70
71 public function get_preset_config() {
72 return apply_filters(
73 'jet-form-builder/editor/preset-config',
74 array(
75 'global_fields' => array(
76 array(
77 'name' => 'from',
78 'label' => __( 'Source:', 'jet-form-builder' ),
79 'type' => 'select',
80 'options' => Tools::with_placeholder(
81 array(
82 array(
83 'value' => 'post',
84 'label' => __( 'Post', 'jet-form-builder' ),
85 ),
86 array(
87 'value' => 'user',
88 'label' => __( 'User', 'jet-form-builder' ),
89 ),
90 array(
91 'value' => 'query_var',
92 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
93 ),
94 )
95 ),
96 ),
97 array(
98 'name' => 'post_from',
99 'label' => __( 'Get post ID from:', 'jet-form-builder' ),
100 'type' => 'select',
101 'options' => Tools::with_placeholder(
102 array(
103 array(
104 'value' => 'current_post',
105 'label' => __( 'Current post', 'jet-form-builder' ),
106 ),
107 array(
108 'value' => 'query_var',
109 'label' => __( 'URL Query Variable', 'jet-form-builder' ),
110 ),
111 )
112 ),
113 'condition' => array(
114 'field' => 'from',
115 'value' => 'post',
116 ),
117 ),
118 array(
119 'name' => 'user_from',
120 'label' => __( 'Get user ID from:', 'jet-form-builder' ),
121 'type' => 'select',
122 'options' => Tools::with_placeholder(
123 array(
124 array(
125 'value' => 'current_user',
126 'label' => __( 'Current 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' => 'user_url',
274 'label' => __( 'User URL', 'jet-form-builder' ),
275 ),
276 array(
277 'value' => 'user_meta',
278 'label' => __( 'User Meta', 'jet-form-builder' ),
279 ),
280 )
281 ),
282 'parent_condition' => array(
283 'field' => 'from',
284 'value' => 'user',
285 ),
286 ),
287 array(
288 'name' => 'key',
289 'label' => __( 'Meta field key', 'jet-form-builder' ),
290 'type' => 'text',
291 'parent_condition' => array(
292 'field' => 'from',
293 'value' => 'user',
294 ),
295 'condition' => array(
296 'field' => 'prop',
297 'value' => 'user_meta',
298 ),
299 ),
300 ),
301 )
302 );
303 }
304
305 /**
306 * Enqueue editor assets
307 *
308 * @return void
309 */
310 public function enqueue_assets() {
311 do_action( 'jet-form-builder/editor-package/before', $this, self::EDITOR_PACKAGE_HANDLE );
312
313 wp_enqueue_script(
314 self::EDITOR_PACKAGE_HANDLE,
315 JET_FORM_BUILDER_URL . 'assets/js/package.js',
316 array(
317 'wp-editor',
318 'wp-core-data',
319 'wp-data',
320 'wp-block-library',
321 'wp-format-library',
322 'wp-api-fetch',
323 ),
324 JET_FORM_BUILDER_VERSION,
325 true
326 );
327
328 wp_localize_script(
329 self::EDITOR_PACKAGE_HANDLE,
330 'jetFormEvents',
331 jet_fb_events()->to_array()
332 );
333
334 wp_localize_script(
335 self::EDITOR_PACKAGE_HANDLE,
336 'jetFormBlockConditions',
337 Block_Condition_Manager::instance()->to_array()
338 );
339
340 wp_set_script_translations(
341 self::EDITOR_PACKAGE_HANDLE,
342 'jet-form-builder',
343 Plugin::instance()->plugin_dir( 'languages' )
344 );
345
346 do_action( 'jet-form-builder/editor-assets/before', $this, self::EDITOR_HANDLE );
347
348 wp_enqueue_script(
349 self::EDITOR_HANDLE,
350 JET_FORM_BUILDER_URL . 'assets/js/editor.js',
351 array(),
352 JET_FORM_BUILDER_VERSION,
353 true
354 );
355
356 wp_enqueue_style(
357 self::EDITOR_HANDLE,
358 JET_FORM_BUILDER_URL . 'assets/css/editor.css',
359 array(
360 'media',
361 'l10n',
362 'buttons',
363 'wp-edit-blocks',
364 'wp-editor',
365 ),
366 JET_FORM_BUILDER_VERSION,
367 'all'
368 );
369
370 $conditions_settings = ( new Action_Condition_Manager() )->get_settings();
371
372 $utm = new Utm_Url( 'wp-admin/editor-jet-form' );
373 $addons = JET_FORM_BUILDER_SITE . '/addons/';
374 $pricing = JET_FORM_BUILDER_SITE . '/pricing/';
375
376 wp_localize_script(
377 self::EDITOR_PACKAGE_HANDLE,
378 'JetFormEditorData',
379 array(
380 'presetConfig' => $this->get_preset_config(),
381 'messagesDefault' => Plugin::instance()->post_type->get_messages_default(),
382 'gateways' => Gateway_Manager::instance()->editor_data(),
383 'helpForRepeaters' => $this->get_help_for_repeaters(),
384 'global_settings' => Tab_Handler_Manager::instance()->all(),
385 'jetEngineVersion' => Tools::get_jet_engine_version(),
386 'actionConditionSettings' => $conditions_settings,
387 'argumentsSource' => Form_Arguments::get_options(),
388 'utmLinks' => array(
389 'allProActions' => $utm->set_campaign( 'pro-actions' )->add_query( $addons ),
390 'limitResponses' => $utm->set_campaign( 'responses-pricing' )->add_query( $pricing ),
391 'scheduleForm' => $utm->set_campaign( 'schedule-pricing' )->add_query( $pricing ),
392 ),
393 'isActivePro' => jet_form_builder()->addons_manager->is_active(),
394 )
395 );
396
397 do_action( 'jet-form-builder/editor-assets/after', $this, self::EDITOR_HANDLE );
398 }
399
400 private function get_help_for_repeaters() {
401 return array(
402 'conditional_block' => array(
403 'label' => __( 'With many conditions for the block, they are checked with the AND operator', 'jet-form-builder' ),
404 ),
405 'conditional_block_or' => array(
406 'label' => __( 'With many conditions for the block, they are checked with the OR operator', 'jet-form-builder' ),
407 ),
408 'conditional_action' => array(
409 'label' => __( 'With many conditions for the action, they are checked with the AND operator', 'jet-form-builder' ),
410 ),
411 'conditional_action_or' => array(
412 'label' => __( 'With many conditions for the action, they are checked with the OR operator', 'jet-form-builder' ),
413 ),
414 );
415 }
416
417 public function enqueue_form_assets() {
418
419 $handle = 'jet-form-builder/form';
420
421 do_action( 'jet-form-builder/other-editor-assets/before', $this, $handle );
422
423 wp_register_script(
424 $handle,
425 JET_FORM_BUILDER_URL . 'assets/js/form-block.js',
426 array(
427 'wp-editor',
428 'wp-core-data',
429 'wp-data',
430 'wp-block-library',
431 'wp-format-library',
432 'wp-api-fetch',
433 ),
434 JET_FORM_BUILDER_VERSION,
435 true
436 );
437
438 wp_register_style(
439 'jet-form-builder-others',
440 Plugin::instance()->plugin_url( 'assets/css/frontend.css' ),
441 array(),
442 Plugin::instance()->get_version()
443 );
444
445 do_action( 'jet-form-builder/other-editor-assets/after', $this, $handle );
446
447 }
448
449 }
450