A A A

Please consider registering
guest

Log In Register

Register | Lost password?
Advanced Search:

— Forum Scope —



— Match —



— Forum Options —




Wildcard usage:
*  matches any number of characters    %  matches exactly one character

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
Linking blog comments and forum posts
May 15, 2009
3:47 pm
Craig
Guest

Hello everyone. Let me start by thanking the developers and everyone here for providing such a great plugin.

Out of the box simple:press is great but it was really lacking one feature, and that is integration between the blog comments and the forum.

I have been working for a week now trying to get this straitned out and I have a "useable" fix.

Please note that this isnt perfect by any means, it does has some issues, and it does need some testing so be sure to use it at your own risk. 

The problems:

  • Akismet. If akismet catches a spam comment that is not spam, when it is restored it will not be posted to the forum.
  • Link on blog post to the forum. You know, the one that says "Join the forum discussion on this post." For some reason it is displaying links to the wrong post, I am not sure why.
The code:
You will need to run this mysql query (be sure to change wp_ if you are not using wp_ as your table prefix)
ALTER TABLE `wp_sfposts` ADD `comment_blog_id` INT NOT NULL DEFAULT '0';

Replace the file sf-includes.php with this:

<?php
/*
Simple:Press Forum
Includes, Constants, Filters and Actions
$LastChangedDate: 2009-03-20 00:51:55 +0000 (Fri, 20 Mar 2009) $
$Rev: 1605 $
*/

if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
die('Access Denied');
}

# ——————————————————————
# Base Constants, Non-forum Filters & Actions
#
# Globally Required (Front/Back Ends)
# ——————————————————————

global $wpdb, $sfglobals;

# GLOBAL DEFINES ===============================================

# set up some global constants
define('SFPLUGNAME', 'Simple:Press Forum');
define('SFVERSION', '4.0.2');
define('SFBUILD', 1370);
define('SFRELEASE', '');

define('SFPLUGHOME', '<a href="http://simple-press.com">'.SFPLUGNAME.'</a>');
define('SFVERCHECK', 'http://simple-press.com/downloads/ForumVersion.chk');
define('SFHOMESITE', 'http://simple-press.com');

if(function_exists('site_url')) {
$SITEURL = trailingslashit(site_url());
} else {
$SITEURL = trailingslashit(get_option('siteurl'));
}
sf_load_locations($SITEURL);

include_once(SF_PLUGIN_DIR.'/sf-user-switches.php');

# setup some values needed for the defines
$SFSTYLE=array();
$SFSTYLE=get_option('sfstyle');
$SFICONPATH = $SFSTYLE['sficon'];
if(empty($SFICONPATH)) $SFICONPATH='default';

define('SFURL', trailingslashit(get_option('sfpermalink')));
define('SFQURL', sf_get_sfqurl(SFURL));

define('SFGROUPS', $wpdb->prefix.'sfgroups');
define('SFFORUMS', $wpdb->prefix.'sfforums');
define('SFTOPICS', $wpdb->prefix.'sftopics');
define('SFPOSTS', $wpdb->prefix.'sfposts');
define('SFMESSAGES', $wpdb->prefix.'sfmessages');
define('SFWAITING', $wpdb->prefix.'sfwaiting');
define('SFTRACK', $wpdb->prefix.'sftrack');
define('SFSETTINGS', $wpdb->prefix.'sfsettings');
define('SFNOTICE', $wpdb->prefix.'sfnotice');
define('SFUSERGROUPS', $wpdb->prefix.'sfusergroups');
define('SFPERMISSIONS', $wpdb->prefix.'sfpermissions');
define('SFDEFPERMISSIONS', $wpdb->prefix.'sfdefpermissions');
define('SFROLES', $wpdb->prefix.'sfroles');
define('SFMEMBERS', $wpdb->prefix.'sfmembers');
define('SFMEMBERSHIPS', $wpdb->prefix.'sfmemberships');
define('SFMETA', $wpdb->prefix.'sfmeta');
define('SFPOSTRATINGS', $wpdb->prefix.'sfpostratings');

