Daily Reply/New Topic Limit

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
artplat17
Registered User
Posts: 13
Joined: Wed Jun 15, 2022 2:57 pm

Daily Reply/New Topic Limit

Post by artplat17 »

I'd love to get some help to find the easiest way to realize that, like MOD or something like that but everything I could find some code from 2006 and maybe we can adapt it to use for 3.3.7

Here code part:

Code: Select all

##########################################################################
## MOD Title:		Topics\posts Limit
## MOD Author: 		Codeblight ([email protected])
## MOD Description:	Adds Topics\posts per day limits for registred user
## MOD Version:		1.0.0
##
## Installation Level:	Easy
## Installation Time:	5 Minutes
##	
##
## Files To Edit:	5
##			posting.php
##			admin/admin_board.php
##			templates/subSilver/admin/board_config_body.tpl
##			language/lang_english/lang_main.php
##			language/lang_english/lang_admin.php
##
## Included Files:	none
##
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2
##
##########################################################################
 
##########################################################################
## Installation/Author Notes:
## First always backup the files that you're going to edit.
##
## This mod adds a new column to your 'users' table.  If you are not happy
## making changes to your SQL database this mod is not for you!
##
## Tested on phpBB 2.0.19 with subSilver and my own template
##########################################################################
 
##########################################################################
## MOD History:
##
##  28.03.2006 - Version 1.0.0 First Release
##########################################################################
 
##########################################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##########################################################################
 
##########################################################################
#
#-----[ SQL ]--------------------------------------------------------------------------------
#
 
INSERT INTO phpbb_config (config_name, config_value) VALUES ('posts_per_day_limit', '50');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('topics_per_day_limit', '10');
 
#
#-----[ OPEN ]-------------------------------------------------------------------------------
#
 
language/lang_english/lang_admin.php
 
#
#-----[ FIND ]-------------------------------------------------------------------------------
#
 
$lang['Flood_Interval'] = 'Flood Interval';
$lang['Flood_Interval_explain'] = 'Number of seconds a user must wait between posts'; 
 
#
#-----[ AFTER, ADD ]-------------------------------------------------------------------------
#
 
$lang['MaxPostsPerDay'] = 'Maximum posts per day';
$lang['MaxPostsPerDayComment'] = 'Maximum posts per day limit for one user (0 - unlimited). This feature don\'t work with guest users.';
$lang['MaxTopicsPerDay'] = 'Maximum new topics per day';
$lang['MaxTopicsPerDayComment'] = 'Maximum new topics per day limit for one user (0 - unlimited). This feature don\'t work with guest users.';
 
#
#-----[ OPEN ]-------------------------------------------------------------------------------
#
 
language/lang_english/lang_main.php
 
#
#-----[ FIND ]-------------------------------------------------------------------------------
#
 
?>
 
#
#-----[ BEFORE, ADD ]-------------------------------------------------------------------------
#
 
$lang['PostsPerDayExceeded'] = 'Your daily limit of %d messages was exceeded, please try again later.';
$lang['TopicsPerDayExceeded'] = 'Your daily limit of %d new topics was exceeded, please try again later.';
 
#
#-----[ OPEN ]-------------------------------------------------------------------------------
#
 
language/lang_russian/lang_admin.php
 
#
#-----[ FIND ]-------------------------------------------------------------------------------
#
 
$lang['Flood_Interval'] = 'Задержка «флуда»';
$lang['Flood_Interval_explain'] = 'Время (в секундах), которое должно пройти между двумя сообщениями пользователя.';
 
#
#-----[ AFTER, ADD ]-------------------------------------------------------------------------
#
 
$lang['MaxPostsPerDay'] = 'Максимум сообщений в день';
$lang['MaxPostsPerDayComment'] = 'Ограничение на число сообщений в день на одного пользователя (0 - не ограничено). Эта опция не работает с гостями.';
$lang['MaxTopicsPerDay'] = 'Максимум новых тем в день';
$lang['MaxTopicsPerDayComment'] = 'Ограничение на число новых тем в день на одного пользователя (0 - не ограничено). Эта опция не работает с гостями.';
 
#
#-----[ OPEN ]--------------------------------------------------------------------------------
#
 
language/lang_russian/lang_main.php
 
#
#-----[ FIND ]--------------------------------------------------------------------------------
#
 
?>
 
#
#-----[ BEFORE, ADD ]--------------------------------------------------------------------------
#
 
$lang['PostsPerDayExceeded'] = 'Ваш лимит из %d сообщений в день был исчерпан, пожалуйста попробуйте позже.';
$lang['TopicsPerDayExceeded'] = 'Ваш лимит из %d новых тем в день был исчерпан, пожалуйста попробуйте позже.';
 
