-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
49 changed files
with
1,422 additions
and
2,084 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,61 @@ | ||
<?php | ||
|
||
// Includes ------------------------------------------------------------------- | ||
require_once dirname(__FILE__).'/../includes/main.inc.php'; | ||
require_once __DIR__.'/../includes/config.inc.php'; | ||
require_once INCLUDES_DIR.'mysql.inc.php'; | ||
require_once INCLUDES_DIR.'usersystem.inc.php'; | ||
require_once INCLUDES_DIR.'forum.inc.php'; | ||
|
||
/** Input validation */ | ||
$post_id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT) ?? 0; | ||
$board = filter_input(INPUT_POST, 'board', FILTER_DEFAULT, FILTER_REQUIRE_SCALAR) ?? null; | ||
$redirect = base64url_decode(filter_input(INPUT_POST, 'url', FILTER_DEFAULT, FILTER_REQUIRE_SCALAR)) ?? '/forum.php'; | ||
|
||
// Error-Checking ------------------------------------------------------------- | ||
if($_POST['id'] == '') { | ||
if($post_id <= 0) { | ||
echo 'Fehler: $_POST[id] ist leer.'; | ||
exit; | ||
} | ||
|
||
$rs = Comment::getRecordset($_POST['id']); | ||
if($rs == false) { | ||
echo 'Post '.$_POST['id'].' existiert nicht'; | ||
exit; | ||
} | ||
/** Fetch Comment record */ | ||
$rs = Comment::getRecordset($post_id); | ||
|
||
if(($_SESSION['user_id'] != $rs['user_id'])) { | ||
echo 'Dieser Post ('.$_POST['id'].') gehört gar nicht dir, sondern'.$user->id2user($rs['user_id']); | ||
if(!$rs || empty($rs)) { | ||
echo 'Post '.$post_id.' existiert nicht'; | ||
exit; | ||
} | ||
|
||
$numchildren = Comment::getNumChildposts($_POST['board'], $_POST['id']); | ||
if($numchildren > 0) { | ||
echo 'Dieser Post ('.$_POST['id'].') hat noch '.$numchildren.' Kinder, du darfst ihn nicht löschen.'; | ||
if(($user->id !== intval($rs['user_id']))) { | ||
echo 'Dieser Post ('.$post_id.') gehört gar nicht dir, sondern'.$user->id2user(intval($rs['user_id'])); | ||
exit; | ||
} | ||
|
||
|
||
// Actions -------------------------------------------------------------------- | ||
|
||
// Brauchts nicht mehr wegen InnoDB-Relation | ||
// Delete read post-records | ||
//$sql = "delete from comments_unread where comment_id = ".$_POST['id']; | ||
//$db->query($sql, __FILE__, __LINE__); | ||
|
||
|
||
// Comment löschen | ||
$sql = "delete from comments where id = ".$_POST['id']; | ||
$db->query($sql, __FILE__, __LINE__); | ||
|
||
$numchildren = Comment::getNumChildposts($board, $post_id); | ||
if($numchildren > 0) { | ||
echo 'Dieser Post ('.$post_id.') hat noch '.$numchildren.' Kinder, du darfst ihn nicht löschen.'; | ||
exit; | ||
} else { | ||
// Comment löschen | ||
$sql = 'DELETE FROM comments WHERE id=?'; | ||
$db->query($sql, __FILE__, __LINE__, 'DELETE comment', [$post_id]); | ||
} | ||
|
||
// Threads fixen | ||
Thread::adjustThreadRecord($rs['board'], $rs['thread_id']); | ||
|
||
// todo: falls es ein thread war, comments_threads record löschen | ||
|
||
|
||
// last post setzen todo: müsste nicht _immer_ passieren | ||
$sql = | ||
"UPDATE comments_threads ct" | ||
." SET last_comment_id = (SELECT MAX(id) from comments c WHERE thread_id = ".$rs['thread_id']." AND c.board = ct.board)" | ||
." WHERE thread_id = ".$rs['thread_id']; | ||
$db->query($sql, __FILE__, __LINE__); | ||
// TODO falls es ein thread war, comments_threads record löschen | ||
|
||
// TODO last post setzen: müsste nicht _immer_ passieren | ||
$sql = 'UPDATE comments_threads ct SET last_comment_id=(SELECT MAX(id) from comments c WHERE thread_id=? AND c.board=ct.board) WHERE thread_id=?'; | ||
$db->query($sql, __FILE__, __LINE__, 'UPDATE comments_threads', [$rs['thread_id'], $rs['thread_id']]); | ||
|
||
// parent neu kompilieren | ||
if($rs['board'] != 'f' || $rs['parent_id'] > 1) { | ||
if($rs['parent_id'] > 1) { //$rs['board'] !== 'f' || | ||
Comment::compile_template($rs['thread_id'], $rs['parent_id'], $rs['board']); | ||
} | ||
|
||
// todo: wenns ein thread war, redirecten auf die Übersicht oder Startseite | ||
header("Location: ".base64url_decode($_POST['url'])); | ||
header("Location: ".$redirect); | ||
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.