Commit 5da996ae authored by Ruslan Kabalin's avatar Ruslan Kabalin

forum: display error if post is submitted after timeout (bug #731990)

Signed-off-by: default avatarRuslan Kabalin <ruslan.kabalin@luns.net.uk>
parent aeab55c2
......@@ -108,6 +108,10 @@ else { // edit post
else if ($moderator) {
$post->editrecord = true;
}
else if (user_can_edit_post($post->poster, $post->ctime, $USER->get('id'), false)) {
$SESSION->add_error_msg(get_string('postaftertimeout', 'interaction.forum', get_config_plugin('interaction', 'forum', 'postdelay')));
redirect('/interaction/forum/topic.php?id=' . $parent->topic);
}
else {
throw new AccessDeniedException(get_string('canteditpost', 'interaction.forum'));
}
......
......@@ -101,6 +101,10 @@ else { // edit topic
else if ($moderator) {
$topic->editrecord = true;
}
else if (user_can_edit_post($topic->poster, $topic->ctime, $USER->get('id'), false)) {
$SESSION->add_error_msg(get_string('postaftertimeout', 'interaction.forum', get_config_plugin('interaction', 'forum', 'postdelay')));
redirect('/interaction/forum/topic.php?id=' . $topicid);
}
else {
throw new AccessDeniedException(get_string('cantedittopic', 'interaction.forum'));
}
......
......@@ -117,6 +117,7 @@ $string['Open'] = 'Open';
$string['Order'] = 'Order';
$string['orderdescription'] = 'Choose where you want the forum to be ordered compared to the other forums';
$string['Post'] = 'Post';
$string['postaftertimeout'] = 'You have submitted your change after timeout of %s minutes. Your change has not been applied.';
$string['postbyuserwasdeleted'] = 'A post by %s was deleted';
$string['postdelay'] = 'Post Delay';
$string['postdelaydescription'] = 'The minimum time (in minutes) that must pass before a new post can be mailed out to forum subscribers. The author of a post may make edits during this time.';
......
......@@ -813,12 +813,16 @@ function user_can_access_forum($forumid, $userid=null) {
*
* @returns boolean
*/
function user_can_edit_post($poster, $posttime, $userid=null) {
function user_can_edit_post($poster, $posttime, $userid=null, $verifydelay=true) {
if (empty($userid)) {
global $USER;
$userid = $USER->get('id');
}
return $poster == $userid && $posttime > (time() - get_config_plugin('interaction', 'forum', 'postdelay') * 60);
$permitted = true;
if ($verifydelay) {
$permitted = $posttime > (time() - get_config_plugin('interaction', 'forum', 'postdelay') * 60);
}
return $poster == $userid && $permitted;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment