1 頁 (共 1 頁)

[外掛]區分發表主題與回覆

發表於 : 2004-04-04 22:03
emn178
第一次寫的小程式

試試吧\r

DEMO:
http://emn178.idv.st

在會員列表的個人資料和瀏覽主題時左邊的資料會顯示

2004/04/06更新:
已經寫出了能夠在舊有的資料庫更新的版本了

下面是直接安裝資料庫的檔案

複製起來存成reply_install.php放在跟目錄下執行

代碼: 選擇全部

<?php 

/*************************************************************************** 
 *                           reply_install.php 
 *                          ------------------- 
 * begin                : 2004/4/6
 * copyright            : emn178	http://emn178.idv.st/
 * email                : emn17@pchome.com.tw
 * 
 * $Id reply_install.php,v 1.1 20040406 084000 emn178 $  *
 *
 ***************************************************************************/

define('IN_PHPBB', true); 
$phpbb_root_path = './'; 
include($phpbb_root_path . 'extension.inc'); 
include($phpbb_root_path . 'common.'.$phpEx); 

// 
// Start session management 
// 
$userdata = session_pagestart($user_ip, PAGE_INDEX); 
init_userprefs($userdata); 
// 
// End session management 
// 

if( !$userdata['session_logged_in'] )
{
	header('Location: ' . append_sid("login.$phpEx?redirect=reply_install.$phpEx", true));
}
if( $userdata['user_level'] != ADMIN )
{
	message_die(GENERAL_MESSAGE, $lang['Not_Authorised']);
}
 
$sql = "ALTER TABLE ".USERS_TABLE." ADD `user_reply` mediumint(8) UNSIGNED DEFAULT '0' NOT NULL AFTER `user_posts`";

if ( !$db->sql_query($sql) )
{ 
   message_die(GENERAL_MESSAGE, 'Error adding field to the tablefont');
} 
else 
{ 
   $text = 'Field has installed successfully' . '<br>'; 
} 

$error = 0;

$sql = "SELECT u.user_id
	FROM " . USERS_TABLE . " u";

$result = $db->sql_query($sql);

while($row = $db->sql_fetchrow($result))
{
	$user_id[] = $row['user_id'];
}

for($i = 0;$i < count($user_id);$i++)
{
	$sql = "UPDATE " . USERS_TABLE . " SET user_reply = user_posts WHERE user_id = $user_id[$i] ";
	if(!$db->sql_query($sql))
		$error++;
}

$sql = "SELECT t.topic_id
	FROM " . TOPICS_TABLE . " t";
		
$result = $db->sql_query($sql);

while($row = $db->sql_fetchrow($result))
{
	$t_topic_id[] = $row['topic_id'];
}

for($i = 0;$i < count($t_topic_id);$i++)
{
	decision($t_topic_id[$i]);
}

function decision($topic_id)
{
	global $db;
	
	$sql = "SELECT p.post_id, p.topic_id, p.poster_id
		FROM " . POSTS_TABLE . " p";
	
	$de = '- 1';
	
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not obtain newer/older topic information', '', __LINE__, __FILE__, $sql);
	}

	while($row = $db->sql_fetchrow($result))
	{
		if($topic_id == $row['topic_id'])
		{
			$post_id[] = $row['post_id'];
			$poster_id[] = $row['poster_id'];
		}
	}
	
	for($i = 0;$i < count($post_id);$i++)
	{
		for($j = 0;$j <count($post_id) - 1;$j++)
		{
			if($post_id[$j] > $post_id[$j+1] )
			{
				$temp = $post_id[$j];
				$post_id[$j] = $post_id[$j+1];
				$post_id[$j+1] = $temp;
				$temp = $poster_id[$j];
				$poster_id[$j] = $poster_id[$j+1];
				$poster_id[$j+1] = $temp;
			}
		}
	}
	
	$sql = "UPDATE " . USERS_TABLE . " SET user_reply = user_reply $de WHERE user_id = $poster_id[0] ";
			
	if(!$db->sql_query($sql))
		$error++;
}

