PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / controllers / FrmAppController.php

FrmAppController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 3.06.06, at classes/controllers/FrmAppController.php

625 lines 18.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class FrmAppController {
4
5 public static function menu() {
6 FrmAppHelper::maybe_add_permissions();
7 if ( ! current_user_can( 'frm_view_forms' ) ) {
8 return;
9 }
10
11 $menu_name = FrmAppHelper::get_menu_name();
12 add_menu_page( 'Formidable', $menu_name, 'frm_view_forms', 'formidable', 'FrmFormsController::route', self::menu_icon(), self::get_menu_position() );
13 }
14
15 private static function get_menu_position() {
16 return apply_filters( 'frm_menu_position', '29.3' );
17 }
18
19 /**
20 * @since 3.05
21 */
22 private static function menu_icon() {
23 $icon = FrmAppHelper::svg_logo(
24 array(
25 'fill' => '#a0a5aa',
26 'orange' => '#a0a5aa',
27 )
28 );
29 $icon = 'data:image/svg+xml;base64,' . base64_encode( $icon );
30 return apply_filters( 'frm_icon', $icon );
31 }
32
33 /**
34 * @since 3.0
35 */
36 public static function add_admin_class( $classes ) {
37 if ( self::is_white_page() ) {
38 $classes .= ' frm-white-body ';
39 }
40 return $classes;
41 }
42
43 /**
44 * @since 3.0
45 */
46 private static function is_white_page() {
47 $is_white_page = ( FrmAppHelper::is_admin_page( 'formidable' ) || FrmAppHelper::is_admin_page( 'formidable-entries' ) || FrmAppHelper::is_admin_page( 'formidable-pro-upgrade' ) || FrmAppHelper::is_admin_page( 'formidable-addons' ) || FrmAppHelper::is_admin_page( 'formidable-import' ) );
48 if ( ! $is_white_page ) {
49 $screen = get_current_screen();
50 $is_white_page = ( $screen && $screen->id === 'edit-frm_display' );
51 }
52
53 return $is_white_page;
54 }
55
56 public static function load_wp_admin_style() {
57 FrmAppHelper::load_font_style();
58 }
59
60 public static function get_form_nav( $form, $show_nav = false, $title = 'show' ) {
61 $show_nav = FrmAppHelper::get_param( 'show_nav', $show_nav, 'get', 'absint' );
62 if ( empty( $show_nav ) || ! $form ) {
63 return;
64 }
65
66 FrmForm::maybe_get_form( $form );
67 if ( ! is_object( $form ) ) {
68 return;
69 }
70
71 $id = $form->id;
72 $current_page = self::get_current_page();
73 $nav_items = self::get_form_nav_items( $form );
74
75 include( FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php' );
76 }
77
78 private static function get_current_page() {
79 global $pagenow;
80
81 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
82 $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title', 'None' );
83 $current_page = isset( $_GET['page'] ) ? $page : $post_type;
84 if ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) {
85 $current_page = 'frm_display';
86 }
87
88 return $current_page;
89 }
90
91 private static function get_form_nav_items( $form ) {
92 $id = $form->parent_form_id ? $form->parent_form_id : $form->id;
93
94 $nav_items = array(
95 array(
96 'link' => admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $id ) ),
97 'label' => __( 'Build', 'formidable' ),
98 'current' => array( 'edit', 'new', 'duplicate' ),
99 'page' => 'formidable',
100 'permission' => 'frm_edit_forms',
101 ),
102 array(
103 'link' => admin_url( 'admin.php?page=formidable&frm_action=settings&id=' . absint( $id ) ),
104 'label' => __( 'Settings', 'formidable' ),
105 'current' => array( 'settings' ),
106 'page' => 'formidable',
107 'permission' => 'frm_edit_forms',
108 ),
109 array(
110 'link' => admin_url( 'admin.php?page=formidable-entries&frm_action=list&form=' . absint( $id ) ),
111 'label' => __( 'Entries', 'formidable' ),
112 'current' => array(),
113 'page' => 'formidable-entries',
114 'permission' => 'frm_view_entries',
115 ),
116 );
117
118 // Let people know reports and views exist.
119 if ( ! FrmAppHelper::pro_is_installed() ) {
120 $nav_items[] = array(
121 'link' => '',
122 'label' => __( 'Views', 'formidable' ),
123 'current' => array(),
124 'page' => '',
125 'permission' => 'frm_view_entries',
126 'atts' => array(
127 'class' => 'frm_show_upgrade frm_noallow',
128 'data-upgrade' => __( 'Views', 'formidable' ),
129 'data-medium' => 'views-nav',
130 ),
131 );
132 $nav_items[] = array(
133 'link' => '',
134 'label' => __( 'Reports', 'formidable' ),
135 'current' => array(),
136 'page' => '',
137 'permission' => 'frm_view_entries',
138 'atts' => array(
139 'class' => 'frm_show_upgrade frm_noallow',
140 'data-upgrade' => __( 'Reports', 'formidable' ),
141 'data-medium' => 'reports-nav',
142 ),
143 );
144 self::include_upgrade_overlay();
145 }
146
147 $nav_args = array(
148 'form_id' => $id,
149 'form' => $form,
150 );
151 return apply_filters( 'frm_form_nav_list', $nav_items, $nav_args );
152 }
153
154 // Adds a settings link to the plugins page
155 public static function settings_link( $links ) {
156 $settings = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable' ) ) . '">' . __( 'Build a Form', 'formidable' ) . '</a>';
157 array_unshift( $links, $settings );
158
159 return $links;
160 }
161
162 public static function pro_get_started_headline() {
163 self::maybe_show_upgrade_bar();
164 self::review_request();
165
166 // Don't display this error as we're upgrading the thing, or if the user shouldn't see the message
167 if ( 'upgrade-plugin' == FrmAppHelper::simple_get( 'action', 'sanitize_title' ) || ! current_user_can( 'update_plugins' ) ) {
168 return;
169 }
170
171 $pro_installed = is_dir( WP_PLUGIN_DIR . '/formidable-pro' );
172 $authorized = get_site_option( 'frmpro-authorized' ) && ! is_callable( 'load_formidable_pro' );
173 if ( ! $authorized ) {
174 return;
175 }
176
177 FrmAppHelper::load_admin_wide_js();
178
179 // user is authorized, but running free version
180 $download_url = '';
181 if ( $pro_installed ) {
182 // if pro version is installed, include link to activate it
183 $inst_install_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=formidable-pro/formidable-pro.php' ), 'activate-plugin_formidable-pro/formidable-pro.php' );
184 } else {
185 $inst_install_url = '#';
186 $download_url = FrmAddonsController::get_pro_download_url();
187
188 if ( empty( $download_url ) ) {
189 $inst_install_url = 'https://formidableforms.com/knowledgebase/install-formidable-forms/?utm_source=WordPress&utm_medium=get-started&utm_campaign=liteplugin';
190 }
191 }
192 ?>
193 <div class="error frm_previous_install">
194 <?php
195 echo apply_filters( // WPCS: XSS ok.
196 'frm_pro_update_msg',
197 sprintf(
198 esc_html__( 'This site has been previously authorized to run Formidable Forms. %1$sInstall Formidable Pro%2$s or %3$sdeauthorize%4$s this site to continue running the free version and remove this message.', 'formidable' ),
199 '<br/><a href="' . esc_url( $inst_install_url ) . '" id="frm_install_link" target="_blank" data-prourl="' . esc_url( $download_url ) . '">',
200 '</a>',
201 '<a href="#" class="frm_deauthorize_link">',
202 '</a>'
203 ),
204 esc_url( $inst_install_url )
205 );
206 ?>
207 <div id="frm_install_message" class="hidden frm_hidden"></div>
208 </div>
209 <?php
210 }
211
212 private static function maybe_show_upgrade_bar() {
213 if ( ! FrmAppHelper::is_formidable_admin() || FrmAppHelper::pro_is_installed() ) {
214 return;
215 }
216
217 $affiliate = FrmAppHelper::get_affiliate();
218 if ( ! empty( $affiliate ) ) {
219 $tip = FrmTipsHelper::get_banner_tip();
220 $link = FrmAppHelper::admin_upgrade_link( 'banner' );
221 ?>
222 <div class="update-nag frm-update-to-pro">
223 <?php echo FrmAppHelper::kses( $tip['tip'] ); // WPCS: XSS ok. ?>
224 <span><?php echo FrmAppHelper::kses( $tip['call'] ); // WPCS: XSS ok. ?></span>
225 <a href="<?php echo esc_url( FrmAppHelper::make_affiliate_url( $link ) ); ?>" class="button">Upgrade to Pro</a>
226 </div>
227 <?php
228 }
229 }
230
231 /**
232 * Add admin notices as needed for reviews
233 *
234 * @since 3.04.03
235 */
236 private static function review_request() {
237 $reviews = new FrmReviews();
238 $reviews->review_request();
239 }
240
241 /**
242 * Save the request to hide the review
243 *
244 * @since 3.04.03
245 */
246 public static function dismiss_review() {
247 FrmAppHelper::permission_check( 'frm_change_settings' );
248 check_ajax_referer( 'frm_ajax', 'nonce' );
249
250 $reviews = new FrmReviews();
251 $reviews->dismiss_review();
252 }
253
254 /**
255 * @since 3.04.02
256 */
257 public static function include_upgrade_overlay() {
258 wp_enqueue_script( 'jquery-ui-dialog' );
259 wp_enqueue_style( 'jquery-ui-dialog' );
260
261 add_action( 'admin_footer', 'FrmAppController::upgrade_overlay_html' );
262 }
263
264 /**
265 * @since 3.06.03
266 */
267 public static function upgrade_overlay_html() {
268 $is_pro = FrmAppHelper::pro_is_installed();
269 $upgrade_link = array(
270 'medium' => 'builder',
271 'content' => 'upgrade',
272 );
273 include( FrmAppHelper::plugin_path() . '/classes/views/shared/upgrade_overlay.php' );
274 }
275
276 /**
277 * @since 3.04.02
278 */
279 public static function remove_upsells() {
280 remove_action( 'frm_before_settings', 'FrmSettingsController::license_box' );
281 remove_action( 'frm_after_settings', 'FrmSettingsController::settings_cta' );
282 }
283
284 /**
285 * Don't nag people to install WPForms
286 *
287 * @since 3.05
288 */
289 public static function remove_wpforms_nag( $upsell ) {
290 if ( is_array( $upsell ) ) {
291 foreach ( $upsell as $k => $plugin ) {
292 if ( strpos( $plugin['slug'], 'wpforms' ) !== false ) {
293 unset( $upsell[ $k ] );
294 }
295 }
296 }
297 return $upsell;
298 }
299
300 /**
301 * If there are CURL problems on this server, wp_remote_post won't work for installing
302 * Use a javascript fallback instead.
303 *
304 * @since 2.0.3
305 */
306 public static function install_js_fallback() {
307 FrmAppHelper::load_admin_wide_js();
308 echo '<div id="hidden frm_install_message"></div><script type="text/javascript">jQuery(document).ready(function(){frm_install_now();});</script>';
309 }
310
311 /**
312 * Check if the database is outdated
313 *
314 * @since 2.0.1
315 * @return boolean
316 */
317 public static function needs_update() {
318 $needs_upgrade = self::compare_for_update(
319 array(
320 'option' => 'frm_db_version',
321 'new_db_version' => FrmAppHelper::$db_version,
322 'new_plugin_version' => FrmAppHelper::plugin_version(),
323 )
324 );
325
326 if ( ! $needs_upgrade ) {
327 $needs_upgrade = apply_filters( 'frm_db_needs_upgrade', $needs_upgrade );
328 }
329 return $needs_upgrade;
330 }
331
332 /**
333 * Check both version number and DB number for changes
334 *
335 * @since 3.0.04
336 */
337 public static function compare_for_update( $atts ) {
338 $db_version = get_option( $atts['option'] );
339
340 if ( strpos( $db_version, '-' ) === false ) {
341 $needs_upgrade = true;
342 } else {
343 $last_upgrade = explode( '-', $db_version );
344 $needs_db_upgrade = (int) $last_upgrade[1] < (int) $atts['new_db_version'];
345 $new_version = version_compare( $last_upgrade[0], $atts['new_plugin_version'], '<' );
346 $needs_upgrade = $needs_db_upgrade || $new_version;
347 }
348
349 return $needs_upgrade;
350 }
351
352 /**
353 * Check for database update and trigger js loading
354 *
355 * @since 2.0.1
356 */
357 public static function admin_init() {
358 new FrmPersonalData(); // register personal data hooks
359
360 if ( ! FrmAppHelper::doing_ajax() && self::needs_update() ) {
361 self::network_upgrade_site();
362 }
363
364 $action = FrmAppHelper::simple_get( 'action', 'sanitize_title' );
365 if ( ! FrmAppHelper::doing_ajax() || $action == 'frm_import_choices' ) {
366 // don't continue during ajax calls
367 self::admin_js();
368 }
369 }
370
371 public static function admin_js() {
372 $version = FrmAppHelper::plugin_version();
373 FrmAppHelper::load_admin_wide_js( false );
374
375 $dependecies = array(
376 'formidable_admin_global',
377 'formidable',
378 'jquery',
379 'jquery-ui-core',
380 'jquery-ui-draggable',
381 'jquery-ui-sortable',
382 'bootstrap_tooltip',
383 'bootstrap-multiselect',
384 );
385
386 if ( FrmAppHelper::is_admin_page( 'formidable-styles' ) ) {
387 $dependecies[] = 'wp-color-picker';
388 }
389
390 wp_register_script( 'formidable_admin', FrmAppHelper::plugin_url() . '/js/formidable_admin.js', $dependecies, $version, true );
391 wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css', array(), $version );
392 wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() . '/js/bootstrap.min.js', array( 'jquery' ), '3.3.4' );
393 wp_register_style( 'formidable-grids', FrmAppHelper::plugin_url() . '/css/frm_grids.css', array(), $version );
394
395 // load multselect js
396 wp_register_script( 'bootstrap-multiselect', FrmAppHelper::plugin_url() . '/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip' ), '0.9.8', true );
397
398 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
399 $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
400
401 global $pagenow;
402 if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow == 'edit.php' && $post_type == 'frm_display' ) ) {
403
404 wp_enqueue_script( 'admin-widgets' );
405 wp_enqueue_style( 'widgets' );
406 wp_enqueue_script( 'formidable' );
407 wp_enqueue_script( 'formidable_admin' );
408 FrmAppHelper::localize_script( 'admin' );
409
410 wp_enqueue_style( 'formidable-admin' );
411 if ( 'formidable-styles' !== $page ) {
412 wp_enqueue_style( 'formidable-grids' );
413 wp_enqueue_style( 'formidable-dropzone' );
414 add_thickbox();
415 } else {
416 $settings = FrmAppHelper::get_settings();
417 if ( empty( $settings->old_css ) ) {
418 wp_enqueue_style( 'formidable-grids' );
419 }
420 }
421
422 wp_register_script( 'formidable-editinplace', FrmAppHelper::plugin_url() . '/js/jquery/jquery.editinplace.packed.js', array( 'jquery' ), '2.3.0' );
423
424 do_action( 'frm_enqueue_builder_scripts' );
425 } else if ( $pagenow == 'post.php' || ( $pagenow == 'post-new.php' && $post_type == 'frm_display' ) ) {
426 if ( isset( $_REQUEST['post_type'] ) ) {
427 $post_type = sanitize_title( $_REQUEST['post_type'] );
428 } else if ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) {
429 $post = get_post( absint( $_REQUEST['post'] ) );
430 if ( ! $post ) {
431 return;
432 }
433 $post_type = $post->post_type;
434 } else {
435 return;
436 }
437
438 if ( $post_type == 'frm_display' ) {
439 wp_enqueue_script( 'jquery-ui-draggable' );
440 wp_enqueue_script( 'formidable_admin' );
441 wp_enqueue_style( 'formidable-admin' );
442 FrmAppHelper::localize_script( 'admin' );
443 }
444 } else if ( $pagenow == 'widgets.php' ) {
445 FrmAppHelper::load_admin_wide_js();
446 }
447 }
448
449 public static function load_lang() {
450 load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() . '/languages/' );
451 }
452
453 /**
454 * Check if the styles are updated when a form is loaded on the front-end
455 *
456 * @since 3.0.1
457 */
458 public static function maybe_update_styles() {
459 if ( self::needs_update() ) {
460 self::network_upgrade_site();
461 }
462 }
463
464 /**
465 * @since 3.0
466 */
467 public static function create_rest_routes() {
468 $args = array(
469 'methods' => 'GET',
470 'callback' => 'FrmAppController::api_install',
471 );
472 register_rest_route( 'frm-admin/v1', '/install', $args );
473 }
474
475 /**
476 * Run silent upgrade on each site in the network during a network upgrade.
477 * Update database settings for all sites in a network during network upgrade process.
478 *
479 * @since 2.0.1
480 *
481 * @param int $blog_id Blog ID.
482 */
483 public static function network_upgrade_site( $blog_id = 0 ) {
484
485 $request = new WP_REST_Request( 'GET', '/frm-admin/v1/install' );
486
487 if ( $blog_id ) {
488 switch_to_blog( $blog_id );
489 $response = rest_do_request( $request );
490 restore_current_blog();
491 } else {
492 $response = rest_do_request( $request );
493 }
494
495 if ( $response->is_error() ) {
496 // if the remove post fails, use javascript instead
497 add_action( 'admin_notices', 'FrmAppController::install_js_fallback' );
498 }
499 }
500
501 /**
502 * @since 3.0
503 */
504 public static function api_install() {
505 if ( self::needs_update() ) {
506 $running = get_option( 'frm_install_running' );
507 if ( false === $running || $running < strtotime( '-5 minutes' ) ) {
508 update_option( 'frm_install_running', time(), 'no' );
509 self::install();
510 delete_option( 'frm_install_running' );
511 }
512 }
513 return true;
514 }
515
516 /**
517 * Silent database upgrade (no redirect).
518 * Called via ajax request during network upgrade process.
519 *
520 * @since 2.0.1
521 */
522 public static function ajax_install() {
523 self::api_install();
524 wp_die();
525 }
526
527 public static function install() {
528 $frmdb = new FrmMigrate();
529 $frmdb->upgrade();
530 }
531
532 public static function uninstall() {
533 FrmAppHelper::permission_check( 'administrator' );
534 check_ajax_referer( 'frm_ajax', 'nonce' );
535
536 $frmdb = new FrmMigrate();
537 $frmdb->uninstall();
538
539 //disable the plugin and redirect after uninstall so the tables don't get added right back
540 deactivate_plugins( FrmAppHelper::plugin_folder() . '/formidable.php', false, false );
541 echo esc_url_raw( admin_url( 'plugins.php?deactivate=true' ) );
542
543 wp_die();
544 }
545
546 public static function drop_tables( $tables ) {
547 global $wpdb;
548 $tables[] = $wpdb->prefix . 'frm_fields';
549 $tables[] = $wpdb->prefix . 'frm_forms';
550 $tables[] = $wpdb->prefix . 'frm_items';
551 $tables[] = $wpdb->prefix . 'frm_item_metas';
552 return $tables;
553 }
554
555 public static function deauthorize() {
556 FrmAppHelper::permission_check( 'frm_change_settings' );
557 check_ajax_referer( 'frm_ajax', 'nonce' );
558
559 delete_option( 'frmpro-credentials' );
560 delete_option( 'frmpro-authorized' );
561 delete_site_option( 'frmpro-credentials' );
562 delete_site_option( 'frmpro-authorized' );
563 wp_die();
564 }
565
566 public static function set_footer_text( $text ) {
567 if ( FrmAppHelper::is_formidable_admin() ) {
568 $link = FrmAppHelper::admin_upgrade_link( 'footer' );
569 $text = sprintf(
570 __( 'Help us spread the %1$sFormidable Forms%2$s love with %3$s %5$s on WordPress.org%4$s. Thank you heaps!', 'formidable' ),
571 '<a href="' . esc_url( FrmAppHelper::make_affiliate_url( $link ) ) . '" target="_blank">',
572 '</a>',
573 '<a href="https://wordpress.org/support/plugin/formidable/reviews/?filter=5#new-post" target="_blank">',
574 '</a>',
575 '&#9733;&#9733;&#9733;&#9733;&#9733;'
576 );
577 $text = '<span id="footer-thankyou">' . $text . '</span>';
578 }
579 return $text;
580 }
581
582 /**
583 * @deprecated 1.07.05
584 * @codeCoverageIgnore
585 */
586 public static function get_form_shortcode( $atts ) {
587 return FrmDeprecated::get_form_shortcode( $atts );
588 }
589
590 /**
591 * @deprecated 2.5.4
592 * @codeCoverageIgnore
593 */
594 public static function widget_text_filter( $content ) {
595 return FrmDeprecated::widget_text_filter( $content );
596 }
597
598 /**
599 * Deprecated in favor of wpmu_upgrade_site
600 *
601 * @deprecated 2.3
602 * @codeCoverageIgnore
603 */
604 public static function front_head() {
605 FrmDeprecated::front_head();
606 }
607
608
609 /**
610 * @deprecated 3.0.04
611 * @codeCoverageIgnore
612 */
613 public static function activation_install() {
614 FrmDeprecated::activation_install();
615 }
616
617 /**
618 * @deprecated 3.0
619 * @codeCoverageIgnore
620 */
621 public static function page_route( $content ) {
622 return FrmDeprecated::page_route( $content );
623 }
624 }
625