Version: 1.00, by dcncdrew
Developer Last Online: Dec 2008
Version: 3.0.9
Rating:
Released: 09-19-2005
Last Update: 09-19-2005
Installs: 4
Is in Beta Stage
No support by the author.
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
Code:
<?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\](.+?)\[/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;
}
}
?>
I know and I also know that it works to an extent and thats why I am tracking it here.
Also, I am not trying to be rude. I just am working on making changes so thats all. And if you cant understand the layout by looking at the html then thats a whole nother problem all together.
The html template means you have the option to have it displayed any way you want. So what I deem a good and logical layout to me is different to you.