Changed config to an array
This commit is contained in:
265
post.php
265
post.php
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
require 'inc/functions.php';
|
||||
require 'inc/display.php';
|
||||
require 'inc/config.php';
|
||||
if (file_exists('inc/instance-config.php')) {
|
||||
require 'inc/instance-config.php';
|
||||
}
|
||||
require 'inc/config.php';
|
||||
require 'inc/template.php';
|
||||
require 'inc/database.php';
|
||||
require 'inc/user.php';
|
||||
@@ -26,12 +26,12 @@
|
||||
if( !isset($_POST['board']) ||
|
||||
!isset($_POST['password'])
|
||||
)
|
||||
error(ERROR_BOT);
|
||||
error($config['error']['bot']);
|
||||
|
||||
$password = $_POST['password'];
|
||||
|
||||
if(empty($password))
|
||||
error(ERROR_INVALIDPASSWORD);
|
||||
error($config['error']['invalidpassword']);
|
||||
|
||||
$delete = Array();
|
||||
foreach($_POST as $post => $value) {
|
||||
@@ -45,15 +45,15 @@
|
||||
// Check if banned
|
||||
checkBan();
|
||||
|
||||
if(BLOCK_TOR && isTor())
|
||||
error(ERROR_TOR);
|
||||
if($config['block_tor'] && isTor())
|
||||
error($config['error']['tor']);
|
||||
|
||||
// Check if board exists
|
||||
if(!openBoard($_POST['board']))
|
||||
error(ERROR_NOBOARD);
|
||||
error($config['error']['noboard']);
|
||||
|
||||
if(empty($delete))
|
||||
error(ERROR_NODELETE);
|
||||
error($config['error']['nodelete']);
|
||||
|
||||
foreach($delete as &$id) {
|
||||
$query = prepare(sprintf("SELECT `password` FROM `posts_%s` WHERE `id` = :id", $board['uri']));
|
||||
@@ -62,7 +62,7 @@
|
||||
|
||||
if($post = $query->fetch()) {
|
||||
if(!empty($password) && $post['password'] != $password)
|
||||
error(ERROR_INVALIDPASSWORD);
|
||||
error($config['error']['invalidpassword']);
|
||||
|
||||
if(isset($_POST['file'])) {
|
||||
// Delete just the file
|
||||
@@ -79,9 +79,9 @@
|
||||
sql_close();
|
||||
|
||||
$is_mod = isset($_POST['mod']) && $_POST['mod'];
|
||||
$root = $is_mod ? ROOT . FILE_MOD . '?/' : ROOT;
|
||||
$root = $is_mod ? $config['root'] . $config['file_mod'] . '?/' : $config['root'];
|
||||
|
||||
header('Location: ' . $root . $board['dir'] . FILE_INDEX, true, REDIRECT_HTTP);
|
||||
header('Location: ' . $root . $board['dir'] . $config['file_index'], true, $config['redirect_http']);
|
||||
|
||||
} elseif(isset($_POST['post'])) {
|
||||
if( !isset($_POST['name']) ||
|
||||
@@ -90,7 +90,7 @@
|
||||
!isset($_POST['body']) ||
|
||||
!isset($_POST['board']) ||
|
||||
!isset($_POST['password'])
|
||||
) error(ERROR_BOT);
|
||||
) error($config['error']['bot']);
|
||||
|
||||
$post = Array('board' => $_POST['board']);
|
||||
|
||||
@@ -99,13 +99,13 @@
|
||||
$post['thread'] = round($_POST['thread']);
|
||||
} else $OP = true;
|
||||
|
||||
//if(!(($OP && $_POST['post'] == BUTTON_NEWTOPIC) ||
|
||||
// (!$OP && $_POST['post'] == BUTTON_REPLY)))
|
||||
// error(ERROR_BOT);
|
||||
if(!(($OP && $_POST['post'] == $config['button_newtopic']) ||
|
||||
(!$OP && $_POST['post'] == $config['button_reply'])))
|
||||
error($config['error']['bot']);
|
||||
|
||||
// Check the referrer
|
||||
if($OP) {
|
||||
if(!isset($_SERVER['HTTP_REFERER']) || !preg_match(URL_MATCH, $_SERVER['HTTP_REFERER'])) error(ERROR_BOT);
|
||||
if(!isset($_SERVER['HTTP_REFERER']) || !preg_match($config['url_match'], $_SERVER['HTTP_REFERER'])) error($config['error']['bot']);
|
||||
}
|
||||
|
||||
// TODO: Since we're now using static HTML files, we can't give them cookies on their first page view
|
||||
@@ -113,7 +113,7 @@
|
||||
|
||||
/*
|
||||
// Check if he has a valid cookie.
|
||||
if(!$user['valid']) error(ERROR_BOT);
|
||||
if(!$user['valid']) error($config['error']['bot']);
|
||||
|
||||
// Check how long he has been here.
|
||||
if(time()-$user['appeared']<LURKTIME) error(ERROR_LURK);
|
||||
@@ -125,25 +125,25 @@
|
||||
// Check if banned
|
||||
checkBan();
|
||||
|
||||
if(BLOCK_TOR && isTor())
|
||||
error(ERROR_TOR);
|
||||
if($config['block_tor'] && isTor())
|
||||
error($config['error']['tor']);
|
||||
|
||||
// Check if board exists
|
||||
if(!openBoard($post['board']))
|
||||
error(ERROR_NOBOARD);
|
||||
error($config['error']['noboard']);
|
||||
|
||||
if(ROBOT_ENABLE && $board['uri'] == ROBOT_BOARD && ROBOT_MUTE) {
|
||||
checkMute();
|
||||
}
|
||||
//if(ROBOT_ENABLE && $board['uri'] == ROBOT_BOARD && ROBOT_MUTE) {
|
||||
// checkMute();
|
||||
//}
|
||||
|
||||
//Check if thread exists
|
||||
if(!$OP && !threadExists($post['thread']))
|
||||
error(ERROR_NONEXISTANT);
|
||||
error($config['error']['nonexistant']);
|
||||
|
||||
// Check for a file
|
||||
if($OP) {
|
||||
if(!isset($_FILES['file']['tmp_name']) || empty($_FILES['file']['tmp_name']))
|
||||
error(ERROR_NOIMAGE);
|
||||
error($config['error']['noimage']);
|
||||
}
|
||||
|
||||
$post['name'] = (!empty($_POST['name'])?$_POST['name']:'Anonymous');
|
||||
@@ -155,43 +155,43 @@
|
||||
$post['has_file'] = $OP || !empty($_FILES['file']['tmp_name']);
|
||||
$post['mod'] = isset($_POST['mod']) && $_POST['mod'];
|
||||
|
||||
if(empty($post['body']) && FORCE_BODY)
|
||||
error(ERROR_TOOSHORTBODY);
|
||||
if(empty($post['body']) && $config['force_body'])
|
||||
error($config['error']['tooshortbody']);
|
||||
|
||||
if($post['mod']) {
|
||||
require 'inc/mod.php';
|
||||
if(!$mod) {
|
||||
// Liar. You're not a mod.
|
||||
error(ERROR_NOTAMOD);
|
||||
error($config['error']['notamod']);
|
||||
}
|
||||
|
||||
$post['sticky'] = $OP && isset($_POST['sticky']);
|
||||
$post['locked'] = $OP && isset($_POST['lock']);
|
||||
$post['raw'] = isset($_POST['raw']);
|
||||
|
||||
if($post['sticky'] && $mod['type'] < MOD_STICKY) error(ERROR_NOACCESS);
|
||||
if($post['locked'] && $mod['type'] < MOD_LOCK) error(ERROR_NOACCESS);
|
||||
if($post['raw'] && $mod['type'] < MOD_RAWHTML) error(ERROR_NOACCESS);
|
||||
if($post['sticky'] && $mod['type'] < $config['mod']['sticky']) error($config['error']['noaccess']);
|
||||
if($post['locked'] && $mod['type'] < $config['mod']['lock']) error($config['error']['noaccess']);
|
||||
if($post['raw'] && $mod['type'] < $config['mod']['rawhtml']) error($config['error']['noaccess']);
|
||||
}
|
||||
|
||||
// Check if thread is locked
|
||||
// but allow mods to post
|
||||
if(!$OP && (!$mod || $mod['type'] < MOD_POSTINLOCKED)) {
|
||||
if(!$OP && (!$mod || $mod['type'] < $config['mod']['postinlocked'])) {
|
||||
if(threadLocked($post['thread']))
|
||||
error(ERROR_LOCKED);
|
||||
error($config['error']['locked']);
|
||||
}
|
||||
|
||||
if($post['has_file']) {
|
||||
$size = $_FILES['file']['size'];
|
||||
if($size > MAX_FILESIZE)
|
||||
error(sprintf3(ERR_FILESIZE, array(
|
||||
if($size > $config['max_filesize'])
|
||||
error(sprintf3($config['error']['filesize'], array(
|
||||
'sz'=>commaize($size),
|
||||
'filesz'=>commaize($size),
|
||||
'maxsz'=>commaize(MAX_FILESIZE))));
|
||||
'maxsz'=>commaize($config['max_filesize']))));
|
||||
}
|
||||
|
||||
if($mod && $mod['type'] >= MOD_MOD && preg_match('/^((.+) )?## (.+)$/', $post['name'], $match)) {
|
||||
if(($mod['type'] == MOD_MOD && $match[3] == 'Mod') || $mod['type'] >= MOD_ADMIN) {
|
||||
if($mod && $mod['type'] >= MOD && preg_match('/^((.+) )?## (.+)$/', $post['name'], $match)) {
|
||||
if(($mod['type'] == MOD && $match[3] == 'Mod') || $mod['type'] >= ADMIN) {
|
||||
$post['mod_tag'] = $match[3];
|
||||
$post['name'] = !empty($match[2])?$match[2]:'Anonymous';
|
||||
}
|
||||
@@ -211,19 +211,17 @@
|
||||
if($post['has_file']) {
|
||||
$post['extension'] = strtolower(substr($post['filename'], strrpos($post['filename'], '.') + 1));
|
||||
$post['file_id'] = time() . rand(100, 999);
|
||||
$post['file'] = $board['dir'] . DIR_IMG . $post['file_id'] . '.' . $post['extension'];
|
||||
$post['thumb'] = $board['dir'] . DIR_THUMB . $post['file_id'] . '.png';
|
||||
$post['zip'] = $OP && $post['has_file'] && ALLOW_ZIP && $post['extension'] == 'zip' ? $post['file'] : false;
|
||||
if(!($post['zip'] || in_array($post['extension'], $allowed_ext))) error(ERROR_FILEEXT);
|
||||
$post['file'] = $board['dir'] . $config['dir']['img'] . $post['file_id'] . '.' . $post['extension'];
|
||||
$post['thumb'] = $board['dir'] . $config['dir']['thumb'] . $post['file_id'] . '.png';
|
||||
}
|
||||
|
||||
// Check string lengths
|
||||
if(strlen($post['name']) > 50) error(sprintf(ERROR_TOOLONG, 'name'));
|
||||
if(strlen($post['email']) > 30) error(sprintf(ERROR_TOOLONG, 'email'));
|
||||
if(strlen($post['subject']) > 40) error(sprintf(ERROR_TOOLONG, 'subject'));
|
||||
if(!$mod && strlen($post['body']) > MAX_BODY) error(ERROR_TOOLONGBODY);
|
||||
if(!(!$OP && $post['has_file']) && strlen($post['body']) < 1) error(ERROR_TOOSHORTBODY);
|
||||
if(strlen($post['password']) > 20) error(sprintf(ERROR_TOOLONG, 'password'));
|
||||
if(strlen($post['name']) > 50) error(sprintf($config['error']['toolong'], 'name'));
|
||||
if(strlen($post['email']) > 30) error(sprintf($config['error']['toolong'], 'email'));
|
||||
if(strlen($post['subject']) > 40) error(sprintf($config['error']['toolong'], 'subject'));
|
||||
if(!$mod && strlen($post['body']) > $config['max_body']) error($config['error']['toolongbody']);
|
||||
if(!(!$OP && $post['has_file']) && strlen($post['body']) < 1) error($config['error']['tooshortbody']);
|
||||
if(strlen($post['password']) > 20) error(sprintf($config['error']['toolong'], 'password'));
|
||||
|
||||
if($post['mod_tag'])
|
||||
$post['trip'] .= ' <a class="nametag">## ' . $post['mod_tag'] . '</a>';
|
||||
@@ -235,26 +233,14 @@
|
||||
|
||||
// Check for a flood
|
||||
if(checkFlood($post)) {
|
||||
error(ERROR_FLOOD);
|
||||
error($config['error']['flood']);
|
||||
}
|
||||
|
||||
if($post['has_file']) {
|
||||
// Just trim the filename if it's too long
|
||||
if(strlen($post['filename']) > 30) $post['filename'] = substr($post['filename'], 0, 27).'…';
|
||||
// Move the uploaded file
|
||||
if(!@move_uploaded_file($_FILES['file']['tmp_name'], $post['file'])) error(ERROR_NOMOVE);
|
||||
|
||||
if($post['zip']) {
|
||||
// Validate ZIP file
|
||||
if(is_resource($zip = zip_open($post['zip'])))
|
||||
// TODO: Check if it's not empty and has at least one (valid) image
|
||||
zip_close($zip);
|
||||
else
|
||||
error(ERR_INVALIDZIP);
|
||||
|
||||
$post['file'] = ZIP_IMAGE;
|
||||
$post['extension'] = strtolower(substr($post['file'], strrpos($post['file'], '.') + 1));
|
||||
}
|
||||
if(!@move_uploaded_file($_FILES['file']['tmp_name'], $post['file'])) error($config['error']['nomove']);
|
||||
|
||||
$size = @getimagesize($post['file']);
|
||||
$post['width'] = $size[0];
|
||||
@@ -263,165 +249,48 @@
|
||||
// Check if the image is valid
|
||||
if($post['width'] < 1 || $post['height'] < 1) {
|
||||
unlink($post['file']);
|
||||
error(ERR_INVALIDIMG);
|
||||
error($config['error']['invalidimg']);
|
||||
}
|
||||
|
||||
if($post['width'] > MAX_WIDTH || $post['height'] > MAX_HEIGHT) {
|
||||
if($post['width'] > $config['max_width'] || $post['height'] > $config['max_height']) {
|
||||
unlink($post['file']);
|
||||
error(ERR_MAXSIZE);
|
||||
error($config['error']['maxsize']);
|
||||
}
|
||||
|
||||
$hash_function = FILE_HASH;
|
||||
$post['filehash'] = $hash_function($post['file']);
|
||||
$post['filehash'] = $config['file_hash']($post['file']);
|
||||
$post['filesize'] = filesize($post['file']);
|
||||
|
||||
$image = createimage($post['extension'], $post['file']);
|
||||
|
||||
if(REDRAW_IMAGE && !$post['zip']) {
|
||||
switch($post['extension']) {
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
imagejpeg($image, $post['file'], JPEG_QUALITY);
|
||||
break;
|
||||
case 'png':
|
||||
imagepng($image, $post['file'], 7);
|
||||
break;
|
||||
case 'gif':
|
||||
if(REDRAW_GIF)
|
||||
imagegif($image, $post['file']);
|
||||
break;
|
||||
case 'bmp':
|
||||
imagebmp($image, $post['file']);
|
||||
break;
|
||||
default:
|
||||
unlink($post['file']);
|
||||
error('Unknwon file extension.');
|
||||
}
|
||||
}
|
||||
|
||||
// Create a thumbnail
|
||||
$thumb = resize($image, $post['width'], $post['height'], $post['thumb'], THUMB_WIDTH, THUMB_HEIGHT);
|
||||
$thumb = resize($image, $post['width'], $post['height'], $post['thumb'], $config['thumb_width'], $config['thumb_height']);
|
||||
|
||||
$post['thumbwidth'] = $thumb['width'];
|
||||
$post['thumbheight'] = $thumb['height'];
|
||||
}
|
||||
|
||||
if(!($mod && $mod['type'] >= MOD_POSTUNORIGINAL) && ROBOT_ENABLE && $board['uri'] == ROBOT_BOARD && checkRobot($post['body_nomarkup'])) {
|
||||
/*
|
||||
if(!($mod && $mod['type'] >= $config['mod']['postunoriginal']) && ROBOT_ENABLE && $board['uri'] == ROBOT_BOARD && checkRobot($post['body_nomarkup'])) {
|
||||
if(ROBOT_MUTE) {
|
||||
error(sprintf(ERROR_MUTED, mute()));
|
||||
error(sprintf($config['error']['muted'], mute()));
|
||||
} else {
|
||||
error(ERROR_UNORIGINAL);
|
||||
error($config['error']['unoriginal']);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Remove DIR_* before inserting them into the database.
|
||||
if($post['has_file']) {
|
||||
$post['file'] = substr_replace($post['file'], '', 0, strlen($board['dir'] . DIR_IMG));
|
||||
$post['thumb'] = substr_replace($post['thumb'], '', 0, strlen($board['dir'] . DIR_THUMB));
|
||||
$post['file'] = substr_replace($post['file'], '', 0, strlen($board['dir'] . $config['dir']['img']));
|
||||
$post['thumb'] = substr_replace($post['thumb'], '', 0, strlen($board['dir'] . $config['dir']['thumb']));
|
||||
}
|
||||
|
||||
// Todo: Validate some more, remove messy code, allow more specific configuration
|
||||
$id = post($post, $OP);
|
||||
|
||||
if($post['has_file'] && $post['zip']) {
|
||||
// Open ZIP
|
||||
$zip = zip_open($post['zip']);
|
||||
// Read files
|
||||
while($entry = zip_read($zip)) {
|
||||
$filename = basename(zip_entry_name($entry));
|
||||
$extension = strtolower(substr($filename, strrpos($filename, '.') + 1));
|
||||
|
||||
if(in_array($extension, $allowed_ext)) {
|
||||
if (zip_entry_open($zip, $entry, 'r')) {
|
||||
// Fake post
|
||||
$dump_post = Array(
|
||||
'subject' => $post['subject'],
|
||||
'email' => $post['email'],
|
||||
'name' => $post['name'],
|
||||
'trip' => $post['trip'],
|
||||
'body' => '',
|
||||
'thread' => $id,
|
||||
'password' => '',
|
||||
'has_file' => true,
|
||||
'file_id' => rand(0, 1000000000),
|
||||
'filename' => $filename
|
||||
);
|
||||
|
||||
$dump_post['file'] = $board['dir'] . DIR_IMG . $dump_post['file_id'] . '.' . $extension;
|
||||
$dump_post['thumb'] = $board['dir'] . DIR_THUMB . $dump_post['file_id'] . '.png';
|
||||
|
||||
// Extract the image from the ZIP
|
||||
$fp = fopen($dump_post['file'], 'w+');
|
||||
fwrite($fp, zip_entry_read($entry, zip_entry_filesize($entry)));
|
||||
fclose($fp);
|
||||
|
||||
$size = @getimagesize($dump_post['file']);
|
||||
$dump_post['width'] = $size[0];
|
||||
$dump_post['height'] = $size[1];
|
||||
|
||||
// Check if the image is valid
|
||||
if($dump_post['width'] < 1 || $dump_post['height'] < 1) {
|
||||
unlink($dump_post['file']);
|
||||
} else {
|
||||
if($dump_post['width'] > MAX_WIDTH || $dump_post['height'] > MAX_HEIGHT) {
|
||||
unlink($dump_post['file']);
|
||||
error(ERR_MAXSIZE);
|
||||
} else {
|
||||
$dump_post['filehash'] = md5_file($dump_post['file']);
|
||||
$dump_post['filesize'] = filesize($dump_post['file']);
|
||||
|
||||
$image = createimage($extension, $dump_post['file']);
|
||||
|
||||
$success = true;
|
||||
if(REDRAW_IMAGE) {
|
||||
switch($extension) {
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
imagejpeg($image, $dump_post['file'], JPEG_QUALITY);
|
||||
break;
|
||||
case 'png':
|
||||
imagepng($image, $dump_post['file'], 7);
|
||||
break;
|
||||
case 'gif':
|
||||
if(REDRAW_GIF)
|
||||
imagegif($image, $dump_post['file']);
|
||||
break;
|
||||
case 'bmp':
|
||||
imagebmp($image, $dump_post['file']);
|
||||
break;
|
||||
default:
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Create a thumbnail
|
||||
$thumb = resize($image, $dump_post['width'], $dump_post['height'], $dump_post['thumb'], THUMB_WIDTH, THUMB_HEIGHT);
|
||||
|
||||
$dump_post['thumbwidth'] = $thumb['width'];
|
||||
$dump_post['thumbheight'] = $thumb['height'];
|
||||
|
||||
// Remove DIR_* before inserting them into the database.
|
||||
$dump_post['file'] = substr_replace($dump_post['file'], '', 0, strlen($board['dir'] . DIR_IMG));
|
||||
$dump_post['thumb'] = substr_replace($dump_post['thumb'], '', 0, strlen($board['dir'] . DIR_THUMB));
|
||||
|
||||
// Create the post
|
||||
post($dump_post, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Close the ZIP
|
||||
zip_entry_close($entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
zip_close($zip);
|
||||
unlink($post['zip']);
|
||||
}
|
||||
|
||||
buildThread(($OP?$id:$post['thread']));
|
||||
|
||||
if(!$OP && strtolower($post['email']) != 'sage' && (REPLY_LIMIT == 0 || numPosts($post['thread']) < REPLY_LIMIT)) {
|
||||
if(!$OP && strtolower($post['email']) != 'sage' && ($config['reply_limit'] == 0 || numPosts($post['thread']) < $config['reply_limit'])) {
|
||||
bumpThread($post['thread']);
|
||||
}
|
||||
|
||||
@@ -431,17 +300,17 @@
|
||||
buildIndex();
|
||||
sql_close();
|
||||
|
||||
$root = $post['mod'] ? ROOT . FILE_MOD . '?/' : ROOT;
|
||||
$root = $post['mod'] ? $config['root'] . $config['file_mod'] . '?/' : $config['root'];
|
||||
|
||||
if(ALWAYS_NOKO || $noko) {
|
||||
header('Location: ' . $root . $board['dir'] . DIR_RES . ($OP?$id:$post['thread']) . '.html' . (!$OP?'#'.$id:''), true, REDIRECT_HTTP);
|
||||
if($config['always_noko'] || $noko) {
|
||||
header('Location: ' . $root . $board['dir'] . $config['dir']['res'] . ($OP?$id:$post['thread']) . '.html' . (!$OP?'#'.$id:''), true, $config['redirect_http']);
|
||||
} else {
|
||||
header('Location: ' . $root . $board['dir'] . FILE_INDEX, true, REDIRECT_HTTP);
|
||||
header('Location: ' . $root . $board['dir'] . $config['file_index'], true, $config['redirect_http']);
|
||||
}
|
||||
|
||||
exit;
|
||||
} else {
|
||||
if(!file_exists(HAS_INSTALLED)) {
|
||||
if(!file_exists($config['has_installed'])) {
|
||||
sql_open();
|
||||
|
||||
// Build all boards
|
||||
@@ -452,7 +321,7 @@
|
||||
}
|
||||
|
||||
sql_close();
|
||||
touch(HAS_INSTALLED, 0777);
|
||||
touch($config['has_installed'], 0777);
|
||||
|
||||
die(Element('page.html', Array(
|
||||
'index'=>ROOT,
|
||||
@@ -464,7 +333,7 @@
|
||||
} else {
|
||||
// They opened post.php in their browser manually.
|
||||
// Possible TODO: Redirect back to homepage.
|
||||
error(ERROR_NOPOST);
|
||||
error($config['error']['nopost']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user