PHP Cross Reference of WordPress Subversion HEAD

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

title

Body

[close]

/wp-admin/import/ -> utw.php (source)

   1  <?php
   2  
   3  class UTW_Import {
   4  
   5  	function header()  {
   6          echo '<div class="wrap">';
   7          echo '<h2>'.__('Import Ultimate Tag Warrior').'</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 Ultimate Tag Warrior 3 installation into this blog using the new WordPress native tagging structure.').'</p>';
  18          echo '<p>'.__('This has not been tested on any other versions of Ultimate Tag Warrior. Mileage may vary.').'</p>';
  19          echo '<p>'.__('To accommodate larger databases for those tag-crazy authors out there, we have made this into an easy 5-step program to help you kick that nasty UTW habit. Just keep clicking along and we will let you know when you are in the clear!').'</p>';
  20          echo '<p><strong>'.__('Don&#8217;t be stupid - backup your database before proceeding!').'</strong></p>';
  21          echo '<form action="admin.php?import=utw&amp;step=1" method="post">';
  22          echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 1 &raquo;').'" /></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          if ( $step > 1 )
  36              check_admin_referer('import-utw');
  37  
  38          // load the header
  39          $this->header();
  40  
  41          switch ( $step ) {
  42              case 0 :
  43                  $this->greet();
  44                  break;
  45              case 1 :
  46                  $this->import_tags();
  47                  break;
  48              case 2 :
  49                  $this->import_posts();
  50                  break;
  51              case 3:
  52                  $this->import_t2p();
  53                  break;
  54              case 4:
  55                  $this->cleanup_import();
  56                  break;
  57          }
  58  
  59          // load the footer
  60          $this->footer();
  61      }
  62  
  63  
  64  	function import_tags ( ) {
  65          echo '<div class="narrow">';
  66          echo '<p><h3>'.__('Reading UTW Tags&#8230;').'</h3></p>';
  67  
  68          $tags = $this->get_utw_tags();
  69  
  70          // if we didn't get any tags back, that's all there is folks!
  71          if ( !is_array($tags) ) {
  72              echo '<p>' . __('No Tags Found!') . '</p>';
  73              return false;
  74          }
  75          else {
  76  
  77              // if there's an existing entry, delete it
  78              if ( get_option('utwimp_tags') ) {
  79                  delete_option('utwimp_tags');
  80              }
  81  
  82              add_option('utwimp_tags', $tags);
  83  
  84  
  85              $count = count($tags);
  86  
  87              echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags were read.'), $count ) . '<br /></p>';
  88              echo '<p>' . __('The following tags were found:') . '</p>';
  89  
  90              echo '<ul>';
  91  
  92              foreach ( $tags as $tag_id => $tag_name ) {
  93  
  94                  echo '<li>' . $tag_name . '</li>';
  95  
  96              }
  97  
  98              echo '</ul>';
  99  
 100              echo '<br />';
 101  
 102              echo '<p>' . __('If you don&#8217;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>';
 103  
 104  
 105          }
 106  
 107          echo '<form action="admin.php?import=utw&amp;step=2" method="post">';
 108          wp_nonce_field('import-utw');
 109          echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 2 &raquo;').'" /></p>';
 110          echo '</form>';
 111          echo '</div>';
 112      }
 113  
 114  
 115  	function import_posts ( ) {
 116          echo '<div class="narrow">';
 117          echo '<p><h3>'.__('Reading UTW Post Tags&#8230;').'</h3></p>';
 118  
 119          // read in all the UTW tag -> post settings
 120          $posts = $this->get_utw_posts();
 121  
 122          // if we didn't get any tags back, that's all there is folks!
 123          if ( !is_array($posts) ) {
 124              echo '<p>' . __('No posts were found to have tags!') . '</p>';
 125              return false;
 126          }
 127          else {
 128  
 129              // if there's an existing entry, delete it
 130              if ( get_option('utwimp_posts') ) {
 131                  delete_option('utwimp_posts');
 132              }
 133  
 134              add_option('utwimp_posts', $posts);
 135  
 136  
 137              $count = count($posts);
 138  
 139              echo '<p>' . sprintf( __('Done! <strong>%s</strong> tag to post relationships were read.'), $count ) . '<br /></p>';
 140  
 141          }
 142  
 143          echo '<form action="admin.php?import=utw&amp;step=3" method="post">';
 144          wp_nonce_field('import-utw');
 145          echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 3 &raquo;').'" /></p>';
 146          echo '</form>';
 147          echo '</div>';
 148  
 149      }
 150  
 151  
 152  	function import_t2p ( ) {
 153  
 154          echo '<div class="narrow">';
 155          echo '<p><h3>'.__('Adding Tags to Posts&#8230;').'</h3></p>';
 156  
 157          // run that funky magic!
 158          $tags_added = $this->tag2post();
 159  
 160          echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags were added!'), $tags_added ) . '<br /></p>';
 161  
 162          echo '<form action="admin.php?import=utw&amp;step=4" method="post">';
 163          wp_nonce_field('import-utw');
 164          echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 4 &raquo;').'" /></p>';
 165          echo '</form>';
 166          echo '</div>';
 167  
 168      }
 169  
 170  
 171  	function get_utw_tags ( ) {
 172  
 173          global $wpdb;
 174  
 175          // read in all the tags from the UTW tags table: should be wp_tags
 176          $tags_query = "SELECT tag_id, tag FROM " . $wpdb->prefix . "tags";
 177  
 178          $tags = $wpdb->get_results($tags_query);
 179  
 180          // rearrange these tags into something we can actually use
 181          foreach ( $tags as $tag ) {
 182  
 183              $new_tags[$tag->tag_id] = $tag->tag;
 184  
 185          }
 186  
 187          return $new_tags;
 188  
 189      }
 190  
 191  	function get_utw_posts ( ) {
 192  
 193          global $wpdb;
 194  
 195          // read in all the posts from the UTW post->tag table: should be wp_post2tag
 196          $posts_query = "SELECT tag_id, post_id FROM " . $wpdb->prefix . "post2tag";
 197  
 198          $posts = $wpdb->get_results($posts_query);
 199  
 200          return $posts;
 201  
 202      }
 203  
 204  
 205  	function tag2post ( ) {
 206  
 207          // get the tags and posts we imported in the last 2 steps
 208          $tags = get_option('utwimp_tags');
 209          $posts = get_option('utwimp_posts');
 210  
 211          // null out our results
 212          $tags_added = 0;
 213  
 214          // loop through each post and add its tags to the db
 215          foreach ( $posts as $this_post ) {
 216  
 217              $the_post = (int) $this_post->post_id;
 218              $the_tag = (int) $this_post->tag_id;
 219  
 220              // what's the tag name for that id?
 221              $the_tag = $tags[$the_tag];
 222  
 223              // screw it, just try to add the tag
 224              wp_add_post_tags($the_post, $the_tag);
 225  
 226              $tags_added++;
 227  
 228          }
 229  
 230          // that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
 231          return $tags_added;
 232  
 233  
 234      }
 235  
 236  
 237  	function cleanup_import ( ) {
 238  
 239          delete_option('utwimp_tags');
 240          delete_option('utwimp_posts');
 241  
 242          $this->done();
 243  
 244      }
 245  
 246  
 247  	function done ( ) {
 248  
 249          echo '<div class="narrow">';
 250          echo '<p><h3>'.__('Import Complete!').'</h3></p>';
 251  
 252          echo '<p>' . __('OK, so we lied about this being a 5-step program! You&#8217;re done!') . '</p>';
 253  
 254          echo '<p>' . __('Now wasn&#8217;t that easy?') . '</p>';
 255  
 256          echo '</div>';
 257  
 258      }
 259  
 260  
 261  	function UTW_Import ( ) {
 262  
 263          // Nothing.
 264  
 265      }
 266  
 267  }
 268  
 269  
 270  // create the import object
 271  $utw_import = new UTW_Import();
 272  
 273  // add it to the import page!
 274  register_importer('utw', 'Ultimate Tag Warrior', __('Import Ultimate Tag Warrior tags into the new native tagging structure.'), array($utw_import, 'dispatch'));
 275  
 276  ?>


Generated Thu Dec 6 06:47:08 2007 for RedAlt XRefs Cross-referenced by PHPXref 0.6 and RedAlt