Auto lock topic

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Ideas Centre
nl2dav
Registered User
Posts: 102
Joined: Tue Jun 25, 2002 10:39 pm
Location: NOP, The Netherlands
Contact:

Re: Auto lock topic

Post by nl2dav » Sat Nov 22, 2008 10:09 am

Auto lock based on topic replies;

Open
posting.php
Find

Code: Select all

            {
                $post_data['post_edit_locked'] = ITEM_LOCKED;
            } 
Add after

Code: Select all

            // lock topic without warning if posts > 3000 
            if ($post_data['topic_replies'] > 3000 )
            {
            $sql = 'UPDATE ' . TOPICS_TABLE . "
                SET topic_status = 1
                WHERE topic_id = $topic_id";
            $db->sql_query($sql);
            }   

mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Auto lock topic

Post by mtrs » Sun Nov 23, 2008 11:03 am

I edited the code in my previous post, added topic_lock log line and only normal topic lock feature.
http://www.phpbb.com/community/viewtopi ... 5#p7804035
I abandoned all of my mods.

Shining Phoenix
Registered User
Posts: 27
Joined: Wed Feb 28, 2007 8:15 am
Contact:

Re: Auto lock topic

Post by Shining Phoenix » Sun Nov 23, 2008 8:25 pm

Whenever a user tried to quote a post, the forum said that it's too old, even when it wasn't. Any ideas?

User avatar
modtang
Registered User
Posts: 16
Joined: Wed Apr 30, 2003 8:37 pm

Re: Auto lock topic

Post by modtang » Sat Dec 20, 2008 5:51 am

mtrs wrote:I tried a short code for this, moderators and posters above 100 post counts are not affected, topic last post time checked and NORMAL_TOPICS locked upon reply/quote attempts.
I edited this to 50 posts and am using it to see how it goes. How does the time work? 2592000 = 30 days? If I'd like to change this to 60 days or 90 days do I just double or triple it?

mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Auto lock topic

Post by mtrs » Sat Dec 20, 2008 10:35 am

modtang wrote:How does the time work? 2592000 = 30 days? If I'd like to change this to 60 days or 90 days do I just double or triple it?

Time works as follows
1 day is 86400 seconds
30 day is (30 * 86400) = 2592000 seconds
...
90 day is (90 * 86400) = 7776000
I abandoned all of my mods.

rae_rae
Registered User
Posts: 49
Joined: Fri Oct 29, 2004 6:44 pm
Location: CA, USA
Contact:

Re: Auto lock topic

Post by rae_rae » Wed Jan 21, 2009 10:05 am

Here we are....a nice PHP script to do this at a custom level:

Code: Select all

<?php

/******************************************************************
* Script to update topic status to LOCKED if topic most recent
* post is older than a set number of days.
*
* Created for: PHPBB 3.x
* Written by: Ray Griffin
* PHP version: 4+
*
* Instructions: Just fill in the credentials at the top of this script
* just below these directions and fill in the max number of days
* a topic is to be considered still new
******************************************************************/

//Credentials
$host = '';
$user = '';
$pass = '';
$db = '';

// Max number of days topic is considered still active (NOT LOCKED)
$max_days = 360;

$link = @mysql_connect($host, $user, $pass);
if (!is_resource($link))
{
   print 'Failed to mysql_connect()';
   exit;
}

if (!mysql_select_db($db, $link))
{
   print 'Failed to mysql_select_db()';
   exit;
}

// Get an array of topic_ids
$topic_ids = array();
$sql = "
   SELECT topic_id
   FROM phpBB3_topics
";
$result = mysql_query($sql, $link);
if (!is_resource($result))
{
   print "mysql_query($sql) is not a valid resource";
   exit;
}
while ($row = mysql_fetch_row($result)) {
   if (!in_array($row[0], $topic_ids))
   {
      $topic_ids[] = $row[0];
   }
}

