-
+ 9BCDEEC7B98A1D38DA2C4D7A070951DBC2C7BF4DAF939E26048A7275BFEFB566419ECB0A8565C366C7EFAEE7FEF0EB26E05CDF13279F76A5284A8B892F50F55B
mp-wp/wp-admin/import/opml.php
(0 . 0)(1 . 155)
19819 <?php
19820 /**
19821 * Links Import Administration Panel.
19822 *
19823 * @copyright 2002 Mike Little <mike@zed1.com>
19824 * @author Mike Little <mike@zed1.com>
19825 * @package WordPress
19826 * @subpackage Administration
19827 */
19828
19829 /** Load WordPress Administration Bootstrap */
19830 $parent_file = 'tools.php';
19831 $submenu_file = 'import.php';
19832 $title = __('Import Blogroll');
19833
19834 class OPML_Import {
19835
19836 function dispatch() {
19837 global $wpdb, $user_ID;
19838 $step = $_POST['step'];
19839 if (!$step) $step = 0;
19840 ?>
19841 <?php
19842 switch ($step) {
19843 case 0: {
19844 include_once('admin-header.php');
19845 if ( !current_user_can('manage_links') )
19846 wp_die(__('Cheatin’ uh?'));
19847
19848 $opmltype = 'blogrolling'; // default.
19849 ?>
19850
19851 <div class="wrap">
19852 <?php screen_icon(); ?>
19853 <h2><?php _e('Import your blogroll from another system') ?> </h2>
19854 <form enctype="multipart/form-data" action="admin.php?import=opml" method="post" name="blogroll">
19855 <?php wp_nonce_field('import-bookmarks') ?>
19856
19857 <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>
19858 <div style="width: 70%; margin: auto; height: 8em;">
19859 <input type="hidden" name="step" value="1" />
19860 <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
19861 <div style="width: 48%;" class="alignleft">
19862 <h3><label for="opml_url"><?php _e('Specify an OPML URL:'); ?></label></h3>
19863 <input type="text" name="opml_url" id="opml_url" size="50" style="width: 90%;" value="http://" />
19864 </div>
19865
19866 <div style="width: 48%;" class="alignleft">
19867 <h3><label for="userfile"><?php _e('Or choose from your local disk:'); ?></label></h3>
19868 <input id="userfile" name="userfile" type="file" size="30" />
19869 </div>
19870
19871 </div>
19872
19873 <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 />
19874 <?php _e('Category:') ?> <select name="cat_id" id="cat_id">
19875 <?php
19876 $categories = get_terms('link_category', 'get=all');
19877 foreach ($categories as $category) {
19878 ?>
19879 <option value="<?php echo $category->term_id; ?>"><?php echo wp_specialchars(apply_filters('link_category', $category->name)); ?></option>
19880 <?php
19881 } // end foreach
19882 ?>
19883 </select></p>
19884
19885 <p class="submit"><input type="submit" name="submit" value="<?php _e('Import OPML File') ?>" /></p>
19886 </form>
19887
19888 </div>
19889 <?php
19890 break;
19891 } // end case 0
19892
19893 case 1: {
19894 check_admin_referer('import-bookmarks');
19895
19896 include_once('admin-header.php');
19897 if ( !current_user_can('manage_links') )
19898 wp_die(__('Cheatin’ uh?'));
19899 ?>
19900 <div class="wrap">
19901
19902 <h2><?php _e('Importing...') ?></h2>
19903 <?php
19904 $cat_id = abs( (int) $_POST['cat_id'] );
19905 if ( $cat_id < 1 )
19906 $cat_id = 1;
19907
19908 $opml_url = $_POST['opml_url'];
19909 if ( isset($opml_url) && $opml_url != '' && $opml_url != 'http://' ) {
19910 $blogrolling = true;
19911 } else { // try to get the upload file.
19912 $overrides = array('test_form' => false, 'test_type' => false);
19913 $file = wp_handle_upload($_FILES['userfile'], $overrides);
19914
19915 if ( isset($file['error']) )
19916 wp_die($file['error']);
19917
19918 $url = $file['url'];
19919 $opml_url = $file['file'];
19920 $blogrolling = false;
19921 }
19922
19923 global $opml, $updated_timestamp, $all_links, $map, $names, $urls, $targets, $descriptions, $feeds;
19924 if ( isset($opml_url) && $opml_url != '' ) {
19925 if ( $blogrolling === true ) {
19926 $opml = wp_remote_fopen($opml_url);
19927 } else {
19928 $opml = file_get_contents($opml_url);
19929 }
19930
19931 /** Load OPML Parser */
19932 include_once('link-parse-opml.php');
19933
19934 $link_count = count($names);
19935 for ( $i = 0; $i < $link_count; $i++ ) {
19936 if ('Last' == substr($titles[$i], 0, 4))
19937 $titles[$i] = '';
19938 if ( 'http' == substr($titles[$i], 0, 4) )
19939 $titles[$i] = '';
19940 $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]);
19941 wp_insert_link($link);
19942 echo sprintf('<p>'.__('Inserted <strong>%s</strong>').'</p>', $names[$i]);
19943 }
19944 ?>
19945
19946 <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>
19947
19948 <?php
19949 } // end if got url
19950 else
19951 {
19952 echo "<p>" . __("You need to supply your OPML url. Press back on your browser and try again") . "</p>\n";
19953 } // end else
19954
19955 if ( ! $blogrolling )
19956 do_action( 'wp_delete_file', $opml_url);
19957 @unlink($opml_url);
19958 ?>
19959 </div>
19960 <?php
19961 break;
19962 } // end case 1
19963 } // end switch
19964 }
19965
19966 function OPML_Import() {}
19967 }
19968
19969 $opml_importer = new OPML_Import();
19970
19971 register_importer('opml', __('Blogroll'), __('Import links in OPML format.'), array(&$opml_importer, 'dispatch'));
19972
19973 ?>