#
#-----[ OPEN ]---------------------------------------------------------------------------------
#
 
admin/admin_board.php
 
#
#-----[ FIND ]---------------------------------------------------------------------------------
#
 
"L_FLOOD_INTERVAL" => $lang['Flood_Interval'],
"L_FLOOD_INTERVAL_EXPLAIN" => $lang['Flood_Interval_explain'], 
 
#
#-----[ AFTER, ADD ]---------------------------------------------------------------------------
#
 
"L_MAX_POSTS_PER_DAY" => $lang['MaxPostsPerDay'], 
"L_MAX_POSTS_PER_DAY_COMMENT" => $lang['MaxPostsPerDayComment'], 
"L_MAX_TOPICS_PER_DAY" => $lang['MaxTopicsPerDay'], 
"L_MAX_TOPICS_PER_DAY_COMMENT" => $lang['MaxTopicsPerDayComment'], 
 
#
#-----[ FIND ]---------------------------------------------------------------------------------
#
 
"FLOOD_INTERVAL" => $new['flood_interval'],
 
#
#-----[ AFTER, ADD ]---------------------------------------------------------------------------
#
 
"POST_PER_DAY_LIMIT" => $new['posts_per_day_limit'],
"TOPIC_PER_DAY_LIMIT" => $new['topics_per_day_limit'],
 
#
#-----[ OPEN ]---------------------------------------------------------------------------------
#
 
templates/subSilver/admin/board_config_body.tpl
 
#
#-----[ FIND ]---------------------------------------------------------------------------------
#
 
<tr>
	<td class="row1">{L_FLOOD_INTERVAL} <br /><span class="gensmall">{L_FLOOD_INTERVAL_EXPLAIN}</span></td>
	<td class="row2"><input class="post" type="text" size="3" maxlength="4" name="flood_interval" value="{FLOOD_INTERVAL}" /></td>
</tr>
 
#
#-----[ AFTER, ADD ]---------------------------------------------------------------------------
#
 
<tr>
	<td class="row1">{L_MAX_POSTS_PER_DAY} <br /><span class="gensmall">{L_MAX_POSTS_PER_DAY_COMMENT}</span></td>
	<td class="row2"><input class="post" type="text" size="3" maxlength="4" name="posts_per_day_limit" value="{POST_PER_DAY_LIMIT}" /></td>
</tr>
<tr>
	<td class="row1">{L_MAX_TOPICS_PER_DAY} <br /><span class="gensmall">{L_MAX_TOPICS_PER_DAY_COMMENT}</span></td>
	<td class="row2"><input class="post" type="text" size="3" maxlength="4" name="topics_per_day_limit" value="{TOPIC_PER_DAY_LIMIT}" /></td>
</tr>
 
#
#-----[ OPEN ]----------------------------------------------------------------------------------
#
 
posting.php
 
#
#-----[ FIND ]----------------------------------------------------------------------------------
#
 
if ( $mode == 'editpost' || $mode == 'delete' || $mode == 'poll_delete' )
 
#
#-----[ BEFORE, ADD ]---------------------------------------------------------------------------
#
 
	if (!$userdata['session_admin'])
	{
		$poster_id = $userdata['user_id'];
		$current_time = time();
 
		switch ( $mode )
		{
		case 'reply':
			// проверка на число новых постов (new post check)
			$sql = "SELECT " . $current_time . " - post_time FROM " . POSTS_TABLE . " WHERE poster_id = " . $poster_id . " AND " . $current_time . " - post_time < 86400";
			if (!$result = $db->sql_query($sql))
			{
				message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql);
			}
 
			if ($db->sql_numfields($result))
			{
				$rowcount = $db->sql_numrows($result);
				if ($rowcount > 0)
				{
					$posts_lim = intval($board_config['posts_per_day_limit']);
					if ($posts_lim > 0)
					{
						if ($posts_lim <= $rowcount)
						{
							message_die(GENERAL_MESSAGE, sprintf($lang['PostsPerDayExceeded'], $board_config['posts_per_day_limit'])); 
						}
					}
				}
			}
			$db->sql_freeresult($result);
			break;
 
        	case 'newtopic':
			// проверка на число топиков (new topic check)
			$sql = "SELECT " . $current_time . " - topic_time FROM " . TOPICS_TABLE . " WHERE topic_poster = " . $poster_id . " AND " . $current_time . " - topic_time < 86400";
 
			if (!$result = $db->sql_query($sql))
			{
				message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql);
			}
			if ($db->sql_numfields($result))
			{
				$rowcount = $db->sql_numrows($result);
				if ($rowcount > 0)
				{
					$topics_lim = intval($board_config['topics_per_day_limit']);
					if ($topics_lim > 0)
					{
						if ($topics_lim <= $rowcount)
						{
							message_die(GENERAL_MESSAGE, sprintf($lang['TopicsPerDayExceeded'], $board_config['topics_per_day_limit'])); 
						}
					}
				}
			}
			$db->sql_freeresult($result);
			break;
		}
	}
 
 
