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
You might want to check out this news script HERE. Very easy to use and customize.
CraKteR Wrote:Change ./forum to the path of your forum.
/forum is the path to my forum.
Unless you mean to just take out the period and make it /forum (which results in even more errors I'm afraid).

Re: RogueDOC
-I'll try it out, thanks.
EDIT: works great!
How come none of the scripts have mysql_close()?
After an page is done loading it will close the database by itself though.

Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. See also freeing resources.
Really? I never knew that. There's something I learned today
Does anyone know how to get this code to show emoticons, this is the code i have so far:
<?php
$forumpath = "../mybb/"; // Path to your forums root directory (with trailing slash)
$fid = "2"; // The forum ID to pull the annoucements from
$limit = "5"; // The amount of annoucements to show

require $forumpath."inc/config.php";

function bb_code(&$string){
    $pattern = array(
        //[ol]
        '#\[list=1\](.*?)\[\/list\]#si',
        //[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',
        //[size=small]
        '#\[size=small](.*?)\[\/size\]#si',
        //[size=medium]
        '#\[size=medium](.*?)\[\/size\]#si',
        //[size=large]
        '#\[size=large](.*?)\[\/size\]#si',
        //[size=x-large]
        '#\[size=x-large](.*?)\[\/size\]#si',
        //[size=xx-large]
        '#\[size=xx-large](.*?)\[\/size\]#si',
        // [size=XXX]
        '#\[size=(&quot;|"|\'|)([0-9\+\-]+)\\1\](.*?)\[\/size\]#si',
        //[align=XXX]
        '#\[align=(&quot;|"|\'|)(.*?)\\1\](.*?)\[\/align\]#si',
        //[color=XXX]
        '#\[color=(&quot;|"|\'|)(.*?)\\1\](.*?)\[\/color\]#si',
        //[font=XXX]
        '#\[font=(&quot;|"|\'|)(.*?)\\1\](.*?)\[\/font\]#si',
        //[quote]
        '#\[quote](.*?)\[\/quote\]#si',
        //[code]
        '#\[code](.*?)\[\/code\]#si',
        //[php]
        '#\[php](.*?)\[\/php\]#si',
	  //Whitespace
	  '#(\r|\n|\r\n)#si');

    $replacement = array(
        //ol
        "\t\t<ol>$1</ol>\r\n",
        //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 = small
        '<font size="2">$1</font>',
        //size = medium
        '<font size="4">$1</font>',
        //size = large
        '<font size="6">$1</font>',
        //size = x-large
        '<font size="8">$1</font>',
        //size = xx-large
        '<font size="10">$1</font>',
        //size = xxx                  
        '<font size="\2">\3</font>',
        //align
        '<p style="text-align: $2">$3</p>',
        //color
        '<font color="$2">$3</font>',
        //color
        '<font face="$2">$3</font>',
        //quote
        '<p style="padding:10px"><b>Quote:</b><br />$1</p>',
        //code
        '<p style="padding:10px"><b>Code:</b><br />$1</p>',
        //php
        '<p style="padding:10px"><b>PHP Code:</b><br />$1</p>',
	  //Whitespace
	  "<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";
}
?>

EDIT:
Where the hell did:
Quote: '#\[\*\](.*?)(\r\n|\r|\n|<br>|<br />|<br/&gt<img src="http://community.mybboard.net/images/smilies/wink.gif" style="vertical-align: middle;" border="0" alt="Wink" />#si',
Come from, that wasnt in the code i posted

EDIT2: Why wont the quote tag work around that code?
Simulationcity Wrote:Really? I never knew that. There's something I learned today
That was taken from the PHP site, although if you connect with mysql_pconnect it won't be, and can't be closed with mysql_close.

MrDoom Wrote:Does anyone know how to get this code to show emoticons, this is the code i have so far:
That depends if you want the smilies from the mybb forum or your own.
CraKteR Wrote:
MrDoom Wrote:Does anyone know how to get this code to show emoticons, this is the code i have so far:
That depends if you want the smilies from the mybb forum or your own.
The ones from the forum really, i tried adding them to the code i posted above but it didnt work.

EDIT:
Also, is it possible to make this take news from multiple forums?
Xilon Wrote: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";
}
?>

So I'm using the abouve code, but, my installation of myBB is a conversion of phpBB, and it is pulling all replies to the threads (http://www.battleroyalegame.com/), however on another site its is all fine (http://www.cragllo.com/).

Anyone help with this please? or know how to solve.
hi too all.
my code work carefully ! but i have 3 problem .
1- i want show new Replys or new threads from all forums in my board.
2- when any one post new Reply to special thread , i want that thread name move up to the first line of "new threads page(under code)" and
username change to new poster username .
plz help me !
i use this code :

Code:
<?php
$forumpath = ".//"; // Path to your forums root directory (with trailing slash)
$fid = "[color=red]i want show all forum new post[/color]"; // The forum ID to pull the annoucements from
$limit = "10"; // The amount of annoucements to show

require $forumpath."inc/config.php";
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))
{
    if(strlen($news['message']) > 50) {
��������$news['message'] = substr($news['subject'], 0, 20);
��������$news['message'] .= "...";
����}
����$date = gmdate("d-m-Y", $news['dateline']);
����$time = date("h:i A", $news['dateline']);
����if($news['replies'] == "1")
����{
��������$replytext = "reply";
����}
����else
����{
��������$replytext = "replies";
����}
����echo "<table cellpadding=\"0\" align=\"center\" style=\"border: solid 0px #000000;\" width=\"100%\" dir=\"rtl\">\n";
����echo "<tr><td dir=\"rtl\" style=\"border: solid 0px #000000;\"\"><a title=\"".$news['message']."\" href=\"showthread.php?tid=".$news['tid']."\">".$news['subject']."</a> | - <a href=\"member.php?action=profile&amp;uid=".$news['uid']."\">".$news['username']."</a> - ".$date." - ".$time." | - : ".$news['replies']." |</td></tr>\n";
����echo "</table><br />\n\n";
}
?>
Pages: 1 2 3 4 5 6 7 8 9 10 11 12