2003-05-30 20:06:21 -04:00
< ? php
// Links
// Copyright (C) 2002 Mike Little -- mike@zed1.com
2003-12-07 22:46:42 -05:00
2004-10-18 23:03:06 -04:00
require_once ( 'admin.php' );
2003-12-10 19:22:36 -05:00
$parent_file = 'link-manager.php' ;
2004-04-25 19:25:31 -04:00
$title = __ ( 'Import Blogroll' );
2003-12-10 19:22:36 -05:00
$this_file = 'link-import.php' ;
2003-05-30 20:06:21 -04:00
2004-04-20 18:56:47 -04:00
$step = $_POST [ 'step' ];
2003-05-30 20:06:21 -04:00
if ( ! $step ) $step = 0 ;
?>
< ? php
switch ( $step ) {
case 0 :
{
2003-12-10 19:22:36 -05:00
include_once ( 'admin-header.php' );
2005-07-14 22:16:45 -04:00
if ( ! current_user_can ( 'manage_links' ) )
2004-04-25 19:25:31 -04:00
die ( __ ( " Cheatin’ uh? " ));
2003-12-09 19:43:15 -05:00
2003-12-07 22:46:42 -05:00
$opmltype = 'blogrolling' ; // default.
2003-05-30 20:06:21 -04:00
?>
2003-12-07 22:46:42 -05:00
2003-05-30 20:06:21 -04:00
< div class = " wrap " >
2005-11-14 04:42:44 -05:00
< h2 >< ? php _e ( 'Import your blogroll from another system' ) ?> </h2>
< form enctype = " multipart/form-data " action = " link-import.php " method = " post " name = " blogroll " >
2003-06-01 05:01:04 -04:00
2005-11-14 04:42:44 -05: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.' ); ?>
< 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>
< input name = " userfile " type = " file " size = " 30 " />
</ div >
2003-12-09 19:43:15 -05:00
2003-10-30 19:37:06 -05:00
2005-11-14 04:42:44 -05:00
</ div >
< p style = " clear: both; margin-top: 1em; " >< ? php _e ( 'Now select a category you want to put these links in.' ) ?> <br />
< ? php _e ( 'Category:' ) ?> <select name="cat_id">
2003-05-30 20:06:21 -04:00
< ? php
2005-11-14 04:42:44 -05:00
$categories = $wpdb -> get_results ( " SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id " );
foreach ( $categories as $category ) {
2003-05-30 20:06:21 -04:00
?>
2005-11-14 04:42:44 -05:00
< option value = " <?php echo $category->cat_id ; ?> " >< ? php echo $category -> cat_id . ': ' . $category -> cat_name ; ?> </option>
2003-05-30 20:06:21 -04:00
< ? php
2005-11-14 04:42:44 -05:00
} // end foreach
2003-05-30 20:06:21 -04:00
?>
2005-11-14 04:42:44 -05:00
</ select ></ p >
2003-06-01 05:01:04 -04:00
2005-11-14 04:42:44 -05:00
< p class = " submit " >< input type = " submit " name = " submit " value = " <?php _e('Import OPML File') ?> » " /></ p >
</ form >
2003-06-01 05:01:04 -04:00
2003-05-30 20:06:21 -04:00
</ div >
< ? php
break ;
} // end case 0
case 1 : {
2003-12-10 19:22:36 -05:00
include_once ( 'admin-header.php' );
2005-07-14 22:16:45 -04:00
if ( ! current_user_can ( 'manage_links' ) )
2004-04-25 19:25:31 -04:00
die ( __ ( " Cheatin' uh ? " ));
2003-05-30 20:06:21 -04:00
?>
< div class = " wrap " >
2003-06-01 05:01:04 -04:00
2004-04-25 19:25:31 -04:00
< h2 >< ? php _e ( 'Importing...' ) ?> </h2>
2003-05-30 20:06:21 -04:00
< ? php
2004-04-20 18:56:47 -04:00
$cat_id = $_POST [ 'cat_id' ];
2003-05-30 20:06:21 -04:00
if (( $cat_id == '' ) || ( $cat_id == 0 )) {
$cat_id = 1 ;
}
2003-12-09 19:43:15 -05:00
2004-04-20 18:56:47 -04:00
$opml_url = $_POST [ 'opml_url' ];
2003-12-09 19:43:15 -05:00
if ( isset ( $opml_url ) && $opml_url != '' ) {
$blogrolling = true ;
2003-05-30 20:06:21 -04:00
}
2003-12-09 19:43:15 -05:00
else // try to get the upload file.
{
2005-12-26 04:55:24 -05:00
$overrides = array ( 'test_form' => false , 'test_type' => false );
$file = wp_handle_upload ( $_FILES [ 'import' ], $overrides );
if ( isset ( $file [ 'error' ]) )
die ( $file [ 'error' ]);
$url = $file [ 'url' ];
$opml_url = $file [ 'file' ];
$blogrolling = false ;
2003-12-09 19:43:15 -05:00
}
if ( isset ( $opml_url ) && $opml_url != '' ) {
2005-09-08 17:01:54 -04:00
$opml = wp_remote_fopen ( $opml_url );
2003-12-10 19:22:36 -05:00
include_once ( 'link-parse-opml.php' );
2003-10-30 19:37:06 -05:00
2003-05-30 20:06:21 -04:00
$link_count = count ( $names );
2003-06-01 05:01:04 -04:00
for ( $i = 0 ; $i < $link_count ; $i ++ ) {
2003-05-30 20:06:21 -04:00
if ( 'Last' == substr ( $titles [ $i ], 0 , 4 ))
2003-06-01 05:01:04 -04:00
$titles [ $i ] = '' ;
2003-12-09 19:43:15 -05:00
if ( 'http' == substr ( $titles [ $i ], 0 , 4 ))
2003-05-30 20:06:21 -04:00
$titles [ $i ] = '' ;
2005-12-26 04:55:24 -05:00
// FIXME: Use wp_insert_link().
2004-05-24 04:22:18 -04:00
$query = " INSERT INTO $wpdb->links (link_url, link_name, link_target, link_category, link_description, link_owner, link_rss)
2005-07-05 16:47:22 -04:00
VALUES ( '{$urls[$i]}' , '".$wpdb->escape($names[$i])."' , '' , $cat_id , '".$wpdb->escape($descriptions[$i])."' , $user_ID , '{$feeds[$i]}' ) \n " ;
2003-06-01 05:01:04 -04:00
$result = $wpdb -> query ( $query );
2005-12-12 17:48:30 -05:00
echo sprintf ( '<p>' . __ ( 'Inserted <strong>%s</strong>' ) . '</p>' , $names [ $i ]);
2003-05-30 20:06:21 -04:00
}
?>
2004-04-25 19:25:31 -04: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-30 20:06:21 -04:00
< ? php
2003-12-09 19:43:15 -05:00
} // end if got url
else
{
2004-04-25 19:25:31 -04:00
echo " <p> " . __ ( " You need to supply your OPML url. Press back on your browser and try again " ) . " </p> \n " ;
2003-12-09 19:43:15 -05:00
} // end else
2003-06-01 05:01:04 -04:00
2005-12-26 04:55:24 -05:00
if ( ! $blogrolling )
@ unlink ( $opml_url );
2003-12-09 19:43:15 -05:00
?>
2004-06-11 14:23:12 -04:00
</ div >
2003-05-30 20:06:21 -04:00
< ? php
break ;
} // end case 1
} // end switch
2005-12-29 16:59:38 -05:00
include ( 'admin-footer.php' );
2003-05-30 20:06:21 -04:00
?>