dcncdrew
09-19-2005, 10:00 PM
This is something I want to implement on my site. It pulls all first posts from a specific forum you specify in descending order by post date. The only issue is that it does not take into account permissions at this point. This is a work in progress. I just wanted something simple but it's looking like it might be more trouble to do so. I had issues with VB's RSS so this is why I started this. I put it together using a few know scripts out there.
The below template.html and include.php file need to be in a folder called "news" in your forum directory.
To implment just write a simple include into a php page outside of your forums using the include.php file.
include.php
<?php
//config//
$includepath = "/path/to/forum/news/"; //path where the news folder resides
$mainurl = "http://www.yoursite.com";
$forumurl = "http://www.yoursite.com/forum/";
$includeurl = "http://www.yoursite.com/forum/news/"; //URL where the news folder resides
$newstemp = "template.html";
// Database Information
$dbserver = 'localhost';
$dbuser = 'username';
$dbpass = 'password';
$dbase = 'your_database';
$db = mysql_connect($dbserver, $dbuser, $dbpass) or die('Could not connect to DB server!');
mysql_select_db($dbase) or die("Could not connect to database: ".mysql_error());
function replace_bb_code($text) {
$text = preg_replace('/\:[0-9a-z\:]+\]/si', ']', $text);
$text = preg_replace( "#\(.+?)\[/b\]#is", "<b>\\1</b>", $text );
$text = preg_replace( "#\[i\](.+?)\[/i\]#is", "<i>\\1</i>", $text );
$text = preg_replace( "#\[u\](.+?)\[/u\]#is", "<u>\\1</u>", $text );
$text = preg_replace( "#\[s\](.+?)\[/s\]#is", "<s>\\1</s>", $text );
$text = eregi_replace("\\[url\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=\"_blank\">\\1</a>",$text);
$text = eregi_replace("\\[url=([^\\[]+)\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=\"_blank\">\\2</a>",$text);
$text = eregi_replace("\\[img\\]([^\\[]*)\\[/img\\]","<img src=\"\\1\" border=0>",$text);
$text = eregi_replace("\\[color=([^\\[]+)\\]([^\\[]*)\\[/color\\]","<font color=\"\\1\">\\2</font>",$text);
$text = eregi_replace("\\[quote\\]([^\\[]*)\\[/quote\\]","<br><br><strong>Quote:</strong><table width='80%' border='0' cellspacing='0' cellpadding='3'><tr><td bgcolor='#EFEFEF'><font color='#000000' size='-2'>\\1</font></td></tr></table><br>",$text);
$text = eregi_replace("\\[code\\]([^\\[]*)\\[/code\\]","<br><br><strong>Code:</strong><table width='80%' border='0' cellpadding='3' cellspacing='0' bgcolor='#FFFFFF' style='border:1px solid gray;'><tr><td bgcolor='#FFFFFF'><font color='#009900' size='-2'>\\1</font></td></tr></table><br>",$text);
$text = eregi_replace("\\[size=([^\\[]+)\\]([^\\[]*)\\[/size\\]","<font size='2'>\\2</font>",$text);
return $text;
}
$forumid = '12'; // You can set your forum ID here to pull the posts from the forum you want
$post_count = $_REQUEST['postcount'];
if (!$post_count) { $post_count = 3; } // You may Change the amount of posts that are returned here by changing the number
$changetemplate = $_REQUEST['template'];
if ($changetemplate == "") { } else { $newstemp = $changetemplate; }
$truncate = $_REQUEST['truncate'];
if (!$truncate) { $truncate = 100000; }
if($_REQUEST['reverse']==1) { ////you may need to change your database prefix from vbforum_ to what yours is
$query = "SELECT * FROM vbforum_post p, vbforum_thread t WHERE p.threadid = t.threadid AND t.forumid ='".$forumid."' ORDER BY p.threadid ASC, p.postid;";
} else {
$query = "SELECT * FROM vbforum_post p, vbforum_thread t WHERE p.threadid = t.threadid AND t.forumid ='".$forumid."' ORDER BY p.threadid DESC, p.postid;";
}
$result = mysql_query($query);
$num = mysql_num_rows($result);
$post = 0;
while($post < $post_count) {
$row = mysql_fetch_object($result);
if($row=="") { break; }
if ($previous_topic == $row->threadid) { // do nothing.
}
else {
$previous_topic = $row->threadid;
$post++;
$posttextquery = "SELECT * FROM vbforum_post WHERE postid='".$row->postid."';";
$posttextresult = mysql_query($posttextquery);
$posttextrow = mysql_fetch_object($posttextresult);
$useridquery = "SELECT * FROM vbforum_user WHERE userid='".$row->userid."';";
$useridresults = mysql_query($useridquery);
$useridrow = mysql_fetch_object($useridresults);
$responsesquery = "SELECT * FROM vbforum_post WHERE threadid='".$row->threadid."';";
$responsesresults = mysql_query($responsesquery);
$num_responses = mysql_num_rows($responsesresults)-1;
$fileopen = fopen($includeurl.$newstemp, "r");
$newsstring = fread($fileopen, filesize($includepath.$newstemp));
$subject = $posttextrow->title;
$newsstring = str_replace("((post_date))", date("F j, Y", $row->dateline), $newsstring);
$newsstring = str_replace("((post_time))", date("g:i a", $row->dateline), $newsstring);
$newsstring = str_replace("((poster_name))", "<a href='".$forumurl."member.php?u=".$row->userid."' target='_blank'>".$useridrow->username."</a>", $newsstring);
$newsstring = str_replace("((post_subject))", $subject, $newsstring);
if (strlen($newsstring) > $truncate) {
$newsstring = str_replace("((post_text))", substr(nl2br($posttextrow->pagetext),0,$truncate)."... <a href='".$forumurl."showthread.php?t=".$row->postid."' target='_blank'>READ MORE</a>", $newsstring);
} else {
$newsstring = str_replace("((post_text))", nl2br($posttextrow->pagetext), $newsstring);
}
$newsstring = str_replace("((comment))", "<a href='".$forumurl."showthread.php?t=".$row->threadid."' target='_blank'>Comments</a>", $newsstring);
$newsstring = str_replace("((responses))", $num_responses, $newsstring);
$newsstring = replace_bb_code($newsstring);
$newsstring = replace_bb_code($newsstring);
echo $newsstring;
}
}
?>
[B]template.html
<table width='535' border='0' align="center" cellpadding='4' cellspacing='1' style='font-family:Verdana;font-size:11px'>
<tr>
<td align='left' bgcolor='#8A8A8A' background="images/header_news.jpg" height="32">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="286" valign="middle" style='font-family:Verdana;font-size:9px;padding-left:3px'><span class="style1">
Posted By: <strong><font color="#FFFFFF"></font>((poster_name))</font></strong><br>
Posted On: ((post_date)) | ((post_time))</span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align='left' bgcolor='#BFBBBA'>
<strong><font color="#343434" size="2" face="Verdana, Arial, Helvetica, sans-serif">
((post_subject))</font></strong><font face="Verdana, Arial, Helvetica, sans-serif"><br>
<br>
<table style='border:1px dotted gray;width:100%;font-family:Verdana;font-size:10px'>
<tr>
<td>
<script language="javascript" type="text/javascript">
<!--
function pointercursor(){document.body.style.cursor = "move";}
function unpointercursor(){document.body.style.cursor="";}
//-->
</script>((post_text))
</td>
</tr>
</table>
</font> <p>
((comment)) - ((responses))</p></td>
</tr>
</table>
<div align="center"><br>
</div>
The below template.html and include.php file need to be in a folder called "news" in your forum directory.
To implment just write a simple include into a php page outside of your forums using the include.php file.
include.php
<?php
//config//
$includepath = "/path/to/forum/news/"; //path where the news folder resides
$mainurl = "http://www.yoursite.com";
$forumurl = "http://www.yoursite.com/forum/";
$includeurl = "http://www.yoursite.com/forum/news/"; //URL where the news folder resides
$newstemp = "template.html";
// Database Information
$dbserver = 'localhost';
$dbuser = 'username';
$dbpass = 'password';
$dbase = 'your_database';
$db = mysql_connect($dbserver, $dbuser, $dbpass) or die('Could not connect to DB server!');
mysql_select_db($dbase) or die("Could not connect to database: ".mysql_error());
function replace_bb_code($text) {
$text = preg_replace('/\:[0-9a-z\:]+\]/si', ']', $text);
$text = preg_replace( "#\(.+?)\[/b\]#is", "<b>\\1</b>", $text );
$text = preg_replace( "#\[i\](.+?)\[/i\]#is", "<i>\\1</i>", $text );
$text = preg_replace( "#\[u\](.+?)\[/u\]#is", "<u>\\1</u>", $text );
$text = preg_replace( "#\[s\](.+?)\[/s\]#is", "<s>\\1</s>", $text );
$text = eregi_replace("\\[url\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=\"_blank\">\\1</a>",$text);
$text = eregi_replace("\\[url=([^\\[]+)\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=\"_blank\">\\2</a>",$text);
$text = eregi_replace("\\[img\\]([^\\[]*)\\[/img\\]","<img src=\"\\1\" border=0>",$text);
$text = eregi_replace("\\[color=([^\\[]+)\\]([^\\[]*)\\[/color\\]","<font color=\"\\1\">\\2</font>",$text);
$text = eregi_replace("\\[quote\\]([^\\[]*)\\[/quote\\]","<br><br><strong>Quote:</strong><table width='80%' border='0' cellspacing='0' cellpadding='3'><tr><td bgcolor='#EFEFEF'><font color='#000000' size='-2'>\\1</font></td></tr></table><br>",$text);
$text = eregi_replace("\\[code\\]([^\\[]*)\\[/code\\]","<br><br><strong>Code:</strong><table width='80%' border='0' cellpadding='3' cellspacing='0' bgcolor='#FFFFFF' style='border:1px solid gray;'><tr><td bgcolor='#FFFFFF'><font color='#009900' size='-2'>\\1</font></td></tr></table><br>",$text);
$text = eregi_replace("\\[size=([^\\[]+)\\]([^\\[]*)\\[/size\\]","<font size='2'>\\2</font>",$text);
return $text;
}
$forumid = '12'; // You can set your forum ID here to pull the posts from the forum you want
$post_count = $_REQUEST['postcount'];
if (!$post_count) { $post_count = 3; } // You may Change the amount of posts that are returned here by changing the number
$changetemplate = $_REQUEST['template'];
if ($changetemplate == "") { } else { $newstemp = $changetemplate; }
$truncate = $_REQUEST['truncate'];
if (!$truncate) { $truncate = 100000; }
if($_REQUEST['reverse']==1) { ////you may need to change your database prefix from vbforum_ to what yours is
$query = "SELECT * FROM vbforum_post p, vbforum_thread t WHERE p.threadid = t.threadid AND t.forumid ='".$forumid."' ORDER BY p.threadid ASC, p.postid;";
} else {
$query = "SELECT * FROM vbforum_post p, vbforum_thread t WHERE p.threadid = t.threadid AND t.forumid ='".$forumid."' ORDER BY p.threadid DESC, p.postid;";
}
$result = mysql_query($query);
$num = mysql_num_rows($result);
$post = 0;
while($post < $post_count) {
$row = mysql_fetch_object($result);
if($row=="") { break; }
if ($previous_topic == $row->threadid) { // do nothing.
}
else {
$previous_topic = $row->threadid;
$post++;
$posttextquery = "SELECT * FROM vbforum_post WHERE postid='".$row->postid."';";
$posttextresult = mysql_query($posttextquery);
$posttextrow = mysql_fetch_object($posttextresult);
$useridquery = "SELECT * FROM vbforum_user WHERE userid='".$row->userid."';";
$useridresults = mysql_query($useridquery);
$useridrow = mysql_fetch_object($useridresults);
$responsesquery = "SELECT * FROM vbforum_post WHERE threadid='".$row->threadid."';";
$responsesresults = mysql_query($responsesquery);
$num_responses = mysql_num_rows($responsesresults)-1;
$fileopen = fopen($includeurl.$newstemp, "r");
$newsstring = fread($fileopen, filesize($includepath.$newstemp));
$subject = $posttextrow->title;
$newsstring = str_replace("((post_date))", date("F j, Y", $row->dateline), $newsstring);
$newsstring = str_replace("((post_time))", date("g:i a", $row->dateline), $newsstring);
$newsstring = str_replace("((poster_name))", "<a href='".$forumurl."member.php?u=".$row->userid."' target='_blank'>".$useridrow->username."</a>", $newsstring);
$newsstring = str_replace("((post_subject))", $subject, $newsstring);
if (strlen($newsstring) > $truncate) {
$newsstring = str_replace("((post_text))", substr(nl2br($posttextrow->pagetext),0,$truncate)."... <a href='".$forumurl."showthread.php?t=".$row->postid."' target='_blank'>READ MORE</a>", $newsstring);
} else {
$newsstring = str_replace("((post_text))", nl2br($posttextrow->pagetext), $newsstring);
}
$newsstring = str_replace("((comment))", "<a href='".$forumurl."showthread.php?t=".$row->threadid."' target='_blank'>Comments</a>", $newsstring);
$newsstring = str_replace("((responses))", $num_responses, $newsstring);
$newsstring = replace_bb_code($newsstring);
$newsstring = replace_bb_code($newsstring);
echo $newsstring;
}
}
?>
[B]template.html
<table width='535' border='0' align="center" cellpadding='4' cellspacing='1' style='font-family:Verdana;font-size:11px'>
<tr>
<td align='left' bgcolor='#8A8A8A' background="images/header_news.jpg" height="32">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="286" valign="middle" style='font-family:Verdana;font-size:9px;padding-left:3px'><span class="style1">
Posted By: <strong><font color="#FFFFFF"></font>((poster_name))</font></strong><br>
Posted On: ((post_date)) | ((post_time))</span></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align='left' bgcolor='#BFBBBA'>
<strong><font color="#343434" size="2" face="Verdana, Arial, Helvetica, sans-serif">
((post_subject))</font></strong><font face="Verdana, Arial, Helvetica, sans-serif"><br>
<br>
<table style='border:1px dotted gray;width:100%;font-family:Verdana;font-size:10px'>
<tr>
<td>
<script language="javascript" type="text/javascript">
<!--
function pointercursor(){document.body.style.cursor = "move";}
function unpointercursor(){document.body.style.cursor="";}
//-->
</script>((post_text))
</td>
</tr>
</table>
</font> <p>
((comment)) - ((responses))</p></td>
</tr>
</table>
<div align="center"><br>
</div>