start_transaction(); //fetch and process wp data $postdata = get_postdata($post_id); $message = $postdata['Content']; $message = ih_cleanArticle($message); $subject = $postdata['Title']; $now = time(); $new_pid = $db->insert_id(); // Create nothing if the post already has topicid $tid = get_post_meta($post_id, 'topicid', TRUE); $pid = get_post_meta($post_id, 'postid', TRUE); if($tid) { print_r(get_post_meta($post_id)); echo "pid: " . $pid; $low_prio = ($db_type == 'mysql') ? 'LOW_PRIORITY ' : ''; $updatethreadquery = "UPDATE ".$db->prefix."topics SET subject='".$db->escape($subject)."', last_post_id='".$new_pid."' WHERE id=".$tid.""; $db->query($updatethreadquery) or die ("Error" . mysql_error() ." File: " . __FILE__ . " on line: " . __LINE__.""); return $post_id; } // Create the topic $db->query('INSERT INTO '.$db->prefix.'topics (poster, subject, posted, last_post, last_poster, forum_id) VALUES(\''.$db->escape($username).'\', \''.$db->escape($subject).'\', '.$now.', '.$now.', \''.$db->escape($username).'\', '.$fid.')') or error('Unable to create topic', __FILE__, __LINE__, $db->error()); $new_tid = $db->insert_id(); $ntid = $new_tid; // Create the post ("topic post") $messagetolink = "Discuss the article [url='www.trickyjig.com/forumwp/?p=".$post_id."'][b]posted here.[/b][/url]"; $db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_id, poster_ip, message, hide_smilies, posted, topic_id) VALUES(\''.$db->escape($username).'\', '.$pun_user['id'].', \''.$_SERVER['REMOTE_ADDR'].'\', \''.$db->escape($messagetolink).'\', \''.$hide_smilies.'\', '.$now.', '.$new_tid.')') or error('Unable to create post', __FILE__, __LINE__, $db->error()); // Update the topic with last_post_id //$db->query('UPDATE '.$db->prefix.'topics SET last_post_id='.$new_pid.' WHERE id='.$new_tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error()); /*not implemented yet due to function conflicts update_search_index('post', $new_pid, $message, $subject); update_forum($fid);*/ $low_prio = ($db_type == 'mysql') ? 'LOW_PRIORITY ' : ''; $db->query('UPDATE '.$low_prio.$db->prefix.'users SET num_posts=num_posts+1, last_post='.$now.' WHERE id='.$pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error()); //$querystring = " "; $db->query('UPDATE '.$low_prio.$db->prefix.'forums SET num_topics=num_topics+1, last_post='.$now.', last_post_id=\''.$pun_user['id'].'\', last_poster=\''.$db->escape($username).'\' WHERE id=\''.$fid.'\'') or error('Unable to update forum', __FILE__, __LINE__, $db->error()); //add custom field to wordpress post $qry = "INSERT INTO {$wpdb->postmeta} (Post_ID, meta_key, meta_value) VALUES ({$post_id}, 'topicid','{$new_tid}');"; $wpdb->query($qry); return $post_id; } /* Cleans WordPress HTML and adds BBCode. This is from NP_PunBB at http://nupusi.com, by Radek HULAN, Bert Garcia and Rickard Andersson. I just removed some Nucleus specific stuff*/ function ih_cleanArticle($article) { global $CONF; // Make sure all linebreaks are \n $article = str_replace("\r", "", $article); // convert links into bbCode $article = preg_replace('/(.*?)<\/a>/', '[url=$2]$3[/url]', $article); $article = preg_replace('//', '[img]$2[/img]', $article); $article = preg_replace('/<%(.*?)%>/', '', $article); // do bold, italic and underline $article = str_replace(array('', '', '', '', '', ''), array('[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]'), $article); // pre/code into bbCode $article = str_replace('
', "[code]", $article);
		$article = str_replace('
', "[/code] ", $article); $article = str_replace('', "[code]", $article); $article = str_replace('', "[/code] ", $article); // blockquote into bbCode $article=str_replace('
',"[quote]",$article); $article=str_replace('
',"[/quote] ",$article); // ending tags into line breaks $article = str_replace('

', "\n\n", $article); $article = str_replace("
\n", "\n", $article); $article = str_replace('
', "\n", $article); $article = str_replace("
\n", "\n", $article); $article = str_replace('
', "\n", $article); $article = str_replace('', "\n", $article); // lists $article = str_replace('
  • ', "* ", $article); // headlines in bold $article = preg_replace('/(.*?)<\/h(.*?)>/', "[b]$2[/b]\n", $article); // strip all other tags $article = trim(strip_tags($article)); // convert < and > if entered to display code $article = str_replace(array('<', '>'), array('<', '>'), $article); return $article; } //Adds a link to the relevant forum topic function ih_add_comment($post_id) { $punbb_info = get_option("wp2punbb_info"); $forumurl = $punbb_info[4]; $commentlink = $punbb_info[5]; $tid = get_post_meta($post_id, 'topicid', TRUE); if($tid){ //echo '| asdf'.$commentlink.'asdf'; echo ('Discuss in Forum | '); } } //Wordpress options handler function ih_add_pages() { add_options_page('WP2PunBB', 'WP2PunBB', 8, __FILE__, 'ih_options_page'); } //Wordpress Options page interface function ih_options_page() { if (isset($_POST['info_update'])) { $punbb_info[0]=$_POST['username']; $punbb_info[1]=$_POST['forumid']; $punbb_info[2]=$_POST['userid']; $punbb_info[3]=$_POST['forumdir']; $punbb_info[4]=$_POST['forumurl']; $punbb_info[5]=$_POST['commentlink']; update_option("wp2punbb_info", $punbb_info); ?>

    Options updated

    Ians WP2PunBB Plugin

    PunBB forum options

    PunBB username:

    PunBB user ID:

    PunBB comment forum ID:

    Comment link text:

    URL to punbb:

    Include final slash e.g. http://www.example.com/forum/

    Absolute path to punbb:

    Include final slash e.g. /var/www/httpdocs/forum/