[修改]OOHOO前輩的adv_top5 MOD

phpBB 2 MOD Support
無論是官方或非官方認證之外掛,安裝與使用問題討論。
(發表文章請按照公告格式發表,違者砍文)

版主: 版主管理群

主題已鎖定
蕭遙
星球公民
星球公民
文章: 120
註冊時間: 2004-09-29 05:21

[修改]OOHOO前輩的adv_top5 MOD

文章 蕭遙 »

安裝了OOHOO的top5,確實相當方便。感謝前輩的辛勤勞動~

不過也發現有個地方不太適合我使用。就是最佳人氣和最多回復的地方,因它是將全部的帖子來排位計算最高人氣和回復,這樣就導致一些當時回復極多,但是已經有很長時間沒有新回復的帖子總是存在top5裏,無法切實反映近期的帖子走向。因此我就稍爲修改了一下,設定最佳人氣和最高回復的帖子從一周内開始計算,這樣可以描述近期内最受歡迎的帖子,對會員來説也會比較方便。^^

我是以最後回復的時間來判斷是否是一周内的帖子的,下面是修改方法:

代碼: 選擇全部


# OPEN adv_top5.php 打開 adv_top5.php
#
# FIND 尋找\r
#
// query
$sql = "SELECT topic_id, topic_title, topic_poster, topic_views, topic_replies, topic_last_post_id, f.forum_id, forum_name
	FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
	WHERE t.forum_id = f.forum_id
	AND topic_moved_id = '0'
	$auth_forums
	ORDER BY $sortby DESC LIMIT 0, $MAX_TOPICS";
#
# REPLACE WITH  替換為\r
#
// query

$date = time() - ( 7 * 86400 );

$sql = "SELECT t.topic_id, topic_title, topic_poster, topic_views, topic_replies, topic_last_post_id, f.forum_id, forum_name, p.post_time
	FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p
	WHERE t.forum_id = f.forum_id
	AND t.topic_last_post_id = p.post_id
	AND topic_moved_id = '0'
	AND p.post_time > $date
	$auth_forums
	ORDER BY $sortby DESC LIMIT 0, $MAX_TOPICS";
$date = time() - ( 7 * 86400 );
這行是設定排列幾天内的帖子,您也可設置為30 * 86400,也就是排列一個月内的帖子。

請各位多多指教^^
momoC
星球公民
星球公民
文章: 167
註冊時間: 2004-09-15 22:39
聯繫:

文章 momoC »

好主意,雖然我不是用 oohoo 的 top5,但也有同樣的困擾...

代碼: 選擇全部

最佳人氣和最高回復的帖子從一周内開始計算,這樣可以描述近期内最受歡迎的帖子,對會員來説也會比較方便。^^ 
  修改過之後,發現確實踢掉了一些比較老的留言,但只要本來已經回覆很多的帖子即使只被會員新增一筆回覆,比起其他小留言新增十筆,還是老留言會被登到最上面。所以不能算是真的秀出「近期內最受歡迎的帖子」,但還是很棒的點子哦~我已經在用了,感謝分享~
蕭遙
星球公民
星球公民
文章: 120
註冊時間: 2004-09-29 05:21

文章 蕭遙 »

那麽也可以如此修改,限制必須主題為一周内發表的,也就是對一個討論串的第一個帖子進行一下篩選。

只需如此改:

代碼: 選擇全部

#
#REPLACE WITH 替換為\r
#
// query 

$date = time() - ( 7 * 86400 ); 

$sql = "SELECT topic_id, topic_time, topic_title, topic_poster, topic_views, topic_replies, topic_last_post_id, f.forum_id, forum_name
   FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, 
   WHERE t.forum_id = f.forum_id
   AND topic_moved_id = '0' 
   AND t.topic_time > $date 
   $auth_forums 
   ORDER BY $sortby DESC LIMIT 0, $MAX_TOPICS"; 