if (defined('CUSTOM_USER_TABLE')) {
define('SFUSERS', CUSTOM_USER_TABLE);
} else {
define('SFUSERS', $wpdb->users);
}
if (defined('CUSTOM_USER_META_TABLE')) {
define('SFUSERMETA', CUSTOM_USER_META_TABLE);
} else {
define('SFUSERMETA', $wpdb->usermeta);
}

define('SFADMINURL', SF_PLUGIN_URL . '/admin/');
define('SFRESOURCES', SF_PLUGIN_URL . '/styles/icons/'.$SFICONPATH.'/');
define('SFCUSTOM', SF_PLUGIN_DIR . '/styles/icons/'.$SFICONPATH.'/custom/');
define('SFJSCRIPT', SF_PLUGIN_URL . '/jscript/');

define('SFSMILEYS', WP_CONTENT_URL . '/forum-smileys/');
define('SFAVATARURL', WP_CONTENT_URL . '/forum-avatars/');

define('SFDATES', get_option('sfdates'));
define('SFTIMES', get_option('sftimes'));

define('SFLOGIN', $SITEURL.'wp-login.php?action=login&amp;view=forum');
define('SFLOGINEMAIL', $SITEURL.'wp-login.php?action=login&view=forum');
define('SFLOGOUT', $SITEURL.'wp-login.php?action=logout&amp;redirect_to='.SFURL);
define('SFREGISTER', $SITEURL.'wp-login.php?action=register&amp;view=forum');
define('SFLOSTPASS', $SITEURL.'wp-login.php?action=lostpassword&amp;view=forum');
define('SFRESETPASS', $SITEURL.'wp-login.php?action=resetpass&amp;view=forum');

define('SFPROFILE', sf_get_sfurl_plus_amp(SFURL).'profile=user');
define('SFMEMBERLIST', sf_get_sfurl_plus_amp(SFURL).'list=members');
define('SFPOLICY', sf_get_sfurl_plus_amp(SFURL).'policy=reg');

# editor defs
define('RICHTEXT', 1);
define('HTML', 2);
define('BBCODE', 3);
define('PLAIN', 4);

# hack to get around wp_list_pages() bug
$wpdb->hide_errors();
$t = $wpdb->get_var("SELECT post_title FROM ".$wpdb->prefix."posts WHERE ID=".get_option('sfpage'));
define('SFPAGETITLE', $t);
$wpdb->show_errors();

# GLOBAL ACTIONS/FILTERS =======================================

# localisation and javascript
add_action('init', 'sf_localisation');

# Rewrite Rules
add_filter('page_rewrite_rules', 'sf_set_rewrite_rules');

add_filter('query_vars', 'sf_set_query_vars');

# linked blog/topic posts
add_filter('the_content', 'sf_blog_show_link');
add_action('save_post', 'sf_save_blog_link');
add_action('publish_post', 'sf_publish_blog_link');
add_action('publish_page', 'sf_publish_blog_link');
add_action('delete_post', 'sf_blog_link_delete');
add_action('comment_post', 'sf_save_comment_forum',5,1);
add_action('edit_comment', 'sf_save_comment_forum',10,1);

if(get_option('sflinkcomments'))
{
add_filter('comments_array', 'sf_topic_as_comments');
}
if (sf_get_system_status() == 'ok')
{
add_action('admin_init', 'sf_blog_link_form');
}

# RSS feeds
add_action('template_redirect', 'sf_feed');
# 404
add_action('template_redirect', 'sfg_404');

# user registrations
if (function_exists('wpmu_create_user'))
{
add_action('wpmu_new_user', 'sf_create_member_data');
} else {
add_action('user_register', 'sf_create_member_data');
}
add_action('delete_user', 'sf_delete_member_data');
add_action('wp_logout', 'sf_call_track_logout');
add_action('register_form', 'sf_register_math', 1);
add_filter('registration_errors', 'sf_register_error');

# Email
$sfmail=array();
$sfmail = get_option('sfmail');
if($sfmail['sfmailuse'])
{
add_filter('wp_mail_from', 'sf_mail_filter_from', 100);
add_filter('wp_mail_from_name', 'sf_mail_filter_name', 100);
}

