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)
Suggested Hosts
User avatar
SuperMaurim®
Registered User
Posts: 12
Joined: Thu Aug 07, 2008 1:28 pm

Re: Auto lock topic

Post by SuperMaurim® »

I did not understand, can you clarify?
There is the code: / / Begin: Lock old topics in my file.
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Auto lock topic

Post by mtrs »

I updated the code: http://www.phpbb.com/community/viewtopi ... #p10895205
Find code was wrong.
I abandoned all of my mods.
User avatar
SuperMaurim®
Registered User
Posts: 12
Joined: Thu Aug 07, 2008 1:28 pm

Re: Auto lock topic

Post 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?
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Auto lock topic

Post 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
	}
I abandoned all of my mods.
User avatar
SuperMaurim®
Registered User
Posts: 12
Joined: Thu Aug 07, 2008 1:28 pm

Re: Auto lock topic

Post by SuperMaurim® »

Again thank you! I had forgotten the privilege of moderators and administrators. Congratulations on the code.
rokhstar
Registered User
Posts: 11
Joined: Tue Oct 06, 2009 2:46 pm

Re: Auto lock topic

Post 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?
rokhstar
Registered User
Posts: 11
Joined: Tue Oct 06, 2009 2:46 pm

Re: Auto lock topic

Post 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?
Brian O'Kelly
Registered User
Posts: 12
Joined: Sat Oct 24, 2009 2:36 pm

Re: Auto lock topic

Post 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
Anyasha
Registered User
Posts: 704
Joined: Mon Aug 07, 2006 4:02 am
Name: Anyasha

Re: Auto lock topic

Post 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
Kiss me, I'm Polish!
T-Flash
Registered User
Posts: 2
Joined: Sat Jan 23, 2010 2:41 pm

Re: Auto lock topic

Post 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
User avatar
azybat
Registered User
Posts: 12
Joined: Mon May 03, 2010 11:15 am
Location: Russia
Name: Alex

Re: Auto lock topic

Post by azybat »

hello there!
is any mod can lock the topic by time or still not?
thx for any answers and stuff
My phpBB based portal is 2Cool.ru and Real Estate forum
Rattus Norvegicus
Registered User
Posts: 5
Joined: Wed Apr 20, 2011 9:06 pm

Re: Auto lock topic

Post 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?
Rattus Norvegicus
Registered User
Posts: 5
Joined: Wed Apr 20, 2011 9:06 pm

Re: Auto lock topic

Post 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.
Altutto
Registered User
Posts: 19
Joined: Wed Jul 17, 2013 9:11 am

Re: Auto lock topic

Post 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?
corleoner
Registered User
Posts: 189
Joined: Wed Jan 29, 2014 9:57 pm

Re: Auto lock topic

Post 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!

Return to “[3.0.x] MOD Requests”