mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Links Import Administration Panel.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @copyright 2002 Mike Little <mike@zed1.com>
mp-wp_genesis 6 * @author Mike Little <mike@zed1.com>
mp-wp_genesis 7 * @package WordPress
mp-wp_genesis 8 * @subpackage Administration
mp-wp_genesis 9 */
mp-wp_genesis 10
mp-wp_genesis 11 /** Load WordPress Administration Bootstrap */
mp-wp_genesis 12 $parent_file = 'tools.php';
mp-wp_genesis 13 $submenu_file = 'import.php';
mp-wp_genesis 14 $title = __('Import Blogroll');
mp-wp_genesis 15
mp-wp_genesis 16 class OPML_Import {
mp-wp_genesis 17
mp-wp_genesis 18 function dispatch() {
mp-wp_genesis 19 global $wpdb, $user_ID;
mp-wp_genesis 20 $step = $_POST['step'];
mp-wp_genesis 21 if (!$step) $step = 0;
mp-wp_genesis 22 ?>
mp-wp_genesis 23 <?php
mp-wp_genesis 24 switch ($step) {
mp-wp_genesis 25 case 0: {
mp-wp_genesis 26 include_once('admin-header.php');
mp-wp_genesis 27 if ( !current_user_can('manage_links') )
mp-wp_genesis 28 wp_die(__('Cheatin’ uh?'));
mp-wp_genesis 29
mp-wp_genesis 30 $opmltype = 'blogrolling'; // default.
mp-wp_genesis 31 ?>
mp-wp_genesis 32
mp-wp_genesis 33 <div class="wrap">
mp-wp_genesis 34 <?php screen_icon(); ?>
mp-wp_genesis 35 <h2><?php _e('Import your blogroll from another system') ?> </h2>
mp-wp_genesis 36 <form enctype="multipart/form-data" action="admin.php?import=opml" method="post" name="blogroll">
mp-wp_genesis 37 <?php wp_nonce_field('import-bookmarks') ?>
mp-wp_genesis 38
mp-wp_genesis 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>
mp-wp_genesis 40 <div style="width: 70%; margin: auto; height: 8em;">
mp-wp_genesis 41 <input type="hidden" name="step" value="1" />
mp-wp_genesis 42 <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
mp-wp_genesis 43 <div style="width: 48%;" class="alignleft">
mp-wp_genesis 44 <h3><label for="opml_url"><?php _e('Specify an OPML URL:'); ?></label></h3>
mp-wp_genesis 45 <input type="text" name="opml_url" id="opml_url" size="50" style="width: 90%;" value="http://" />
mp-wp_genesis 46 </div>
mp-wp_genesis 47
mp-wp_genesis 48 <div style="width: 48%;" class="alignleft">
mp-wp_genesis 49 <h3><label for="userfile"><?php _e('Or choose from your local disk:'); ?></label></h3>
mp-wp_genesis 50 <input id="userfile" name="userfile" type="file" size="30" />
mp-wp_genesis 51 </div>
mp-wp_genesis 52
mp-wp_genesis 53 </div>
mp-wp_genesis 54
mp-wp_genesis 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 />
mp-wp_genesis 56 <?php _e('Category:') ?> <select name="cat_id" id="cat_id">
mp-wp_genesis 57 <?php
mp-wp_genesis 58 $categories = get_terms('link_category', 'get=all');
mp-wp_genesis 59 foreach ($categories as $category) {
mp-wp_genesis 60 ?>
mp-wp_genesis 61 <option value="<?php echo $category->term_id; ?>"><?php echo wp_specialchars(apply_filters('link_category', $category->name)); ?></option>
mp-wp_genesis 62 <?php
mp-wp_genesis 63 } // end foreach
mp-wp_genesis 64 ?>
mp-wp_genesis 65 </select></p>
mp-wp_genesis 66
mp-wp_genesis 67 <p class="submit"><input type="submit" name="submit" value="<?php _e('Import OPML File') ?>" /></p>
mp-wp_genesis 68 </form>
mp-wp_genesis 69
mp-wp_genesis 70 </div>
mp-wp_genesis 71 <?php
mp-wp_genesis 72 break;
mp-wp_genesis 73 } // end case 0
mp-wp_genesis 74
mp-wp_genesis 75 case 1: {
mp-wp_genesis 76 check_admin_referer('import-bookmarks');
mp-wp_genesis 77
mp-wp_genesis 78 include_once('admin-header.php');
mp-wp_genesis 79 if ( !current_user_can('manage_links') )
mp-wp_genesis 80 wp_die(__('Cheatin’ uh?'));
mp-wp_genesis 81 ?>
mp-wp_genesis 82 <div class="wrap">
mp-wp_genesis 83
mp-wp_genesis 84 <h2><?php _e('Importing...') ?></h2>
mp-wp_genesis 85 <?php
mp-wp_genesis 86 $cat_id = abs( (int) $_POST['cat_id'] );
mp-wp_genesis 87 if ( $cat_id < 1 )
mp-wp_genesis 88 $cat_id = 1;
mp-wp_genesis 89
mp-wp_genesis 90 $opml_url = $_POST['opml_url'];
mp-wp_genesis 91 if ( isset($opml_url) && $opml_url != '' && $opml_url != 'http://' ) {
mp-wp_genesis 92 $blogrolling = true;
mp-wp_genesis 93 } else { // try to get the upload file.
mp-wp_genesis 94 $overrides = array('test_form' => false, 'test_type' => false);
mp-wp_genesis 95 $file = wp_handle_upload($_FILES['userfile'], $overrides);
mp-wp_genesis 96
mp-wp_genesis 97 if ( isset($file['error']) )
mp-wp_genesis 98 wp_die($file['error']);
mp-wp_genesis 99
mp-wp_genesis 100 $url = $file['url'];
mp-wp_genesis 101 $opml_url = $file['file'];
mp-wp_genesis 102 $blogrolling = false;
mp-wp_genesis 103 }
mp-wp_genesis 104
mp-wp_genesis 105 global $opml, $updated_timestamp, $all_links, $map, $names, $urls, $targets, $descriptions, $feeds;
mp-wp_genesis 106 if ( isset($opml_url) && $opml_url != '' ) {
mp-wp_genesis 107 if ( $blogrolling === true ) {
mp-wp_genesis 108 $opml = wp_remote_fopen($opml_url);
mp-wp_genesis 109 } else {
mp-wp_genesis 110 $opml = file_get_contents($opml_url);
mp-wp_genesis 111 }
mp-wp_genesis 112
mp-wp_genesis 113 /** Load OPML Parser */
mp-wp_genesis 114 include_once('link-parse-opml.php');
mp-wp_genesis 115
mp-wp_genesis 116 $link_count = count($names);
mp-wp_genesis 117 for ( $i = 0; $i < $link_count; $i++ ) {
mp-wp_genesis 118 if ('Last' == substr($titles[$i], 0, 4))
mp-wp_genesis 119 $titles[$i] = '';
mp-wp_genesis 120 if ( 'http' == substr($titles[$i], 0, 4) )
mp-wp_genesis 121 $titles[$i] = '';
mp-wp_genesis 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]);
mp-wp_genesis 123 wp_insert_link($link);
mp-wp_genesis 124 echo sprintf('<p>'.__('Inserted <strong>%s</strong>').'</p>', $names[$i]);
mp-wp_genesis 125 }
mp-wp_genesis 126 ?>
mp-wp_genesis 127
mp-wp_genesis 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>
mp-wp_genesis 129
mp-wp_genesis 130 <?php
mp-wp_genesis 131 } // end if got url
mp-wp_genesis 132 else
mp-wp_genesis 133 {
mp-wp_genesis 134 echo "<p>" . __("You need to supply your OPML url. Press back on your browser and try again") . "</p>\n";
mp-wp_genesis 135 } // end else
mp-wp_genesis 136
mp-wp_genesis 137 if ( ! $blogrolling )
mp-wp_genesis 138 do_action( 'wp_delete_file', $opml_url);
mp-wp_genesis 139 @unlink($opml_url);
mp-wp_genesis 140 ?>
mp-wp_genesis 141 </div>
mp-wp_genesis 142 <?php
mp-wp_genesis 143 break;
mp-wp_genesis 144 } // end case 1
mp-wp_genesis 145 } // end switch
mp-wp_genesis 146 }
mp-wp_genesis 147
mp-wp_genesis 148 function OPML_Import() {}
mp-wp_genesis 149 }
mp-wp_genesis 150
mp-wp_genesis 151 $opml_importer = new OPML_Import();
mp-wp_genesis 152
mp-wp_genesis 153 register_importer('opml', __('Blogroll'), __('Import links in OPML format.'), array(&$opml_importer, 'dispatch'));
mp-wp_genesis 154
mp-wp_genesis 155 ?>