更簡單了。不過如果老討論串發了新芽的話,也會被篩選掉儸……
頭像
心靈捕手
默默耕耘的老師
默默耕耘的老師
文章: 8510
註冊時間: 2004-04-30 01:54
來自: Taiwan

Re: [修改]OOHOO前輩的adv_top5 MOD

文章 心靈捕手 »

蕭遙 寫:安裝了OOHOO的top5,確實相當方便。感謝前輩的辛勤勞動~

不過也發現有個地方不太適合我使用。就是最佳人氣和最多回復的地方,因它是將全部的帖子來排位計算最高人氣和回復,這樣就導致一些當時回復極多,但是已經有很長時間沒有新回復的帖子總是存在top5裏,無法切實反映近期的帖子走向。因此我就稍爲修改了一下,設定最佳人氣和最高回復的帖子從一周内開始計算,這樣可以描述近期内最受歡迎的帖子,對會員來説也會比較方便。^^
Good Idea! (:Y)
施比受有福,祝福您好運! ^_^
歡迎光臨★★心靈捕手★★ :: 討論區
https://wang5555.dnsfor.me/phpBB3/
momoC
星球公民
星球公民
文章: 167
註冊時間: 2004-09-15 22:39
聯繫:

文章 momoC »

啊,原來可以這樣,帥。確實舊留言就被踢掉了,很難兩全吧....但還是很好用,謝謝囉~
最後由 momoC 於 2004-10-19 13:40 編輯,總共編輯了 1 次。
動機不明
喝咖啡的綠皮猴
喝咖啡的綠皮猴
文章: 1179
註冊時間: 2002-03-06 20:37
來自: GOP (重啟)

文章 動機不明 »

我也有一個想法,不知道 蕭遙大 可不可以做到... :D

目前的 top5 只是顯示在首頁,如果可以擺到 forum 版面內,那麼就可以各別顯示該區的 top5 了!

----
$sql = "SELECT ****
那一行底下加入 forum_id 的判斷應該就行了.... (不知道對不對?)
bu
版面管理員
版面管理員
文章: 443
註冊時間: 2003-02-23 12:46
來自: 25° 4′N 121° 29′E
聯繫:

文章 bu »

動機不明 寫:我也有一個想法,不知道 蕭遙大 可不可以做到... :D

目前的 top5 只是顯示在首頁,如果可以擺到 forum 版面內,那麼就可以各別顯示該區的 top5 了!

----
$sql = "SELECT ****
那一行底下加入 forum_id 的判斷應該就行了.... (不知道對不對?)
是可以做的出來的啊 ^^
也許等下就給他改出來 ^^
(用整合式 Top5 來改)
*譯文資料在phpBB 技術文件
bu.femto-size
*和我聯絡,請寄 or Google Talk 圖檔
*作品: Intergrated Toplist & Message Can
蕭遙
星球公民
星球公民
文章: 120
註冊時間: 2004-09-29 05:21

文章 蕭遙 »

嗯。剛才已經給它改出來了,是用bu兄的整合式TOP5改的,因要用到當前forumid這個變量,只能整合到viewforum裏面……\r

打開 viewforum.php ,在合適処加入:

代碼: 選擇全部


//
// Mod setting
//
// Topics text length
$MAX_STR_LEN = 60;
// Topics to display
$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;

function cutStr($str) {

	global $MAX_STR_LEN;

	$str = (strlen($str) > $MAX_STR_LEN) ? (substr($str, 0, $MAX_STR_LEN - 1) . "...") : $str;
	return $str;
}

// set template
$template->set_filenames(array("body" => "forum_top5_body.tpl"));

$template->assign_vars(array(
	"icon_url" => $images['icon_latest_reply'],
	"icon_alt" => $lang['View_latest_post'],
	"nav_links" => "$last_link  $hot_links  $top_links"
));

// query

$date = time() - ( 7 * 86400 );

