| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
require_once('admin.php'); |
|---|
| 6 |
$parent_file = 'link-manager.php'; |
|---|
| 7 |
$title = __('Import Blogroll'); |
|---|
| 8 |
$this_file = 'link-import.php'; |
|---|
| 9 |
|
|---|
| 10 |
$step = $_POST['step']; |
|---|
| 11 |
if (!$step) $step = 0; |
|---|
| 12 |
?> |
|---|
| 13 |
<?php |
|---|
| 14 |
switch ($step) { |
|---|
| 15 |
case 0: { |
|---|
| 16 |
include_once('admin-header.php'); |
|---|
| 17 |
if ( !current_user_can('manage_links') ) |
|---|
| 18 |
wp_die(__('Cheatin’ uh?')); |
|---|
| 19 |
|
|---|
| 20 |
$opmltype = 'blogrolling'; |
|---|
| 21 |
?> |
|---|
| 22 |
|
|---|
| 23 |
<div class="wrap"> |
|---|
| 24 |
|
|---|
| 25 |
<h2><?php _e('Import your blogroll from another system') ?> </h2> |
|---|
| 26 |
<form enctype="multipart/form-data" action="link-import.php" method="post" name="blogroll"> |
|---|
| 27 |
<?php wp_nonce_field('import-bookmarks') ?> |
|---|
| 28 |
|
|---|
| 29 |
<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> |
|---|
| 30 |
<div style="width: 70%; margin: auto; height: 8em;"> |
|---|
| 31 |
<input type="hidden" name="step" value="1" /> |
|---|
| 32 |
<input type="hidden" name="MAX_FILE_SIZE" value="30000" /> |
|---|
| 33 |
<div style="width: 48%; float: left;"> |
|---|
| 34 |
<h3><?php _e('Specify an OPML URL:'); ?></h3> |
|---|
| 35 |
<input type="text" name="opml_url" size="50" style="width: 90%;" value="http://" /> |
|---|
| 36 |
</div> |
|---|
| 37 |
|
|---|
| 38 |
<div style="width: 48%; float: left;"> |
|---|
| 39 |
<h3><?php _e('Or choose from your local disk:'); ?></h3> |
|---|
| 40 |
<input id="userfile" name="userfile" type="file" size="30" /> |
|---|
| 41 |
</div> |
|---|
| 42 |
|
|---|
| 43 |
</div> |
|---|
| 44 |
|
|---|
| 45 |
<p style="clear: both; margin-top: 1em;"><?php _e('Now select a category you want to put these links in.') ?><br /> |
|---|
| 46 |
<?php _e('Category:') ?> <select name="cat_id"> |
|---|
| 47 |
<?php |
|---|
| 48 |
$categories = get_terms('link_category', 'get=all'); |
|---|
| 49 |
foreach ($categories as $category) { |
|---|
| 50 |
?> |
|---|
| 51 |
<option value="<?php echo $category->term_id; ?>"><?php echo wp_specialchars(apply_filters('link_category', $category->name)); ?></option> |
|---|
| 52 |
<?php |
|---|
| 53 |
} |
|---|
| 54 |
?> |
|---|
| 55 |
</select></p> |
|---|
| 56 |
|
|---|
| 57 |
<p class="submit"><input type="submit" name="submit" value="<?php _e('Import OPML File »') ?>" /></p> |
|---|
| 58 |
</form> |
|---|
| 59 |
|
|---|
| 60 |
</div> |
|---|
| 61 |
<?php |
|---|
| 62 |
break; |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
case 1: { |
|---|
| 66 |
check_admin_referer('import-bookmarks'); |
|---|
| 67 |
|
|---|
| 68 |
include_once('admin-header.php'); |
|---|
| 69 |
if ( !current_user_can('manage_links') ) |
|---|
| 70 |
wp_die(__('Cheatin’ uh?')); |
|---|
| 71 |
?> |
|---|
| 72 |
<div class="wrap"> |
|---|
| 73 |
|
|---|
| 74 |
<h2><?php _e('Importing...') ?></h2> |
|---|
| 75 |
<?php |
|---|
| 76 |
$cat_id = abs( (int) $_POST['cat_id'] ); |
|---|
| 77 |
if ( $cat_id < 1 ) |
|---|
| 78 |
$cat_id = 1; |
|---|
| 79 |
|
|---|
| 80 |
$opml_url = $_POST['opml_url']; |
|---|
| 81 |
if ( isset($opml_url) && $opml_url != '' && $opml_url != 'http://' ) { |
|---|
| 82 |
$blogrolling = true; |
|---|
| 83 |
} else { |
|---|
| 84 |
$overrides = array('test_form' => false, 'test_type' => false); |
|---|
| 85 |
$file = wp_handle_upload($_FILES['userfile'], $overrides); |
|---|
| 86 |
|
|---|
| 87 |
if ( isset($file['error']) ) |
|---|
| 88 |
wp_die($file['error']); |
|---|
| 89 |
|
|---|
| 90 |
$url = $file['url']; |
|---|
| 91 |
$opml_url = $file['file']; |
|---|
| 92 |
$blogrolling = false; |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
if ( isset($opml_url) && $opml_url != '' ) { |
|---|
| 96 |
if ( $blogrolling === true ) { |
|---|
| 97 |
$opml = wp_remote_fopen($opml_url); |
|---|
| 98 |
} else { |
|---|
| 99 |
$opml = file_get_contents($opml_url); |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
include_once('link-parse-opml.php'); |
|---|
| 103 |
|
|---|
| 104 |
$link_count = count($names); |
|---|
| 105 |
for ( $i = 0; $i < $link_count; $i++ ) { |
|---|
| 106 |
if ('Last' == substr($titles[$i], 0, 4)) |
|---|
| 107 |
$titles[$i] = ''; |
|---|
| 108 |
if ( 'http' == substr($titles[$i], 0, 4) ) |
|---|
| 109 |
$titles[$i] = ''; |
|---|
| 110 |
$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]); |
|---|
| 111 |
wp_insert_link($link); |
|---|
| 112 |
echo sprintf('<p>'.__('Inserted <strong>%s</strong>').'</p>', $names[$i]); |
|---|
| 113 |
} |
|---|
| 114 |
?> |
|---|
| 115 |
|
|---|
| 116 |
<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> |
|---|
| 117 |
|
|---|
| 118 |
<?php |
|---|
| 119 |
} |
|---|
| 120 |
else |
|---|
| 121 |
{ |
|---|
| 122 |
echo "<p>" . __("You need to supply your OPML url. Press back on your browser and try again") . "</p>\n"; |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
if ( ! $blogrolling ) |
|---|
| 126 |
apply_filters( 'wp_delete_file', $opml_url); |
|---|
| 127 |
@unlink($opml_url); |
|---|
| 128 |
?> |
|---|
| 129 |
</div> |
|---|
| 130 |
<?php |
|---|
| 131 |
break; |
|---|
| 132 |
} |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
include('admin-footer.php'); |
|---|
| 136 |
|
|---|
| 137 |
?> |
|---|
| 138 |
|
|---|