/** * Import backup data * * @param $file array * @return bool * */ public static function import_backup($file = '') { global $wpdb, $yiw_wptables; $wpdb->show_errors(); $error = ''; if (isset($_FILES['import-file']) && empty($file)) { if (!isset($_FILES['import-file'])) { wp_die(__("The file you have insert doesn't valid.", 'yit')); } switch (substr($_FILES['import-file']['name'], -3)) { case 'xml': $error = sprintf(__('The file you have insert is a WordPress eXtended RSS (WXR) file. You need to use this into the %s admin page to import this file. Here only <b>.gz</b> file are allowed. <a href="%s" title="Tools -> Import">Tools -> Import</a>', 'yit'), admin_url('import.php', false)); break; case 'zip': case 'rar': $error = sprintf(__('The file you have insert is a ZIP or RAR file, that it doesn\'t allowed in this case. Here only <b>.gz</b> file are allowed. <a href="%s" title="Tools -> Import">Tools -> Import</a>', 'yit'), admin_url('import.php', false)); break; } if (substr($_FILES['import-file']['name'], -2) != 'gz') { $error = sprintf(__('The file you have insert is not a valid file. Here only <b>.gz</b> file are allowed. <a href="%s" title="Tools -> Import">Tools -> Import</a>', 'yit'), admin_url('import.php', false)); } if ($error != '') { yit_get_model('message')->addMessage($error, 'error'); return false; } } $file = empty($file) ? $_FILES['import-file']['tmp_name'] : $file; // get db encoded $content_file = file_get_contents($file); $db = unserialize(base64_decode(gzuncompress($content_file))); //yit_debug($db); die; array_walk_recursive($db, 'yit_convert_url', 'in_import'); //yit_debug($db); die; if (!is_array($db)) { wp_die(__('An error encoured during during import. Please try again.', 'yit')); } set_time_limit(0); // tables foreach (self::$wptables as $table) { // delete all row of each table $wpdb->query("TRUNCATE TABLE {$wpdb->{$table}}"); // insert new data $error_data = array(); $insert = array(); foreach ($db[$table] as $id => $data) { $insert[] = YIT_Backup::_makeInsertSQL($data); } if (!empty($db[$table])) { $insert = implode(', ', $insert); $fields = implode('`, `', array_keys($db[$table][0])); //wp_die("INSERT INTO `{$wpdb->$table}` ( `$fields` ) VALUES " . $insert); $wpdb->query("INSERT INTO `{$wpdb->{$table}}` ( `{$fields}` ) VALUES " . $insert); } } $tables = apply_filters('yit_sample_data_tables', array()); $tables = apply_filters('yit_sample_data_tables_import', $tables); if (!empty($tables)) { foreach ($tables as $table) { if (!isset($db[$table])) { continue; } if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}{$table}'") == $wpdb->prefix . $table) { #yiw_string_( '<p></p><p><strong>', '// ' . $table, '</strong><br />' ); // delete all row of each table $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}{$table}"); #yiw_string_( '', sprintf( __( 'Truncated %s table', 'yit' ), $wpdb->prefix . $table ), '...<br />' ); // insert new data $insert = array(); foreach ($db[$table] as $id => $data) { $insert[] = YIT_Backup::_makeInsertSQL($data); } if (!empty($db[$table])) { $insert = implode(', ', $insert); $fields = implode('`, `', array_keys($db[$table][0])); $wpdb->query("INSERT INTO `{$wpdb->prefix}{$table}` ( `{$fields}` ) VALUES " . $insert); } } } } # yiw_string_( '<p></p><p><strong>', '// options', '</strong><br />' ); // delete options $theme = get_option('stylesheet'); $options = array(yit_get_model('panel')->option_name, 'sidebars_widgets', 'show_on_front', 'page_on_front', 'page_for_posts', 'widget%', 'theme\\_mods\\_%', 'rewrite_rules'); $options = apply_filters('yit_sample_data_options', $options); $options = apply_filters('yit_sample_data_options_import', $options); $sql_options = array(); foreach ($options as $option) { if (strpos($option, '%') !== FALSE) { $operator = 'LIKE'; } else { $operator = '='; } $sql_options[] = "option_name {$operator} '{$option}'"; } $sql_options = implode(' OR ', $sql_options); $sql = "DELETE FROM {$wpdb->options} WHERE {$sql_options};"; #if( $wpdb->query( $sql ) ) #yiw_string_( '', sprintf( __( 'Deleted value from %s table', 'yit' ), $wpdb->options ), '...<br />' ); #else #yiw_string_( '', sprintf( __( 'Error during deleting from %s table (SQL: %s)', 'yit' ), $wpdb->options, $sql ), '...<br />' ); $wpdb->query($sql); // update options $error_data = array(); $check = $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_id = 1", ARRAY_A); foreach ($db['options'] as $id => $option) { if (!isset($check['blog_id'])) { unset($option['blog_id']); } if ($wpdb->insert($wpdb->options, $option)) { $insert = true; } else { $insert = false; } // save the ID that has error, to show. if (!$insert) { $wpdb->print_error(); } //$error_data[] = $option['option_name']; } #if( $insert ) # yiw_string_( '', sprintf( __( 'Insert new values, into %s table', 'yit' ), $wpdb->options ), '...</p>' ); #else # yiw_string_( '', sprintf( __( 'Error during insert new values (IDs: %s), into %s table', 'yit' ), implode( $error_data, ' ' ), $wpdb->options ), '...</p>' ); # echo '</p>'; yit_delete_cache_callback(); do_action('yit_after_import'); return true; }
/** * Check if the theme is updated. If so, the cache folder will be * emptied. * * @since 1.0.0 */ protected function _checkThemeVersion() { global $yit; $option_name = 'yit_' . YIT_THEME_NAME . '_version'; $old_version = get_option($option_name); $new_version = $yit->getConfigThemeVersion(); if (!$old_version) { //first theme install update_option($option_name, $new_version); } elseif (version_compare($old_version, $new_version, '!=')) { //update to newer version yit_delete_cache_callback(); update_option($option_name, $new_version); } }