Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: 127.0.0.1 on September 22, 2004, 10:24:01 AM

Title: User Not Allowed to Edit Own Post After X Hours
Post by: 127.0.0.1 on September 22, 2004, 10:24:01 AM
Applying this modification will superficially disable regular users from modifying their own posts after xx hours. By superficially I mean, it only removes the modify link from their options. This does not effect mods or admins who are allowed to edit posts. I put this together in about 2 minutes so forgive me if there are errors. It seems to work for me so far.

SMF Version: 1.0 RC

* The default time limit to modify posts is set at 12 hours (43200 in unix time stamp). One hour in a unix time stamp is 3600. So to set your own time limit multipy 3600 by x hours.


<edit file>
Sources/Display.php
</edit file>

<search for>
function prepareDisplayContext($reset = false)
{
global $settings, $txt, $modSettings, $scripturl, $options;
global $themeUser, $context, $messages_request, $topic, $ID_MEMBER, $attachments;
</search for>

<add after>
global $user_info;
</add after>

<search for>
// Run BBC interpreter on the message.
$message['body'] = doUBBC($message['body'], $message['smileysEnabled']);
</search for>

<add after>

// Find the time differential from original post time to current time.
$time_difference = (time() + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600) - $message['posterTime'];
</add after>

<search for>
'can_modify' => allowedTo('modify_any') || (allowedTo('modify_replies') && $context['user']['started']) || (allowedTo('modify_own') && $message['ID_MEMBER'] == $ID_MEMBER),
</search for>

<replace>
'can_modify' => allowedTo('modify_any') || (allowedTo('modify_replies') && $context['user']['started']) || (allowedTo('modify_own') && $message['ID_MEMBER'] == $ID_MEMBER && $time_difference < 43200),
</replace>



Any corrections or additions are welcome :)

Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: andrea on September 22, 2004, 01:02:50 PM
Nice tip. I plan to activate something like this in my own forum.

You might want to add a similar check for deletion of own posts - user not allowed to delete own post after x hours.
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: [Unknown] on September 22, 2004, 02:23:30 PM
<add after>
global $user_info;
</add after>


You don't really need this, because...

<add after>

// Find the time differential from original post time to current time.
$time_difference = (time() + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600) - $message['posterTime'];
</add after>


You're overcomplicating it.  Times in the database are stored without the time offset, and so is time().  If you're comparing those two, there's no need to apply any offsets....

<add after>

// Find the time differential from original post time to current time.
$time_difference = time() - $message['posterTime'];
</add after>


The rest of it looks fine, of course, but there is another small problem; if I manually typed the correct URL, it would still allow me to edit.  This change would have to be made in Post.php, when checking permissions there.

-[Unknown]
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: 127.0.0.1 on September 22, 2004, 08:22:42 PM
Alright. How does this look?


<edit file>
Sources/Display.php
</edit file>

<search for>
// Run BBC interpreter on the message.
$message['body'] = doUBBC($message['body'], $message['smileysEnabled']);
</search for>

<add after>

// Find the time differential from original post time to current time.
$time_difference = time() - $message['posterTime'];
</add after>

<search for>
'can_modify' => allowedTo('modify_any') || (allowedTo('modify_replies') && $context['user']['started']) || (allowedTo('modify_own') && $message['ID_MEMBER'] == $ID_MEMBER),
</search for>

<replace>
'can_modify' => allowedTo('modify_any') || (allowedTo('modify_replies') && $context['user']['started']) || (allowedTo('modify_own') && $message['ID_MEMBER'] == $ID_MEMBER && $time_difference < 43200),
</replace>

<edit file>
Sources/Post.php
</edit file>

