| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 5 | 2 | |
| 6 | 3 | class FrmMigrate { |
| 7 | 4 | public $fields; |
| 8 | 5 | public $forms; |
| @@ -9,13 +6,17 @@ | ||
| 9 | 6 | public $entries; |
| 10 | 7 | public $entry_metas; |
| 11 | 8 | |
| 12 | 9 | public function __construct() { |
| 10 | + if ( ! defined( 'ABSPATH' ) ) { | |
| 11 | + die( 'You are not allowed to call this page directly.' ); | |
| 12 | + } | |
| 13 | + | |
| 13 | 14 | global $wpdb; |
| 14 | - $this->fields = $wpdb->prefix . 'frm_fields'; | |
| 15 | - $this->forms = $wpdb->prefix . 'frm_forms'; | |
| 16 | - $this->entries = $wpdb->prefix . 'frm_items'; | |
| 17 | - $this->entry_metas = $wpdb->prefix . 'frm_item_metas'; | |
| 15 | + $this->fields = $wpdb->prefix . 'frm_fields'; | |
| 16 | + $this->forms = $wpdb->prefix . 'frm_forms'; | |
| 17 | + $this->entries = $wpdb->prefix . 'frm_items'; | |
| 18 | + $this->entry_metas = $wpdb->prefix . 'frm_item_metas'; | |
| 18 | 19 | } |
| 19 | 20 | |
| 20 | 21 | public function upgrade() { |
| 21 | 22 | do_action( 'frm_before_install' ); |
| @@ -72,13 +73,13 @@ | ||
| 72 | 73 | |
| 73 | 74 | return $wpdb->get_charset_collate(); |
| 74 | 75 | } |
| 75 | 76 | |
| 76 | - private function create_tables() { | |
| 77 | - $charset_collate = $this->collation(); | |
| 78 | - $sql = array(); | |
| 77 | + private function create_tables() { | |
| 78 | + $charset_collate = $this->collation(); | |
| 79 | + $sql = array(); | |
| 79 | 80 | |
| 80 | - /* Create/Upgrade Fields Table */ | |
| 81 | + /* Create/Upgrade Fields Table */ | |
| 81 | 82 | $sql[] = 'CREATE TABLE ' . $this->fields . ' ( |
| 82 | 83 | id BIGINT(20) NOT NULL auto_increment, |
| 83 | 84 | field_key varchar(100) default NULL, |
| 84 | 85 | name text default NULL, |
| @@ -95,9 +96,9 @@ | ||
| 95 | 96 | KEY form_id (form_id), |
| 96 | 97 | UNIQUE KEY field_key (field_key) |
| 97 | 98 | )'; |
| 98 | 99 | |
| 99 | - /* Create/Upgrade Forms Table */ | |
| 100 | + /* Create/Upgrade Forms Table */ | |
| 100 | 101 | $sql[] = 'CREATE TABLE ' . $this->forms . ' ( |
| 101 | 102 | id int(11) NOT NULL auto_increment, |
| 102 | 103 | form_key varchar(100) default NULL, |
| 103 | 104 | name varchar(255) default NULL, |
| @@ -113,9 +114,9 @@ | ||
| 113 | 114 | PRIMARY KEY (id), |
| 114 | 115 | UNIQUE KEY form_key (form_key) |
| 115 | 116 | )'; |
| 116 | 117 | |
| 117 | - /* Create/Upgrade Items Table */ | |
| 118 | + /* Create/Upgrade Items Table */ | |
| 118 | 119 | $sql[] = 'CREATE TABLE ' . $this->entries . ' ( |
| 119 | 120 | id BIGINT(20) NOT NULL auto_increment, |
| 120 | 121 | item_key varchar(100) default NULL, |
| 121 | 122 | name varchar(255) default NULL, |
| @@ -136,9 +137,9 @@ | ||
| 136 | 137 | KEY parent_item_id (parent_item_id), |
| 137 | 138 | UNIQUE KEY item_key (item_key) |
| 138 | 139 | )'; |
| 139 | 140 | |
| 140 | - /* Create/Upgrade Meta Table */ | |
| 141 | + /* Create/Upgrade Meta Table */ | |
| 141 | 142 | $sql[] = 'CREATE TABLE ' . $this->entry_metas . ' ( |
| 142 | 143 | id BIGINT(20) NOT NULL auto_increment, |
| 143 | 144 | meta_value longtext default NULL, |
| 144 | 145 | field_id BIGINT(20) NOT NULL, |
| @@ -148,18 +149,18 @@ | ||
| 148 | 149 | KEY field_id (field_id), |
| 149 | 150 | KEY item_id (item_id) |
| 150 | 151 | )'; |
| 151 | 152 | |
| 152 | - foreach ( $sql as $q ) { | |
| 153 | + foreach ( $sql as $q ) { | |
| 153 | 154 | if ( function_exists( 'dbDelta' ) ) { |
| 154 | 155 | dbDelta( $q . $charset_collate . ';' ); |
| 155 | 156 | } else { |
| 156 | 157 | global $wpdb; |
| 157 | - $wpdb->query( $q . $charset_collate ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 158 | + $wpdb->query( $q . $charset_collate ); // WPCS: unprepared SQL ok. | |
| 158 | 159 | } |
| 159 | 160 | unset( $q ); |
| 160 | - } | |
| 161 | - } | |
| 161 | + } | |
| 162 | + } | |
| 162 | 163 | |
| 163 | 164 | private function maybe_create_contact_form() { |
| 164 | 165 | $form_exists = FrmForm::get_id_by_key( 'contact-form' ); |
| 165 | 166 | if ( ! $form_exists ) { |
| @@ -172,21 +173,21 @@ | ||
| 172 | 173 | * |
| 173 | 174 | * @since 3.06 |
| 174 | 175 | */ |
| 175 | 176 | private function add_default_template() { |
| 176 | - if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) { | |
| 177 | + if ( ! function_exists( 'libxml_disable_entity_loader' ) ) { | |
| 177 | 178 | // XML import is not enabled on your server. |
| 178 | 179 | return; |
| 179 | 180 | } |
| 180 | 181 | |
| 181 | 182 | $set_err = libxml_use_internal_errors( true ); |
| 182 | - $loader = FrmXMLHelper::maybe_libxml_disable_entity_loader( true ); | |
| 183 | + $loader = libxml_disable_entity_loader( true ); | |
| 183 | 184 | |
| 184 | 185 | $file = FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml'; |
| 185 | 186 | FrmXMLHelper::import_xml( $file ); |
| 186 | 187 | |
| 187 | 188 | libxml_use_internal_errors( $set_err ); |
| 188 | - FrmXMLHelper::maybe_libxml_disable_entity_loader( $loader ); | |
| 189 | + libxml_disable_entity_loader( $loader ); | |
| 189 | 190 | } |
| 190 | 191 | |
| 191 | 192 | /** |
| 192 | 193 | * @param int|string $old_db_version |
| @@ -195,9 +196,9 @@ | ||
| 195 | 196 | if ( ! $old_db_version ) { |
| 196 | 197 | $old_db_version = get_option( 'frm_db_version' ); |
| 197 | 198 | } |
| 198 | 199 | if ( strpos( $old_db_version, '-' ) ) { |
| 199 | - $last_upgrade = explode( '-', $old_db_version ); | |
| 200 | + $last_upgrade = explode( '-', $old_db_version ); | |
| 200 | 201 | $old_db_version = (int) $last_upgrade[1]; |
| 201 | 202 | } |
| 202 | 203 | |
| 203 | 204 | if ( ! is_numeric( $old_db_version ) ) { |
| @@ -204,9 +205,9 @@ | ||
| 204 | 205 | // bail if we don't know the previous version |
| 205 | 206 | return; |
| 206 | 207 | } |
| 207 | 208 | |
| 208 | - $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90, 97, 98 ); | |
| 209 | + $migrations = array( 16, 11, 16, 17, 23, 25, 86, 90 ); | |
| 209 | 210 | foreach ( $migrations as $migration ) { |
| 210 | 211 | if ( FrmAppHelper::$db_version >= $migration && $old_db_version < $migration ) { |
| 211 | 212 | $function_name = 'migrate_to_' . $migration; |
| 212 | 213 | $this->$function_name(); |
| @@ -213,20 +214,20 @@ | ||
| 213 | 214 | } |
| 214 | 215 | } |
| 215 | 216 | } |
| 216 | 217 | |
| 217 | - public function uninstall() { | |
| 218 | + public function uninstall() { | |
| 218 | 219 | if ( ! current_user_can( 'administrator' ) ) { |
| 219 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 220 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 220 | 221 | wp_die( esc_html( $frm_settings->admin_permission ) ); |
| 221 | - } | |
| 222 | + } | |
| 222 | 223 | |
| 223 | - global $wpdb, $wp_roles; | |
| 224 | + global $wpdb, $wp_roles; | |
| 224 | 225 | |
| 225 | - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 226 | - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 227 | - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 228 | - $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 226 | + $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); // WPCS: unprepared SQL ok. | |
| 227 | + $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); // WPCS: unprepared SQL ok. | |
| 228 | + $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); // WPCS: unprepared SQL ok. | |
| 229 | + $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); // WPCS: unprepared SQL ok. | |
| 229 | 230 | |
| 230 | 231 | delete_option( 'frm_options' ); |
| 231 | 232 | delete_option( 'frm_db_version' ); |
| 232 | 233 | delete_option( 'frm_install_running' ); |
| @@ -231,18 +232,15 @@ | ||
| 231 | 232 | delete_option( 'frm_db_version' ); |
| 232 | 233 | delete_option( 'frm_install_running' ); |
| 233 | 234 | delete_option( 'frm_lite_settings_upgrade' ); |
| 234 | 235 | delete_option( 'frm-usage-uuid' ); |
| 235 | - delete_option( 'frm_inbox' ); | |
| 236 | - delete_option( 'frmpro_css' ); | |
| 237 | - delete_option( 'frm_welcome_redirect' ); | |
| 238 | 236 | |
| 239 | - // Delete roles. | |
| 240 | - $frm_roles = FrmAppHelper::frm_capabilities(); | |
| 241 | - $roles = get_editable_roles(); | |
| 242 | - foreach ( $frm_roles as $frm_role => $frm_role_description ) { | |
| 243 | - foreach ( $roles as $role => $details ) { | |
| 244 | - $wp_roles->remove_cap( $role, $frm_role ); | |
| 237 | + //delete roles | |
| 238 | + $frm_roles = FrmAppHelper::frm_capabilities(); | |
| 239 | + $roles = get_editable_roles(); | |
| 240 | + foreach ( $frm_roles as $frm_role => $frm_role_description ) { | |
| 241 | + foreach ( $roles as $role => $details ) { | |
| 242 | + $wp_roles->remove_cap( $role, $frm_role ); | |
| 245 | 243 | unset( $role, $details ); |
| 246 | 244 | } |
| 247 | 245 | unset( $frm_role, $frm_role_description ); |
| 248 | 246 | } |
| @@ -264,62 +262,16 @@ | ||
| 264 | 262 | // delete transients |
| 265 | 263 | delete_transient( 'frmpro_css' ); |
| 266 | 264 | delete_transient( 'frm_options' ); |
| 267 | 265 | delete_transient( 'frmpro_options' ); |
| 268 | - delete_transient( 'frm_activation_redirect' ); | |
| 269 | 266 | |
| 270 | 267 | $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_%' ) ); |
| 271 | 268 | |
| 272 | 269 | do_action( 'frm_after_uninstall' ); |
| 270 | + return true; | |
| 271 | + } | |
| 273 | 272 | |
| 274 | - return true; | |
| 275 | - } | |
| 276 | - | |
| 277 | 273 | /** |
| 278 | - * Clear frmpro_css transient. | |
| 279 | - * | |
| 280 | - * @since 4.10.02 | |
| 281 | - */ | |
| 282 | - private function migrate_to_98() { | |
| 283 | - delete_transient( 'frmpro_css' ); | |
| 284 | - } | |
| 285 | - | |
| 286 | - /** | |
| 287 | - * Move default_blank and clear_on_focus to placeholder. | |
| 288 | - * | |
| 289 | - * @since 4.0 | |
| 290 | - */ | |
| 291 | - private function migrate_to_97() { | |
| 292 | - $this->migrate_to_placeholder( 'clear_on_focus' ); | |
| 293 | - $this->migrate_to_placeholder( 'default_blank' ); | |
| 294 | - } | |
| 295 | - | |
| 296 | - /** | |
| 297 | - * Move clear_on_focus or default_blank to placeholder. | |
| 298 | - * | |
| 299 | - * @since 4.0 | |
| 300 | - */ | |
| 301 | - private function migrate_to_placeholder( $type = 'clear_on_focus' ) { | |
| 302 | - $query = array( | |
| 303 | - 'field_options like' => '"' . $type . '";s:1:"1";', | |
| 304 | - ); | |
| 305 | - | |
| 306 | - $fields = FrmDb::get_results( $this->fields, $query, 'id, default_value, field_options, options' ); | |
| 307 | - | |
| 308 | - foreach ( $fields as $field ) { | |
| 309 | - FrmAppHelper::unserialize_or_decode( $field->field_options ); | |
| 310 | - FrmAppHelper::unserialize_or_decode( $field->options ); | |
| 311 | - $update_values = FrmXMLHelper::migrate_field_placeholder( $field, $type ); | |
| 312 | - if ( empty( $update_values ) ) { | |
| 313 | - continue; | |
| 314 | - } | |
| 315 | - | |
| 316 | - FrmField::update( $field->id, $update_values ); | |
| 317 | - unset( $field ); | |
| 318 | - } | |
| 319 | - } | |
| 320 | - | |
| 321 | - /** | |
| 322 | 274 | * Delete uneeded default templates |
| 323 | 275 | * |
| 324 | 276 | * @since 3.06 |
| 325 | 277 | */ |
| @@ -339,10 +291,10 @@ | ||
| 339 | 291 | |
| 340 | 292 | $fields = $this->get_fields_with_size(); |
| 341 | 293 | |
| 342 | 294 | foreach ( (array) $fields as $f ) { |
| 343 | - FrmAppHelper::unserialize_or_decode( $f->field_options ); | |
| 344 | - $size = $f->field_options['size']; | |
| 295 | + $f->field_options = maybe_unserialize( $f->field_options ); | |
| 296 | + $size = $f->field_options['size']; | |
| 345 | 297 | $this->maybe_convert_migrated_size( $size ); |
| 346 | 298 | |
| 347 | 299 | if ( $size === $f->field_options['size'] ) { |
| 348 | 300 | continue; |
| @@ -362,26 +314,12 @@ | ||
| 362 | 314 | $this->revert_widget_field_size(); |
| 363 | 315 | } |
| 364 | 316 | |
| 365 | 317 | private function get_fields_with_size() { |
| 366 | - $field_types = array( | |
| 367 | - 'textarea', | |
| 368 | - 'text', | |
| 369 | - 'number', | |
| 370 | - 'email', | |
| 371 | - 'url', | |
| 372 | - 'rte', | |
| 373 | - 'date', | |
| 374 | - 'phone', | |
| 375 | - 'password', | |
| 376 | - 'image', | |
| 377 | - 'tag', | |
| 378 | - 'file', | |
| 379 | - ); | |
| 380 | - | |
| 318 | + $field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' ); | |
| 381 | 319 | $query = array( |
| 382 | - 'type' => $field_types, | |
| 383 | - 'field_options like' => 's:4:"size";', | |
| 320 | + 'type' => $field_types, | |
| 321 | + 'field_options like' => 's:4:"size";', | |
| 384 | 322 | 'field_options not like' => 's:4:"size";s:0:', |
| 385 | 323 | ); |
| 386 | 324 | |
| 387 | 325 | return FrmDb::get_results( $this->fields, $query, 'id, field_options' ); |
| @@ -397,9 +335,9 @@ | ||
| 397 | 335 | if ( empty( $widgets ) ) { |
| 398 | 336 | return; |
| 399 | 337 | } |
| 400 | 338 | |
| 401 | - FrmAppHelper::unserialize_or_decode( $widgets ); | |
| 339 | + $widgets = maybe_unserialize( $widgets ); | |
| 402 | 340 | foreach ( $widgets as $k => $widget ) { |
| 403 | 341 | if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) { |
| 404 | 342 | continue; |
| 405 | 343 | } |
| @@ -425,9 +363,8 @@ | ||
| 425 | 363 | return; |
| 426 | 364 | } |
| 427 | 365 | |
| 428 | 366 | $pixel_conversion = 9; |
| 429 | - | |
| 430 | 367 | $size = round( (int) $int_size / $pixel_conversion ); |
| 431 | 368 | } |
| 432 | 369 | |
| 433 | 370 | /** |
| @@ -438,9 +375,9 @@ | ||
| 438 | 375 | */ |
| 439 | 376 | private function migrate_to_25() { |
| 440 | 377 | // get the style that was created with the style migration |
| 441 | 378 | $frm_style = new FrmStyle(); |
| 442 | - $styles = $frm_style->get_all( 'post_date', 'ASC', 1 ); | |
| 379 | + $styles = $frm_style->get_all( 'post_date', 'ASC', 1 ); | |
| 443 | 380 | if ( empty( $styles ) ) { |
| 444 | 381 | return; |
| 445 | 382 | } |
| 446 | 383 | |
| @@ -447,9 +384,8 @@ | ||
| 447 | 384 | foreach ( $styles as $style ) { |
| 448 | 385 | if ( $style->post_content['field_width'] == '400px' ) { |
| 449 | 386 | $style->post_content['field_width'] = '100%'; |
| 450 | 387 | $frm_style->save( (array) $style ); |
| 451 | - | |
| 452 | 388 | return; |
| 453 | 389 | } |
| 454 | 390 | } |
| 455 | 391 | } |
| @@ -461,11 +397,11 @@ | ||
| 461 | 397 | * @since 2.0.2 |
| 462 | 398 | */ |
| 463 | 399 | private function migrate_to_23() { |
| 464 | 400 | global $wpdb; |
| 465 | - $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 401 | + $exists = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $this->forms . ' LIKE "parent_form_id"' ); // WPCS: unprepared SQL ok. | |
| 466 | 402 | if ( empty( $exists ) ) { |
| 467 | - $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 403 | + $wpdb->query( 'ALTER TABLE ' . $this->forms . ' ADD parent_form_id int(11) default 0' ); // WPCS: unprepared SQL ok. | |
| 468 | 404 | } |
| 469 | 405 | } |
| 470 | 406 | |
| 471 | 407 | /** |
| @@ -474,9 +410,9 @@ | ||
| 474 | 410 | private function migrate_to_17() { |
| 475 | 411 | $fields = $this->get_fields_with_size(); |
| 476 | 412 | |
| 477 | 413 | foreach ( $fields as $f ) { |
| 478 | - FrmAppHelper::unserialize_or_decode( $f->field_options ); | |
| 414 | + $f->field_options = maybe_unserialize( $f->field_options ); | |
| 479 | 415 | if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) { |
| 480 | 416 | continue; |
| 481 | 417 | } |
| 482 | 418 | |
| @@ -497,9 +433,9 @@ | ||
| 497 | 433 | if ( empty( $widgets ) ) { |
| 498 | 434 | return; |
| 499 | 435 | } |
| 500 | 436 | |
| 501 | - FrmAppHelper::unserialize_or_decode( $widgets ); | |
| 437 | + $widgets = maybe_unserialize( $widgets ); | |
| 502 | 438 | foreach ( $widgets as $k => $widget ) { |
| 503 | 439 | if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) { |
| 504 | 440 | continue; |
| 505 | 441 | } |
| @@ -509,49 +445,48 @@ | ||
| 509 | 445 | } |
| 510 | 446 | |
| 511 | 447 | private function convert_character_to_px( &$size ) { |
| 512 | 448 | $pixel_conversion = 9; |
| 513 | - | |
| 514 | 449 | $size = round( $pixel_conversion * (int) $size ); |
| 515 | 450 | $size .= 'px'; |
| 516 | 451 | } |
| 517 | 452 | |
| 518 | - /** | |
| 519 | - * Migrate post and email notification settings into actions | |
| 520 | - */ | |
| 521 | - private function migrate_to_16() { | |
| 522 | - $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' ); | |
| 453 | + /** | |
| 454 | + * Migrate post and email notification settings into actions | |
| 455 | + */ | |
| 456 | + private function migrate_to_16() { | |
| 457 | + $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' ); | |
| 523 | 458 | |
| 524 | - /** | |
| 525 | - * Old email settings format: | |
| 526 | - * email_to: Email or field id | |
| 527 | - * also_email_to: array of fields ids | |
| 528 | - * reply_to: Email, field id, 'custom' | |
| 529 | - * cust_reply_to: string | |
| 530 | - * reply_to_name: field id, 'custom' | |
| 531 | - * cust_reply_to_name: string | |
| 532 | - * plain_text: 0|1 | |
| 533 | - * email_message: string or '' | |
| 534 | - * email_subject: string or '' | |
| 535 | - * inc_user_info: 0|1 | |
| 536 | - * update_email: 0, 1, 2 | |
| 537 | - * | |
| 538 | - * Old autoresponder settings format: | |
| 539 | - * auto_responder: 0|1 | |
| 540 | - * ar_email_message: string or '' | |
| 541 | - * ar_email_to: field id | |
| 542 | - * ar_plain_text: 0|1 | |
| 543 | - * ar_reply_to_name: string | |
| 544 | - * ar_reply_to: string | |
| 545 | - * ar_email_subject: string | |
| 546 | - * ar_update_email: 0, 1, 2 | |
| 547 | - * | |
| 548 | - * New email settings: | |
| 549 | - * post_content: json settings | |
| 550 | - * post_title: form id | |
| 551 | - * post_excerpt: message | |
| 552 | - */ | |
| 553 | - foreach ( $forms as $form ) { | |
| 459 | + /** | |
| 460 | + * Old email settings format: | |
| 461 | + * email_to: Email or field id | |
| 462 | + * also_email_to: array of fields ids | |
| 463 | + * reply_to: Email, field id, 'custom' | |
| 464 | + * cust_reply_to: string | |
| 465 | + * reply_to_name: field id, 'custom' | |
| 466 | + * cust_reply_to_name: string | |
| 467 | + * plain_text: 0|1 | |
| 468 | + * email_message: string or '' | |
| 469 | + * email_subject: string or '' | |
| 470 | + * inc_user_info: 0|1 | |
| 471 | + * update_email: 0, 1, 2 | |
| 472 | + * | |
| 473 | + * Old autoresponder settings format: | |
| 474 | + * auto_responder: 0|1 | |
| 475 | + * ar_email_message: string or '' | |
| 476 | + * ar_email_to: field id | |
| 477 | + * ar_plain_text: 0|1 | |
| 478 | + * ar_reply_to_name: string | |
| 479 | + * ar_reply_to: string | |
| 480 | + * ar_email_subject: string | |
| 481 | + * ar_update_email: 0, 1, 2 | |
| 482 | + * | |
| 483 | + * New email settings: | |
| 484 | + * post_content: json settings | |
| 485 | + * post_title: form id | |
| 486 | + * post_excerpt: message | |
| 487 | + */ | |
| 488 | + foreach ( $forms as $form ) { | |
| 554 | 489 | if ( $form->is_template && $form->default_template ) { |
| 555 | 490 | // don't migrate the default templates since the email will be added anyway |
| 556 | 491 | continue; |
| 557 | 492 | } |
| @@ -556,24 +491,23 @@ | ||
| 556 | 491 | continue; |
| 557 | 492 | } |
| 558 | 493 | |
| 559 | 494 | // Format form options |
| 560 | - $form_options = $form->options; | |
| 561 | - FrmAppHelper::unserialize_or_decode( $form_options ); | |
| 495 | + $form_options = maybe_unserialize( $form->options ); | |
| 562 | 496 | |
| 563 | - // Migrate settings to actions | |
| 564 | - FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id ); | |
| 565 | - } | |
| 566 | - } | |
| 497 | + // Migrate settings to actions | |
| 498 | + FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id ); | |
| 499 | + } | |
| 500 | + } | |
| 567 | 501 | |
| 568 | - private function migrate_to_11() { | |
| 569 | - global $wpdb; | |
| 502 | + private function migrate_to_11() { | |
| 503 | + global $wpdb; | |
| 570 | 504 | |
| 571 | 505 | $forms = FrmDb::get_results( $this->forms, array(), 'id, options' ); |
| 572 | 506 | |
| 573 | - $sending = __( 'Sending', 'formidable' ); | |
| 574 | - $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif'; | |
| 575 | - $old_default_html = <<<DEFAULT_HTML | |
| 507 | + $sending = __( 'Sending', 'formidable' ); | |
| 508 | + $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif'; | |
| 509 | + $old_default_html = <<<DEFAULT_HTML | |
| 576 | 510 | <div class="frm_submit"> |
| 577 | 511 | [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button] |
| 578 | 512 | <input type="submit" value="[button_label]" [button_action] /> |
| 579 | 513 | <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" /> |
| @@ -581,22 +515,22 @@ | ||
| 581 | 515 | DEFAULT_HTML; |
| 582 | 516 | unset( $sending, $img ); |
| 583 | 517 | |
| 584 | 518 | $new_default_html = FrmFormsHelper::get_default_html( 'submit' ); |
| 585 | - $draft_link = FrmFormsHelper::get_draft_link(); | |
| 519 | + $draft_link = FrmFormsHelper::get_draft_link(); | |
| 586 | 520 | foreach ( $forms as $form ) { |
| 587 | - FrmAppHelper::unserialize_or_decode( $form->options ); | |
| 521 | + $form->options = maybe_unserialize( $form->options ); | |
| 588 | 522 | if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) { |
| 589 | - continue; | |
| 590 | - } | |
| 523 | + continue; | |
| 524 | + } | |
| 591 | 525 | |
| 592 | - if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { | |
| 593 | - $form->options['submit_html'] = $new_default_html; | |
| 526 | + if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { | |
| 527 | + $form->options['submit_html'] = $new_default_html; | |
| 594 | 528 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 595 | - } elseif ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) { | |
| 529 | + } else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) { | |
| 596 | 530 | $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] ); |
| 597 | 531 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 598 | - } | |
| 532 | + } | |
| 599 | 533 | unset( $form ); |
| 600 | - } | |
| 601 | - } | |
| 534 | + } | |
| 535 | + } | |
| 602 | 536 | } |