$sql = "SELECT t.topic_id, topic_title, topic_poster, topic_views, topic_replies, topic_last_post_id, f.forum_id, forum_name, p.post_time
	FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p
	WHERE t.forum_id = f.forum_id
	AND t.forum_id = $forum_id
	AND t.topic_last_post_id = p.post_id
	AND topic_moved_id = '0'
	AND p.post_time > $date
	$auth_forums
	ORDER BY topic_views DESC LIMIT 0, $MAX_TOPICS";

if( !$result = $db->sql_query($sql) )
{
	echo '<p align="center"><font color="red"><b>ADV_TOPN_MOD TOPICS QUERY ERROR!!</b></font></p>';
	exit;
}

// 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_MESSAGE, 'TOP5 MOD TOPIC_POSTER QUERY ERROR!!');
	}

	$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") . '" target="_top">' . "$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_MESSAGE, 'TOP5 MOD LAST_REPLIER QUERY ERROR!!');
	}

	$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") . '" target="_top">' . "$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($board_config['default_dateformat'], $r_row['post_time'], $board_config['board_timezone']),
		"poster_url" => $poster_url,
		"replier_url" => $replier_url,
		"last_post_url" => $last_post_url
	));
}

$template->assign_vars(array( 
   'S_CONTENT_DIRECTION' => $lang['DIRECTION'], 
   'S_CONTENT_ENCODING' => $lang['ENCODING'], 

   'T_HEAD_STYLESHEET' => $theme['template_name'] . "/" . $theme['head_stylesheet'], 
   'T_BODY_BGCOLOR' => '#'.$theme['td_color3'], 

   'L_FORUM' => $lang['Forum'], 
   'L_TOPICS' => $lang['Topics'], 
   'L_REPLIES' => $lang['Replies'], 
   'L_AUTHOR' => $lang['Author'], 
   'L_VIEWS' => $lang['Views'], 
   'L_POSTS' => $lang['Posts'], 
   'L_LASTPOST' => $lang['Last_Post'] 
));
再打開 viewforum_body.tpl ,在合適処加入:

代碼: 選擇全部

<table width="100%" cellpadding="0" cellspacing="0" border="0" style="{background-color: white;}">
  <tr>
    <td valign="top">
      <table width="100%" border="0" cellpadding="4" cellspacing="1" class="forumline">
	<tr> 
	  <th align="center" class="thCornerL" width="20%"> {L_FORUM} </th>
	  <th align="center" class="thTop" width="40%"> {L_TOPICS} </th>
	  <th align="center" class="thTop" nowrap>  {L_AUTHOR}  </th>
	  <th align="center" class="thTop" nowrap> {L_REPLIES} </th>
	  <th align="center" class="thTop" nowrap> {L_VIEWS} </th>
	  <th align="center" class="thCornerR" nowrap> {L_LASTPOST} </th>
	</tr>
	<!-- BEGIN toprow -->
        <tr>
          <td class="row1" nowrap><span class="forumlink"><a href="{toprow.forum_url}" target="_top" class="forumlink">{toprow.forum_name}</a></span></td>       
          <td class="row2" nowrap><span class="topictitle"><a href="{toprow.topic_url}" target="_top" class="topictitle">{toprow.topic}</a></span></td>
          <td class="row1" align="center" nowrap><span class="name">{toprow.poster_url}</span></td>
          <td class="row2" align="center" nowrap><span class="postdetails">{toprow.topic_replies}</span></td>
          <td class="row1" align="center" nowrap><span class="postdetails">{toprow.topic_views}</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="_top"><img src="{icon_url}" border="0" alt="{icon_alt}" /></a></span></td>        
        </tr>
        <!-- END toprow -->
      </table>
    </td>  
  </tr>
</table>
即可。因在版面内顯示本版最新回復的top5無意義(最新回復的當然就浮在最上面了),因此就去掉了切換,我是直接顯示最高人氣的帖子了。如果需要顯示最高回復的帖子,就改這裡:

