ok, here is the code to use the build_new_post function in vB to insert the data. this will make the post number increase automatically, make the posts searchable, make similar threads work. however, there is one tiny problem.
- the posts have \n\n in them, when they should be actual new lines. anyone know how to fix this?
other than that, it works just fine. i just need to figure this last thing out.
original authors code commented out:
PHP Code:
<?php
require('./global.php');
require('./includes/functions_newpost.php');
// RSS News Feed Hack
// ------------------------------
// By: Andrew Wickham of
// LiquidPro Inc.
//
// get the rss settings
$query = $DB_site->query("SELECT * FROM " . TABLE_PREFIX . "rss_settings");
$data = $DB_site->fetch_array($query);
$rss_enabled = $data[enabled];
if($rss_enabled == 1) {
// include the RSS class
require_once('class.RSS.php');
$query = $DB_site->query("SELECT * FROM " . TABLE_PREFIX . "rss_user WHERE enabled = '1'");
while($data = $DB_site->fetch_array($query)) {
$rss_source = $data[source];
$rss_forumid = $data[forumid];
$rss_userid = $data[userid];
$foruminfo = fetch_foruminfo($rss_forumid);
$bbuserinfo = fetch_userinfo($rss_userid);
//$query2 = $DB_site->query("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = '$rss_userid'");
//$data2 = $DB_site->fetch_array($query2);
//$rss_user_data[username] = $data2[username];
//$rss_user_data[posts] = $data2[posts];
// get the bot`s username
//$rss_user_query = $DB_site->query("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = '$rss_userid'");
//$rss_user_data = $DB_site->fetch_array($rss_user_query);
//$rss_username = $rss_user_data[username];
//$rss_posts = $rss_user_data[posts];
$rss_data = implode("",file($rss_source));
$rss = new RSS($rss_data, 1);
$rss_allItems = $rss->getAllItems();
// check and see what items are in the database, and mark the old ones as old
$rss_query = $DB_site->query("SELECT * FROM " . TABLE_PREFIX . "thread WHERE rss_feed = '1' AND postuserid = '$rss_userid'");
for($i = count($rss_allItems) - 1; $i >= 0; $i--) {
$rss_allItems[$i][OLD] = false;
}
// if there's no items in the database
if($DB_site->num_rows($rss_query) == 0) {
for($i = count($rss_allItems) - 1; $i >= 0; $i--) {
$rss_allItems[$i][OLD] = false;
}
}
// filter out the old items
while($rss_thread_data = $DB_site->fetch_array($rss_query)) {
for($j = count($rss_allItems) - 1; $j >= 0; $j--) {
if($rss_thread_data[title] == $rss_allItems[$j][TITLE] &&
$rss_thread_data[rss_date] == $rss_allItems[$j][pubDate]) {
$rss_allItems[$j][OLD] = true;
}
}
}
// insert the new items into the database
for($j = count($rss_allItems) - 1; $j >= 0; $j--) {
if(!$rss_allItems[$j][OLD]) {
// update the user profile
//$rss_posts++;
$rss_title = $rss_allItems[$j][TITLE];
$rss_dateline = $rss_allItems[$j]['pubDate'];
$current_dateline = time();
$rss_description = $rss_allItems[$j][DESCRIPTION];
$rss_description .= "\r\n\r\n[url=" . $rss_allItems[$j][LINK] . "]View the Entire Article[/url]\r\n";
// change <br> tags to newline
$rss_description = str_replace("<br>", \n, $rss_description);
$rss_description = str_replace("<br />", \n, $rss_description);
$rss_title = html_entity_decode($rss_title, ENT_NOQUOTES);
$rss_description = html_entity_decode($rss_description, ENT_NOQUOTES);
/*
//$rss_title = str_replace("'", "\'", $rss_title);
//$rss_description = str_replace("'", "\'", $rss_description);
//$rss_title = str_replace("?", "--", $rss_title);
//$rss_description = str_replace("?", "--", $rss_description);
//$rss_title = str_replace("$", "\$", $rss_title);
//$rss_description = str_replace("$", "\$", $rss_description);
//sql and php don't recognize the html escape strings.
*/
$rss_description=mysql_escape_string($rss_description);
$rss_title=mysql_escape_string($rss_title);
// get the next available threadid
//$rss_threadid_query = $DB_site->query("SELECT * FROM " . TABLE_PREFIX . "thread ORDER BY threadid DESC");
//$rss_threadid_data = $DB_site->fetch_array($rss_threadid_query);
//$rss_threadid = $rss_threadid_data[threadid] + 1;
// get the next available postid
//$rss_postid_query = $DB_site->query("SELECT * FROM " . TABLE_PREFIX . "post ORDER By postid DESC");
//$rss_postid_data = $DB_site->fetch_array($rss_postid_query);
//$rss_postid = $rss_postid_data[postid] + 1;
//$DB_site->query("INSERT INTO " . TABLE_PREFIX . "post (`threadid`, `username`, `userid`, `title`, `dateline`, `pagetext`, `allowsmilie`, `showsignature`, `visible`) VALUES ('$rss_threadid', '$rss_username', '$rss_userid', '$rss_title', '$current_dateline', '$rss_description', '1', '1', '1')");
//$DB_site->query("INSERT INTO " . TABLE_PREFIX . "thread (`title`, `forumid`, `firstpostid`, `lastpost`, `open`, `postusername`, `postuserid`, `lastposter`, `dateline`, `visible`, `rss_feed`, `rss_date`) VALUES ('$rss_title', '$rss_forumid', '$rss_postid', '$current_dateline', '1', '$rss_username', '$rss_userid', '$rss_username', '$current_dateline', '1', '1', '$rss_dateline')");
//$DB_site->query("UPDATE " . TABLE_PREFIX . "forum SET lastpost = '$current_dateline', lastposter = '$rss_username', lastthread = '$rss_title', lastthreadid = '$rss_threadid' WHERE forumid = '$rss_forumid'");
// Setup the thread
$post['signature'] = true;
$post[title] = $rss_title;
$post[message] = $rss_description;
$post[poststarttime] = TIMENOW;
$post[posthash] = md5($post[poststarttime] . $bbuserinfo['userid'] . $bbuserinfo['salt']);
// build the thread
build_new_post('thread', $foruminfo, array(), 0, $post, $errors, $rss_userid);
}
}
// update the posts in the database
//$DB_site->query("UPDATE " . TABLE_PREFIX . "user SET posts = '$rss_posts' WHERE userid = '$rss_userid'");
}
}
//
// ------------------------------
// End of RSS News Hack
?>
and in functions_newpost.php i added a variable into the function and wrapped the global statement around an IF/ELSE:
PHP Code:
// ###################### Start newpost #######################
function build_new_post($type = 'thread', $foruminfo, $threadinfo, $parentid, &$post, &$errors, $rss_userid = '0')
{
//NOTE: permissions are not checked in this function
// $post is passed by reference, so that any changes (wordwrap, censor, etc) here are reflected on the copy outside the function
// $post[] includes:
// title, iconid, message, parseurl, email, signature, preview, disablesmilies, rating
// $errors will become any error messages that come from the checks before preview kicks in
if ($rss_userid == '0')
{
global $DB_site, $vboptions, $vbphrase, $bbuserinfo, $forumperms, $usergroupcache, $_REQUEST;
}
else
{
global $DB_site, $vboptions, $vbphrase, $bbuserinfo, $forumperms, $usergroupcache, $_REQUEST;
$bbuserinfo = fetch_userinfo($rss_userid);
}
|