News:

SMF 2.1.6 has been released! Take it for a spin! Read more.

Main Menu

Set edit time by membergroup.

Started by Antechinus, April 02, 2010, 07:11:03 PM

Previous topic - Next topic

Antechinus

Need some tips on where to start with this.

What I want to do is have a short courtesy edit time for all members, so they can correct typos or whatever. But, I also want to be able to set an unlimited edit time for certain membergroups.

IOW, restricted time so idiots cannot go back and screw threads up or dishonestly change what they said after the fact, but with trusted groups having the ability to edit posted articles they wrote at any time.

Where do I start? :)

Arantor

* Arantor sees who it is and skips the otherwise obligatory mind reader gag.

What version of SMF?
Holder of controversial views, all of which my own.


Antechinus

Hell, you expect an ex-Senior Support Specialist to provide you with relevant details?

Errr, 1.1.x for now. ;D

Arantor

Well... ;D

There are, as ever with such things, two parts to it.

1. Setting/storing (depending on elegance, really) the rules for membergroups. If it's not going to change, it could just be hardcoded into the relevant places. Otherwise it gets a lot more complex because the rules for groups have to be stored somewhere, and an interface built (probably in the membergroups area).

2. The code in question are these four segments.

This one appears at ~589, ~674
if ($row['ID_MEMBER'] == $ID_MEMBER && !allowedTo('modify_any'))
{
// Give an extra five minutes over the disable time threshold, so they can type.
if (!empty($modSettings['edit_disable_time']) && $row['posterTime'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
fatal_lang_error('modify_post_time_passed', false);
elseif ($row['ID_MEMBER_POSTER'] == $ID_MEMBER && !allowedTo('modify_own'))
isAllowedTo('modify_replies');
else
isAllowedTo('modify_own');
}


This one at ~1262
if ($row['ID_MEMBER'] == $ID_MEMBER && !allowedTo('modify_any'))
{
if (!empty($modSettings['edit_disable_time']) && $row['posterTime'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
fatal_lang_error('modify_post_time_passed', false);
elseif ($row['ID_MEMBER_POSTER'] == $ID_MEMBER && !allowedTo('modify_own'))
isAllowedTo('modify_replies');
else
isAllowedTo('modify_own');
}
elseif ($row['ID_MEMBER_POSTER'] == $ID_MEMBER && !allowedTo('modify_any'))
{
isAllowedTo('modify_replies');

// If you're modifying a reply, I say it better be logged...
$moderationAction = true;
}
else
{
isAllowedTo('modify_any');

// Log it, assuming you're not modifying your own post.
if ($row['ID_MEMBER'] != $ID_MEMBER)
$moderationAction = true;
}


And this variation appears at ~2187
if (isset($_POST['message']) || isset($_POST['subject']) || isset($_POST['icon']))
{
if (!empty($row['locked']))
isAllowedTo('moderate_board');

if ($row['ID_MEMBER'] == $ID_MEMBER && !allowedTo('modify_any'))
{
if (!empty($modSettings['edit_disable_time']) && $row['posterTime'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
fatal_lang_error('modify_post_time_passed', false);
elseif ($row['ID_MEMBER_STARTED'] == $ID_MEMBER && !allowedTo('modify_own'))
isAllowedTo('modify_replies');
else
isAllowedTo('modify_own');
}
// Otherwise, they're locked out; someone who can modify the replies is needed.
elseif ($row['ID_MEMBER_STARTED'] == $ID_MEMBER && !allowedTo('modify_any'))
isAllowedTo('modify_replies');
else
isAllowedTo('modify_any');

// Only log this action if it wasn't your message.
$moderationAction = $row['ID_MEMBER'] != $ID_MEMBER;
}


The principle part is the first if statement, which catches edit time and checks all the permission permutations, but even before that it checks the edit time.

Essentially you'd want to replace $modSettings['edit_disable_time'] with a value you've arrived at - it's fine to soft-replace it in the code immediately before it.

Without knowing exactly what the rules are (primary group/secondary group? based on having a given permission or not? even having a new permission maybe? assigning by user id?) I can't direct you as to how best to approach it.
Holder of controversial views, all of which my own.


Antechinus

I'll skip the mind reader joke and just ask which file you found that code in. ;D

Anyway, for my purposes it could be hard coded. Basically I have two particular membergroups that are always set as secondary. They are the groups that I would want to set an unlimited edit time on.

Arantor

Crap I forgot that. It's Sources/Post.php.

Let's say for the sake of argument they are groups 10 and 11.

The quickest - though not necessarily the *cleanest* method - would be to add this little segment immediately before the blocks of code above, same segment, all four blocks. In short if it's a member of those groups, temporarily disable the edit time totally by removing the setting - good until the end of the page.


global $user_info;
if (!empty(array_intersect(array(10, 11), $user_info['groups'])) && !empty($modSettings['edit_disable_time']))
  unset($modSettings['edit_disable_time']);


The global probably isn't strictly necessary but this way we ensure $user_info is in scope.
Holder of controversial views, all of which my own.


Antechinus

Ok, looks good. Would there be any advantage in trying for a more elegant method? As long as there's no significant performance hit it shouldn't matter too much.

Arantor

There's no real performance hit at all, both groups are pretty small invariably, and it's only running when the user clicks edit, when the user clicks inline modify, or to save in either case; it's pretty lightweight generally.

A more elegant method would be applicable perhaps if it were a permission or you were doing staggering, e.g. groups x and y had 5 minutes, groups z and a had 10 minutes, groups b and c 20 minutes. But as it's normal or unlimited, there's really no need to get more complex than it needs to be.
Holder of controversial views, all of which my own.


Antechinus

Cool. Thanks. I'll give it a go later and see what happens.

Advertisement: