Implement feature for deleting posts and improving ajax requests
This commit is contained in:
@@ -211,6 +211,39 @@
|
||||
exit;
|
||||
}
|
||||
|
||||
if($post[0]['user_id'] != $_SESSION['user']['ID']) {
|
||||
echo json_encode(['success' => false, 'message' => 'Du kannst keine Posts löschen, die dir nicht gehören.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$post = $this->PostsModel->preparePostList($post);
|
||||
$body = $this->load->view('network/posts/delete_modal', ['post' => $post[0]], true);
|
||||
|
||||
echo json_encode(['success' => true, 'title' => 'Post löschen', 'body' => $body]);
|
||||
}
|
||||
|
||||
public function deletePost() {
|
||||
header('Content-Type: application/json');
|
||||
if(!isset($_SESSION['user'])) {
|
||||
echo json_encode(['success' => false, 'message' => 'Du musst eingeloggt sein, um die Posts deines Accounts zu löschen']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$uuid = $this->input->post('uuid');
|
||||
$post = $this->PostsModel->getPostByUUID($uuid);
|
||||
|
||||
if(empty($post)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Der angegebene Post existiert nicht.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if($post[0]['user_id'] != $_SESSION['user']['ID']) {
|
||||
echo json_encode(['success' => false, 'message' => 'Du kannst keine Posts löschen, die dir nicht gehören.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->PostsModel->deletePost($_SESSION['user']['ID'], $uuid);
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Der Post wurde erfolgreich gelöscht.']);
|
||||
}
|
||||
}
|
@@ -210,14 +210,13 @@
|
||||
Bitte erstelle dir entweder
|
||||
<a href="<?= base_url('login') ?>">kostenlos einen neuen Account</a>
|
||||
oder
|
||||
<a href="<?= base_url('login') ?>">melde dich an</a>.
|
||||
<a href="<?= base_url('login') ?>">melde dich an</a>
|
||||
.
|
||||
</div>
|
||||
<?php
|
||||
exit;
|
||||
}
|
||||
|
||||
var_dump($this->input->post('postMedia'));
|
||||
|
||||
$content = $this->input->post('content');
|
||||
if (strlen($content) >= 10000) {
|
||||
?>
|
||||
@@ -247,23 +246,25 @@
|
||||
}
|
||||
|
||||
$media = $this->input->post('postMedia');
|
||||
foreach ($media as $entry) {
|
||||
$image = str_replace(' ', '+', $entry['image']);
|
||||
$image = substr($image, strpos($image, ',') + 1);
|
||||
$image = base64_decode($image);
|
||||
if (!empty($media)) {
|
||||
foreach ($media as $entry) {
|
||||
$image = str_replace(' ', '+', $entry['image']);
|
||||
$image = substr($image, strpos($image, ',') + 1);
|
||||
$image = base64_decode($image);
|
||||
|
||||
$fileUrl = $this->FileModel->uploadFileByContent($image, $entry['name'], $entry['type'], $entry['size']);
|
||||
$fileUrl = $this->FileModel->uploadFileByContent($image, $entry['name'], $entry['type'], $entry['size']);
|
||||
|
||||
$this->PostsModel->addImageToPost($postID, $fileUrl);
|
||||
$this->PostsModel->addImageToPost($postID, $fileUrl);
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="alert alert-success" role="alert">
|
||||
<b>Dein Post wurde erfolgreich veröffentlicht!</b> Möchtest du nun deine Posts ansehen? <br>
|
||||
<button type="button" class="btn btn-sm btn-default" data-dismiss="modal">Nein</button>
|
||||
<a href='<?= base_url('user/' . $_SESSION['user']['username'] . '/posts') ?>' class='btn btn-sm btn-primary'>Ja</a>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="alert alert-success" role="alert">
|
||||
<b>Dein Post wurde erfolgreich veröffentlicht!</b> Möchtest du nun deine Posts ansehen? <br>
|
||||
<button type="button" class="btn btn-sm btn-default" data-dismiss="modal">Nein</button>
|
||||
<a href='<?= base_url('user/' . $_SESSION['user']['username'] . '/posts') ?>' class='btn btn-sm btn-primary'>Ja</a>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function followers($user = "")
|
||||
|
@@ -39,6 +39,15 @@
|
||||
return $insertedPost[0]['ID'];
|
||||
}
|
||||
|
||||
public function deletePost($userID, $uuid) {
|
||||
$postID = $this->db->query('SELECT ID FROM user_posts WHERE user_id = ? AND uuid = ?', [$userID, $uuid])->result_array()[0]['ID'];
|
||||
$this->db->query('DELETE FROM user_posts WHERE user_id = ? AND uuid = ?', [$userID, $uuid]);
|
||||
$this->db->query('DELETE FROM user_posts_hashtags WHERE postID = ?', [$postID]);
|
||||
$this->db->query('DELETE FROM user_posts_mentions WHERE postID = ?', [$postID]);
|
||||
$this->db->query('DELETE FROM user_posts_likes WHERE postID = ?', [$postID]);
|
||||
$this->db->query('DELETE FROM user_posts_media WHERE postID = ?', [$postID]);
|
||||
}
|
||||
|
||||
public function addImageToPost($postID, $imageUrl) {
|
||||
$this->db->query('INSERT INTO user_posts_media (postID, mediaType, mediaUrl) VALUES (?, ?, ?)', [$postID, 'image', $imageUrl]);
|
||||
}
|
||||
@@ -284,7 +293,9 @@
|
||||
}
|
||||
|
||||
public function getPostByUUID($uuid) {
|
||||
$this->db->cache_off();
|
||||
$result = $this->db->query('SELECT * FROM user_posts WHERE uuid = ?', [$uuid])->result_array();
|
||||
$this->db->cache_on();
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
21
application/views/network/posts/delete_modal.php
Normal file
21
application/views/network/posts/delete_modal.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
?>
|
||||
|
||||
<form id="postDeleteForm">
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<b>Bist du dir wirklich sicher, dass du diesen Post löschen willst?</b>
|
||||
<ul class="comment-list" style="pointer-events: none">
|
||||
<?php
|
||||
$post['hideActionBtns'] = true;
|
||||
$this->load->view('network/posts/post_item', $post) ?>
|
||||
</ul>
|
||||
<!-- --><?php //var_dump($post) ?>
|
||||
</div>
|
||||
<button type="reset" class="btn btn-sm btn-primary round float-right" data-dismiss="modal">
|
||||
Nein, Post behalten
|
||||
</button>
|
||||
<button type="submit" class="btn btn-sm btn-red outline round float-right" onclick="deletePost('<?= $post['uuid'] ?>')">
|
||||
Ja, endgültig löschen
|
||||
</button>
|
||||
</form>
|
@@ -43,39 +43,41 @@
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="action-btns">
|
||||
<a href="#" data-uuid="<?= $uuid ?>" class="action-btn reply-button" data-toggle="tooltip" data-placement="top" title="Antworten">
|
||||
<i class="far fa-comment"></i>
|
||||
<span><?= $replyCount ?></span>
|
||||
</a>
|
||||
<a href="#" data-uuid="<?= $uuid ?>" class="action-btn like-button <?= isset($userHasLiked) && $userHasLiked ? 'active' : '' ?>" data-toggle="tooltip" data-placement="top" title="Gefällt mir">
|
||||
<i class="<?= isset($userHasLiked) && $userHasLiked ? 'fas' : 'far' ?> fa-heart"></i>
|
||||
<span><?= $likeCount ?></span>
|
||||
</a>
|
||||
<div class="action-btn dropdown">
|
||||
<a href="#" class="action-btn more-options-button" id="postMoreOptionsButton<?= $uuid ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-h"></i>
|
||||
<?php if (!isset($hideActionBtns) || !$hideActionBtns): ?>
|
||||
<div class="action-btns">
|
||||
<a href="#" data-uuid="<?= $uuid ?>" class="action-btn reply-button" data-toggle="tooltip" data-placement="top" title="Antworten">
|
||||
<i class="far fa-comment"></i>
|
||||
<span><?= $replyCount ?></span>
|
||||
</a>
|
||||
<a href="#" data-uuid="<?= $uuid ?>" class="action-btn like-button <?= isset($userHasLiked) && $userHasLiked ? 'active' : '' ?>" data-toggle="tooltip" data-placement="top" title="Gefällt mir">
|
||||
<i class="<?= isset($userHasLiked) && $userHasLiked ? 'fas' : 'far' ?> fa-heart"></i>
|
||||
<span><?= $likeCount ?></span>
|
||||
</a>
|
||||
<div class="action-btn dropdown">
|
||||
<a href="#" class="action-btn more-options-button" id="postMoreOptionsButton<?= $uuid ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-h"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu" aria-labelledby="postMoreOptionsButton<?= $uuid ?>">
|
||||
<a href="#" onclick="copyToClipboard('<?= base_url('user/' . $username . '/post/' . $uuid) ?>')" class="dropdown-item">
|
||||
<i class="fa fa-copy"></i>
|
||||
Link zum Post kopieren
|
||||
</a>
|
||||
<a href="#" onclick="openPostReportModal('<?= $uuid ?>')" class="dropdown-item">
|
||||
<i class="fa fa-flag"></i>
|
||||
Post melden
|
||||
</a>
|
||||
<?php if (isset($_SESSION['user']) && $_SESSION['user']['username'] == $username): ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a href="#" onclick="openDeletePostModal('<?= $uuid ?>')" class="dropdown-item text-danger">
|
||||
<i class="fa fa-trash"></i>
|
||||
Post löschen
|
||||
<div class="dropdown-menu" aria-labelledby="postMoreOptionsButton<?= $uuid ?>">
|
||||
<a href="#" onclick="copyToClipboard('<?= base_url('user/' . $username . '/post/' . $uuid) ?>')" class="dropdown-item">
|
||||
<i class="fa fa-copy"></i>
|
||||
Link zum Post kopieren
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<a href="#" onclick="openPostReportModal('<?= $uuid ?>')" class="dropdown-item">
|
||||
<i class="fa fa-flag"></i>
|
||||
Post melden
|
||||
</a>
|
||||
<?php if (isset($_SESSION['user']) && $_SESSION['user']['username'] == $username): ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a href="#" onclick="openDeletePostModal('<?= $uuid ?>')" class="dropdown-item text-danger">
|
||||
<i class="fa fa-trash"></i>
|
||||
Post löschen
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user