[分享] [Hack]Top Topics on index 1.0.0 for plus 153

phpBB Plus Support
本區是討論關於 phpBB 2 plus 使用上的問題討論!
(發表文章請按照公告格式發表,違者砍文)

版主: 版主管理群

主題已鎖定
hanson.hung
星球公民
星球公民
文章: 48
註冊時間: 2006-05-07 16:15

[分享] [Hack]Top Topics on index 1.0.0 for plus 153

文章 hanson.hung »

########################################################
## Mod Title: The last Five and the Five popular (answers/views) on index.php for plus 1.53
## Mod Version: 1.1.0 for plus 1.53
## Author: Andrey Politov aka Sergeant < andypolv@mail.ru >
## Hack Updated to phpBB 2.0.11 Compatibility by: Thoul <thoul@users.sourceforge.net>
## Hack Updated based on code created by FB-ke
## Description: Adds small table (3 columns) on the top of the forum index
## with 5 last posts, 5 popular (with maximum answers) and 5
## popular (with maximum views). It helps to provide easy access
## to the last topics and keep on the top interesting topics.
##
## Installation Level: Easy
## Installation Time: 5 Minutes
## Files To Edit: 3 (4 if you have Russian language installed)
## index.php
## templates/subSilver/index_body.tpl
## language/lang_english/lang_main.php
## language/lang_russian/lang_main.php
##
## Included Files: none
##
########################################################
##
## Before Adding This hack To Your Forum,
## You Should Back Up All Files Related To This hack
##
########################################################
##
## Installation Notes:
##
## Follow the steps below.
##
########################################################


#
#-----[ OPEN ]------------------------------------------
#
portal.php
#
#-----[ FIND ]------------------------------------------
#
//
// Start Top Posters hack
if ( $CFG['number_top_posters'] > 0 )
#
#-----[ BEFORE, ADD ]------------------------------------------
#

//------------------------------------------------------------------------
// Top Topics on Index 1.1.0 - Begin Code Addition
//
$template->assign_vars(array(
'L_TOPICSRECENT' => $lang['TopicsRecent'],
'L_TOPICSPOPULAR' => $lang['TopicsPopular'],
'L_TOPICSPOPULARVIEW' => $lang['TopicsPopularView'])
);

// Get forum auth information to insure privacy of hidden topics
$topics_auth = auth(AUTH_ALL, AUTH_LIST_ALL, $userdata);
$topics_auth_sql = '';
foreach($topics_auth as $k=>$v)
{
if( $v['auth_view'] && $v['auth_read'] )
{
$topics_auth_sql .= (( empty($topics_auth_sql) ) ? '': ', ') . $k;
}
}

