Advertisement:

Author Topic: User Not Allowed to Edit Own Post After X Hours  (Read 34875 times)

Offline 127.0.0.1

  • Jr. Member
  • **
  • Posts: 265
  • Gender: Male
User Not Allowed to Edit Own Post After X Hours
« 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.

Code: [Select]
<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 :)

« Last Edit: September 22, 2004, 10:25:36 AM by 127.0.0.1 »

Offline andrea

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,324
  • Gender: Female
  • I'm a smiley.
    • Smiley Sets
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #1 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.
Andrea Hubacher
Ex Lead Support Specialist
www.simplemachines.org

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



Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #2 on: September 22, 2004, 02:23:30 PM »
Code: [Select]
<add after>
global $user_info;
</add after>

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

Code: [Select]
<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....

Code: [Select]
<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]

Offline 127.0.0.1

  • Jr. Member
  • **
  • Posts: 265
  • Gender: Male
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #3 on: September 22, 2004, 08:22:42 PM »
Alright. How does this look?

Code: [Select]
<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>

Offline A.M.A

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,133
  • Gender: Male
  • ..
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #4 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 :)
Really sorry .. real life is demanding my full attention .. will be back soon hopefully :)

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #5 on: September 22, 2004, 08:47:41 PM »
Alright. How does this look?

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

Code: [Select]
<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 ;).

Code: [Select]
<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]

Offline raedzaro

  • Jr. Member
  • **
  • Posts: 116
    • just to tell the world that I'm Jordanian
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #6 on: April 03, 2005, 08:17:11 AM »
what is the final change shall be done, I'm totally lost

Offline andrea

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,324
  • Gender: Female
  • I'm a smiley.
    • Smiley Sets
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #7 on: April 03, 2005, 01:36:05 PM »
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



Offline raedzaro

  • Jr. Member
  • **
  • Posts: 116
    • just to tell the world that I'm Jordanian
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #8 on: April 07, 2005, 06:57:34 AM »
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?

Offline raedzaro

  • Jr. Member
  • **
  • Posts: 116
    • just to tell the world that I'm Jordanian
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #9 on: June 13, 2005, 12:12:57 PM »
any one can till what is the final change I have to do?

Offline azuregenesis

  • Semi-Newbie
  • *
  • Posts: 86
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #10 on: June 23, 2005, 08:17:01 PM »
anyone?

nvm, got it :)
« Last Edit: June 24, 2005, 06:45:39 AM by azuregenesis »

Offline TarantinoArchives

  • Full Member
  • ***
  • Posts: 442
  • Gender: Male
  • Call it, friendo
    • The Quentin Tarantino Archives
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #11 on: July 02, 2005, 01:19:50 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?

Offline codenaught

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 14,653
  • Gender: Male
  • Formerly Known As akabugeyes
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #12 on: July 02, 2005, 01:34:13 PM »
Admin -> Posts and Topics
Dev Consultant
Former SMF Doc Coordinator

Offline TarantinoArchives

  • Full Member
  • ***
  • Posts: 442
  • Gender: Male
  • Call it, friendo
    • The Quentin Tarantino Archives
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #13 on: July 02, 2005, 01:44:21 PM »
Admin -> Posts and Topics

thanks. found it :-)
it's great to have that option now

Offline fiver

  • Jr. Member
  • **
  • Posts: 319
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #14 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.


« Last Edit: August 07, 2005, 03:28:03 PM by fivearts »

Offline bjp

  • Jr. Member
  • **
  • Posts: 163
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #15 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
« Last Edit: August 19, 2005, 04:22:34 AM by bjp »

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: User Not Allowed to Edit Own Post After X Hours
« Reply #16 on: September 09, 2005, 01:15:45 PM »
I'm afraid it's minutes not seconds.

-[Unknown]