MyBB Community Forums

Full Version: BB Code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I have an external webpage that is pulling 'news' out of the announcements forum on the website's forum and displaying it on the main page of the website. The problem is, obviously it doesnt parse the BB code tags in the posts, so is there a way to use the MyBB BB code engine thingo on that external page?

I also want to have a login sort of thing on the page, that if a person it logged in it tells them how many new posts/threads have been made since they last visited etc etc.

any ideas? Smile
For the bbcode:

$message = "Hi, this is my news item!";
require_once "path/to/inc/functions_post.php";
$message = postify($message, "no", "yes", "yes", "yes", "yes");

Of course, you'll have to modify it a bit.

For the login sort of thing, what you want is what is similar to what is in the portal.php file, so I'd take a look at that. (Infact, you could even pull out the code we use to show the latest announcements on the portal).

Chris
What we have on the front page, is:
<?php
include "news.php";
?>
The source of news.php is:
<?php
$forumpath = "/"; // Path to your forums root directory (with trailing slash)
$fid = "23"; // The forum ID to pull the annoucements from
$limit = "10"; // The amount of annoucements to show

require "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))
{
    $date = date("jS of F Y", $news['dateline']);
    $time = date("h:i A", $news['dateline']);
    if($news['replies'] == "1")
    {
        $replytext = "reply";
    }
    else
    {
        $replytext = "replies";
    }
    echo "<table width=\"90%\" align=\"center\" bgcolor=\"black\" cellpadding=\"0\" cellspacing=\"1\">\n";
    echo "<tr><td bgcolor=\"white\" style=\"padding: 3px;background-image:url(".$forumpath."images/black/thead.jpg); font-weight: bold; font-family: Verdana; font-size: 13px;\"><span style=\"float:right; font-size: 9px;\">(<a href=\"".$forumpath."showthread.php?tid=".$news['tid']."\"><font color=\"white\">".$news['replies']." ".$replytext."</font></a>) | Posted by <a href=\"".$forumpath."member.php?action=profile&amp;uid=".$news['uid']."\"><font color=\"white\">".$news['username']."</font></a> on the ".$date." at ".$time."&nbsp;</span>&nbsp;".$news['subject']."</td></tr>\n";
    echo "<tr><td bgcolor=\"white\" style=\"padding: 5px;\">". $news['message'] ."</td></tr>\n";
    echo "</table><br />\n\n";
}
?>

So to i just have to require functions_post.php at the top of news.php, and then wrap the $news['message'] part with postify(); ?
Well i did that, and the bbcode parsing works fine. i ended up including global.php as well because it said something about calling a member function on a non-object.
the issue i have with including global.php, and we always get this error, is

Quote:Warning: Cannot modify header information - headers already sent by (output started at /path/to/index.php:9) in /path/to/inc/functions.php on line 802

Im not sure how to fix that without editing global.php which i obviously dont want to do Toungue
Include global.php before functions.php ?
<?php 
require "global.php";
require "inc/functions_post.php";
?>
thats what it is Toungue i dont even have functions.php included Confused
Quote:Warning: Cannot modify header information - headers already sent by (output started at /path/to/index.php:9) in /path/to/inc/functions.php on line 802

There is some white space on line 9 of index.php, or at least something being outputted to the browser.

You need to include/require MyBB before anything is sent to the browser.
as you know, that is no longer the case, and i still get the error.
i get one error, but most other people get 2 errors saying the same thing o.O
Would using the ob_start(); tag help? (Just it solves my probs sometimes - just place it at the very top of the code)
When trying this, I get this error:

Fatal error: Call to a member function on a non-object in /hsphere/local/home/********/rctgo.simgames.net/forums/inc/functions_post.php on line 156

I'm using this code:

<?php
$forumpath = "forums/"; // Path to your forums root directory (with trailing slash)
$fid = "55"; // The forum ID to pull the annoucements from
$limit = "10"; // The amount of annoucements to show
require_once "/hsphere/local/home/belloman/rctgo.simgames.net/forums/inc/functions_post.php";
$message = postify($message, "no", "yes", "yes", "yes", "yes");

require "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))
{
$date = date("jS of F Y", $news['dateline']);
$time = date("h:i A", $news['dateline']);
if($news['replies'] == "1")
{
$replytext = "reply";
}
else
{
$replytext = "replies";
}
echo "<table width=\"90%\" align=\"center\" bgcolor=\"black\" cellpadding=\"0\" cellspacing=\"1\">\n";
echo "<tr><td bgcolor=\"white\" style=\"padding: 3px;background-image:url(".$forumpath."images/black/thead.jpg); font-weight: bold; font-family: Verdana; font-size: 13px;\"><span style=\"float:right; font-size: 9px;\">(<a href=\"".$forumpath."showthread.php?tid=".$news['tid']."\"><font color=\"white\">".$news['replies']." ".$replytext."</font></a>Wink | Posted by <a href=\"".$forumpath."member.php?action=profile&amp;uid=".$news['uid']."\"><font color=\"white\">".$news['username']."</font></a> on the ".$date." at ".$time."&nbsp;</span>&nbsp;".$news['subject']."</td></tr>\n";
echo "<tr><td bgcolor=\"white\" style=\"padding: 5px;\">". $news['message'] ."</td></tr>\n";
echo "</table><br />\n\n";
}
?>
Pages: 1 2