if($error == 0)
	$text = $text . "All infomation of replies is update successfully.";
else
	$text = $text . '<font color="#ff0000">' . "There are some unexpected errors." . '</font>';

message_die(GENERAL_MESSAGE, $text);

?>
以下是for phpbb版本\r

增加顯示在會員列表中

2004/04/07修正內容:
viewtopic.php部分少了一段程式碼,已加上去\r

代碼: 選擇全部

################################################################# 
## Mod Title: 區分發表主題與回覆(Separate Topics and Replies MOD) 
## Mod Version: v1.2 for phpBB
## Author: emn178 - http://emn178.idv.st 
## 
## Description: 此Mod能夠將使用者的文章數區分為主題數和回覆數\r
##
## Installation Level: Easy 
## Installation Time: 5 Minutes 
## Files To Edit: 7 
##                         memberlist.php 
##                         viewtopic.php 
##                         includes/functions_post.php 
##                         includes/usercp_viewprofile.php 
##                         templates/subSilver/memberlist_body.tpl 
##                         templates/subSilver/profile_view_body.tpl 
##                         templates/subSilver/viewtopic_body.tpl 
## Included Files: N/A 
################################################################# 

在SQL資料庫的phpbb_users資料表格中,增加一個user_reply欄位在user_posts後面 

欄位      類型      長度   屬性      Null      內定值      額外 
user_reply   MEDIUMNIT   8   UNSIGNED   not null   0 
# 
#-----[ 開啟 ]------------------------------------------ 
# 
includes/functions_post.php 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
$sign = ($mode == 'delete') ? '- 1' : '+ 1'; 
# 
#-----[ 前面加上 ]------------------------------------------ 
# 
//reply and posts mod 
$reply = false; 
$sqlp = "SELECT p.post_id, p.topic_id 
      FROM " . POSTS_TABLE . " p 
      WHERE forum_id = $forum_id"; 
$resultat = $db->sql_query($sqlp); 
while($row = $db->sql_fetchrow($resultat)) 
{ 
   if($topic_id == $row['topic_id']) 
      $postid[] = $row['post_id']; 
} 
if(count($postid) > 1) 
{ 
   for($i = 0;$i < count($postid);$i++) 
   { 
      if($post_id > $postid[$i]) 
         $reply = true; 
   } 
} 
if($mode == 'reply') 
   $replysign = '+ 1'; 
if($mode == 'delete' && $reply == true) 
   $replysign = "- 1"; 
