]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/link-import.php
Wordpress 2.0.4
[autoinstalls/wordpress.git] / wp-admin / link-import.php
1 <?php
2 // Links
3 // Copyright (C) 2002 Mike Little -- mike@zed1.com
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     {
17         include_once('admin-header.php');
18         if ( !current_user_can('manage_links') )
19             die (__("Cheatin&#8217; uh?"));
20
21         $opmltype = 'blogrolling'; // default.
22 ?>
23
24 <div class="wrap">
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.'); ?>
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
44 </div>
45
46 <p style="clear: both; margin-top: 1em;"><?php _e('Now select a category you want to put these links in.') ?><br />
47 <?php _e('Category:') ?> <select name="cat_id">
48 <?php
49 $categories = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id");
50 foreach ($categories as $category) {
51 ?>
52 <option value="<?php echo $category->cat_id; ?>"><?php echo $category->cat_id.': '.$category->cat_name; ?></option>
53 <?php
54 } // end foreach
55 ?>
56 </select></p>
57
58 <p class="submit"><input type="submit" name="submit" value="<?php _e('Import OPML File') ?> &raquo;" /></p>
59 </form>
60
61 </div>
62 <?php
63                 break;
64             } // end case 0
65
66     case 1: {
67                 check_admin_referer('import-bookmarks');
68
69                 include_once('admin-header.php');
70                 if ( !current_user_can('manage_links') )
71                     die (__("Cheatin' uh ?"));
72 ?>
73 <div class="wrap">
74
75      <h2><?php _e('Importing...') ?></h2>
76 <?php
77                 $cat_id = $_POST['cat_id'];
78                 if (($cat_id == '') || ($cat_id == 0)) {
79                     $cat_id  = 1;
80                 }
81
82                 $opml_url = $_POST['opml_url'];
83                 if (isset($opml_url) && $opml_url != '' && $opml_url != 'http://') {
84                                         $blogrolling = true;
85                 }
86                 else // try to get the upload file.
87                                 {
88                                         $overrides = array('test_form' => false, 'test_type' => false);
89                                         $file = wp_handle_upload($_FILES['userfile'], $overrides);
90
91                                         if ( isset($file['error']) )
92                                                 die($file['error']);
93
94                                         $url = $file['url'];
95                                         $opml_url = $file['file'];
96                                         $blogrolling = false;
97                                 }
98
99                 if (isset($opml_url) && $opml_url != '') {
100                     $opml = wp_remote_fopen($opml_url);
101                     include_once('link-parse-opml.php');
102
103                     $link_count = count($names);
104                     for ($i = 0; $i < $link_count; $i++) {
105                         if ('Last' == substr($titles[$i], 0, 4))
106                             $titles[$i] = '';
107                         if ('http' == substr($titles[$i], 0, 4))
108                             $titles[$i] = '';
109                         // FIXME:  Use wp_insert_link().
110                         $query = "INSERT INTO $wpdb->links (link_url, link_name, link_target, link_category, link_description, link_owner, link_rss)
111                                 VALUES('{$urls[$i]}', '".$wpdb->escape($names[$i])."', '', $cat_id, '".$wpdb->escape($descriptions[$i])."', $user_ID, '{$feeds[$i]}')\n";
112                         $result = $wpdb->query($query);
113                                                 echo sprintf('<p>'.__('Inserted <strong>%s</strong>').'</p>', $names[$i]);
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 <?php
118                 } // end if got url
119                 else
120                 {
121                     echo "<p>" . __("You need to supply your OPML url. Press back on your browser and try again") . "</p>\n";
122                 } // end else
123
124                                 if ( ! $blogrolling )
125                                         @unlink($opml_url);
126 ?>
127 </div>
128 <?php
129                 break;
130             } // end case 1
131 } // end switch
132
133 include('admin-footer.php');
134
135 ?>