Ticket #4931: btt.importer.diff

File btt.importer.diff, 3.7 kB (added by westi, 10 months ago)

The importer

  • wp-admin/import/btt.php

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