Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: charlottezweb on October 04, 2005, 07:57:17 PM

Title: New users only able to reply to posts within last x days...
Post by: charlottezweb on October 04, 2005, 07:57:17 PM
If this exists or has been requested before, sorry -- I wasn't sure how to search for something like this :)

I had a request on a board to make it so that new members have to have "x" amount of posts before they can reply to threads older than "x" days.

For example, we get some new sign-ups there who reply to posts that are years old thus digging them up becomes a nuissance to regular members. They would like to set a requirement so that you have to have, say, 100 posts before you can reply to posts beyond x (90?) days. 

It would be nice to have this as a mod or built-in feature where you can specify the posts required by the user and the number of days old the posts have to be in order for them to reply.

Hope that makes sense!  ;D
Title: Re: New users only able to reply to posts within last x days...
Post by: Oldiesmann on October 05, 2005, 01:13:04 PM
Not too hard to do. However, do you mean the time since the last reply or the time since the topic was started?
Title: Re: New users only able to reply to posts within last x days...
Post by: Ivan Minic on October 05, 2005, 01:23:14 PM
Last reply..
I had few ideas but were unable to complete because of that..
Title: Re: New users only able to reply to posts within last x days...
Post by: charlottezweb on October 05, 2005, 01:37:32 PM
Quote from: Ivan Minic on October 05, 2005, 01:23:14 PM
Last reply..

Exactly.  If a post hasn't been replied to in x amount of days, someone with less than y posts should not have the ability to post a reply.

(edit, fixed word)
Title: Re: New users only able to reply to posts within last x days...
Post by: Oldiesmann on October 05, 2005, 02:24:08 PM
Ok. Easy to do :)

Sources/Display.php

Find
// The start isn't a number; it's information about what to do, where to go.

Add before that
// Figure out when the topic was last replied to...
$request = db_query("
SELECT
m.posterTime, t.ID_LAST_MSG
FROM {$db_prefix}messages AS m, {$db_prefix}topics AS t
WHERE t.ID_TOPIC = $topic
AND m.ID_MSG = t.ID_LAST_MSG", __FILE__, __LINE__);
$topiclastreplied = mysql_result($request, 0);


Then find
$context['can_reply'] &= empty($topicinfo['locked']) || allowedTo('moderate_board');

And add after that
if(!$user_info['is_guest'])
$context['can_reply'] &= (floor((time() - $topiclastreplied) / 84600) < 90 || $user_info['posts'] > 99);


Or, if you want to do it differently for each group:
if(!$user_info['is_guests'])
{
if($user_info['posts'] < 100))
{
$days = 90;
}
elseif($user_info['posts'] < 200)
{
$days = 100;
}
...

$timediff = floor((time() - $topiclastreplied) / 84600);
$context['can_reply'] &= $timediff < $days;
}


Just continue the pattern above.
Title: Re: New users only able to reply to posts within last x days...
Post by: charlottezweb on October 08, 2005, 11:58:17 AM
Worked perfectly -- THANKS so much!!

-Jason
Title: Re: New users only able to reply to posts within last x days...
Post by: Septimus on October 05, 2008, 01:15:26 AM
How do you do this in 2.0? Can you make it display a message telling them why they cannot reply?
Title: Re: New users only able to reply to posts within last x days...
Post by: Nathaniel on November 05, 2008, 05:44:54 AM
Edits to the 'Display.php' file, for SMF 2 Beta.

Find this code:
    // The start isn't a number; it's information about what to do, where to go.
Replace with this code:
        // Figure out when the topic was last replied to...
   $request = $smcFunc['db_query']('', '
        SELECT
            m.poster_time
        FROM {db_prefix}messages AS m, {db_prefix}topics AS t
        WHERE t.ID_TOPIC = {int:topic}
            AND m.id_msg = t.id_last_msg',
        array(
            'topic' => $topic,
        )
    );
    list($topiclastreplied) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
   
    // The start isn't a number; it's information about what to do, where to go.


Find this code:
    $context['can_reply'] &= empty($topicinfo['locked']) || allowedTo('moderate_board');
Replace with this code:
    $context['can_reply'] &= empty($topicinfo['locked']) || allowedTo('moderate_board');
    if(!$user_info['is_guest'])
        $context['can_reply'] &= (floor((time() - $topiclastreplied) / 84600) < 90 || $user_info['posts'] > 99);


You can change that last edit as required. :)