/** * Performs post-import cleanup of files and the cache */ function import_end() { wp_import_cleanup($this->id); wp_cache_flush(); foreach (get_taxonomies() as $tax) { delete_option("{$tax}_children"); _get_term_hierarchy($tax); } wp_defer_term_counting(false); wp_defer_comment_counting(false); do_action('import_end'); }
/** * The form of the second step. * * @param none * @return none */ private function step2() { $file = wp_import_handle_upload(); if (isset($file['error'])) { return new WP_Error('Error', esc_html($file['error'])); } else { if (!file_exists($file['file'])) { return new WP_Error('Error', sprintf(__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'advanced-csv-importer'), esc_html($file['file']))); } } $csv_file = get_attached_file($file['id']); $post_objects = Main::get_post_objects($csv_file); if (is_wp_error($post_objects)) { echo '<p><strong>' . __('Failed to open file.', 'advanced-csv-importer') . '</strong></p>'; wp_import_cleanup($file['id']); return $post_objects; } else { $inserted_posts = Main::insert_posts($post_objects); wp_import_cleanup($file['id']); return $inserted_posts; } }
/** * Handles the JSON upload and initial parsing of the file to prepare for * displaying author import options * * @return bool False if error uploading or invalid file, true otherwise */ private function handle_upload() { $file = wp_import_handle_upload(); if (isset($file['error'])) { return $this->error_message(esc_html__('Sorry, there has been an error.', 'wp-options-importer'), esc_html($file['error'])); } if (!isset($file['file'], $file['id'])) { return $this->error_message(esc_html__('Sorry, there has been an error.', 'wp-options-importer'), esc_html__('The file did not upload properly. Please try again.', 'wp-options-importer')); } $this->file_id = intval($file['id']); if (!file_exists($file['file'])) { wp_import_cleanup($this->file_id); return $this->error_message(esc_html__('Sorry, there has been an error.', 'wp-options-importer'), sprintf(esc_html__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'wp-options-importer'), esc_html($file['file']))); } if (!is_file($file['file'])) { wp_import_cleanup($this->file_id); return $this->error_message(esc_html__('Sorry, there has been an error.', 'wordpress-importer'), esc_html__('The path is not a file, please try again.', 'wordpress-importer')); } $file_contents = file_get_contents($file['file']); $this->import_data = json_decode($file_contents, true); set_transient($this->transient_key(), $this->import_data, DAY_IN_SECONDS); wp_import_cleanup($this->file_id); return $this->run_data_check(); }
/** * Performs post-import cleanup of files and the cache */ function import_end() { wp_import_cleanup($this->id); wp_cache_flush(); wp_defer_term_counting(false); wp_defer_comment_counting(false); echo '<p>' . __('Import complete.', 'wc_customer_relationship_manager') . '</p>'; echo '<p>' . sprintf(_n('%d Customer has been successfully added.', '%d Customers has been successfully added.', $this->row, 'wc_customer_relationship_manager'), $this->row) . '</p>'; if (!empty($this->groups_added)) { echo '<p>' . sprintf(_n('%d Group has been successfully added.', '%d Groups has been successfully added.', count($this->groups_added), 'wc_customer_relationship_manager'), count($this->groups_added)) . ' (' . implode(', ', $this->groups_added) . ')</p>'; } if (!empty($this->statuses_added)) { echo '<p>' . sprintf(_n('%d Customer status has been successfully added.', '%d Customer statuses has been successfully added.', count($this->statuses_added), 'wc_customer_relationship_manager'), count($this->statuses_added)) . ' (' . implode(', ', $this->statuses_added) . ')</p>'; } if (!empty($this->not_import)) { echo '<p>' . sprintf(_n('%d Customer was not added.', '%d Customers was not added.', count($this->not_import), 'wc_customer_relationship_manager'), count($this->not_import)) . '</p>'; echo '<code>'; foreach ($this->not_import as $key => $value) { echo $value[0] . '<br>'; } echo '</code>'; } do_action('wcrm_import_end'); }
private function get_posts($field) { $xml = $this->load_XML($field); if ($xml) { if ($field == 'artists') { return $this->parse_artists($xml); } if ($field == 'venues') { return $this->parse_venues($xml); } else { if ($field == "shows") { return $this->parse_shows($xml); } else { if ($field == "workshops") { return $this->parse_workshops($xml); } else { if ($field == "contacts") { return $this->parse_contacts($xml); } else { if ($field == "vendors") { return $this->parse_vendors($xml); } else { return array(); } } } } } wp_import_cleanup($xml['id']); } else { return false; } }
function import() { $options = get_option('html_import'); if ($_POST['import_files'] == 'file') { // preserve original file name so we can use it for slugs later ( maybe ) $this->filename = $_FILES['import']['name']; // upload the file $file = wp_import_handle_upload(); if (isset($file['error'])) { echo $file['error']; return; } echo '<h2>' . __('Importing HTML file...', 'import-html-pages') . '</h2>'; $this->file = $file['file']; $this->get_single_file(); $this->print_results($options['type']); wp_import_cleanup($file['id']); if ($options['import_images']) { $this->find_images(); } if ($options['import_documents']) { $this->find_documents(); } if ($options['fix_links']) { $this->find_internal_links(); } } elseif ($_POST['import_files'] == 'directory') { // in case they entered something dumb and didn't fix it when we showed an error on the options page... if (validate_import_file($options['root_directory']) > 0) { wp_die(__("The beginning directory you entered is not an absolute path. Relative paths are not allowed here.", 'import-html-pages')); } $this->table = ''; $this->redirects = ''; $this->filearr = array(); $skipdirs = explode(",", $options['skipdirs']); $this->skip = array_merge($skipdirs, array('.', '..', '_vti_cnf', '_notes')); $this->allowed = explode(",", $options['file_extensions']); echo '<h2>' . __('Importing HTML files...', 'import-html-pages') . '</h2>'; $this->get_files_from_directory($options['root_directory']); $this->print_results($options['type']); if (isset($options['import_images']) && $options['import_images']) { $this->find_images(); } if (isset($options['import_documents']) && $options['import_documents']) { $this->find_documents(); } if (isset($options['fix_links']) && $options['fix_links']) { $this->find_internal_links(); } } else { _e("Your file upload didn't work. Try again?", 'html-import-pages'); } do_action('import_done', 'html'); }
function process_posts() { global $wpdb; $i = -1; echo "<ol>"; foreach ($this->posts as $post) { if ('' != trim($post)) { ++$i; unset($post_categories); // Take the pings out first preg_match("|(-----\n\nPING:.*)|s", $post, $pings); $post = preg_replace("|(-----\n\nPING:.*)|s", '', $post); // Then take the comments out preg_match("|(-----\nCOMMENT:.*)|s", $post, $comments); $post = preg_replace("|(-----\nCOMMENT:.*)|s", '', $post); // We ignore the keywords $post = preg_replace("|(-----\nKEYWORDS:.*)|s", '', $post); // We want the excerpt preg_match("|-----\nEXCERPT:(.*)|s", $post, $excerpt); $excerpt = $wpdb->escape(trim($excerpt[1])); $post = preg_replace("|(-----\nEXCERPT:.*)|s", '', $post); // We're going to put extended body into main body with a more tag preg_match("|-----\nEXTENDED BODY:(.*)|s", $post, $extended); $extended = trim($extended[1]); if ('' != $extended) { $extended = "\n<!--more-->\n{$extended}"; } $post = preg_replace("|(-----\nEXTENDED BODY:.*)|s", '', $post); // Now for the main body preg_match("|-----\nBODY:(.*)|s", $post, $body); $body = trim($body[1]); $post_content = $wpdb->escape($body . $extended); $post = preg_replace("|(-----\nBODY:.*)|s", '', $post); // Grab the metadata from what's left $metadata = explode("\n", $post); foreach ($metadata as $line) { preg_match("/^(.*?):(.*)/", $line, $token); $key = trim($token[1]); $value = trim($token[2]); // Now we decide what it is and what to do with it switch ($key) { case '': break; case 'AUTHOR': $post_author = $value; break; case 'TITLE': $post_title = $wpdb->escape($value); break; case 'STATUS': // "publish" and "draft" enumeration items match up; no change required $post_status = $value; if (empty($post_status)) { $post_status = 'publish'; } break; case 'ALLOW COMMENTS': $post_allow_comments = $value; if ($post_allow_comments == 1) { $comment_status = 'open'; } else { $comment_status = 'closed'; } break; case 'CONVERT BREAKS': $post_convert_breaks = $value; break; case 'ALLOW PINGS': $post_allow_pings = trim($meta[2][0]); if ($post_allow_pings == 1) { $post_allow_pings = 'open'; } else { $post_allow_pings = 'closed'; } break; case 'PRIMARY CATEGORY': if (!empty($value)) { $post_categories[] = $wpdb->escape($value); } break; case 'CATEGORY': if (!empty($value)) { $post_categories[] = $wpdb->escape($value); } break; case 'DATE': $post_modified = strtotime($value); $post_modified = date('Y-m-d H:i:s', $post_modified); $post_modified_gmt = get_gmt_from_date("{$post_modified}"); $post_date = $post_modified; $post_date_gmt = $post_modified_gmt; break; default: // echo "\n$key: $value"; break; } // end switch } // End foreach // Let's check to see if it's in already if ($post_id = post_exists($post_title, '', $post_date)) { echo '<li>'; printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title)); } else { echo '<li>'; printf(__('Importing post <i>%s</i>...'), stripslashes($post_title)); $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt'); $post_id = wp_insert_post($postdata); // Add categories. if (0 != count($post_categories)) { wp_create_categories($post_categories, $post_id); } } $comment_post_ID = $post_id; // Now for comments $comments = explode("-----\nCOMMENT:", $comments[0]); $num_comments = 0; foreach ($comments as $comment) { if ('' != trim($comment)) { // Author preg_match("|AUTHOR:(.*)|", $comment, $comment_author); $comment_author = $wpdb->escape(trim($comment_author[1])); $comment = preg_replace('|(\\n?AUTHOR:.*)|', '', $comment); preg_match("|EMAIL:(.*)|", $comment, $comment_author_email); $comment_author_email = $wpdb->escape(trim($comment_author_email[1])); $comment = preg_replace('|(\\n?EMAIL:.*)|', '', $comment); preg_match("|IP:(.*)|", $comment, $comment_author_IP); $comment_author_IP = trim($comment_author_IP[1]); $comment = preg_replace('|(\\n?IP:.*)|', '', $comment); preg_match("|URL:(.*)|", $comment, $comment_author_url); $comment_author_url = $wpdb->escape(trim($comment_author_url[1])); $comment = preg_replace('|(\\n?URL:.*)|', '', $comment); preg_match("|DATE:(.*)|", $comment, $comment_date); $comment_date = trim($comment_date[1]); $comment_date = date('Y-m-d H:i:s', strtotime($comment_date)); $comment = preg_replace('|(\\n?DATE:.*)|', '', $comment); $comment_content = $wpdb->escape(trim($comment)); $comment_content = str_replace('-----', '', $comment_content); // Check if it's already there if (!comment_exists($comment_author, $comment_date)) { $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content'); $commentdata = wp_filter_comment($commentdata); wp_insert_comment($commentdata); $num_comments++; } } } if ($num_comments) { printf(__('(%s comments)'), $num_comments); } // Finally the pings // fix the double newline on the first one $pings[0] = str_replace("-----\n\n", "-----\n", $pings[0]); $pings = explode("-----\nPING:", $pings[0]); $num_pings = 0; foreach ($pings as $ping) { if ('' != trim($ping)) { // 'Author' preg_match("|BLOG NAME:(.*)|", $ping, $comment_author); $comment_author = $wpdb->escape(trim($comment_author[1])); $ping = preg_replace('|(\\n?BLOG NAME:.*)|', '', $ping); preg_match("|IP:(.*)|", $ping, $comment_author_IP); $comment_author_IP = trim($comment_author_IP[1]); $ping = preg_replace('|(\\n?IP:.*)|', '', $ping); preg_match("|URL:(.*)|", $ping, $comment_author_url); $comment_author_url = $wpdb->escape(trim($comment_author_url[1])); $ping = preg_replace('|(\\n?URL:.*)|', '', $ping); preg_match("|DATE:(.*)|", $ping, $comment_date); $comment_date = trim($comment_date[1]); $comment_date = date('Y-m-d H:i:s', strtotime($comment_date)); $ping = preg_replace('|(\\n?DATE:.*)|', '', $ping); preg_match("|TITLE:(.*)|", $ping, $ping_title); $ping_title = $wpdb->escape(trim($ping_title[1])); $ping = preg_replace('|(\\n?TITLE:.*)|', '', $ping); $comment_content = $wpdb->escape(trim($ping)); $comment_content = str_replace('-----', '', $comment_content); $comment_content = "<strong>{$ping_title}</strong>\n\n{$comment_content}"; $comment_type = 'trackback'; // Check if it's already there if (!comment_exists($comment_author, $comment_date)) { $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type'); $commentdata = wp_filter_comment($commentdata); wp_insert_comment($commentdata); $num_pings++; } } } if ($num_pings) { printf(__('(%s pings)'), $num_pings); } echo "</li>"; } flush(); } echo '</ol>'; wp_import_cleanup($this->id); echo '<h3>' . sprintf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')) . '</h3>'; }
/** * Performs post-import cleanup of files and the cache */ function import_end() { wp_import_cleanup($this->id); wp_defer_term_counting(false); wp_defer_comment_counting(false); wp_cache_flush(); $taxonomies = get_taxonomies(); foreach ($taxonomies as $tax) { delete_option("{$tax}_children"); _get_term_hierarchy($tax); $args = array('hide_empty' => 0, 'fields' => 'ids'); $terms = get_terms($tax, $args); if (is_array($terms) && !empty($terms)) { wp_update_term_count_now($terms, $tax); } } do_action('import_end'); }
function process_posts() { if (!($fp = fopen($this->file, "r"))) { echo '<p><strong>' . __('Failed to open file.', 'wc2') . '</strong></p>'; wp_import_cleanup($this->id); return false; } global $wpdb; $wc2_item = WC2_DB_Item::get_instance(); //all delete //$wc2_item->delete_all_item_data(); //die(); $err = new WP_Error(); $sp = ","; $lines = array(); $buf = ''; while (!feof($fp)) { $temp = fgets($fp, 10240); if (0 == strlen($temp)) { continue; } $num = substr_count($temp, '"'); if (0 == $num % 2 && '' == $buf) { $lines[] = $temp; } elseif (1 == $num % 2 && '' == $buf) { $buf .= $temp; } elseif (0 == $num % 2 && '' != $buf) { $buf .= $temp; } elseif (1 == $num % 2 && '' != $buf) { $buf .= $temp; $lines[] = $buf; $buf = ''; } } fclose($fp); //Post data - fixed define('COL_POST_ID', 0); define('COL_POST_AUTHOR', 1); define('COL_POST_CONTENT', 2); define('COL_POST_TITLE', 3); define('COL_POST_EXCERPT', 4); define('COL_POST_STATUS', 5); define('COL_POST_COMMENT_STATUS', 6); define('COL_POST_PASSWORD', 7); define('COL_POST_NAME', 8); define('COL_POST_MODIFIED', 9); define('COL_POST_CATEGORY', 10); define('COL_POST_TAG', 11); define('COL_POST_CUSTOM_FIELD', 12); define('COL_ITEM_CODE', 13); define('COL_ITEM_NAME', 14); $item_base_column = $wc2_item->get_item_base_column(); $item_meta_column = $wc2_item->get_item_meta_column(); $item_sku_column = $wc2_item->get_item_sku_column(); $item_sku_meta_column = $wc2_item->get_item_sku_meta_column(); $system = wc2_get_option('system'); $this->encode_type = isset($system['csv_encode_type']) ? $system['csv_encode_type'] : 0; $start_col = 13; $sku_start_col = $start_col; foreach ((array) $item_base_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $sku_start_col++; } } foreach ((array) $item_meta_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $sku_start_col++; } } $post_status = array('publish', 'future', 'draft', 'pending', 'private'); $pre_item_code = ''; $item_id = 0; $sku_id = 1; $this->data_rows = count($lines); $this->success = 0; $this->false = 0; //Progressbar 処理件数SET echo '<script type="text/javascript">PG_Set_Max(' . $this->data_rows . ');</script>' . "\r\n"; ob_flush(); flush(); foreach ($lines as $row => $line) { $datas = array(); $datas = explode($sp, trim($line)); $this->values = array(); $buf = ''; foreach ($datas as $data) { $num = substr_count($data, '"'); if (0 == $num % 2 && '' == $buf) { if ('"' == substr($data, 0, 1)) { $data = substr($data, 1); } if ('"' == substr($data, -1)) { $data = substr($data, 0, -1); } $data = str_replace(array('""'), '"', $data); $this->values[] = false !== $data ? $data : ''; } elseif (1 == $num % 2 && '' == $buf) { $buf .= $data; } elseif (0 == $num % 2 && '' != $buf) { $buf .= $sp . $data; } elseif (1 == $num % 2 && '' != $buf) { $buf .= $sp . $data; if ('"' == substr($buf, 0, 1)) { $buf = substr($buf, 1); } if ('"' == substr($buf, -1)) { $buf = substr($buf, 0, -1); } $buf = str_replace(array('""'), '"', $buf); $this->values[] = false !== $buf ? $buf : ''; $buf = ''; } } if ('Post ID' == $this->values[COL_POST_ID]) { $this->data_rows -= 1; $this->progress_add(); continue; } if ($pre_item_code == $this->values[COL_ITEM_CODE] && WC2_Utils::is_blank($this->values[COL_POST_ID])) { $mode = 'add'; $post_id = ''; } else { $post_id = !WC2_Utils::is_blank($this->values[COL_POST_ID]) ? (int) $this->values[COL_POST_ID] : ''; if ($post_id) { $post_ob = get_post($post_id); if (!isset($post_ob->ID) || empty($post_ob)) { $this->error_log($row, __("Post-ID {$post_id} does not exist.", 'wc2')); $this->create_log(); $this->progress_add(); continue; } $mode = 'upd'; } else { $mode = 'add'; } } $wc2_item->set_the_post_id($post_id); //data_check foreach ($this->values as $key => $val) { $value = trim($val); switch ($key) { case COL_POST_ID: if (!preg_match("/^[0-9]+\$/", $value) && 0 != strlen($value)) { $this->error_log($row, __('A value of the Post-ID is abnormal.', 'wc2')); } break; case COL_POST_AUTHOR: case COL_POST_COMMENT_STATUS: case COL_POST_PASSWORD: case COL_POST_NAME: case COL_POST_TITLE: case COL_POST_CONTENT: case COL_POST_EXCERPT: break; case COL_POST_STATUS: if (0 == strlen($value) || !in_array($value, $post_status)) { $this->error_log($row, __('A value of the display status is abnormal.', 'wc2')); } break; case COL_POST_MODIFIED: if ('future' == $this->values[COL_POST_STATUS] && (0 == strlen($value) || '0000-00-00 00:00:00' == $value)) { if (preg_match($date_pattern, $value, $match)) { if (checkdate($match[2], $match[3], $match[1]) && (0 < $match[4] && 24 > $match[4]) && (0 < $match[5] && 60 > $match[5]) && (0 < $match[6] && 60 > $match[6])) { } else { $this->error_log($row, __('A value of the schedule is abnormal.', 'wc2')); } } else { $this->error_log($row, __('A value of the schedule is abnormal.', 'wc2')); } } else { if (0 != strlen($value) && '0000-00-00 00:00:00' != $value) { if (preg_match("/^[0-9]+\$/", substr($value, 0, 4))) { if (strtotime($value) === false) { $this->error_log($row, __('A value of the schedule is abnormal.', 'wc2')); } } else { $datetime = explode(' ', $value); $date_str = $this->dates_interconv($datetime[0]) . ' ' . $datetime[1]; if (strtotime($date_str) === false) { $this->error_log($row, __('A value of the schedule is abnormal.', 'wc2')); } } } } break; case COL_POST_CATEGORY: if (0 == strlen($value)) { $this->error_log($row, __('A category is non-input.', 'wc2')); } break; case COL_POST_TAG: case COL_POST_CUSTOM_FIELD: break; case COL_ITEM_CODE: if (0 == strlen($value)) { $this->error_log($row, __('An item code is non-input.', 'wc2')); } else { $post_ids = $wc2_item->get_some_post_ids_by_item_code($value); if ('upd' == $mode) { if (1 < count($post_ids)) { $this->error_log($row, __('This Item-Code has been duplicated.', 'wc2')); foreach ($post_ids as $res_val) { $this->error_log($row, "item_code=" . $value . ", post_id=" . $res_val['item_post_id']); } } elseif (1 === count($post_ids)) { if ($post_ids[0]['item_post_id'] != $post_id) { $this->error_log($row, __('This Item-Code has already been used.', 'wc2')); $this->error_log($row, "item_code=" . $value . ", post_id=" . $post_ids[0]['item_post_id']); } } } else { if ('add' == $mode) { if ($value != $pre_item_code) { if (0 < count($post_ids)) { $this->error_log($row, __('This Item-Code has already been used.', 'wc2')); foreach ($post_ids as $res_val) { $this->error_log($row, "item_code=" . $value . ", post_id=" . $res_val['item_post_id']); } } } } } } break; case COL_ITEM_NAME: if (0 == strlen($value)) { $this->error_log($row, __('An item name is non-input.', 'wc2')); } break; } } //表示する Item column をエラーチェック $check_num = $start_col; foreach ($item_base_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $check_column[$key] = $check_num; $check_num++; } } foreach ($item_meta_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $check_column[$key] = $check_num; $check_num++; } } foreach ($item_sku_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $check_column[$key] = $check_num; $check_num++; } } foreach ($item_sku_meta_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $check_column[$key] = $check_num; $check_num++; } } foreach ($check_column as $column_key => $data_num) { switch ($column_key) { case ITEM_PRODUCT_TYPE: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Product type is abnormal.', 'wc2')); } break; case ITEM_CHARGES_TYPE: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Billing type is abnormal.', 'wc2')); } break; case ITEM_PURCHASE_LIMIT_LOWEST: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Purchase limit(lowest) is abnormal.', 'wc2')); } break; case ITEM_PURCHASE_LIMIT_HIGHEST: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Purchase limit(highest) is abnormal.', 'wc2')); } break; case ITEM_POINT_RATE: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the point rate is abnormal.', 'wc2')); } break; case ITEM_QUANTITY_DISCOUNT_NUM1: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount1(number) is abnormal.', 'wc2')); } break; case ITEM_QUANTITY_DISCOUNT_RATE1: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount1(rate) is abnormal.', 'wc2')); } break; case ITEM_QUANTITY_DISCOUNT_NUM2: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount2(number) is abnormal.', 'wc2')); } break; case ITEM_QUANTITY_DISCOUNT_RATE2: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount2(rate) is abnormal.', 'wc2')); } break; case ITEM_QUANTITY_DISCOUNT_NUM3: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount3(number) is abnormal.', 'wc2')); } break; case ITEM_QUANTITY_DISCOUNT_RATE3: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount3(rate) is abnormal.', 'wc2')); } break; case ITEM_SKU_CODE: if (0 == strlen($this->values[$data_num])) { $this->error_log($row, __('A SKU code is non-input.', 'wc2')); } break; case ITEM_SKU_NAME: case ITEM_SKU_UNIT: break; case ITEM_SKU_STOCK: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the SKU stock is abnormal.', 'wc2')); } break; case ITEM_SKU_STATUS: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the SKU status is abnormal.', 'wc2')); } break; case ITEM_SKU_PRICE: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the SKU price is abnormal.', 'wc2')); } break; case ITEM_SKU_COSTPRICE: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the SKU cost price is abnormal.', 'wc2')); } break; case ITEM_SKU_LISTPRICE: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the SKU list price is abnormal.', 'wc2')); } break; case ITEM_SKU_SET_QUANTITY_DISCOUNT: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount applies is abnormal.', 'wc2')); } break; } } if ('' != $this->get_log_line()) { $this->create_log(); $this->progress_add(); continue; } $post = array(); if ($pre_item_code != $this->values[COL_ITEM_CODE]) { $sku_id = 1; if ($this->values[COL_POST_MODIFIED] == '' || $this->values[COL_POST_MODIFIED] == '0000-00-00 00:00:00') { $post['post_date'] = current_time('mysql'); $post['post_date_gmt'] = current_time('mysql', 1); $post['post_modified'] = current_time('mysql'); $post['post_modified_gmt'] = current_time('mysql', 1); } else { if (preg_match("/^[0-9]+\$/", substr($this->values[COL_POST_MODIFIED], 0, 4))) { $time_data = strtotime($this->values[COL_POST_MODIFIED]); } else { $datetime = explode(' ', $this->values[COL_POST_MODIFIED]); $date_str = $this->dates_interconv($datetime[0]) . ' ' . $datetime[1]; $time_data = strtotime($date_str); } $post['post_date'] = date('Y-m-d H:i:s', $time_data); $post['post_date_gmt'] = gmdate('Y-m-d H:i:s', $time_data); $post['post_modified'] = date('Y-m-d H:i:s', $time_data); $post['post_modified_gmt'] = gmdate('Y-m-d H:i:s', $time_data); } if ('publish' == $this->values[COL_POST_STATUS]) { $now = current_time('mysql'); if (mysql2date('U', $post['post_modified'], false) > mysql2date('U', $now, false)) { $this->values[COL_POST_STATUS] = 'future'; } } elseif ('future' == $this->values[COL_POST_STATUS]) { $now = current_time('mysql'); if (mysql2date('U', $post['post_modified'], false) <= mysql2date('U', $now, false)) { $this->values[COL_POST_STATUS] = 'publish'; } } $post['ID'] = $post_id; $post['post_author'] = !WC2_Utils::is_blank($this->values[COL_POST_AUTHOR]) ? $this->values[COL_POST_AUTHOR] : 1; $post['post_content'] = $this->convert_encoding($this->values[COL_POST_CONTENT]); $post['post_title'] = $this->convert_encoding($this->values[COL_POST_TITLE]); $post['post_excerpt'] = $this->convert_encoding($this->values[COL_POST_EXCERPT]); $post['post_status'] = $this->values[COL_POST_STATUS]; $post['comment_status'] = !WC2_Utils::is_blank($this->values[COL_POST_COMMENT_STATUS]) ? $this->values[COL_POST_COMMENT_STATUS] : 'close'; $post['ping_status'] = 'close'; $post['post_password'] = '******' == $post['post_status'] ? '' : $this->values[COL_POST_PASSWORD]; $post['post_type'] = ITEM_POST_TYPE; $post['post_parent'] = 0; $post_name = sanitize_title($this->convert_encoding($this->values[COL_POST_NAME])); $post['post_name'] = wp_unique_post_slug($post_name, $post_id, $post['post_status'], $post['post_type'], $post['post_parent']); $post['to_ping'] = ''; $post['pinged'] = ''; $post['menu_order'] = 0; $post['post_content_filtered'] = ''; if (empty($post['post_name']) && !in_array($post['post_status'], array('draft', 'pending', 'auto-draft'))) { $post['post_name'] = sanitize_title($post['post_title'], $post_id); } if ($mode == 'add') { $post['guid'] = ''; if (false === $wpdb->insert($wpdb->posts, $post)) { $this->error_log($row, __('This data was not registered in the database.', 'wc2')); $pre_item_code = $this->values[COL_ITEM_CODE]; $this->create_log(); $this->progress_add(); continue; } $post_id = $wpdb->insert_id; $wc2_item->set_the_post_id($post_id); $where = array('ID' => $post_id); $wpdb->update($wpdb->posts, array('guid' => get_permalink($post_id)), $where); } elseif ($mode == 'upd') { $where = array('ID' => $post_id); if (false === $wpdb->update($wpdb->posts, $post, $where)) { $this->error_log($row, __('The data were not registered with a database.', 'wc2')); $pre_item_code = $this->values[COL_ITEM_CODE]; $this->create_log(); $this->progress_add(); continue; } //delete all metas of Item $meta_key_table = array(); $cfrows = explode(';', trim($this->values[COL_POST_CUSTOM_FIELD])); //if( !(1 === count($cfrows) && '' == reset($cfrows)) ) { if ('' != reset($cfrows)) { foreach ($cfrows as $cf) { list($meta_key, $meta_value) = explode('=', $cf, 2); if (!WC2_Utils::is_blank($meta_key)) { array_push($meta_key_table, $this->convert_encoding($meta_key)); } } } $meta_key_table = apply_filters('wc2_filter_importitem_delete_postmeta', $meta_key_table); $res = $wc2_item->delete_custome_field_key($meta_key_table); if (false === $res) { $this->error_log($row, __('Error : delete postmeta', 'wc2')); $pre_item_code = $this->values[COL_ITEM_CODE]; $this->create_log(); $this->progress_add(); continue; } //delete Item revisions $res = $wc2_item->delete_item_revision(); if (false === $res) { $this->error_log($row, __('Error : delete revisions', 'wc2')); $pre_item_code = $this->values[COL_ITEM_CODE]; $this->create_log(); $this->progress_add(); continue; } //delete relationships of category $res = $wc2_item->delete_term_relationship(); if (false === $res) { $this->error_log($row, __('Error : delete term_relationships(category)', 'wc2')); $pre_item_code = $this->values[COL_ITEM_CODE]; $this->create_log(); $this->progress_add(); continue; } //delete relationships of tag //$query = "SELECT term_taxonomy_id, COUNT(*) AS ct FROM {$wpdb->term_relationships} GROUP BY term_taxonomy_id"; //$relation_data = $wpdb->get_results( $query, ARRAY_A ); $relation_data = $wc2_item->get_count_term_taxonomy(); foreach ((array) $relation_data as $relation_rows) { $term_taxonomy_where['term_taxonomy_id'] = $relation_rows['term_taxonomy_id']; // $term_taxonomy_id['term_taxonomy_id'] = $relation_rows['term_taxonomy_id']; $term_taxonomy_updatas['count'] = $relation_rows['ct']; if (false === $wpdb->update($wpdb->term_taxonomy, $term_taxonomy_updatas, $term_taxonomy_where)) { $this->error_log($row, __('Error : delete term_relationships(tag)', 'wc2')); $pre_item_code = $this->values[COL_ITEM_CODE]; continue; } } } //add term_relationships, edit term_taxonomy //category $categories = explode(';', $this->values[COL_POST_CATEGORY]); $category_ids = array(); foreach ((array) $categories as $category) { $cat = get_term_by('slug', $category, 'item'); if ($cat == false) { $category = (string) $category; $this->error_log($row, __(sprintf('Since the category slug "%s" does not exist or could not be category registration.', $this->convert_encoding($category)), 'wc2')); continue; } $category_ids[] = $cat->term_id; } $term_taxonomy_ids = wp_set_post_terms($post_id, $category_ids, 'item'); foreach ($term_taxonomy_ids as $term_taxonomy_id) { $wc2_item->term_taxonomy_count_post($term_taxonomy_id); } //tag $tags_concat = str_replace(';', ',', $this->convert_encoding($this->values[COL_POST_TAG])); $term_taxonomy_ids = wp_set_post_terms($post_id, $tags_concat, 'item-tag'); foreach ($term_taxonomy_ids as $term_taxonomy_id) { $wc2_item->term_taxonomy_count_post($term_taxonomy_id); } //add custom field $cfrows = explode(';', trim($this->values[COL_POST_CUSTOM_FIELD])); //if( !(1 === count($cfrows) && '' == reset($cfrows)) ) { if ('' != reset($cfrows)) { $valstr = ''; foreach ($cfrows as $cf) { list($meta_key, $meta_value) = explode('=', $cf, 2); if (!WC2_Utils::is_blank($meta_key)) { update_post_meta($post_id, $this->convert_encoding($meta_key), $this->convert_encoding($meta_value)); } } } $wc2_item->clear_column(); //Item data set $col = $start_col; foreach ($item_base_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $wc2_item->set_the_item_value($key, $this->set_value($col, $column['type'])); $col++; } } foreach ($item_meta_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $wc2_item->set_the_item_value($key, $this->set_value($col, $column['type'])); $col++; } } //SKU data set $col = $sku_start_col; foreach ($item_sku_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $wc2_item->set_the_item_sku_value($key, $sku_id, $this->set_value($col, $column['type'])); $col++; } } foreach ($item_sku_meta_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $wc2_item->set_the_item_sku_value($key, $sku_id, $this->set_value($col, $column['type'])); $col++; } } if ($mode == 'add') { $wc2_item->add_item_data(); } elseif ($mode == 'upd') { $wc2_item->update_item_data(); } } else { //sku登録のみの行 $sku_id++; //SKU data set $col = $sku_start_col; foreach ($item_sku_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $wc2_item->set_the_item_sku_value($key, $sku_id, $this->set_value($col, $column['type'])); $col++; } } foreach ($item_sku_meta_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $wc2_item->set_the_item_sku_value($key, $sku_id, $this->set_value($col, $column['type'])); $col++; } } $item_id = $wc2_item->get_item_id_by_post_id($post_id); $sku_data = $wc2_item->get_item_sku_data($item_id, $sku_id); if (0 == $wc2_item->count_sku_data($sku_id)) { if (0 < $sku_id and '' != $wc2_item->get_the_item_sku_code($sku_id)) { $res = $wc2_item->add_item_sku_data($sku_id, $wc2_item->get_item_sku_data($item_id, $sku_id)); if (false === $res) { break; } } } else { $res = $wc2_item->update_item_sku_data($sku_id, $wc2_item->get_item_sku_data($item_id, $sku_id)); if (false === $res) { break; } } } if ('' != $this->get_log_line()) { $this->create_log(); } //登録成功数加算 $this->success += 1; $pre_item_code = $this->values[COL_ITEM_CODE]; clean_post_cache($post_id); wp_cache_delete($post_id, 'posts'); wp_cache_delete($post_id, 'post_meta'); clean_object_term_cache($post_id, 'post'); //進捗加算 $this->progress_add(); } wp_import_cleanup($this->id); $this->false = $this->data_rows - $this->success; echo '<h3>' . __('All Done.', 'wc2') . '</h3> <h3>' . sprintf(__('Success %d failure %d', 'wc2'), $this->success, $this->false) . '</h3>'; if (0 < strlen($this->log)) { WC2_Utils::wc2_log($this->log, "import_item.log"); echo str_replace("\n", "<br />", $this->log); } }
function process_posts() { global $wpdb; $i = -1; echo '<ol>'; foreach ($this->posts as $post) { // There are only ever one of these $post_title = $this->get_tag($post, 'title'); $post_date = $this->get_tag($post, 'wp:post_date'); $post_date_gmt = $this->get_tag($post, 'wp:post_date_gmt'); $comment_status = $this->get_tag($post, 'wp:comment_status'); $ping_status = $this->get_tag($post, 'wp:ping_status'); $post_status = $this->get_tag($post, 'wp:status'); $post_parent = $this->get_tag($post, 'wp:post_parent'); $post_type = $this->get_tag($post, 'wp:post_type'); $guid = $this->get_tag($post, 'guid'); $post_author = $this->get_tag($post, 'dc:creator'); $post_content = $this->get_tag($post, 'content:encoded'); $post_content = str_replace(array('<![CDATA[', ']]>'), '', $post_content); $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('\$1')", $post_content); $post_content = str_replace('<br>', '<br />', $post_content); $post_content = str_replace('<hr>', '<hr />', $post_content); preg_match_all('|<category>(.*?)</category>|is', $post, $categories); $categories = $categories[1]; $cat_index = 0; foreach ($categories as $category) { $categories[$cat_index] = $wpdb->escape($this->unhtmlentities(str_replace(array('<![CDATA[', ']]>'), '', $category))); $cat_index++; } if ($post_id = post_exists($post_title, '', $post_date)) { echo '<li>'; printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title)); } else { echo '<li>'; printf(__('Importing post <i>%s</i>...'), stripslashes($post_title)); $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt', 'guid', 'post_parent', 'post_type'); $comment_post_ID = $post_id = wp_insert_post($postdata); // Add categories. if (0 != count($categories)) { wp_create_categories($categories, $post_id); } } // Now for comments preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments); $comments = $comments[1]; $num_comments = 0; if ($comments) { foreach ($comments as $comment) { $comment_author = $this->get_tag($comment, 'wp:comment_author'); $comment_author_email = $this->get_tag($comment, 'wp:comment_author_email'); $comment_author_IP = $this->get_tag($comment, 'wp:comment_author_IP'); $comment_author_url = $this->get_tag($comment, 'wp:comment_author_url'); $comment_date = $this->get_tag($comment, 'wp:comment_date'); $comment_date_gmt = $this->get_tag($comment, 'wp:comment_date_gmt'); $comment_content = $this->get_tag($comment, 'wp:comment_content'); $comment_approved = $this->get_tag($comment, 'wp:comment_approved'); $comment_type = $this->get_tag($comment, 'wp:comment_type'); $comment_parent = $this->get_tag($comment, 'wp:comment_parent'); if (!comment_exists($comment_author, $comment_date)) { $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent'); wp_insert_comment($commentdata); $num_comments++; } } } if ($num_comments) { printf(' ' . __('(%s comments)'), $num_comments); } // Now for post meta preg_match_all('|<wp:postmeta>(.*?)</wp:postmeta>|is', $post, $postmeta); $postmeta = $postmeta[1]; if ($postmeta) { foreach ($postmeta as $p) { $key = $this->get_tag($p, 'wp:meta_key'); $value = $this->get_tag($p, 'wp:meta_value'); add_post_meta($post_id, $key, $value); } } $index++; } echo '</ol>'; wp_import_cleanup($this->id); echo '<h3>' . sprintf(__('All done.') . ' <a href="%s">' . __('Have fun!') . '</a>', get_option('home')) . '</h3>'; }
function import_end() { wp_import_cleanup($this->id); wp_cache_flush(); echo '<p>' . __('All done.', 'wordpress-importer') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'wordpress-importer') . '</a>' . '</p>'; }
/** * Performs post-import cleanup of files and the cache */ function import_end() { wp_import_cleanup($this->id); wp_cache_flush(); foreach (get_taxonomies() as $tax) { delete_option("{$tax}_children"); _get_term_hierarchy($tax); } wp_defer_term_counting(false); wp_defer_comment_counting(false); echo '<p>' . __('All done.', 'wordpress-importer') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'wordpress-importer') . '</a>' . '</p>'; echo '<p>' . __('Remember to update the passwords and roles of imported users.', 'wordpress-importer') . '</p>'; if ($this->one_click) { $main_menu = get_term_by('slug', 'main-menu', 'nav_menu'); $top_menu = get_term_by('slug', 'top-menu', 'nav_menu'); $footer_menu = get_term_by('slug', 'menu-footer', 'nav_menu'); $menu_locations = get_theme_mod('nav_menu_locations'); if ($main_menu) { $menu_locations['menu-header'] = $main_menu->term_id; } if ($top_menu) { $menu_locations['menu-top'] = $top_menu->term_id; } if ($footer_menu) { $menu_locations['menu-footer'] = $footer_menu->term_id; } set_theme_mod('nav_menu_locations', $menu_locations); if ($this->front_page) { update_option('page_on_front', $this->processed_posts[intval($this->front_page)]); update_option('show_on_front', 'page'); } $quick_setup = admin_url('admin.php?page=wpv_import'); echo <<<REDIRECT \t\t\t<script> \t\t\t\t/*<![CDATA[*/ \t\t\t\tsetTimeout(function() { \t\t\t\t\twindow.location = '{$quick_setup}'; \t\t\t\t}, 3000); \t\t\t\t/*]]>*/ \t\t\t</script> REDIRECT; } do_action('import_end'); }
/** * Import names from a csv file into directory */ function name_directory_import() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.', 'name-directory')); } global $wpdb; global $table_directory; global $table_directory_name; $directory_id = intval($_GET['dir']); $import_success = false; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $file = wp_import_handle_upload(); if (isset($file['error'])) { echo $file['error']; return; } $csv = array_map('str_getcsv', file($file['file'])); wp_import_cleanup($file['id']); array_shift($csv); $names_imported = 0; $names_duplicate = 0; foreach ($csv as $entry) { if (!($prepared_row = name_directory_prepared_import_row($entry))) { continue; } if (name_directory_name_exists_in_directory($prepared_row['name'], $directory_id)) { $names_duplicate++; continue; } $wpdb->insert($table_directory_name, array('directory' => $directory_id, 'name' => stripslashes_deep($prepared_row['name']), 'letter' => name_directory_get_first_char($prepared_row['name']), 'description' => stripslashes_deep($prepared_row['description']), 'published' => $prepared_row['published'], 'submitted_by' => $prepared_row['submitted_by']), array('%d', '%s', '%s', '%s', '%d', '%s')); $names_imported++; } $notice_class = 'updated'; $import_success = true; $import_message = sprintf(__('Imported %d entries in this directory', 'name-directory'), $names_imported); if ($names_imported === 0) { $notice_class = 'error'; $import_success = false; $import_message = __('Could not import any names into Name Directory', 'name-directory'); } if ($names_duplicate > 0) { $ignored = count($csv) == $names_duplicate ? __('all', 'name-directory') : $names_duplicate; echo '<div class="error" style="border-left: 4px solid #ffba00;"><p>' . sprintf(__('Ignored %s names, because they were duplicate (already in the directory)', 'name-directory'), $ignored) . '</p></div>'; } elseif ($names_imported === 0) { $import_message .= ', ' . __('please check your .csv-file', 'name-directory'); } echo '<div class="' . $notice_class . '"><p>' . $import_message . '</p></div>'; } $wp_file = admin_url('options-general.php'); $wp_page = $_GET['page']; $wp_sub = $_GET['sub']; $overview_url = sprintf("%s?page=%s", $wp_file, $wp_page); $wp_url_path = sprintf("%s?page=%s&sub=%s&dir=%d", $wp_file, $wp_page, $wp_sub, $directory_id); $wp_ndir_path = sprintf("%s?page=%s&sub=%s&dir=%d", $wp_file, $wp_page, 'manage-directory', $directory_id); $directory = $wpdb->get_row("SELECT * FROM " . $table_directory . " WHERE `id` = " . $directory_id, ARRAY_A); echo '<div class="wrap">'; echo '<h2>' . sprintf(__('Import names for %s', 'name-directory'), $directory['name']) . '</h2>'; echo '<div class="narrow"><p>'; if (!$import_success && empty($names_duplicate)) { echo __('Use the upload form below to upload a .csv-file containing all of your names (in the first column), description and submitter are optional.', 'name-directory') . ' '; echo '<h4>' . __('If you saved it from Excel or OpenOffice, please ensure that:', 'name-directory') . '</h4> '; echo '<ol><li>' . __('There is a header row (this contains the column names, the first row will NOT be imported)', 'name-directory'); echo '</li><li>' . __('Fields are encapsulated by double quotes', 'name-directory'); echo '</li><li>' . __('Fields are comma-separated', 'name-directory'); echo '</li></ol>'; echo '<h4>' . __('If uploading or importing fails, these are your options', 'name-directory') . ':</h4><ol><li>'; echo sprintf(__('Please check out %s first and ensure your file is formatted the same.', 'name-directory'), '<a href="http://plugins.svn.wordpress.org/name-directory/assets/name-directory-import-example.csv" target="_blank">' . __('the example import file', 'name-directory') . '</a>') . '</li>'; echo '<li> <a href="https://wiki.openoffice.org/wiki/Documentation/OOo3_User_Guides/Calc_Guide/Saving_spreadsheets#Saving_as_a_CSV_file">OpenOffice csv-export help</a> </li> <li> <a href="https://support.office.com/en-us/article/Import-or-export-text-txt-or-csv-files-e8ab9ff3-be8d-43f1-9d52-b5e8a008ba5c?CorrelationId=fa46399d-2d7a-40bd-b0a5-27b99e96cf68&ui=en-US&rs=en-US&ad=US#bmexport">Excel csv-export help</a> </li> <li> <a href="http://www.freefileconvert.com" target="_blank">' . __('Use an online File Convertor', 'name-directory') . '</a> </li><li>'; echo sprintf(__('If everything else fails, you can always ask a question at the %s.', 'name-directory'), '<a href="https://wordpress.org/support/plugin/name-directory" target="_blank">' . __('plugin support forums', 'name-directory') . '</a>') . ' '; echo '</li></ol></p>'; if (!function_exists('str_getcsv')) { echo '<div class="error"><p>'; echo __('Name Directory Import requires PHP 5.3, you seem to have in older version. Importing names will not work for your website.', 'name-directory'); echo '</p></div>'; } echo '<h3>' . __('Upload your .csv-file', 'name-directory') . '</h3>'; wp_import_upload_form($wp_url_path); } echo '</div></div>'; echo '<a href="' . $wp_ndir_path . '">' . sprintf(__('Back to %s', 'name-directory'), '<i>' . $directory['name'] . '</i>') . '</a>'; echo ' | '; echo '<a href="' . $overview_url . '">' . __('Go to Name Directory Overview', 'name-directory') . '</a>'; }
function process_posts() { $i = -1; echo '<ol>'; $numPosts = count($this->posts); //Kavinda: Uncomment the next line to test the import with only 10 post. //$numPosts = 10; for ($i = 0; $i < $numPosts; $i++) { $this->process_post($this->posts[$i]); } echo '</ol>'; wp_import_cleanup($this->id); // Write out a CSV file with URL mappings - this should persist beyond this import, // so write it out to disk ourselves if (count($this->old_new_post_mapping) > 0) { $output_filename = 'permalinkmap.csv'; // Delete old permalink file if (file_exists($output_filename)) { unlink($output_filename); } $csv_file_contents = "OldPermalink,NewPermalink\n"; foreach ($this->old_new_post_mapping as $key => $value) { // Append the items - escape any commas $csv_file_contents .= sprintf("%s,%s\n", str_replace(',', ',,', $key), str_replace(',', ',,', $value)); } $fhandle = fopen($output_filename, 'w'); fwrite($fhandle, $csv_file_contents); fclose($fhandle); echo '<a href="permalinkmap.csv">Click here to download a CSV file containing mappings from imported Permalinks to the new WordPress Permalinks</a><br />Note that this file is statically generated, it will need to be manually deleted.<br />'; } echo '<h3>' . sprintf(__('All done.') . ' <a href="%s">' . __('Have fun!') . '</a>', get_option('home')) . '</h3>'; }
function process_comments() { echo '<ol>'; // Parse the file: and act on comments as directed $this->get_entries(array(&$this, 'process_comment')); $this->process_orphan_comments(); // call it once to capture replies on the last post $this->process_orphan_comments(TRUE); // call it again to force import any remaining unmatched orphans echo '</ol>'; wp_import_cleanup($this->id); do_action('import_done', 'disqus-importer'); if ($this->num_comments) { echo '<h3>' . sprintf(_n('Imported %s comment.', 'Imported %s comments.', $this->num_comments, 'disqus-importer'), $this->num_comments) . '</h3>'; } if ($this->num_duplicates) { echo '<h3>' . sprintf(_n('Skipped %s duplicate.', 'Skipped %s duplicates.', $this->num_duplicates, 'disqus-importer'), $this->num_duplicates) . '</h3>'; } if ($this->num_uncertain) { echo '<h3>' . sprintf(_n('Could not determine the correct item to attach %s comment to.', 'Could not determine the correct item to attach %s comments to.', $this->num_uncertain, 'disqus-importer'), $this->num_uncertain) . '</h3>'; } echo '<h3>' . sprintf(__('All done.', 'disqus-importer') . ' <a href="%s">' . __('Have fun!', 'disqus-importer') . '</a>', get_option('home')) . '</h3>'; }
private function lastfmimport_upload() { $file = wp_import_handle_upload(); if (isset($file['error'])) { echo $file['error']; return; } $this->importfile = $file['file']; $this->extractzip(); $this->lastfmimport_import(); //if ( is_wp_error( $result ) ) // return $result; wp_import_cleanup($file['id']); $this->rm_r($this->tmpdir); $this->tmpdir = null; echo '<h3>'; printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')); echo '</h3>'; }
/** * Performs post-import cleanup of files and the cache */ function import_end() { wp_import_cleanup($this->id); wp_cache_flush(); foreach (get_taxonomies() as $tax) { delete_option("{$tax}_children"); _get_term_hierarchy($tax); } wp_defer_term_counting(false); wp_defer_comment_counting(false); echo '<p>' . __('All done.', 'wordpress-importer') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'wordpress-importer') . '</a></p>'; echo '<p>' . __('Remember to update the passwords and roles of imported users.', 'wordpress-importer') . '</p>'; do_action('import_end'); // deprecated do_action('tf_ext_import_end', array('version' => @$this->version, 'authors' => @$this->authors, 'posts' => @$this->posts, 'terms' => @$this->terms, 'categories' => @$this->categories, 'tags' => @$this->tags, 'base_url' => @$this->base_url, 'processed_authors' => @$this->processed_authors, 'author_mapping' => @$this->author_mapping, 'processed_terms' => @$this->processed_terms, 'processed_posts' => @$this->processed_posts, 'post_orphans' => @$this->post_orphans, 'processed_menu_items' => @$this->processed_menu_items, 'menu_item_orphans' => @$this->menu_item_orphans, 'missing_menu_items' => @$this->missing_menu_items, 'fetch_attachments' => @$this->fetch_attachments, 'url_remap' => @$this->url_remap, 'featured_images' => @$this->featured_images, 'old_site_url' => @$this->old_site_url, 'new_site_url' => @$this->new_site_url, 'upload_url_old' => @$this->upload_url_old, 'install_url' => @$this->install_url, 'tfuse_options' => @$this->tfuse_options)); }
function import() { $file = wp_import_handle_upload(); if ( isset($file['error']) ) { echo $file['error']; return; } $this->file = $file['file']; $this->import_posts(); wp_import_cleanup($file['id']); echo '<h3>'; printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')); echo '</h3>'; }
function process_posts() { global $wpdb; $handle = $this->fopen($this->file, 'r'); if ($handle == null) { return false; } $context = ''; $post = new StdClass(); $comment = new StdClass(); $comments = array(); $ping = new StdClass(); $pings = array(); echo "<div class='wrap'><ol>"; while ($line = $this->fgets($handle)) { $line = trim($line); if ('-----' == $line) { // Finishing a multi-line field if ('comment' == $context) { $comments[] = $comment; $comment = new StdClass(); } else { if ('ping' == $context) { $pings[] = $ping; $ping = new StdClass(); } } $context = ''; } else { if ('--------' == $line) { // Finishing a post. $context = ''; $result = $this->save_post($post, $comments, $pings); if (is_wp_error($result)) { return $result; } $post = new StdClass(); $comment = new StdClass(); $ping = new StdClass(); $comments = array(); $pings = array(); } else { if ('BODY:' == $line) { $context = 'body'; } else { if ('EXTENDED BODY:' == $line) { $context = 'extended'; } else { if ('EXCERPT:' == $line) { $context = 'excerpt'; } else { if ('KEYWORDS:' == $line) { $context = 'keywords'; } else { if ('COMMENT:' == $line) { $context = 'comment'; } else { if ('PING:' == $line) { $context = 'ping'; } else { if (0 === strpos($line, "AUTHOR:")) { $author = trim(substr($line, strlen("AUTHOR:"))); if ('' == $context) { $post->post_author = $author; } else { if ('comment' == $context) { $comment->comment_author = $author; } } } else { if (0 === strpos($line, "TITLE:")) { $title = trim(substr($line, strlen("TITLE:"))); if ('' == $context) { $post->post_title = $title; } else { if ('ping' == $context) { $ping->title = $title; } } } else { if (0 === strpos($line, "STATUS:")) { $status = trim(strtolower(substr($line, strlen("STATUS:")))); if (empty($status)) { $status = 'publish'; } $post->post_status = $status; } else { if (0 === strpos($line, "ALLOW COMMENTS:")) { $allow = trim(substr($line, strlen("ALLOW COMMENTS:"))); if ($allow == 1) { $post->comment_status = 'open'; } else { $post->comment_status = 'closed'; } } else { if (0 === strpos($line, "ALLOW PINGS:")) { $allow = trim(substr($line, strlen("ALLOW PINGS:"))); if ($allow == 1) { $post->ping_status = 'open'; } else { $post->ping_status = 'closed'; } } else { if (0 === strpos($line, "CATEGORY:")) { $category = trim(substr($line, strlen("CATEGORY:"))); if ('' != $category) { $post->categories[] = $category; } } else { if (0 === strpos($line, "PRIMARY CATEGORY:")) { $category = trim(substr($line, strlen("PRIMARY CATEGORY:"))); if ('' != $category) { $post->categories[] = $category; } } else { if (0 === strpos($line, "DATE:")) { $date = trim(substr($line, strlen("DATE:"))); $date = strtotime($date); $date = date('Y-m-d H:i:s', $date); $date_gmt = get_gmt_from_date($date); if ('' == $context) { $post->post_modified = $date; $post->post_modified_gmt = $date_gmt; $post->post_date = $date; $post->post_date_gmt = $date_gmt; } else { if ('comment' == $context) { $comment->comment_date = $date; } else { if ('ping' == $context) { $ping->comment_date = $date; } } } } else { if (0 === strpos($line, "EMAIL:")) { $email = trim(substr($line, strlen("EMAIL:"))); if ('comment' == $context) { $comment->comment_author_email = $email; } else { $ping->comment_author_email = ''; } } else { if (0 === strpos($line, "IP:")) { $ip = trim(substr($line, strlen("IP:"))); if ('comment' == $context) { $comment->comment_author_IP = $ip; } else { $ping->comment_author_IP = $ip; } } else { if (0 === strpos($line, "URL:")) { $url = trim(substr($line, strlen("URL:"))); if ('comment' == $context) { $comment->comment_author_url = $url; } else { $ping->comment_author_url = $url; } } else { if (0 === strpos($line, "BLOG NAME:")) { $blog = trim(substr($line, strlen("BLOG NAME:"))); $ping->comment_author = $blog; } else { // Processing multi-line field, check context. if (!empty($line)) { $line .= "\n"; } if ('body' == $context) { $post->post_content .= $line; } else { if ('extended' == $context) { $post->extended .= $line; } else { if ('excerpt' == $context) { $post->post_excerpt .= $line; } else { if ('keywords' == $context) { $post->post_keywords .= $line; } else { if ('comment' == $context) { $comment->comment_content .= $line; } else { if ('ping' == $context) { $ping->comment_content .= $line; } } } } } } } } } } } } } } } } } } } } } } } } } } } $this->fclose($handle); echo '</ol>'; wp_import_cleanup($this->id); do_action('import_done', 'mt'); echo '<h3>' . sprintf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')) . '</h3></div>'; }
/** * Handles the JSON upload and initial parsing of the file to prepare for * displaying author import options * * @return bool False if error uploading or invalid file, true otherwise */ private function handle_upload() { $file = trailingslashit(get_template_directory()) . "importer/data/wp_options.json"; $file_contents = file_get_contents($file); $this->import_data = json_decode($file_contents, true); set_transient($this->transient_key(), $this->import_data, DAY_IN_SECONDS); wp_import_cleanup($this->file_id); return $this->run_data_check(); }
function process_posts() { echo '<ol>'; $this->get_entries(array(&$this, 'process_post')); echo '</ol>'; wp_import_cleanup($this->id); do_action('import_done', 'wordpress'); echo '<h3>' . sprintf(__('All done.') . ' <a href="%s">' . __('Have fun!') . '</a>', get_option('home')) . '</h3>'; }
/** * Performs post-import cleanup of files and the cache */ function import_end() { wp_import_cleanup($this->id); wp_cache_flush(); foreach (get_taxonomies() as $tax) { delete_option("{$tax}_children"); _get_term_hierarchy($tax); } wp_defer_term_counting(false); wp_defer_comment_counting(false); echo '<p>' . __('All done.', 'nav-menu-roles') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'nav-menu-roles') . '</a>' . '</p>'; do_action('import_end'); }
/** * Performs post-import cleanup of files and the cache */ function import_end() { wp_import_cleanup($this->id); wp_cache_flush(); foreach (get_taxonomies() as $tax) { delete_option("{$tax}_children"); _get_term_hierarchy($tax); } wp_defer_term_counting(false); wp_defer_comment_counting(false); echo '<p>' . __('All done.', 'wordpress-importer') . '</p>'; do_action('import_end'); }
/** * Performs post-import cleanup of files and the cache */ function import_end() { wp_import_cleanup($this->id); wp_cache_flush(); foreach (get_taxonomies() as $tax) { delete_option("{$tax}_children"); _get_term_hierarchy($tax); } wp_defer_term_counting(false); wp_defer_comment_counting(false); update_option('cherry_sample_data', 1); do_action('import_end'); $this->log(date('Y-m-d H:i:s')); $this->log(PHP_EOL . 'Import end' . PHP_EOL); }
function process_posts() { ini_set("auto_detect_line_endings", true); $h = new RS_CSV_Helper(); $handle = $h->fopen($this->file, 'r'); if ($handle == false) { echo '<p><strong>' . __('Failed to open file.', 'really-simple-csv-importer') . '</strong></p>'; wp_import_cleanup($this->id); return false; } $is_first = true; $post_statuses = get_post_stati(); echo '<ol>'; while (($data = $h->fgetcsv($handle)) !== FALSE) { if ($is_first) { $h->parse_columns($this, $data); $is_first = false; } else { echo '<li>'; $post = array(); $is_update = false; $error = new WP_Error(); // (string) (required) post type $post_type = $h->get_data($this, $data, 'post_type'); if ($post_type) { if (post_type_exists($post_type)) { $post['post_type'] = $post_type; } else { $error->add('post_type_exists', sprintf(__('Invalid post type "%s".', 'really-simple-csv-importer'), $post_type)); } } else { echo __('Note: Please include post_type value if that is possible.', 'really-simple-csv-importer') . '<br>'; } // (int) post id $post_id = $h->get_data($this, $data, 'ID'); $post_id = $post_id ? $post_id : $h->get_data($this, $data, 'post_id'); if ($post_id) { $post_exist = get_post($post_id); if (is_null($post_exist)) { // if the post id is not exists $post['import_id'] = $post_id; } else { if (!$post_type || $post_exist->post_type == $post_type) { $post['ID'] = $post_id; $is_update = true; } else { $error->add('post_type_check', sprintf(__('The post type value from your csv file does not match the existing data in your database. post_id: %d, post_type(csv): %s, post_type(db): %s', 'really-simple-csv-importer'), $post_id, $post_type, $post_exist->post_type)); } } } // (string) post slug $post_name = $h->get_data($this, $data, 'post_name'); if ($post_name) { $post['post_name'] = $post_name; } // (login or ID) post_author $post_author = $h->get_data($this, $data, 'post_author'); if ($post_author) { if (is_numeric($post_author)) { $user = get_user_by('id', $post_author); } else { $user = get_user_by('login', $post_author); } if (isset($user) && is_object($user)) { $post['post_author'] = $user->ID; unset($user); } } // (string) publish date $post_date = $h->get_data($this, $data, 'post_date'); if ($post_date) { $post['post_date'] = date("Y-m-d H:i:s", strtotime($post_date)); } $post_date_gmt = $h->get_data($this, $data, 'post_date_gmt'); if ($post_date_gmt) { $post['post_date_gmt'] = date("Y-m-d H:i:s", strtotime($post_date_gmt)); } // (string) post status $post_status = $h->get_data($this, $data, 'post_status'); if ($post_status) { if (in_array($post_status, $post_statuses)) { $post['post_status'] = $post_status; } } // (string) post password $post_password = $h->get_data($this, $data, 'post_password'); if ($post_password) { $post['post_password'] = $post_password; } // (string) post title $post_title = $h->get_data($this, $data, 'post_title'); if ($post_title) { $post['post_title'] = $post_title; } // (string) post content $post_content = $h->get_data($this, $data, 'post_content'); if ($post_content) { $post['post_content'] = $post_content; } // (string) post excerpt $post_excerpt = $h->get_data($this, $data, 'post_excerpt'); if ($post_excerpt) { $post['post_excerpt'] = $post_excerpt; } // (int) post parent $post_parent = $h->get_data($this, $data, 'post_parent'); if ($post_parent) { $post['post_parent'] = $post_parent; } // (int) menu order $menu_order = $h->get_data($this, $data, 'menu_order'); if ($menu_order) { $post['menu_order'] = $menu_order; } // (string) comment status $comment_status = $h->get_data($this, $data, 'comment_status'); if ($comment_status) { $post['comment_status'] = $comment_status; } // (string, comma separated) slug of post categories $post_category = $h->get_data($this, $data, 'post_category'); if ($post_category) { $categories = preg_split("/,+/", $post_category); if ($categories) { $post['post_category'] = wp_create_categories($categories); } } // (string, comma separated) name of post tags $post_tags = $h->get_data($this, $data, 'post_tags'); if ($post_tags) { $post['post_tags'] = $post_tags; } // (string) post thumbnail image uri $post_thumbnail = $h->get_data($this, $data, 'post_thumbnail'); $meta = array(); $tax = array(); // add any other data to post meta foreach ($data as $key => $value) { if ($value !== false && isset($this->column_keys[$key])) { // check if meta is custom taxonomy if (substr($this->column_keys[$key], 0, 4) == 'tax_') { // (string, comma divided) name of custom taxonomies $customtaxes = preg_split("/,+/", $value); $taxname = substr($this->column_keys[$key], 4); $tax[$taxname] = array(); foreach ($customtaxes as $key => $value) { $tax[$taxname][] = $value; } } else { $meta[$this->column_keys[$key]] = $value; } } } /** * Filter post data. * * @param array $post (required) * @param bool $is_update */ $post = apply_filters('really_simple_csv_importer_save_post', $post, $is_update); /** * Filter meta data. * * @param array $meta (required) * @param array $post * @param bool $is_update */ $meta = apply_filters('really_simple_csv_importer_save_meta', $meta, $post, $is_update); /** * Filter taxonomy data. * * @param array $tax (required) * @param array $post * @param bool $is_update */ $tax = apply_filters('really_simple_csv_importer_save_tax', $tax, $post, $is_update); /** * Filter thumbnail URL or path. * * @since 1.3 * * @param string $post_thumbnail (required) * @param array $post * @param bool $is_update */ $post_thumbnail = apply_filters('really_simple_csv_importer_save_thumbnail', $post_thumbnail, $post, $is_update); /** * Option for dry run testing * * @since 0.5.7 * * @param bool false */ $dry_run = apply_filters('really_simple_csv_importer_dry_run', false); if (!$error->get_error_codes() && $dry_run == false) { /** * Get Alternative Importer Class name. * * @since 0.6 * * @param string Class name to override Importer class. Default to null (do not override). */ $class = apply_filters('really_simple_csv_importer_class', null); // save post data if ($class && class_exists($class, false)) { $importer = new $class(); $result = $importer->save_post($post, $meta, $tax, $post_thumbnail, $is_update); } else { $result = $this->save_post($post, $meta, $tax, $post_thumbnail, $is_update); } if ($result->isError()) { $error = $result->getError(); } else { $post_object = $result->getPost(); if (is_object($post_object)) { /** * Fires adter the post imported. * * @since 1.0 * * @param WP_Post $post_object */ do_action('really_simple_csv_importer_post_saved', $post_object); } echo esc_html(sprintf(__('Processing "%s" done.', 'really-simple-csv-importer'), $post_title)); } } // show error messages foreach ($error->get_error_messages() as $message) { echo esc_html($message) . '<br>'; } echo '</li>'; } } echo '</ol>'; $h->fclose($handle); wp_import_cleanup($this->id); echo '<h3>' . __('All Done.', 'really-simple-csv-importer') . '</h3>'; }
function process_posts() { $i = -1; echo '<ol>'; foreach ($this->posts as $post) { $result = $this->process_post($post); if (is_wp_error($result)) { return $result; } } echo '</ol>'; wp_import_cleanup($this->id); echo '<h3>' . sprintf(__('All done.') . ' <a href="%s">' . __('Have fun!') . '</a>', get_option('home')) . '</h3>'; }
function process_posts() { echo '<ol>'; $this->get_entries(array(&$this, 'process_post')); echo '</ol>'; wp_import_cleanup($this->id); do_action('import_done', 'wordpress'); echo '<p><a href="' . home_url() . '/wp-admin/nav-menus.php">We imported the dummy content for you! <br /><br />Just set up your menus and fill them out in the theme locations on the left of your menu page.</a></p>'; echo '<p>Don\'t forgett to set up the post message\'s under the categories.</p>'; echo '<h3><a href="' . home_url() . '">Have fun!</a></h3>'; }
function import() { $file = wp_import_handle_upload(); if ( isset($file['error']) ) { echo $file['error']; return; } $this->file = $file['file']; $result = $this->import_posts(); if ( is_wp_error( $result ) ) return $result; wp_import_cleanup($file['id']); do_action('import_done', 'blogware'); echo '<h3>'; printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')); echo '</h3>'; }
/** * Performs post-import cleanup of files and the cache */ function import_end() { wp_import_cleanup($this->id); wp_cache_flush(); foreach (get_taxonomies() as $tax) { delete_option("{$tax}_children"); _get_term_hierarchy($tax); } wp_defer_term_counting(false); wp_defer_comment_counting(false); echo '<p>' . __('All done.', 'radium') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'radium') . '</a>' . '</p>'; echo '<p>' . __('Remember to update the passwords and roles of imported users.', 'radium') . '</p>'; do_action('import_end'); }
/** * Performs post-import cleanup of files and the cache */ function import_end() { wp_import_cleanup($this->id); wp_cache_flush(); foreach (get_taxonomies() as $tax) { delete_option("{$tax}_children"); _get_term_hierarchy($tax); } wp_defer_term_counting(false); wp_defer_comment_counting(false); // This block lists the imported items (including ones that already exist(ed)) // and provides edit and preview links. if (!empty($this->processed_posts) && is_array($this->processed_posts)) { echo '<p>'; foreach ($this->processed_posts as $the_imported_article) { $the_imported_post = get_post($the_imported_article); printf(__('%s “<strong>%s</strong>” imported. ', 'anno'), ucfirst(esc_html($the_imported_post->post_type)), esc_html($the_imported_post->post_title)); if ($the_imported_post->post_type == 'attachment') { $preview_url = get_permalink($the_imported_post->ID); } else { $preview_url = get_permalink($the_imported_post->ID); if (is_ssl()) { $preview_url = str_replace('http://', 'https://', $preview_link); } $preview_url = add_query_arg('preview', 'true', $preview_url); } printf(__('[ %sEdit%s | %sPreview%s ]', 'anno'), '<a href="' . esc_url(get_edit_post_link($the_imported_post->ID)) . '">', '</a>', '<a href="' . esc_url($preview_url) . '">', '</a>.'); echo '<br />'; } echo '</p>'; } echo '<p>' . __('All done.', 'anno') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'anno') . '</a>' . '</p>'; echo '<p>' . __('Remember to update the passwords and roles of imported users.', 'anno') . '</p>'; do_action('import_end'); }