Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Hack: bb replies as wp comments; using bb API?

Cheers!

Further hack here, to migrate any comments made to WP posts that have a corresponding bb topic (via the bbPress Post plugin again) as replies to the thread. Unfortunately the date/time won’t be right, it’ll be like a new post just made.

This needs to be installed/activated as a plugin to work, and to prevent it somehow accidentally happening again I suggest you immediately uninstall it. To run it, simply append “?lulz=p” to a URL and it’ll get to work – make sure you only do this once! An interface would be a lot neater, but, well, meh.

At your own risk.

<?php
/*
Plugin Name: Comments migrate
Plugin URI:
Description: moves wp comments into bb posts.
Author: fel64
Version: 0.7
Author URI: http://www.loinhead.net/
*/
function felmigrate()
{
global $bbdb, $bb_table_prefix;
//foreach blogpost/topic in wp_bbpress_post_posts
$bridge = $bbdb->get_results( ' SELECT post_id, topic_id
FROM wp_bbpress_post_posts', ARRAY_A );
foreach( $bridge as $sumthing => $link )
{
//foreach comment
$wppost = $link['post_id'];
$bbtopic = $link['topic_id'];
$felcoms = $bbdb->get_results( " SELECT comment_author, comment_date, comment_content, comment_author_IP
FROM wp_comments
WHERE comment_post_ID = $wppost" );
if( $felcoms )
{
foreach( $felcoms as $sumthing => $felcom )
{
//if valid user
$felu = bb_get_user_by_name( $felcom->comment_author );
if( $felu )
{
//create new post in that thread with said details
fel_new_post( $bbtopic, $felcom, $felu->ID );
}
}
}
}
//party
}
function fel_new_post( $topic_id, $post_details, $felID ) {
global $bbdb, $bb_cache, $bb_table_prefix, $thread_ids_cache;
$topic_id = (int) $topic_id;

$bb_post = $post_details->comment_content;
//$bb_post = apply_filters('pre_post', $bb_post, false, $topic_id);
$bb_post = htmlspecialchars( $bb_post, ENT_QUOTES );
$post_status = 0;
$now = bb_current_time('mysql');
//$now = $post_details->comment_date;
$uid = $felID;
$uname = $post_details->comment_author;
$ip = $post_details->comment_author_IP;

$topic = get_topic( $topic_id );
$forum_id = $topic->forum_id;

if ( $bb_post && $topic ) {
$topic_posts = ( 0 == $post_status ) ? $topic->topic_posts + 1 : $topic->topic_posts;
$bbdb->query("INSERT INTO $bbdb->posts
(forum_id, topic_id, poster_id, post_text, post_time, poster_ip, post_status, post_position)
VALUES
('$forum_id', '$topic_id', '$uid', '$bb_post','$now', '$ip', '$post_status', $topic_posts)");
$post_id = $bbdb->insert_id;
if ( 0 == $post_status ) {
$bbdb->query("UPDATE $bbdb->forums SET posts = posts + 1 WHERE forum_id = $topic->forum_id");

/* if( $now < $topic->topic_time )
{
$now = $topic->topic_time;
$uid = $topic->topic_last_poster;
$uname = $topic->topic_last_poster_name;
$post_id = $topic->topic_last_post_id;
}
*/ $bbdb->query("UPDATE $bbdb->topics SET topic_time = '$now', topic_last_poster = '$uid', topic_last_poster_name = '$uname',
topic_last_post_id = '$post_id', topic_posts = '$topic_posts' WHERE topic_id = '$topic_id'");
if ( isset($thread_ids_cache[$topic_id]) ) {
$thread_ids_cache[$topic_id]['post'][] = $post_id;
$thread_ids_cache[$topic_id]['poster'][] = $uid;
}
$post_ids = get_thread_post_ids( $topic_id );
if ( !in_array($uid, array_slice($post_ids['poster'], 0, -1)) )
bb_update_usermeta( $uid, $bb_table_prefix . 'topics_replied', $bb_current_user->data->topics_replied + 1 );
} else
bb_update_topicmeta( $topic->topic_id, 'deleted_posts', isset($topic->deleted_posts) ? $topic->deleted_posts + 1 : 1 );
if ( !bb_current_user_can('throttle') )
bb_update_usermeta( $uid, 'last_posted', time() );
$bb_cache->flush_one( 'topic', $topic_id );
$bb_cache->flush_many( 'thread', $topic_id );
$bb_cache->flush_many( 'forum', $forum_id );
do_action('bb_new_post', $post_id);
return $post_id;
} else {
return false;
}
}

//plunge
if( $_GET['lulz'] = 'p' )
felmigrate();
?>

Skip to toolbar