# Login/registration: has to be at root level
include_once('credentials/sf-credentials.php');

# Credential Actions/Filters
if (sf_get_system_status() != 'Install')
{
add_action('login_head', 'sf_login_header');
add_filter('login_headerurl', 'sf_login_url');
add_filter('login_headertitle', 'sf_login_title');
add_action('login_form', 'sf_login_form_action');
add_action('register_form', 'sf_login_form_action', 100);
add_action('lostpassword_form', 'sf_login_form_action');
add_action('register_form', 'sf_register_as_forum');
add_action('lostpassword_form', 'sf_register_as_forum');
add_action('wp_login', 'sf_post_login_check');

# Dashboard notifications
add_action('activity_box_end', 'sf_announce', 1);
}

# browser title
add_filter('wp_title', 'sf_setup_browser_title');

# Deactivating and Removal
add_action('deactivate_simple-forum/sf-control.php', 'sf_remove_data');

# ——————————————————————
# sf_load_foundation()
#
# Forum specific Constants, Filters, Actions and Includes
# Required by forum
# ——————————————————————
function sf_load_foundation()
{
global $sfglobals, $current_user;

# setup some values needed for the defines
if(function_exists('site_url')) {
$SITEURL = trailingslashit(site_url());
} else {
$SITEURL = trailingslashit(get_option('siteurl'));
}

sf_load_locations($SITEURL);

$SFSTYLE=array();
$SFSTYLE=get_option('sfstyle');
$SFCSSPATH = $SFSTYLE['sfskin'];
if(empty($SFCSSPATH)) $SFCSSPATH='default';

define('SFSKINCSS', SF_PLUGIN_URL . '/styles/skins/'.$SFCSSPATH.'/'.$SFCSSPATH.'.css');
define('SFEDITORDIR', SF_PLUGIN_DIR . '/editors/');
define('SFEDITORURL', SF_PLUGIN_URL . '/editors/');
define('SFEDSTYLE', SF_PLUGIN_URL . '/styles/editors/');
define('SFSIZE', $SFSTYLE['sfsize']);

include_once('forum/sf-globals.php');
include_once('forum/sf-primitives.php');
include_once('forum/sf-database.php');
include_once('forum/sf-support.php');
include_once('forum/sf-permalinks.php');
include_once('forum/sf-permissions.php');
if(file_exists(SF_PLUGIN_DIR.'/forum/sf-pluggable.php'))
{
include_once('forum/sf-pluggable.php');
}
include_once('forum/sf-pagecomponents.php');
include_once('forum/sf-page.php');
include_once('forum/sf-forms.php');
include_once('forum/sf-filters.php');
include_once('forum/sf-links.php');
if(file_exists(SF_PLUGIN_DIR.'/forum/hooks/sf-hook-template.php'))
{
include_once('forum/hooks/sf-hook-template.php');
}
include_once('messaging/sf-pmcomponents.php');
include_once('messaging/sf-pmdatabase.php');
include_once('messaging/sf-pmcontrol.php');

# define $sfglobals now…(and not in the globals file)
# needed to load correct editor at startup
$sfglobals = array();
$editor=array();
$editor=get_option('sfeditor');
if(empty($editor['sflang'])) $editor['sflang']='en';
$sfglobals['editor'] = $editor;
if($editor['sfusereditor'] && $current_user->ID)
{
$sfglobals['editor']['sfeditor'] = sf_get_member_item($current_user->ID, 'editor');
}

# WP Page Title
add_filter('the_title', 'sf_setup_page_title');

# Content Filters (Save and Display)
add_filter('sf_save_post_content', 'sf_parse_bbcode', 1);
add_filter('sf_save_post_content', 'balanceTags', 30);
add_filter('sf_save_post_content', 'sf_filter_nbsp');
add_filter('sf_save_post_content', 'sf_convert_code', 100);
add_filter('sf_save_post_content', 'sf_profanity_check');
add_filter('sf_save_post_content', 'sf_qt_filter', 1);
add_filter('sf_save_post_content', 'sf_package_links', 2);

$sffilters = array();
$sffilters = get_option('sffilters');
if($sffilters['sfnofollow'])
{
add_filter('sf_save_post_content', 'sf_rel_nofollow');
}
if($sffilters['sftarget'])
{
add_filter('sf_save_post_content', 'sf_target_blank');
}

if((get_option('sfdemocracy')) && (function_exists('jal_insert_poll')))
{
add_filter('sf_show_post_content', 'jal_insert_poll', 110);
add_filter('sf_save_post_content', 'jal_add_dem_div');
}
if(get_option('sfimgenlarge'))
{
add_filter('sf_show_post_content', 'sf_show_image_thumbnail', 100);
}
add_filter('sf_save_topic_title', 'balanceTags', 30);
add_filter('sf_save_topic_title', 'sf_filter_nohtml_kses');
add_filter('sf_save_topic_title', 'sf_filter_square_brackets');
add_filter('sf_save_topic_title', 'sf_profanity_check');
add_filter('sf_save_post_name', 'strip_tags');
add_filter('sf_save_post_name', 'trim');
add_filter('sf_save_post_name', 'wp_specialchars', 30);
add_filter('sf_save_post_name', 'wp_filter_kses');
add_filter('sf_save_post_email', 'trim');
add_filter('sf_save_post_email', 'sanitize_email');
add_filter('sf_save_post_email', 'wp_filter_kses');
add_filter('sf_show_post_content', 'convert_chars');
add_filter('sf_show_post_content', 'make_clickable');
add_filter('sf_show_post_content', 'wpautop', 30);
add_filter('sf_show_post_content', 'sf_filter_nbsp',31);
add_filter('sf_show_post_name', 'wptexturize');
add_filter('sf_show_post_name', 'convert_chars');
add_filter('sf_show_post_name', 'wp_specialchars');
add_filter('sf_show_topic_title', 'sf_filter_square_brackets');

return;
}

