MyBB Community Forums

Full Version: Show elements of Portal.php on main site
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,


I would like to have the Posts since lats here and users online from the portal show on the main page of the site. What code do I have to copy for that?

Thanks,
CT
bump plz answer...
I'm looking for the same. Especially "Users Online."
OK, so now we have to get someone to code it, like MiNT or Tikitiki. Toungue
Most of the code it commented out, search for what you want and use it.

For Users Online, focus on lines 217 to 279. It's not quite as simple as copy/paste, you'll have to do some tweaking and the like.
Of what file?
portal.php
Yeah, um, I don't know much PHP, sorry.

There is a Last Five Posts thing, though, if you're interested. I think it's by DennisTT or something.... I don't remember, I got it a while ago:
<?php if($_GET["head"] == "only")
{
?>
<head><link rel="stylesheet" href="style.css" type="text/css"><meta http-equiv="Refresh" content="120"></head>
<body bgcolor="#fbfcff">
<?php
// Host
    $DBhost="DB HOST";

// Database User Name
    $DBuser="DB USERNAME";

// Database Password
    $DBpass="DB PASS";

// Database Name
    $DBname="DB NAME";

$connect = mysql_connect($DBhost, $DBuser, $DBpass);
mysql_select_db($DBname,$connect) or die ("Could not select database");
mysql_query($connect);

$topic_result = mysql_query("SELECT COUNT(*) as count FROM nsbb_threads");
$topic_count = mysql_fetch_array($topic_result);
$topic_count = $topic_count['count'];
$post_result = mysql_query("SELECT COUNT(*) as count FROM nsbb_posts");
$post_count = mysql_fetch_array($post_result);
$post_count = $post_count['count'];
$user_result = mysql_query("SELECT COUNT(*) as count FROM nsbb_users");
$user_count = mysql_fetch_array($user_result);
$user_count = $user_count['count'];
$forum_result = mysql_query("SELECT COUNT(*) as count FROM nsbb_forums");
$forum_count = mysql_fetch_array($forum_result);
$forum_count = $forum_count['count'];

echo "<div align='center' valign='center'><table cellpadding='0' cellspacing='0' width='100%'>";

//echo "<tr><td><p><b>".$topic_count."</b></p></td><td><p>Threads</p></td></tr>";
//echo "<tr><td><p><b>".$post_count."</b></p></td><td><p>Posts</p></td></tr>";
//echo "<tr><td><p><b>".$user_count."</b></p></td><td><p><a href='http://newslang.awardspace.com/forum/memberlist.php' target='_blank' title='Memberlist'>Users</a></p></td></tr>";
//echo "<tr><td><p><b>".$forum_count."</b></p></td><td><p>Boards</p></td></tr>";
//echo "</table></td>";
//echo "<td width='50%'>";
//echo "<table width='100%' cellpadding='0' cellspacing='0'>";

// this will add the last 3 threads started on your forums
$var = 0;
$sql = mysql_query("SELECT * FROM nsbb_posts ORDER BY dateline DESC LIMIT 5");
while ($row = mysql_fetch_array($sql)) {
	   if($var % 2 == 0)
	   {
	    $bgcolor='#C6DEFF';
	   }
	   else
	   {
	    $bgcolor='#fbfcff';
	   }
	   $var++;
           $tid = $row['tid'];
           $fid = $row['fid'];
           $subject = $row['subject'];
           $replies = $row['replies'];
           $views = $row['views'];
	   $uid = $row['uid'];
	   $username = $row['username'];
$sql_query2 = "SELECT * FROM nsbb_forums WHERE fid='$fid'";
$results = mysql_query($sql_query2);
$row = mysql_fetch_array($results);
echo "<td width='50%' bgcolor='$bgcolor'><p><a title='Forum: ".$row['name']."' target='_blank' href='forum/showthread.php?tid=".$tid."&action=lastpost'><strong>".$subject."</strong></a></p></td><td bgcolor='$bgcolor' width='50%'><p>by <a href='forum/member.php?action=profile&uid=$uid' target='_blank'>$username</a></p></td></tr>";
}
echo "</table></div>";
?>
</body>
<?php
}
else
{
?>
<head><link rel="stylesheet" href="style.css" type="text/css"><meta http-equiv="Refresh" content="120"></head>
<body bgcolor="#fbfcff">
<table width="100%">
<tr>
<td width="50%"><h3>NS 3.0 Statistics</h3></td>
<td width="50%"><h3>NS 3.0 Recent Posts</h3></td>
</tr>
<tr>
<td>
<?php
// Host
    $DBhost="DB HOST";

// Database User Name
    $DBuser="DB USERNAME";

// Database Password
    $DBpass="DB PASS";

// Database Name
    $DBname="DB NAME";

$connect = mysql_connect($DBhost, $DBuser, $DBpass);
mysql_select_db($DBname,$connect) or die ("Could not select database");
mysql_query($connect);

$topic_result = mysql_query("SELECT COUNT(*) as count FROM nsbb_threads");
$topic_count = mysql_fetch_array($topic_result);
$topic_count = $topic_count['count'];
$post_result = mysql_query("SELECT COUNT(*) as count FROM nsbb_posts");
$post_count = mysql_fetch_array($post_result);
$post_count = $post_count['count'];
$user_result = mysql_query("SELECT COUNT(*) as count FROM nsbb_users");
$user_count = mysql_fetch_array($user_result);
$user_count = $user_count['count'];
$forum_result = mysql_query("SELECT COUNT(*) as count FROM nsbb_forums");
$forum_count = mysql_fetch_array($forum_result);
$forum_count = $forum_count['count'];

echo "<table>";

echo "<tr><td><p><b>".$topic_count."</b></p></td><td><p>Threads</p></td></tr>";
echo "<tr><td><p><b>".$post_count."</b></p></td><td><p>Posts</p></td></tr>";
echo "<tr><td><p><b>".$user_count."</b></p></td><td><p><a href='http://newslang.awardspace.com/forum/memberlist.php' target='_blank' title='Memberlist'>Users</a></p></td></tr>";
echo "<tr><td><p><b>".$forum_count."</b></p></td><td><p>Boards</p></td></tr>";
echo "</table></td>";
echo "<td width='50%'>";
echo "<table width='100%' cellpadding='0' cellspacing='0'>";

// this will add the last 3 threads started on your forums
$var = 0;
$sql = mysql_query("SELECT * FROM nsbb_posts ORDER BY dateline DESC LIMIT 5");
while ($row = mysql_fetch_array($sql)) {
	   if($var % 2 == 0)
	   {
	    $bgcolor='#C6DEFF';
	   }
	   else
	   {
	    $bgcolor='#fbfcff';
	   }
	   $var++;
           $tid = $row['tid'];
           $fid = $row['fid'];
           $subject = $row['subject'];
           $replies = $row['replies'];
           $views = $row['views'];
	   $uid = $row['uid'];
	   $username = $row['username'];
$sql_query2 = "SELECT * FROM nsbb_forums WHERE fid='$fid'";
$results = mysql_query($sql_query2);
$row = mysql_fetch_array($results);
echo "<td width='50%' bgcolor='$bgcolor'><p><a title='Forum: ".$row['name']."' target='_blank' href='forum/showthread.php?tid=".$tid."&action=lastpost'><strong>".$subject."</strong></a></p></td><td bgcolor='$bgcolor' width='50%'><p>by <a href='forum/member.php?action=profile&uid=$uid' target='_blank'>$username</a></p></td></tr>";
}
echo "</table></tr></td></table>";
?>
</body>
<?php
}
?>

Yeah, I did really sloppy PHP editing and just changed the $_GET var.
To put recent posts on your page, create an iframe with the URL of recent.php?head=only.
I it could be made much simpler, the way that I did, tho it is the last 7threads.

Index.php (main page on your site)
<?php
// Here we show teh latest forum topics! :w00t:
include 'configforumz.php';

$db = mysql_connect($config['hostname'], $config['username'], $config['password']);

if (!mysql_select_db($config['database'] , $db)) 
{
     die("could not connect");
}

$result = mysql_query("SELECT * FROM mybb_threads ORDER BY tid DESC LIMIT 0,7" ,$db);
$id = 0;
while($item = mysql_fetch_array($result))  
{   
    // Output the cells
    echo '<br /><strong><a href="http://yourforum.com?tid='.$item['tid'].'">'.$item['subject'].'</a></strong><br />&nbsp;';
    $id = 1;
}

if($id == 0) 
{    
    echo '<p><strong> Oops, it seems like the db thinks that there are no articles in the db!  Please E-mail [email protected]</p>';   
}

?>

Configforumz.php
<?php 
$config['hostname'] = "localhost";

$config['username'] = "forumdb";

$config['password'] = "password";

$config['database'] = "forums";

Hope this helps.
?>
Oh, I know. I just did a sloppy job. I was planning on simplifying it later.

I still need help on getting the users online thing to work, though.