MyBB Community Forums

Full Version: Displaying News on Homepage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12
Thanks agian, works great! *reps*
Works beautifully! It would be even better if you got the BB codes working! Smile
Belloman Wrote:Works beautifully! It would be even better if you got the BB codes working! Smile

In order for BBCode to work, use this code below. Note, I haven't compared it between k776's and ours, so the layout may look different. Smile

<?php 
$forumpath = "./forums/"; // Path to your forums root directory (with trailing slash)
$fid = "15"; // The forum ID to pull the annoucements from
$limit = "7"; // The amount of annoucements to show

require $forumpath."inc/config.php";function bb_code(&$string){
	$pattern = array(
		//[ul]
		'#\[list\](.*?)\[\/list\]#si',
		//[*]
		'#\[\*\](.*?)(\r\n|\r|\n|<br>|<br />|<br/>)#si',
		//[url]
		'#\[url\](.*?)\[\/(url)\]#si',
		//[url=XXX]
		'#\[url=(&quot;|"|\'|)(.*?)\\1\](.*?)\[\/url\]#si',	
		//[i],[u]
		'#\[u\](.*?)\[/u\]#si',
		'#\[i\](.*?)\[/i\]#si',
		//[b]
		'#\[b\](.*?)\[/b\]#si',
		//[img]
		'#\[img\](.*?)\[\/img\]#si',
		// font size
		'#\[size=(&quot;|"|\'|)([0-9\+\-]+)\\1\](.*?)\[\/size\]#si',		'#(\r|\n|\r\n)#si');

	$replacement = array(
		//ul
		"\t\t<ul>$1</ul>\r\n",
		//li
		"\t\t\t<li>$1</li>\r\n",
		//a
		'<a href="$1">$1</a>',
		//a
		'<a href="$2">$3</a>',
		//i, u
		'<u>$1</u>',
		'<em>$1</em>',
		//b
		'<strong>$1</strong>',
		//img							
		'<img src="$1" alt="User Posted Image" />',
		//size				
		'<font size="\2">\3</font>',		"<br />");
	$string = preg_replace ($pattern, $replacement, stripslashes($string) );	$string = str_replace ('<br /><br />', "</p>\r\n\t\t<p>", $string);
}
mysql_select_db($config['database'], mysql_connect($config['hostname'], $config['username'], $config['password']));

$query = mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.dateline,t.replies,p.message,u.avatar FROM ".$config['table_prefix']."threads t LEFT JOIN ".$config['table_prefix']."posts p ON (t.tid = p.tid) LEFT JOIN ".$config['table_prefix']."users u ON (t.uid = u.uid) WHERE t.fid='".$fid."' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND p.replyto='0' ORDER BY t.tid DESC LIMIT 0, ".$limit."") or die(mysql_error());
while($news = mysql_fetch_array($query))
{
	$date = gmdate("jS F Y", $news['dateline']);
	$time = gmdate("h:i A", $news['dateline']);	bb_code($news['message']);	if($news['replies'] == "1")
	{
		$replytext = "reply";
	}
	else
	{
		$replytext = "replies";
	}
	if($news['avatar'] != "")
	{
		if(substr($news['avatar'], 0, 7) != "http://")
		{
			$url = $forumpath;
		}
		$avatarbit = "<img style='float:left; margin:10px;'src=\"".$url.$news['avatar']."\" alt=\"".$url.$news['avatar']."\" />\r\n\t\t";
	}
	else
	{
		$avatarbit = "";
	}
	echo "\t<div class=\"news\">\r\n\t\t";
	echo "<div class='details'>(<a href=\"".$forumpath."showthread.php?tid=".$news['tid']."\">".$news['replies']." ".$replytext."</a>) | Posted by <a href=\"".$forumpath."member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> on ".$date." at ".$time."(GMT+1)</div>\r\n\t\t";
	echo "<h2>".$news['subject']."</h2>\r\n\t\t";
	echo $avatarbit."<p>".$news['message']."</p>\r\n\t\t<div style=\"clear:both;\"></div>\r\n\t";
	echo "</div>\r\n";
}
?>
The bbcode parser from that was coded for vBulletin though, and it is buggy, especially around lists so if you want to use it then modify it for your needs.

Why doesn't MyBB totally transfer to CSS? like in this template (the divs and all) instead of having tables? That would, imo, make MyBB the best. Well, as far as templates go anyway :p
That one doesn't work for me. I just get:

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /hsphere/local/home/belloman/bellomanstudios.simgames.net/weee.php on line 68
That's because a smilie got in the way in that code :| weird... anyway try this:
<?php 
require $forumpath."inc/config.php";

