• Welcome to Simple Machines Community Forum. Please login or sign up.
December 06, 2021, 01:56:13 PM

News:

Want to get involved in developing SMF, then why not lend a hand on our github!


User Not Allowed to Edit Own Post After X Hours

Started by 127.0.0.1, September 22, 2004, 10:24:01 AM

Previous topic - Next topic

127.0.0.1

September 22, 2004, 10:24:01 AM Last Edit: September 22, 2004, 10:25:36 AM by 127.0.0.1
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 :)


andrea

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.

Andrea Hubacher
Ex Lead Support Specialist
www.simplemachines.org

Personal Signature:
Most recent work:
10 Aqua Themes for SMF



[Unknown]

<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]

127.0.0.1

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>

A.M.A

I really like it very much .. thanks for sharing this tip .. one of the few things I loved in VB :)
Really sorry .. real life is demanding my full attention .. will be back soon hopefully :)

[Unknown]

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]

raedzaro

what is the final change shall be done, I'm totally lost

andrea

FYI: 1.1 will have this feature built in the standard distribution.

Andrea Hubacher
Ex Lead Support Specialist
www.simplemachines.org

Personal Signature:
Most recent work:
10 Aqua Themes for SMF



raedzaro

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?

raedzaro

any one can till what is the final change I have to do?

azuregenesis

June 23, 2005, 08:17:01 PM #10 Last Edit: June 24, 2005, 06:45:39 AM by azuregenesis
anyone?

nvm, got it :)

TarantinoArchives

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?

codenaught

Dev Consultant
Former SMF Doc Coordinator

TarantinoArchives

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

fiver

August 07, 2005, 02:39:11 PM #14 Last Edit: August 07, 2005, 03:28:03 PM by fivearts
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.



bjp

August 19, 2005, 03:47:20 AM #15 Last Edit: August 19, 2005, 04:22:34 AM by bjp
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

[Unknown]


Advertisement: