Translations of this page: en bg cs de fi fr hu it ja pl ru tr zh

This is an old revision of the document!


PunBB 1.3 integration

General

Common tasks

Recent 10 posts

<?php
 
define('RECENT_POSTS_SHOW_POST', true); // Set to false to show topic subject only
define('RECENT_POSTS_MAX_POST_LENGTH', 20); // Limit length of the post text displayed
 
if (!defined('FORUM_ROOT'))
	define('FORUM_ROOT', './');
 
require FORUM_ROOT.'include/common.php';
 
// Get 10 lastest posts
$query = array(
	'SELECT'	=> 'p.id, p.message, t.subject',
	'FROM'		=> 'posts AS p',
	'JOINS'		=> array(
		array(
			'LEFT JOIN'		=> 'topics AS t',
			'ON'			=> 'p.topic_id = t.id'
		)
	),
	'ORDER BY'	=> 'p.posted DESC',
	'LIMIT'		=> '0,10'
);
 
$result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
 
$recent_posts = array();
while ($cur_post = $forum_db->fetch_assoc($result))
	$recent_posts[] = $cur_post;
 
// Print out posts
if (!empty($recent_posts))
{
	?>
	<ul>
	<?php
	foreach($recent_posts as $cur_post)
	{
 
		echo '<li><a href="', forum_link($forum_url['post'], $cur_post['id']), '">', $cur_post['subject'], '</a>';
 
		if (RECENT_POSTS_SHOW_POST)
		{
			if (utf8_strlen($cur_post['message']) > RECENT_POSTS_MAX_POST_LENGTH)
				$cur_post['message'] = utf8_substr($cur_post['message'], 0, RECENT_POSTS_MAX_POST_LENGTH).'…';
 
			echo '<br />', "\n", $cur_post['message'];
		}
 
		echo '</li>';
	}
	?>
	</ul>
	<?php
}
 
?>

Showing all topics

<?php
 
if (!defined('FORUM_ROOT'))
	define('FORUM_ROOT', './');
 
require FORUM_ROOT.'include/common.php';
 
// Get all topics
$query = array(
	'SELECT'	=> 't.id, subject, t.last_post, forum_id',
	'FROM'		=> 'topics AS t',
	'JOINS'		=>	array(
		array(
			'INNER JOIN'	=>	'forums AS f',
			'ON'		=>	'f.id = t.forum_id'
		)
	),
	'ORDER BY'	=> 'last_post DESC',
);
 
$result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
 
if (!$forum_user['is_guest'])
	$tracked_topics = get_tracked_topics();
 
?>
<ul>
<?php
 
while ($cur_topic = $forum_db->fetch_assoc($result))
{
	echo '<li>';
 
	if (!$forum_user['is_guest'] && $cur_topic['last_post'] > $forum_user['last_visit'] && (!isset($tracked_topics['topics'][$cur_topic['id']]) || $tracked_topics['topics'][$cur_topic['id']] < $cur_topic['last_post']) && (!isset($tracked_topics['forums'][ $cur_topic['forum_id'] ]) || $tracked_topics['forums'][ $cur_topic['forum_id'] ] < $cur_topic['last_post']))
		echo '[unread]&nbsp;';
	else
		echo '[read]&nbsp;';
	echo '<a href="', forum_link($forum_url['topic'], $cur_topic['id']), '">', $cur_topic['subject'], '</a>';
 
	echo '</li>';
}
 
?>
</ul>

Personal Tools