# ——————————————————————
# sf_load_includes()
#
# Includes to satisfy Template Tags
# ——————————————————————
function sf_load_includes()
{
include_once('forum/sf-globals.php');
include_once('forum/sf-primitives.php');
include_once('forum/sf-database.php');
include_once('forum/sf-support.php');
include_once('forum/sf-permalinks.php');
include_once('forum/sf-permissions.php');
if(file_exists(SF_PLUGIN_DIR.'/forum/sf-pluggable.php'))
{
include_once('forum/sf-pluggable.php');
}
include_once('forum/sf-topiccomponents.php');
include_once('forum/sf-filters.php');
include_once('forum/sf-newuserview.php');
include_once('forum/sf-forumcomponents.php');
include_once('forum/sf-pagecomponents.php');

return;
}

# ——————————————————————
# sf_load_locations()
#
# Use new WP 2.6 wp-content and wp-plugin defines or create them
# if not using 2.6
# ——————————————————————

function sf_load_locations($SITEURL)
{
# check if already defined
if(defined('SF_PLUGIN_DIR')) return;

if (!defined('WP_CONTENT_DIR')) define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
if (!defined('WP_CONTENT_URL')) define('WP_CONTENT_URL', $SITEURL . 'wp-content');

if (defined('WP_PLUGIN_DIR'))
{
define('SF_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__)));
} else {
define('SF_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins/' . basename(dirname(__FILE__)));
}

if (defined('WP_PLUGIN_URL'))
{
define('SF_PLUGIN_URL', WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)));
} else {
define('SF_PLUGIN_URL', WP_CONTENT_URL . '/plugins/' . basename(dirname(__FILE__)));
}

return;
}

?>

And replace sf-public.php with this:

<?php
/*
Simple:Press Forum
Public Functions to support Actions/filters
$LastChangedDate: 2009-01-24 15:49:29 +0000 (Sat, 24 Jan 2009) $
$Rev: 1293 $
*/

if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
die('Access Denied');
}

