Here is code i am using, see it in action on
http://www.phpbb.com/rules/#rule6a (note the code is still early and smilies don't work if you set it to view the whole post instead of just topic title links.
You don't need to add in your username or pasword or anything either it gets it all for you.
Be warned it is a bit long code, but there are a features other mods don't have.
Code: Select all
<?php
## Mod Title: Topic Extraction [PHPBB3]
## Version: 1.0.0
#############
## Edit Below
#############
// Where to take the topics from
// Always a number
$forum = '2';
// How many topics to show
$limit = '2';
// How to show the topics
// full or blank ('')
$show = 'full';
// How to display the date and time if used
// short or long
$date_time = 'short';
// How top display the topic link if usede
// topic or phpbb
$topic_link_type = 'topic';
// Comments link - how to send them to comments
// topic or reply
$comment = 'topic';
// Path to your forums directory
// Usually ./forum/ or ./phpBB/ or ./forums/
$phpbb_root_path = './phpbb3/';
// Folder where your phpbb3 is
// Something like /phpbb3/ or /forum/
$phpbb_folder = '/phpbb3/';
// Change blow to whatever extension your using for php files (usually .php)
$phpEx = 'php';
#############################################
## No Editing unless you know what your doing
#############################################
if ( !defined('IN_PHPBB') )
{
define('IN_PHPBB', true);
define('IN_CRON', true);
}
include($phpbb_root_path . 'common.php');
if ($show == '' || $show == 'full')
{
// Select the topic information from the correct forum and set it to $grab_topics
$grab_topics = $db->sql_query("SELECT * FROM `{$table_prefix}topics` WHERE `forum_id` = '{$forum}' AND `topic_moved_id` = '0' ORDER BY `topic_id` DESC LIMIT {$limit}");
}
else if ($show == 'topic')
{
$grab_topics = $db->sql_query("SELECT * FROM `{$table_prefix}topics` WHERE `forum_id` = '{$forum}' AND `topic_id` = '{$_GET['t']}' ORDER BY `topic_id` DESC");
}
// Grab the information using an array and set it to $echo_topic
while ($echo_topic = $db->sql_fetchrow($grab_topics))
{
// Select the post information from the correct forum and set it to $grab_posts
$grab_posts = $db->sql_query("SELECT * FROM `{$table_prefix}posts` WHERE `forum_id` = '{$forum}' AND `topic_id` = '{$echo_topic['topic_id']}' LIMIT 1");
// Grab the information using an array and set it to $echo_post
while ($echo_post = $db->sql_fetchrow($grab_posts))
{
// Find the user the posted
$find_user = $db->sql_query("SELECT * FROM `{$table_prefix}users` WHERE `user_id` = '{$echo_post['poster_id']}'");
// Sort this users info into array for the post
while ($echo_user = $db->sql_fetchrow($find_user))
{
// Get rid of all those annoying characters from bbcode
$echo_post['post_text'] = preg_replace('/\:[0-9a-z\:]+\]/si', ']', $echo_post['post_text']);
// BBCode
$echo_post['post_text'] = str_replace("[b]","<strong>",$echo_post['post_text']);
$echo_post['post_text'] = str_replace("[/b]","</strong>",$echo_post['post_text']);
$echo_post['post_text'] = str_replace("[i]","<em>",$echo_post['post_text']);
$echo_post['post_text'] = str_replace("[/i]","</em>",$echo_post['post_text']);
$echo_post['post_text'] = str_replace("[u]","<u>",$echo_post['post_text']);
$echo_post['post_text'] = str_replace("[/u]","</u>",$echo_post['post_text']);
$echo_post['post_text'] = preg_replace('/\[quote=(.*)\](.*)\[\/quote\]/Usi','<div style=\"padding: 7px\">$2</div>',$echo_post['post_text']);
$echo_post['post_text'] = str_replace("[quote]","<strong>Quote</strong><em>",$echo_post['post_text']);
$echo_post['post_text'] = str_replace("[/quote]","</em>",$echo_post['post_text']);
$echo_post['post_text'] = str_replace("[code]","<strong>Code</strong><em>",$echo_post['post_text']);
$echo_post['post_text'] = str_replace("
","</em>",$echo_post['post_text']);
$echo_post['post_text'] = preg_replace('/\[list\](.*)\[\/list\]/si',"<div style=\"padding: 7px\">$1</div>",$echo_post['post_text']);
$echo_post['post_text'] = preg_replace('/\
- (.*)\[\/list\]/si',"<div style=\"padding: 7px\">$1</div>",$echo_post['post_text']);
$echo_post['post_text'] = str_replace("[img]","<img src=\"",$echo_post['post_text']);
$echo_post['post_text'] = str_replace("[/img]","\" alt=\"image\" />",$echo_post['post_text']);
$echo_post['post_text'] = preg_replace('/\[url\](.*)\[\/url\]/Usi','<a href="$1">$1</a>',$echo_post['post_text']);
$echo_post['post_text'] = preg_replace('/\[url=(.*)\](.*)\[\/url\]/Usi','<a href="$1">$2</a>',$echo_post['post_text']);
$echo_post['post_text'] = preg_replace('/\[color=(.*)\](.*)\[\/color\]/Usi','<span style="{color:$1}">$2</span>',$echo_post['post_text']);
$echo_post['post_text'] = preg_replace('/\[size=(.*)\](.*)\[\/size\]/Usi','<span style="{font-size:$1pt}">$2</span>',$echo_post['post_text']);
$echo_post['post_text'] = str_replace("\n", "\n<br />\n", $echo_post['post_text']);
// Way to display date and time
// long
if($date_time == "long")
{
$echo_topic['topic_time'] = strftime("%A %e %B %H:%M",$echo_topic['topic_time']);
}
// short
if ($date_time == "short")
{
$echo_topic['topic_time'] = strftime("%a %e %b %H:%M",$echo_topic['topic_time']);
}
// Way to display comment link
// Go right to the topic
if ($comment == 'topic')
{
$comment_link = "{$phpbb_folder}viewtopic.php?t={$echo_topic['topic_id']}";
}
// Go right to the reply box
if ($comment == 'reply')
{
$comment_link = "{$phpbb_folder}posting.php?mode=reply&t={$echo_topic['topic_id']}";
}
// Topic link types
// This link goes to the topic display
if ($topic_link_type == 'topic')
{
$topic_link = "?show1=topic&t={$echo_topic['topic_id']}";
}
// This link goes to the actual phpbb topic
if ($topic_link_type == 'phpbb')
{
$topic_link = "{$phpbb_folder}viewtopic.php?t={$echo_topic['topic_id']}";
}
##################################
## Edit for look and feel of topic
##################################
// Display just the title
if ($show != 'full' && !isset($_GET['show1']))
{
echo "<a href='{$topic_link}'>{$echo_topic['topic_title']}</a><br />";
}
// Display many topics - for news, shoutbox etc
else if ($show == 'full')
{
echo "
<strong>{$echo_topic['topic_title']}</strong> by <strong>{$echo_user['username']}</strong> at <strong>{$echo_topic['topic_time']}</strong>
<br />
<br />
{$echo_post['post_text']}
<br />
<br />
<a href=\"{$comment_link}\">Comments {$echo_topic['topic_replies']}</a>
<hr size=\"1\">
";
}
// Display the topic for when used with the one above, click link and go here
if ($_GET['show1'] == 'topic')
{
echo "
<strong>{$echo_topic['topic_title']}</strong> by <strong>{$echo_user['username']}</strong> at <strong>{$echo_topic['topic_time']}</strong>
<br />
<br />
{$echo_post['post_text']}
<br />
<br />
<a href=\"{$comment_link}\">Comments {$echo_topic['topic_replies']}</a>
<hr size=\"1\">
";
}
}
}
}
?>
[/code]