2003-05-31 02:06:21 +02:00
< ? php
2008-08-14 08:30:38 +02:00
/**
* Links Import Administration Panel .
*
* @ package WordPress
* @ subpackage Administration
*/
/** Load WordPress Administration Bootstrap */
2008-11-29 19:09:09 +01:00
$parent_file = 'tools.php' ;
$submenu_file = 'import.php' ;
2006-11-18 08:31:29 +01:00
$title = __ ( 'Import Blogroll' );
2003-05-31 02:06:21 +02:00
2008-11-29 19:23:03 +01:00
class OPML_Import {
2008-12-09 22:50:35 +01:00
function dispatch () {
2008-12-10 19:43:43 +01:00
global $wpdb , $user_ID ;
2010-02-22 20:48:38 +01:00
$step = isset ( $_POST [ 'step' ] ) ? $_POST [ 'step' ] : 0 ;
2003-05-31 02:06:21 +02:00
switch ( $step ) {
2007-02-27 16:24:54 +01:00
case 0 : {
2010-02-27 17:44:26 +01:00
include_once ( ABSPATH . 'wp-admin/admin-header.php' );
2007-02-27 16:24:54 +01:00
if ( ! current_user_can ( 'manage_links' ) )
wp_die ( __ ( 'Cheatin’ uh?' ));
2003-12-10 01:43:15 +01:00
2007-02-27 16:24:54 +01:00
$opmltype = 'blogrolling' ; // default.
2003-05-31 02:06:21 +02:00
?>
2003-12-08 04:46:42 +01:00
2003-05-31 02:06:21 +02:00
< div class = " wrap " >
2008-11-27 00:35:23 +01:00
< ? php screen_icon (); ?>
2005-11-14 10:42:44 +01:00
< h2 >< ? php _e ( 'Import your blogroll from another system' ) ?> </h2>
2008-12-10 19:22:56 +01:00
< form enctype = " multipart/form-data " action = " admin.php?import=opml " method = " post " name = " blogroll " >
2006-05-04 11:20:44 +02:00
< ? php wp_nonce_field ( 'import-bookmarks' ) ?>
2003-06-01 11:01:04 +02:00
2007-01-16 01:27:14 +01:00
< p >< ? php _e ( 'If a program or website you use allows you to export your links or subscriptions as OPML you may import them here.' ); ?> </p>
2005-11-14 10:42:44 +01:00
< div style = " width: 70%; margin: auto; height: 8em; " >
< input type = " hidden " name = " step " value = " 1 " />
2010-02-22 20:48:38 +01:00
< input type = " hidden " name = " MAX_FILE_SIZE " value = " <?php echo wp_max_upload_size(); ?> " />
2008-03-15 00:58:31 +01:00
< div style = " width: 48%; " class = " alignleft " >
2008-05-04 12:37:06 +02:00
< h3 >< label for = " opml_url " >< ? php _e ( 'Specify an OPML URL:' ); ?> </label></h3>
2009-04-18 08:47:56 +02:00
< input type = " text " name = " opml_url " id = " opml_url " size = " 50 " class = " code " style = " width: 90%; " value = " http:// " />
2005-11-14 10:42:44 +01:00
</ div >
2008-03-15 00:58:31 +01:00
< div style = " width: 48%; " class = " alignleft " >
2008-05-04 12:37:06 +02:00
< h3 >< label for = " userfile " >< ? php _e ( 'Or choose from your local disk:' ); ?> </label></h3>
2006-01-25 01:49:13 +01:00
< input id = " userfile " name = " userfile " type = " file " size = " 30 " />
2005-11-14 10:42:44 +01:00
</ div >
2003-12-10 01:43:15 +01:00
2005-11-14 10:42:44 +01:00
</ div >
2008-05-04 12:37:06 +02:00
< p style = " clear: both; margin-top: 1em; " >< label for = " cat_id " >< ? php _e ( 'Now select a category you want to put these links in.' ) ?> </label><br />
< ? php _e ( 'Category:' ) ?> <select name="cat_id" id="cat_id">
2003-05-31 02:06:21 +02:00
< ? php
2009-12-23 16:31:02 +01:00
$categories = get_terms ( 'link_category' , array ( 'get' => 'all' ));
2005-11-14 10:42:44 +01:00
foreach ( $categories as $category ) {
2003-05-31 02:06:21 +02:00
?>
2009-05-18 17:11:07 +02:00
< option value = " <?php echo $category->term_id ; ?> " >< ? php echo esc_html ( apply_filters ( 'link_category' , $category -> name )); ?> </option>
2003-05-31 02:06:21 +02:00
< ? php
2005-11-14 10:42:44 +01:00
} // end foreach
2003-05-31 02:06:21 +02:00
?>
2005-11-14 10:42:44 +01:00
</ select ></ p >
2003-06-01 11:01:04 +02:00
2009-05-05 21:43:53 +02:00
< p class = " submit " >< input type = " submit " name = " submit " value = " <?php esc_attr_e('Import OPML File') ?> " /></ p >
2005-11-14 10:42:44 +01:00
</ form >
2003-06-01 11:01:04 +02:00
2003-05-31 02:06:21 +02:00
</ div >
< ? php
2007-02-27 16:24:54 +01:00
break ;
} // end case 0
2003-05-31 02:06:21 +02:00
2007-02-27 16:24:54 +01:00
case 1 : {
2006-05-04 11:20:44 +02:00
check_admin_referer ( 'import-bookmarks' );
2006-03-31 01:12:54 +02:00
2010-02-27 17:44:26 +01:00
include_once ( ABSPATH . 'wp-admin/admin-header.php' );
2007-02-27 16:24:54 +01:00
if ( ! current_user_can ( 'manage_links' ) )
wp_die ( __ ( 'Cheatin’ uh?' ));
2003-05-31 02:06:21 +02:00
?>
< div class = " wrap " >
2003-06-01 11:01:04 +02:00
2007-02-27 16:24:54 +01:00
< h2 >< ? php _e ( 'Importing...' ) ?> </h2>
2003-05-31 02:06:21 +02:00
< ? php
2007-08-01 21:40:30 +02:00
$cat_id = abs ( ( int ) $_POST [ 'cat_id' ] );
if ( $cat_id < 1 )
2007-02-27 16:24:54 +01:00
$cat_id = 1 ;
$opml_url = $_POST [ 'opml_url' ];
if ( isset ( $opml_url ) && $opml_url != '' && $opml_url != 'http://' ) {
$blogrolling = true ;
} else { // try to get the upload file.
$overrides = array ( 'test_form' => false , 'test_type' => false );
2009-02-20 22:39:20 +01:00
$_FILES [ 'userfile' ][ 'name' ] .= '.txt' ;
2007-02-27 16:24:54 +01:00
$file = wp_handle_upload ( $_FILES [ 'userfile' ], $overrides );
if ( isset ( $file [ 'error' ]) )
wp_die ( $file [ 'error' ]);
$url = $file [ 'url' ];
$opml_url = $file [ 'file' ];
$blogrolling = false ;
}
2008-12-10 19:43:43 +01:00
global $opml , $updated_timestamp , $all_links , $map , $names , $urls , $targets , $descriptions , $feeds ;
2007-02-27 16:24:54 +01:00
if ( isset ( $opml_url ) && $opml_url != '' ) {
2007-05-10 23:21:54 +02:00
if ( $blogrolling === true ) {
$opml = wp_remote_fopen ( $opml_url );
} else {
$opml = file_get_contents ( $opml_url );
}
2007-06-14 04:25:30 +02:00
2008-08-14 08:30:38 +02:00
/** Load OPML Parser */
2010-02-27 17:44:26 +01:00
include_once ( ABSPATH . 'wp-admin/link-parse-opml.php' );
2007-02-27 16:24:54 +01:00
$link_count = count ( $names );
for ( $i = 0 ; $i < $link_count ; $i ++ ) {
if ( 'Last' == substr ( $titles [ $i ], 0 , 4 ))
$titles [ $i ] = '' ;
if ( 'http' == substr ( $titles [ $i ], 0 , 4 ) )
$titles [ $i ] = '' ;
$link = array ( 'link_url' => $urls [ $i ], 'link_name' => $wpdb -> escape ( $names [ $i ]), 'link_category' => array ( $cat_id ), 'link_description' => $wpdb -> escape ( $descriptions [ $i ]), 'link_owner' => $user_ID , 'link_rss' => $feeds [ $i ]);
wp_insert_link ( $link );
echo sprintf ( '<p>' . __ ( 'Inserted <strong>%s</strong>' ) . '</p>' , $names [ $i ]);
}
2003-05-31 02:06:21 +02:00
?>
2007-02-27 16:24:54 +01:00
< p >< ? php printf ( __ ( 'Inserted %1$d links into category %2$s. All done! Go <a href="%3$s">manage those links</a>.' ), $link_count , $cat_id , 'link-manager.php' ) ?> </p>
2003-05-31 02:06:21 +02:00
< ? php
2007-02-27 16:24:54 +01:00
} // end if got url
else
{
echo " <p> " . __ ( " You need to supply your OPML url. Press back on your browser and try again " ) . " </p> \n " ;
} // end else
if ( ! $blogrolling )
2008-01-04 20:36:34 +01:00
do_action ( 'wp_delete_file' , $opml_url );
2007-02-27 16:24:54 +01:00
@ unlink ( $opml_url );
2003-12-10 01:43:15 +01:00
?>
2004-06-11 20:23:12 +02:00
</ div >
2003-05-31 02:06:21 +02:00
< ? php
2007-02-27 16:24:54 +01:00
break ;
} // end case 1
2003-05-31 02:06:21 +02:00
} // end switch
2008-11-29 19:23:03 +01:00
}
function OPML_Import () {}
}
$opml_importer = new OPML_Import ();
2005-12-29 22:59:38 +01:00
2008-11-29 19:23:03 +01:00
register_importer ( 'opml' , __ ( 'Blogroll' ), __ ( 'Import links in OPML format.' ), array ( & $opml_importer , 'dispatch' ));
2005-12-29 22:59:38 +01:00
2008-11-29 19:09:09 +01:00
?>