source: trunk/www.guidonia.net/wp/wp-admin/import/btt.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 3.7 KB
Line 
1<?php
2/**
3 * BunnyTags Plugin Tag Importer
4 *
5 * @package WordPress
6 * @subpackage Importer
7 */
8
9/**
10 * BunnyTags Plugin tag converter
11 *
12 * This will process the BunnyTags plugin tags and convert them to the WordPress
13 * 2.3 taxonomy.
14 *
15 * @since unknown
16 */
17class BunnyTags_Import {
18
19 function header() {
20 echo '<div class="wrap">';
21 screen_icon();
22 echo '<h2>'.__('Import Bunny&#8217;s Technorati Tags').'</h2>';
23 echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
24 }
25
26 function footer() {
27 echo '</div>';
28 }
29
30 function greet() {
31 echo '<div class="narrow">';
32 echo '<p>'.__('Howdy! This imports tags from Bunny&#8217;s Technorati Tags into WordPress tags.').'</p>';
33 echo '<p>'.__('This is suitable for Bunny&#8217;s Technorati Tags version 0.6.').'</p>';
34 echo '<p><strong>'.__('All existing Bunny&#8217;s Technorati Tags will be removed after import.').'</strong></p>';
35 echo '<p><strong>'.__('Don&#8217;t be stupid - backup your database before proceeding!').'</strong></p>';
36 echo '<form action="admin.php?import=btt&amp;step=1" method="post">';
37 wp_nonce_field('import-btt');
38 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Import Tags').'" /></p>';
39 echo '</form>';
40 echo '</div>';
41 }
42
43 function dispatch() {
44 if ( empty($_GET['step']) )
45 $step = 0;
46 else
47 $step = absint($_GET['step']);
48
49 // load the header
50 $this->header();
51
52 switch ( $step ) {
53 case 0 :
54 $this->greet();
55 break;
56 case 1 :
57 check_admin_referer('import-btt');
58 $this->check_post_keyword( true );
59 break;
60 case 2 :
61 check_admin_referer('import-btt');
62 $this->check_post_keyword( false );
63 break;
64 case 3:
65 $this->done();
66 break;
67 }
68
69 // load the footer
70 $this->footer();
71 }
72
73 function check_post_keyword($precheck = true) {
74 global $wpdb;
75
76 echo '<div class="narrow">';
77 echo '<p><h3>'.__('Reading Bunny&#8217;s Technorati Tags&#8230;').'</h3></p>';
78
79 // import Bunny's Keywords tags
80 $metakeys = $wpdb->get_results("SELECT post_id, meta_id, meta_key, meta_value FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'tags'");
81 if ( !is_array($metakeys)) {
82 echo '<p>' . __('No Tags Found!') . '</p>';
83 return false;
84 } else {
85 $count = count($metakeys);
86 echo '<p>' . sprintf( _n('Done! <strong>%s</strong> post with tags were read.', 'Done! <strong>%s</strong> posts with tags were read.', $count), $count ) . '<br /></p>';
87 echo '<ul>';
88 foreach ( $metakeys as $post_meta ) {
89 if ( $post_meta->meta_value != '' ) {
90 $post_keys = explode(' ', $post_meta->meta_value);
91 foreach ( $post_keys as $keyword ) {
92 $keyword = addslashes(trim(str_replace('+',' ',$keyword)));
93 if ( '' != $keyword ) {
94 echo '<li>' . $post_meta->post_id . '&nbsp;-&nbsp;' . $keyword . '</li>';
95 if ( !$precheck )
96 wp_add_post_tags($post_meta->post_id, $keyword);
97 }
98 }
99 }
100 if ( !$precheck )
101 delete_post_meta($post_meta->post_id, 'tags');
102 }
103 echo '</ul>';
104 }
105
106 echo '<form action="admin.php?import=btt&amp;step='.($precheck? 2:3).'" method="post">';
107 wp_nonce_field('import-btt');
108 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Next').'" /></p>';
109 echo '</form>';
110 echo '</div>';
111 }
112
113 function done() {
114 echo '<div class="narrow">';
115 echo '<p><h3>'.__('Import Complete!').'</h3></p>';
116 echo '</div>';
117 }
118
119 function BunnyTags_Import() {
120 }
121
122}
123
124// create the import object
125$btt_import = new BunnyTags_Import();
126
127// add it to the import page!
128register_importer('btt', 'Bunny&#8217;s Technorati Tags', __('Import Bunny&#8217;s Technorati Tags into WordPress tags.'), array($btt_import, 'dispatch'));
129
130?>
Note: See TracBrowser for help on using the repository browser.