//reply and posts mod 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
if ($mode != 'poll_delete') 
{ 
   $sql = "UPDATE " . USERS_TABLE . " 
         SET user_posts = user_posts $sign 
         WHERE user_id = $user_id"; 
# 
#-----[ 改成 ]------------------------------------------ 
# 
if ($mode != 'poll_delete') 
{ 
   $sql = "UPDATE " . USERS_TABLE . " 
         SET user_posts = user_posts $sign, 
         user_reply = user_reply $replysign 
         WHERE user_id = $user_id"; 
# 
#-----[ 開啟 ]------------------------------------------ 
# 
viewtopic.php
# 
#-----[ 尋找 ]------------------------------------------ 
# 
// 
// Go ahead and pull all data for this topic 
// 
$sql = "SELECT u.username, u.user_id, u.user_posts, 
# 
#-----[ 之中找到 ]------------------------------------------ 
# 
u.user_posts, 
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
u.user_reply, 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
$poster_posts = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Posts'] . ': ' . $postrow[$i]['user_posts'] : ''; 
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
$poster_topic = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Topics'] . ': ' . ($postrow[$i]['user_posts'] - $postrow[$i]['user_reply']) : ''; 
$poster_reply = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Replies'] . ': ' . $postrow[$i]['user_reply'] : ''; 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
'POSTER_POSTS' => $poster_posts, 
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
'POSTER_TOPICS' => $poster_topic, 
'POSTER_REPLIES' => $poster_reply, 
# 
#-----[ 開啟 ]------------------------------------------ 
# 
templates/subSilver/viewtopic_body.tpl 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
{postrow.POSTER_POSTS}<br /> 
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
{postrow.POSTER_TOPICS}<br /> 
{postrow.POSTER_REPLIES}<br /> 
# 
#-----[ 開啟 ]------------------------------------------ 
# 
includes/usercp_viewprofile.php 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
$posts_per_day = $profiledata['user_posts'] / $memberdays; 
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
$topic = $profiledata['user_posts'] - $profiledata['user_reply']; 
$reply = $profiledata['user_reply']; 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
'POSTS' => $profiledata['user_posts'], 
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
'TOPICS' => $topic, 
'REPLIES' => $reply, 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
'L_TOTAL_POSTS' => $lang['Total_posts'], 
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
'L_TOTAL_TOPICS' => $lang['Topics'], 
'L_TOTAL_REPLIES' => $lang['Replies'], 
# 
#-----[ 開啟 ]------------------------------------------ 
# 
templates/subSilver/profile_view_body.tpl 
# 
#-----[ 尋找 ]------------------------------------------ 

      <tr> 
        <td valign="top" align="right" nowrap="nowrap"><span class="gen">{L_TOTAL_POSTS}: </span></td> 
        <td valign="top"><b><span class="gen">{POSTS}</span></b><br /><span class="genmed">[{POST_PERCENT_STATS} / {POST_DAY_STATS}]</span> <br /><span class="genmed"><a href="{U_SEARCH_USER}" class="genmed">{L_SEARCH_USER_POSTS}</a></span></td> 
      </tr> 
# 
#-----[ 改成 ]------------------------------------------ 
# 
      <tr> 
        <td valign="top" align="right" nowrap="nowrap"><span class="gen">{L_TOTAL_POSTS}: </span></td> 
        <td valign="top"><b><span class="gen">{POSTS}</span></b></td> 
      </tr> 
      <tr> 
      <td valign="top" align="right" nowrap="nowrap"><span class="gen">{L_TOTAL_TOPICS}: </span></td> 
        <td valign="top"><b><span class="gen">{TOPICS}</span></b></td> 
      </tr> 
      <tr> 
      <td valign="top" align="right" nowrap="nowrap"><span class="gen">{L_TOTAL_REPLIES}: </span></td> 
        <td valign="top"><b><span class="gen">{REPLIES}</span></b><br /> 
        <span class="genmed">[{POST_PERCENT_STATS} / {POST_DAY_STATS}]</span><br /><span class="genmed"><a href="{U_SEARCH_USER}" class="genmed">{L_SEARCH_USER_POSTS}</a></span></td> 
      </tr> 
# 
#-----[ 開啟 ]------------------------------------------ 
# 
memberlist.php 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
'L_POSTS' => $lang['Posts'], 
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
'L_TOPICS' => $lang['Topics'], 
'L_REPLIES' => $lang['Replies'], 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
$sql = "SELECT username, user_id, user_viewemail, user_posts, user_regdate, user_from, user_website, user_email, user_icq, user_aim, user_yim, user_msnm, user_avatar, user_avatar_type, user_allowavatar 
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
, user_reply 
# 
#-----[ 變成 ]------------------------------------------ 
# 
$sql = "SELECT username, user_id, user_viewemail, user_posts, user_regdate, user_from, user_website, user_email, user_icq, user_aim, user_yim, user_msnm, user_avatar, user_avatar_type, user_allowavatar, user_reply 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
$posts = ( $row['user_posts'] ) ? $row['user_posts'] : 0; 
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
$topic = ( $row['user_posts'] ) ? ($row['user_posts'] - $row['user_reply']) : 0; 
$reply = ( $row['user_reply'] ) ? $row['user_reply'] : 0; 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
'POSTS' => $posts, 
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
'TOPICS' => $topic, 
'REPLIES' => $reply, 
# 
#-----[ 開啟 ]------------------------------------------ 
# 
templates/subSilver/memberlist_body.tpl 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
<th class="thTop" nowrap="nowrap">{L_POSTS}</th> 
# 
#-----[ 改成 ]------------------------------------------ 
# 
<th class="thTop" nowrap="nowrap" width = "150">{L_POSTS}/{L_TOPICS}/{L_REPLIES}</th> 
# 
#-----[ 尋找 ]------------------------------------------ 
# 
<td class="{memberrow.ROW_CLASS}" align="center" valign="middle"><span class="gen">{memberrow.POSTS}</span></td> 
# 
#-----[ 改成 ]------------------------------------------ 
# 
<td class="{memberrow.ROW_CLASS}" align="center" valign="middle"><span class="gen">{memberrow.POSTS} / {memberrow.TOPICS} / {memberrow.REPLIES}</span></td> 
# 
#-----[ 儲存並關閉所有檔案 ]------------------------------------------ 
# 
# EoM
以下是 for plus 版本\r

代碼: 選擇全部

################################################################# 
## Mod Title: 區分發表主題與回覆(Separate Topics and Replies MOD) 
## Mod Version: v1.0 for phpBB plus
## Author: emn178 - http://emn178.idv.st
## 
## Description: 此Mod能夠將使用者的文章數區分為主題數和回覆數\r
##
## Installation Level: Easy 
## Installation Time: 5 Minutes 
## Files To Edit: 5
##			include/functions_post.php 
##			profilcp/profilcp_public_base.php 
##			viewtopic.php 
##			templates/fisubsilversh/viewtopic_body.tpl
##			templates/fisubsilversh/profilcp/public_base_body.tpl
## Included Files: N/A 
################################################################# 

在SQL資料庫的phpbb_users資料表格中,增加一個user_reply欄位在user_posts後面\r

欄位		類型		長度	屬性		Null		內定值		額外
user_reply	MEDIUMNIT	8	UNSIGNED	not null	0
# 
#-----[ 開啟 ]------------------------------------------ 
# 
include/functions_post.php
# 
#-----[ 尋找 ]------------------------------------------ 
#
if ($mode == 'delete') 
{ 
	if ($count_posts) 
	{ 
		$sign = "- 1"; 
	} 
	else 
	{ 
		$sign = ""; 
	} 
}
else
{
	if ($count_posts) 
	{ 
		$sign = "+ 1"; 
	} 
	else 
	{ 
		$sign = ""; 
	} 
}
# 
#-----[ 前面加上 ]------------------------------------------ 
# 
	//reply and posts mod by emn178
	$reply = false;
	$sqlp = "SELECT p.post_id, p.topic_id 
			FROM " . POSTS_TABLE . " p
			WHERE forum_id = $forum_id"; 
	$resultat = $db->sql_query($sqlp); 
	while($row = $db->sql_fetchrow($resultat))
	{
		if($topic_id == $row['topic_id'])
			$postid[] = $row['post_id'];
	}
	if(count($postid) > 1)
	{
		for($i = 0;$i < count($postid);$i++)
		{
			if($post_id > $postid[$i])
				$reply = true;
		}
	}
	//reply and posts mod by emn178
# 
#-----[ 改成 ]------------------------------------------ 
#
if ($mode == 'delete') 
{ 
	if ($count_posts) 
	{ 
		$sign = "- 1"; 
		if($reply == true)
			$replysign = "- 1";
	} 
	else 
	{ 
		$sign = ""; 
	} 
}
else 
{ 
	if ($count_posts) 
	{ 
		$sign = "+ 1"; 
		if($mode == 'reply')
			$replysign = "+ 1";
	} 
	else 
	{ 
		$sign = ""; 
	} 
}
# 
#-----[ 尋找 ]------------------------------------------ 
#
if ($mode != 'poll_delete')
{
	$sql = "UPDATE " . USERS_TABLE . "
			SET user_posts = user_posts $sign 
			WHERE user_id = $user_id";
# 
#-----[ 改成 ]------------------------------------------ 
#
if ($mode != 'poll_delete')
{
	$sql = "UPDATE " . USERS_TABLE . "
			SET user_posts = user_posts $sign, 
			user_reply = user_reply $replysign
			WHERE user_id = $user_id";
# 
#-----[ 開啟 ]------------------------------------------ 
# 
profilcp/profilcp_public_base.php
# 
#-----[ 尋找 ]------------------------------------------ 
#
$posts_per_day	= $view_userdata['user_posts'] / $memberdays;
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
$topic			= $view_userdata['user_posts'] - $view_userdata['user_reply'];
$reply			= $view_userdata['user_reply'];
# 
#-----[ 尋找 ]------------------------------------------ 
#
'L_TOTAL_POSTS'			=> $lang['Total_posts'],
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
'L_TOTAL_TOPICS'		=> $lang['Topics'],
'L_TOTAL_REPLIES'		=> $lang['Replies'],
# 
#-----[ 尋找 ]------------------------------------------ 
#
'POSTS'					=> $nb_posts,
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
'TOPICS'				=> $topic,
'REPLIES'				=> $reply,
# 
#-----[ 開啟 ]------------------------------------------ 
# 
viewtopic.php
# 
#-----[ 尋找 ]------------------------------------------ 
#
$poster_posts = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Posts'] . ': ' . $postrow[$i]['user_posts'] : '';
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
$poster_topic = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Topics'] . ': ' . ($postrow[$i]['user_posts'] - $postrow[$i]['user_reply']) : '';
$poster_reply = ( $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['Replies'] . ': ' . $postrow[$i]['user_reply'] : '';
# 
#-----[ 尋找 ]------------------------------------------ 
#
'POSTER_POSTS' => $poster_posts,
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
'POSTER_TOPICS' => $poster_topic,
'POSTER_REPLIES' => $poster_reply,
# 
#-----[ 開啟 ]------------------------------------------ 
# 
templates/fisubsilversh/viewtopic_body.tpl
# 
#-----[ 尋找 ]------------------------------------------ 
#
{postrow.POSTER_POSTS}<br />
# 
#-----[ 後面加上 ]------------------------------------------ 
# 
{postrow.POSTER_TOPICS}<br />
{postrow.POSTER_REPLIES}<br />
# 
#-----[ 開啟 ]------------------------------------------ 
# 
templates/fisubsilversh/public_base_body.tpl
# 
#-----[ 尋找 ]------------------------------------------ 
#
				<tr> 
					<td valign="top" align="right" nowrap="nowrap"><span class="gen">{L_TOTAL_POSTS}: </span></td>
					<td valign="top">
						<span class="gen"><b>{POSTS}</b></span><br />
						<!-- BEGIN switch_post_stat -->
						<span class="genmed">[{POST_PERCENT_STATS} / {POST_DAY_STATS}]</span><br />
						<span class="genmed"><a href="{U_SEARCH_USER}" class="genmed">{L_SEARCH_USER_POSTS}</a></span>
						<!-- END switch_post_stat -->
				</tr>
# 
#-----[ 改成 ]------------------------------------------ 
#
				<tr> 
					<td valign="top" align="right" nowrap="nowrap"><span class="gen">{L_TOTAL_POSTS}: </span></td>
					<td valign="top">
						<span class="gen"><b>{POSTS}</b></span>
				</tr>
				<tr>
					<td valign="top" align="right" nowrap="nowrap"><span class="gen">{L_TOTAL_TOPICS}: </span></td>
					<td valign="top">
						<span class="gen"><b>{TOPICS}</b></span>
				</tr>
				<tr>
					<td valign="top" align="right" nowrap="nowrap"><span class="gen">{L_TOTAL_REPLIES}: </span></td>
					<td valign="top">
						<span class="gen"><b>{REPLIES}</b></span><br />
						<!-- BEGIN switch_post_stat -->
						<span class="genmed">[{POST_PERCENT_STATS} / {POST_DAY_STATS}]</span><br />
						<span class="genmed"><a href="{U_SEARCH_USER}" class="genmed">{L_SEARCH_USER_POSTS}</a></span></td>
						<!-- END switch_post_stat -->
				</tr>
# 
#-----[ 儲存並關閉所有檔案 ]------------------------------------------ 
# 
# EoM
有問題可以到\r

http://phpbb-tw.net/phpbb/viewtopic.php?t=23813

或我的論壇提出討論