function bb_code(&$string){
	$pattern = array(
		//[ul]
		'#\[list\](.*?)\[\/list\]#si',
		//[*]
		'#\[\*\](.*?)(\r\n|\r|\n|<br>|<br />|<br/>)#si',
		//[url]
		'#\[url\](.*?)\[\/(url)\]#si',
		//[url=XXX]
		'#\[url=(&quot;|"|\'|)(.*?)\\1\](.*?)\[\/url\]#si',	   
		//[i],[u]
		'#\[u\](.*?)\[/u\]#si',
		'#\[i\](.*?)\[/i\]#si',
		//[b]
		'#\[b\](.*?)\[/b\]#si',
		//[img]
		'#\[img\](.*?)\[\/img\]#si',
		// font size
		'#\[size=(&quot;|"|\'|)([0-9\+\-]+)\\1\](.*?)\[\/size\]#si',		'#(\r|\n|\r\n)#si');

	$replacement = array(
		//ul
		"\t\t<ul>$1</ul>\r\n",
		//li
		"\t\t\t<li>$1</li>\r\n",
		//a
		'<a href="$1">$1</a>',
		//a
		'<a href="$2">$3</a>',
		//i, u
		'<u>$1</u>',
		'<em>$1</em>',
		//b
		'<strong>$1</strong>',
		//img							 
		'<img src="$1" alt="User Posted Image" />',
		//size				  
		'<font size="\2">\3</font>',		"<br />");
	$string = preg_replace ($pattern, $replacement, stripslashes($string) );	$string = str_replace ('<br /><br />', "</p>\r\n\t\t<p>", $string);
}
mysql_select_db($config['database'], mysql_connect($config['hostname'], $config['username'], $config['password']));

$query = mysql_query("SELECT t.tid,t.subject,t.uid,t.username,t.dateline,t.replies,p.message,u.avatar FROM ".$config['table_prefix']."threads t LEFT JOIN ".$config['table_prefix']."posts p ON (t.tid = p.tid) LEFT JOIN ".$config['table_prefix']."users u ON (t.uid = u.uid) WHERE t.fid='".$fid."' AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND p.replyto='0' ORDER BY t.tid DESC LIMIT 0, ".$limit."") or die(mysql_error());
while ($news = mysql_fetch_array ($query)){
	$date = gmdate ("jS F Y", $news['dateline']);
	$time = gmdate ("h:i A", $news['dateline']);

	//Parse BBCode
	bb_code($news['message']);

	if($news['replies'] == "1"){
		$replytext = "reply";
	} else {
		$replytext = "replies";
	}

	if($news['avatar'] != ""){
		if(substr($news['avatar'], 0, 7) != "http://")
		{
			$url = $forumpath;
		}
		$avatarbit = "<img style='float:left; margin:10px;'src=\"".$url.$news['avatar']."\" alt=\"".$url.$news['avatar']."\" />\r\n\t\t";
	} else {
		$avatarbit = "";
	}

	echo "\t<div class=\"news\">\r\n\t\t";
	echo "<div class='details'>(<a href=\"".$forumpath."showthread.php?tid=".$news['tid']."\">".$news['replies']." ".$replytext." </a>) | Posted by <a href=\"".$forumpath."member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> on ".$date." at ".$time."</div>\r\n\t\t";
	echo "<h2>".$news['subject']."</h2>\r\n\t\t";
	echo $avatarbit."<p>".$news['message']."</p>\r\n\t\t<div style=\"clear:both;\"></div>\r\n\t";
	echo "</div>\r\n";
}
?>
When I add this to the beginning, it works.

Quote:$forumpath = "./forums/"; // Path to your forums root directory (with trailing slash)
$fid = "4"; // The forum ID to pull the annoucements from
$limit = "10"; // The amount of annoucements to show

But above each post, I get this:

Warning: preg_replace(): Compilation failed: missing ) at offset 146 in /hsphere/local/home/belloman/bellomanstudios.simgames.net/weee.php on line 46

EDIT: Okay, now it works. There was a smilie in there for some reason...

Thanks for this!
- Belloman

2nd Edit: I have it up and running on my site! Yippee! Thanks for this. I really love it now! Smile
Gah! I keep getting "No database selected" but I have all the correct credentials.
Anyway we can get a border on the code Xilon posted?
Hello. An update. I'm still working on this (not as fast as before). I got everything except badword filter and smilies working. Just need permission from Chris to release it now (since its redistributing a decompiled functions_post.php file).
Pages: 1 2 3 4 5 6 7 8 9 10 11 12