<search for>
// Editing a message...
elseif (isset($_REQUEST['msg']))
{
checkSession('get');

// Get the existing message.
$request = db_query("
SELECT
m.ID_MEMBER, m.modifiedTime, m.smileysEnabled, m.body,
</search for>

<replace>
// Editing a message...
elseif (isset($_REQUEST['msg']))
{
checkSession('get');

// Get the existing message.
$request = db_query("
SELECT
m.ID_MEMBER, m.modifiedTime, m.smileysEnabled, m.body, m.posterTime,
</replace>

<search for>
if ($row['ID_MEMBER'] == $ID_MEMBER && !allowedTo('modify_any'))
{
if ($row['ID_MEMBER_POSTER'] == $ID_MEMBER && !allowedTo('modify_own'))
isAllowedTo('modify_replies');
else
isAllowedTo('modify_own');
}
</search for>

<replace>
// Find the time differential from original post time to current time.
$time_difference = time() - $row['posterTime'];

if ($row['ID_MEMBER'] == $ID_MEMBER && !allowedTo('modify_any') &&  $time_difference < 43200)
{
if ($row['ID_MEMBER_POSTER'] == $ID_MEMBER && !allowedTo('modify_own'))
isAllowedTo('modify_replies');
else
isAllowedTo('modify_own');
}
</replace>
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: A.M.A on September 22, 2004, 08:35:14 PM
I really like it very much .. thanks for sharing this tip .. one of the few things I loved in VB :)
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: [Unknown] on September 22, 2004, 08:47:41 PM
Quote from: 127.0.0.1 on September 22, 2004, 08:22:42 PM
Alright. How does this look?

Pretty good - just one small nitpick......


<replace>
// Find the time differential from original post time to current time.
$time_difference = time() - $row['posterTime'];

if ($row['ID_MEMBER'] == $ID_MEMBER && !allowedTo('modify_any') &&  $time_difference < 43200)
{
if ($row['ID_MEMBER_POSTER'] == $ID_MEMBER && !allowedTo('modify_own'))
isAllowedTo('modify_replies');
else
isAllowedTo('modify_own');
}
</replace>


This means "if the time difference is that small, don't check their permissions.  Probably not what you were going for, but the logic is there ;).


<replace>
// Find the time differential from original post time to current time.
$time_difference = time() - $row['posterTime'];

if ($row['ID_MEMBER'] == $ID_MEMBER && $time_difference > 43200)
fatal_lang_error(1, false);

if ($row['ID_MEMBER'] == $ID_MEMBER && !allowedTo('modify_any'))
{
if ($row['ID_MEMBER_POSTER'] == $ID_MEMBER && !allowedTo('modify_own'))
isAllowedTo('modify_replies');
else
isAllowedTo('modify_own');
}
</replace>


This means, "if the difference is great, and they are the poster, DIE!!!"  It will affect administrators, though, so you might want to make it:

if ($row['ID_MEMBER'] == $ID_MEMBER && $time_difference > 43200 && !allowedTo('admin_forum'))

Or, for moderators:

if ($row['ID_MEMBER'] == $ID_MEMBER && $time_difference > 43200 && !allowedTo('modify_any'))

-[Unknown]
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: raedzaro on April 03, 2005, 08:17:11 AM
what is the final change shall be done, I'm totally lost
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: andrea on April 03, 2005, 01:36:05 PM
FYI: 1.1 will have this feature built in the standard distribution.
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: raedzaro on April 07, 2005, 06:57:34 AM
Quote from: andrea on April 03, 2005, 01:36:05 PM
FYI: 1.1 will have this feature built in the standard distribution.
Thanx Andea for Information but what shall I do to activate this feature on my form till final SMF 1.1 released to All users?
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: raedzaro on June 13, 2005, 12:12:57 PM
any one can till what is the final change I have to do?
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: azuregenesis on June 23, 2005, 08:17:01 PM
anyone?

nvm, got it :)
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: TarantinoArchives on July 02, 2005, 01:19:50 PM
Quote from: andrea on April 03, 2005, 01:36:05 PM
FYI: 1.1 will have this feature built in the standard distribution.

i have beta 1.1p installed. where can i set a time after that a user can't modify anymore?
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: codenaught on July 02, 2005, 01:34:13 PM
Admin -> Posts and Topics
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: TarantinoArchives on July 02, 2005, 01:44:21 PM
Quote from: akabugeyes on July 02, 2005, 01:34:13 PM
Admin -> Posts and Topics

thanks. found it :-)
it's great to have that option now
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: fiver on August 07, 2005, 02:39:11 PM
I have 1.1b3p installed.

How do I assign different timing to different groups?

Eg.
Those with 1-10 posts cannot edit.
Those with 10 posts will have 10 mins to edit.
Those with 60+ post will have 60 mins to edit.
and maybe, those with 1000+ post will have no time limit.


Oooops! Just realise it's Tips and Trick forum and no question allowed. :P

Time to go to bed.


Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: bjp on August 19, 2005, 03:47:20 AM
Sorry but with smf 1.0 beta this option is not working for me. members can always modify there message after le time.

In Admin -> Posts and Topics
I switch it to 600 sc, but even after this time, régular member can modify ?

In display template, i'ts exactly the same as défaut template :

if ($message['can_modify'])
         echo '
                           <a href="', $scripturl, '?action=post;msg=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], ';sesc=', $context['session_id'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/modify.gif" alt="' . $txt[66] . '" border="0" />' : $txt[17]), '</a>';

In display.php (source), it seems that this code is not working:

'can_modify' => allowedTo('modify_any') || (allowedTo('modify_replies') && $context['user']['started']) || (allowedTo('modify_own') && $message['ID_MEMBER'] == $ID_MEMBER && (empty($modSettings['edit_disable_time']) || $message['posterTime'] + $modSettings['edit_wait_time'] * 60 > time())),

I ckeck in sql, smf setting, there the good setting :  edit_disable_time 30

My forum is french language, maybe it's a probleme of time setting ?
I say this because of my time : %d %B %Y &agrave; %H:%M:%S
Title: Re: User Not Allowed to Edit Own Post After X Hours
Post by: [Unknown] on September 09, 2005, 01:15:45 PM
I'm afraid it's minutes not seconds.

-[Unknown]