Code: Select all
if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
{
//Put your code where moderators/admins are not affected
}
Will this also lock topics which already are posted?mtrs wrote:I tested a shorter code for this.
Open
posting.php
FindBefore addCode: Select all
// Determine some vars
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
I helped someone with a similar task in this topic: http://www.phpbb.com/community/viewtopi ... &t=1753855Brian 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
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
FindAdd afterCode: Select all
$current_time = time();
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
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);
}
}
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);
}
}
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)
How can I modify this code to make it close topics older than 7 days?I tested a shorter code for this.
Open
posting.php
FindBefore addCode: Select all
// Determine some vars
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.');
Rattus Norvegicus wrote:Never mind...
This code does the job
I've put it in the viewtopic.php right before the lines: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); } }
There might be a better place to put it in the viewtopic.php file, but my selection seems ok.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)