mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-16 23:00:21 +00:00
Trailing whitespace cleanup
git-svn-id: https://develop.svn.wordpress.org/trunk@6726 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -9,10 +9,10 @@ class WP_Import {
|
||||
var $mtnames = array ();
|
||||
var $newauthornames = array ();
|
||||
var $allauthornames = array ();
|
||||
|
||||
|
||||
var $author_ids = array ();
|
||||
var $tags = array ();
|
||||
|
||||
|
||||
var $j = -1;
|
||||
var $fetch_attachments = false;
|
||||
var $url_remap = array ();
|
||||
@@ -51,25 +51,25 @@ class WP_Import {
|
||||
function has_gzip() {
|
||||
return is_callable('gzopen');
|
||||
}
|
||||
|
||||
|
||||
function fopen($filename, $mode='r') {
|
||||
if ( $this->has_gzip() )
|
||||
return gzopen($filename, $mode);
|
||||
return fopen($filename, $mode);
|
||||
}
|
||||
|
||||
|
||||
function feof($fp) {
|
||||
if ( $this->has_gzip() )
|
||||
return gzeof($fp);
|
||||
return feof($fp);
|
||||
}
|
||||
|
||||
|
||||
function fgets($fp, $len=8192) {
|
||||
if ( $this->has_gzip() )
|
||||
return gzgets($fp, $len);
|
||||
return fgets($fp, $len);
|
||||
}
|
||||
|
||||
|
||||
function fclose($fp) {
|
||||
if ( $this->has_gzip() )
|
||||
return gzclose($fp);
|
||||
@@ -86,7 +86,7 @@ class WP_Import {
|
||||
if ($fp) {
|
||||
while ( !$this->feof($fp) ) {
|
||||
$importline = rtrim($this->fgets($fp));
|
||||
|
||||
|
||||
// this doesn't check that the file is perfectly valid but will at least confirm that it's not the wrong format altogether
|
||||
if ( !$is_wxr_file && preg_match('|xmlns:wp="http://wordpress[.]org/export/\d+[.]\d+/"|', $importline) )
|
||||
$is_wxr_file = true;
|
||||
@@ -123,7 +123,7 @@ class WP_Import {
|
||||
return $is_wxr_file;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function get_wp_authors() {
|
||||
// We need to find unique values of author names, while preserving the order, so this function emulates the unique_value(); php function, without the sorting.
|
||||
$temp = $this->allauthornames;
|
||||
@@ -140,11 +140,11 @@ class WP_Import {
|
||||
|
||||
function get_authors_from_post() {
|
||||
global $current_user;
|
||||
|
||||
|
||||
// this will populate $this->author_ids with a list of author_names => user_ids
|
||||
|
||||
|
||||
foreach ( $_POST['author_in'] as $i => $in_author_name ) {
|
||||
|
||||
|
||||
if ( !empty($_POST['user_select'][$i]) ) {
|
||||
// an existing user was selected in the dropdown list
|
||||
$user = get_userdata( intval($_POST['user_select'][$i]) );
|
||||
@@ -153,26 +153,26 @@ class WP_Import {
|
||||
}
|
||||
elseif ( $this->allow_create_users() ) {
|
||||
// nothing was selected in the dropdown list, so we'll use the name in the text field
|
||||
|
||||
|
||||
$new_author_name = trim($_POST['user_create'][$i]);
|
||||
// if the user didn't enter a name, assume they want to use the same name as in the import file
|
||||
if ( empty($new_author_name) )
|
||||
$new_author_name = $in_author_name;
|
||||
|
||||
|
||||
$user_id = username_exists($new_author_name);
|
||||
if ( !$user_id ) {
|
||||
if ( !$user_id ) {
|
||||
$user_id = wp_create_user($new_author_name, 'changeme');
|
||||
}
|
||||
|
||||
|
||||
$this->author_ids[$in_author_name] = $user_id;
|
||||
}
|
||||
|
||||
|
||||
// failsafe: if the user_id was invalid, default to the current user
|
||||
if ( empty($this->author_ids[$in_author_name]) ) {
|
||||
$this->author_ids[$in_author_name] = intval($current_user->ID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function wp_authors_form() {
|
||||
@@ -196,10 +196,10 @@ class WP_Import {
|
||||
$this->users_form($j, $author);
|
||||
echo '</li>';
|
||||
}
|
||||
|
||||
|
||||
if ( $this->allow_fetch_attachments() ) {
|
||||
?>
|
||||
</ol>
|
||||
?>
|
||||
</ol>
|
||||
<h2><?php _e('Import Attachments'); ?></h2>
|
||||
<p>
|
||||
<input type="checkbox" value="1" name="attachments" id="import-attachments" />
|
||||
@@ -208,14 +208,14 @@ class WP_Import {
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
echo '<input type="submit" value="Submit">'.'<br />';
|
||||
echo '</form>';
|
||||
|
||||
}
|
||||
|
||||
|
||||
function users_form($n, $author) {
|
||||
|
||||
|
||||
if ( $this->allow_create_users() ) {
|
||||
printf(__('Create user %1$s or map to existing'), ' <input type="text" value="'.$author.'" name="'.'user_create['.intval($n).']'.'" maxlength="30"> <br />');
|
||||
}
|
||||
@@ -225,7 +225,7 @@ class WP_Import {
|
||||
|
||||
// keep track of $n => $author name
|
||||
echo '<input type="hidden" name="author_in['.intval($n).']" value="'.htmlspecialchars($author).'" />';
|
||||
|
||||
|
||||
$users = get_users_of_blog();
|
||||
?><select name="user_select[<?php echo $n; ?>]">
|
||||
<option value="0">- Select -</option>
|
||||
@@ -252,10 +252,10 @@ class WP_Import {
|
||||
// fetch the user ID for a given author name, respecting the mapping preferences
|
||||
function checkauthor($author) {
|
||||
global $current_user;
|
||||
|
||||
|
||||
if ( !empty($this->author_ids[$author]) )
|
||||
return $this->author_ids[$author];
|
||||
|
||||
|
||||
// failsafe: map to the current user
|
||||
return $current_user->ID;
|
||||
}
|
||||
@@ -334,7 +334,7 @@ class WP_Import {
|
||||
|
||||
function process_post($post) {
|
||||
global $wpdb;
|
||||
|
||||
|
||||
$post_ID = (int) $this->get_tag( $post, 'wp:post_id' );
|
||||
if ( $post_ID && !empty($this->post_ids_processed[$post_ID]) ) // Processed already
|
||||
return 0;
|
||||
@@ -357,7 +357,7 @@ class WP_Import {
|
||||
$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 domain="tag">(.*?)</category>|is', $post, $tags);
|
||||
$tags = $tags[1];
|
||||
|
||||
@@ -377,7 +377,7 @@ class WP_Import {
|
||||
}
|
||||
|
||||
$post_exists = post_exists($post_title, '', $post_date);
|
||||
|
||||
|
||||
if ( $post_exists ) {
|
||||
echo '<li>';
|
||||
printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
|
||||
@@ -405,7 +405,7 @@ class WP_Import {
|
||||
$remote_url = $this->get_tag( $post, 'wp:attachment_url' );
|
||||
if ( !$remote_url )
|
||||
$remote_url = $guid;
|
||||
|
||||
|
||||
$comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url);
|
||||
if ( !$post_id or is_wp_error($post_id) )
|
||||
return $post_id;
|
||||
@@ -414,7 +414,7 @@ class WP_Import {
|
||||
printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
|
||||
$comment_post_ID = $post_id = wp_insert_post($postdata);
|
||||
}
|
||||
|
||||
|
||||
if ( is_wp_error( $post_id ) )
|
||||
return $post_id;
|
||||
|
||||
@@ -422,7 +422,7 @@ class WP_Import {
|
||||
if ( $post_id && $post_ID ) {
|
||||
$this->post_ids_processed[intval($post_ID)] = intval($post_id);
|
||||
}
|
||||
|
||||
|
||||
// Add categories.
|
||||
if (count($categories) > 0) {
|
||||
$post_cats = array();
|
||||
@@ -495,15 +495,15 @@ class WP_Import {
|
||||
$key = $this->get_tag( $p, 'wp:meta_key' );
|
||||
$value = $this->get_tag( $p, 'wp:meta_value' );
|
||||
$value = stripslashes($value); // add_post_meta() will escape.
|
||||
|
||||
|
||||
$this->process_post_meta($post_id, $key, $value);
|
||||
|
||||
} }
|
||||
|
||||
|
||||
do_action('import_post_added', $post_id);
|
||||
print "</li>\n";
|
||||
}
|
||||
|
||||
|
||||
function process_post_meta($post_id, $key, $value) {
|
||||
// the filter can return false to skip a particular metadata key
|
||||
$_key = apply_filters('import_post_meta_key', $key);
|
||||
@@ -512,7 +512,7 @@ class WP_Import {
|
||||
do_action('import_post_meta', $post_id, $_key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function process_attachment($postdata, $remote_url) {
|
||||
if ($this->fetch_attachments and $remote_url) {
|
||||
printf( __('Importing attachment <i>%s</i>... '), htmlspecialchars($remote_url) );
|
||||
@@ -524,7 +524,7 @@ class WP_Import {
|
||||
else {
|
||||
print '('.size_format(filesize($upload['file'])).')';
|
||||
}
|
||||
|
||||
|
||||
if ( $info = wp_check_filetype($upload['file']) ) {
|
||||
$postdata['post_mime_type'] = $info['type'];
|
||||
}
|
||||
@@ -532,13 +532,13 @@ class WP_Import {
|
||||
print __('Invalid file type');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$postdata['guid'] = $upload['url'];
|
||||
|
||||
// as per wp-admin/includes/upload.php
|
||||
$post_id = wp_insert_attachment($postdata, $upload['file']);
|
||||
wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) );
|
||||
|
||||
|
||||
// remap the thumbnail url. this isn't perfect because we're just guessing the original url.
|
||||
if ( preg_match('@^image/@', $info['type']) && $thumb_url = wp_get_attachment_thumb_url($post_id) ) {
|
||||
$parts = pathinfo($remote_url);
|
||||
@@ -546,17 +546,17 @@ class WP_Import {
|
||||
$name = basename($parts['basename'], ".{$ext}");
|
||||
$this->url_remap[$parts['dirname'] . '/' . $name . '.thumbnail.' . $ext] = $thumb_url;
|
||||
}
|
||||
|
||||
|
||||
return $post_id;
|
||||
}
|
||||
else {
|
||||
printf( __('Skipping attachment <i>%s</i>'), htmlspecialchars($remote_url) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function fetch_remote_file($post, $url) {
|
||||
$upload = wp_upload_dir($post['post_date']);
|
||||
|
||||
|
||||
// extract the file name and extension from the url
|
||||
$file_name = basename($url);
|
||||
|
||||
@@ -566,10 +566,10 @@ class WP_Import {
|
||||
echo $upload['error'];
|
||||
return new WP_Error( 'upload_dir_error', $upload['error'] );
|
||||
}
|
||||
|
||||
|
||||
// fetch the remote url and write it to the placeholder file
|
||||
$headers = wp_get_http($url, $upload['file']);
|
||||
|
||||
|
||||
// make sure the fetch was successful
|
||||
if ( $headers['response'] != '200' ) {
|
||||
@unlink($upload['file']);
|
||||
@@ -579,34 +579,34 @@ class WP_Import {
|
||||
@unlink($upload['file']);
|
||||
return new WP_Error( 'import_file_error', __('Remote file is incorrect size') );
|
||||
}
|
||||
|
||||
|
||||
$max_size = $this->max_attachment_size();
|
||||
if ( !empty($max_size) and filesize($upload['file']) > $max_size ) {
|
||||
@unlink($upload['file']);
|
||||
return new WP_Error( 'import_file_error', sprintf(__('Remote file is too large, limit is %s', size_format($max_size))) );
|
||||
}
|
||||
|
||||
|
||||
// keep track of the old and new urls so we can substitute them later
|
||||
$this->url_remap[$url] = $upload['url'];
|
||||
// if the remote url is redirected somewhere else, keep track of the destination too
|
||||
if ( $headers['x-final-location'] != $url )
|
||||
$this->url_remap[$headers['x-final-location']] = $upload['url'];
|
||||
|
||||
|
||||
return $upload;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// sort by strlen, longest string first
|
||||
function cmpr_strlen($a, $b) {
|
||||
return strlen($b) - strlen($a);
|
||||
}
|
||||
|
||||
|
||||
// update url references in post bodies to point to the new local files
|
||||
function backfill_attachment_urls() {
|
||||
|
||||
|
||||
// make sure we do the longest urls first, in case one is a substring of another
|
||||
uksort($this->url_remap, array(&$this, 'cmpr_strlen'));
|
||||
|
||||
|
||||
global $wpdb;
|
||||
foreach ($this->url_remap as $from_url => $to_url) {
|
||||
// remap urls in post_content
|
||||
@@ -615,11 +615,11 @@ class WP_Import {
|
||||
$result = $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, '%s', '%s') WHERE meta_key='enclosure'", $from_url, $to_url) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// update the post_parent of orphans now that we know the local id's of all parents
|
||||
function backfill_parents() {
|
||||
global $wpdb;
|
||||
|
||||
|
||||
foreach ($this->orphans as $child_id => $parent_id) {
|
||||
$local_child_id = $this->post_ids_processed[$child_id];
|
||||
$local_parent_id = $this->post_ids_processed[$parent_id];
|
||||
@@ -628,7 +628,7 @@ class WP_Import {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function is_valid_meta_key($key) {
|
||||
// skip _wp_attached_file metadata since we'll regenerate it from scratch
|
||||
if ( $key == '_wp_attached_file' )
|
||||
@@ -640,7 +640,7 @@ class WP_Import {
|
||||
function allow_create_users() {
|
||||
return apply_filters('import_allow_create_users', true);
|
||||
}
|
||||
|
||||
|
||||
// give the user the option of downloading and importing attached files
|
||||
function allow_fetch_attachments() {
|
||||
return apply_filters('import_allow_fetch_attachments', true);
|
||||
@@ -650,20 +650,20 @@ class WP_Import {
|
||||
// can be overridden with a filter - 0 means no limit
|
||||
return apply_filters('import_attachment_size_limit', 0);
|
||||
}
|
||||
|
||||
|
||||
function import_start() {
|
||||
wp_defer_term_counting(true);
|
||||
wp_defer_comment_counting(true);
|
||||
do_action('import_start');
|
||||
}
|
||||
|
||||
|
||||
function import_end() {
|
||||
do_action('import_end');
|
||||
|
||||
|
||||
// clear the caches after backfilling
|
||||
foreach ($this->post_ids_processed as $post_id)
|
||||
clean_post_cache($post_id);
|
||||
|
||||
|
||||
wp_defer_term_counting(false);
|
||||
wp_defer_comment_counting(false);
|
||||
}
|
||||
@@ -676,10 +676,10 @@ class WP_Import {
|
||||
$file = get_attached_file($this->id);
|
||||
$this->import_file($file);
|
||||
}
|
||||
|
||||
|
||||
function import_file($file) {
|
||||
$this->file = $file;
|
||||
|
||||
|
||||
$this->import_start();
|
||||
$this->get_authors_from_post();
|
||||
$this->get_entries();
|
||||
@@ -689,11 +689,11 @@ class WP_Import {
|
||||
$this->backfill_parents();
|
||||
$this->backfill_attachment_urls();
|
||||
$this->import_end();
|
||||
|
||||
|
||||
if ( is_wp_error( $result ) )
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
function handle_upload() {
|
||||
$file = wp_import_handle_upload();
|
||||
if ( isset($file['error']) ) {
|
||||
|
||||
Reference in New Issue
Block a user