| 47 | | function users_form($n) { |
|---|
| 48 | | global $wpdb, $testing; |
|---|
| 49 | | $users = $wpdb->get_results("SELECT user_login FROM $wpdb->users ORDER BY user_login"); |
|---|
| 50 | | ?><select name="userselect[<?php echo $n; ?>]"> |
|---|
| 51 | | <option value="#NONE#">- Select -</option> |
|---|
| 52 | | <?php |
|---|
| 53 | | foreach ($users as $user) { |
|---|
| 54 | | echo '<option value="'.$user->user_login.'">'.$user->user_login.'</option>'; |
|---|
| 55 | | } |
|---|
| 56 | | ?> |
|---|
| 57 | | </select> |
|---|
| 58 | | <?php |
|---|
| 59 | | } |
|---|
| 60 | | |
|---|
| 61 | | //function to check the authorname and do the mapping |
|---|
| 62 | | function checkauthor($author) { |
|---|
| 63 | | global $wpdb; |
|---|
| 64 | | //mtnames is an array with the names in the mt import file |
|---|
| 65 | | $pass = 'changeme'; |
|---|
| 66 | | if (!(in_array($author, $this->mtnames))) { //a new mt author name is found |
|---|
| 67 | | ++ $this->j; |
|---|
| 68 | | $this->mtnames[$this->j] = $author; //add that new mt author name to an array |
|---|
| 69 | | $user_id = username_exists($this->newauthornames[$this->j]); //check if the new author name defined by the user is a pre-existing wp user |
|---|
| 70 | | if (!$user_id) { //banging my head against the desk now. |
|---|
| 71 | | if ($this->newauthornames[$this->j] == 'left_blank') { //check if the user does not want to change the authorname |
|---|
| 72 | | $user_id = wp_create_user($author, $pass); |
|---|
| 73 | | $this->newauthornames[$this->j] = $author; //now we have a name, in the place of left_blank. |
|---|
| 74 | | } else { |
|---|
| 75 | | $user_id = wp_create_user($this->newauthornames[$this->j], $pass); |
|---|
| 76 | | } |
|---|
| 77 | | } else { |
|---|
| 78 | | return $user_id; // return pre-existing wp username if it exists |
|---|
| 79 | | } |
|---|
| 80 | | } else { |
|---|
| 81 | | $key = array_search($author, $this->mtnames); //find the array key for $author in the $mtnames array |
|---|
| 82 | | $user_id = username_exists($this->newauthornames[$key]); //use that key to get the value of the author's name from $newauthornames |
|---|
| 83 | | } |
|---|
| 84 | | |
|---|
| 85 | | return $user_id; |
|---|
| | 50 | function has_gzip() { |
|---|
| | 51 | return is_callable('gzopen'); |
|---|
| | 52 | } |
|---|
| | 53 | |
|---|
| | 54 | function fopen($filename, $mode='r') { |
|---|
| | 55 | if ( $this->has_gzip() ) |
|---|
| | 56 | return gzopen($filename, $mode); |
|---|
| | 57 | return fopen($filename, $mode); |
|---|
| | 58 | } |
|---|
| | 59 | |
|---|
| | 60 | function feof($fp) { |
|---|
| | 61 | if ( $this->has_gzip() ) |
|---|
| | 62 | return gzeof($fp); |
|---|
| | 63 | return feof($fp); |
|---|
| | 64 | } |
|---|
| | 65 | |
|---|
| | 66 | function fgets($fp, $len=8192) { |
|---|
| | 67 | if ( $this->has_gzip() ) |
|---|
| | 68 | return gzgets($fp, $len); |
|---|
| | 69 | return fgets($fp, $len); |
|---|
| | 70 | } |
|---|
| | 71 | |
|---|
| | 72 | function fclose($fp) { |
|---|
| | 73 | if ( $this->has_gzip() ) |
|---|
| | 74 | return gzclose($fp); |
|---|
| | 75 | return fclose($fp); |
|---|
| 148 | | $formnames = array (); |
|---|
| 149 | | $selectnames = array (); |
|---|
| 150 | | |
|---|
| 151 | | foreach ($_POST['user'] as $key => $line) { |
|---|
| 152 | | $newname = trim(stripslashes($line)); |
|---|
| 153 | | if ($newname == '') |
|---|
| 154 | | $newname = 'left_blank'; //passing author names from step 1 to step 2 is accomplished by using POST. left_blank denotes an empty entry in the form. |
|---|
| 155 | | array_push($formnames, "$newname"); |
|---|
| 156 | | } // $formnames is the array with the form entered names |
|---|
| 157 | | |
|---|
| 158 | | foreach ($_POST['userselect'] as $user => $key) { |
|---|
| 159 | | $selected = trim(stripslashes($key)); |
|---|
| 160 | | array_push($selectnames, "$selected"); |
|---|
| 161 | | } |
|---|
| 162 | | |
|---|
| 163 | | $count = count($formnames); |
|---|
| 164 | | for ($i = 0; $i < $count; $i ++) { |
|---|
| 165 | | if ($selectnames[$i] != '#NONE#') { //if no name was selected from the select menu, use the name entered in the form |
|---|
| 166 | | array_push($this->newauthornames, "$selectnames[$i]"); |
|---|
| 167 | | } else { |
|---|
| 168 | | array_push($this->newauthornames, "$formnames[$i]"); |
|---|
| | 142 | global $current_user; |
|---|
| | 143 | |
|---|
| | 144 | // this will populate $this->author_ids with a list of author_names => user_ids |
|---|
| | 145 | |
|---|
| | 146 | foreach ( $_POST['author_in'] as $i => $in_author_name ) { |
|---|
| | 147 | |
|---|
| | 148 | if ( !empty($_POST['user_select'][$i]) ) { |
|---|
| | 149 | // an existing user was selected in the dropdown list |
|---|
| | 150 | $user = get_userdata( intval($_POST['user_select'][$i]) ); |
|---|
| | 151 | if ( isset($user->ID) ) |
|---|
| | 152 | $this->author_ids[$in_author_name] = $user->ID; |
|---|
| | 153 | } |
|---|
| | 154 | elseif ( $this->allow_create_users() ) { |
|---|
| | 155 | // nothing was selected in the dropdown list, so we'll use the name in the text field |
|---|
| | 156 | |
|---|
| | 157 | $new_author_name = trim($_POST['user_create'][$i]); |
|---|
| | 158 | // if the user didn't enter a name, assume they want to use the same name as in the import file |
|---|
| | 159 | if ( empty($new_author_name) ) |
|---|
| | 160 | $new_author_name = $in_author_name; |
|---|
| | 161 | |
|---|
| | 162 | $user_id = username_exists($new_author_name); |
|---|
| | 163 | if ( !$user_id ) { |
|---|
| | 164 | $user_id = wp_create_user($new_author_name, 'changeme'); |
|---|
| | 165 | } |
|---|
| | 166 | |
|---|
| | 167 | $this->author_ids[$in_author_name] = $user_id; |
|---|
| | 168 | } |
|---|
| | 169 | |
|---|
| | 170 | // failsafe: if the user_id was invalid, default to the current user |
|---|
| | 171 | if ( empty($this->author_ids[$in_author_name]) ) { |
|---|
| | 172 | $this->author_ids[$in_author_name] = intval($current_user->ID); |
|---|
| | 216 | |
|---|
| | 217 | function users_form($n, $author) { |
|---|
| | 218 | |
|---|
| | 219 | if ( $this->allow_create_users() ) { |
|---|
| | 220 | printf(__('Create user %1$s or map to existing'), ' <input type="text" value="'.$author.'" name="'.'user_create['.intval($n).']'.'" maxlength="30"> <br />'); |
|---|
| | 221 | } |
|---|
| | 222 | else { |
|---|
| | 223 | echo __('Map to existing').'<br />'; |
|---|
| | 224 | } |
|---|
| | 225 | |
|---|
| | 226 | // keep track of $n => $author name |
|---|
| | 227 | echo '<input type="hidden" name="author_in['.intval($n).']" value="'.htmlspecialchars($author).'" />'; |
|---|
| | 228 | |
|---|
| | 229 | $users = get_users_of_blog(); |
|---|
| | 230 | ?><select name="user_select[<?php echo $n; ?>]"> |
|---|
| | 231 | <option value="0">- Select -</option> |
|---|
| | 232 | <?php |
|---|
| | 233 | foreach ($users as $user) { |
|---|
| | 234 | echo '<option value="'.$user->user_id.'">'.$user->user_login.'</option>'; |
|---|
| | 235 | } |
|---|
| | 236 | ?> |
|---|
| | 237 | </select> |
|---|
| | 238 | <?php |
|---|
| | 239 | } |
|---|
| 208 | | $this->get_entries(array(&$this, 'process_author')); |
|---|
| 209 | | $this->wp_authors_form(); |
|---|
| 210 | | } |
|---|
| | 242 | $is_wxr_file = $this->get_entries(array(&$this, 'process_author')); |
|---|
| | 243 | if ( $is_wxr_file ) { |
|---|
| | 244 | $this->wp_authors_form(); |
|---|
| | 245 | } |
|---|
| | 246 | else { |
|---|
| | 247 | echo '<h2>'.__('Invalid file').'</h2>'; |
|---|
| | 248 | echo '<p>'.__('Please upload a valid WXR (WordPress eXtended RSS) export file.').'</p>'; |
|---|
| | 249 | } |
|---|
| | 250 | } |
|---|
| | 251 | |
|---|
| | 252 | // fetch the user ID for a given author name, respecting the mapping preferences |
|---|
| | 253 | function checkauthor($author) { |
|---|
| | 254 | global $current_user; |
|---|
| | 255 | |
|---|
| | 256 | if ( !empty($this->author_ids[$author]) ) |
|---|
| | 257 | return $this->author_ids[$author]; |
|---|
| | 258 | |
|---|
| | 259 | // failsafe: map to the current user |
|---|
| | 260 | return $current_user->ID; |
|---|
| | 261 | } |
|---|
| | 262 | |
|---|
| | 263 | |
|---|
| 518 | | if ( $headers['response'] != '200' ) |
|---|
| 519 | | return new WP_Error( 'import_file_error', __(sprintf('Remote file returned error response %d', intval($headers['response']))) ); |
|---|
| 520 | | elseif ( isset($headers['content-length']) && filesize($upload['file']) != $headers['content-length'] ) |
|---|
| | 571 | if ( $headers['response'] != '200' ) { |
|---|
| | 572 | @unlink($upload['file']); |
|---|
| | 573 | return new WP_Error( 'import_file_error', sprintf(__('Remote file returned error response %d'), intval($headers['response'])) ); |
|---|
| | 574 | } |
|---|
| | 575 | elseif ( isset($headers['content-length']) && filesize($upload['file']) != $headers['content-length'] ) { |
|---|
| | 576 | @unlink($upload['file']); |
|---|
| | 636 | // give the user the option of creating new users to represent authors in the import file? |
|---|
| | 637 | function allow_create_users() { |
|---|
| | 638 | return apply_filters('import_allow_create_users', true); |
|---|
| | 639 | } |
|---|
| | 640 | |
|---|
| | 641 | // give the user the option of downloading and importing attached files |
|---|
| | 642 | function allow_fetch_attachments() { |
|---|
| | 643 | return apply_filters('import_allow_fetch_attachments', true); |
|---|
| | 644 | } |
|---|
| | 645 | |
|---|
| | 646 | function max_attachment_size() { |
|---|
| | 647 | // can be overridden with a filter - 0 means no limit |
|---|
| | 648 | return apply_filters('import_attachment_size_limit', 0); |
|---|
| | 649 | } |
|---|
| | 650 | |
|---|
| | 651 | |
|---|