3 * Links Import Administration Panel.
5 * @copyright 2002 Mike Little <mike@zed1.com>
6 * @author Mike Little <mike@zed1.com>
8 * @subpackage Administration
11 /** Load WordPress Administration Bootstrap */
12 $parent_file = 'tools.php';
13 $submenu_file = 'import.php';
14 $title = __('Import Blogroll');
19 global $wpdb, $user_ID;
20 $step = $_POST['step'];
21 if (!$step) $step = 0;
26 include_once('admin-header.php');
27 if ( !current_user_can('manage_links') )
28 wp_die(__('Cheatin’ uh?'));
30 $opmltype = 'blogrolling'; // default.
34 <?php screen_icon(); ?>
35 <h2><?php _e('Import your blogroll from another system') ?> </h2>
36 <form enctype="multipart/form-data" action="admin.php?import=opml" method="post" name="blogroll">
37 <?php wp_nonce_field('import-bookmarks') ?>
39 <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>
40 <div style="width: 70%; margin: auto; height: 8em;">
41 <input type="hidden" name="step" value="1" />
42 <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
43 <div style="width: 48%;" class="alignleft">
44 <h3><label for="opml_url"><?php _e('Specify an OPML URL:'); ?></label></h3>
45 <input type="text" name="opml_url" id="opml_url" size="50" style="width: 90%;" value="http://" />
48 <div style="width: 48%;" class="alignleft">
49 <h3><label for="userfile"><?php _e('Or choose from your local disk:'); ?></label></h3>
50 <input id="userfile" name="userfile" type="file" size="30" />
55 <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 />
56 <?php _e('Category:') ?> <select name="cat_id" id="cat_id">
58 $categories = get_terms('link_category', 'get=all');
59 foreach ($categories as $category) {
61 <option value="<?php echo $category->term_id; ?>"><?php echo wp_specialchars(apply_filters('link_category', $category->name)); ?></option>
67 <p class="submit"><input type="submit" name="submit" value="<?php _e('Import OPML File') ?>" /></p>
76 check_admin_referer('import-bookmarks');
78 include_once('admin-header.php');
79 if ( !current_user_can('manage_links') )
80 wp_die(__('Cheatin’ uh?'));
84 <h2><?php _e('Importing...') ?></h2>
86 $cat_id = abs( (int) $_POST['cat_id'] );
90 $opml_url = $_POST['opml_url'];
91 if ( isset($opml_url) && $opml_url != '' && $opml_url != 'http://' ) {
93 } else { // try to get the upload file.
94 $overrides = array('test_form' => false, 'test_type' => false);
95 $file = wp_handle_upload($_FILES['userfile'], $overrides);
97 if ( isset($file['error']) )
98 wp_die($file['error']);
101 $opml_url = $file['file'];
102 $blogrolling = false;
105 global $opml, $updated_timestamp, $all_links, $map, $names, $urls, $targets, $descriptions, $feeds;
106 if ( isset($opml_url) && $opml_url != '' ) {
107 if ( $blogrolling === true ) {
108 $opml = wp_remote_fopen($opml_url);
110 $opml = file_get_contents($opml_url);
113 /** Load OPML Parser */
114 include_once('link-parse-opml.php');
116 $link_count = count($names);
117 for ( $i = 0; $i < $link_count; $i++ ) {
118 if ('Last' == substr($titles[$i], 0, 4))
120 if ( 'http' == substr($titles[$i], 0, 4) )
122 $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]);
123 wp_insert_link($link);
124 echo sprintf('<p>'.__('Inserted <strong>%s</strong>').'</p>', $names[$i]);
128 <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>
134 echo "<p>" . __("You need to supply your OPML url. Press back on your browser and try again") . "</p>\n";
137 if ( ! $blogrolling )
138 do_action( 'wp_delete_file', $opml_url);
148 function OPML_Import() {}
151 $opml_importer = new OPML_Import();
153 register_importer('opml', __('Blogroll'), __('Import links in OPML format.'), array(&$opml_importer, 'dispatch'));