2003-05-31 02:06:21 +02:00
< ? php
// Links
// Copyright (C) 2002 Mike Little -- mike@zed1.com
2003-12-08 04:46:42 +01:00
2004-10-19 05:03:06 +02:00
require_once ( 'admin.php' );
2006-11-18 08:31:29 +01:00
$parent_file = 'link-manager.php' ;
$title = __ ( 'Import Blogroll' );
2003-12-11 01:22:36 +01:00
$this_file = 'link-import.php' ;
2003-05-31 02:06:21 +02:00
2004-04-21 00:56:47 +02:00
$step = $_POST [ 'step' ];
2003-05-31 02:06:21 +02:00
if ( ! $step ) $step = 0 ;
?>
< ? php
switch ( $step ) {
case 0 :
{
2003-12-11 01:22:36 +01:00
include_once ( 'admin-header.php' );
2005-07-15 04:16:45 +02:00
if ( ! current_user_can ( 'manage_links' ) )
2006-07-10 07:29:10 +02:00
wp_die ( __ ( 'Cheatin’ uh?' ));
2003-12-10 01:43:15 +01:00
2003-12-08 04:46:42 +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 " >
2005-11-14 10:42:44 +01:00
< h2 >< ? php _e ( 'Import your blogroll from another system' ) ?> </h2>
< form enctype = " multipart/form-data " action = " link-import.php " 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
2006-11-20 03:23:41 +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.' ); ?>
2005-11-14 10:42:44 +01:00
< div style = " width: 70%; margin: auto; height: 8em; " >
< input type = " hidden " name = " step " value = " 1 " />
< input type = " hidden " name = " MAX_FILE_SIZE " value = " 30000 " />
< div style = " width: 48%; float: left; " >
< h3 >< ? php _e ( 'Specify an OPML URL:' ); ?> </h3>
< input type = " text " name = " opml_url " size = " 50 " style = " width: 90%; " value = " http:// " />
</ div >
< div style = " width: 48%; float: left; " >
< h3 >< ? php _e ( 'Or choose from your local disk:' ); ?> </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
2003-10-31 01:37:06 +01:00
2005-11-14 10:42:44 +01:00
</ div >
2006-11-20 03:23:41 +01:00
< p style = " clear: both; margin-top: 1em; " >< ? php _e ( 'Now select a category you want to put these links in.' ) ?> <br />
2005-11-14 10:42:44 +01:00
< ? php _e ( 'Category:' ) ?> <select name="cat_id">
2003-05-31 02:06:21 +02:00
< ? php
2006-02-27 05:57:30 +01:00
$categories = get_categories ( 'hide_empty=0' );
2005-11-14 10:42:44 +01:00
foreach ( $categories as $category ) {
2003-05-31 02:06:21 +02:00
?>
2006-02-27 05:57:30 +01:00
< option value = " <?php echo $category->cat_ID ; ?> " >< ? php echo wp_specialchars ( $category -> cat_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
2006-02-17 02:29:33 +01:00
< p class = " submit " >< input type = " submit " name = " submit " value = " <?php _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
break ;
} // end case 0
case 1 : {
2006-05-04 11:20:44 +02:00
check_admin_referer ( 'import-bookmarks' );
2006-03-31 01:12:54 +02:00
2003-12-11 01:22:36 +01:00
include_once ( 'admin-header.php' );
2005-07-15 04:16:45 +02:00
if ( ! current_user_can ( 'manage_links' ) )
2006-07-10 07:29:10 +02:00
wp_die ( __ ( 'Cheatin’ uh?' ));
2003-05-31 02:06:21 +02:00
?>
< div class = " wrap " >
2003-06-01 11:01:04 +02:00
2004-04-26 01:25:31 +02:00
< h2 >< ? php _e ( 'Importing...' ) ?> </h2>
2003-05-31 02:06:21 +02:00
< ? php
2004-04-21 00:56:47 +02:00
$cat_id = $_POST [ 'cat_id' ];
2003-05-31 02:06:21 +02:00
if (( $cat_id == '' ) || ( $cat_id == 0 )) {
$cat_id = 1 ;
}
2003-12-10 01:43:15 +01:00
2004-04-21 00:56:47 +02:00
$opml_url = $_POST [ 'opml_url' ];
2006-01-16 20:57:20 +01:00
if ( isset ( $opml_url ) && $opml_url != '' && $opml_url != 'http://' ) {
2003-12-10 01:43:15 +01:00
$blogrolling = true ;
2003-05-31 02:06:21 +02:00
}
2003-12-10 01:43:15 +01:00
else // try to get the upload file.
{
2005-12-26 10:55:24 +01:00
$overrides = array ( 'test_form' => false , 'test_type' => false );
2006-01-25 01:49:13 +01:00
$file = wp_handle_upload ( $_FILES [ 'userfile' ], $overrides );
2005-12-26 10:55:24 +01:00
if ( isset ( $file [ 'error' ]) )
2006-07-06 00:00:03 +02:00
wp_die ( $file [ 'error' ]);
2005-12-26 10:55:24 +01:00
$url = $file [ 'url' ];
$opml_url = $file [ 'file' ];
$blogrolling = false ;
2003-12-10 01:43:15 +01:00
}
if ( isset ( $opml_url ) && $opml_url != '' ) {
2005-09-08 23:01:54 +02:00
$opml = wp_remote_fopen ( $opml_url );
2003-12-11 01:22:36 +01:00
include_once ( 'link-parse-opml.php' );
2003-10-31 01:37:06 +01:00
2003-05-31 02:06:21 +02:00
$link_count = count ( $names );
2003-06-01 11:01:04 +02:00
for ( $i = 0 ; $i < $link_count ; $i ++ ) {
2003-05-31 02:06:21 +02:00
if ( 'Last' == substr ( $titles [ $i ], 0 , 4 ))
2003-06-01 11:01:04 +02:00
$titles [ $i ] = '' ;
2003-12-10 01:43:15 +01:00
if ( 'http' == substr ( $titles [ $i ], 0 , 4 ))
2003-05-31 02:06:21 +02:00
$titles [ $i ] = '' ;
2006-02-27 05:57:30 +01:00
$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 );
2005-12-12 23:48:30 +01:00
echo sprintf ( '<p>' . __ ( 'Inserted <strong>%s</strong>' ) . '</p>' , $names [ $i ]);
2003-05-31 02:06:21 +02:00
}
?>
2006-11-20 03:23:41 +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
2003-12-10 01:43:15 +01:00
} // end if got url
else
{
2004-04-26 01:25:31 +02:00
echo " <p> " . __ ( " You need to supply your OPML url. Press back on your browser and try again " ) . " </p> \n " ;
2003-12-10 01:43:15 +01:00
} // end else
2003-06-01 11:01:04 +02:00
2005-12-26 10:55:24 +01:00
if ( ! $blogrolling )
@ 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
break ;
} // end case 1
} // end switch
2005-12-29 22:59:38 +01:00
include ( 'admin-footer.php' );
2003-05-31 02:06:21 +02:00
?>