ORDER BY topic_views LIMIT 0, $MAX_TOPICS";

為\r

ORDER BY topic_replies DESC LIMIT 0, $MAX_TOPICS";
最後由 蕭遙 於 2004-10-19 23:55 編輯,總共編輯了 1 次。
bu
版面管理員
版面管理員
文章: 443
註冊時間: 2003-02-23 12:46
來自: 25° 4′N 121° 29′E
聯繫:

文章 bu »

果然,還是有人比我快了 @@"

但是我可能還是要研究一下喔 ^^"

可能會出和你不太一樣的程式碼....
*譯文資料在phpBB 技術文件
bu.femto-size
*和我聯絡,請寄 or Google Talk 圖檔
*作品: Intergrated Toplist & Message Can
蕭遙
星球公民
星球公民
文章: 120
註冊時間: 2004-09-29 05:21

文章 蕭遙 »

期待^^ 不過你寫的會否象原來的advtop5一樣把代碼剝離出來作爲單獨的文件呢?我是不喜歡向原來的文件裏塞太多東西啦…… 能放在外面的盡量放外面,只用幾個語句挂進去,這樣容易看也方便檢查的說^^ 不過這裡因爲用到$forum_id,不得已才放到viewforum.php 裏面…… 有什麽好辦法的說?
最後由 蕭遙 於 2004-10-19 23:56 編輯,總共編輯了 1 次。
bu
版面管理員
版面管理員
文章: 443
註冊時間: 2003-02-23 12:46
來自: 25° 4′N 121° 29′E
聯繫:

文章 bu »

最簡單的方法就是放在viewfourm 中\r
基本上,最不容易出錯的就是這種方法....

對了!我改好了 ^^

OPEN 打開

代碼: 選擇全部

viewforum.php
FIND 找到\r

代碼: 選擇全部

//
// Mozilla navigation bar
//
$nav_links['up'] = array(
	'url' => append_sid('index.'.$phpEx),
	'title' => sprintf($lang['Forum_Index'], $board_config['sitename'])
);
AFTER, ADD 在之後加入\r

代碼: 選擇全部

   // 
   // TOP5 MOD Begin Edit by bu MOD by OOHOO 
   // 

// 
// Mod setting 
// 
// Topics text length 
$MAX_STR_LEN = 60; 
// Topics to display 
$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; 

function cutStr($str) { 

   global $MAX_STR_LEN; 

   $str = (strlen($str) > $MAX_STR_LEN) ? (substr($str, 0, $MAX_STR_LEN - 1) . "...") : $str; 
   return $str; 
} 

// query 
$sql = "SELECT topic_id, topic_title, topic_poster, topic_views, topic_replies, topic_last_post_id, f.forum_id, forum_name 
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f 
WHERE t.forum_id = '".$forum_id."' 
AND topic_moved_id = '0' 
   $auth_forums \r
ORDER BY topic_last_post_id DESC LIMIT 0, $MAX_TOPICS"; 

if( !$result = $db->sql_query($sql) ) 
{ 
   echo '<p align="center"><font color="red"><b>ADV_TOPN_MOD TOPICS QUERY ERROR!!</b></font></p>'; 
   exit; 
} 

// fetch rows 
while( $rows = $db->sql_fetchrow($result) ) 
{ 
   $topic_url = append_sid("viewtopic.$phpEx?t=" . $rows['topic_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_MESSAGE, 'ADV_TOP5 MOD TOPIC_POSTER QUERY ERROR!!'); 
   } 

   $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") . '" target="_top">' . "$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_MESSAGE, 'ADV_TOP5 MOD LAST_REPLIER QUERY ERROR!!'); 
   } 

   $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") . '" target="_top">' . "$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("top5row", array( 
      "topic" => cutStr($rows['topic_title']), 
      "topic_url" => $topic_url, 
      "topic_views" => $rows['topic_views'], 
      "topic_replies" => $rows['topic_replies'], 
      "post_time" => create_date($board_config['default_dateformat'], $r_row['post_time'], $board_config['board_timezone']), 
      "poster_url" => $poster_url, 
      "replier_url" => $replier_url, 
      "last_post_url" => $last_post_url 
   )); 
   } 

   // 
   // TOP5 MOD END Edit by bu 
   //
