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 :)
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.
<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]
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>
I really like it very much .. thanks for sharing this tip .. one of the few things I loved in VB :)
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]
what is the final change shall be done, I'm totally lost
FYI: 1.1 will have this feature built in the standard distribution.
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?
any one can till what is the final change I have to do?
anyone?
nvm, got it :)
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?
Admin -> Posts and Topics
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
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.
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 à %H:%M:%S
I'm afraid it's minutes not seconds.
-[Unknown]