The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
vBulletin-WordPress Bridge Details »» | |||||||||||||||||||||||||
I have been looking around for a WordPress - vBulletin plug-in and can?t seem to find one. I had time today to look at the WordPress code and tried out some things, and came up with a small hack for a bridge.
This bridge will let you use vBulletin as the main comments area for the blog entry. A copy of the intro blog entry is automatically created in a specific forum you choose, as well as a link back to the original blog entry from the forum. The blog entry will also show the total comments made. Let me first say that I don?t have any experience in creating plug-ins for WordPress so please don?t ask me to convert this to one. If you plan to make this as an official plug-in or improve on it, please make sure to let me know so I can place a link on this article to yours. Thanks and I hope you all enjoy it. Note:
Database Changes: I have added a new column in WordPress? posts table to maintian the vBulletin thread id that will be automatically generated for the blog entry. Note that the table name prefix might be different from your WordPress table settings: Code:
ALTER TABLE `wp_posts` ADD `vb_threadid` INT(10); Save the following as vb3?settings.php and upload it to the Wordpress wp-includes folder: Code:
<?php // This just holds the vb variables $vb_bridge = 1; // 1=on 0=off $vb_forumid = '2'; // forum id to post copy of article $vb_userid = '1'; // user id to use for posting the article $vb_username = 'admin'; // name of the user id $vb_path = 'http://www.yoursite.com/forum'; //complete url of forums $vb_dbprefix = 'vb3_'; //vBulletin database prefix $vb_readmessage = 'Read the full blog entry.'; //message to be used in the forum to link back to the blog entry ?>
Added in v1.1: In the attached files at the right, download postfeed.php and upload it to the root folder of your vB forums (it should be in the same folder where external.php is). Files to be Modified: Here comes the slightly harder part. We need to modify some WordPress files. Part of the changes assume that you are using the Kubrick default theme. If you are using a different theme, change the corresponding files accordingly. wp-includes/comment-functions.php Replace: Code:
function get_comments_number( $comment_id ) { global $wpdb, $comment_count_cache; $comment_id = (int) $comment_id; if (!isset($comment_count_cache[$comment_id])) $comment_count_cache[$comment_id] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$comment_id' AND comment_approved = '1'"); return apply_filters('get_comments_number', $comment_count_cache[$comment_id]); } Code:
function get_comments_number( $comment_id ) { global $wpdb, $comment_count_cache; include (ABSPATH . WPINC . '/vb3-settings.php'); $comment_id = (int) $comment_id; if (!isset($comment_count_cache[$comment_id])) { if ($vb_bridge){ $vb_threadid = $wpdb->get_var("SELECT vb_threadid FROM $wpdb->comments WHERE id = '$comment_id'"); $comment_count_cache[$comment_id] = $wpdb->get_var("SELECT count(*)-1 FROM {$vb_dbprefix}post WHERE threadid = '$vb_threadid'"); } else { $comment_count_cache[$comment_id] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$comment_id' AND comment_approved = '1'"); } } return apply_filters('get_comments_number', $comment_count_cache[$comment_id]); } Code:
function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') { global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb; global $comment_count_cache; Code:
include (ABSPATH . WPINC . '/vb3-settings.php'); if ($vb_bridge){ $vb_threadid = $post->vb_threadid; if ($vb_threadid == "") { echo $none; return; } else { $comment_count_cache[$id] = $wpdb->get_var("SELECT count(*)-1 FROM {$vb_dbprefix}post WHERE threadid = '$vb_threadid'"); } $number = $comment_count_cache[$id]; echo '<a href="'.$vb_path.'/showthread.php?t=' . $vb_threadid .'&goto=newpost">'; comments_number($zero, $one, $more, $number); echo '</a>'; return; } Added in v1.1: wp-includes/feed-functions.php Replace: Code:
function comments_rss_link($link_text = 'Comments RSS', $commentsrssfilename = '') { $url = comments_rss($commentsrssfilename); echo "<a href='$url'>$link_text</a>"; } Code:
function comments_rss_link($link_text = 'Comments RSS', $commentsrssfilename = '') { global $post; include_once (ABSPATH . WPINC . '/vb3-settings.php'); if ($vb_bridge){ $url = $vb_path . '/postfeed.php?t=' . $post->vb_threadid . '&type=rss2'; } else { $url = comments_rss($commentsrssfilename); } echo "<a href='$url'>$link_text</a>"; } wp-admin/post.php Below: Code:
require_once('admin.php'); Code:
include_once (ABSPATH . WPINC . '/vb3-settings.php'); Code:
$result = $wpdb->query($postquery); Code:
// VB Bridge Start if ($vb_bridge) { if ($post_title == "") { return; } $saveid = $vb_userid; $savename = $vb_username; $author_name = $wpdb->get_var("SELECT `user_login` FROM $wpdb->users WHERE `id` = '$post_author'"); if ($author_name != ""){ $vb_authorid = $wpdb->get_var("SELECT `userid` FROM " . $vb_dbprefix . "user WHERE `username` = '$author_name'"); if ($vb_authorid != ""){ $saveid = $vb_authorid; $savename = $author_name; } } $curtime = time(); $sql = "INSERT INTO `{$vb_dbprefix}thread` SET `title`='{$post_title}',`lastpost`='{$curtime}', `forumid`='{$vb_forumid}', `open`='1', `postusername`='{$savename}', `postuserid`='{$saveid}', `lastposter`='{$savename}', `dateline`='{$curtime}', `visible`='1'"; $vbresult = $wpdb->query($sql); $vb_threadid = $wpdb->insert_id; if ($excerpt == ""){ $moreflag = strpos($content,'<!--more-->'); if ($moreflag === false) { $introtext = $content; } else { $introtext = substr($content, 0, $moreflag); } $bbcontent = '[quote'.']'.strip_tags($introtext).'['.'/quote]'; } else { $bbcontent = '[quote'.']'.strip_tags($excerpt).'['.'/quote]'; } $bbcontent .= '[URL='.get_permalink($post_ID).']['.'b]'.$vb_readmessage.'['.'/b]['.'/URL]'; $sql = "INSERT INTO `{$vb_dbprefix}post` SET `threadid`='{$vb_threadid}', `username`='{$savename}', `userid`='{$saveid}', `title`='{$post_title}', `pagetext`='{$bbcontent}', `ipaddress`='{$REMOTE_ADDR}', `allowsmilie`='1', `iconid`='1',`visible`='1', `dateline`='{$curtime}'"; $vbresult = $wpdb->query($sql); $sql = "UPDATE `{$vb_dbprefix}forum` SET `threadcount`=`threadcount`+1, `lastpost`='{$curtime}', `lastposter`='{$savename}', `lastthread`='{$post_title}', `lastthreadid`='{$vb_threadid}', `lasticonid`='1' WHERE `forumid`='{$vb_forumid}' LIMIT 1"; $vbresult = $wpdb->query($sql); $sql = "UPDATE $wpdb->posts SET `vb_threadid`={$vb_threadid} WHERE `ID`='{$post_ID}'"; $vbresult = $wpdb->query($sql); } // VB Bridge End If you are using the Kubrick default theme, open wp-content/themes/default/comments.php Replace contents with: Code:
<?php // Do not delete these lines if ('comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) die ('Please do not load this page directly. Thanks!'); if (!empty($post->post_password)) { // if there's a password if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie ?> <p class="nocomments">This post is password protected. Enter the password to view comments.<p> <?php return; } } /* This variable is for alternating comment background */ $oddcomment = 'alt'; ?> <!-- You can start editing here. --> <p class="postmetadata">Discuss: <?php comments_popup_link('No Comments ?', '1 Comment ?', '% Comments ?'); ?></p> If you are using the Kubrick default theme, open wp-content/themes/default/single.php Replace: Code:
You can <a href="#respond">leave a response</a>, or <a href="<?php trackback_url(true); ?>" rel="trackback">trackback</a> from your own site. Code:
You can <a href="/forum/showthread.php?t=<?php echo( $post->vb_threadid ); ?>&goto=newpost">leave a response</a>, or <a href="<?php trackback_url(true); ?>" rel="trackback">trackback</a> from your own site. If you are using the Kubrick default theme, open wp-content/themes/default/footer.php Replace: Code:
and <a href="feed:<?php bloginfo('comments_rss2_url'); ?>">Comments (RSS)</a>. Code:
<!-- and <a href="feed:<?php bloginfo('comments_rss2_url'); ?>">Comments (RSS)</a>.--> Lastly, open wp-rss2.php Replace: Code:
<wfw:commentRSS><?php echo comments_rss(); ?></wfw:commentRSS> Code:
<wfw:commentRSS>http://www.yoursite.com/forum/showthread.php?t=<?php echo $post->vb_threadid; ?></wfw:commentRSS> vBulletin Settings: The RSS feed will not work if you haven't activated RSS External synidcation on your forum. To do this, on your forums admincp, go to vBulletin Options->External Data Provider and check 'Yes' on Enable RSS Syncidcation. Final Words: Well, that?s about it! I?m not sure how often I can visit this thread but I hope those who find success in implementing the bridge, can help those who are having problems. Again, if you have suggestions on improving the script, let me know. Thanks and happy modding! Live Demo: http://www.internettablettalk.com/blog/ Revision History: v1.2 (12/7/2005): Uses correct vB user id and user name of the blog author. This will work only if the username of the Wordpress user is exactly the same as the vB username. If not, it uses $vb_userid and $vb_username defined in the settings. v1.1 (8/19/2005): Revisions are based on reports by Darth Gill (see discussion). New version includes vB RSS thread parser and a bug fix on vB not displaying recently added blog entry on the forum level. Current revisions are marked in green. Changes:
Screenshots: Show Your Support
|
Comments |
#132
|
||||
|
||||
I got a little impatient for an update, so I started hacking this myself into WordPress 2 / vB 3.5.
Everything except the comments RSS feed works so far. Any ideas? |
#133
|
|||
|
|||
hey scruffy will you share see your hack code? maybe the group can work out the RSS too
|
#134
|
||||
|
||||
Sure, check the attachment. I used Beyond Compare to find the differences between my hacked files and the originals, so if I missed anything, give me a shout.
|
#135
|
||||
|
||||
Quote:
I did exactly what you had in your instructions, but i end up with this error: Code:
WordPress database error: [Table 'gamerene_wp.user' doesn't exist] SELECT userid FROM user WHERE username = 'admin' WordPress database error: [Table 'gamerene_wp.thread' doesn't exist] INSERT INTO thread SET title='test',lastpost='1144575715', forumid='183', open='1', postusername='moethelawn', postuserid='1', lastposter='moethelawn', dateline='1144575715', visible='1' WordPress database error: [Table 'gamerene_wp.post' doesn't exist] INSERT INTO post SET threadid='8', username='moethelawn', userid='1', title='test', pagetext=' |
#136
|
||||
|
||||
I'm still a MySQL noob, but it looks like vB and WP are in different databases...?
|
#137
|
|||
|
|||
installed using your hack ^^^ and very impressed.
please keep us updated of any progress! |
#138
|
|||
|
|||
This works well for me VB 3.5.4 and WP 2.0.2. Some bugs:
The attached version fixes the first problem. It would be great to see the others fixed and the whole thing packaged into a proper WP plugin. |
#139
|
||||
|
||||
I would love to see this ported to plugins for 3.5.
|
#140
|
||||
|
||||
OK, I just did a bit more to this. I've tested a few different methods of creating blog entries, and these are known to work as expected (the entry's status options were set to 'Draft' unless otherwise stated):
Does not create thread (vb_threadid = NULL)Each of the above tests were done on a fresh entry, and just to confirm that no duplicate threads can be created by the same blog entry, I did a rather important check: Updates threadAlong the way, I removed some parts of the queries which made the first post jump to its chronological place in the thread whenever the blog entry is edited. I've totally ignored the 'Private' post status so far; I hope it doesn't need a whole new bunch of queries. |
#141
|
|||
|
|||
Is this an update, or were you just telling us your progress?
Cheers PS: Anyone notice funny characters come up in the VB forums when you post an image in the WP entry? e.g maxps3.com Thanks! Quote:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|