On the index page of my site (http://fragnet.ca) I'm using the template version of the 'Show forum threads as news articles' MOD (to display recent threads + messages at the bottom of my site) and the 'Top Five' MOD (to display the recent threads in the left column of my site).
Only want to use parts of the portal. I would like to use all 3 (portal, news articles and top five) together.
This is my index page (http://fragnet.ca):
Code: Select all
<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './forum/'; // Replace with your own root path
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include_once($phpbb_root_path . 'common.' . $phpEx);
include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl( $user->data );
$user->setup('mods/news_articles');
// Gets the name of this file
$this_file = get_this_filesname(__FILE__);
/*
FROM HERE, you can now change whatever you want in order to suit your needs.
For example, you can build the datas to however you like. OR you can change the output variables.
That is where the html gets outputted.
If you know php variables and html, you can modify that to your own usage.
*/
//
// User Config Options
//
$fora_ids = array(359, 381, 406, 450, 536, 525, 530, 514, 519, 391, 590, 594, 555, 358, 618, 549, 566, 420, 415, 567, 580, 573, 593, 581); // array of forum ids you want posts from
$parent_ids = true; // array of parent forum ids, set to false if not used
$articles = 15; // number of posts to return
$offset = 58; // offset : Set this variable if you don't want the result set begin on the first entry
$children = true; // This variable specifies whether we should include the "child forums" of the given $forum_ids in the results
$sort_order = sort_order_query('active_desc');
$allow_attach = false; // Show attachments, if any ?
$allow_ranks = true; // Show ranks ?
$allow_sigs = false; // Show signatures ?
$allow_avatar = true; // Show avatars ?
// Get the posts
$posts = get_news($fora_ids, $parent_ids, $articles, $offset, $children, $sort_order, $allow_attach, $allow_ranks, $allow_sigs, $allow_avatar);
//-- mod: top five ---------------------------------------------------------//
include($phpbb_root_path . 'includes/top_five.' . $phpEx);
//-- end: top five ---------------------------------------------------------//
// Assign Common vars
// Language vars are in: language/en/mods/news_articles.php
$template->assign_vars(array(
'L_BREADCRUMBS' => $user->lang['LN_BREADCRUMBS'],
'L_NUM_REPLIES' => $user->lang['LN_NUM_REPLIES'],
'L_NUM_VIEWS' => $user->lang['LN_NUM_VIEWS'],
'L_POST_ATTACHMENT' => $user->lang['LN_POST_ATTACHMENTS'],
'L_ATTACHMENTS' => $user->lang['LN_ATTACHMENTS'],
'L_IS_ATTACHMENTS' => $user->lang['LN_IS_ATTACHMENTS'],
'L_NUM_ATTACHMENTS' => $user->lang['LN_NUMBER_ATTACHMENTS'],
'L_ATTACH_DOWNLOADS' => $user->lang['LN_ATTACH_DOWNLOADS'],
'L_ATTACH_COMMENTS' => $user->lang['LN_ATTACH_COMMENTS'],
'L_DOWNLOAD_EXPLAIN' => $user->lang['LN_DOWNLOAD_EXPLAIN'],
'L_POSTED_ON' => $user->lang['LN_POSTED_ON'],
'L_POSTED_BY' => $user->lang['LN_POSTED_BY'],
'L_RANK_TITLE' => $user->lang['LN_RANK_TITLE'],
'L_DISCUSS_TOPIC' => $user->lang['LN_DISCUSS_TOPIC'],
'L_INDEX' => $user->lang['FORUM_INDEX'],
'U_INDEX' => append_sid($phpbb_root_path),
));
// Build the output
foreach($posts as $post)
{
// First set all the data in vars
$bbcode_options = (($post['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($post['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($post['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);
// Actual Post
$post_text = generate_text_for_display($post['post_text'], $post['bbcode_uid'], $post['bbcode_bitfield'], $bbcode_options);
$post_text = bbcode_nl2br($post_text);
$post_text = smiley_text($post_text);
$post_link = append_sid($phpbb_root_path . 'viewtopic.' . $phpEx, array('f' => $post['forum_id'], 't' => $post['topic_id'])) . '#p' . $post['post_id'];
$post_subject = censor_text($post['topic_title']);
$post_time = $user->format_date($post['post_time']);
$post_replies_count = $post['topic_replies_real'];
$post_views = $post['topic_views'];
// Post Tracking (Is it unread or not?)
$topic_tracking_info = get_complete_topic_tracking($post['forum_id'], $post['topic_id'], false);
$is_this_unread = (isset($topic_tracking_info[$post['topic_id']]) && $post['topic_last_post_time'] > $topic_tracking_info[$post['topic_id']]) ? true : false;
// Post Icons
$post_icon = $icon_alt_text = $topic_type = '';
topic_status($post, $post['topic_replies_real'], $is_this_unread, $post_icon, $icon_alt_text, $topic_type);
$post_icon = $user->img($post_icon, $icon_alt_text, false, '', 'src');
$icon_alt_text = $user->lang[$icon_alt_text];
// Attachments
$is_there_attachments = $post['is_there_attachments'];
$post_attachments = $post['attachments'];
$post_attachment_names = $post['attachment_names'];
$post_attachment_downloads = $post['attachment_downloads'];
$post_attachment_comments = $post['attachment_comments'];
$post_attachment_filesize = $post['attachment_filesize'];
$num_of_attachments = $post['num_of_attachments'];
$poster_avatar = $user_rank_title = $user_rank_image = $user_signature = '';
// User Information
if($post['allow_avatar'])
{
$poster_avatar = get_user_avatar($post['user_avatar'], $post['user_avatar_type'], $post['user_avatar_width'], $post['user_avatar_height']);
}
$poster_link = append_sid($phpbb_root_path . 'memberlist.' . $phpEx, array('mode' => 'viewprofile', 'u' => $post['user_id']));
$poster_name = get_username_string('full', $post['user_id'], $post['topic_last_poster_name'], $post['user_colour']);
// Ranks
if($post['allow_ranks'])
{
if($post['user_id'] != ANONYMOUS)
{
// unset($user_rank_title, $user_rank_image, $user_rank_image_relative_src);
unset($user_rank_image_relative_src);
get_user_rank($post['user_rank_id'], $post['user_posts'], $user_rank_title, $user_rank_image, $user_rank_image_relative_src);
}
}
// Signatures
if($post['allow_sigs'])
{
$user_signature = generate_text_for_display($post['user_sig'], $post['user_sig_bbcode_uid'], $post['user_sig_bbcode_bitfield'], $bbcode_options);
$user_signature = bbcode_nl2br($user_signature);
$user_signature = smiley_text($user_signature);
}
// THE BUILDING BLOCKS ARE DONE!
// ITS TIME TO START PUTTING THE BLOCKS TOGETHER INTO COHERENT HTML
$template->assign_block_vars('postrow', array(
'POST_ID' => $post['post_id'],
'POST_ICON' => $post_icon,
'POST_ICON_ALT' => $icon_alt_text,
'POST_SUBJECT' => $post_subject,
'S_UNREAD' => ($is_this_unread ? true : false),
'U_POST_LINK' => $post_link,
'REPLY_COUNT' => $post_replies_count,
'VIEW_COUNT' => $post_views,
'HAS_ATTACHMENTS' => $is_there_attachments,
'POST_TIME' => $post_time,
'POST_AUTHOR' => $poster_name,
'POSTER_AVATAR' => $poster_avatar,
'POSTER_PROFILE' => $poster_link,
'RANK_TITLE' => $user_rank_title,
'RANK_IMG' => $user_rank_image,
'MESSAGE' => $post_text,
'SIGNATURE' => (!empty($user_signature) ? $user_signature : ''),
'L_ATTACH_SHOWN' => ($allow_attach ? $user->lang['LN_ATTACH_DISPLAY'] : $user->lang['LN_ATTACH_NOT_DISPLAY']),
));
// Breadcrumbs
if(isset($post['breadcrumb_ids']))
{
foreach($post['breadcrumb_ids'] as $name => $id)
{
$template->assign_block_vars('postrow.nav_links', array(
'U_VIEW_FORUM' => append_sid($phpbb_root_path . 'viewforum.' . $phpEx, array('f' => $id)),
'FORUM_NAME' => $name,
));
}
}
if($is_there_attachments && $post['allow_attachments'])
{
foreach($post_attachment_filesize as &$filesize)
{
$filesize = get_formatted_filesize($filesize);
}
unset($filesize); // Breaking reference
for($j=key($post_attachments);$j<$num_of_attachments;$j++)
{
$template->assign_block_vars('postrow.attachments', array(
'NUM_ATTACHMENTS' => $num_of_attachments,
'URL_ATTACHMENT' => $post_attachments[$j],
'NAME_ATTACHMENT' => $post_attachment_names[$j],
'HAS_COMMENTS' => (!empty($post_attachment_comments[$j]) ? true : false),
'ATTACHMENT_COMMENT' => (!empty($post_attachment_comments[$j]) ? $post_attachment_comments[$j] : ''),
'DOWNLOAD_COUNT' => ( ($post_attachment_downloads[$j] > 0) ? $post_attachment_downloads[$j] : 0),
'FILESIZE' => $post_attachment_filesize[$j],
));
}
}
}
$template->assign_block_vars('navlinks', array(
'U_VIEW_FORUM' => append_sid($phpbb_root_path . $this_file . '.' . $phpEx),
'FORUM_NAME' => $user->lang['LN_FORUM_NEWS'],
));
// Output page
page_header($user->lang['LN_FORUM_NEWS']);
$template->set_filenames(array(
'body' => 'page_index.html')
);
page_footer();
exit;
/*
* Start Functions block
*/
/*
* Get the name of the file
*
* @param $info passed as __FILE__
* @return (string) the name of the file minus the file ext
*/
function get_this_filesname($info)
{
// Gets the name of this file
$this_file = pathinfo($info);
return substr($this_file['basename'], 0, strpos($this_file['basename'], '.'));
}
/*
* @param String $sort_order Has 12 options: (Default is recent_desc)
* Options:
1. 'recent_asc' Gives oldest to newest topics
2. 'recent_desc' Vice versa
3. 'active_asc' Gives the early replied to recently replied
4. 'active_desc' Vice versa
5. 'subject_asc' Gives it in alphabetical order
6. 'subject_desc' Vice versa
7. 'author_asc' Gives authors in alphabetical order
8. 'author_desc' Vice versa
9. 'views_asc' Gives the least views to most views
10. 'views_desc' Vice versa
11. 'replies_asc' Gives the least replies to the most replies
12. 'replies_desc' Vice versa
* @return String $sort_order_query The mysql coding to be used in the get_news function
*/
function sort_order_query($sort_order)
{
// switches for sort_order
switch ($sort_order)
{
case 'recent_asc':
$sort_order_query = 't.topic_time ASC';
break;
case 'recent_desc':
$sort_order_query = 't.topic_time DESC';
break;
case 'active_asc':
$sort_order_query = 't.topic_last_post_id ASC';
break;
case 'active_desc':
$sort_order_query = 't.topic_last_post_id DESC';
break;
case 'subject_asc':
$sort_order_query = 't.topic_title ASC';
break;
case 'subject_desc':
$sort_order_query = 't.topic_title DESC';
break;
case 'author_asc':
$sort_order_query = 't.topic_last_poster_name ASC';
break;
case 'author_desc':
$sort_order_query = 't.topic_last_poster_name DESC';
break;
case 'views_asc':
$sort_order_query = 't.topic_views ASC';
break;
case 'views_desc':
$sort_order_query = 't.topic_views DESC';
break;
case 'replies_asc':
$sort_order_query = 't.topic_replies_real ASC';
break;
case 'replies_desc':
$sort_order_query = 't.topic_replies_real DESC';
break;
default:
$sort_order_query = 't.topic_time DESC';
}
return($sort_order_query);
}
/** VERSION 4.09
* Retrieve the first post of each topic in a given forum
*
* @param Array $forum_ids An array containing all the forum ids of the forums that must be included
* @param Array $parent_only_ids An array containg the forum ids that will only give you the topics inside that forum, and not any children. It is used to mix up with $forum_ids. However if $include_children is false, this will do nothing. If you do not want to use it, declare false on it when calling the function
* @param Integer $limit The maximum number of topics to be returned
* @param Integer $offset Set this variable if you don't want the result set begin on the first entry
* @param Boolean $include_children This variable specifies whether we should include the "child forums" of the given $forum_ids in the results
* @param String $sort_order It is mysql coding of the query order. This is given by the sort_order_query function (Default is t.topic_time DESC)
* @param Boolean $allow_attachments (Default is true) Displays attachments (NOT INLINE IT WILL SHOW ALL ATTACHMENTS BUT INLINE WILL NOT BE PROCESSED)
* @param Boolean $allow_ranks (Default is true) Display ranks
* @param Boolean $allow_sigs (Default is true) Display signatures
* @param Boolean $allow_avatar (Default is true) Display avatars
* @return Array $posts An array holding all the posts and their data
*
* NOTES: If you want forum posts + children (subforum) posts. Check include_children as true and check false for $parent_only_ids.
* If you want forum posts + children (subforum) posts + forum posts not including children posts. Check include_children as true, and input values for $forum_ids and $parent_only_ids
* If you only want forum posts, DO NOT check $forum_ids as false and use $parent_only_ids. You must check $include_children as false, and simply input values for $forum_ids, and check $parent_only_ids as false.
* Remember that $parent_only_ids only work when $forum_ids are working regardless of $include_children. So $forum_ids is always the first one you have to use.
* The function will not output topics which are not approved.
*/
function get_news($forum_ids = array(), $parent_only_ids = array(), $limit = 10, $offset = 0, $include_children = false, $sort_order = 't.topic_time DESC', $allow_attachments = true, $allow_ranks = true, $allow_sigs = true, $allow_avatar = true)
{
global $db, $phpbb_root_path, $phpEx;
if (!is_array($forum_ids))
{
$forum_ids = array($forum_ids);
}
if (!is_array($parent_only_ids))
{
$parent_only_ids = array($parent_only_ids);
}
// If required merge the children into the $forum_ids
if ($include_children)
{
// This can get very heavy when specifing a big array $forum_ids
$child_forums = array();
foreach ($forum_ids as $parent)
{
$children = get_forum_branch($parent, 'children');
foreach ($children as $child)
{
$child_forums[] = $child['forum_id'];
}
}
// Merge
$forum_ids = array_merge($forum_ids, $child_forums, $parent_only_ids);
}
// Remove duplicates
$forum_ids = array_unique($forum_ids);
$post_query = 'p.post_id, p.post_time, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.post_attachment, t.topic_id, t.forum_id, t.topic_title, t.topic_status, t.poll_start, t.topic_views, t.topic_replies_real, t.topic_type, t.topic_last_poster_name, t.topic_last_post_id, t.topic_last_post_time, u.user_id, u.user_colour';
if($allow_ranks)
{
$post_query .= ',u.user_rank, u.user_posts';
}
if($allow_sigs)
{
$post_query .= ',u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield';
}
if($allow_avatar)
{
$post_query .= ',u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height';
}
// Now select the post data
$post_sql_ary = array(
'SELECT' => $post_query,
'FROM' => array(
POSTS_TABLE => 'p',
TOPICS_TABLE => 't',
),
'LEFT_JOIN' => array(
array(
'FROM' => array(USERS_TABLE => 'u'),
'ON' => 'u.user_id = p.poster_id',
),
),
'WHERE' => '(' . $db->sql_in_set('t.forum_id', $forum_ids) . ' AND p.post_id = t.topic_last_post_id AND t.topic_approved = 1)',
'ORDER_BY' => 't.topic_type DESC,' . $sort_order, #DELETE t.topic_type DESC if you do not want to preserve announcements and stickies.
);
$sql = $db->sql_build_query('SELECT', $post_sql_ary);
$result = $db->sql_query_limit($sql, $limit, $offset);
// Set an array with the posts
$posts = array();
while ($post = $db->sql_fetchrow($result))
{
// Getting the Attachments
if($allow_attachments && $post['post_attachment'])
{
// unset($attachment_urls, $attachment_ids, $attachment_names,$attachment_downloads, $attachment_comments, $attachment_filesize, $num_of_attachment_ids);
$attachments_sql_ary = array(
'SELECT' => 'a.attach_id, a.real_filename, a.download_count, a.attach_comment, a.filesize',
'FROM' => array(
ATTACHMENTS_TABLE => 'a',
),
'WHERE' => '(a.post_msg_id = ' . $post['post_id'] . ' AND a.in_message = 0)',
'ORDER_BY' => 'a.attach_id DESC',
);
$attachments_sql = $db->sql_build_query('SELECT', $attachments_sql_ary);
$attachments_result = $db->sql_query($attachments_sql);
$attachment_urls = $attachment_ids = $attachment_names = array();
$attachment_downloads = $attachment_comments = $attachment_filesize = array();
while ($row = $db->sql_fetchrow($attachments_result))
{
$attachment_ids[] = $row['attach_id'];
$attachment_names[] = $row['real_filename'];
$attachment_downloads[] = $row['download_count'];
$attachment_comments[] = $row['attach_comment'];
$attachment_filesize[] = $row['filesize'];
}
$db->sql_freeresult($attachments_result);
$num_of_attachment_ids = count($attachment_ids);
for($i=key($attachment_ids);$i<$num_of_attachment_ids;$i++)
{
$attachment_urls[$i] = $phpbb_root_path . 'download/file.' . $phpEx . '?id=' . $attachment_ids[$i];
}
}
// Getting the Breadcrumbs
unset($breadcrumb_ids);
if($post['forum_id'] > 0)
{
$breadcrumb_ids_sql_ary = array(
'SELECT' => 'f.forum_id, f.forum_name',
'FROM' => array(
FORUMS_TABLE => 'f',
),
'WHERE' => '(f.left_id <= (SELECT left_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $post['forum_id'] . ') AND f.right_id >= (SELECT right_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $post['forum_id'] . '))',
);
$bread_crumb_ids_sql = $db->sql_build_query('SELECT', $breadcrumb_ids_sql_ary);
$bread_crumb_ids_result = $db->sql_query($bread_crumb_ids_sql);
while ($row = $db->sql_fetchrow($bread_crumb_ids_result))
{
$breadcrumb_ids[$row['forum_name']] = $row['forum_id'];
}
$db->sql_freeresult($bread_crumb_ids_result);
}
$posts[] = array(
// FOR POSTS
'forum_id' => $post['forum_id'],
'post_id' => $post['post_id'],
'post_time' => $post['post_time'],
'post_text' => $post['post_text'],
// PARSING
'bbcode_bitfield' => $post['bbcode_bitfield'],
'bbcode_uid' => $post['bbcode_uid'],
'enable_bbcode' => $post['enable_bbcode'],
'enable_smilies' => $post['enable_smilies'],
'enable_magic_url' => $post['enable_magic_url'],
// TOPIC DETAILS
'topic_id' => $post['topic_id'],
'topic_title' => $post['topic_title'],
'topic_views' => $post['topic_views'],
'topic_replies_real' => $post['topic_replies_real'],
'topic_type' => $post['topic_type'],
'topic_last_post_id' => $post['topic_last_post_id'],
'topic_last_post_time' => $post['topic_last_post_time'],
'topic_status' => $post['topic_status'],
// POLL
'poll_start' => $post['poll_start'],
// ATTACHMENTS
'allow_attachments' => $allow_attachments,
'is_there_attachments' => $post['post_attachment'],
'attachments' => (isset($attachment_urls) ? $attachment_urls : array() ),
'attachment_names' => (isset($attachment_names) ? $attachment_names : array() ),
'attachment_downloads' => (isset($attachment_downloads) ? $attachment_downloads : array() ),
'attachment_comments' => (isset($attachment_comments) ? $attachment_comments : array() ),
'attachment_filesize' => (isset($attachment_filesize) ? $attachment_filesize : array() ),
'num_of_attachments' => (isset($num_of_attachment_ids) ? $num_of_attachment_ids : 0 ),
// BREADCRUMBS
'breadcrumb_ids' => $breadcrumb_ids,
// FOR USER
'user_id' => $post['user_id'],
'topic_last_poster_name' => $post['topic_last_poster_name'],
'user_colour' => $post['user_colour'],
// AVATAR
'allow_avatar' => $allow_avatar,
'user_avatar' => ( ($allow_avatar == true) ? $post['user_avatar'] : ''),
'user_avatar_type' => ( ($allow_avatar == true) ? $post['user_avatar_type'] : ''),
'user_avatar_width' => ( ($allow_avatar == true) ? $post['user_avatar_width'] : 0),
'user_avatar_height' => ( ($allow_avatar == true) ? $post['user_avatar_height'] : 0),
// RANKS
'allow_ranks' => $allow_ranks,
'user_rank_id' => ( ($allow_ranks == true) ? $post['user_rank'] : -1),
'user_posts' => ( ($allow_ranks == true) ? $post['user_posts'] : 0),
// SIGNATURES
'allow_sigs' => $allow_sigs,
'user_sig' => ( ($allow_sigs == true) ? $post['user_sig'] : ''),
'user_sig_bbcode_uid' => ( ($allow_sigs == true) ? $post['user_sig_bbcode_uid'] : ''),
'user_sig_bbcode_bitfield' => ( ($allow_sigs == true) ? $post['user_sig_bbcode_bitfield'] : ''),
);
}
$db->sql_freeresult($result);
// Return it
return $posts;
}
?>
You can see that I am ''merging'' the template version of the 'Show forum threads as news articles' MOD and the 'Top Five' MOD using this line:
Code: Select all
//-- mod: top five ---------------------------------------------------------//
include($phpbb_root_path . 'includes/top_five.' . $phpEx);
//-- end: top five ---------------------------------------------------------//
top_five.php:
Code: Select all
<?php
/**
*
* @package phpBB3
* @version $Id:
* @copyright (c) 2010 Rich McGirr
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Include only once.
*/
if (!defined('INCLUDES_TOP_FIVE_PHP'))
{
define('INCLUDES_TOP_FIVE_PHP', true);
global $auth, $cache, $user, $db, $phpbb_root_path, $phpEx, $template;
$user->add_lang('mods/top_five');
$excluded_forums = array('561', '560', '442', '569', '585', '586', '604', '614', '615', '617');
// we have auths, change the sql query below
$sql_and = (sizeof($excluded_forums)) ? ' AND ' . $db->sql_in_set('t.forum_id', $excluded_forums, true) : '';
// grab all posts that meet criteria and auths
$sql_ary = array(
'SELECT' => 'u.user_id, u.username, u.user_colour, t.topic_title, t.forum_id, t.topic_last_post_id, t.topic_last_post_time, t.topic_last_poster_name',
'FROM' => array(TOPICS_TABLE => 't'),
'LEFT_JOIN' => array(
array(
'FROM' => array(USERS_TABLE => 'u'),
'ON' => 't.topic_last_poster_id = u.user_id',
),
),
'WHERE' => 't.topic_approved = 1 AND t.topic_status <> ' . ITEM_MOVED . ' ' . $sql_and,
'ORDER_BY' => 't.topic_last_post_time DESC',
);
$result = $db->sql_query_limit($db->sql_build_query('SELECT', $sql_ary), 41);
$is_row = false;
while( $row = $db->sql_fetchrow($result) )
{
$is_row = true;
$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id']);
$topic_title = censor_text($row['topic_title']);
$is_guest = $row['user_id'] != ANONYMOUS ? false : true;
$template->assign_block_vars('top_five_topic',array(
'U_TOPIC' => $view_topic_url,
'USERNAME_FULL' => $is_guest ? $user->lang['BY'] . ' ' . get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $row['topic_last_poster_name']) : $user->lang['BY'] . ' ' . get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
'LAST_TOPIC_TIME' => $user->format_date($row['topic_last_post_time']),
'TOPIC_TITLE' => $user->lang['IN'] . ' ' . $topic_title));
}
$db->sql_freeresult($result);
// if user doesn't have permission to read any forums, show a message
if (!$is_row)
{
$template->assign_block_vars('top_five_topic', array(
'NO_TOPIC_TITLE' => $user->lang['NO_TOPIC_EXIST'],
));
}
// top five posters
// an array of user types we dont' bother with
// could add board founder (USER_FOUNDER) if wanted
$ignore_users = array(USER_IGNORE, USER_INACTIVE);
if (($user_posts = $cache->get('_top_five_posters')) === false)
{
$user_posts = array();
// grab users with most posts
$sql = 'SELECT user_id, username, user_colour, user_posts
FROM ' . USERS_TABLE . '
WHERE ' . $db->sql_in_set('user_type', $ignore_users, true) . '
AND user_posts <> 0
ORDER BY user_posts DESC';
$result = $db->sql_query_limit($sql, 5);
while ($row = $db->sql_fetchrow($result))
{
$user_posts[$row['user_id']] = array(
'user_id' => $row['user_id'],
'username' => $row['username'],
'user_colour' => $row['user_colour'],
'user_posts' => $row['user_posts'],
);
}
$db->sql_freeresult($result);
// cache this data for five minutes, this improves performance
$cache->put('_top_five_posters', $user_posts, 300);
}
foreach ($user_posts as $row)
{
$username_string = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
$template->assign_block_vars('top_five_active',array(
'S_SEARCH_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $row['user_id'] . '&sr=posts'),
'POSTS' => $row['user_posts'],
'USERNAME_FULL' => $username_string)
);
}
// newest registered users
if (($newest_users = $cache->get('_top_five_newest_users')) === false)
{
$newest_users = array();
// grab most recent registered users
$sql = 'SELECT user_id, username, user_colour, user_regdate
FROM ' . USERS_TABLE . '
WHERE ' . $db->sql_in_set('user_type', $ignore_users, true) . '
AND user_inactive_reason = 0
ORDER BY user_regdate DESC';
$result = $db->sql_query_limit($sql, 5);
while ($row = $db->sql_fetchrow($result))
{
$newest_users[$row['user_id']] = array(
'user_id' => $row['user_id'],
'username' => $row['username'],
'user_colour' => $row['user_colour'],
'user_regdate' => $row['user_regdate'],
);
}
$db->sql_freeresult($result);
// cache this data for ever, cache is purged when adding or deleting users
$cache->put('_top_five_newest_users', $newest_users);
}
foreach ($newest_users as $row)
{
$username_string = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
$template->assign_block_vars('top_five_newest',array(
'REG_DATE' => $user->format_date($row['user_regdate']),
'USERNAME_FULL' => $username_string)
);
}
}
?>
Would it be possible to get some help achieving this?
Again thank you for this great MOD!