Page 2 of 3

Re: Auto lock topic

Posted: Sat Nov 22, 2008 10:09 am
by nl2dav
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);
            }   

Re: Auto lock topic

Posted: Sun Nov 23, 2008 11:03 am
by mtrs
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

Re: Auto lock topic

Posted: Sun Nov 23, 2008 8:25 pm
by Shining Phoenix
Whenever a user tried to quote a post, the forum said that it's too old, even when it wasn't. Any ideas?

Re: Auto lock topic

Posted: Sat Dec 20, 2008 5:51 am
by modtang
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?

Re: Auto lock topic

Posted: Sat Dec 20, 2008 10:35 am
by mtrs
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

Re: Auto lock topic

Posted: Wed Jan 21, 2009 10:05 am
by rae_rae
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";

?>

Re: Auto lock topic

Posted: Thu Jan 22, 2009 8:07 pm
by rae_rae
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

Re: Auto lock topic

Posted: Fri Jan 23, 2009 3:08 pm
by idiotnesia
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.

Re: Auto lock topic

Posted: Thu Mar 26, 2009 1:05 pm
by ibelphegor
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      

Re: Auto lock topic

Posted: Fri Mar 27, 2009 3:28 pm
by mtrs
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

}  

Re: Auto lock topic

Posted: Fri Mar 27, 2009 7:11 pm
by ibelphegor
Great! work perfect.. Thanks.

Re: Auto lock topic

Posted: Sat Jul 11, 2009 5:20 pm
by cfeedback
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.

Re: Auto lock topic

Posted: Mon Sep 21, 2009 11:36 pm
by ClubCalibra
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...

Re: Auto lock topic

Posted: Thu Oct 01, 2009 4:56 pm
by SuperMaurim®
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.

Re: Auto lock topic

Posted: Thu Oct 01, 2009 7:19 pm
by mtrs
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