// For each of the topic_ids, determine if any are too old
$updates = 0;
if (!is_array($topic_ids))
{
   print 'There are no topic_ids in the system';
   exit;
}
foreach ($topic_ids as $id)
{
   // Get the date difference
   $sql = "
      SELECT DATEDIFF( (

         SELECT FROM_UNIXTIME( UNIX_TIMESTAMP( NOW( ) ) ) ) , (

            SELECT FROM_UNIXTIME( topic_last_post_time )
            FROM `phpBB3_topics`
            WHERE `topic_id` = $id
         )
      ) AS days_diff
   ";
   $result = mysql_query($sql, $link);
   if (!is_resource($result))
   {
      print "mysql_query($sql) is not a valid resource";
      exit;
   }
   while ($row = mysql_fetch_row($result)) {
      $days_old = $row[0];
   }
   if ($days_old >= $max_days)
   {
      // Lock the old stuff
      $sql = "
         UPDATE `phpBB3_topics`
         SET topic_status = 1
         WHERE topic_id = $id
      ";
      $ret = mysql_query($sql, $link);
      if ($ret)
      {
         $updates++;
      }
   }
}

print "Finished. Updated $updates records";

?>

rae_rae
Registered User
Posts: 49
Joined: Fri Oct 29, 2004 6:44 pm
Location: CA, USA
Contact:

Re: Auto lock topic

Post by rae_rae » Thu Jan 22, 2009 8:07 pm

Here is my version of the posting.php code...which also works with the quote button in version 3. Interestingly, the old code didn't work.

Code: Select all

//Check topic last post time and lock if last post is older than 360 days
$current_time = time();
if ($user->data['user_id'] != ANONYMOUS && ($mode == 'reply' || $mode == 'quote'))
{
	// Learn the last post time
	$sql = 'SELECT topic_last_post_time, topic_type, topic_title
		FROM ' . TOPICS_TABLE . '
		WHERE topic_id = ' . $topic_id;

	$sql = "
		SELECT DATEDIFF( (

					SELECT FROM_UNIXTIME( UNIX_TIMESTAMP( NOW( ) ) ) ) , (

						SELECT FROM_UNIXTIME( topic_last_post_time )
						FROM `phpBB3_topics`
						WHERE `topic_id` = $topic_id
					)
				) AS topic_last_post_time, topic_type, topic_title
		FROM `phpBB3_topics`
		WHERE `topic_id` = $topic_id
	";
	$result = $db->sql_query_limit($sql, 1);
	
	if ($row = $db->sql_fetchrow($result))
	{
		$topic_age = $row['topic_last_post_time'];
		$topic_type = $row['topic_type'];
		$topic_title = $row['topic_title'];
	}
	$db->sql_freeresult($result);

	// Determine if the topic age is older than 360 days
	if ($topic_age >= 360)
	{
		//Lock topic and give error warning
		$sql = 'UPDATE ' . TOPICS_TABLE . "
			SET topic_status = 1
			WHERE topic_id = $topic_id";
		$db->sql_query($sql);
		
		add_log('mod', $forum_id, $topic_id, 'LOG_' . 'LOCK', $topic_title);
		trigger_error('This topic is too old to reply, so, it\'s locked now. Thanks.');
	}
}
//End of lock topic

idiotnesia
Registered User
Posts: 509
Joined: Sun Jun 18, 2006 10:58 am
Location: www.phpbbindonesia.com
Name: Pungky Putra
Contact:

Re: Auto lock topic

Post by idiotnesia » Fri Jan 23, 2009 3:08 pm

I think the best way is using cron feature from phpBB3.

FYI evil<3 has similar mod "Forum prune move" http://www.phpbb.com/community/viewtopi ... 9&t=912205

Maybe somebody here can adapt the code.

ibelphegor
Registered User
Posts: 453
Joined: Wed Oct 24, 2007 8:37 am

Re: Auto lock topic

Post by ibelphegor » Thu Mar 26, 2009 1:05 pm

Sorry for the bump, but how can i use that code and choose specific forum/s?
mtrs wrote:I tried a short code for this, moderators and posters above 100 post counts are not affected, topic last post time checked and NORMAL_TOPICS locked upon reply/quote attempts.

Open
posting.php
Find

Code: Select all