#
#-----[ SAVE/CLOSE ALL FILES ]-----------------------------------------------------------------------
#
# EoM


Thanks for attention and help ;) hope together we can make it working
Last edited by P_I on Sat Feb 18, 2023 1:42 pm, edited 2 times in total.
Reason: Moved to phpBB custom coding
artplat17
Registered User
Posts: 13
Joined: Wed Jun 15, 2022 2:57 pm

Re: Daily Reply/New Topic Limit

Post by artplat17 »

Solved!

Tutorial how to limit daily replies:
1) open /includes/functions_posting.php
2) find

Code: Select all

// We do not handle erasing posts here
3) add before

Code: Select all

    
// Check if user is not an admin
if ($auth->acl_get('a_')) {
// user is an admin, do not apply reply limit
} else {
$reply_limit = 6; // Set the daily reply limit here
$user_id = $user->data['user_id'];
$today = getdate();
$timestamp = mktime(0, 0, 0, $today['mon'], $today['mday'], $today['year']);
$sql = "SELECT COUNT(*) AS reply_count FROM " . POSTS_TABLE . " WHERE poster_id = $user_id AND post_time >= $timestamp";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row['reply_count'] >= $reply_limit) {
	$time_left = 86400 - (time() - $timestamp); // Calculate remaining time in seconds
		if ($time_left < 60) {
        	$remaining_time = $time_left . " seconds";
        	} elseif ($time_left < 3600) {
        	$remaining_time = floor($time_left / 60) . " minutes and " . ($time_left % 60) . " seconds";
        	} else {
        	$remaining_time = floor($time_left / 3600) . " hours and " . floor(($time_left % 3600) / 60) . " minutes";
 }
trigger_error("<strong class='post-limit'>You have reached your daily response limit. Please try to submit your reply again in $remaining_time ;)</strong>");
}}
PS: Soon will add New Topic Daily Limit MOD as well!
Tested on phpBB 3.3.7
Last edited by artplat17 on Sat Feb 18, 2023 9:49 pm, edited 1 time in total.
User avatar
halil16
Registered User
Posts: 1266
Joined: Fri Jul 24, 2020 11:30 pm
Location: Turkiye
Name: Halil
Contact:

Re: Daily Reply/New Topic Limit

Post by halil16 »

Good!. So, can he choose a private forum in the daily topic limit soon? For example, only one topic per day can be opened in a forum with an ID of 5. Thanks. I'm following.
* Hire me at fiverr for your phpBB board.
"The day we will need ideas more than possessions, we will find the secret to true wealth." - Peyami Safa
I'm learning English...
Contributions: #Hashtag, Elegance, Latte
artplat17
Registered User
Posts: 13
Joined: Wed Jun 15, 2022 2:57 pm

Re: Daily Reply/New Topic Limit

Post by artplat17 »

halil16 wrote: Sat Feb 18, 2023 1:58 pm Good!. So, can he choose a private forum in the daily topic limit soon? For example, only one topic per day can be opened in a forum with an ID of 5. Thanks. I'm following.
Sorry but It takes a lot of time to test and make working some code because I don't know php only few bases things and I use chatgpt to mod phpbb.

I just share working functional mod that I use for my personal needs :)

Tutorial how to limit daily new topic:
1) open /posting.php
2) find

Code: Select all

page_footer();
3) add before

Code: Select all

if ($mode == 'post' && $post_data['post_id'] == 0) {
    if ($user->data['is_registered'] && !$user->data['is_bot'] && !$auth->acl_get('a_')) {
        $time_span = time() - 24 * 3600; // 24 hours
        $topic_limit = 1; // 1 topic per day
        $sql = 'SELECT COUNT(topic_id) AS topic_count 
                FROM ' . TOPICS_TABLE . ' 
                WHERE topic_time > ' . $time_span . ' 
                AND topic_poster = ' . $user->data['user_id'];
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $topic_count = $row['topic_count'];
        $db->sql_freeresult($result);
        if ($topic_count >= $topic_limit) {
            trigger_error("<strong class='topic-limit'>We allow to create only one new topic per day to prevent spam. Please try again tomorrow! ;)</strong>");
        }
    }
}
Tested on phpBB 3.3.7
Post Reply

Return to “phpBB Custom Coding”