diff --git a/js/ajax.js b/js/ajax.js index 56f0df5c..eccffdec 100644 --- a/js/ajax.js +++ b/js/ajax.js @@ -58,7 +58,19 @@ $(window).ready(function() { success: function(post_response) { if (post_response.error) { if (post_response.banned) { - // You are banned. Must post the form normally so the user can see the ban message. + // You are banned or warned. Must post the form normally so the user can see the ban message. + do_not_ajax = true; + $(form).find('input[type="submit"]').each(function() { + var $replacement = $(''); + $replacement.attr('name', $(this).attr('name')); + $replacement.val(submit_txt); + $(this) + .after($replacement) + .replaceWith($('').val(submit_txt)); + }); + $(form).submit(); + } else if (post_response.telegram) { + // You received a telegram. Must post the form normally so the user can see the telegram message. do_not_ajax = true; $(form).find('input[type="submit"]').each(function() { var $replacement = $(''); diff --git a/post.php b/post.php index fea3553f..b79880ed 100644 --- a/post.php +++ b/post.php @@ -1317,36 +1317,15 @@ if (isset($_POST['delete'])) { $query->execute() or error(db_error($query)); $telegrams = $query->fetchAll(PDO::FETCH_ASSOC); - if (count($telegrams) > 0) - goto skip_redirect; - - if (!isset($_POST['json_response'])) { - header('Location: ' . $redirect, true, $config['redirect_http']); - } else { - header('Content-Type: text/json; charset=utf-8'); - echo json_encode(array( - 'redirect' => $redirect, - 'noko' => $noko, - 'id' => $id - )); - } - skip_redirect: - - - if ($config['try_smarter'] && $post['op']) - $build_pages = range(1, $config['max_pages']); - - if ($post['op']) - clean($id); - - event('post-after', $post); - - buildIndex(); - if (count($telegrams) > 0) { $ids = implode(', ', array_map(function($x) { return (int)$x['id']; }, $telegrams)); query("UPDATE ``telegrams`` SET ``seen`` = 1 WHERE ``id`` IN({$ids})") or error(db_error()); - die(Element('page.html', array( + // Give JS users a redirect instead of an error + if (isset($_POST['json_response'])) { + header('Content-Type: text/json'); + echo json_encode(array('error' => true, 'telegram' => true)); + } else { + echo Element('page.html', array( 'title' => _('Important message from Moderation'), 'config' => $config, 'body' => Element('important.html', array( @@ -1354,18 +1333,47 @@ if (isset($_POST['delete'])) { 'redirect' => $redirect, 'telegrams' => $telegrams, )) - ))); + )); + } + } else { + if (!isset($_POST['json_response'])) { + header('Location: ' . $redirect, true, $config['redirect_http']); + } else { + header('Content-Type: text/json; charset=utf-8'); + echo json_encode(array( + 'redirect' => $redirect, + 'noko' => $noko, + 'id' => $id + )); + } } + if ($post['op']) { + clean($id); + + if ($config['try_smarter']) + $build_pages = range(1, $config['max_pages']); + } + + event('post-after', $post); + + // If this is a new thread or the poster is returning to the index, build it before they redirect + if ($post['op'] || !$noko) + buildIndex(); + // We are already done, let's continue our heavy-lifting work in the background (if we run off FastCGI) - if (function_exists('fastcgi_finish_request')) + if (function_exists('fastcgi_finish_request')) { @fastcgi_finish_request(); + } - if ($post['op']) + if (!$post['op'] && $noko) + buildIndex(); + + if ($post['op']) { rebuildThemes('post-thread', $board['uri']); - else + } else { rebuildThemes('post', $board['uri']); - + } } elseif (isset($_POST['appeal'])) { if (!isset($_POST['ban_id'])) error($config['error']['bot']);