Page 3 of 3

Re: Auto lock topic

Posted: Fri Oct 02, 2009 12:50 am
by SuperMaurim®
I did not understand, can you clarify?
There is the code: / / Begin: Lock old topics in my file.

Re: Auto lock topic

Posted: Fri Oct 02, 2009 6:36 am
by mtrs
I updated the code: http://www.phpbb.com/community/viewtopi ... #p10895205
Find code was wrong.

Re: Auto lock topic

Posted: Fri Oct 02, 2009 1:16 pm
by SuperMaurim®
It worked perfectly, thanks mtrs! But I would like moderators and administrators were not affected, as was the first code. You can, please help me?

Re: Auto lock topic

Posted: Fri Oct 02, 2009 1:36 pm
by mtrs
Moderators can reply to a locked topic, then unlock the topic.
or

Code: Select all

	if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
	{
		//Put your code where moderators/admins are not affected
	}

Re: Auto lock topic

Posted: Fri Oct 02, 2009 4:13 pm
by SuperMaurim®
Again thank you! I had forgotten the privilege of moderators and administrators. Congratulations on the code.

Re: Auto lock topic

Posted: Mon Oct 19, 2009 3:00 pm
by rokhstar
mtrs wrote: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' && 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
Will this also lock topics which already are posted?

Re: Auto lock topic

Posted: Tue Oct 20, 2009 9:26 am
by rokhstar
It seems to be working. But doesnt lock with the "locked button". :) Its okay with me.
But is it somehow possible for admins and moderators to avoid being affected by it?

Re: Auto lock topic

Posted: Sun Oct 25, 2009 10:22 pm
by Brian O'Kelly
I am trying to configure this so a topic will be locked within seconds after posting... and only in specified forums. Basically I want the user to post and then the topic to lock automatically so it cannot be replied to.

Any chance on getting a bit of help with the code for this??
Thanks

Re: Auto lock topic

Posted: Wed Oct 28, 2009 4:44 am
by Anyasha
Brian O'Kelly wrote:I am trying to configure this so a topic will be locked within seconds after posting... and only in specified forums. Basically I want the user to post and then the topic to lock automatically so it cannot be replied to.

Any chance on getting a bit of help with the code for this??
Thanks
I helped someone with a similar task in this topic: http://www.phpbb.com/community/viewtopi ... &t=1753855

Re: Auto lock topic

Posted: Sat Jan 23, 2010 2:49 pm
by T-Flash
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      

Hello,
I have a question there.
Used that code everything works and its really fine. I liked your job!

But there is only one problem if you can say me how its fixable I will be really happy.

When a user press more then 1 time on reply or locked button they see the error message on old topics.
But admins see more then 1 time a entry on ACP over moderation logs. If its possible to fix it? that only admins have to see it 1 time and not multiplie entrys ? Some dont want to see it more then 1 time because its only spam up the log overview.


And second: Is it possible to lock the topics immediatly ?
Maybe its possible to make a code that admins can press on one button over acp and all old topics get closed.
Because the spam in moderation logs is really bad and one of these 2 things have to be fixed up ... so thats only my last problem which I have now.

I need any help.
I will be very happy if anyone can help me by that question!


Thanks & Best regards
T-Flash

Re: Auto lock topic

Posted: Sun Nov 07, 2010 1:34 pm
by azybat
hello there!
is any mod can lock the topic by time or still not?
thx for any answers and stuff

Re: Auto lock topic

Posted: Fri Apr 22, 2011 9:33 pm
by Rattus Norvegicus
I have been looking at the codes in this topic, and now i'm trying to make my own (I'm a complete newbie).

My goal is to auto lock topics older than 90 days when users enters them, and only in a few specific forums.

For that, I have put this code in the viewtopic.php:

Code: Select all

$excluded_forum_ids = array(149);
if (in_array($forum_id, $excluded_forum_ids))
{

       if (isset($topic_data['topic_last_post_time']) < time() - 7776000)
       {

          $sql = 'UPDATE ' . TOPICS_TABLE . "
             SET topic_status = " . ITEM_LOCKED . "
             WHERE topic_id = $topic_id";
          $db->sql_query($sql);

       }
}
It does only lock topics in the specified forum id 149, but instead of only locking those topics older than 90 days it locks EVERY topic, even the new ones.

Please help me figuring out what causes this huge problem?

Re: Auto lock topic

Posted: Sat Apr 23, 2011 2:28 am
by Rattus Norvegicus
Never mind...

This code does the job :mrgreen:

Code: Select all

$excluded_forum_ids = array(149);
if (in_array($forum_id, $excluded_forum_ids))
{

$sql = 'SELECT topic_last_post_time
            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'];
        }
        $db->sql_freeresult($result);
                  
        if ((time() - $topic_age) > 47520000 )
        {
            $sql = 'UPDATE ' . TOPICS_TABLE . "
                SET topic_status = " . ITEM_LOCKED . "
                WHERE topic_id = $topic_id";
            $db->sql_query($sql);            
        }
}
I've put it in the viewtopic.php right before the lines:

Code: Select all

// This rather complex gaggle of code handles querying for topics but
// also allows for direct linking to a post (and the calculation of which
// page the post is on and the correct display of viewtopic)
There might be a better place to put it in the viewtopic.php file, but my selection seems ok.

Re: Auto lock topic

Posted: Wed Jul 17, 2013 9:22 am
by Altutto
Sorry for bumping this old topic.
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.');
How can I modify this code to make it close topics older than 7 days?

Re: Auto lock topic

Posted: Mon Nov 30, 2015 9:40 pm
by corleoner
Rattus Norvegicus wrote:Never mind...

This code does the job :mrgreen:

Code: Select all

$excluded_forum_ids = array(149);
if (in_array($forum_id, $excluded_forum_ids))
{

$sql = 'SELECT topic_last_post_time
            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'];
        }
        $db->sql_freeresult($result);
                  
        if ((time() - $topic_age) > 47520000 )
        {
            $sql = 'UPDATE ' . TOPICS_TABLE . "
                SET topic_status = " . ITEM_LOCKED . "
                WHERE topic_id = $topic_id";
            $db->sql_query($sql);            
        }
}
I've put it in the viewtopic.php right before the lines:

Code: Select all

// This rather complex gaggle of code handles querying for topics but
// also allows for direct linking to a post (and the calculation of which
// page the post is on and the correct display of viewtopic)
There might be a better place to put it in the viewtopic.php file, but my selection seems ok.

This seemed to fix my issue from the previous topic which I posted in last night.

Thank you!