I received the code today for SMF commenter but its not working for me. I'm revising it, but this may take a few days, as I have some other projects to work on over the weekend.
James, I'm posting the code so you can take a look at it over the weekend as well.
wp_smf_commenter.php Code:
<?php
/*
Plugin Name: SMF Commenter
Plugin URI:
Description: When a new Wordpress post is published the post is duplicated in the forums and a link is added to the word press post.
Author: twistedsymphony
Version: .4
Author URI: http://web-nine.com/
*/
/* Copyright 2007 twistedsymphony (email : twistedsymphony@gmail.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2.1 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
I offer no warranties and no support for this plugin. Maybe it's mean but I
have better things to do. I wrote this plugin because there was no good solution
to integrating WP and SMF. I only offer this plugin because I know there are
many others interested in this integration which is the only reason I'm
releasing it at all. I made it for my own devices but if someone else can use
this as is without my help then great. I've tried to comment as much of this
as possible because if you ask me for help I probably wont have time to respond.
*/
/*******************************************************
INSTALLATION INSTRUCTIONS
1.
*******************************************************/
if (!defined('SMF'))
define('SMF', 1);
include_once('/homepages/13/d174540341/htdocs/nintendo/forums/Sources/Subs-Post.php');
//returns the SMF topic id from the postmeta table if an SMF ID has been set for the specified post
function get_smf_id($wp_id){
global $wpdb;
//check the post meta table for smf_id tags and return the value if one exists
@$smf_id = $wpdb->get_var("SELECT meta_value FROM $wpdb->postmeta WHERE post_id=$wp_id and meta_key='smf_id'");
//return the SMF topic id
return $smf_id;
}
//if SMF topic ID exists and is valid then add a link to the end of the WP post. else do nothing
function add_smf_link($content = '') {
Global $id; //get the WP id of the current post.
$wpsmfc = get_option('wpsmfc'); //get the user options
$smf_id = get_smf_id($id); //get the smf id
//check if the SMF ID was returned or invalid
If ((is_numeric($smf_id)) && ($smf_id != 0)){
//add the link text to the end of the content
$content .= "<p><a href=".$wpsmfc['wpsmfc_url']."/index.php?topic=".$smf_id.">".$wpsmfc['wpsmfc_wptxt']."</a></p>";
}
//return the content
return $content;
}
//checks if there is an SMF topic id associated with a published post, if not it creates a new topic and associates the ids
function create_smf_topic($id){
global $wpdb; //needed to use the WP database
$wpsmfc = get_option('wpsmfc'); //get the user options
$smf_id = get_smf_id($id); //get the SMF ID from the database
//checks if the id exists
If (is_null($smf_id)){
//generates the url (which includes necessary data) to the topic creation script
$url = get_option('home').'/wp-content/plugins/wp_smf_commenter/smf_create_topic.php?wp_id='.$id.'&smf_board='.$wpsmfc['wpsmfc_bid'].'&smf_user='.$wpsmfc['wpsmfc_mid'].'<xt='.$wpsmfc['wpsmfc_smtxt'];
//fires off the url... there are 4 ways to do this and none of them seem to work right.
//wp_redirect($url);
//header("Location: $url");
echo '<head><meta HTTP-EQUIV="REFRESH" content="0; url='.$url.'"></head>';
//header("Refresh: 0;url=$url");
//echo '<script type="text/javascript">window.open(\''.$url.'\')</script>';
//fopen ($url, "rb");
}
}
//this function filters the comment number on the news page to reflect the number of comments in SMF
function smf_comment_count(){
global $id, $wpdb;
$smf_id = get_smf_id($id); //get the smf id
if (is_null($smf_id)){//check that an SMF ID was returned
$smf_count = 0;
}else{
@$smf_count = $wpdb->get_var("SELECT COUNT(*) FROM smf_messages WHERE ID_TOPIC = $smf_id"); //get the post count from the SMF tables
$smf_count -=1; //subtract 1 to account for the first post created by WP.
}
return $smf_count;
}
//Calls the wp_smf_pollster_options.php page and adds it to the admin options when requested by the action below
function wpsmfc_add_options_page(){
add_options_page('SMF Commenter Options', 'SMF Commenter', 'manage_options', 'wp_smf_commenter/wp_smf_commenter_options.php');
}
//creats an SMF topic and relates the WP post id to the SMF topic id in a meta tag (if they do not already exist) whenever a post is published
add_action('publish_post', 'create_smf_topic');
// fires off the "add_smf_link" function whenever post content is dispalyed in Wordpress
add_filter('the_content', 'add_smf_link');
// sets the # of comments to the actual number of comments in the forum
add_filter('get_comments_number', 'smf_comment_count');
//calls the function to create the options page whenever it is requested.
add_action('admin_head', 'wpsmfc_add_options_page');
?> wp_smf_commenter_options.php Code:
<?php
/*
Author: twistedsymphony
Author URI: http://web-nine.com/
Description: Options for WP SMF Commenter
*/
//grabs the plugin data from the base plugin page for Commenter
load_plugin_textdomain('wpsmfc',$path = 'wp-content/plugins/wp_smf_commenter');
// Commenter's URI when viewed from the admin panel
$location = get_option('siteurl') . '/wp-admin/options-general.php?page=wp_smf_commenter/wp_smf_commenter_options.php';
//This creates the starting options if none exist
$wpsmfc_new=array(
"wpsmfc_mid" => 1,
"wpsmfc_bid" => 1,
"wpsmfc_wptxt" => "Discuss this topic in our forums.",
"wpsmfc_smtxt" => "View this topic on the news page.",
"wpsmfc_url" => $location.'/fourms'
);
add_option('wpsmfc', $wpsmfc_new);
//grabs the form sumbit data and updates the options
if ('process' == $_POST['stage']){
$wpsmfc=array(
"wpsmfc_mid" => $_POST['wpsmfc_mid'],
"wpsmfc_bid" => $_POST['wpsmfc_bid'],
"wpsmfc_wptxt" => $_POST['wpsmfc_wptxt'],
"wpsmfc_smtxt" => $_POST['wpsmfc_smtxt'],
"wpsmfc_url" => $_POST['wpsmfc_url']
);
update_option('wpsmfc', $wpsmfc);
}
//places the option in a useable variable for display back on the form
$wpsmfc = get_option('wpsmfc');
//the rest of this is the html form that makes up the Commenter options page... soo many options!
?><div class="wrap">
<h2><?php _e('SMF Commenter Options', 'wpsmfc') ?></h2>
<form name="form1" method="post" action="<?php echo $location ?>&updated=true">
<input type="hidden" name="stage" value="process" />
<p><input name="wpsmfc_mid" type="text" id="wpsmfc_mid" value="<?php echo $wpsmfc['wpsmfc_mid']; ?>" size="5" />
This is the Member ID of the SMF member you would like to appear as the one creating the WP posts in SMF (needs to be an admin for html support)</p>
<p><input name="wpsmfc_bid" type="text" id="wpsmfc_bid" value="<?php echo $wpsmfc['wpsmfc_bid']; ?>" size="5" />
This is the Board ID of the SMF board you would like the SMF topics to appear in.</p>
<p><input name="wpsmfc_wptxt" type="text" id="wpsmfc_wptxt" value="<?php echo $wpsmfc['wpsmfc_wptxt']; ?>" size="40" />
This is the text that will appear at the bottom of every WP post to link to SMF.</p>
<p><input name="wpsmfc_smtxt" type="text" id="wpsmfc_smtxt" value="<?php echo $wpsmfc['wpsmfc_smtxt']; ?>" size="40" />
This is the text that will appear at the bottom of every SMF topic to link back to WP.</p>
<p><input name="wpsmfc_url" type="text" id="wpsmfc_url" value="<?php echo $wpsmfc['wpsmfc_url']; ?>" size="40" />
This is the base URL of your SMF forum as it appears in the browser (exclude "/index.php" and everything after it).</p>
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Update Options', 'wpsmfc') ?> »" />
</p>
</form>
</div>