Archived
1
0

Implement feature for deleting posts and improving ajax requests

This commit is contained in:
Marcel 2018-10-17 13:56:22 +02:00
parent b32b2790c8
commit 334aa22362
23 changed files with 193 additions and 96 deletions

View File

@ -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.']);
}
}

View File

@ -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,6 +246,7 @@
}
$media = $this->input->post('postMedia');
if (!empty($media)) {
foreach ($media as $entry) {
$image = str_replace(' ', '+', $entry['image']);
$image = substr($image, strpos($image, ',') + 1);
@ -265,6 +265,7 @@
</div>
<?php
}
}
public function followers($user = "")
{

View File

@ -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;
}

View 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>

View File

@ -43,6 +43,7 @@
</div>
<?php endif; ?>
</div>
<?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>
@ -76,6 +77,7 @@
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>

View File

@ -166,7 +166,7 @@ $('span').keyup(function (e) {
let tagsList = [];
$(function () {
$.ajax({
url: 'http://192.168.178.39/admin/blog/tagsList',
url: '/admin/blog/tagsList',
method: 'GET',
success: function (data) {
console.log(data);
@ -222,7 +222,7 @@ $(function () {
function getPostData() {
const postID = $('#postID').val();
$.ajax({
url: 'http://192.168.178.39/admin/blog/getPost',
url: '/admin/blog/getPost',
method: 'post',
data: {
postID
@ -255,7 +255,7 @@ function getContentData() {
const contentID = $('#contentID').val();
const lang = $('#postLanguage').val();
$.ajax({
url: 'http://192.168.178.39/admin/blog/getContent',
url: '/admin/blog/getContent',
method: 'post',
data: {
postID, contentID, lang
@ -275,7 +275,7 @@ function getTranslationData() {
const translationID = $('#translationID').val();
const lang = $('#postLanguage').val();
$.ajax({
url: 'http://192.168.178.39/admin/blog/getTranslationData',
url: '/admin/blog/getTranslationData',
method: 'post',
data: {
postID, translationID, lang
@ -294,7 +294,7 @@ function getTranslationData() {
function getPostTags() {
const postID = $('#postID').val();
$.ajax({
url: 'http://192.168.178.39/admin/blog/getPostTags',
url: '/admin/blog/getPostTags',
method: 'POST',
data: {
postID
@ -367,7 +367,7 @@ function sendPost(executionFinished) {
postTags = $('#postTags').tagsinput('items');
$.ajax({
url: 'http://192.168.178.39/admin/blog/sendEdit',
url: '/admin/blog/sendEdit',
method: 'post',
data: {
postID,
@ -413,7 +413,7 @@ function publishPost() {
contentFR = $('#switchLanguages').find('> li[data-lang=fr]').data('contentid');
$.ajax({
url: 'http://192.168.178.39/admin/blog/publishPost',
url: '/admin/blog/publishPost',
method: 'post',
data: {
postID, contentID,
@ -460,7 +460,7 @@ $('.upload-btn').on('change', '.upload-image', function () {
$('.img-container').css('background-image', 'url(' + reader.result + ')');
$.ajax({
url: 'http://192.168.178.39/admin/files/uploadImage',
url: '/admin/files/uploadImage',
type: 'POST',
data: {
image: reader.result,

View File

@ -1,6 +1,6 @@
$(document).ready(function () {
$.ajax({
url: "http://192.168.178.39/blog/getComments",
url: "/blog/getComments",
data: {
url: window.location.pathname
},
@ -33,7 +33,7 @@ var addComment = function () {
var item;
$.ajax({
url: "http://192.168.178.39/blog/comment",
url: "/blog/comment",
method: 'POST',
data: {
url: window.location.pathname,
@ -117,7 +117,7 @@ function wait(ms) {
function likeDislike(postID) {
$.ajax({
type: "POST",
url: "http://192.168.178.39/blog/like",
url: "/blog/like",
data: {
postID: postID
},

View File

@ -2,7 +2,7 @@ let bar = new Nanobar();
function loadPlayer() {
$.ajax({
url: 'http://192.168.178.39/tools/csgo/data/' + $('#player-id').text(),
url: '/tools/csgo/data/' + $('#player-id').text(),
method: 'GET',
success: function (result) {
console.log(result);
@ -113,7 +113,7 @@ $(window).keydown(function (event) {
function defaultPage() {
$.ajax({
url: 'http://192.168.178.39/tools/csgo/getDefaultPage/' + $('#player-id').text(),
url: '/tools/csgo/getDefaultPage/' + $('#player-id').text(),
method: 'GET',
success: function (data) {
bar.go(40);

View File

@ -244,7 +244,7 @@ $('#new-category-submit').click(function () {
var name = $('input[name=new-category-name]').val();
var display_name = $('input[name=new-category-display-name]').val();
$.ajax({
url: "http://192.168.178.39/admin/blog/new_category",
url: "/admin/blog/new_category",
type: "POST",
data: {
name: name,
@ -380,7 +380,7 @@ $('#tags-input').keypress(function (event) {
var deletePost = function (id) {
var row = $("#post-" + id);
$.ajax({
url: "http://192.168.178.39/admin/blog/delete",
url: "/admin/blog/delete",
data: {
id: id
},
@ -434,16 +434,16 @@ $('#deleteModal').on('show.bs.modal', function (event) {
removeButton.removeAttr('disabled');
switch (type) {
case "Blog-Post":
removeButton.attr('onclick', 'deletePostFinally(' + id + ', "http://192.168.178.39/admin/blog/deleteFinally", "post")');
removeButton.attr('onclick', 'deletePostFinally(' + id + ', "/admin/blog/deleteFinally", "post")');
break;
case "Projekt":
removeButton.attr('onclick', 'deletePostFinally(' + id + ', "http://192.168.178.39/admin/projects/delete", "entry")');
removeButton.attr('onclick', 'deletePostFinally(' + id + ', "/admin/projects/delete", "entry")');
break;
case "Projekt-Kategorie":
removeButton.attr('onclick', 'deletePostFinally(' + id + ', "http://192.168.178.39/admin/projects/delete_category", "category")');
removeButton.attr('onclick', 'deletePostFinally(' + id + ', "/admin/projects/delete_category", "category")');
break;
case "Datei":
removeButton.attr('onclick', 'deletePostFinally(' + id + ', "http://192.168.178.39/admin/files/delete", "file")');
removeButton.attr('onclick', 'deletePostFinally(' + id + ', "/admin/files/delete", "file")');
break;
}
removeButton.css('cursor', 'pointer');
@ -502,7 +502,7 @@ function deletePostFinally(id, url, selector) {
function restorePost(id) {
var row = $("#post-" + id);
$.ajax({
url: "http://192.168.178.39/admin/blog/restore",
url: "/admin/blog/restore",
data: {
id: id
},
@ -595,7 +595,7 @@ $(".table").DataTable({
function loadNotificationsAsync() {
$.ajax({
url: 'http://192.168.178.39/Main/getNotifications',
url: '/Main/getNotifications',
method: 'post',
success: (data) => {
console.log(data);

View File

@ -25,7 +25,7 @@ function activateDownloadSlider() {
var loadDownloadInfo = function (id) {
$.ajax({
url: 'http://192.168.178.39/downloads/getDownload',
url: '/downloads/getDownload',
data: {
id: id
},

View File

@ -28,7 +28,7 @@ $('#statusModal').on('show.bs.modal', (e) => {
function archiveFeedback(id) {
const row = $('#entry-' + id);
$.ajax({
url: 'http://192.168.178.39/admin/feedback/archive',
url: '/admin/feedback/archive',
method: 'post',
data: {
id

View File

@ -37,7 +37,7 @@ $(document).ready(function () {
function loadPosts(onLoad) {
// const category = $('#social-post-container .sort-list-filter > li > a.active').attr('data-filter');
$.ajax({
url: "http://192.168.178.39/main/getPosts",
url: "/main/getPosts",
data: {
amount: amount,
offset: offset,

View File

@ -232,7 +232,7 @@ $(document).ready(function () {
} else {
var loginname = $('#loginname').val();
$.ajax({
url: 'http://192.168.178.39/login/forget',
url: '/login/forget',
method: 'POST',
data: {
username: loginname
@ -278,7 +278,7 @@ $(document).ready(function () {
function registerAccount(username, email, password, passwordRepeat) {
$.ajax({
url: "http://192.168.178.39/login/register",
url: "/login/register",
method: "POST",
data: {
username: username,

View File

@ -3,7 +3,7 @@ setInterval(function () {
}, 60000);
function stillAlive() {
$.get('http://192.168.178.39/Main/stillAlive');
$.get('/Main/stillAlive');
}
jQuery(function ($) {
@ -106,7 +106,7 @@ function sendFeedback() {
$('#feedbackModal #message').addClass('has-error');
} else {
$.ajax({
url: "http://192.168.178.39/Main/addFeedback",
url: "/Main/addFeedback",
method: "POST",
data: {
message: message,
@ -135,7 +135,7 @@ function sendContactMessage() {
$('#contactModal .modal-body').append('<div class="modal-loading-container"><div class="modal-loading-icon"><i class="fa fa-cog fa-spin"></i></div></div>');
$('#contactModalSend').button('loading');
$.ajax({
url: "http://192.168.178.39/Main/contactTeam",
url: "/Main/contactTeam",
method: "POST",
data: {
message: message,
@ -285,7 +285,7 @@ function addReadMoreBtns() {
$('#notificationMenuButton').click(() => {
$.ajax({
url: 'http://192.168.178.39/Main/notificationsRead',
url: '/Main/notificationsRead',
method: 'post',
success: (data) => {
if (data.success) {
@ -298,7 +298,7 @@ $('#notificationMenuButton').click(() => {
function loadNotificationsAsync() {
$.ajax({
url: 'http://192.168.178.39/Main/getNotifications',
url: '/Main/getNotifications',
method: 'POST',
beforeSend: () => {
$('#notificationMenu').prepend('<div class="text-center"><i class="fa fa-cog fa-spin fa-4x my-4"></i></div>');

View File

@ -30,7 +30,7 @@ function generateNickname() {
$.ajax(
{
url: "http://192.168.178.39/tools/generators/nickname_functions",
url: "/tools/generators/nickname_functions",
cache: false,
dataType: 'text',
data: {

View File

@ -176,7 +176,7 @@ function submitPost(content, replyTo) {
}
$.ajax({
url: "http://192.168.178.39/user/publishPost",
url: "/user/publishPost",
method: 'POST',
data: {
content,

View File

@ -5,7 +5,7 @@ function showFullPost(uuid, username) {
defaultUrl += window.location.search;
$.ajax({
url: "http://192.168.178.39/user/single_post_data/" + username + "/" + uuid,
url: "/user/single_post_data/" + username + "/" + uuid,
beforeSend: () => {
const origin = encodeURI(btoa(window.location.href));
window.history.pushState('', '', '/user/' + username + '/post/' + uuid + '?o=' + origin);
@ -113,7 +113,7 @@ function addPostLike(el) {
const text = $('span', el);
const likeCount = parseInt(text.text());
$.ajax({
url: 'http://192.168.178.39/posts/addPostLike',
url: '/posts/addPostLike',
method: 'post',
data: {
postUUID: uuid
@ -196,7 +196,7 @@ function openPostReportModal(uuid) {
function loadPostReportModal(uuid) {
$.ajax({
url: 'http://192.168.178.39/posts/getReportModal',
url: '/posts/getReportModal',
data: {
uuid
},
@ -218,7 +218,7 @@ function loadPostReportModal(uuid) {
function submitReportForm(postUuid, reportReason, reportText) {
$.ajax({
url: 'http://192.168.178.39/posts/reportPost',
url: '/posts/reportPost',
data: {
uuid: postUuid,
reason: reportReason,
@ -252,7 +252,7 @@ function submitReportForm(postUuid, reportReason, reportText) {
function openDeletePostModal(uuid) {
$('body').append(`
<div class="modal fade" id="postDeleteModal" tabindex="-1" role="dialog" aria-labelledby="postReportLabel">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="postReportTitle">Post löschen</h4>
@ -260,7 +260,7 @@ function openDeletePostModal(uuid) {
<span>&times;</span>
</button>
</div>
<div class="modal-body text-center" id="postReportBody">
<div class="modal-body text-center" id="postDeleteBody">
<i class="fa fa-cog fa-spin fa-4x"></i>
</div>
</div>
@ -278,12 +278,41 @@ function openDeletePostModal(uuid) {
function loadDeletePostModal(uuid) {
$.ajax({
url: 'http://192.168.178.39/posts/getDeleteModal',
url: '/posts/getDeleteModal',
data: {
uuid
},
method: 'post',
success: data => {
$('#postDeleteModal').html(data);
$('#postReportTitle').text(data.title);
$('#postDeleteBody').removeClass('text-center').html(data.body);
}
});
}
function deletePost(uuid) {
$.ajax({
url: '/posts/deletePost',
method: 'post',
data: { uuid },
beforeSend: () => {
$('#postDeleteBody').addClass('text-center').html('<i class="fa fa-cog fa-spin fa-4x"></i>');
},
success: data => {
if(data.success) {
$('#postDeleteBody').html('<div class="alert alert-success" role="alert"></div>');
} else {
$('#postDeleteBody').html('<div class="alert alert-danger" role="alert"></div>');
}
$('#postDeleteBody').removeClass('text-center').find('.alert').text(data.message);
setTimeout(() => {
$('#postDeleteModal').modal('hide');
$(`.post-item[data-uuid=${uuid}]`).slideUp();
setTimeout(() => {
$('#postDeleteModal').modal('dispose').remove();
$(`.post-item[data-uuid=${uuid}]`).remove();
}, 500);
}, 2000);
}
})
}

View File

@ -6,9 +6,9 @@ let running = false;
let loadingUrl;
if(window.location.pathname.indexOf('popular') !== -1) {
loadingUrl = 'http://192.168.178.39/posts/getPopularPosts';
loadingUrl = '/posts/getPopularPosts';
} else {
loadingUrl = 'http://192.168.178.39/posts/getFeedPosts';
loadingUrl = '/posts/getFeedPosts';
}
function loadEntries() {

View File

@ -18,7 +18,7 @@ function searchEntries() {
if (!s_running && ((s_itemsLeft || val_changed) && (query.val().length > 0 || (type === 'type-users' && (rank !== '' || lang !== '' || country !== ''))))) {
console.log(rank);
$.ajax({
url: 'http://192.168.178.39/posts/getSearchPosts',
url: '/posts/getSearchPosts',
data: {
query: query.val(),
type,
@ -160,7 +160,7 @@ $('.user-search select').change(() => {
function initUserSearch() {
$.ajax({
url: 'http://192.168.178.39/posts/getAvailableCountries',
url: '/posts/getAvailableCountries',
success: (data) => {
const countrySelect = $('#searchForCountry').find('.dropdown-menu');
console.log(data);
@ -184,7 +184,7 @@ function initUserSearch() {
});
$.ajax({
url: 'http://192.168.178.39/posts/getAvailableLanguages',
url: '/posts/getAvailableLanguages',
success: (data) => {
const langSelect = $('#searchForLang').find('.dropdown-menu');
for (let lang of data.languages) {

View File

@ -75,7 +75,7 @@ function toggleSubbed(isSubbed) {
function sendFollowerRequest() {
$.ajax({
url: "http://192.168.178.39/user/switchFollowing",
url: "/user/switchFollowing",
method: "POST",
success: function (data) {
console.log(data);

View File

@ -46,7 +46,7 @@ function sendEdit() {
editor.start();
$.ajax({
url: 'http://192.168.178.39/admin/projects/sendEdit',
url: '/admin/projects/sendEdit',
data: data,
method: 'POST',
success: data => {
@ -128,7 +128,7 @@ $('.upload-btn').on('change', '.upload-image', function () {
$('.uploaded-image-container').css('background-image', `url(${reader.result}`);
$.ajax({
url: 'http://192.168.178.39/admin/files/uploadImage',
url: '/admin/files/uploadImage',
type: 'POST',
data: {
image: reader.result,

View File

@ -19,7 +19,7 @@ $('.vote-btn').click(function (e) {
$('.vote-container .fa-sync').fadeIn();
$.ajax({
url: 'http://192.168.178.39/projects/addVote/index',
url: '/projects/addVote/index',
method: 'POST',
data: {
id: $('.vote-container').data('id'),

View File

@ -13,7 +13,7 @@ $(document).ready(() => {
function loadPostData() {
$.ajax({
url: "http://192.168.178.39/user/single_post_data/" + modal.data('username') + "/" + modal.data('uuid'),
url: "/user/single_post_data/" + modal.data('username') + "/" + modal.data('uuid'),
success: (data) => {
$('.modal-body', modal).removeClass('text-center').html(data);
registerPostEvents();