// Comments to forum
function sf_save_comment_forum($comment_id){
global $wpdb;
include_once(SF_PLUGIN_DIR.'/sf-slugs.php');
require_once('forum/sf-links.php');
# first – get the comment content
$comment = get_comment($comment_id);
$slug = sf_create_slug($comment->comment_content, 'topic');
if ( empty($comment) )
return;
if($comment->comment_approved == '1')
{
#second – select forum_id from topic of forums
$topic = $wpdb->get_row("SELECT forum_id, topic_id FROM ".SFTOPICS." WHERE blog_post_id = ".$comment->comment_post_ID.";");
if($topic->forum_id == NULL || $topic->forum_id == '')
return;

$fpost = $wpdb->get_row("SELECT post_id FROM ".SFPOSTS." WHERE comment_blog_id= ".$comment_id.";");
if($fpost->post_id != '')
{
$wpdb->query("UPDATE ".SFPOSTS." SET post_content='".$comment->comment_content."' WHERE post_id=".$fpost->post_id);
}else{

# and insert into post of forum
$sql = "INSERT INTO ".SFPOSTS." (post_content, post_date, topic_id, user_id, forum_id, comment_blog_id) VALUES ('".$comment->comment_content."', now(), ".$topic->topic_id.", ".$comment->user_id.", ".$topic->forum_id.", ".$comment_id.");";
$wpdb->query($sql);

# and then update postmeta with forum AND topic
$text = $topic->forum_id."@".$topic->topic_id;
sf_blog_links_postmeta('save', mysql_insert_id(), $text);

# Update authors forum post count
$postcount = (sf_get_member_item($comment->user_id, 'posts')+1);
sf_update_member_item($comment->user_id, 'posts', $postcount);

# Update forum, topic and post index data
sf_build_forum_index($topic->forum_id);
sf_build_post_index($topic->topic_id, $slug);
}
}
}


# ——————————————————————
# sf_track_logout()
#
# Filter Call
# Sets up the last visited upon user logout
# ——————————————————————
function sf_call_track_logout()
{
sf_load_foundation();
sf_track_logout();
return;
}

# ——————————————————————
# sf_register_math()
#
# Filter Call
# Sets up the spam math on registration form
# ——————————————————————
function sf_register_math()
{
$sflogin = array();
$sflogin = get_option('sflogin');
if($sflogin['sfregmath'])
{
include_once('forum/sf-primitives.php');

$spammath = sf_math_spam_build();

$out ='<input type="hidden" size="30" name="url" value="" /></p>'."\\n";
$out.='<p><strong>'.__("Math Required!", "sforum").'</strong><br />'."\\n";
$out.=sprintf(__("What is the sum of: <strong> %s + %s </strong>", "sforum"), $spammath[0], $spammath[1]).'&nbsp;&nbsp;&nbsp;'."\\n";
$out.='<input type="text" tabindex="3" size="7" id="sfvalue1" name="sfvalue1" value="" /></p>'."\\n";
$out.='<input type="hidden" name="sfvalue2" value="'.$spammath[2].'" />'."\\n";
echo $out;
}
return;
}

# ——————————————————————
# sf_register_error()
#
# Filter Call
# Sets up the spam math error is required
# $errors: registration errors array
# ——————————————————————
function sf_register_error($errors)
{
global $ISFORUM;

$sflogin = array();
$sflogin = get_option('sflogin');

if($sflogin['sfregmath'])
{
include_once('forum/sf-primitives.php');

$spamtest=sf_spamcheck();
if($spamtest[0] == true)
{
$errormsg = str_replace('1@', '<b>ERROR</b>: ', $spamtest[1]);

if($ISFORUM == false)
{
$errors->add('Bad Math', $errormsg);
} else {
$errors['math_check'] = $errormsg;
}
}
}
return $errors;
}

