From 915dcc55ebfcdb441f4b0efee90b12334718b9bd Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 20 Jan 2011 19:35:41 +1100 Subject: Added styles and yotsuba.css --- main.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'main.js') diff --git a/main.js b/main.js index d0b0e0d6..dd46cd18 100644 --- a/main.js +++ b/main.js @@ -24,8 +24,49 @@ function citeReply(id) { document.getElementById('body').value += '>>' + id + '\n'; } +var selectedstyle = 'Yotsuba B'; +var styles = [ + ['Yotsuba B', '/default.css'], + ['Yotsuba', '/yotsuba.css'] +]; + +function changeStyle(x) { + localStorage.stylesheet = styles[x][1]; + document.getElementById('stylesheet').href = styles[x][1]; + selectedstyle = styles[x][0]; +} + +newLink = document.createElement('link'); +newLink.rel = 'stylesheet'; +newLink.type = 'text/css'; +newLink.id = 'stylesheet'; +document.getElementsByTagName('head')[0].insertBefore(newLink, document.getElementsByTagName('link')[0].lastChild) + +if(localStorage.stylesheet) { + for(x=0;x Date: Fri, 21 Jan 2011 13:14:55 +1100 Subject: ... --- default.css | 0 inc/display.php | 13 ++++++++++++- inc/functions.php | 36 ++++++++++++++++++++++++++++++++++++ inc/mod.php | 37 +------------------------------------ main.js | 23 +++++++++++++++++++++-- style.css | 13 ++++++++++++- 6 files changed, 82 insertions(+), 40 deletions(-) create mode 100644 default.css (limited to 'main.js') diff --git a/default.css b/default.css new file mode 100644 index 00000000..e69de29b diff --git a/inc/display.php b/inc/display.php index 66637d0d..0678cef7 100644 --- a/inc/display.php +++ b/inc/display.php @@ -110,7 +110,9 @@ global $board; $built = '
' . - '

'; + '

' . + // Delete + ''; + $built .= ' '; + // Delete + $built .= ''; + $built .= ' execute() or error(db_error($query)); } + // Remove file from post + function deleteFile($id, $remove_entirely_if_already=true) { + global $board; + + $query = prepare(sprintf("SELECT `thread`,`thumb`,`file` FROM `posts_%s` WHERE `id` = :id AND `thread` IS NOT NULL LIMIT 1", $board['uri'])); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + if($query->rowCount() < 1) { + error(ERROR_INVALIDPOST); + } + + $post = $query->fetch(); + + $query = prepare(sprintf("UPDATE `posts_%s` SET `thumb` = NULL, `thumbwidth` = NULL, `thumbheight` = NULL, `filewidth` = NULL, `fileheight` = NULL, `filesize` = NULL, `filename` = NULL, `filehash` = NULL, `file` = :file WHERE `id` = :id OR `thread` = :id", $board['uri'])); + if($post['file'] == 'deleted' && $remove_entirely_if_already) { + // Already deleted; remove file fully + $query->bindValue(':file', null, PDO::PARAM_NULL); + } else { + // Delete thumbnail + @unlink($board['dir'] . DIR_THUMB . $post['thumb']); + + // Delete file + @unlink($board['dir'] . DIR_IMG . $post['file']); + + // Set file to 'deleted' + $query->bindValue(':file', 'deleted', PDO::PARAM_INT); + } + // Update database + + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + buildThread($post['thread']); + } + // Delete a post (reply or thread) function deletePost($id) { global $board; diff --git a/inc/mod.php b/inc/mod.php index 5e3a2c87..5a3e6157 100644 --- a/inc/mod.php +++ b/inc/mod.php @@ -173,40 +173,5 @@ '' . ''; } - - // Remove file from post - function deleteFile($id) { - global $board; - - $query = prepare(sprintf("SELECT `thread`,`thumb`,`file` FROM `posts_%s` WHERE `id` = :id AND `thread` IS NOT NULL LIMIT 1", $board['uri'])); - $query->bindValue(':id', $id, PDO::PARAM_INT); - $query->execute() or error(db_error($query)); - - if($query->rowCount() < 1) { - error(ERROR_INVALIDPOST); - } - - $post = $query->fetch(); - - $query = prepare(sprintf("UPDATE `posts_%s` SET `thumb` = NULL, `thumbwidth` = NULL, `thumbheight` = NULL, `filewidth` = NULL, `fileheight` = NULL, `filesize` = NULL, `filename` = NULL, `filehash` = NULL, `file` = :file WHERE `id` = :id OR `thread` = :id", $board['uri'])); - if($post['file'] == 'deleted') { - // Already deleted; remove file fully - $query->bindValue(':file', null, PDO::PARAM_NULL); - } else { - // Delete thumbnail - @unlink($board['dir'] . DIR_THUMB . $post['thumb']); - - // Delete file - @unlink($board['dir'] . DIR_IMG . $post['file']); - - // Set file to 'deleted' - $query->bindValue(':file', 'deleted', PDO::PARAM_INT); - } - // Update database - - $query->bindValue(':id', $id, PDO::PARAM_INT); - $query->execute() or error(db_error($query)); - - buildThread($post['thread']); - } + ?> \ No newline at end of file diff --git a/main.js b/main.js index dd46cd18..d0a82dda 100644 --- a/main.js +++ b/main.js @@ -14,9 +14,21 @@ function focusId(id) document.getElementById(id).focus(); init(); } + +function generatePassword() { + pass = ''; + chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+'; + for(i=0;i<8;i++) { + rnd = Math.floor(Math.random() * chars.length); + pass += chars.substring(rnd,rnd + 1); + } + return pass; +} + function dopost(form) { - localStorage.name = form.name.value; - localStorage.email = form.email.value; + localStorage.name = form.name.value.replace(/ ##.+$/, ''); + if(form.email.value != 'sage') + localStorage.email = form.email.value; return form.body.value != "" || (typeof form.thread != "undefined" && form.file.value != ""); } @@ -65,6 +77,13 @@ function init() newElement.appendChild(style); } + if(!localStorage.password) + localStorage.password = generatePassword(); + elements = document.getElementsByName('password'); + for(x=0;x Date: Fri, 11 Feb 2011 23:02:30 +1100 Subject: a Fixed delete by IP, plus a bunch of small stuff --- inc/functions.php | 12 ++++++++---- inc/mod.php | 12 +++++++++++- main.js | 7 +++++-- mod.php | 39 ++++++++++++++++++++++++++++++++++++++- post.php | 2 +- 5 files changed, 63 insertions(+), 9 deletions(-) (limited to 'main.js') diff --git a/inc/functions.php b/inc/functions.php index c9b85ad4..6901de62 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -299,7 +299,7 @@ } // Delete a post (reply or thread) - function deletePost($id) { + function deletePost($id, $error_if_doesnt_exist=true) { global $board; // Select post and replies (if thread) in one query @@ -308,7 +308,9 @@ $query->execute() or error(db_error($query)); if($query->rowCount() < 1) { - error(ERROR_INVALIDPOST); + if($error_if_doesnt_exist) + error(ERROR_INVALIDPOST); + else return false; } // Delete posts and maybe replies @@ -337,6 +339,8 @@ if(isset($rebuild)) { buildThread($rebuild); } + + return true; } function clean() { @@ -370,7 +374,7 @@ while($th = $query->fetch()) { $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $th['sticky'], $th['locked'], $mod ? '?/' : ROOT, $mod); - $posts = prepare(sprintf("SELECT `id`, `subject`, `email`, `name`, `trip`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename`,`ip` FROM `posts_%s` WHERE `thread` = ? ORDER BY `time` DESC LIMIT ?", $board['uri'])); + $posts = prepare(sprintf("SELECT `id`, `subject`, `email`, `name`, `trip`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename`,`ip` FROM `posts_%s` WHERE `thread` = ? ORDER BY `id` DESC LIMIT ?", $board['uri'])); $posts->bindValue(1, $th['id']); $posts->bindValue(2, THREADS_PREVIEW, PDO::PARAM_INT); $posts->execute() or error(db_error($posts)); @@ -859,7 +863,7 @@ switch($type) { case 'jpg': case 'jpeg': - if(!$image = imagecreatefromjpeg($source_pic)) { + if(!$image = @imagecreatefromjpeg($source_pic)) { unlink($source_pic); error(ERR_INVALIDIMG); } diff --git a/inc/mod.php b/inc/mod.php index 5a3e6157..115c595a 100644 --- a/inc/mod.php +++ b/inc/mod.php @@ -20,7 +20,7 @@ $query = prepare("SELECT `id`,`type` FROM `mods` WHERE `username` = :username AND `password` = :password LIMIT 1"); $query->bindValue(':username', $username); $query->bindValue(':password', $password); - $query->execute(); + $query->execute() or error(db_error($query)); if($user = $query->fetch()) { return $mod = Array( @@ -56,6 +56,16 @@ unset($_SESSION['mod']); } + function modLog($action) { + global $mod; + $query = prepare("INSERT INTO `modlogs` VALUES (:id, :ip, :time, :text)"); + $query->bindValue(':id', $mod['id'], PDO::PARAM_INT); + $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); + $query->bindValue(':time', time(), PDO::PARAM_INT); + $query->bindValue(':text', $action); + $query->execute() or error(db_error($query)); + } + if(isset($_COOKIE['mod']) && isset($_SESSION['mod']) && is_array($_SESSION['mod'])) { // Should be username:session hash $cookie = explode(':', $_COOKIE['mod']); diff --git a/main.js b/main.js index d0a82dda..038713cd 100644 --- a/main.js +++ b/main.js @@ -6,8 +6,11 @@ function highlightReply(id) if (divs[i].className.indexOf('post') != -1) divs[i].className = divs[i].className.replace(/highlighted/, ''); } - if (id) - document.getElementById('reply_'+id).className += ' highlighted'; + if (id) { + post = document.getElementById('reply_'+id); + if(post) + post.className += ' highlighted'; + } } function focusId(id) { diff --git a/mod.php b/mod.php index 43dd8d26..12b730a0 100644 --- a/mod.php +++ b/mod.php @@ -43,6 +43,8 @@ if(!login($_POST['username'], $_POST['password'])) loginForm(ERROR_INVALID, $_POST['username']); + modLog("Logged in."); + // Login successful // Set cookies setCookies(); @@ -295,6 +297,9 @@ } $query->execute() or error(db_error($query)); + // Record the action + modLog("Created a new board: {$b['title']}"); + // Open the board openBoard($b['uri']) or error("Couldn't open board after creation."); @@ -356,6 +361,10 @@ // Delete post deleteFile($post); + + // Record the action + modLog("Removed file from post #{$post}"); + // Rebuild board buildIndex(); @@ -377,6 +386,10 @@ // Delete post deletePost($post); + + // Record the action + modLog("Deleted post #{$post}"); + // Rebuild board buildIndex(); @@ -399,8 +412,12 @@ $query->bindValue(':id', $post, PDO::PARAM_INT); if($matches[2] == 'un') { + // Record the action + modLog("Unstickied post #{$post}"); $query->bindValue(':sticky', 0, PDO::PARAM_INT); } else { + // Record the action + modLog("Stickied post #{$post}"); $query->bindValue(':sticky', 1, PDO::PARAM_INT); } @@ -429,8 +446,12 @@ $query->bindValue(':id', $post, PDO::PARAM_INT); if($matches[2] == 'un') { + // Record the action + modLog("Unlocked post #{$post}"); $query->bindValue(':locked', 0, PDO::PARAM_INT); } else { + // Record the action + modLog("Locked post #{$post}"); $query->bindValue(':locked', 1, PDO::PARAM_INT); } @@ -454,10 +475,22 @@ if(!openBoard($boardName)) error(ERROR_NOBOARD); - $query = prepare(sprintf("SELECT `id` FROM `posts_%s` WHERE `ip` = (SELECT `ip` FROM `posts_%s` WHERE `id` = :id)", $board['uri'], $board['uri'])); + $query = prepare(sprintf("SELECT `ip` FROM `posts_%s` WHERE `id` = :id", $board['uri'])); $query->bindValue(':id', $post); $query->execute() or error(db_error($query)); + if(!$post = $query->fetch()) + error(ERROR_INVALIDPOST); + + $ip = $post['ip']; + + // Record the action + modLog("Deleted all posts by IP address: #{$ip}"); + + $query = prepare(sprintf("SELECT `id` FROM `posts_%s` WHERE `ip` = :ip", $board['uri'])); + $query->bindValue(':ip', $ip); + $query->execute() or error(db_error($query)); + if($query->rowCount() < 1) error(ERROR_INVALIDPOST); @@ -529,6 +562,10 @@ } else { $query->bindValue(':reason', null, PDO::PARAM_NULL); } + + // Record the action + modLog("Created a ban for {$_POST['ip']} with reason {$_POST['reason']}"); + $query->execute() or error(db_error($query)); // Delete too diff --git a/post.php b/post.php index 62260e1b..38599222 100644 --- a/post.php +++ b/post.php @@ -221,7 +221,7 @@ 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(strlen($post['body']) > MAX_BODY) error(ERROR_TOOLONGBODY); + 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')); -- cgit v1.3