Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### inc/functions.php:
- // the user is not currently logged in as a moderator
- $mod = false;
- +// Setting to true will cause error messages to be given as JSON.
- +$wantjson = false;
- +
- register_shutdown_function('fatal_error_handler');
- ...
- function displayBan($ban) {
- - global $config;
- + global $config, $wantjson;
- $ban['ip'] = $_SERVER['REMOTE_ADDR'];
- $banhtml = Element('page.html', array(
- 'title' => 'Banned!',
- 'config' => $config,
- 'body' => Element('banned.html', array(
- 'config' => $config,
- 'ban' => $ban
- ))));
- + if ($wantjson) {
- + header('Content-Type: application/json');
- + die(json_encode(array('error' => 'ban', 'banhtml' => $banhtml)));
- + }
- +
- die($banhtml);
- }
- ### inc/display.php:
- function error($message, $priority = true) {
- - global $board, $mod, $config;
- + global $board, $mod, $config, $wantjson;
- if ($config['syslog'] && $priority !== false) {
- ...
- if (defined('STDIN')) {
- // Running from CLI
- die('Error: ' . $message . "\n");
- }
- + if ($wantjson) {
- + header('Content-Type: application/json');
- + die(json_encode(array('error' => 'message', 'message' => _($message))));
- + }
- +
- die(Element('page.html', array(
- ### post.php:
- } elseif (isset($_POST['post'])) {
- + if (isset($_POST['wantjson']) && $_POST['wantjson'])
- + $wantjson = true;
- if (!isset($_POST['body'], $_POST['board']))
- error($config['error']['bot']);
- ...
- $root = $post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root'];
- - if ($config['always_noko'] || $noko) {
- + if ($wantjson || $config['always_noko'] || $noko) {
- $redirect = $root . $board['dir'] . $config['dir']['res'] .
- ...
- rebuildThemes('post');
- + if ($wantjson) {
- + $response = array();
- + $response['status'] = 'success';
- + $response['postid'] = intval($id);
- + $response['threadid'] = $post['op'] ? null : intval($post['thread']);
- + $response['board'] = $board['uri'];
- + $response['url'] = $redirect;
- +
- + header('Content-Type: application/json');
- + die(json_encode($response));
- + }
- header('Location: ' . $redirect, true, $config['redirect_http']);
- } else {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement