header(); switch ($step) { case 0 : $this->greet(); break; case 1 : $this->get_dates(); break; case 2 : $this->get_hits(); break; } // load the footer $this->footer(); } function header() { echo '
'; echo '

'.__('bStat Upgrader').'

'; } function footer() { echo '
'; } function greet() { echo '
'; echo '

'.__('Yeah baby! This imports hit counts and search engine terms from older versions of bSuite or bStat into the new bSuite bStat.').'

'; echo '

'.__('This has not been tested much. Mileage may vary.').'

'; if(!bstat){ echo '

'.__('You must activate bStat before proceeding.').'

'; }else{ echo '

'.__('Don’t be stupid - backup your database before proceeding!').'

'; echo '
'; echo '

'; echo '
'; } echo '
'; } function get_dates() { global $wpdb; $dates_hits = $wpdb->get_col('SELECT bstat_date FROM '. $wpdb->prefix .'bstat_hits GROUP BY bstat_date '); update_option('bstat_import_hits', $dates_hits); $dates_refs = $wpdb->get_col('SELECT bstat_date FROM '. $wpdb->prefix .'bstat_refs WHERE issearchengine = 1 GROUP BY bstat_date '); update_option('bstat_import_refs', $dates_refs); echo '
'; echo '

You've got '. count($dates_hits) .' days of hits and '. count($dates_refs) .' days of referrers (yes, they're often different).

'; echo '
'; echo '

'; echo '
'; } function get_hits() { echo '
'; // update search table with content from all posts global $wpdb, $bstat; set_time_limit(0); ignore_user_abort(TRUE); $dates_hits = get_option('bstat_import_hits'); $date_hit = array_shift($dates_hits); $hits = $wpdb->get_results(' SELECT post_id, hits_reads FROM '. $wpdb->prefix .'bstat_hits WHERE bstat_date = "'. $date_hit .'" ', ARRAY_A); update_option('bstat_import_hits', $dates_hits); if( is_array( $hits ) ) { echo '

You've got '. count($hits) .' entries in the hits table for '. $date_hit .'. Just '. count($dates_hits).' more days to go, please be patient.

'; foreach( $hits as $hit ) { $wpdb->get_results(" INSERT INTO $bstat->hits_table (post_id, hit_count, hit_date) VALUES ({$hit['post_id']}, {$hit['hits_reads']}, '{$date_hit}') ON DUPLICATE KEY UPDATE hit_count = hit_count + {$hit['hits_reads']} "); echo '. '; } } $dates_refs = get_option('bstat_import_refs'); $date_ref = array_shift($dates_refs); $refs = $wpdb->get_results(' SELECT post_id, hits, ref FROM '. $wpdb->prefix .'bstat_refs WHERE bstat_date = "'. $date_ref .'" AND issearchengine = 1 ', ARRAY_A); update_option('bstat_import_refs', $dates_refs); if( is_array( $refs ) ) { echo '

You've got '. count($refs) .' entries in the refs table for '. $date_ref .'. Only '. count($dates_refs).' more days to go, please be patient.

'; foreach( $refs as $ref ) { // check if this search is already in the terms table if(!is_term(urldecode($ref['ref']), 'bsuite_search')) wp_insert_term(urldecode($ref['ref']), 'bsuite_search'); // it's in the terms table, what's the id? $term_id = is_term(urldecode($ref['ref'])); // write it to the bsuite3_refs table with date if(!empty($term_id)){ $wpdb->query(" INSERT INTO $bstat->rterms_table (post_id, term_id, hit_count, hit_date) VALUES ({$ref['post_id']}, $term_id, {$ref['hits']}, '$date_ref') ON DUPLICATE KEY UPDATE hit_count = hit_count + {$ref['hits']}; "); // the following is disabled now because it causes memory problems //wp_set_object_terms($ref['post_id'], urldecode($ref['ref']), 'bsuite_search', TRUE); } echo '. '; } } if(count($dates_hits) == 0 && count($dates_refs) == 0){ echo '

Yep. We're done.

'; echo '

Now, go deactivate this plugin. You don't need it anymore. (Running it again will inflate your stats, but that's cheating.)

'; } else { ?>

importer_code, $bstat_import->importer_name, $bstat_import->importer_desc, array (&$bstat_import, 'dispatch')); } add_action('activate_'.plugin_basename(__FILE__), 'bstat_importer_activate'); function bstat_importer_activate() { global $wp_db_version; // Deactivate on pre 2.3 blogs if($wp_db_version<6075) { $current = get_settings('active_plugins'); array_splice($current, array_search( plugin_basename(__FILE__), $current), 1 ); update_option('active_plugins', $current); do_action('deactivate_'.plugin_basename(__FILE__)); } } ?>