# ——————————————————————
# sf_setup_browser_title()
#
# Filter call
# Sets up the browser page title if All In One SEO Pack installed
# $title page title
# ——————————————————————
function sf_setup_browser_title($title)
{
# check if alll in one seo pack is installed
if((class_exists('Platinum_SEO_Pack') || ('All_in_One_SEO_Pack')) && trim($title) == trim(SFPAGETITLE))
{
require_once('forum/sf-filters.php');
require_once('forum/sf-database.php');

$sfaiosp = get_option('sfaiosp');

if ($sfaiosp['sfaiosp_topic'])
{
$topicslug = get_query_var('sf_topic');
if ($topicslug) $topictitle = sf_get_topic_name($topicslug);
}

if ($sfaiosp['sfaiosp_forum'])
{
$forumslug = get_query_var('sf_forum');
if ($forumslug && $forumslug != 'all') $forumtitle = sf_get_forum_name($forumslug);
}

$spftitle = '';
$sep = $sfaiosp['sfaiosp_sep'];
if ($topictitle) $spftitle .= $topictitle.' '.$sfaiosp['sfaiosp_sep'].' ';
if ($forumtitle) $spftitle .= $forumtitle.' '.$sfaiosp['sfaiosp_sep'].' ';
$title = $spftitle.$title;
}

return $title;
}

# ——————————————————————
# sf_blog_link_form()
#
# Filter call
# Sets up the forum post linking form in the Post Write screen
# This version for WP systems 2.5 and above
# ——————————————————————
function sf_blog_link_form()
{
global $current_user;

if(function_exists('add_meta_box'))
{
sf_initialise_globals();

# can the user do this?
if (!$current_user->sflinkuse) return;

add_meta_box('sfforumlink', __("Link To Forum", "sforum"), 'sf_populate_post_form', 'post', 'advanced');
add_meta_box('sfforumlink', __("Link To Forum", "sforum"), 'sf_populate_post_form', 'page', 'advanced');
}
return;
}

# ——————————————————————
# sf_populate_post_form()
#
# Callback routine for post linking form on WP2.5 and above
# ——————————————————————
function sf_populate_post_form()
{
global $post;

$forumid = 0;
$text = '';

if(isset($post->ID))
{
require_once('forum/sf-links.php');

$islink = sf_blog_links_postmeta('read', $post->ID, '');
if($islink)
{
$islink=explode('@', $islink->meta_value);
$forumid = $islink[0];
$text = 'checked="checked"';
}
}
# WP 2.5+ Post Page
?>
<label for="sflink" class="selectit">
<input type="checkbox" <?php echo($text); ?> name="sflink" id="sflink" />
<?php _e("Create Forum Topic", "sforum"); ?></label><br /><br />
<label for="sfforum" class="selectit"><?php _e("Select Forum:", "sforum"); ?><br />
<?php
echo(sf_blog_links_list($forumid)).'</label>';
return;
}

# ——————————————————————
# sf_save_blog_link()
#
# Filter call
# Called on a Post Save to create the blog/forum Link
# $postid id of the blog post to link to
# ——————————————————————
function sf_save_blog_link($postid)
{
if(isset($_POST['sflink']))
{
require_once('forum/sf-links.php');

# sadly need to check if both items already set (forum @ topic)
$checkrow = sf_blog_links_postmeta('read', $postid, '');
if(($checkrow) && (strpos($checkrow->meta_value, '@')))
{
# already cooked
return;
} else {
$text = $_POST['sfforum'];
sf_blog_links_postmeta('save', $postid, $text);
}
}
return;
}