FIND 找到\r

代碼: 選擇全部

	'L_AUTHOR' => $lang['Author'], 
AFTER, ADD 在之後加入\r

代碼: 選擇全部

'icon_url' => $images['icon_latest_reply'], // TOP5 
'icon_alt' => $lang['View_latest_post'], // TOP5 
OPEN 打開

代碼: 選擇全部

viewforum_body.tpl
FIND A PLACE, PUT 找個好地方,放入\r

代碼: 選擇全部

<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0" style="background-color: white"> 
  <tr><td height="18" valign="top"><span class="nav">{nav_links}</span></td></tr> 
  <tr> 
    <td valign="top"> 
      <table width="100%" border="0" cellpadding="4" cellspacing="1" width="100%" class="forumline"> 
   <tr> 
     <th align="center" class="thTop" width="40%"> {L_TOPICS} </th> 
     <th align="center" class="thTop" nowrap>  {L_AUTHOR}  </th> 
     <th align="center" class="thTop" nowrap> {L_REPLIES} </th> 
     <th align="center" class="thTop" nowrap> {L_VIEWS} </th> 
     <th align="center" class="thCornerR" nowrap> {L_LASTPOST} </th> 
   </tr> 
   <!-- BEGIN top5row --> 
        <tr> 
          <td class="row2" nowrap><span class="topictitle"><a href="{top5row.topic_url}" target="_top" class="topictitle">{top5row.topic}</a></span></td> 
          <td class="row1" align="center" nowrap><span class="name">{top5row.poster_url}</span></td> 
          <td class="row2" align="center" nowrap><span class="postdetails">{top5row.topic_replies}</span></td> 
          <td class="row1" align="center" nowrap><span class="postdetails">{top5row.topic_views}</span></td> 
          <td class="row2" align="center" nowrap><span class="postdetails">{top5row.post_time}<br />{top5row.replier_url} <a href="{top5row.last_post_url}" target="_top"><img src="{icon_url}" border="0" alt="{icon_alt}" /></a></span></td>        
        </tr> 
        <!-- END top5row --> 
      </table> 
    </td>  
  </tr> 
</table>
完成 ^^

如果想和蕭大哥的一樣是人氣數排名
請找到 [php]<?php// query
$sql = "SELECT topic_id, topic_title, topic_poster, topic_views, topic_replies, topic_last_post_id, f.forum_id, forum_name
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
WHERE t.forum_id = '".$forum_id."'
AND topic_moved_id = '0'
$auth_forums
ORDER BY topic_last_post_id DESC LIMIT 0, $MAX_TOPICS";

?>[/php]

改成 [php]<?php// query
$sql = "SELECT topic_id, topic_title, topic_poster, topic_views, topic_replies, topic_last_post_id, f.forum_id, forum_name
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
WHERE t.forum_id = '".$forum_id."'
AND topic_moved_id = '0'
$auth_forums
ORDER BY topic_views DESC LIMIT 0, $MAX_TOPICS";

?>[/php]
最後由 bu 於 2004-10-19 23:55 編輯,總共編輯了 1 次。
*譯文資料在phpBB 技術文件
bu.femto-size
*和我聯絡,請寄 or Google Talk 圖檔
*作品: Intergrated Toplist & Message Can
蕭遙
星球公民
星球公民
文章: 120
註冊時間: 2004-09-29 05:21

文章 蕭遙 »

@@ 忽然發現我把文件名寫錯了,趕緊改回來……\r

看了看,才發現我忘記把sql語句裏不需要的where條件去掉了…… 算了,反正也不影響用…………
主題已鎖定

回到「外掛問題討論」