[教學] 新版整合 Top5 for Integrated Toplist

MODs Released by Other phpbb Sites
非官方認證通過之 MOD ,或許有安全性之疑慮,所有問題由原發表者回覆!

版主: 版主管理群

主題已鎖定
頭像
brentsu
星球公民
星球公民
文章: 232
註冊時間: 2004-08-23 09:08
來自: BNW 時尚資訊網
聯繫:

[教學] 新版整合 Top5 for Integrated Toplist

文章 brentsu »

雖然我安裝過的 MOD 沒有某些版主那麼多,但是 phpBB 每大改一次,大家就要改到手軟.... 實在也不是辦法....
phpBB 又沒有像 XOOPS 那樣,可以隨時安裝、移除的外掛....

所以這次我全新安裝 phpBB 2.0.18 之後,打算用新的方式來【重裝】以前裝過的 MOD,辦法是利用 include 指令,把 Top5 改用【外掛】方式來安裝!

舉例來說,以前的【Integrated Toplist】被我精簡成【新版整合 Top5】,你只要這樣改就行了:

代碼: 選擇全部

# 
#-----[ OPEN 打?}檔案 ]------------------------------------------ 
# 

index.php

# 
#-----[ FIND 尋找 ]------------------------------------------ 
# 

$is_auth_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata, $forum_data);

# 
#-----[ AFTER, ADD 在之後, 新增 ]------------------------------------------ 
# 

include($phpbb_root_path . 'includes/toplist.'.$phpEx);

# 
#-----[ FIND 尋找 ]------------------------------------------ 
# 

		'L_POSTS' => $lang['Posts'],

# 
#-----[ AFTER, ADD 在之後, 新增 ]------------------------------------------ 
# 

		'ICON_URL' => $images['icon_latest_reply'],
		'ICON_ALT' => $lang['View_latest_post'],
		'L_AUTHOR' => $lang['Author'],
如果新版 phpBB 沒有改過【subSilver/index_body.tpl】檔案,其實只要把舊版 copy 過去即可。
底下是新的 MOD,這個部份是我自己修改的,與原本【Integrated Toplist】不同。

代碼: 選擇全部

# 
#-----[ OPEN 打?}檔案 ]------------------------------------------ 
# 

templates/subSilver/index_body.tpl

# 
#-----[ FIND 尋找 ]------------------------------------------ 
# 

		<a href="{U_SEARCH_UNANSWERED}" class="gensmall">{L_SEARCH_UNANSWERED}</a></td>
  </tr>
</table>

# 
#-----[ AFTER, ADD 在之後, 新增 ]------------------------------------------ 
# 

<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0">
  <tr>
 <td valign="top">
<table width="100%" border="0" cellpadding="4" cellspacing="1" width="100%" class="forumline">
	<tr> 
	  <th align="center" class="thCornerL" width="15%">&nbsp;{L_FORUM}&nbsp;</th>
	  <th align="center" class="thTop" width="70%">&nbsp;{L_TOPICS}&nbsp;</th>
	  <th align="center" class="thTop" nowrap>&nbsp;{L_REPLIES}&nbsp;</th>
	  <th align="center" class="thCornerR" nowrap>&nbsp;{L_LASTPOST}&nbsp;</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="row2" align="center" nowrap><span class="postdetails">{toprow.TOPIC_REPLIES}</span></td>
 <td class="row2" align="center" nowrap><span class="postdetails">{toprow.POST_TIME}<br />{toprow.REPLIER_URL}&nbsp;<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>
<br clear="all">

# 
#-----[ SAVE/CLOSE ALL FILES 儲存並關閉所有檔案 ]------------------------------------------ 
# 
# EoM 結束修改\r


最後你只要把底下的 toplist.php 新增檔案放在 include 檔案夾裡面就行囉~~
這個 toplist.php 程式不必因 phpBB 而修改,以後再有新的大改版 phpBB 2.0.19,也只要改上面的部份!!

甚至只需要修改第一段的 code 喔~~超簡單的吧!!!

代碼: 選擇全部

<?php
/***************************************************************************
 *                                toplist.php
 *                            -------------------
 *   begin                : Saturday, Feb 13, 2001
 *   copyright            : (C) 2001 The phpBB Group
 *   email                : support@phpbb.com
 *
 *   $Id: Integrated Toplist 1.0.3 2005/11/15 15:17:14 acydburn Exp $
 *
 *
 ***************************************************************************/

// Topics text length
$MAX_STR_LEN = 60;
	 
// Topics to display (Default: 5)
$MAX_TOPICS = 15;
	 
// 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;

// Order by
// topic_last_post_id (Default)
// topic_replies
// topic_views
$sortby="topic_last_post_id";

//
// Option of Toplist End
//

function cutStr($str) {
	global $MAX_STR_LEN;
	$str = (strlen($str) > $MAX_STR_LEN) ? (substr($str, 0, $MAX_STR_LEN - 1) . "...") : $str;
	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 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_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") . '" 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_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") . '" 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
	));
}
?>
※架設伺服器主機:Mac mini 1.5GHz, 1GB RAM x 三部
※架設主機作業系統:Mac OS X Server 10.6.6 Snow Leopard
※我的上網方式:固定制 ADSL 16M/8M、6 IP
※安裝的伺服器:Apache + php 5 + MySQL 5
※我的 phpBB2 版本:phpBB 3.0.x UTF-8 版
※BNW會議室網址: http://www.bnw.com.tw/conference/
bu
版面管理員
版面管理員
文章: 443
註冊時間: 2003-02-23 12:46
來自: 25° 4′N 121° 29′E
聯繫:

文章 bu »

=.=||

版權宣告請加上如

代碼: 選擇全部

 // Based on OOHOO's adv-top5, Integrated into index by bu,and Modified by brentsu 
:mrgreen:

不論是什麼授權... 都要來個名稱宣告 !!
*譯文資料在phpBB 技術文件
bu.femto-size
*和我聯絡,請寄 or Google Talk 圖檔
*作品: Intergrated Toplist & Message Can
主題已鎖定

回到「非官方認證外掛」