Changeset 5700 for trunk/wp-admin/import/utw.php
- Timestamp:
- 06/14/2007 02:25:30 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/import/utw.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/import/utw.php
r5390 r5700 2 2 3 3 class UTW_Import { 4 4 5 5 function header() { 6 6 echo '<div class="wrap">'; … … 24 24 echo '</div>'; 25 25 } 26 27 26 27 28 28 function dispatch () { 29 29 if ( empty( $_GET['step'] ) ) { … … 32 32 $step = (int) $_GET['step']; 33 33 } 34 34 35 35 // load the header 36 36 $this->header(); 37 37 38 38 switch ( $step ) { 39 39 case 0 : … … 53 53 break; 54 54 } 55 55 56 56 // load the footer 57 57 $this->footer(); 58 58 } 59 60 59 60 61 61 function import_tags ( ) { 62 62 echo '<div class="narrow">'; 63 63 echo '<p><h3>'.__('Reading UTW Tags…').'</h3></p>'; 64 64 65 65 $tags = $this->get_utw_tags(); 66 66 67 67 // if we didn't get any tags back, that's all there is folks! 68 68 if ( !is_array($tags) ) { … … 78 78 79 79 add_option('utwimp_tags', $tags); 80 80 81 81 82 82 $count = count($tags); 83 83 84 84 echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags were read.'), $count ) . '<br /></p>'; 85 85 echo '<p>' . __('The following tags were found:') . '</p>'; 86 86 87 87 echo '<ul>'; 88 88 89 89 foreach ( $tags as $tag_id => $tag_name ) { 90 90 91 91 echo '<li>' . $tag_name . '</li>'; 92 92 93 93 } 94 94 95 95 echo '</ul>'; 96 96 97 97 echo '<br />'; 98 98 99 99 echo '<p>' . __('If you don’t want to import any of these tags, you should delete them from the UTW tag management page and then re-run this import.') . '</p>'; 100 101 102 } 103 100 101 102 } 103 104 104 echo '<form action="admin.php?import=utw&step=2" method="post">'; 105 105 echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 2 »').'" /></p>'; … … 107 107 echo '</div>'; 108 108 } 109 110 109 110 111 111 function import_posts ( ) { 112 112 echo '<div class="narrow">'; … … 129 129 130 130 add_option('utwimp_posts', $posts); 131 131 132 132 133 133 $count = count($posts); 134 134 135 135 echo '<p>' . sprintf( __('Done! <strong>%s</strong> tag to post relationships were read.'), $count ) . '<br /></p>'; 136 136 137 137 } 138 138 … … 143 143 144 144 } 145 146 145 146 147 147 function import_t2p ( ) { 148 148 … … 152 152 // run that funky magic! 153 153 $tags_added = $this->tag2post(); 154 154 155 155 echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags where added!'), $tags_added ) . '<br /></p>'; 156 156 … … 161 161 162 162 } 163 164 163 164 165 165 function get_utw_tags ( ) { 166 166 167 167 global $wpdb; 168 168 169 169 // read in all the tags from the UTW tags table: should be wp_tags 170 170 $tags_query = "SELECT tag_id, tag FROM " . $wpdb->prefix . "tags"; 171 171 172 172 $tags = $wpdb->get_results($tags_query); 173 173 174 174 // rearrange these tags into something we can actually use 175 175 foreach ( $tags as $tag ) { 176 176 177 177 $new_tags[$tag->tag_id] = $tag->tag; 178 179 } 180 178 179 } 180 181 181 return $new_tags; 182 182 183 183 } 184 184 185 185 function get_utw_posts ( ) { 186 186 187 187 global $wpdb; 188 188 189 189 // read in all the posts from the UTW post->tag table: should be wp_post2tag 190 190 $posts_query = "SELECT tag_id, post_id FROM " . $wpdb->prefix . "post2tag"; 191 191 192 192 $posts = $wpdb->get_results($posts_query); 193 193 194 194 return $posts; 195 196 } 197 198 195 196 } 197 198 199 199 function tag2post ( ) { 200 200 201 201 // get the tags and posts we imported in the last 2 steps 202 202 $tags = get_option('utwimp_tags'); 203 203 $posts = get_option('utwimp_posts'); 204 204 205 205 // null out our results 206 206 $tags_added = 0; 207 207 208 208 // loop through each post and add its tags to the db 209 209 foreach ( $posts as $this_post ) { 210 210 211 211 $the_post = (int) $this_post->post_id; 212 212 $the_tag = (int) $this_post->tag_id; 213 213 214 214 // what's the tag name for that id? 215 215 $the_tag = $tags[$the_tag]; 216 216 217 217 // screw it, just try to add the tag 218 218 wp_add_post_tags($the_post, $the_tag); 219 219 220 220 $tags_added++; 221 222 } 223 221 222 } 223 224 224 // that's it, all posts should be linked to their tags properly, pending any errors we just spit out! 225 225 return $tags_added; 226 227 228 } 229 230 226 227 228 } 229 230 231 231 function cleanup_import ( ) { 232 232 233 233 delete_option('utwimp_tags'); 234 234 delete_option('utwimp_posts'); 235 235 236 236 $this->done(); 237 238 } 239 240 237 238 } 239 240 241 241 function done ( ) { 242 242 243 243 echo '<div class="narrow">'; 244 244 echo '<p><h3>'.__('Import Complete!').'</h3></p>'; 245 245 246 246 echo '<p>' . __('OK, so we lied about this being a 5-step program! You’re done!') . '</p>'; 247 247 248 248 echo '<p>' . __('Now wasn’t that easy?') . '</p>'; 249 250 echo '</div>'; 251 252 } 253 249 250 echo '</div>'; 251 252 } 253 254 254 255 255 function UTW_Import ( ) { 256 256 257 257 // Nothing. 258 259 } 260 258 259 } 260 261 261 } 262 262
Note: See TracChangeset
for help on using the changeset viewer.