/tags/Doduo_1.1/WebKitSite/blog/wp-admin/import/btt.php

https://github.com/weissms/owb-mirror · PHP · 115 lines · 92 code · 18 blank · 5 comment · 10 complexity · 34ca1074d54529f328827c421a40ddcd MD5 · raw file

  1. <?php
  2. class BunnyTags_Import {
  3. function header() {
  4. echo '<div class="wrap">';
  5. echo '<h2>'.__('Import Bunny&#8217;s Technorati Tags').'</h2>';
  6. echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
  7. }
  8. function footer() {
  9. echo '</div>';
  10. }
  11. function greet() {
  12. echo '<div class="narrow">';
  13. echo '<p>'.__('Howdy! This imports tags from an existing Bunny&#8217;s Technorati Tags installation into this blog using the new WordPress native tagging structure.').'</p>';
  14. echo '<p>'.__('This is suitable for Bunny&#8217;s Technorati Tags version 0.6.').'</p>';
  15. echo '<p><strong>'.__('All existing Bunny&#8217;s Technorati Tags will be removed after import.').'</strong></p>';
  16. echo '<p><strong>'.__('Don&#8217;t be stupid - backup your database before proceeding!').'</strong></p>';
  17. echo '<form action="admin.php?import=btt&amp;step=1" method="post">';
  18. wp_nonce_field('import-btt');
  19. echo '<p class="submit"><input type="submit" name="submit" value="'.__('Import Tags &raquo;').'" /></p>';
  20. echo '</form>';
  21. echo '</div>';
  22. }
  23. function dispatch() {
  24. if ( empty($_GET['step']) )
  25. $step = 0;
  26. else
  27. $step = abs(intval($_GET['step']));
  28. // load the header
  29. $this->header();
  30. switch ( $step ) {
  31. case 0 :
  32. $this->greet();
  33. break;
  34. case 1 :
  35. check_admin_referer('import-btt');
  36. $this->check_post_keyword( true );
  37. break;
  38. case 2 :
  39. check_admin_referer('import-btt');
  40. $this->check_post_keyword( false );
  41. break;
  42. case 3:
  43. $this->done();
  44. break;
  45. }
  46. // load the footer
  47. $this->footer();
  48. }
  49. function check_post_keyword($precheck = true) {
  50. global $wpdb;
  51. echo '<div class="narrow">';
  52. echo '<p><h3>'.__('Reading Bunny&#8217;s Technorati Tags&#8230;').'</h3></p>';
  53. // import Bunny's Keywords tags
  54. $metakeys = $wpdb->get_results("SELECT post_id, meta_id, meta_key, meta_value FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'tags'");
  55. if ( !is_array($metakeys)) {
  56. echo '<p>' . __('No Tags Found!') . '</p>';
  57. return false;
  58. } else {
  59. $count = count($metakeys);
  60. echo '<p>' . sprintf( __('Done! <strong>%s</strong> posts with tags were read.'), $count ) . '<br /></p>';
  61. echo '<ul>';
  62. foreach ( $metakeys as $post_meta ) {
  63. if ( $post_meta->meta_value != '' ) {
  64. $post_keys = explode(' ', $post_meta->meta_value);
  65. foreach ( $post_keys as $keyword ) {
  66. $keyword = addslashes(trim(str_replace('+',' ',$keyword)));
  67. if ( '' != $keyword ) {
  68. echo '<li>' . $post_meta->post_id . '&nbsp;-&nbsp;' . $keyword . '</li>';
  69. if ( !$precheck )
  70. wp_add_post_tags($post_meta->post_id, $keyword);
  71. }
  72. }
  73. }
  74. if ( !$precheck )
  75. delete_post_meta($post_meta->post_id, 'tags');
  76. }
  77. echo '</ul>';
  78. }
  79. echo '<form action="admin.php?import=btt&amp;step='.($precheck? 2:3).'" method="post">';
  80. wp_nonce_field('import-btt');
  81. echo '<p class="submit"><input type="submit" name="submit" value="'.__('Next &raquo;').'" /></p>';
  82. echo '</form>';
  83. echo '</div>';
  84. }
  85. function done() {
  86. echo '<div class="narrow">';
  87. echo '<p><h3>'.__('Import Complete!').'</h3></p>';
  88. echo '</div>';
  89. }
  90. function BunnyTags_Import() {
  91. }
  92. }
  93. // create the import object
  94. $btt_import = new BunnyTags_Import();
  95. // add it to the import page!
  96. register_importer('btt', 'Bunny&#8217;s Technorati Tags', __('Import Bunny&#8217;s Technorati Tags into the new native tagging structure.'), array($btt_import, 'dispatch'));
  97. ?>