PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.26.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.26.1
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 / models / FrmMigrate.php

FrmMigrate.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.26.1, at classes/models/FrmMigrate.php

852 lines 22.8 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 FrmMigrate {
7
8 /**
9 * @var string
10 */
11 public $fields;
12
13 /**
14 * @var string
15 */
16 public $forms;
17
18 /**
19 * @var string
20 */
21 public $entries;
22
23 /**
24 * @var string
25 */
26 public $entry_metas;
27
28 public function __construct() {
29 global $wpdb;
30 $this->fields = $wpdb->prefix . 'frm_fields';
31 $this->forms = $wpdb->prefix . 'frm_forms';
32 $this->entries = $wpdb->prefix . 'frm_items';
33 $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
34 }
35
36 /**
37 * @return void
38 */
39 public function upgrade() {
40 do_action( 'frm_before_install' );
41
42 global $wpdb, $frm_vars;
43
44 $frm_vars['doing_upgrade'] = true;
45
46 $needs_upgrade = FrmAppController::compare_for_update(
47 array(
48 'option' => 'frm_db_version',
49 'new_db_version' => FrmAppHelper::$db_version,
50 'new_plugin_version' => FrmAppHelper::plugin_version(),
51 )
52 );
53
54 if ( $needs_upgrade ) {
55 // update rewrite rules for views and other custom post types
56 flush_rewrite_rules();
57
58 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
59
60 $old_db_version = get_option( 'frm_db_version' );
61
62 $this->create_tables();
63 $this->migrate_data( $old_db_version );
64 $this->check_that_tables_exist();
65
66 // SAVE DB VERSION.
67 update_option( 'frm_db_version', FrmAppHelper::plugin_version() . '-' . FrmAppHelper::$db_version );
68
69 if ( ! $old_db_version ) {
70 $this->maybe_create_contact_form();
71
72 if ( false === get_option( 'frm_first_activation' ) ) {
73 update_option( 'frm_first_activation', time(), false );
74 }
75
76 $this->update_settings_for_new_install();
77 }
78 }//end if
79
80 do_action( 'frm_after_install' );
81
82 $frm_vars['doing_upgrade'] = false;
83
84 FrmAppHelper::save_combined_js();
85
86 // update the styling settings
87 if ( function_exists( 'get_filesystem_method' ) ) {
88 $frm_style = new FrmStyle();
89 $frm_style->update( 'default' );
90 }
91 }
92
93 /**
94 * Updates some settings for new installs.
95 *
96 * @since 6.23
97 *
98 * @return void
99 */
100 private function update_settings_for_new_install() {
101 $settings = FrmAppHelper::get_settings();
102
103 $settings->denylist_check = 1;
104 $settings->installed_after_welcome_tour_update = 1;
105 $settings->store();
106 }
107
108 /**
109 * If we fail to create the database tables, add an inbox notice.
110 * This informs the user that they need to correct the issue and try again.
111 *
112 * @since 6.19
113 *
114 * @return void
115 */
116 private function check_that_tables_exist() {
117 // Check the DB that the table $this->forms exists.
118 global $wpdb;
119 $exists = $wpdb->get_results( $wpdb->prepare( 'SHOW TABLES LIKE %s', $this->forms ) );
120
121 if ( $exists ) {
122 $inbox = new FrmInbox();
123 $inbox->dismiss( 'failed-to-create-tables' );
124 return;
125 }
126
127 $message = array(
128 'key' => 'failed-to-create-tables',
129 'subject' => 'Something went wrong setting up the database',
130 'message' => 'For steps to continue, see our <a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">documentation</a>. If you need assistance, we recommend that you reach out to your hosting provider. Then <a href="' . esc_url( admin_url( 'admin.php?page=formidable&frm_add_tables=1' ) ) . '">click here</a> to try again.',
131 'cta' => '<a href="https://formidableforms.com/knowledgebase/install-formidable-forms/#kb-missing-database-tables">Learn More</a>',
132 'type' => 'error',
133 );
134
135 $inbox = new FrmInbox();
136 $inbox->add_message( $message );
137 }
138
139 /**
140 * @return string
141 */
142 public function collation() {
143 global $wpdb;
144
145 if ( ! $wpdb->has_cap( 'collation' ) ) {
146 return '';
147 }
148
149 return $wpdb->get_charset_collate();
150 }
151
152 /**
153 * @return void
154 */
155 private function create_tables() {
156 $charset_collate = $this->collation();
157 $sql = array();
158
159 /* Create/Upgrade Fields Table */
160 $sql[] = 'CREATE TABLE ' . $this->fields . ' (
161 id BIGINT(20) NOT NULL auto_increment,
162 field_key varchar(100) default NULL,
163 name text default NULL,
164 description longtext default NULL,
165 type text default NULL,
166 default_value longtext default NULL,
167 options longtext default NULL,
168 field_order int(11) default 0,
169 required int(1) default NULL,
170 field_options longtext default NULL,
171 form_id int(11) default NULL,
172 created_at datetime NOT NULL,
173 PRIMARY KEY (id),
174 KEY form_id (form_id),
175 UNIQUE KEY field_key (field_key)
176 )';
177
178 /* Create/Upgrade Forms Table */
179 $sql[] = 'CREATE TABLE ' . $this->forms . ' (
180 id int(11) NOT NULL auto_increment,
181 form_key varchar(100) default NULL,
182 name varchar(255) default NULL,
183 description text default NULL,
184 parent_form_id int(11) default 0,
185 logged_in tinyint(1) default NULL,
186 editable tinyint(1) default NULL,
187 is_template tinyint(1) default 0,
188 default_template tinyint(1) default 0,
189 status varchar(255) default NULL,
190 options longtext default NULL,
191 created_at datetime NOT NULL,
192 PRIMARY KEY (id),
193 UNIQUE KEY form_key (form_key)
194 )';
195
196 /* Create/Upgrade Items Table */
197 $sql[] = 'CREATE TABLE ' . $this->entries . ' (
198 id BIGINT(20) NOT NULL auto_increment,
199 item_key varchar(100) default NULL,
200 name varchar(255) default NULL,
201 description text default NULL,
202 ip text default NULL,
203 form_id BIGINT(20) default NULL,
204 post_id BIGINT(20) default NULL,
205 user_id BIGINT(20) default NULL,
206 parent_item_id BIGINT(20) default 0,
207 is_draft tinyint(1) default 0,
208 updated_by BIGINT(20) default NULL,
209 created_at datetime NOT NULL,
210 updated_at datetime NOT NULL,
211 PRIMARY KEY (id),
212 KEY form_id (form_id),
213 KEY post_id (post_id),
214 KEY user_id (user_id),
215 KEY parent_item_id (parent_item_id),
216 UNIQUE KEY item_key (item_key)
217 )';
218
219 /* Create/Upgrade Meta Table */
220 $sql[] = 'CREATE TABLE ' . $this->entry_metas . ' (
221 id BIGINT(20) NOT NULL auto_increment,
222 meta_value longtext default NULL,
223 field_id BIGINT(20) NOT NULL,
224 item_id BIGINT(20) NOT NULL,
225 created_at datetime NOT NULL,
226 PRIMARY KEY (id),
227 KEY field_id (field_id),
228 KEY item_id (item_id)
229 )';
230
231 foreach ( $sql as $q ) {
232 if ( function_exists( 'dbDelta' ) ) {
233 dbDelta( $q . $charset_collate . ';' );
234 } else {
235 global $wpdb;
236 $wpdb->query( $q . $charset_collate ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
237 }
238 unset( $q );
239 }
240
241 $this->add_composite_indexes_for_entries();
242 }
243
244 /**
245 * These indexes help optimize database queries for entries.
246 *
247 * @since 6.6
248 * @since 6.16.3 idx_form_id_is_draft was also added to frm_items.
249 * @since 6.17 idx_form_id_type was also added to frm_fields.
250 *
251 * @return void
252 */
253 private function add_composite_indexes_for_entries() {
254 global $wpdb;
255
256 $table_name = "{$wpdb->prefix}frm_items";
257 $index_name = 'idx_is_draft_created_at';
258
259 if ( ! self::index_exists( $table_name, $index_name ) ) {
260 $wpdb->query( "CREATE INDEX idx_is_draft_created_at ON `{$wpdb->prefix}frm_items` (is_draft, created_at)" );
261 }
262
263 $table_name = "{$wpdb->prefix}frm_item_metas";
264 $index_name = 'idx_field_id_item_id';
265
266 if ( ! self::index_exists( $table_name, $index_name ) ) {
267 $wpdb->query( "CREATE INDEX idx_field_id_item_id ON `{$wpdb->prefix}frm_item_metas` (field_id, item_id)" );
268 }
269
270 $table_name = "{$wpdb->prefix}frm_items";
271 $index_name = 'idx_form_id_is_draft';
272
273 if ( ! self::index_exists( $table_name, $index_name ) ) {
274 $wpdb->query( "CREATE INDEX idx_form_id_is_draft ON `{$wpdb->prefix}frm_items` (form_id, is_draft)" );
275 }
276
277 $table_name = "{$wpdb->prefix}frm_fields";
278 $index_name = 'idx_form_id_type';
279
280 if ( ! self::index_exists( $table_name, $index_name ) ) {
281 $wpdb->query( "CREATE INDEX idx_form_id_type ON `{$wpdb->prefix}frm_fields` (form_id, type(30))" );
282 }
283 }
284
285 /**
286 * Check that an index exists in a database table before trying to add it (which results in an error).
287 *
288 * @since 6.6
289 *
290 * @param string $table_name
291 * @param string $index_name
292 *
293 * @return bool
294 */
295 private static function index_exists( $table_name, $index_name ) {
296 global $wpdb;
297 $row = $wpdb->get_row(
298 $wpdb->prepare(
299 'SELECT 1 FROM information_schema.statistics
300 WHERE table_schema = database()
301 AND table_name = %s
302 AND index_name = %s
303 LIMIT 1',
304 array( $table_name, $index_name )
305 )
306 );
307 return (bool) $row;
308 }
309
310 /**
311 * @return void
312 */
313 private function maybe_create_contact_form() {
314 $form_exists = FrmForm::get_id_by_key( 'contact-form' );
315
316 if ( ! $form_exists ) {
317 $this->add_default_template();
318 }
319 }
320
321 /**
322 * Create the default contact form
323 *
324 * @since 3.06
325 *
326 * @return void
327 */
328 private function add_default_template() {
329 if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) {
330 // XML import is not enabled on your server.
331 return;
332 }
333
334 $set_err = libxml_use_internal_errors( true );
335 $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true );
336
337 $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml';
338 FrmXMLHelper::import_xml( $file );
339
340 libxml_use_internal_errors( $set_err );
341 FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader );
342 }
343
344 /**
345 * @param int|string $old_db_version
346 *
347 * @return void
348 */
349 private function migrate_data( $old_db_version ) {
350 if ( ! $old_db_version ) {
351 $old_db_version = get_option( 'frm_db_version' );
352 }
353
354 if ( strpos( $old_db_version, '-' ) ) {
355 $last_upgrade = explode( '-', $old_db_version );
356 $old_db_version = (int) $last_upgrade[1];
357 }
358
359 if ( ! is_numeric( $old_db_version ) ) {
360 // bail if we don't know the previous version
361 return;
362 }
363
364 $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98, 101, 104 );
365
366 foreach ( $migrations as $migration ) {
367 if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) {
368 $function_name = 'migrate_to_' . $migration;
369 $this->$function_name();
370 }
371 }
372 }
373
374 public function uninstall() {
375 if ( ! current_user_can( 'administrator' ) ) {
376 $frm_settings = FrmAppHelper::get_settings();
377 wp_die( esc_html( $frm_settings->admin_permission ) );
378 }
379
380 global $wpdb, $wp_roles;
381
382 $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
383 $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
384 $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
385 $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
386
387 delete_option( 'frm_options' );
388 delete_option( 'frm_db_version' );
389 delete_option( 'frm_install_running' );
390 delete_option( 'frm_lite_settings_upgrade' );
391 delete_option( 'frm-usage-uuid' );
392 delete_option( 'frm_inbox' );
393 delete_option( 'frmpro_css' );
394 delete_option( FrmOnboardingWizardController::REDIRECT_STATUS_OPTION );
395 delete_option( FrmEmailSummaryHelper::$option_name );
396
397 // Delete roles.
398 $frm_roles = FrmAppHelper::frm_capabilities();
399 $roles = get_editable_roles();
400
401 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
402 foreach ( $roles as $role => $details ) {
403 $wp_roles->remove_cap( $role, $frm_role );
404 unset( $role, $details );
405 }
406 unset( $frm_role, $frm_role_description );
407 }
408 unset( $roles, $frm_roles );
409
410 // delete actions, views, and styles
411
412 // prevent the post deletion from triggering entries to be deleted
413 remove_action( 'before_delete_post', 'FrmProDisplaysController::before_delete_post' );
414 remove_action( 'deleted_post', 'FrmProEntriesController::delete_entry' );
415
416 $post_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type in (%s, %s, %s)', FrmFormActionsController::$action_post_type, FrmStylesController::$post_type, 'frm_display' ) );
417
418 foreach ( $post_ids as $post_id ) {
419 // Delete's each post.
420 wp_delete_post( $post_id, true );
421 }
422 unset( $post_ids );
423
424 // delete transients
425 delete_transient( 'frmpro_css' );
426 delete_transient( 'frm_options' );
427 delete_transient( 'frmpro_options' );
428 delete_transient( FrmOnboardingWizardController::TRANSIENT_NAME );
429
430 $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) );
431
432 do_action( 'frm_after_uninstall' );
433
434 return true;
435 }
436
437 /**
438 * In older versions of Lite, it's possible we've saved the wrong location ID.
439 * So force it to get valid values again.
440 *
441 * @since 6.25
442 *
443 * @return void
444 */
445 private function migrate_to_104() {
446 if ( FrmSquareLiteConnectHelper::get_merchant_id( 'test' ) ) {
447 FrmSquareLiteConnectHelper::get_location_id( true, 'test' );
448 }
449
450 if ( FrmSquareLiteConnectHelper::get_merchant_id( 'live' ) ) {
451 FrmSquareLiteConnectHelper::get_location_id( true, 'live' );
452 }
453 }
454
455 /**
456 * Disables summary email for multisite (not the main site) if recipient setting isn't changed.
457 *
458 * @since 6.8
459 *
460 * @return void
461 */
462 private function migrate_to_101() {
463 if ( ! is_multisite() || get_main_site_id() === get_current_blog_id() ) {
464 return;
465 }
466
467 $frm_settings = FrmAppHelper::get_settings();
468
469 if ( empty( $frm_settings->summary_emails ) || '[admin_email]' !== $frm_settings->summary_emails_recipients ) {
470 // User changed it.
471 return;
472 }
473
474 $frm_settings->summary_emails = 0;
475 $frm_settings->store();
476 }
477
478 /**
479 * Clear frmpro_css transient.
480 *
481 * @since 4.10.02
482 *
483 * @return void
484 */
485 private function migrate_to_98() {
486 delete_transient( 'frmpro_css' );
487 }
488
489 /**
490 * Move default_blank and clear_on_focus to placeholder.
491 *
492 * @since 4.0
493 *
494 * @return void
495 */
496 private function migrate_to_97() {
497 $this->migrate_to_placeholder( 'clear_on_focus' );
498 $this->migrate_to_placeholder( 'default_blank' );
499 }
500
501 /**
502 * Move clear_on_focus or default_blank to placeholder.
503 *
504 * @since 4.0
505 *
506 * @param string $type Field option key to migrate.
507 *
508 * @return void
509 */
510 private function migrate_to_placeholder( $type = 'clear_on_focus' ) {
511 $query = array(
512 'field_options like' => '"' . $type . '";s:1:"1";',
513 );
514
515 $fields = FrmDb::get_results( $this->fields, $query, 'id, default_value, field_options, options' );
516
517 foreach ( $fields as $field ) {
518 FrmAppHelper::unserialize_or_decode( $field->field_options );
519 FrmAppHelper::unserialize_or_decode( $field->options );
520 $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type );
521
522 if ( empty( $update_values ) ) {
523 continue;
524 }
525
526 FrmField::update( $field->id, $update_values );
527 unset( $field );
528 }
529 }
530
531 /**
532 * Delete unneeded default templates
533 *
534 * @since 3.06
535 *
536 * @return void
537 */
538 private function migrate_to_90() {
539 $form = FrmForm::getOne( 'contact' );
540
541 if ( $form && $form->default_template == 1 ) {
542 FrmForm::destroy( 'contact' );
543 }
544 }
545
546 /**
547 * Reverse migration 17 -- Divide by 9
548 *
549 * @since 3.0.05
550 *
551 * @return void
552 */
553 private function migrate_to_86() {
554
555 $fields = $this->get_fields_with_size();
556
557 foreach ( $fields as $f ) {
558 FrmAppHelper::unserialize_or_decode( $f->field_options );
559 $size = $f->field_options['size'];
560 $this->maybe_convert_migrated_size( $size );
561
562 if ( $size === $f->field_options['size'] ) {
563 continue;
564 }
565
566 $f->field_options['size'] = $size;
567 FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
568 unset( $f );
569 }
570
571 // reverse the extra size changes in widgets
572 $widgets = get_option( 'widget_frm_show_form' );
573
574 if ( empty( $widgets ) ) {
575 return;
576 }
577
578 $this->revert_widget_field_size();
579 }
580
581 /**
582 * @return array
583 */
584 private function get_fields_with_size() {
585 $field_types = array(
586 'textarea',
587 'text',
588 'number',
589 'email',
590 'url',
591 'rte',
592 'date',
593 'phone',
594 'password',
595 'image',
596 'tag',
597 'file',
598 );
599
600 $query = array(
601 'type' => $field_types,
602 'field_options like' => 's:4:"size";',
603 'field_options not like' => 's:4:"size";s:0:',
604 );
605
606 return FrmDb::get_results( $this->fields, $query, 'id, field_options' );
607 }
608
609 /**
610 * Reverse the extra size changes in widgets
611 *
612 * @since 3.0.05
613 *
614 * @return void
615 */
616 private function revert_widget_field_size() {
617 $widgets = get_option( 'widget_frm_show_form' );
618
619 if ( empty( $widgets ) ) {
620 return;
621 }
622
623 FrmAppHelper::unserialize_or_decode( $widgets );
624
625 foreach ( $widgets as $k => $widget ) {
626 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
627 continue;
628 }
629
630 $this->maybe_convert_migrated_size( $widgets[ $k ]['size'] );
631 }
632 update_option( 'widget_frm_show_form', $widgets );
633 }
634
635 /**
636 * Divide by 9 to reverse the multiplication
637 *
638 * @since 3.0.05
639 *
640 * @param string $size Size string to maybe convert, passed by reference.
641 *
642 * @return void
643 */
644 private function maybe_convert_migrated_size( &$size ) {
645 $has_px_size = ! empty( $size ) && strpos( $size, 'px' );
646
647 if ( ! $has_px_size ) {
648 return;
649 }
650
651 $int_size = str_replace( 'px', '', $size );
652
653 if ( ! is_numeric( $int_size ) || (int) $int_size < 900 ) {
654 return;
655 }
656
657 $pixel_conversion = 9;
658
659 $size = round( (int) $int_size / $pixel_conversion );
660 }
661
662 /**
663 * Migrate old styling settings. If sites are using the old
664 * default 400px field width, switch it to 100%
665 *
666 * @since 2.0.4
667 *
668 * @return void
669 */
670 private function migrate_to_25() {
671 // get the style that was created with the style migration
672 $frm_style = new FrmStyle();
673 $styles = $frm_style->get_all( 'post_date', 'ASC', 1 );
674
675 if ( empty( $styles ) ) {
676 return;
677 }
678
679 foreach ( $styles as $style ) {
680 if ( $style->post_content['field_width'] === '400px' ) {
681 $style->post_content['field_width'] = '100%';
682 $frm_style->save( (array) $style );
683
684 return;
685 }
686 }
687 }
688
689 /**
690 * Check if the parent_form_id columns exists.
691 * If not, try and add it again
692 *
693 * @since 2.0.2
694 *
695 * @return void
696 */
697 private function migrate_to_23() {
698 global $wpdb;
699 $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
700
701 if ( empty( $exists ) ) {
702 $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
703 }
704 }
705
706 /**
707 * Change field size from character to pixel -- Multiply by 9
708 *
709 * @return void
710 */
711 private function migrate_to_17() {
712 $fields = $this->get_fields_with_size();
713
714 foreach ( $fields as $f ) {
715 FrmAppHelper::unserialize_or_decode( $f->field_options );
716
717 if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) {
718 continue;
719 }
720
721 $this->convert_character_to_px( $f->field_options['size'] );
722
723 FrmField::update( $f->id, array( 'field_options' => $f->field_options ) );
724 unset( $f );
725 }
726
727 $this->adjust_widget_size();
728 }
729
730 /**
731 * Change the characters in widgets to pixels
732 *
733 * @return void
734 */
735 private function adjust_widget_size() {
736 $widgets = get_option( 'widget_frm_show_form' );
737
738 if ( empty( $widgets ) ) {
739 return;
740 }
741
742 FrmAppHelper::unserialize_or_decode( $widgets );
743
744 foreach ( $widgets as $k => $widget ) {
745 if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) {
746 continue;
747 }
748 $this->convert_character_to_px( $widgets[ $k ]['size'] );
749 }
750 update_option( 'widget_frm_show_form', $widgets );
751 }
752
753 /**
754 * @param string $size
755 *
756 * @return void
757 */
758 private function convert_character_to_px( &$size ) {
759 $pixel_conversion = 9;
760
761 $size = round( $pixel_conversion * (int) $size );
762 $size .= 'px';
763 }
764
765 /**
766 * Migrate post and email notification settings into actions
767 */
768 private function migrate_to_16() {
769 $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' );
770
771 /**
772 * Old email settings format:
773 * email_to: Email or field id
774 * also_email_to: array of fields ids
775 * reply_to: Email, field id, 'custom'
776 * cust_reply_to: string
777 * reply_to_name: field id, 'custom'
778 * cust_reply_to_name: string
779 * plain_text: 0|1
780 * email_message: string or ''
781 * email_subject: string or ''
782 * inc_user_info: 0|1
783 * update_email: 0, 1, 2
784 *
785 * Old autoresponder settings format:
786 * auto_responder: 0|1
787 * ar_email_message: string or ''
788 * ar_email_to: field id
789 * ar_plain_text: 0|1
790 * ar_reply_to_name: string
791 * ar_reply_to: string
792 * ar_email_subject: string
793 * ar_update_email: 0, 1, 2
794 *
795 * New email settings:
796 * post_content: json settings
797 * post_title: form id
798 * post_excerpt: message
799 */
800 foreach ( $forms as $form ) {
801 if ( $form->is_template && $form->default_template ) {
802 // don't migrate the default templates since the email will be added anyway
803 continue;
804 }
805
806 // Format form options
807 $form_options = $form->options;
808 FrmAppHelper::unserialize_or_decode( $form_options );
809
810 // Migrate settings to actions
811 FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id );
812 }
813 }
814
815 private function migrate_to_11() {
816 global $wpdb;
817
818 $forms = FrmDb::get_results( $this->forms, array(), 'id, options' );
819
820 $sending = __( 'Sending', 'formidable' );
821 $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif';
822 $old_default_html = <<<DEFAULT_HTML
823 <div class="frm_submit">
824 [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button]
825 <input type="submit" value="[button_label]" [button_action] />
826 <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" />
827 </div>
828 DEFAULT_HTML;
829 unset( $sending, $img );
830
831 $new_default_html = FrmFormsHelper::get_default_html( 'submit' );
832 $draft_link = FrmFormsHelper::get_draft_link();
833
834 foreach ( $forms as $form ) {
835 FrmAppHelper::unserialize_or_decode( $form->options );
836
837 if ( empty( $form->options['submit_html'] ) ) {
838 continue;
839 }
840
841 if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) {
842 $form->options['submit_html'] = $new_default_html;
843 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
844 } elseif ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) {
845 $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] );
846 $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) );
847 }
848 unset( $form );
849 }
850 }
851 }
852