diff options
| author | Savetheinternet <savetheinternet@n0v4.com> | 2011-01-21 13:14:55 +1100 |
|---|---|---|
| committer | Savetheinternet <savetheinternet@n0v4.com> | 2011-01-21 13:14:55 +1100 |
| commit | 67148f28463f8d4f2b7b61d38aa5d71df9658e4c (patch) | |
| tree | f500f0f9e21604e2f3d9017566ff31acc54d8bfc /inc | |
| parent | ec34fa8076985bf16cf82675fa490860214a486d (diff) | |
...
Diffstat (limited to 'inc')
| -rw-r--r-- | inc/display.php | 13 | ||||
| -rw-r--r-- | inc/functions.php | 36 | ||||
| -rw-r--r-- | inc/mod.php | 37 |
3 files changed, 49 insertions, 37 deletions
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 = '<div class="post reply"' . (!$index?' id="reply_' . $this->id . '"':'') . '>' . - '<p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>'; + '<p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>' . + // Delete + '<input type="checkbox" class="delete" name="delete_' . $this->id . '" id="delete_' . $this->id . '" /><label for="delete_' . $this->id . '">'; // Subject if(!empty($this->subject)) @@ -135,6 +137,9 @@ // Date/time $built .= ' ' . date(POST_DATE, $this->time); + // End delete + $built .= '</label>'; + $built .= ' <a class="post_no"' . // JavaScript highlight ($index?'':' onclick="highlightReply(' . $this->id . ');"') . @@ -266,6 +271,9 @@ $built .= '<div class="post op"><p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>'; + // Delete + $built .= '<input type="checkbox" class="delete" name="delete_' . $this->id . '" id="delete_' . $this->id . '" /><label for="delete_' . $this->id . '">'; + // Subject if(!empty($this->subject)) $built .= '<span class="subject">' . $this->subject . '</span> '; @@ -289,6 +297,9 @@ // Date/time $built .= ' ' . date(POST_DATE, $this->time); + // End delete + $built .= '</label>'; + $built .= ' <a class="post_no"' . // JavaScript highlight ($index?'':' onclick="highlightReply(' . $this->id . ');"') . diff --git a/inc/functions.php b/inc/functions.php index 13f636e1..c9b85ad4 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -262,6 +262,42 @@ $query->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 @@ '</form>' . '</fieldset>'; } - - // 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 |
