代碼: 選擇全部
##############################################################
## 外掛名稱: Better Toplist (改良的最多列表)
## 外掛作者: wang5555 < wang55.wang55@msa.hinet.net > (心靈捕手) http://220.134.232.37/
## 外掛描述: 這個外掛, 將論壇內最後發表, 最多回覆, 以及最多觀看的主題 (最後發表者), 在首頁列表.
##
## 外掛版本: 1.0.0
##
## 安裝難度: 簡單
## 安裝時間: < 5 Minutes
## 需要編輯的檔案: 2
## index.php
## templates/subSilver/index_body.tpl
## 附加檔案: 無
## 版權聲明: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
##############################################################
## 由於安全上的考量, 請檢查: http://phpbb-tw.net/phpbb/index.php
## 是否有此外掛的最新版本.
################################################################
## 作者留言:
##
## 1. 此外掛中心思想, 乃參考 Top5 Topics 2.1.0, 特此銘謝
## 該外掛參考連結: http://phpbb-tw.net/phpbb/viewtopic.php?t=5044
##
## 2. 此外掛乃參考 Integrated Toplist 撰寫, 特此銘謝
## 該外掛參考連結: http://phpbb-tw.net/phpbb/viewtopic.php?t=31959
##
## 3. 此外掛為了有效降低資料庫查詢的次數, 以及濃縮 index_body.tpl 版面
## 因此 /* 省略 主題發表人 查詢 */, 以及註解 // 版面名稱, 回覆, 發表人, 觀看
##
## 4. 此外掛在 phpBB 2.0.22 (utf-8) 安裝, 測試無誤
##
################################################################
## 外掛歷史:
##
## 2007-04-01 - Version 1.0.0
## - 首次發表
##
##############################################################
## 新增外掛前, 請先備份相關檔案.
##############################################################
#
#-----[ OPEN ]------------------------------------------
#
index.php
#
#-----[ FIND ]------------------------------------------
#
//
// Find which forums are visible for this user
//
$is_auth_ary = array();
$is_auth_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata, $forum_data);
#
#-----[ AFTER, ADD ]------------------------------------------
#
//
// + Better Toplist =====
//
//
// Option of Toplist Start
//
// 主題字數長度
$MAX_STR_LEN = 20;
// 主題列表數目
$MAX_TOPICS = 5;
// 0 => users can see all topics including authorized issue(but they cant read the posts)
// 1 => users can see only authorized topics
$AUTH_SECRUITY = 1;
// 主題排序依據
$sortby = 'topic_last_post_id';
$sortby2 = 'topic_replies';
$sortby3 = 'topic_views';
//
// Option of Toplist End
//
function cutStr($str) {
global $MAX_STR_LEN;
$str = (mb_strlen($str, 'utf-8') > $MAX_STR_LEN) ? (mb_substr($str, 0, $MAX_STR_LEN - 3, 'utf-8') . "...") : $str;// UTF-8
return $str;
}
// Find which forums are visible for this user
$is_auth_ary_top5 = array();
$is_auth_ary_top5 = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
$auth_forum_ary_top5 = array();
// Get forum info
$sql = "SELECT forum_id FROM " . FORUMS_TABLE;
if( !$q_forums = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Toplist ERROR: Fetch forum info fail', __LINE__, __FILE__, $sql);
}
// Authorized forums info
while( $forum_row = $db->sql_fetchrow($q_forums) )
{
$forum_id1 = $forum_row['forum_id'];
if( $is_auth_ary_top5[$forum_id1]['auth_read'] == 1)
{
if(function_exists("array_push"))
{
array_push($auth_forum_ary_top5, $forum_id1);
} else {
$auth_id=count($auth_forum_ary_top5);
$auth_forum_ary_top5[$auth_id]=$forum_id1;
}
}
}
if( sizeOf($auth_forum_ary_top5) == 0 || !$AUTH_SECRUITY )
{
$auth_forums_top5 = "";
}
else
{
$auth_forums_top5 = 'AND f.forum_id IN(';
if(sizeOf($auth_forum_ary_top5) > 1)
{
$auth_forums_top5 .= implode (',', $auth_forum_ary_top5);
}
else
{
$auth_forums_top5 .= $auth_forum_ary_top5[0];
}
$auth_forums_top5 .= ')';
}
// 最後發表
// query
$sql = "SELECT t.topic_id, t.topic_title, t.topic_poster, t.topic_views, t.topic_replies, t.topic_last_post_id, f.forum_id, f.forum_name
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
WHERE t.forum_id = f.forum_id
AND topic_moved_id = '0'
$auth_forums_top5
ORDER BY $sortby DESC LIMIT 0, $MAX_TOPICS";
if( !$result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Toplist ERROR: Fetch topic info fail', __LINE__, __FILE__, $sql);
}
// fetch rows
while( $rows = $db->sql_fetchrow($result) )
{
$topic_url = append_sid("viewtopic.$phpEx?t=" . $rows['topic_id']);
$forum_url = append_sid("viewforum.$phpEx?f=" . $rows['forum_id']);
$topic_poster = $rows['topic_poster'];
$topic_last_post_id = $rows['topic_last_post_id'];
// Grab topic poster and last replier data
/*
$sql = "SELECT post_username, user_id, username
FROM " . POSTS_TABLE . ", " . USERS_TABLE . "
WHERE topic_id = '" . $rows['topic_id'] . "'
AND poster_id = user_id
ORDER BY post_id LIMIT 0, 1";
if( !$p_result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Toplist ERROR: Fetch topic poster fail', __LINE__, __FILE__, $sql);
}
$p_row = $db->sql_fetchrow($p_result);
$poster_name = ( $topic_poster != ANONYMOUS ) ? $p_row['username'] : ( !$p_row['post_username'] ? $lang['Guest'] : $p_row['post_username']);
$poster_url = ( $topic_poster != ANONYMOUS && !$p_row['post_username'] ) ? ('<a href="' . append_sid("profile.$phpEx?mode=viewprofile&u=$topic_poster") . '">' . "$poster_name</a>") : $poster_name;
*/
/* 省略 主題發表人 查詢 */
$sql = "SELECT post_username, user_id, username, post_time
FROM " . POSTS_TABLE . ", " . USERS_TABLE . "
WHERE post_id = '$topic_last_post_id'
AND poster_id = user_id";
if( !$r_result = $db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Toplist ERROR: Fetch topic last replier fail', __LINE__, __FILE__, $sql);
}
$r_row = $db->sql_fetchrow($r_result);
$replier_id = $r_row['user_id'];
$replier_name = ( $replier_id != ANONYMOUS ) ? $r_row['username'] : ( !$r_row['post_username'] ? $lang['Guest'] : $r_row['post_username']);
$replier_url = ( $replier_id != ANONYMOUS && !$r_row['post_username'] ) ? ('<a href="' . append_sid("profile.$phpEx?mode=viewprofile&u=$replier_id") . '">' . "$replier_name</a>") : $replier_name;
$last_post_url = append_sid("viewtopic.$phpEx?p=$topic_last_post_id#$topic_last_post_id");
$template->assign_block_vars("toprow", array(
//'FORUM_NAME' => $rows['forum_name'],
//'FORUM_URL' => $forum_url,
'TOPIC' => cutStr($rows['topic_title']),
'TOPIC_URL' => $topic_url,
//'TOPIC_VIEWS' => $rows['topic_views'],
//'TOPIC_REPLIES' => $rows['topic_replies'],
'POST_TIME' => create_date('Y-m-d', $r_row['post_time'], $board_config['board_timezone']),
//'POSTER_URL' => $poster_url,
'REPLIER_URL' => $replier_url,
'LAST_POST_URL' => $last_post_url
));
}
// 最多回覆
// query
$sql2 = "SELECT t.topic_id, t.topic_title, t.topic_poster, t.topic_views, t.topic_replies, t.topic_last_post_id, f.forum_id, f.forum_name
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
WHERE t.forum_id = f.forum_id
AND topic_moved_id = '0'
$auth_forums_top5
ORDER BY $sortby2 DESC LIMIT 0, $MAX_TOPICS";
if( !$result2 = $db->sql_query($sql2) )
{
message_die(GENERAL_ERROR, 'Toplist ERROR: Fetch topic info fail', __LINE__, __FILE__, $sql2);
}
// fetch rows
while( $rows2 = $db->sql_fetchrow($result2) )
{
$topic_url2 = append_sid("viewtopic.$phpEx?t=" . $rows2['topic_id']);
$forum_url2 = append_sid("viewforum.$phpEx?f=" . $rows2['forum_id']);
$topic_poster2 = $rows2['topic_poster'];
$topic_last_post_id2 = $rows2['topic_last_post_id'];
// Grab topic poster and last replier data
/*
$sql2 = "SELECT post_username, user_id, username
FROM " . POSTS_TABLE . ", " . USERS_TABLE . "
WHERE topic_id = '" . $rows2['topic_id'] . "'
AND poster_id = user_id
ORDER BY post_id LIMIT 0, 1";
if( !$p_result2 = $db->sql_query($sql2) )
{
message_die(GENERAL_ERROR, 'Toplist ERROR: Fetch topic poster fail', __LINE__, __FILE__, $sql2);
}
$p_row2 = $db->sql_fetchrow($p_result2);
$poster_name2 = ( $topic_poster2 != ANONYMOUS ) ? $p_row2['username'] : ( !$p_row2['post_username'] ? $lang['Guest'] : $p_row2['post_username']);
$poster_url2 = ( $topic_poster2 != ANONYMOUS && !$p_row2['post_username'] ) ? ('<a href="' . append_sid("profile.$phpEx?mode=viewprofile&u=$topic_poster") . '">' . "$poster_name2</a>") : $poster_name2;
*/
/* 省略 主題發表人 查詢 */
$sql2 = "SELECT post_username, user_id, username, post_time
FROM " . POSTS_TABLE . ", " . USERS_TABLE . "
WHERE post_id = '$topic_last_post_id2'
AND poster_id = user_id";
if( !$r_result2 = $db->sql_query($sql2) )
{
message_die(GENERAL_ERROR, 'Toplist ERROR: Fetch topic last replier fail', __LINE__, __FILE__, $sql2);
}
$r_row2 = $db->sql_fetchrow($r_result2);
$replier_id2 = $r_row2['user_id'];
$replier_name2 = ( $replier_id2 != ANONYMOUS ) ? $r_row2['username'] : ( !$r_row2['post_username'] ? $lang['Guest'] : $r_row2['post_username']);
$replier_url2 = ( $replier_id2 != ANONYMOUS && !$r_row2['post_username'] ) ? ('<a href="' . append_sid("profile.$phpEx?mode=viewprofile&u=$replier_id") . '">' . "$replier_name2</a>") : $replier_name2;
$last_post_url2 = append_sid("viewtopic.$phpEx?p=$topic_last_post_id2#$topic_last_post_id2");
$template->assign_block_vars("toprow_reply", array(
//'FORUM_NAME2' => $rows2['forum_name'],
//'FORUM_URL2' => $forum_url2,
'TOPIC' => cutStr($rows2['topic_title']),
'TOPIC_URL2' => $topic_url2,
//'TOPIC_VIEWS2' => $rows2['topic_views'],
//'TOPIC_REPLIES2' => $rows2['topic_replies'],
'POST_TIME2' => create_date('Y-m-d', $r_row2['post_time'], $board_config['board_timezone']),
//'POSTER_URL2' => $poster_url2,
'REPLIER_URL2' => $replier_url2,
'LAST_POST_URL2' => $last_post_url2
));
}
// 最多觀看
// query
$sql3 = "SELECT t.topic_id, t.topic_title, t.topic_poster, t.topic_views, t.topic_replies, t.topic_last_post_id, f.forum_id, f.forum_name
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
WHERE t.forum_id = f.forum_id
AND topic_moved_id = '0'
$auth_forums_top5
ORDER BY $sortby3 DESC LIMIT 0, $MAX_TOPICS";
if( !$result3 = $db->sql_query($sql3) )
{
message_die(GENERAL_ERROR, 'Toplist ERROR: Fetch topic info fail', __LINE__, __FILE__, $sql3);
}
// fetch rows
while( $rows3 = $db->sql_fetchrow($result3) )
{
$topic_url3 = append_sid("viewtopic.$phpEx?t=" . $rows3['topic_id']);
$forum_url3 = append_sid("viewforum.$phpEx?f=" . $rows3['forum_id']);
$topic_poster3 = $rows3['topic_poster'];
$topic_last_post_id3 = $rows3['topic_last_post_id'];
// Grab topic poster and last replier data
/*
$sql3 = "SELECT post_username, user_id, username
FROM " . POSTS_TABLE . ", " . USERS_TABLE . "
WHERE topic_id = '" . $rows3['topic_id'] . "'
AND poster_id = user_id
ORDER BY post_id LIMIT 0, 1";
if( !$p_result3 = $db->sql_query($sql3) )
{
message_die(GENERAL_ERROR, 'Toplist ERROR: Fetch topic poster fail', __LINE__, __FILE__, $sql3);
}
$p_row3 = $db->sql_fetchrow($p_result3);
$poster_name3 = ( $topic_poster3 != ANONYMOUS ) ? $p_row3['username'] : ( !$p_row3['post_username'] ? $lang['Guest'] : $p_row3['post_username']);
$poster_url3 = ( $topic_poster3 != ANONYMOUS && !$p_row3['post_username'] ) ? ('<a href="' . append_sid("profile.$phpEx?mode=viewprofile&u=$topic_poster") . '">' . "$poster_name3</a>") : $poster_name3;
*/
/* 省略 主題發表人 查詢 */
$sql3 = "SELECT post_username, user_id, username, post_time
FROM " . POSTS_TABLE . ", " . USERS_TABLE . "
WHERE post_id = '$topic_last_post_id3'
AND poster_id = user_id";
if( !$r_result3 = $db->sql_query($sql3) )
{
message_die(GENERAL_ERROR, 'Toplist ERROR: Fetch topic last replier fail', __LINE__, __FILE__, $sql3);
}
$r_row3 = $db->sql_fetchrow($r_result3);
$replier_id3 = $r_row3['user_id'];
$replier_name3 = ( $replier_id3 != ANONYMOUS ) ? $r_row3['username'] : ( !$r_row3['post_username'] ? $lang['Guest'] : $r_row3['post_username']);
$replier_url3 = ( $replier_id3 != ANONYMOUS && !$r_row3['post_username'] ) ? ('<a href="' . append_sid("profile.$phpEx?mode=viewprofile&u=$replier_id") . '">' . "$replier_name3</a>") : $replier_name3;
$last_post_url3 = append_sid("viewtopic.$phpEx?p=$topic_last_post_id3#$topic_last_post_id3");
$template->assign_block_vars("toprow_view", array(
//'FORUM_NAME3' => $rows3['forum_name'],
//'FORUM_URL3' => $forum_url3,
'TOPIC' => cutStr($rows3['topic_title']),
'TOPIC_URL3' => $topic_url3,
//'TOPIC_VIEWS3' => $rows3['topic_views'],
//'TOPIC_REPLIES3' => $rows3['topic_replies'],
'POST_TIME3' => create_date('Y-m-d', $r_row3['post_time'], $board_config['board_timezone']),
//'POSTER_URL3' => $poster_url3,
'REPLIER_URL3' => $replier_url3,
'LAST_POST_URL3' => $last_post_url3
));
}
//
// - Better Toplist =====
//
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/index_body.tpl
#
#-----[ FIND ]------------------------------------------
#
<table width="100%" cellpadding="1" cellspacing="1" border="0">
<tr>
<td align="left" valign="top"><span class="gensmall">{L_ONLINE_EXPLAIN}</span></td>
</tr>
</table>
#
#-----[ AFTER, ADD ]------------------------------------------
<table width="100%" border="0" cellpadding="0" cellspacing="0" width="100%" class="forumline">
<tr>
<td width="33%">
<table width="100%" height="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td class="catHead" height="25" colspan="2" nowrap="nowrap"><span class="cattitle" title="最後發表">最後發表</span></td>
</tr>
<tr>
<th align="center" class="thCornerL" width="70%"> {L_TOPICS} </th>
<th align="center" class="thCornerR" width="30%"> {L_LASTPOST} </th>
</tr>
<!-- BEGIN toprow -->
<tr height="30">
<td class="row1" nowrap><span class="topictitle"><a href="{toprow.TOPIC_URL}" target="_self" class="topictitle">{toprow.TOPIC}</a></span></td>
<td class="row2" align="center" nowrap><span class="postdetails">{toprow.POST_TIME}<br />{toprow.REPLIER_URL} <a href="{toprow.LAST_POST_URL}" target="_self"><img src="{ICON_URL}" border="0" alt="{ICON_ALT}" /></a></span></td>
</tr>
<!-- END toprow -->
<tr>
<td colspan="2" class="catBottom" align="center" valign="middle" height="25"> </td>
</tr>
</table>
</td>
<td width="34%">
<table width="100%" height="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td class="catHead" height="25" colspan="2" nowrap="nowrap"><span class="cattitle" title="最多回覆">最多回覆</span></td>
</tr>
<tr>
<th align="center" class="thCornerL" width="70%"> {L_TOPICS} </th>
<th align="center" class="thCornerR" width="30%"> {L_LASTPOST} </th>
</tr>
<!-- BEGIN toprow_reply -->
<tr height="30">
<td class="row1" nowrap><span class="topictitle"><a href="{toprow_reply.TOPIC_URL2}" target="_self" class="topictitle">{toprow_reply.TOPIC2}</a></span></td>
<td class="row2" align="center" nowrap><span class="postdetails">{toprow_reply.POST_TIME2}<br />{toprow_reply.REPLIER_URL2} <a href="{toprow_reply.LAST_POST_URL2}" target="_self"><img src="{ICON_URL}" border="0" alt="{ICON_ALT}" /></a></span></td>
</tr>
<!-- END toprow_reply -->
<tr>
<td colspan="2" class="catBottom" align="center" valign="middle" height="25"> </td>
</tr>
</table>
</td>
<td width="33%">
<table width="100%" height="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td class="catHead" height="25" colspan="2" nowrap="nowrap"><span class="cattitle" title="最多觀看">最多觀看</span></td>
</tr>
<tr>
<th align="center" class="thCornerL" width="70%"> {L_TOPICS} </th>
<th align="center" class="thCornerR" width="30%"> {L_LASTPOST} </th>
</tr>
<!-- BEGIN toprow_view -->
<tr height="30">
<td class="row1" nowrap><span class="topictitle"><a href="{toprow_view.TOPIC_URL3}" target="_self" class="topictitle">{toprow_view.TOPIC3}</a></span></td>
<td class="row2" align="center" nowrap><span class="postdetails">{toprow_view.POST_TIME3}<br />{toprow_view.REPLIER_URL3} <a href="{toprow_view.LAST_POST_URL3}" target="_self"><img src="{ICON_URL}" border="0" alt="{ICON_ALT}" /></a></span></td>
</tr>
<!-- END toprow_view -->
<tr>
<td colspan="2" class="catBottom" align="center" valign="middle" height="25"> </td>
</tr>
</table>
</td>
</tr>
</table>
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM