1 | <?php |
---|
2 | |
---|
3 | class JeromesKeywordV1_Import { |
---|
4 | |
---|
5 | function header() { |
---|
6 | echo '<div class="wrap">'; |
---|
7 | echo '<h2>'.__('Import Jerome’s Keywords').'</h2>'; |
---|
8 | echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>'; |
---|
9 | } |
---|
10 | |
---|
11 | function footer() { |
---|
12 | echo '</div>'; |
---|
13 | } |
---|
14 | |
---|
15 | function greet() { |
---|
16 | echo '<div class="narrow">'; |
---|
17 | echo '<p>'.__('Howdy! This imports tags from an existing Jerome’s Keywords 1.x installation into this blog using the new WordPress native tagging structure.').'</p>'; |
---|
18 | echo '<p>'.__('This is not suitable for Jerome’s Keywords version 2.x.').'</p>'; |
---|
19 | echo '<p><strong>'.__('Don’t be stupid - backup your database before proceeding!').'</strong></p>'; |
---|
20 | echo '<p><em>'.__('Source code is modified from Ultimate Tag Warrior importer (utw.php)').'</em></p>'; |
---|
21 | echo '<form action="admin.php?import=jkw1&step=1" method="post">'; |
---|
22 | echo '<p class="submit"><input type="submit" name="submit" value="'.__('Next »').'" /></p>'; |
---|
23 | echo '</form>'; |
---|
24 | echo '</div>'; |
---|
25 | } |
---|
26 | |
---|
27 | |
---|
28 | function dispatch () { |
---|
29 | if ( empty( $_GET['step'] ) ) { |
---|
30 | $step = 0; |
---|
31 | } else { |
---|
32 | $step = (int) $_GET['step']; |
---|
33 | } |
---|
34 | |
---|
35 | // load the header |
---|
36 | $this->header(); |
---|
37 | |
---|
38 | switch ( $step ) { |
---|
39 | case 0 : |
---|
40 | $this->greet(); |
---|
41 | break; |
---|
42 | case 1 : |
---|
43 | $this->check_post_keyword( true ); |
---|
44 | break; |
---|
45 | case 2 : |
---|
46 | $this->check_post_keyword( false ); |
---|
47 | break; |
---|
48 | case 3: |
---|
49 | $this->cleanup_import(); |
---|
50 | break; |
---|
51 | } |
---|
52 | |
---|
53 | // load the footer |
---|
54 | $this->footer(); |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | function check_post_keyword ( $precheck = true ) { |
---|
59 | global $wpdb; |
---|
60 | |
---|
61 | echo '<div class="narrow">'; |
---|
62 | echo '<p><h3>'.__('Reading Jerome’s Keywords Tags…').'</h3></p>'; |
---|
63 | |
---|
64 | // import Jerome's Keywords tags |
---|
65 | $qry = "SELECT post_id, meta_id, meta_key, meta_value |
---|
66 | FROM $wpdb->postmeta |
---|
67 | WHERE $wpdb->postmeta.meta_key = 'keywords'"; |
---|
68 | $metakeys = $wpdb->get_results($qry); |
---|
69 | if ( !is_array($metakeys)) { |
---|
70 | echo '<p>' . __('No Tags Found!') . '</p>'; |
---|
71 | return false; |
---|
72 | } |
---|
73 | else { |
---|
74 | $count = count($metakeys); |
---|
75 | echo '<p>' . sprintf( __('Done! <strong>%s</strong> posts with tags were read.'), $count ) . '<br /></p>'; |
---|
76 | |
---|
77 | echo '<ul>'; |
---|
78 | |
---|
79 | foreach($metakeys as $post_meta) { |
---|
80 | if ($post_meta->meta_value != '') { |
---|
81 | $post_keys = explode(',', $post_meta->meta_value); |
---|
82 | foreach($post_keys as $keyword) { |
---|
83 | $keyword = addslashes(trim($keyword)); |
---|
84 | if ($keyword != '') |
---|
85 | echo '<li>' . $post_meta->post_id . ' - ' . $keyword . '</li>'; |
---|
86 | if( !$precheck ){ |
---|
87 | wp_add_post_tags($post_meta->post_id, $keyword); |
---|
88 | } |
---|
89 | } |
---|
90 | } |
---|
91 | if( !$precheck ){ |
---|
92 | delete_post_meta($post_meta->post_id, 'keywords'); |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | echo '</ul>'; |
---|
97 | |
---|
98 | } |
---|
99 | |
---|
100 | echo '<form action="admin.php?import=jkw1&step='.($precheck? 2:3).'" method="post">'; |
---|
101 | echo '<p class="submit"><input type="submit" name="submit" value="'.__('Next »').'" /></p>'; |
---|
102 | echo '</form>'; |
---|
103 | echo '</div>'; |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | function cleanup_import ( ) { |
---|
108 | |
---|
109 | |
---|
110 | $this->done(); |
---|
111 | |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | function done ( ) { |
---|
116 | |
---|
117 | echo '<div class="narrow">'; |
---|
118 | echo '<p><h3>'.__('Import Complete!').'</h3></p>'; |
---|
119 | echo '</div>'; |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | function JeromesKeywordV1_Import ( ) { |
---|
125 | |
---|
126 | // Nothing. |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | // create the import object |
---|
134 | $jkw1_import = new JeromesKeywordV1_Import(); |
---|
135 | |
---|
136 | // add it to the import page! |
---|
137 | register_importer('jkw1', 'Jerome’s keyword', __('Import Jerome’s keyword into the new native tagging structure.'), array($jkw1_import, 'dispatch')); |
---|
138 | |
---|
139 | ?> |
---|