Wordpress 2.0.2
[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
28 <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.'); ?>
29 <div style="width: 70%; margin: auto; height: 8em;">
30 <input type="hidden" name="step" value="1" />
31 <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
32 <div style="width: 48%; float: left;">
33 <h3><?php _e('Specify an OPML URL:'); ?></h3>
34 <input type="text" name="opml_url" size="50" style="width: 90%;" value="http://" />
35 </div>
36
37 <div style="width: 48%; float: left;">
38 <h3><?php _e('Or choose from your local disk:'); ?></h3>
39 <input id="userfile" name="userfile" type="file" size="30" />
40 </div>
41
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 = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id");
49 foreach ($categories as $category) {
50 ?>
51 <option value="<?php echo $category->cat_id; ?>"><?php echo $category->cat_id.': '.$category->cat_name; ?></option>
52 <?php
53 } // end foreach
54 ?>
55 </select></p>
56
57 <p class="submit"><input type="submit" name="submit" value="<?php _e('Import OPML File') ?> &raquo;" /></p>
58 </form>
59
60 </div>
61 <?php
62                 break;
63             } // end case 0
64
65     case 1: {
66                 include_once('admin-header.php');
67                 if ( !current_user_can('manage_links') )
68                     die (__("Cheatin' uh ?"));
69 ?>
70 <div class="wrap">
71
72      <h2><?php _e('Importing...') ?></h2>
73 <?php
74                 $cat_id = $_POST['cat_id'];
75                 if (($cat_id == '') || ($cat_id == 0)) {
76                     $cat_id  = 1;
77                 }
78
79                 $opml_url = $_POST['opml_url'];
80                 if (isset($opml_url) && $opml_url != '' && $opml_url != 'http://') {
81                                         $blogrolling = true;
82                 }
83                 else // try to get the upload file.
84                                 {
85                                         $overrides = array('test_form' => false, 'test_type' => false);
86                                         $file = wp_handle_upload($_FILES['userfile'], $overrides);
87
88                                         if ( isset($file['error']) )
89                                                 die($file['error']);
90
91                                         $url = $file['url'];
92                                         $opml_url = $file['file'];
93                                         $blogrolling = false;
94                                 }
95
96                 if (isset($opml_url) && $opml_url != '') {
97                     $opml = wp_remote_fopen($opml_url);
98                     include_once('link-parse-opml.php');
99
100                     $link_count = count($names);
101                     for ($i = 0; $i < $link_count; $i++) {
102                         if ('Last' == substr($titles[$i], 0, 4))
103                             $titles[$i] = '';
104                         if ('http' == substr($titles[$i], 0, 4))
105                             $titles[$i] = '';
106                         // FIXME:  Use wp_insert_link().
107                         $query = "INSERT INTO $wpdb->links (link_url, link_name, link_target, link_category, link_description, link_owner, link_rss)
108                                 VALUES('{$urls[$i]}', '".$wpdb->escape($names[$i])."', '', $cat_id, '".$wpdb->escape($descriptions[$i])."', $user_ID, '{$feeds[$i]}')\n";
109                         $result = $wpdb->query($query);
110                                                 echo sprintf('<p>'.__('Inserted <strong>%s</strong>').'</p>', $names[$i]);
111                     }
112 ?>
113      <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>
114 <?php
115                 } // end if got url
116                 else
117                 {
118                     echo "<p>" . __("You need to supply your OPML url. Press back on your browser and try again") . "</p>\n";
119                 } // end else
120
121                                 if ( ! $blogrolling )
122                                         @unlink($opml_url);
123 ?>
124 </div>
125 <?php
126                 break;
127             } // end case 1
128 } // end switch
129
130 include('admin-footer.php');
131
132 ?>