[MOD-DB]Only_View_Topics_from_Last_N_Days

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
Locked
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

[MOD-DB]Only_View_Topics_from_Last_N_Days

Post by asinshesq »

Code: Select all

############################################################## 
## MOD Title: Only_View_Topics_From_Last_N_Days_(Retain_Setting_Between_Sessions) 
## MOD Author: asinshesq < asinsh@speakeasy.net > (Alan Sinsheimer) N/A
## MOD Description:	This mod allows a user to set his own default for how far 
##			back in time he wants to go when looking in viewforum at
##			old topics that have not been posted to for a while.  
##			In the forum view on an unmodded board, the default is 
##			always "All", and if a user changes it while looking at 
##			the topics in a given forum, the setting gets reset back 
##			to "All" as soon as he moves on to another forum (and 
##			stays at "All" even if he goes back to the original forum 
##			where he changed it).
##
##			This mod also corrects the behavior of the function so that 
##			it finds all topics that have been posted to in the last N days 
##			(on an unmodded board, if you set it to look at topics for the 
##			last N days, it will show you topics that were started 
##			N days ago, but the proper behavior is to look for topics 
##			that have been posted to in the last N days; this mod 
##			fixes that behavior).
##
##			Finally, this mod fixes a few bugs in phpbb that mess up
##			pagination in various circumstances...see
##			http://www.phpbb.com/phpBB/viewtopic.php?t=203533 
##			for details.
##
##			The real author of most of this mod is Slimy, who started this at
##			http://www.phpbb.com/phpBB/viewtopic.php?t=147116 . 
##			I merely refined what he had already done.
##
## MOD Version: 1.0.4 
## 
## Installation Level:	Easy 
## Installation Time:	5 Minutes 
## Files To Edit: 	viewforum.php
##			includes/functions.php
## Included Files:	n/a
############################################################## 
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the 
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code 
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered 
## in our MOD-Database, located at: http://www.phpbb.com/mods/ 
############################################################## 
## Author Notes:	none needed
## 
############################################################## 
## MOD History: 
##   2004-08-31 - Version 1.0.4
##      -	added 'intval' to prevent sql injection 
##   2004-07-25 - Version 1.0.3
##      -	add a fix to a bug inherent in phpbb (not caused by this mod)...see
##		http://www.phpbb.com/phpBB/viewtopic.php?t=203533 for details.
##   2004-07-16 - Version 1.0.2
##      -	corrected code to be found so matches viewforum file in 2.0.9
##
##   2004-07-16 - Version 1.0.1 
##      -	this is the first version using a proper template; the only change from the 
##		prior version is a line	that adds Announcements to the pagination count so 
##		that Announcements don't screw up the pagination
## 
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
##############################################################

# 
#-----[ SQL ]------------------------------------------ 
# 

ALTER TABLE phpbb_users ADD topic_view_time_id mediumint(8) default '0' AFTER user_regdate;

# 
#-----[ OPEN ]------------------------------------------ 
#
viewforum.php 

# 
#-----[ FIND ]------------------------------------------ 
# 
if ( !empty($HTTP_POST_VARS['topicdays']) || !empty($HTTP_GET_VARS['topicdays']) )
{
	$topic_days = ( !empty($HTTP_POST_VARS['topicdays']) ) ? intval($HTTP_POST_VARS['topicdays']) : intval($HTTP_GET_VARS['topicdays']);
	$min_topic_time = time() - ($topic_days * 86400);

	$sql = "SELECT COUNT(t.topic_id) AS forum_topics 
		FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p 
		WHERE t.forum_id = $forum_id 
			AND p.post_id = t.topic_last_post_id
			AND p.post_time >= $min_topic_time"; 

	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not obtain limited topics count information', '', __LINE__, __FILE__, $sql);
	}
	$row = $db->sql_fetchrow($result);

	$topics_count = ( $row['forum_topics'] ) ? $row['forum_topics'] : 1;
	$limit_topics_time = "AND p.post_time >= $min_topic_time";

	if ( !empty($HTTP_POST_VARS['topicdays']) )
	{
		$start = 0;
	}
}
else
{
	$topics_count = ( $forum_row['forum_topics'] ) ? $forum_row['forum_topics'] : 1;

	$limit_topics_time = '';
	$topic_days = 0;
}
 
# 
#-----[ REPLACE WITH ]------------------------------------------ 
# 

