-
+ 87B5A1C98D186A17C15559C2D19CB9A1BC36A64EF9328B0E5FCB183FA8AB33E8C2EEE45671E975E7B81562201B17BAF1A19B584BE9C34278AC555DDF0DC1563F
mp-wp/wp-admin/includes/import.php
(0 . 0)(1 . 87)
34449 <?php
34450 /**
34451 * WordPress Administration Importer API.
34452 *
34453 * @package WordPress
34454 * @subpackage Administration
34455 */
34456
34457 /**
34458 * Retrieve list of importers.
34459 *
34460 * @since 2.0.0
34461 *
34462 * @return array
34463 */
34464 function get_importers() {
34465 global $wp_importers;
34466 if ( is_array($wp_importers) )
34467 uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
34468 return $wp_importers;
34469 }
34470
34471 /**
34472 * Register importer for WordPress.
34473 *
34474 * @since 2.0.0
34475 *
34476 * @param string $id Importer tag. Used to uniquely identify importer.
34477 * @param string $name Importer name and title.
34478 * @param string $description Importer description.
34479 * @param callback $callback Callback to run.
34480 * @return WP_Error Returns WP_Error when $callback is WP_Error.
34481 */
34482 function register_importer( $id, $name, $description, $callback ) {
34483 global $wp_importers;
34484 if ( is_wp_error( $callback ) )
34485 return $callback;
34486 $wp_importers[$id] = array ( $name, $description, $callback );
34487 }
34488
34489 /**
34490 * Cleanup importer.
34491 *
34492 * Removes attachment based on ID.
34493 *
34494 * @since 2.0.0
34495 *
34496 * @param string $id Importer ID.
34497 */
34498 function wp_import_cleanup( $id ) {
34499 wp_delete_attachment( $id );
34500 }
34501
34502 /**
34503 * Handle importer uploading and add attachment.
34504 *
34505 * @since 2.0.0
34506 *
34507 * @return array
34508 */
34509 function wp_import_handle_upload() {
34510 $overrides = array( 'test_form' => false, 'test_type' => false );
34511 $_FILES['import']['name'] .= '.import';
34512 $file = wp_handle_upload( $_FILES['import'], $overrides );
34513
34514 if ( isset( $file['error'] ) )
34515 return $file;
34516
34517 $url = $file['url'];
34518 $type = $file['type'];
34519 $file = addslashes( $file['file'] );
34520 $filename = basename( $file );
34521
34522 // Construct the object array
34523 $object = array( 'post_title' => $filename,
34524 'post_content' => $url,
34525 'post_mime_type' => $type,
34526 'guid' => $url
34527 );
34528
34529 // Save the data
34530 $id = wp_insert_attachment( $object, $file );
34531
34532 return array( 'file' => $file, 'id' => $id );
34533 }
34534
34535 ?>