$current_time = time(); 
Add after

Code: Select all

//Check topic last post time and lock if last post is older than 30 days - moderators and posters above 100 post counts are not affected
    if ($user->data['user_id'] != ANONYMOUS && ($mode == 'reply' || $mode == 'quote') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_') && $user->data['user_posts'] < 100)
    {
    // Learn the last post time
        $sql = 'SELECT topic_last_post_time, topic_type, topic_title
            FROM ' . TOPICS_TABLE . '
            WHERE topic_id = ' . $topic_id;
               
        $result = $db->sql_query_limit($sql, 1);
          
        if ($row = $db->sql_fetchrow($result))
        {
            $topic_age = $row['topic_last_post_time'];
            $topic_type = $row['topic_type'];
            $topic_title = $row['topic_title'];
        }
        $db->sql_freeresult($result);        
        
        if ((time() - $topic_age) > 2592000 && $topic_type == POST_NORMAL)//The last topic post 30 days old topics, are locked
        {
            //Lock topic and give error warning        
            $sql = 'UPDATE ' . TOPICS_TABLE . "
                SET topic_status = 1
                WHERE topic_id = $topic_id";
            $db->sql_query($sql);
            
            add_log('mod', $forum_id, $topic_id, 'LOG_' . 'LOCK', $topic_title);
            trigger_error('This topic is too old to reply, so, it\'s locked now. Thanks.');
        }   
    }
//End of lock topic      

mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Auto lock topic

Post by mtrs » Fri Mar 27, 2009 3:28 pm

ibelphegor wrote:how can i use that code and choose specific forum/s?
You should test forum_id numbers.

Code: Select all

//only forum_id 55  and 544 affected
$excluded_forum_ids = array(55,544);
if (in_array($forum_id, $excluded_forum_ids))
{

//Put your code here

}  
I abandoned all of my mods.

ibelphegor
Registered User
Posts: 453
Joined: Wed Oct 24, 2007 8:37 am

Re: Auto lock topic

Post by ibelphegor » Fri Mar 27, 2009 7:11 pm

Great! work perfect.. Thanks.

cfeedback
Registered User
Posts: 58
Joined: Tue May 13, 2008 6:15 pm
Location: Reno, NV

Re: Auto lock topic

Post by cfeedback » Sat Jul 11, 2009 5:20 pm

Is there a way to get this to work without having someone attempt to make a post? I'd like to lock any topic in a specific forum after 36 hours without a reply.

ClubCalibra
Registered User
Posts: 7
Joined: Tue Nov 25, 2008 8:42 pm

Re: Auto lock topic

Post by ClubCalibra » Mon Sep 21, 2009 11:36 pm

Ironically .. I 'm bumping this older post lol

I'm trying to impliment this on my forum

Using the

Code: Select all

//Check topic last post time and lock if last post is older than 30 days - moderators and posters above 100 post counts are not affected
    if ($user->data['user_id'] != ANONYMOUS && ($mode == 'reply' || $mode == 'quote') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_') && $user->data['user_posts'] < 100)
    {
    // Learn the last post time
        $sql = 'SELECT topic_last_post_time, topic_type, topic_title
            FROM ' . TOPICS_TABLE . '
            WHERE topic_id = ' . $topic_id;
               
        $result = $db->sql_query_limit($sql, 1);
          
        if ($row = $db->sql_fetchrow($result))
        {
            $topic_age = $row['topic_last_post_time'];
            $topic_type = $row['topic_type'];
            $topic_title = $row['topic_title'];
        }
        $db->sql_freeresult($result);        
        
        if ((time() - $topic_age) > 2592000 && $topic_type == POST_NORMAL)//The last topic post 30 days old topics, are locked
        {
            //Lock topic and give error warning        
            $sql = 'UPDATE ' . TOPICS_TABLE . "
                SET topic_status = 1
                WHERE topic_id = $topic_id";
            $db->sql_query($sql);
            
            add_log('mod', $forum_id, $topic_id, 'LOG_' . 'LOCK', $topic_title);
            trigger_error('This topic is too old to reply, so, it\'s locked now. Thanks.');
        }   
    }
//End of lock topic      
Works ok for reply - but when the quote button is used on recent (IE today) posts - it displays the 'This topic is too old to reply, so, it\'s locked now. Thanks. message

using the below code - which "which also works with the quote button in version 3" generates a few sql errors when trying to reply or quote

Code: Select all

//Check topic last post time and lock if last post is older than 360 days
$current_time = time();
if ($user->data['user_id'] != ANONYMOUS && ($mode == 'reply' || $mode == 'quote'))
{
   // Learn the last post time
   $sql = 'SELECT topic_last_post_time, topic_type, topic_title
      FROM ' . TOPICS_TABLE . '
      WHERE topic_id = ' . $topic_id;

   $sql = "
      SELECT DATEDIFF( (

               SELECT FROM_UNIXTIME( UNIX_TIMESTAMP( NOW( ) ) ) ) , (

                  SELECT FROM_UNIXTIME( topic_last_post_time )
                  FROM `phpBB3_topics`
                  WHERE `topic_id` = $topic_id
               )
            ) AS topic_last_post_time, topic_type, topic_title
      FROM `phpBB3_topics`
      WHERE `topic_id` = $topic_id
   ";
   $result = $db->sql_query_limit($sql, 1);
   
   if ($row = $db->sql_fetchrow($result))
   {
      $topic_age = $row['topic_last_post_time'];
      $topic_type = $row['topic_type'];
      $topic_title = $row['topic_title'];
   }
   $db->sql_freeresult($result);

   // Determine if the topic age is older than 360 days
   if ($topic_age >= 360)
   {
      //Lock topic and give error warning
      $sql = 'UPDATE ' . TOPICS_TABLE . "
         SET topic_status = 1
         WHERE topic_id = $topic_id";
      $db->sql_query($sql);
      
      add_log('mod', $forum_id, $topic_id, 'LOG_' . 'LOCK', $topic_title);
      trigger_error('This topic is too old to reply, so, it\'s locked now. Thanks.');
   }
}
//End of lock topic
Any Guru's out there who can help ? I would like the mod to work if there is a reply or quoting of a topic which is older than a set time... using the first code the quote function doesn't work...

User avatar
SuperMaurim®
Registered User
Posts: 12
Joined: Thu Aug 07, 2008 1:28 pm

Re: Auto lock topic

Post by SuperMaurim® » Thu Oct 01, 2009 4:56 pm

Thanks mtrs,

Works perfectly. But as our friend said, if the User click on the name of a recent topic, it states that the topic is old and will be locked. Do not lock the topic but also does not allow the User to use the quote button on topics that are not old.

mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Auto lock topic

Post by mtrs » Thu Oct 01, 2009 7:19 pm

I tested a shorter code for this.

Open
posting.php
Find

Code: Select all

// Determine some vars
Before add

Code: Select all

//Begin: Lock old topics
if ($mode != 'post' && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_') && isset($post_data['topic_last_post_time']) && $post_data['topic_status'] == ITEM_UNLOCKED)
{
	//If topic last post time is older than 30 days, topic will be locked. 86400 is one month in seconds * 30 = 1 month
	if ($post_data['topic_last_post_time'] < (time() - (86400 * 1)) && $post_data['topic_type'] == POST_NORMAL)
	{
		//Lock topic and give error warning
		$sql = 'UPDATE ' . TOPICS_TABLE . "
			SET topic_status = " . ITEM_LOCKED . "
			WHERE topic_id = $topic_id";
		$db->sql_query($sql);

		add_log('mod', $forum_id, $topic_id, 'LOG_' . 'LOCK', $post_data['topic_title']);
		trigger_error('This topic is too old to reply, so, it\'s locked now. Thanks.');
	} 
}
//End: Lock old topics
Last edited by mtrs on Tue Oct 20, 2009 9:55 am, edited 2 times in total.
I abandoned all of my mods.

Locked

Return to “[3.0.x] MOD Requests”

Who is online

Users browsing this forum: Exabot [Bot] and 25 guests