if( empty($topics_auth_sql) )
{
$template->assign_block_vars('topicrecentpopular', array(
'TOPICSPOPULAR' => $lang['No_Posts'],
'TOPICSPOPULARVIEW' => $lang['No_Posts'],
'TOPICSRECENT' => $lang['No_Posts']
));
}
else
{
//
// Okay, let's build the topic recent and popular
//
$active_topics_sql = 'SELECT t.topic_id, t.topic_title, t.topic_replies, t.topic_views, t.topic_last_post_id
FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE. ' f
WHERE t.forum_id IN (' . $topics_auth_sql . ')
AND f.forum_id = t.forum_id
ORDER BY %1$s DESC
LIMIT 0,5';
$active_topics_sql_a = sprintf($active_topics_sql, 'topic_last_post_id');
$active_topics_sql_b = sprintf($active_topics_sql, 'topic_replies');
$active_topics_sql_c = sprintf($active_topics_sql, 'topic_views');
$recent_row = $popular_row = $viewed_row = array();

if( !$active_topics_a = $db->sql_query($active_topics_sql_a))
{
message_die(GENERAL_ERROR, 'Could not retrieve recent topics', '', __LINE__, __FILE__, $active_topics_sql_a);
}
$recent_row = $db->sql_fetchrowset($active_topics_a);
$db->sql_freeresult($active_topics_a);

if( !$active_topics_b = $db->sql_query($active_topics_sql_b))
{
message_die(GENERAL_ERROR, 'Could not retrieve popular topics', '', __LINE__, __FILE__, $active_topics_sql_b);
}
$popular_row = $db->sql_fetchrowset($active_topics_b);
$db->sql_freeresult($active_topics_b);

if( !$active_topics_c = $db->sql_query($active_topics_sql_c))
{
message_die(GENERAL_ERROR, 'Could not retrieve most viewed topics', '', __LINE__, __FILE__, $active_topics_sql_c);
}
$viewed_row = $db->sql_fetchrowset($active_topics_c);
$db->sql_freeresult($active_topics_c);

for( $i = 0; $i < 5; $i++ )
{
$recent_topic_title = $recent_row[$i]['topic_title'];
$popular_topic_title = $popular_row[$i]['topic_title'];
$viewed_topic_title = $viewed_row[$i]['topic_title'];

if( strlen($recent_topic_title) > 40 )
{
$recent_topic_title = substr($recent_topic_title, 0, 40) . '...';
}

if( strlen($popular_topic_title) > 40 )
{
$popular_topic_title = substr($popular_topic_title, 0, 40) . '...';
}

if( strlen($viewed_topic_title) > 40 )
{
$viewed_topic_title = substr($viewed_topic_title, 0, 40) . '...';
}

$recent_post = '<a href="viewtopic.php?' . POST_TOPIC_URL . '=' . $recent_row[$i]['topic_id'] . '" title="' . $recent_row[$i]['topic_title'] . '">' . $recent_topic_title . '</a>';
$popular_post = '<a href="viewtopic.php?' . POST_TOPIC_URL . '=' . $popular_row[$i]['topic_id'] . '" title="' . $popular_row[$i]['topic_title'] . '">' . $popular_topic_title . '</a>';
$popular_total_replies = $popular_row[$i]['topic_replies'];
$viewed_post = '<a href="viewtopic.php?' . POST_TOPIC_URL . '=' . $viewed_row[$i]['topic_id'] . '" title="' . $viewed_row[$i]['topic_title'] . '">' . $viewed_topic_title . '</a>';
$viewed_total_replies = $viewed_row[$i]['topic_views'];

$template->assign_block_vars('topicrecentpopular', array(
'TOPICSPOPULAR' => $popular_post,
'TOPICSPOPULARC' => $popular_total_replies,
'TOPICSPOPULARVIEW' => $viewed_post,
'TOPICSPOPULARVIEWC' => $viewed_total_replies,
'TOPICSRECENT' => $recent_post)
);
}
}
//
// Top Topics on Index 1.1.0 - End Code Addition
//------------------------------------------------------------------------
#
#-----[ OPEN ]------------------------------------------
#
templates/fisubsilversh/portal_body.tpl
#
#-----[ FIND ]------------------------------------------
#
<!-- END welcome_text -->
#
#-----[ AFTER, ADD ]------------------------------------------
#
<!-- Top Topics on Index 1.1.0 - Begin Code Addition -->
<table width="100%" cellpadding="2" cellspacing="1" border="0" class="forumline">
<tr>
<th width="25%" class="thTop" nowrap="nowrap">&nbsp;{L_TOPICSRECENT}&nbsp;</th>
<th width="38%" colspan="2" class="thTop" nowrap="nowrap">&nbsp;{L_TOPICSPOPULAR}&nbsp;</th>
<th width="37%" colspan="2" class="thTop" nowrap="nowrap">&nbsp;{L_TOPICSPOPULARVIEW}&nbsp;</th>
</tr>
<!-- BEGIN topicrecentpopular -->
<tr>
<td width="29%" class="row2" align="left" valign="middle"><span class="gensmall">{topicrecentpopular.TOPICSRECENT}</span></td>
<td width="31%" class="row2" align="left" valign="middle"><span class="gensmall">{topicrecentpopular.TOPICSPOPULAR}</span></td>
<td width="6%" class="row2" align="center" valign="middle"><span class="gensmall">{topicrecentpopular.TOPICSPOPULARC}</span></td>
<td width="29%" class="row2" align="left" valign="middle"><span class="gensmall">{topicrecentpopular.TOPICSPOPULARVIEW}</span></td>
<td width="6%" class="row2" align="center" valign="middle"><span class="gensmall">{topicrecentpopular.TOPICSPOPULARVIEWC}</span></td>
</tr>
<!-- END topicrecentpopular -->
</table>
<!-- Top Topics on Index 1.1.0 - End Code Addition -->
<table border="0" cellpadding="0" cellspacing="0" class="tbl"><tr><td class="tbll"><img src="images/spacer.gif" alt="" width="8" height="4" /></td><td class="tblbot"><img src="images/spacer.gif" alt="" width="8" height="4" /></td><td class="tblr"><img src="images/spacer.gif" alt="" width="8" height="4" /></td></tr></table>
<br />
#
#-----[ OPEN ]------------------------------------------
#
language/lang_english/lang_main.php
#
#-----[ FIND ]------------------------------------------
#
//
// That's all, Folks!
// -------------------------------------------------
#
#-----[ BEFORE, ADD ]------------------------------------------
#
//------------------------------------------------------------------------
// Top Topics on Index 1.1.0 - Begin Code Addition
//
$lang['TopicsRecent'] = "最新文章";
$lang['TopicsPopular'] = "最多討論文章";
$lang['TopicsPopularView'] = "最多觀看文章";
//
// Top Topics on Index 1.1.0 - End Code Addition
//------------------------------------------------------------------------
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# End
bibo8045
星球公民
星球公民
文章: 83
註冊時間: 2005-03-06 18:34

文章 bibo8045 »

非常感謝hanson.hung 大大..
小弟先安裝上去,有問題再請教研討!
先行提出一個問題,"最新文章"能否僅針對某個分區或是特定幾個分區做統計呢?
hanson.hung
星球公民
星球公民
文章: 48
註冊時間: 2006-05-07 16:15

文章 hanson.hung »

Hi bibo8045,
想請教您僅針對某個分區或是特定幾個分區做統計的用意或目的是為了什麼呢!?
:-D
bibo8045
星球公民
星球公民
文章: 83
註冊時間: 2005-03-06 18:34

文章 bibo8045 »

哈囉 hanson.hung
因為有些分區不重要,例如測試貼圖區,或是抱怨區..等等不是很有用!
而有些分區是屬於開站的研討主題,所以只要顯示該區的最新文章即可...

用意大概是這樣子~~有辦法限制嗎?
hanson.hung
星球公民
星球公民
文章: 48
註冊時間: 2006-05-07 16:15

文章 hanson.hung »

Hi bibo8045,
我大概了解您的需求, 但由於小弟php的功力沒那麼強,
所以....................讓您失望了....... :oops:

如果要達到您的需求, 可能要先寫個後台管理程式, 讓每個討論版都可選擇是否顯示最近文章在首頁, 如此才能排除您覺得不重要的討論版, 或許程式碼可參考hentaibbc大大的『主題類型 4.0.0』MOD的程式碼.
bibo8045
星球公民
星球公民
文章: 83
註冊時間: 2005-03-06 18:34

文章 bibo8045 »

嗨 hanson.hung
別這麼說哩~您這樣說功力不強那我們這些人阿不就都準備躲起來了..
只希望板上其他大大們願意提供些意見心得,嘗試修改讓小弟達成願望..
阿彌陀佛..
主題已鎖定

回到「phpBB 2 plus 綜合討論」