MyBB Community Forums

Full Version: Showing specific threads on a custom index page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I have a problem, and I can't seem to find a way how to fix this. The situation is as follows:

I'm currently developing a custom index page, which users will arrive at when they visit the forum. I've made the page based on the original index.php file which is more or less intact (removed some unnecessary code like stats, birthdays etc which won't be showing on the page). I also have the custom template for it, basically I kept the header and welcome box, but I removed everything below like forum listing etc. That's all fine, and it looks good.

Now I want to use my "news script", which I got from this forum a few years back and has been used on my website. With this script I want to show certain topics from specific forums on this new custom index page. I've tried everything I could think of to get this script going, but I keep getting errors, like:

Quote:Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/manne/public_html/forum_ontwikkel/index_tdnl.php(166) : eval()'d code on line 34

The original script is as follows:

 <?php

    $fid = 2;
    $limit = 12;
    $forumpath = 'forum/';

    chdir($forumpath);
    define("IN_MYBB", 1);
    require('./global.php');
    require_once MYBB_ROOT."inc/class_parser.php";
    $parser = new postParser;
    chdir('../');
?>

<?php
    
    $query = $db->simple_select('threads', '*', "fid='2' OR fid='122' ORDER BY tid DESC LIMIT {$limit}");
    if($db->num_rows($query) > 0)
    {
        while($row = $db->fetch_array($query))
        {
            $query2 = $db->simple_select('posts', '*', "pid='{$row['firstpost']}'");
            $row2 = $db->fetch_array($query2);
            
            $date = my_date($mybb->settings['dateformat'], $row2['dateline'], "", 1);
            $time = my_date($mybb->settings['timeformat'], $row2['dateline'], "", 1);

            $options = array(
                            'allow_html' => '1', 
                            'filter_badwords' => '1', 
                            'allow_mycode' => '1', 
                            'allow_smilies' => '1', 
                            'nl2br' => '1', 
                            'me_username' => '1'
                            );
            $message = $parser->parse_message($row2['message'], $options);
	   	echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a><<br> 
                Door <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a> op {$date} om {$time}");
	    }
    }
    else
    {
        echo 'Nothing to display.';
    }
?>

But some things are not correct, so I have been changing a few things. Some things are already being defined in the customindex.php file, other definitions are not needed when running the script in the forum folder instead of the website root (which the script is originally made for).

[code]
 <?php

    $fid = 2;
    $limit = 12;

?>

<?php
    
    $query = $db->simple_select('threads', '*', "fid='2' OR fid='122' ORDER BY tid DESC LIMIT {$limit}");
    if($db->num_rows($query) > 0)
    {
        while($row = $db->fetch_array($query))
        {
            $query2 = $db->simple_select('posts', '*', "pid='{$row['firstpost']}'");
            $row2 = $db->fetch_array($query2);
            
            $date = my_date($mybb->settings['dateformat'], $row2['dateline'], "", 1);
            $time = my_date($mybb->settings['timeformat'], $row2['dateline'], "", 1);

            $options = array(
                            'allow_html' => '1', 
                            'filter_badwords' => '1', 
                            'allow_mycode' => '1', 
                            'allow_smilies' => '1', 
                            'nl2br' => '1', 
                            'me_username' => '1'
                            );
            $message = $parser->parse_message($row2['message'], $options);
	   	echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a><<br> 
                Door <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a> op {$date} om {$time}");
	    }
    }
    else
    {
        echo 'Nothing to display.';
    }
?>

But still I get the same error. I tried adding this code to the template. Adding only the first part to the index file and the second part to the template etc. etc. Somewhere I'm doing something completely wrong, but I don't know why. Basically I want to make two columns which show the first posts of different specific forum(s). Like one column with announcements from in example fid 1, 4 and 7. And on column with announcements from in example fid 22 and 77. It's basically a completely customized/revamped portal kind of page.

Any help much much appreciated!
I checked both above codes (2nd is missing files inclusion code) on local host AND didn't get any error !!
Thanks for checking. That's strange, so there might be something interfering between the script and the page I'm trying to incorporate it in, conflicting code or something? The custom page I'm building, and where I want to use the code, looks like this:

The code of index_tdnl.php (based on index.php):
<?php
/**
 * MyBB 1.6
 * Copyright 2010 MyBB Group, All Rights Reserved
 *
 * Website: http://mybb.com
 * License: http://mybb.com/about/license
 *
 * $Id: index.php 5480 2011-07-04 21:29:44Z huji $
 */

define("IN_MYBB", 1);
define('THIS_SCRIPT', 'index_tdnl.php');

$templatelist = "index_tdnl,index_whosonline,index_welcomemembertext,index_welcomeguest,index_whosonline_memberbit,forumbit_depth1_cat,forumbit_depth1_forum,forumbit_depth2_cat,forumbit_depth2_forum,forumbit_depth1_forum_lastpost,forumbit_depth2_forum_lastpost,index_modcolumn,forumbit_moderators,forumbit_subforums,index_welcomeguesttext";
$templatelist .= ",index_birthdays_birthday,index_birthdays,index_pms,index_loginform,index_logoutlink,index_stats,forumbit_depth3,forumbit_depth3_statusicon,index_boardstats";

require_once "./global.php";

require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_forumlist.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;

$plugins->run_hooks("index_start");

// Load global language phrases
$lang->load("index");

$logoutlink = $loginform = '';
if($mybb->user['uid'] != 0)
{
	eval("\$logoutlink = \"".$templates->get("index_logoutlink")."\";");
}
else
{
	//Checks to make sure the user can login; they haven't had too many tries at logging in.
	//Function call is not fatal
	if(login_attempt_check(false) !== false)
	{
		eval("\$loginform = \"".$templates->get("index_loginform")."\";".@$col[23]);
	}
}
$whosonline = '';
if($mybb->settings['showwol'] != 0 && $mybb->usergroup['canviewonline'] != 0)
{
	// Get the online users.
	$timesearch = TIME_NOW - $mybb->settings['wolcutoff'];
	$comma = '';
	$query = $db->query("
		SELECT s.sid, s.ip, s.uid, s.time, s.location, s.location1, u.username, u.invisible, u.usergroup, u.displaygroup
		FROM ".TABLE_PREFIX."sessions s
		LEFT JOIN ".TABLE_PREFIX."users u ON (s.uid=u.uid)
		WHERE s.time>'$timesearch'
		ORDER BY u.username ASC, s.time DESC
	");

	$forum_viewers = array();
	$membercount = 0;
	$onlinemembers = '';
	$guestcount = 0;
	$anoncount = 0;
	$doneusers = array();

	// Fetch spiders
	$spiders = $cache->read("spiders");

	// Loop through all users.
	while($user = $db->fetch_array($query))
	{
		// Create a key to test if this user is a search bot.
		$botkey = my_strtolower(str_replace("bot=", '', $user['sid']));

		// Decide what type of user we are dealing with.
		if($user['uid'] > 0)
		{
			// The user is registered.
			if($doneusers[$user['uid']] < $user['time'] || !$doneusers[$user['uid']])
			{
				// If the user is logged in anonymously, update the count for that.
				if($user['invisible'] == 1)
				{
					++$anoncount;
				}
				++$membercount;
				if($user['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1 || $user['uid'] == $mybb->user['uid'])
				{
					// If this usergroup can see anonymously logged-in users, mark them.
					if($user['invisible'] == 1)
					{
						$invisiblemark = "*";
					}
					else
					{
						$invisiblemark = '';
					}

					// Properly format the username and assign the template.
					$user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
					$user['profilelink'] = build_profile_link($user['username'], $user['uid']);
					eval("\$onlinemembers .= \"".$templates->get("index_whosonline_memberbit", 1, 0)."\";");
					$comma = $lang->comma;
				}
				// This user has been handled.
				$doneusers[$user['uid']] = $user['time'];
			}
		}
		elseif(my_strpos($user['sid'], "bot=") !== false && $spiders[$botkey])
		{
			// The user is a search bot.
			$onlinemembers .= $comma.format_name($spiders[$botkey]['name'], $spiders[$botkey]['usergroup']);
			$comma = $lang->comma;
			++$botcount;
		}
		else
		{
			// The user is a guest.
			++$guestcount;
		}

		if($user['location1'])
		{
			$forum_viewers[$user['location1']]++;
		}
	}

	// Build the who's online bit on the index page.
	$onlinecount = $membercount + $guestcount + $botcount;
	
	if($onlinecount != 1)
	{
		$onlinebit = $lang->online_online_plural;
	}
	else
	{
		$onlinebit = $lang->online_online_singular;
	}
	if($membercount != 1)
	{
		$memberbit = $lang->online_member_plural;
	}
	else
	{
		$memberbit = $lang->online_member_singular;
	}
	if($anoncount != 1)
	{
		$anonbit = $lang->online_anon_plural;
	}
	else
	{
		$anonbit = $lang->online_anon_singular;
	}
	if($guestcount != 1)
	{
		$guestbit = $lang->online_guest_plural;
	}
	else
	{
		$guestbit = $lang->online_guest_singular;
	}
	$lang->online_note = $lang->sprintf($lang->online_note, my_number_format($onlinecount), $onlinebit, $mybb->settings['wolcutoffmins'], my_number_format($membercount), $memberbit, my_number_format($anoncount), $anonbit, my_number_format($guestcount), $guestbit);
	eval("\$whosonline = \"".$templates->get("index_whosonline")."\";");
}

eval("\$index = \"".$templates->get("index_tdnl")."\";");
output_page($index);

?>

The index_tdnl template (based on the index template):
<html>
<head>
<title>{$mybb->settings['bbname']}</title>
{$headerinclude}
<script type="text/javascript">
<!--
	lang.no_new_posts = "{$lang->no_new_posts}";
	lang.click_mark_read = "{$lang->click_mark_read}";
// -->
</script>
</head>
<body>
{$header_tdnl}
->>> I want to add the script on this location <<<-
</body>
</html>

The custom header_tdnl template (based on the header template):
<div id="container_tdnl">

		<a name="top" id="top"></a>
		<div id="header">
			<div class="logo"><a href="{$mybb->settings['bburl']}/index.php"><img src="{$theme['logo']}" alt="{$mybb->settings['bbname']}" title="{$mybb->settings['bbname']}" /></a></div>
			<hr class="hidden" />
			<div id="panel">
				{$welcomeblock}
			</div>
		</div>

<br>
<div id="container_intro">

		<div id="intro_tdnl">
			<b><font color="#4eafcf">Tangodown</font></b> is een open tactical gaming community (geen clan). Iedereen is welkom om met ons mee te doen. Teamwork, tactiek en plezier is waar het om gaat. Via georganiseerde gamesessies wordt dit wekelijks in de praktijk gebracht.
		</div>
		<div id="meespelen_tdnl">
			<a href="wiki"><img src="http://www.tangodown.nl/images/button_meespelen.png" border="0" Alt="Meespelen? Lees hier hoe dat kan!"></a>
		</div>
</div>
		<hr class="hidden" />
		<br class="clear" />

		<div id="content">

<br />

			<br />