/*view topics in last N days MOD start*/
if ( isset($HTTP_POST_VARS['topicdays']) || isset($HTTP_GET_VARS['topicdays']) )
{
	$topic_days = ( isset($HTTP_POST_VARS['topicdays']) ) ? intval($HTTP_POST_VARS['topicdays']) : intval($HTTP_GET_VARS['topicdays']);
	//$min_topic_time = time() - ($topic_days * 86400);

	$sql = "UPDATE " . USERS_TABLE . "
		SET topic_view_time_id = $topic_days
		WHERE user_id = " . $userdata['user_id'];
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not update topics view time information', '', __LINE__, __FILE__, $sql);
	}
}

$sql = "SELECT topic_view_time_id FROM " . USERS_TABLE . "
	WHERE user_id = " . $userdata['user_id'];
if ( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not obtain topics view time information', '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$topic_days = $row['topic_view_time_id'];
if ($topic_days != 0)
{
	$min_topic_time = time() - ($topic_days * 86400);
}
else
{
	$min_topic_time = 0;
}
	
$sql = "SELECT COUNT(t.topic_id) AS forum_topics 
	FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p 
	WHERE t.forum_id = $forum_id 
		AND p.post_id = t.topic_last_post_id
		AND (p.post_time >= $min_topic_time || t.topic_type = " . POST_ANNOUNCE . ")";

if ( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not obtain limited topics count information', '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);

$topics_count = ( $row['forum_topics'] ) ? $row['forum_topics'] : 1;
$limit_topics_time = "AND p2.post_time >= $min_topic_time";

if ( !empty($HTTP_POST_VARS['topicdays']) )
{
	$start = 0;
}
/*view topics in last N days MOD end*/

# 
#-----[ FIND ]------------------------------------------ 
#
		'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $topics_count / $board_config['topics_per_page'] )),

# 
#-----[ REPLACE WITH ]------------------------------------------ 
#
		'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), max(1, ceil( $topics_count / $board_config['topics_per_page'] ))),

# 
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM 
Last edited by asinshesq on Mon Oct 11, 2004 2:14 pm, edited 14 times in total.
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

revision

Post by asinshesq »

I slightly revised the above file to fix a pagination error caused by the original mod not counting any announcements. The only changed line is the last line in the final $sql definition, which now reads:

AND (p.post_time >= $min_topic_time || t.topic_type = " . POST_ANNOUNCE . ")";
Last edited by asinshesq on Fri Jul 16, 2004 9:57 am, edited 1 time in total.
User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Post by morpheus2matrix »

Please, use the correct MOD Template for your MOD :wink:
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

morpheus2matrix wrote: Please, use the correct MOD Template for your MOD :wink:


OK, I have now changed the first post in this topic to conform to the template.
Grand Edgemaster
Registered User
Posts: 14
Joined: Mon Jun 14, 2004 6:29 pm
Location: London

Post by Grand Edgemaster »

In the last comment,:

Code: Select all

/view topics in last N days MOD end*/ 

# 
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM 

Should be this:

Code: Select all

} 
/*view topics in last N days MOD end*/ 

# 
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM 
(The Leading star was missing)
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

Thanks, Grand Edgemsaster. Don't know how that got dropped when I pasted things into the template. But I've fixed the code in the first post now so it is good to go. Let me know what you think.

(I haven't tried loading this with easymod yet...I'll try that tonight but if you do it let me know how that works out too.)
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

OK, I've tried it with virgin 2.0.9 files and easymod and it works perfectly. (I had to change the 'find' code to match some changes made in 2.0.7 that I hadn't already picked up, but the version above reflects that change so it works fine for 2.0.9).
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

I have confirmed that this works fine with 2.0.10.

Note that phpbb has a bug related to pagination (described here: http://www.phpbb.com/phpBB/viewtopic.php?t=203533 ) that becomes more apparant when you use this mod. For that reason, I have picked up the fix for that bug (described at http://www.phpbb.com/phpBB/viewtopic.php?t=203533) in a new version 1.0.3 of this mod (reproduced in the first post of this topic).
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

This mod has now been validated, so please go here: http://www.phpbb.com/phpBB/viewtopic.php?t=228843 for any further discussion.
Darkmonkey
Former Team Member
Posts: 1707
Joined: Fri Oct 24, 2003 3:48 pm
Location: Where the trout streams flow and the air is nice

Post by Darkmonkey »

As Above.

This MOD has now been released into the MOD DB: http://www.phpbb.com/phpBB/viewtopic.php?t=228843

Locked.
Locked

Return to “[2.0.x] MODs in Development”