]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/import.php
Wordpress 2.6.2
[autoinstalls/wordpress.git] / wp-admin / includes / import.php
1 <?php
2
3 function get_importers() {
4         global $wp_importers;
5         if ( is_array($wp_importers) )
6                 uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
7         return $wp_importers;
8 }
9
10 function register_importer( $id, $name, $description, $callback ) {
11         global $wp_importers;
12         if ( is_wp_error( $callback ) )
13                 return $callback;
14         $wp_importers[$id] = array ( $name, $description, $callback );
15 }
16
17 function wp_import_cleanup( $id ) {
18         wp_delete_attachment( $id );
19 }
20
21 function wp_import_handle_upload() {
22         $overrides = array( 'test_form' => false, 'test_type' => false );
23         $_FILES['import']['name'] .= '.import';
24         $file = wp_handle_upload( $_FILES['import'], $overrides );
25
26         if ( isset( $file['error'] ) )
27                 return $file;
28
29         $url = $file['url'];
30         $type = $file['type'];
31         $file = addslashes( $file['file'] );
32         $filename = basename( $file );
33
34         // Construct the object array
35         $object = array( 'post_title' => $filename,
36                 'post_content' => $url,
37                 'post_mime_type' => $type,
38                 'guid' => $url
39         );
40
41         // Save the data
42         $id = wp_insert_attachment( $object, $file );
43
44         return array( 'file' => $file, 'id' => $id );
45 }
46
47 ?>