PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.6
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.6
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 / FrmAddonsController.php

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

1,491 lines 39.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmAddonsController {
7
8 /**
9 * @var string $plugin
10 */
11 protected static $plugin;
12
13 /**
14 * @return void
15 */
16 public static function menu() {
17 if ( ! current_user_can( 'activate_plugins' ) ) {
18 return;
19 }
20
21 $label = __( 'Add-Ons', 'formidable' );
22 $label = '<span style="color:#1da867">' . $label . '</span>';
23
24 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' );
25
26 if ( ! FrmAppHelper::pro_is_installed() ) {
27 add_submenu_page(
28 'formidable',
29 'Formidable | ' . __( 'Upgrade', 'formidable' ),
30 '<span class="frm-upgrade-submenu">' . __( 'Upgrade', 'formidable' ) . '</span>',
31 'frm_view_forms',
32 'formidable-pro-upgrade',
33 'FrmAddonsController::upgrade_to_pro'
34 );
35 } elseif ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) ) {
36 wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) );
37 exit;
38 }
39 }
40
41 /**
42 * @return void
43 */
44 public static function list_addons() {
45 FrmAppHelper::include_svg();
46 $installed_addons = apply_filters( 'frm_installed_addons', array() );
47 $license_type = '';
48
49 $addons = self::get_api_addons();
50 $errors = array();
51
52 if ( isset( $addons['error'] ) ) {
53 $api = new FrmFormApi();
54 $errors = $api->get_error_from_response( $addons );
55 $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : '';
56 unset( $addons['error'] );
57 }
58
59 $pro = array(
60 'pro' => array(
61 'title' => 'Formidable Forms Pro',
62 'slug' => 'formidable-pro',
63 'released' => '2011-02-05',
64 'docs' => 'knowledgebase/',
65 'excerpt' => 'Create calculators, surveys, smart forms, and data-driven applications. Build directories, real estate listings, job boards, and much more.',
66 ),
67 );
68 $addons = $pro + $addons;
69 self::prepare_addons( $addons );
70
71 $pricing = FrmAppHelper::admin_upgrade_link( 'addons' );
72
73 include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' );
74 }
75
76 /**
77 * @return void
78 */
79 public static function license_settings() {
80 $plugins = apply_filters( 'frm_installed_addons', array() );
81 if ( empty( $plugins ) ) {
82 esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
83
84 return;
85 }
86
87 ksort( $plugins );
88
89 include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' );
90 }
91
92 /**
93 * @return array
94 */
95 protected static function get_api_addons() {
96 $api = new FrmFormApi();
97 $addons = $api->get_api_info();
98
99 if ( empty( $addons ) ) {
100 $addons = self::fallback_plugin_list();
101 } else {
102 foreach ( $addons as $k => $addon ) {
103 if ( empty( $addon['excerpt'] ) && $k !== 'error' ) {
104 unset( $addons[ $k ] );
105 }
106 }
107 }
108
109 return $addons;
110 }
111
112 /**
113 * If the API is unable to connect, show something on the addons page
114 *
115 * @since 3.04.03
116 * @return array
117 */
118 protected static function fallback_plugin_list() {
119 $list = array(
120 'formidable-pro' => array(
121 'title' => 'Formidable Forms Pro',
122 'link' => 'pricing/',
123 'docs' => '',
124 'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.',
125 ),
126 'mailchimp' => array(
127 'title' => 'Mailchimp Forms',
128 'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a Mailchimp mailing list when they submit forms and update their information along with the entry.',
129 ),
130 'registration' => array(
131 'title' => 'User Registration Forms',
132 'link' => 'downloads/user-registration/',
133 'excerpt' => 'Give new users access to your site as quickly and painlessly as possible. Allow users to register, edit and be able to login to their profiles on your site from the front end in a clean, customized registration form.',
134 ),
135 'paypal' => array(
136 'title' => 'PayPal Standard Forms',
137 'link' => 'downloads/paypal-standard/',
138 'excerpt' => 'Automate your business by collecting instant payments from your clients. Collect information, calculate a total, and send them on to PayPal. Require a payment before publishing content on your site.',
139 ),
140 'stripe' => array(
141 'title' => 'Stripe Forms',
142 'docs' => 'knowledgebase/stripe/',
143 'excerpt' => 'Any Formidable forms on your site can accept credit card payments without users ever leaving your site.',
144 ),
145 'authorize-net' => array(
146 'title' => 'Authorize.net AIM Forms',
147 'link' => 'downloads/authorize-net-aim/',
148 'docs' => 'knowledgebase/authorize-net-aim/',
149 'excerpt' => 'Accept one-time payments directly on your site, using Authorize.net AIM.',
150 ),
151 'woocommerce' => array(
152 'title' => 'WooCommerce Forms',
153 'excerpt' => 'Use a Formidable form on your WooCommerce product pages.',
154 ),
155 'autoresponder' => array(
156 'title' => 'Form Action Automation',
157 'docs' => 'knowledgebase/schedule-autoresponder/',
158 'excerpt' => 'Schedule email notifications, SMS messages, and API actions.',
159 ),
160 'modal' => array(
161 'title' => 'Bootstrap Modal Forms',
162 'link' => 'downloads/bootstrap-modal/',
163 'docs' => 'knowledgebase/bootstrap-modal/',
164 'excerpt' => 'Open a view or form in a Bootstrap popup.',
165 ),
166 'bootstrap' => array(
167 'title' => 'Bootstrap Style Forms',
168 'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.',
169 ),
170 'zapier' => array(
171 'title' => 'Zapier Forms',
172 'excerpt' => 'Connect with hundreds of different applications through Zapier. Insert a new row in a Google docs spreadsheet, post on Twitter, or add a new Dropbox file with your form.',
173 ),
174 'signature' => array(
175 'title' => 'Digital Signature Forms',
176 'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.',
177 ),
178 'api' => array(
179 'title' => 'Formidable Forms API',
180 'link' => 'downloads/formidable-api/',
181 'excerpt' => 'Send entry results to any other site that has a Rest API. This includes the option of sending entries from one Formidable site to another.',
182 ),
183 'twilio' => array(
184 'title' => 'Twilio SMS Forms',
185 'docs' => 'knowledgebase/twilio-add-on/',
186 'excerpt' => 'Allow users to text their votes for polls created by Formidable Forms, or send SMS notifications when entries are submitted or updated.',
187 ),
188 'views' => array(
189 'title' => 'Formidable Views',
190 'excerpt' => 'Add the power of views to your Formidable Forms to display your form submissions in listings, tables, calendars, and more.',
191 ),
192 'quiz_maker' => array(
193 'title' => 'Quiz Maker',
194 'link' => 'downloads/quiz-maker/',
195 'excerpt' => 'Make quizzes, automatically score them and show user scores.',
196 ),
197 );
198
199 $defaults = array(
200 'released' => '',
201 );
202
203 foreach ( $list as $k => $info ) {
204 $info['slug'] = $k;
205 $list[ $k ] = array_merge( $defaults, $info );
206 }
207 return $list;
208 }
209
210 /**
211 * If Pro is missing but has been authenticated, include a download URL
212 *
213 * @since 3.04.03
214 * @return string
215 */
216 public static function get_pro_download_url() {
217 $license = self::get_pro_license();
218 $api = new FrmFormApi( $license );
219 $downloads = $api->get_api_info();
220 $pro = self::get_pro_from_addons( $downloads );
221
222 return isset( $pro['url'] ) ? $pro['url'] : '';
223 }
224
225 /**
226 * @since 4.08
227 */
228 public static function get_pro_license() {
229 $pro_cred_store = 'frmpro-credentials';
230 $pro_wpmu_store = 'frmpro-wpmu-sitewide';
231 if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) {
232 $creds = get_site_option( $pro_cred_store );
233 } else {
234 $creds = get_option( $pro_cred_store );
235 }
236
237 if ( empty( $creds ) || ! is_array( $creds ) || ! isset( $creds['license'] ) ) {
238 return '';
239 }
240
241 $license = $creds['license'];
242 if ( empty( $license ) ) {
243 return '';
244 }
245
246 if ( strpos( $license, '-' ) ) {
247 // this is a fix for licenses saved in the past
248 $license = strtoupper( $license );
249 }
250 return $license;
251 }
252
253 /**
254 * @since 4.08
255 *
256 * @param array $addons
257 * @return array
258 */
259 protected static function get_pro_from_addons( $addons ) {
260 return isset( $addons['93790'] ) ? $addons['93790'] : array();
261 }
262
263 /**
264 * @since 4.06
265 */
266 public static function license_type() {
267 if ( is_callable( 'FrmProAddonsController::license_type' ) ) {
268 return FrmProAddonsController::license_type();
269 }
270
271 return 'free';
272 }
273
274 /**
275 * @since 4.0.01
276 */
277 public static function is_license_expired() {
278 $version_info = self::get_primary_license_info();
279 if ( ! isset( $version_info['error'] ) ) {
280 return false;
281 }
282
283 return $version_info['error'];
284 }
285
286 /**
287 * @since 4.08
288 *
289 * @return boolean|int false or the number of days until expiration.
290 */
291 public static function is_license_expiring() {
292 if ( is_callable( 'FrmProAddonsController::is_license_expiring' ) ) {
293 return FrmProAddonsController::is_license_expiring();
294 }
295
296 return false;
297 }
298
299 /**
300 * @since 4.08
301 *
302 * @return array|false
303 */
304 protected static function get_primary_license_info() {
305 $installed_addons = apply_filters( 'frm_installed_addons', array() );
306 if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) {
307 return false;
308 }
309 $installed_addons = array(
310 'formidable_pro' => $installed_addons['formidable_pro'],
311 );
312
313 return self::fill_update_addon_info( $installed_addons );
314 }
315
316 /**
317 * @since 3.04.03
318 */
319 public static function check_update( $transient ) {
320 if ( ! FrmAppHelper::pro_is_installed() ) {
321 // Don't make any changes if only Lite is installed.
322 return $transient;
323 }
324
325 if ( ! is_object( $transient ) ) {
326 $transient = new stdClass();
327 }
328
329 $installed_addons = apply_filters( 'frm_installed_addons', array() );
330 if ( empty( $installed_addons ) ) {
331 return $transient;
332 }
333
334 $version_info = self::fill_update_addon_info( $installed_addons );
335 $transient->last_checked = time();
336 $wp_plugins = self::get_plugins();
337
338 foreach ( $version_info as $id => $plugin ) {
339 $plugin = (object) $plugin;
340
341 if ( ! isset( $plugin->new_version ) || ! isset( $plugin->package ) ) {
342 continue;
343 }
344
345 $folder = $plugin->plugin;
346 if ( empty( $folder ) ) {
347 continue;
348 }
349
350 if ( ! self::is_installed( $folder ) ) {
351 // don't show an update if the plugin isn't installed
352 continue;
353 }
354
355 $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array();
356 $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0';
357 $plugin->slug = explode( '/', $folder )[0];
358
359 if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) {
360 $transient->response[ $folder ] = $plugin;
361 } else {
362 $transient->no_update[ $folder ] = $plugin;
363 }
364
365 $transient->checked[ $folder ] = $wp_version;
366
367 }
368
369 return $transient;
370 }
371
372 /**
373 * Copy of FrmAppHelper::get_plugins.
374 * Because this gets called on "pre_set_site_transient_update_plugins" an old version of FrmAppHelper may be loaded on plugin update.
375 * This means that trying to access FrmAppHelper::get_plugins when upgrading from a Lite version before v5.5 results in a one-off error.
376 *
377 * @since 5.5.2
378 * @return array
379 */
380 protected static function get_plugins() {
381 if ( ! function_exists( 'get_plugins' ) ) {
382 require_once ABSPATH . 'wp-admin/includes/plugin.php';
383 }
384 return get_plugins();
385 }
386
387 /**
388 * Check if a plugin is installed before showing an update for it
389 *
390 * @since 3.05
391 *
392 * @param string $plugin - the folder/filename.php for a plugin
393 *
394 * @return bool - True if installed
395 */
396 protected static function is_installed( $plugin ) {
397 $all_plugins = self::get_plugins();
398 return isset( $all_plugins[ $plugin ] );
399 }
400
401 /**
402 * @since 3.04.03
403 *
404 * @param array $installed_addons
405 *
406 * @return array
407 */
408 protected static function fill_update_addon_info( $installed_addons ) {
409 $checked_licenses = array();
410 $version_info = array();
411
412 foreach ( $installed_addons as $addon ) {
413 if ( $addon->store_url !== 'https://formidableforms.com' ) {
414 // check if this is a third-party addon
415 continue;
416 }
417
418 $new_license = $addon->license;
419 if ( empty( $new_license ) || in_array( $new_license, $checked_licenses ) ) {
420 continue;
421 }
422
423 $checked_licenses[] = $new_license;
424
425 $api = new FrmFormApi( $new_license );
426 if ( empty( $version_info ) ) {
427 $version_info = $api->get_api_info();
428 continue;
429 }
430
431 $plugin = $api->get_addon_for_license( $addon, $version_info );
432 if ( empty( $plugin ) ) {
433 continue;
434 }
435
436 $download_id = isset( $plugin['id'] ) ? $plugin['id'] : 0;
437 if ( ! empty( $download_id ) && ! isset( $version_info[ $download_id ]['package'] ) ) {
438 // if this addon is using its own license, get the update url
439 $addon_info = $api->get_api_info();
440
441 $version_info[ $download_id ] = $addon_info[ $download_id ];
442 if ( isset( $addon_info['error'] ) ) {
443 $version_info[ $download_id ]['error'] = array(
444 'message' => $addon_info['error']['message'],
445 'code' => $addon_info['error']['code'],
446 );
447 }
448 }
449 }
450
451 return $version_info;
452 }
453
454 /**
455 * Get the action link for an addon that isn't active.
456 *
457 * @since 3.06.03
458 * @param string $plugin The plugin slug
459 * @return array
460 */
461 public static function install_link( $plugin ) {
462 $link = array();
463 $addon = self::get_addon( $plugin );
464
465 if ( $addon ) {
466 if ( $addon['status']['type'] === 'installed' && ! empty( $addon['activate_url'] ) ) {
467 $link = array(
468 'url' => $addon['plugin'],
469 'class' => 'frm-activate-addon',
470 );
471 } elseif ( isset( $addon['url'] ) && ! empty( $addon['url'] ) ) {
472 $link = array(
473 'url' => $addon['url'],
474 'class' => 'frm-install-addon',
475 );
476 } elseif ( isset( $addon['categories'] ) && ! empty( $addon['categories'] ) ) {
477 $link = array(
478 'categories' => $addon['categories'],
479 );
480 }
481
482 if ( ! empty( $link ) ) {
483 $link['status'] = $addon['status']['type'];
484 }
485 } elseif ( current_user_can( 'activate_plugins' ) && self::is_installed( 'formidable-' . $plugin . '/formidable-' . $plugin . '.php' ) ) {
486 $link = array(
487 'url' => 'formidable-' . $plugin . '/formidable-' . $plugin . '.php',
488 'class' => 'frm-activate-addon',
489 );
490 }
491
492 return $link;
493 }
494
495 /**
496 * @since 4.09
497 * @param string $plugin The plugin slug
498 * @return array|false
499 */
500 protected static function get_addon( $plugin ) {
501 $addons = self::get_api_addons();
502 self::prepare_addons( $addons );
503 foreach ( $addons as $addon ) {
504 $slug = explode( '/', $addon['plugin'] );
505 if ( $slug[0] === 'formidable-' . $plugin ) {
506 return $addon;
507 }
508 }
509 return false;
510 }
511
512 /**
513 * @since 4.09
514 * @return string
515 */
516 protected static function get_license_type() {
517 $license_type = '';
518 $addons = self::get_api_addons();
519 if ( isset( $addons['error'] ) && isset( $addons['error']['type'] ) ) {
520 $license_type = $addons['error']['type'];
521 }
522 return $license_type;
523 }
524
525 /**
526 * @since 3.04.03
527 *
528 * @param array $addons
529 * @param object $license The FrmAddon object
530 *
531 * @return array
532 */
533 public static function get_addon_for_license( $addons, $license ) {
534 $download_id = $license->download_id;
535 $plugin = array();
536 if ( empty( $download_id ) && ! empty( $addons ) ) {
537 foreach ( $addons as $addon ) {
538 if ( strtolower( $license->plugin_name ) == strtolower( $addon['title'] ) ) {
539 return $addon;
540 }
541 }
542 } elseif ( isset( $addons[ $download_id ] ) ) {
543 $plugin = $addons[ $download_id ];
544 }
545
546 return $plugin;
547 }
548
549 /**
550 * @return void
551 */
552 protected static function prepare_addons( &$addons ) {
553 $activate_url = '';
554 if ( current_user_can( 'activate_plugins' ) ) {
555 $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) );
556 }
557
558 $loop_addons = $addons;
559 foreach ( $loop_addons as $id => $addon ) {
560 if ( is_numeric( $id ) ) {
561 $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] );
562 $file_name = $addon['plugin'];
563 } else {
564 $slug = $id;
565 if ( isset( $addon['file'] ) ) {
566 $base_file = $addon['file'];
567 } else {
568 $base_file = 'formidable-' . $slug;
569 }
570 $file_name = $base_file . '/' . $base_file . '.php';
571 if ( ! isset( $addon['plugin'] ) ) {
572 $addon['plugin'] = $file_name;
573 }
574 }
575
576 $addon['installed'] = self::is_installed( $file_name );
577 if ( $addon['installed'] && 'formidable-views/formidable-views.php' === $file_name ) {
578 $active_views_version = self::get_active_views_version();
579 if ( false !== $active_views_version && $slug !== $active_views_version ) {
580 $addon['installed'] = false;
581 }
582 }
583
584 $addon['activate_url'] = '';
585
586 if ( $addon['installed'] && ! empty( $activate_url ) && ! self::is_plugin_active( $file_name, $slug ) ) {
587 $addon['activate_url'] = add_query_arg(
588 array(
589 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ),
590 'plugin' => $file_name,
591 ),
592 $activate_url
593 );
594 }
595
596 if ( ! isset( $addon['docs'] ) ) {
597 $addon['docs'] = 'knowledgebase/formidable-' . $slug . '/';
598 }
599 self::prepare_addon_link( $addon['docs'] );
600
601 if ( ! isset( $addon['link'] ) ) {
602 $addon['link'] = 'downloads/' . $slug . '/';
603 }
604 self::prepare_addon_link( $addon['link'] );
605
606 self::set_addon_status( $addon );
607 $addons[ $id ] = $addon;
608 }
609 }
610
611 /**
612 * @return bool
613 */
614 private static function is_plugin_active( $file_name, $slug ) {
615 if ( 'formidable-views/formidable-views.php' === $file_name ) {
616 return self::get_active_views_version() === $slug;
617 }
618 return is_plugin_active( $file_name );
619 }
620
621 /**
622 * @return string|false either 'visual-views' or 'views', false if one is not found.
623 */
624 private static function get_active_views_version() {
625 if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) {
626 return false;
627 }
628 $plugin_version = FrmViewsAppHelper::plugin_version();
629 return version_compare( $plugin_version, '5.0', '>=' ) ? 'visual-views' : 'views';
630 }
631
632 /**
633 * @since 3.04.02
634 *
635 * @return void
636 */
637 protected static function prepare_addon_link( &$link ) {
638 $site_url = 'https://formidableforms.com/';
639 if ( strpos( $link, 'http' ) !== 0 ) {
640 $link = $site_url . $link;
641 }
642 $link = FrmAppHelper::make_affiliate_url( $link );
643 $query_args = array(
644 'utm_source' => 'WordPress',
645 'utm_medium' => 'addons',
646 'utm_campaign' => 'liteplugin',
647 );
648 $link = add_query_arg( $query_args, $link );
649 }
650
651 /**
652 * Add the status to the addon array. Status options are:
653 * installed, active, not installed
654 *
655 * @since 3.04.02
656 *
657 * @return void
658 */
659 protected static function set_addon_status( &$addon ) {
660 if ( ! empty( $addon['activate_url'] ) ) {
661 $addon['status'] = array(
662 'type' => 'installed',
663 'label' => __( 'Installed', 'formidable' ),
664 );
665 } elseif ( $addon['installed'] ) {
666 $addon['status'] = array(
667 'type' => 'active',
668 'label' => __( 'Active', 'formidable' ),
669 );
670 } else {
671 $addon['status'] = array(
672 'type' => 'not-installed',
673 'label' => __( 'Not Installed', 'formidable' ),
674 );
675 }
676 }
677
678 /**
679 * @return void
680 */
681 public static function upgrade_to_pro() {
682 FrmAppHelper::include_svg();
683
684 $link_parts = array(
685 'medium' => 'upgrade',
686 'content' => 'button',
687 );
688
689 $features = array(
690 'Display Entries' => array(
691 array(
692 'label' => 'Display form data with virtually limitless views',
693 'link' => array(
694 'content' => 'views',
695 'param' => 'views-display-form-data',
696 ),
697 'lite' => false,
698 ),
699 array(
700 'label' => 'Generate graphs and stats based on your submitted data',
701 'link' => array(
702 'content' => 'graphs',
703 'param' => 'statistics-graphs-wordpress-forms',
704 ),
705 'lite' => false,
706 ),
707 ),
708 'Entry Management' => array(
709 array(
710 'label' => 'Import entries from a CSV',
711 'link' => array(
712 'content' => 'import-entries',
713 'param' => 'importing-exporting-wordpress-forms',
714 ),
715 'lite' => false,
716 ),
717 array(
718 'label' => 'Logged-in users can save drafts and return later',
719 'link' => array(
720 'content' => 'save-drafts',
721 'param' => 'save-drafts-wordpress-form',
722 ),
723 'lite' => false,
724 ),
725 array(
726 'label' => 'Flexibly and powerfully view, edit, and delete entries from anywhere on your site',
727 'link' => array(
728 'content' => 'front-edit',
729 'param' => 'wordpress-front-end-editing',
730 ),
731 'lite' => false,
732 ),
733 array(
734 'label' => 'View form submissions from the back-end',
735 'lite' => true,
736 ),
737 array(
738 'label' => 'Export your entries to a CSV',
739 'lite' => true,
740 ),
741 ),
742 'Form Building' => array(
743 array(
744 'label' => 'Save a calculated value into a field',
745 'link' => array(
746 'content' => 'calculations',
747 'param' => 'field-calculations-wordpress-form',
748 ),
749 'lite' => false,
750 ),
751 array(
752 'label' => 'Allow multiple file uploads',
753 'link' => array(
754 'content' => 'file-uploads',
755 'param' => 'wordpress-multi-file-upload-fields',
756 ),
757 'lite' => false,
758 ),
759 array(
760 'label' => 'Repeat sections of fields',
761 'link' => array(
762 'content' => 'repeaters',
763 'param' => 'repeatable-sections-forms',
764 ),
765 'lite' => false,
766 ),
767 array(
768 'label' => 'Hide and show fields conditionally based on other fields or the user\'s role',
769 'link' => array(
770 'content' => 'conditional-logic',
771 'param' => 'conditional-logic-wordpress-forms',
772 ),
773 'lite' => false,
774 ),
775 array(
776 'label' => 'Confirmation fields',
777 'link' => array(
778 'content' => 'confirmation-fields',
779 'param' => 'confirmation-fields-wordpress-forms',
780 ),
781 'lite' => false,
782 ),
783 array(
784 'label' => 'Multi-paged forms',
785 'link' => array(
786 'content' => 'page-breaks',
787 'param' => 'wordpress-multi-page-forms',
788 ),
789 'lite' => false,
790 ),
791 array(
792 'label' => 'Include section headings, page breaks, rich text, dates, times, scales, star ratings, sliders, toggles, dynamic fields populated from other forms, passwords, and tags in advanced forms.',
793 'lite' => false,
794 ),
795 array(
796 'label' => 'Include text, email, url, paragraph text, radio, checkbox, dropdown fields, hidden fields, user ID fields, and HTML blocks in your form.',
797 'lite' => true,
798 ),
799 array(
800 'label' => 'Drag & Drop Form building',
801 'link' => array(
802 'content' => 'drag-drop',
803 'param' => 'drag-drop-forms',
804 ),
805 'lite' => true,
806 ),
807 array(
808 'label' => 'Create forms from Templates',
809 'link' => array(
810 'content' => 'form-templates',
811 'param' => 'wordpress-form-templates',
812 ),
813 'lite' => true,
814 ),
815 array(
816 'label' => 'Import and export forms with XML',
817 'link' => array(
818 'content' => 'import',
819 'param' => 'importing-exporting-wordpress-forms',
820 ),
821 'lite' => true,
822 ),
823 array(
824 'label' => 'Use input placeholder text in your fields that clear when typing starts.',
825 'lite' => true,
826 ),
827 ),
828 'Form Actions' => array(
829 array(
830 'label' => 'Conditionally send your email notifications based on values in your form',
831 'link' => array(
832 'content' => 'conditional-emails',
833 ),
834 'lite' => false,
835 ),
836 array(
837 'label' => 'Create and edit WordPress posts or custom posts from the front-end',
838 'link' => array(
839 'content' => 'create-posts',
840 'param' => 'create-posts-pages-wordpress-forms',
841 ),
842 'lite' => false,
843 ),
844 array(
845 'label' => 'Send multiple emails and autoresponders',
846 'link' => array(
847 'content' => 'multiple-emails',
848 'param' => 'virtually-unlimited-emails',
849 ),
850 'lite' => true,
851 ),
852 ),
853 'Form Appearance' => array(
854 array(
855 'label' => 'Create Multiple styles for different forms',
856 'link' => array(
857 'content' => 'multiple-styles',
858 'param' => 'wordpress-visual-form-styler',
859 ),
860 'lite' => false,
861 ),
862 array(
863 'label' => 'Customizable layout with CSS classes',
864 'link' => array(
865 'content' => 'form-layout',
866 'param' => 'wordpress-mobile-friendly-forms',
867 ),
868 'lite' => true,
869 ),
870 array(
871 'label' => 'Customize the HTML for your forms',
872 'link' => array(
873 'content' => 'custom-html',
874 'param' => 'customizable-html-wordpress-form',
875 ),
876 'lite' => true,
877 ),
878 array(
879 'label' => 'Style your form with the Visual Form Styler',
880 'lite' => true,
881 ),
882 ),
883 );
884
885 include( FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php' );
886 }
887
888 /**
889 * Install Pro after connection with Formidable.
890 *
891 * @since 4.02.05
892 *
893 * @return void
894 */
895 public static function connect_pro() {
896 FrmAppHelper::permission_check( 'install_plugins' );
897 check_ajax_referer( 'frm_ajax', 'nonce' );
898
899 $url = self::get_current_plugin();
900 if ( FrmAppHelper::pro_is_installed() || empty( $url ) ) {
901 wp_die();
902 }
903
904 $response = array();
905
906 // It's already installed and active.
907 $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
908 if ( is_wp_error( $active ) ) {
909 // The plugin was installed, but not active. Download it now.
910 self::ajax_install_addon();
911 } else {
912 $response['active'] = true;
913 $response['success'] = true;
914 }
915
916 echo json_encode( $response );
917 wp_die();
918 }
919
920 /**
921 * @since 5.5.2
922 *
923 * @param string $plugin
924 * @param string $redirect
925 * @param bool $network_wide
926 * @param bool $silent
927 * @return null|WP_Error Null on success, WP_Error on invalid file.
928 */
929 protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
930 if ( ! function_exists( 'activate_plugin' ) ) {
931 require_once ABSPATH . 'wp-admin/includes/plugin.php';
932 }
933 return activate_plugin( $plugin, $redirect, $network_wide, $silent );
934 }
935
936 /**
937 * @since 5.0.10
938 *
939 * @return string
940 */
941 protected static function get_current_plugin() {
942 if ( ! isset( self::$plugin ) ) {
943 self::$plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' );
944 }
945 return self::$plugin;
946 }
947
948 /**
949 * @since 4.08
950 */
951 protected static function download_and_activate() {
952 if ( is_admin() ) {
953 FrmAppHelper::set_current_screen_and_hook_suffix();
954 }
955
956 self::maybe_show_cred_form();
957
958 $installed = self::install_addon();
959 if ( is_array( $installed ) && isset( $installed['message'] ) ) {
960 return $installed;
961 }
962 self::maybe_activate_addon( $installed );
963 }
964
965 /**
966 * @since 3.04.02
967 *
968 * @return void
969 */
970 protected static function maybe_show_cred_form() {
971 if ( ! function_exists( 'request_filesystem_credentials' ) ) {
972 include_once( ABSPATH . 'wp-admin/includes/file.php' );
973 }
974
975 // Start output bufferring to catch the filesystem form if credentials are needed.
976 ob_start();
977
978 $show_form = false;
979 $method = '';
980 $url = add_query_arg( array( 'page' => 'formidable-settings' ), admin_url( 'admin.php' ) );
981 $url = esc_url_raw( $url );
982 $creds = request_filesystem_credentials( $url, $method, false, false, null );
983
984 if ( false === $creds ) {
985 $show_form = true;
986 } elseif ( ! WP_Filesystem( $creds ) ) {
987 request_filesystem_credentials( $url, $method, true, false, null );
988 $show_form = true;
989 }
990
991 if ( $show_form ) {
992 $form = ob_get_clean();
993 $message = __( 'Sorry, your site requires FTP authentication. Please download plugins from FormidableForms.com and install them manually.', 'formidable' );
994 $data = $form;
995 $response = array(
996 'success' => false,
997 'message' => $message,
998 'form' => $form,
999 );
1000 wp_send_json( $response );
1001 }
1002
1003 ob_end_clean();
1004 }
1005
1006 /**
1007 * Checks if an addon download url is allowed.
1008 *
1009 * @since 6.2
1010 *
1011 * @param string $download_url
1012 *
1013 * @return bool
1014 */
1015 public static function url_is_allowed( $download_url ) {
1016 return (
1017 FrmAppHelper::validate_url_is_in_s3_bucket( $download_url, 'zip' ) || in_array( $download_url, self::allowed_external_urls(), true )
1018 );
1019 }
1020
1021 /**
1022 * We do not need any extra credentials if we have gotten this far,
1023 * so let's install the plugin.
1024 *
1025 * @since 3.04.02
1026 */
1027 protected static function install_addon() {
1028 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1029
1030 $download_url = self::get_current_plugin();
1031
1032 if ( ! self::url_is_allowed( $download_url ) ) {
1033 return array(
1034 'message' => 'Plugin URL is not valid',
1035 'success' => false,
1036 );
1037 }
1038
1039 // Create the plugin upgrader with our custom skin.
1040 $installer = new Plugin_Upgrader( new FrmInstallerSkin() );
1041 $installer->install( $download_url );
1042
1043 // Flush the cache and return the newly installed plugin basename.
1044 wp_cache_flush();
1045
1046 $plugin = $installer->plugin_info();
1047 if ( ! $plugin ) {
1048 return array(
1049 'message' => 'Plugin was not installed. ' . $installer->result,
1050 'success' => false,
1051 );
1052 }
1053 return $plugin;
1054 }
1055
1056 /**
1057 * @since 3.06.03
1058 *
1059 * @return void
1060 */
1061 public static function ajax_activate_addon() {
1062
1063 self::install_addon_permissions();
1064
1065 FrmAppHelper::set_current_screen_and_hook_suffix();
1066
1067 $plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
1068 self::maybe_activate_addon( $plugin );
1069
1070 echo json_encode( self::get_addon_activation_response() );
1071 wp_die();
1072 }
1073
1074 /**
1075 * @return array
1076 */
1077 private static function get_addon_activation_response() {
1078 $activating_page = self::get_activating_page();
1079
1080 $message = $activating_page ? __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ) : __( 'Your plugin has been activated.', 'formidable' );
1081
1082 $response = array(
1083 'message' => $message,
1084 'saveAndReload' => $activating_page,
1085 );
1086
1087 return $response;
1088 }
1089
1090 /**
1091 * Return a string that reflects the page from which the addon is being activated on,
1092 * if it is from settings or form builder, otherwise return empty string.
1093 *
1094 * @return string
1095 */
1096 private static function get_activating_page() {
1097 $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1098 if ( false !== strpos( $referer, 'frm_action=settings' ) ) {
1099 return 'settings';
1100 }
1101
1102 if ( false !== strpos( $referer, 'frm_action=edit' ) ) {
1103 return 'form_builder';
1104 }
1105
1106 return '';
1107 }
1108
1109 /**
1110 * @since 3.04.02
1111 *
1112 * @param string $installed The plugin folder name with file name
1113 */
1114 protected static function maybe_activate_addon( $installed ) {
1115 if ( ! $installed ) {
1116 return;
1117 }
1118
1119 $activate = self::activate_plugin( $installed );
1120 if ( is_wp_error( $activate ) ) {
1121 // Ignore the invalid header message that shows with nested plugins.
1122 if ( $activate->get_error_code() !== 'no_plugin_header' ) {
1123 if ( wp_doing_ajax() ) {
1124 echo json_encode( array( 'error' => $activate->get_error_message() ) );
1125 wp_die();
1126 }
1127 return array(
1128 'message' => $activate->get_error_message(),
1129 'success' => false,
1130 );
1131 }
1132 }
1133 }
1134
1135 /**
1136 * Run security checks before installing
1137 *
1138 * @since 3.04.02
1139 *
1140 * @return void
1141 */
1142 protected static function install_addon_permissions() {
1143 check_ajax_referer( 'frm_ajax', 'nonce' );
1144
1145 if ( ! current_user_can( 'activate_plugins' ) || ! self::get_current_plugin() ) {
1146 echo json_encode( true );
1147 wp_die();
1148 }
1149 }
1150
1151 /**
1152 * @since 4.08
1153 *
1154 * @return string
1155 */
1156 public static function connect_link() {
1157 $auth = get_option( 'frm_connect_token' );
1158 if ( empty( $auth ) ) {
1159 $auth = hash( 'sha512', wp_rand() );
1160 update_option( 'frm_connect_token', $auth );
1161 }
1162 $link = FrmAppHelper::admin_upgrade_link( 'connect', 'api-connect' );
1163 $args = array(
1164 'v' => 2,
1165 'siteurl' => FrmAppHelper::site_url(),
1166 'url' => get_rest_url(),
1167 'token' => $auth,
1168 'l' => self::get_pro_license(),
1169 );
1170
1171 return add_query_arg( $args, $link );
1172 }
1173
1174 /**
1175 * Check the auth value for install permission.
1176 *
1177 * @since 4.08
1178 *
1179 * @return bool
1180 */
1181 public static function can_install_addon_api() {
1182 // Verify params present (auth & download link).
1183 $post_auth = FrmAppHelper::get_param( 'token', '', 'request', 'sanitize_text_field' );
1184 $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' );
1185
1186 if ( ! $post_auth || ! $post_url ) {
1187 return false;
1188 }
1189
1190 // Verify auth.
1191 $auth = get_option( 'frm_connect_token' );
1192 if ( empty( $auth ) || ! hash_equals( $auth, $post_auth ) ) {
1193 return false;
1194 }
1195
1196 return true;
1197 }
1198
1199 /**
1200 * Install and/or activate the add-on file.
1201 *
1202 * @since 4.08
1203 */
1204 public static function install_addon_api() {
1205 self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' );
1206
1207 $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' );
1208
1209 // Delete so cannot replay.
1210 delete_option( 'frm_connect_token' );
1211
1212 // It's already installed and active.
1213 $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
1214 if ( is_wp_error( $active ) ) {
1215 // Download plugin now.
1216 $response = self::download_and_activate();
1217 if ( is_array( $response ) && isset( $response['success'] ) ) {
1218 return $response;
1219 }
1220 }
1221
1222 // If empty license, save it now.
1223 if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) {
1224 load_formidable_pro();
1225 $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) );
1226 if ( ! $license ) {
1227 return array(
1228 'success' => false,
1229 'error' => 'That site does not have a valid license key.',
1230 );
1231 }
1232
1233 $response = FrmAddon::activate_license_for_plugin( $license, 'formidable_pro' );
1234 if ( ! $response['success'] ) {
1235 // Could not activate license.
1236 return $response;
1237 }
1238 }
1239
1240 return array(
1241 'success' => true,
1242 );
1243 }
1244
1245 /**
1246 * Render a conditional action button for a specified plugin
1247 *
1248 * @param string $plugin
1249 * @param array|string $upgrade_link_args
1250 * @since 4.09
1251 */
1252 public static function conditional_action_button( $plugin, $upgrade_link_args ) {
1253 if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) {
1254 return FrmProAddonsController::conditional_action_button( $plugin, $upgrade_link_args );
1255 }
1256
1257 $addon = self::get_addon( $plugin );
1258 $upgrade_link = FrmAppHelper::admin_upgrade_link( $upgrade_link_args );
1259
1260 $upgrade_link_args['link'] = $upgrade_link;
1261 self::addon_upgrade_link( $addon, $upgrade_link_args );
1262 }
1263
1264 /**
1265 * Render a conditional action button for an add on
1266 *
1267 * @since 4.09.01
1268 *
1269 * @param array $addon
1270 * @param string|false $license_type
1271 * @param string $plan_required
1272 * @param string $upgrade_link
1273 */
1274 public static function show_conditional_action_button( $atts ) {
1275 if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) {
1276 return FrmProAddonsController::show_conditional_action_button( $atts );
1277 }
1278
1279 self::addon_upgrade_link( $atts['addon'], $atts['upgrade_link'] );
1280 }
1281
1282 /**
1283 * @since 4.09.01
1284 *
1285 * @param array|false $addon
1286 * @param string|array $upgrade_link
1287 *
1288 * @return void
1289 */
1290 protected static function addon_upgrade_link( $addon, $upgrade_link ) {
1291 $atts = is_array( $upgrade_link ) ? $upgrade_link : array();
1292 $upgrade_link = is_array( $upgrade_link ) ? $upgrade_link['link'] : $upgrade_link;
1293
1294 if ( $addon ) {
1295 $upgrade_link .= '&utm_content=' . $addon['slug'];
1296 }
1297
1298 if ( $addon && isset( $addon['categories'] ) && in_array( 'Solution', $addon['categories'], true ) ) {
1299 // Solutions will go to a separate page.
1300 $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] );
1301 }
1302
1303 $class = ! empty( $atts['class'] ) ? $atts['class'] : '';
1304 if ( strpos( $class, 'frm-button' ) === false ) {
1305 $class .= ' frm-button-secondary frm-button-sm';
1306 }
1307 ?>
1308 <a class="install-now button <?php echo esc_attr( $class ); ?>" href="<?php echo esc_url( $upgrade_link ); ?>" target="_blank" rel="noopener" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>">
1309 <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?>
1310 </a>
1311 <?php
1312 }
1313
1314 /**
1315 * @since 3.04.02
1316 *
1317 * @return void
1318 */
1319 public static function ajax_install_addon() {
1320 self::install_addon_permissions();
1321
1322 $result = self::download_and_activate();
1323 if ( isset( $result['success'] ) && ! $result['success'] ) {
1324 echo json_encode( $result );
1325 wp_die();
1326 }
1327
1328 echo json_encode( self::get_addon_activation_response() );
1329 wp_die();
1330 }
1331
1332 /**
1333 * Allowed URLs used for internal source of plugins installation.
1334 *
1335 * @since 6.3.1
1336 *
1337 * @return array
1338 */
1339 private static function allowed_external_urls() {
1340 $allowed_url_list = array(
1341 'https://downloads.wordpress.org/plugin/formidable-gravity-forms-importer.zip',
1342 'https://downloads.wordpress.org/plugin/formidable-import-pirate-forms.zip',
1343 'https://downloads.wordpress.org/plugin/wp-mail-smtp.zip',
1344 );
1345
1346 /**
1347 * List of URLs used in plugin formidable internal installation.
1348 *
1349 * @since 6.3.1
1350 *
1351 * @param array $allowed_url_list List of URLs.
1352 */
1353 $allowed_url_list = apply_filters( 'frm_allowed_external_urls', $allowed_url_list );
1354
1355 if ( ! is_array( $allowed_url_list ) ) {
1356 _doing_it_wrong( __METHOD__, 'Only an array of URLs could be used within this filter.', '6.3.1' );
1357
1358 return array();
1359 }
1360
1361 return $allowed_url_list;
1362 }
1363
1364 /**
1365 * Gets required plan for an addon.
1366 *
1367 * @since 6.4.2
1368 *
1369 * @return string Empty string if no plan is required for active license.
1370 */
1371 public static function get_addon_required_plan( $addon_id ) {
1372 $api = new FrmFormApi();
1373 $addons = $api->get_api_info();
1374
1375 if ( is_array( $addons ) && array_key_exists( $addon_id, $addons ) ) {
1376 $dates = $addons[ $addon_id ];
1377 $requires = FrmFormsHelper::get_plan_required( $dates );
1378 }
1379
1380 if ( ! isset( $requires ) || ! is_string( $requires ) ) {
1381 $requires = '';
1382 }
1383
1384 return $requires;
1385 }
1386
1387 /**
1388 * @since 4.06.02
1389 *
1390 * @deprecated 4.09.01
1391 *
1392 * @return void
1393 */
1394 public static function ajax_multiple_addons() {
1395 FrmDeprecated::ajax_multiple_addons();
1396 }
1397
1398 /**
1399 * @since 3.04.03
1400 * @deprecated 3.06
1401 * @codeCoverageIgnore
1402 * @return array
1403 */
1404 public static function error_for_license( $license ) {
1405 return FrmDeprecated::error_for_license( $license );
1406 }
1407
1408 /**
1409 * @since 3.04.03
1410 * @deprecated 3.06
1411 * @codeCoverageIgnore
1412 */
1413 public static function get_pro_updater() {
1414 return FrmDeprecated::get_pro_updater();
1415 }
1416
1417 /**
1418 * @since 3.04.03
1419 * @deprecated 3.06
1420 * @codeCoverageIgnore
1421 *
1422 * @return array
1423 */
1424 public static function get_addon_info( $license = '' ) {
1425 return FrmDeprecated::get_addon_info( $license );
1426 }
1427
1428 /**
1429 * @since 3.04.03
1430 * @deprecated 3.06
1431 * @codeCoverageIgnore
1432 *
1433 * @return string
1434 */
1435 public static function get_cache_key( $license ) {
1436 return FrmDeprecated::get_cache_key( $license );
1437 }
1438
1439 /**
1440 * @since 3.04.03
1441 *
1442 * @deprecated 3.06
1443 *
1444 * @codeCoverageIgnore
1445 *
1446 * @return void
1447 */
1448 public static function reset_cached_addons( $license = '' ) {
1449 FrmDeprecated::reset_cached_addons( $license );
1450 }
1451
1452 /**
1453 * @since 2.03.08
1454 * @deprecated 3.04.03
1455 * @codeCoverageIgnore
1456 *
1457 * @param boolean $return
1458 * @param string $package
1459 *
1460 * @return boolean
1461 */
1462 public static function add_shorten_edd_filename_filter( $return, $package ) {
1463 return FrmDeprecated::add_shorten_edd_filename_filter( $return, $package );
1464 }
1465
1466 /**
1467 * @since 2.03.08
1468 * @deprecated 3.04.03
1469 * @codeCoverageIgnore
1470 *
1471 * @param string $filename
1472 * @param string $ext
1473 *
1474 * @return string
1475 */
1476 public static function shorten_edd_filename( $filename, $ext ) {
1477 return FrmDeprecated::shorten_edd_filename( $filename, $ext );
1478 }
1479
1480 /**
1481 * @deprecated 3.04.03
1482 *
1483 * @codeCoverageIgnore
1484 *
1485 * @return void
1486 */
1487 public static function get_licenses() {
1488 FrmDeprecated::get_licenses();
1489 }
1490 }
1491