# ——————————————————————
# sf_publish_blog_link()
#
# Filter call
# Called on a Post Publish to create the blog/forum Link
# $postid id of the blog post to link to
# ——————————————————————
function sf_publish_blog_link($postid)
{
global $wpdb;

include_once(SF_PLUGIN_DIR.'/sf-slugs.php');

if(isset($_POST['sflink']))
{
require_once('forum/sf-links.php');

# sadly need to check if both items already set (forum @ topic)
$checkrow = sf_blog_links_postmeta('read', $postid, '');
if(($checkrow) && (strpos($checkrow->meta_value, '@')))
{
# already cooked
return;
} else {
# first – get the post content
$content = $wpdb->get_row("SELECT post_content, post_title, post_author, post_status FROM ".$wpdb->prefix."posts WHERE ID = ".$postid.";");
$post_title = apply_filters('sf_save_topic_title', $content->post_title);
$post_title = $wpdb->escape($post_title);
$slug = sf_create_slug($post_title, 'topic');

# now create the topic and post records – it should already be escaped fully.
$sql = "INSERT INTO ".SFTOPICS." (topic_name, topic_slug, topic_date, forum_id, user_id, post_count, blog_post_id, post_id) VALUES ('".$post_title."', '".$slug."', now(), ".$_POST['sfforum'].", ".$content->post_author.", 1, ".$postid.", ".$postid.");";
$wpdb->query($sql);

$topicid = $wpdb->insert_id;

# check the topic slug and if empty use the topic id
if(empty($slug))
{
$slug = 'topic-'.$topicid;
$thistopic = $wpdb->query("
UPDATE ".SFTOPICS."
SET topic_slug='".$slug."', topic_name='".$slug."'
WHERE topic_id=".$topicid);
}

# Full content or excerpt?
$postcontent = sf_make_excerpt($postid, $content->post_content);
$postcontent = $wpdb->escape($postcontent);

$sql = "INSERT INTO ".SFPOSTS." (post_content, post_date, topic_id, user_id, forum_id) VALUES ('".$postcontent."', now(), ".$topicid.", ".$content->post_author.", ".$_POST['sfforum'].");";
$wpdb->query($sql);

# and then update postmeta with forum AND topic
$text = $_POST['sfforum']."@".$topicid;
sf_blog_links_postmeta('save', $postid, $text);

# Update authors forum post count
$postcount = (sf_get_member_item($content->post_author, 'posts')+1);
sf_update_member_item($content->post_author, 'posts', $postcount);

# Update forum, topic and post index data
sf_build_forum_index($_POST['sfforum']);
sf_build_post_index($topicid, $slug);
}
}
return;
}

# ——————————————————————
# sf_blog_show_link()
#
# Filter call
# Adds the user-defined link text to a blog post
# $content The content of the target post
# ——————————————————————
function sf_blog_show_link($content)
{
global $wp_query;

require_once('forum/sf-links.php');
require_once('forum/sf-database.php');
require_once('forum/sf-permalinks.php');

$postid = $wp_query->post->ID;
$out = '';
$checkrow = sf_blog_links_postmeta('read', $postid, '');

if($checkrow)
{
# link found for this post
$keys = explode('@', $checkrow->meta_value);

$text = stripslashes(get_option('sflinkblogtext'));
$icon = '<img src="'.SFRESOURCES.'bloglink.png" alt="" />';
$text = str_replace('%ICON%', $icon, $text);

$postcount = sf_get_posts_count_in_topic($keys[1]);
if(!$postcount)
{
# break the link
sf_blog_links_postmeta('delete', $postid, '');
return $content;
}
$counttext = ' – ('.$postcount.') '.__("Posts", "sforum");

$out = '<span class="sfforumlink"><a href="'.sf_build_url(sf_get_forum_slug($keys[0]), sf_get_topic_slug($keys[1]), 1, 0).'">'.$text.'</a>'.$counttext.'</span>';

if(get_option('sflinkabove'))
{
return $out.$content;
} else {
return $content.$out;
}
} else {
return $content;
}
}

# ——————————————————————
# sf_blog_link_delete()
#
# Action call
# Removes forum link if blog post is deleted
# $postid ID of the post being deleted
# ——————————————————————
function sf_blog_link_delete($postid)
{
require_once('forum/sf-links.php');

$islink = sf_blog_links_postmeta('read', $postid, '');
if($islink)
{
$keys = explode('@', $islink->meta_value);
sf_break_post_link($keys[1], $postid);
}
return;
}

# ——————————————————————
# sf_blog_links_list()
#
# Support Routine
# Lists forums for the post write link box
# $forumid ID of the forum if already linked (Edit mode)
# ——————————————————————
function sf_blog_links_list($forumid)
{
$groups = sf_get_combined_groups_and_forums_bloglink();
if($groups)
{
$out = '';
$out.= '<select id="sfforum" name="sfforum">'."\\n";

foreach($groups as $group)
{
$out.= '<optgroup label="'.$group['group_name'].'">'."\\n";
if($group['forums'])
{
foreach($group['forums'] as $forum)
{
if($forumid == $forum['forum_id'])
{
$text = 'selected="selected" ';
} else {
$text = '';
}
$out.='<option '.$text.'value="'.$forum['forum_id'].'">&nbsp;&nbsp;&nbsp;&nbsp;'.stripslashes($forum['forum_name']).'</option>'."\\n";
}
}
$out.='</optgroup>';
}
$out.='</select>'."\\n";
}
return $out;
}

# ——————————————————————
# sf_topic_as_comments()
#
# NOT DIRECTLY CALLABLE
# Adds the topic posts to the comments stream
# $comments Passed in by the comments_array filter
# ——————————————————————
function sf_topic_as_comments($comments)
{
global $wp_query;

sf_load_includes();
sf_initialise_globals();

if($comments)
{
$postid = $comments[0]->comment_post_ID;
} else {
$postid = $wp_query->post->ID;
}
$link = sf_blog_links_postmeta('read', $postid, '');
if(!$link) return $comments;

$link = explode('@', $link->meta_value);

# quick permission check
if(!sf_can_view_forum($link[0])) return $comments;

$topicid = $link[1];
$thread = sf_get_thread_for_comments($topicid);
if($thread)
{
$index = count($comments);
foreach($thread as $post)
{
$comments[$index]->comment_ID = 0;
$comments[$index]->comment_post_ID = $postid;

if($post['user_id'] == "")
{
$comments[$index]->comment_author = stripslashes($post['guest_name']);
$comments[$index]->comment_author_email = stripslashes($post['guest_email']);
$comments[$index]->comment_author_url = "";
} else {
$comments[$index]->comment_author = stripslashes($post['display_name']);
$comments[$index]->comment_author_email = stripslashes($post['user_email']);
$comments[$index]->comment_author_url = sf_check_url($post['user_url']);
}
$comments[$index]->comment_author_IP = "";
$comments[$index]->comment_date = $post['post_date'];
$comments[$index]->comment_date_gmt = $post['post_date'];
$comments[$index]->comment_content = sf_filter_content(stripslashes($post['post_content']), "");
$comments[$index]->comment_karma = 0;
$comments[$index]->comment_approved = 1;
$comments[$index]->comment_agent = "";
$comments[$index]->comment_type = "";
$comments[$index]->comment_parent = 0;
$comments[$index]->user_id = $post['user_id'];
$comments[$index]->comment_subscribe = "N";
$comments[$index]->comment_reply_ID = 0;

$index++;
}
}
return $comments;
}

function sf_get_thread_for_comments($topicid)
{
global $wpdb;

$records = $wpdb->get_results(
"SELECT ".SFPOSTS.".post_id, post_content, ".sf_zone_datetime('post_date').", ".SFPOSTS.".user_id, guest_name, guest_email, post_status,
".SFMEMBERS.".display_name, user_url, user_email
FROM ".SFPOSTS."
LEFT JOIN ".SFUSERS." ON ".SFPOSTS.".user_id = ".SFUSERS.".ID
LEFT JOIN ".SFMEMBERS." ON ".SFPOSTS.".user_id = ".SFMEMBERS.".user_id
WHERE topic_id = ".$topicid." AND post_status = 0 AND post_index > 1
ORDER BY post_id DESC", ARRAY_A);

return $records;
}

?>

If anyone can help me improve upon this code I would love to hear your suggestions.

I know my methods may not be the best but hopefully it will be enough to build upon.

Feb 8, 2010
5:55 am
Demon
Guest

made a forum thread for this question

Forum Timezone: America/Chicago

Most Users Ever Online: 444

Currently Online: Yellow Swordfish
73 Guest(s)

Currently Browsing this Page:
1 Guest(s)

See All Online Activity

Top Posters:

-Radio-: 1251

Lee H: 606

Luffer: 535

Conrad_Farlow: 502

jim: 478

neon: 263

ovizii: 240

Tal: 240

Member Stats:

Guest Posters: 2625

Members: 7361

Moderators: 1

Admins: 2

Forum Stats:

Groups: 5

Forums: 16

Topics: 10890

Posts: 79531

Moderators: Brandon C (162)

Administrators: Yellow Swordfish (22211), Mr Papa (23688)