Changeset 3093
- Timestamp:
- 11/15/05 23:39:32 (3 years ago)
- Files:
-
- trunk/wp-admin/admin-functions.php (modified) (1 diff)
- trunk/wp-admin/import/rss.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wp-admin/admin-functions.php
r3092 r3093 1731 1731 } 1732 1732 1733 function wp_import_cleanup($file) { 1734 wp_delete_attachment($file['id']); 1735 } 1736 1737 function wp_import_upload_form($action) { 1733 1738 ?> 1739 <script type="text/javascript"> 1740 function cancelUpload() { 1741 o = document.getElementById('uploadForm'); 1742 o.method = 'GET'; 1743 o.action.value = 'view'; 1744 o.submit(); 1745 } 1746 </script> 1747 <form enctype="multipart/form-data" id="uploadForm" method="POST" action="<?php echo $action ?>"> 1748 <label for="upload"><?php _e('File:'); ?></label><input type="file" id="upload" name="import" /> 1749 <input type="hidden" name="action" value="save" /> 1750 <div id="buttons"> 1751 <input type="submit" value="<?php _e('Import'); ?>" /> 1752 <input type="button" value="<?php _e('Cancel'); ?>" onclick="cancelUpload()" /> 1753 </div> 1754 </form> 1755 <?php 1756 } 1757 1758 function wp_import_handle_upload() { 1759 $overrides = array('test_form' => false, 'test_type' => false); 1760 $file = wp_handle_upload($_FILES['import'], $overrides); 1761 1762 if ( isset($file['error']) ) 1763 return $file; 1764 1765 $url = $file['url']; 1766 $file = $file['file']; 1767 $filename = basename($file); 1768 1769 // Construct the object array 1770 $object = array( 1771 'post_title' => $filename, 1772 'post_content' => $url, 1773 'post_mime_type' => 'import', 1774 'guid' => $url 1775 ); 1776 1777 // Save the data 1778 $id = wp_insert_attachment($object, $file); 1779 1780 return array('file' => $file, 'id' => $id); 1781 } 1782 1783 ?> trunk/wp-admin/import/rss.php
r3062 r3093 8 8 9 9 var $posts = array (); 10 var $file; 10 11 11 12 function header() { … … 25 26 26 27 function greet() { 27 _e("<p>Howdy! This importer allows you to extract posts from any RSS 2.0 file into your blog. This is useful if you want to import your posts from a system that is not handled by a custom import tool. To get started you must edit the following line in this file (<code>import/rss.php</code>) </p> 28 <p><code>define('RSSFILE', '');</code></p> 29 <p>You want to define where the RSS file we'll be working with is, for example: </p> 30 <p><code>define('RSSFILE', 'rss.xml');</code></p> 31 <p>You have to do this manually for security reasons. When you're done reload this page and we'll take you to the next step.</p>"); 32 if ('' != RSSFILE) 33 echo '<a href="admin.php?import=rss&step=1">' . __('Begin RSS Import »') . '</a>'; 28 _e("<p>Howdy! This importer allows you to extract posts from any RSS 2.0 file into your blog. This is useful if you want to import your posts from a system that is not handled by a custom import tool. Pick an RSS file to upload and click Import.</p>"); 29 wp_import_upload_form("admin.php?import=rss&step=1"); 34 30 } 35 31 … … 38 34 39 35 set_magic_quotes_runtime(0); 40 $datalines = file( RSSFILE); // Read the file into an array36 $datalines = file($this->file); // Read the file into an array 41 37 $importdata = implode('', $datalines); // squish it 42 38 $importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata); … … 116 112 } else { 117 113 $post_id = wp_insert_post($post); 118 if (!$post_id) 119 die(__("Couldn't get post ID")); 120 114 if (!$post_id) { 115 echo(__("Couldn't get post ID")); 116 return; 117 } 118 121 119 if (0 != count($categories)) 122 120 wp_create_categories($categories, $post_id); … … 131 129 132 130 function import() { 133 // FIXME: Don't die 134 if ('' == RSSFILE) 135 die("You must edit the RSSFILE line as described on the <a href='import-mt.php'>previous page</a> to continue."); 131 $file = wp_import_handle_upload(); 132 if ( isset($file['error']) ) { 133 echo $file['error']; 134 return; 135 } 136 136 137 if (!file_exists(RSSFILE)) 138 die("The file you specified does not seem to exist. Please check the path you've given."); 139 137 $this->file = $file['file']; 140 138 $this->get_posts(); 141 139 $this->import_posts(); 140 wp_import_cleanup($file); 141 142 142 echo '<h3>All done. <a href="' . get_option('home') . '">Have fun!</a></h3>'; 143 143 }
