ADD: удаление поста и комментариев

* Удаление комментариев
* Удаление постов. Виден для персонала, мета- тег noindex, закрытие ответов в комментариях.
* Мелкие исправление ошибок
This commit is contained in:
Evg 2021-03-25 00:37:55 +03:00
parent 034e680798
commit 5976860d04
12 changed files with 250 additions and 164 deletions

View file

@ -58,7 +58,7 @@ class CommentController extends \MainController
$comment = Request::getPost('comment');
if (strlen($comment) < 6 || strlen($comment) > 1024)
if (Base::getStrlen($comment) < 6 || Base::getStrlen($comment) > 1024)
{
Base::addMsg('Длина комментария должна быть от 6 до 1000 знаков', 'error');
redirect('/' . $vurl);

View file

@ -25,10 +25,7 @@ class PostController extends \MainController
hl_preliminary_exit();
}
// Array ( [user_id] => 6 [login] => AdreS [name] => Олег [email] => ss@sdf.ru [trust_level] => 1 [about] => Тестовый аккаунт [avatar] => [isLoggedIn] => 1 [ipaddress] => 127.0.0.1 )
//print_r(Request::getSession('account'));
//exit;
if($account = Request::getSession('account')){
// Получаем все теги отписанные участником
$space_user = SpaceModel::getSpaceUser($account['user_id']);
@ -39,24 +36,25 @@ class PostController extends \MainController
}
$pagesCount = PostModel::getPostHomeCount($space_user);
$posts = PostModel::getPostHome($page, $space_user);
$posts = PostModel::getPostHome($page, $space_user, $account);
$result = Array();
foreach($posts as $ind => $row){
if(!$row['avatar'] ) {
$row['avatar'] = 'noavatar.png';
}
$row['avatar'] = $row['avatar'];
$row['title'] = $row['post_title'];
$row['slug'] = $row['post_slug'];
$row['num_comments'] = $row['post_comments'];
$row['post_comments'] = Base::ru_num('comm', $row['post_comments']);
$row['date'] = Base::ru_date($row['post_date']);
$result[$ind] = $row;
$row['avatar'] = $row['avatar'];
$row['title'] = $row['post_title'];
$row['slug'] = $row['post_slug'];
$row['num_comments'] = $row['post_comments'];
$row['is_delete'] = $row['post_is_delete'];
$row['post_comments'] = Base::ru_num('comm', $row['post_comments']);
$row['date'] = Base::ru_date($row['post_date']);
$result[$ind] = $row;
}
// Последние комментарии и отписанные пространства
$latest_comments = CommentModel::latestComments();
$space_hide = SpaceModel::getSpaceUser($user_id);
@ -138,7 +136,8 @@ class PostController extends \MainController
$row['avatar'] = $row['avatar'];
$row['title'] = $row['post_title'];
$row['slug'] = $row['post_slug'];
$row['num_comments'] = $row['post_comments'];
$row['num_comments'] = $row['post_comments'];
$row['is_delete'] = $row['post_is_delete'];
$row['post_comments'] = Base::ru_num('comm', $row['post_comments']);
$row['date'] = Base::ru_date($row['post_date']);
$result[$ind] = $row;
@ -226,7 +225,8 @@ class PostController extends \MainController
'login' => $post['login'],
'my_post' => $post['my_post'],
'avatar' => $post['avatar'],
'num_comments' => $post['post_comments'],
'num_comments' => $post['post_comments'],
'is_delete' => $post['post_is_delete'],
'space_tip' => $post['space_tip'],
'space_slug' => $post['space_slug'],
'space_name' => $post['space_name'],
@ -506,15 +506,35 @@ class PostController extends \MainController
}
$post_id = Request::getPost('post_id');
// Получим пост
$post = PostModel::getPostId($post_id);
PostModel::setPostFavorite($post_id, $account['user_id']);
return true;
}
// Помещаем пост в закладки
public function deletePost()
{
// Авторизировались или нет
if (!$account = Request::getSession('account'))
{
return false;
}
// Доступ только персоналу
if ($account['trust_level'] != 5) {
return false;
}
$post_id = Request::getPost('post_id');
PostModel::PostDelete($post_id);
return true;
}
}

View file

@ -18,7 +18,7 @@ class Base
UserModel::checkCookie();
$uid['id'] = null;
$user['trust_level'] = null;
$uid['trust_level'] = null;
}
$uid['msg'] = self::getMsg();

View file

@ -12,7 +12,7 @@ class PostModel extends \MainModel
// Посты на главной
// $page - страницы
// $tags_user - список id отписанных тегов
public static function getPostHome($page, $space_user)
public static function getPostHome($page, $space_user, $account)
{
$result = Array();
@ -25,16 +25,26 @@ class PostModel extends \MainModel
} else {
$string = 0;
}
$offset = ($page-1) * 15;
$sql = "SELECT p.post_id, p.post_title, p.post_slug, p.post_user_id, p.post_space_id, p.post_comments, p.post_date, p.post_votes,
$offset = ($page-1) * 15;
if(!$account) {$account['trust_level'] = 0;}
// Показывать удаленный пост и для персонала
if($account['trust_level'] != 5) {
$display = 'AND p.post_is_delete = 0';
} else {
$display = '';
}
$sql = "SELECT p.post_id, p.post_title, p.post_slug, p.post_user_id, p.post_space_id, p.post_comments, p.post_date, p.post_votes, p.post_is_delete,
u.id, u.login, u.avatar,
s.space_id, s.space_slug, s.space_name, space_tip
fROM posts as p
INNER JOIN users as u ON u.id = p.post_user_id
INNER JOIN space as s ON s.space_id = p.post_space_id
WHERE p.post_space_id NOT IN(".$string.")
$display
ORDER BY p.post_id DESC LIMIT 15 OFFSET ".$offset." ";
@ -76,6 +86,7 @@ class PostModel extends \MainModel
$q = XD::select('*')->from(['posts']);
$query = $q->leftJoin(['users'])->on(['users.id'], '=', ['post_user_id'])
->leftJoin(['space'])->on(['space_id'], '=', ['post_space_id'])
->where(['post_is_delete'], '=', 0)
->orderBy(['post_comments'])->desc();
$result = $query->getSelect();
@ -107,6 +118,7 @@ class PostModel extends \MainModel
$query = $q->leftJoin(['users'])->on(['id'], '=', ['post_user_id'])
->leftJoin(['space'])->on(['space_id'], '=', ['post_space_id'])
->where(['login'], '=', $login)
->and(['post_is_delete'], '=', 0)
->orderBy(['post_id'])->desc();
$result = $query->getSelect();
@ -234,5 +246,14 @@ class PostModel extends \MainModel
}
}
// Удаляем пост
public static function PostDelete($post_id)
{
XD::update(['posts'])->set(['post_is_delete'], '=', 1)
->where(['post_id'], '=', $post_id)->run();
return true;
}
}

View file

@ -439,6 +439,10 @@ input.form-about {width: 250px;}
.telo-detail_post img {
max-width: 600px;
}
.telo-detail_post.dell {
background-color: rgb(246, 196, 184);
padding-left: 10px;
}
.post-telo {
margin-bottom: 12px;
}
@ -542,7 +546,7 @@ a.space_3 {
.block-comments {
margin: 0 0 20px 0;
}
ol.dell.comment-telo {
ol.dell.comment-telo, .dell.comm-telo_bottom {
font-size: 13px;
color: #888;
}
@ -563,6 +567,9 @@ ol.comment-telo {
margin-left: 40px;
margin-right: 40px;
}
.comm-telo_bottom {
margin-bottom: 20px;
}
.comm-telo-body{
max-width: 750px;
}
@ -604,14 +611,12 @@ ol.comment-telo {
color: #888;
font-size: 13px;
}
.comments_subtree {
position: relative;
}
.comments_subtree.dell {
display: none;
opacity: 0.3;
}
.com-line {
position: absolute;
left: 20px;

View file

@ -61,4 +61,17 @@ $(function(){
$('#comm_' + comm_id).addClass('dell');
});
});
// Удаляем пост
$(document).on('click', '.delpost', function() {
var post_id = $(this).data('post');
$.ajax({
url: '/post/del/' + post_id,
type: 'POST',
data: {post_id: post_id},
}).done(function(data) {
$('.telo-detail_post').addClass('dell');
});
});
});

View file

@ -14,39 +14,35 @@
<?php foreach ($data['comments'] as $comm) { ?>
<?php if($comm['comment_del'] == 0) { ?>
<ol class="comment-telo">
<li>
<div class="voters">
<div class="comm-up-id"></div>
<div class="score"><?= $comm['comment_votes'] ?></div>
<div class="comm-telo_bottom">
<div class="voters">
<div class="comm-up-id"></div>
<div class="score"><?= $comm['comment_votes'] ?></div>
</div>
<div class="comm-telo">
<div class="comm-header">
<img class="ava" src="/uploads/avatar/small/<?php echo $comm['avatar'] ?>">
<span class="user">
<a href="/u/<?php echo $comm['login']; ?>"><?php echo $comm['login']; ?></a>
<?php echo $comm['date']; ?>
</span>
<span class="otst"> | </span>
<span class="date">
<a href="/posts/<?php echo $comm['post_slug']; ?>"><?php echo $comm['post_title']; ?></a>
</span>
</div>
<div class="comm-telo">
<div class="comm-header">
<img class="ava" src="/uploads/avatar/small/<?php echo $comm['avatar'] ?>">
<span class="user">
<a href="/u/<?php echo $comm['login']; ?>"><?php echo $comm['login']; ?></a>
<?php echo $comm['date']; ?>
</span>
<span class="otst"> | </span>
<span class="date">
<a href="/posts/<?php echo $comm['post_slug']; ?>"><?php echo $comm['post_title']; ?></a>
</span>
</div>
<div class="comm-telo-body">
<?php echo $comm['content']; ?>
</div>
<div class="comm-telo-body">
<?php echo $comm['content']; ?>
</div>
</li>
</ol>
</div>
</div>
<?php } else { ?>
<ol class="dell comment-telo<?php if ($comm['level'] == 0) { ?> one<?php } ?><?php if ($comm['level'] == 2) { ?> two<?php } ?><?php if ($comm['level'] > 2) { ?> three<?php } ?>">
<li class="comments_subtree" id="comm_<?= $comm['comment_id']; ?>">
<div class="voters"></div>
~ Комментарий удален
</li>
</ol>
<div class="dell comm-telo_bottom">
<div class="voters"></div>
~ Комментарий удален
</div>
<?php } ?>
<?php } ?>

View file

@ -12,30 +12,40 @@
<?php if (!empty($data['comments'])) { ?>
<?php foreach ($data['comments'] as $comm) { ?>
<?php if($comm['comment_del'] == 0) { ?>
<div class="comm-telo_bottom">
<div class="voters">
<div class="comm-up-id"></div>
<div class="score"><?php echo $comm['comment_votes']; ?></div>
</div>
<div class="voters">
<div class="comm-up-id"></div>
<div class="score"><?php echo $comm['comment_votes']; ?></div>
</div>
<div class="comm-telo">
<div class="comm-header">
<img class="ava" alt="<?php echo $comm['login']; ?>" src="/uploads/avatar/small/<?php echo $comm['avatar']; ?>">
<span class="user">
<a href="/u/<?php echo $comm['login']; ?>"><?php echo $comm['login']; ?></a>
<?php echo $comm['date']; ?>
</span>
<span class="otst"> | </span>
<span class="date">
<a href="/posts/<?= $comm['post_slug']; ?>"><?php echo $comm['post_title']; ?></a>
</span>
<div class="comm-telo">
<div class="comm-header">
<img class="ava" alt="<?php echo $comm['login']; ?>" src="/uploads/avatar/small/<?php echo $comm['avatar']; ?>">
<span class="user">
<a href="/u/<?php echo $comm['login']; ?>"><?php echo $comm['login']; ?></a>
<?php echo $comm['date']; ?>
</span>
<span class="otst"> | </span>
<span class="date">
<a href="/posts/<?= $comm['post_slug']; ?>"><?php echo $comm['post_title']; ?></a>
</span>
</div>
<div class="comm-telo-body">
<?php echo $comm['content']; ?>
</div>
</div>
</div>
<?php } else { ?>
<div class="dell comm-telo_bottom">
<div class="voters"></div>
~ Комментарий удален
</div>
<div class="comm-telo-body">
<?php echo $comm['content']; ?>
</div>
</div>
<?php } ?>
<?php } ?>
<?php } else { ?>

View file

@ -5,10 +5,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php if (isset($data['post']['is_delete'])) { ?>
<meta name="robots" content="noindex" />
<?php } ?>
<title><?= $data['title']; ?></title>
<meta name = "description" content = "<?= $data['description']; ?>" />
<link rel="stylesheet" href="/assets/css/style.css">
<link rel="icon" href="/favicon.ico">
</head>
<body class="bd<?php if(Request::getCookie('dayNight') == 'dark') {?> dark<?php } ?>">
<header>

View file

@ -23,6 +23,11 @@
<?php } ?>
<div class="post-body">
<a class="u-url" href="/posts/<?= $post['post_slug']; ?>">
<?php if ($post['is_delete'] == 1) { ?>
<svg class="md-icon">
<use xlink:href="/assets/svg/icons.svg#eye"></use>
</svg>
<?php } ?>
<h2 class="titl"><?= $post['post_title']; ?></h2>
</a>

View file

@ -1,86 +1,95 @@
<?php include TEMPLATE_DIR . '/header.php'; ?>
<section>
<div class="wrap">
<div class="telo-detail_post">
<h1 class="titl"><?= $data['post']['title']; ?></h1>
<div class="footer">
<img class="ava" src="/uploads/avatar/small/<?= $data['post']['avatar']; ?>">
<span class="user">
<a href="/u/<?= $data['post']['login']; ?>"><?= $data['post']['login']; ?></a>
</span>
<span class="date">
<?= $data['post']['date']; ?>
<?php if($data['post']['edit_date']) { ?>
(изм. <?= $data['post']['edit_date']; ?>)
<?php } ?>
</span>
<span class="date">
<a class="space space_<?= $data['post']['space_tip'] ?>" href="/s/<?= $data['post']['space_slug']; ?>" title="<?= $data['post']['space_name']; ?>">
<?= $data['post']['space_name']; ?>
</a>
</span>
<?php if ($uid['id']) { ?>
<?php if($uid['login'] == $data['post']['login']) { ?>
<span class="date">
&nbsp; <a href="/post/edit/<?= $data['post']['id']; ?>">
<svg class="md-icon moon">
<use xlink:href="/assets/svg/icons.svg#edit"></use>
</svg>
</a>
</span>
<?php if($data['post']['my_post'] == $data['post']['id']) { ?>
<span class="mu_post">+ в профиле</span>
<?php } else { ?>
<a class="user-mypost" data-opt="1" data-post="<?= $data['post']['id']; ?>">
<span class="mu_post">В профиль</span>
</a>
<?php if($data['post']['is_delete'] == 0 || $uid['trust_level'] == 5) { ?>
<div class="telo-detail_post<?php if($data['post']['is_delete'] == 1) { ?> dell<?php } ?>">
<h1 class="titl"><?= $data['post']['title']; ?></h1>
<div class="footer">
<img class="ava" src="/uploads/avatar/small/<?= $data['post']['avatar']; ?>">
<span class="user">
<a href="/u/<?= $data['post']['login']; ?>"><?= $data['post']['login']; ?></a>
</span>
<span class="date">
<?= $data['post']['date']; ?>
<?php if($data['post']['edit_date']) { ?>
(изм. <?= $data['post']['edit_date']; ?>)
<?php } ?>
</span>
<span class="date">
<a class="space space_<?= $data['post']['space_tip'] ?>" href="/s/<?= $data['post']['space_slug']; ?>" title="<?= $data['post']['space_name']; ?>">
<?= $data['post']['space_name']; ?>
</a>
</span>
<?php if ($uid['id']) { ?>
<?php if($uid['login'] == $data['post']['login']) { ?>
<span class="date">
&nbsp; <a href="/post/edit/<?= $data['post']['id']; ?>">
<svg class="md-icon moon">
<use xlink:href="/assets/svg/icons.svg#edit"></use>
</svg>
</a>
</span>
<?php if($data['post']['my_post'] == $data['post']['id']) { ?>
<span class="mu_post">+ в профиле</span>
<?php } else { ?>
<a class="user-mypost" data-opt="1" data-post="<?= $data['post']['id']; ?>">
<span class="mu_post">В профиль</span>
</a>
<?php } ?>
<?php } ?>
<?php } ?>
<?php if ($data['post']['favorite_post']){ ?>
<span class="otst"> | </span>
<span class="user-favorite" data-post="<?= $data['post']['id']; ?>">
<span class="mu_favorite">Убрать из избранного</span>
</span>
<?php } else { ?>
<span class="otst"> | </span>
<span class="user-favorite" data-post="<?= $data['post']['id']; ?>">
<span class="mu_favorite">В избранное</span>
</span>
<?php } ?>
<?php if($uid['trust_level'] ==5) { ?>
<span class="otst"> | </span>
<span id="cm_dell" class="cm_add_link">
<a data-post="<?= $data['post']['id']; ?>" class="delpost">Удалить</a>
</span>
<?php if ($data['post']['favorite_post']){ ?>
<span class="otst"> | </span>
<span class="user-favorite" data-post="<?= $data['post']['id']; ?>">
<span class="mu_favorite">Убрать из избранного</span>
</span>
<?php } else { ?>
<span class="otst"> | </span>
<span class="user-favorite" data-post="<?= $data['post']['id']; ?>">
<span class="mu_favorite">В избранное</span>
</span>
<?php } ?>
<?php if($uid['trust_level'] ==5) { ?>
<span class="otst"> | </span>
<span id="cm_dell" class="cm_add_link">
<a data-post="<?= $data['post']['id']; ?>" class="delpost">Удалить</a>
</span>
<?php } ?>
<?php } ?>
<?php } ?>
</div>
<div class="post">
<?= $data['post']['content']; ?>
</div>
</div>
<div class="post">
<?= $data['post']['content']; ?>
</div>
<?php if ($uid['id']) { ?>
<form id="add_comm" class="new_comment" action="/comment/add" accept-charset="UTF-8" method="post">
<?= csrf_field() ?>
<textarea rows="5" placeholder="Напишите, что нибудь..." name="comment" id="comment"></textarea>
<div>
<input type="hidden" name="post_id" id="post_id" value="<?= $data['post']['id']; ?>">
<input type="hidden" name="comm_id" id="comm_id" value="0">
<input type="submit" name="commit" value="Комментарий" class="comment-post">
</div>
</form>
<?php } else { ?>
<textarea rows="5" disabled="disabled" placeholder="Вы должны войти в систему, чтобы оставить комментарий." name="comment" id="comment"></textarea>
<div>
<input type="submit" name="commit" value="Комментарий" class="comment-post" disabled="disabled">
</div>
<?php } ?>
</div>
<?php } else { ?>
<div class="telo-detail_post dell">
Пост удален...
</div>
<?php } ?>
<?php if ($uid['id']) { ?>
<form id="add_comm" class="new_comment" action="/comment/add" accept-charset="UTF-8" method="post">
<?= csrf_field() ?>
<textarea rows="5" placeholder="Напишите, что нибудь..." name="comment" id="comment"></textarea>
<div>
<input type="hidden" name="post_id" id="post_id" value="<?= $data['post']['id']; ?>">
<input type="hidden" name="comm_id" id="comm_id" value="0">
<input type="submit" name="commit" value="Комментарий" class="comment-post">
</div>
</form>
<?php } else { ?>
<textarea rows="5" disabled="disabled" placeholder="Вы должны войти в систему, чтобы оставить комментарий." name="comment" id="comment"></textarea>
<div>
<input type="submit" name="commit" value="Комментарий" class="comment-post" disabled="disabled">
</div>
<?php } ?>
</div>
<?php if (!empty($data['comments'])) { ?>
<div class="telo comments">
<h2><?= $data['post']['num_comments'] ?> <?= $data['post']['post_comments'] ?></h2>
@ -139,10 +148,11 @@
<?= $comm['content'] ?>
</div>
</div>
<span id="cm_add_link<?php $comm['comment_id']; ?>" class="cm_add_link">
<a data-post_id="<?= $data['post']['id']; ?>" data-id="<?= $comm['comment_id']; ?>" class="addcomm">Ответить</a>
</span>
<?php if($data['post']['is_delete'] == 0 || $uid['trust_level'] == 5) { ?>
<span id="cm_add_link<?php $comm['comment_id']; ?>" class="cm_add_link">
<a data-post_id="<?= $data['post']['id']; ?>" data-id="<?= $comm['comment_id']; ?>" class="addcomm">Ответить</a>
</span>
<?php } ?>
<?php if($uid['trust_level'] ==5) { ?>
<span id="cm_dell" class="cm_add_link">
<a data-id="<?= $comm['comment_id']; ?>" class="delcomm">Удалить</a>

View file

@ -76,9 +76,10 @@ Route::type('post')->get('/comments/addform')->controller('CommentController@add
Route::get('/post/add')->controller('PostController@addPost');
// Само добавление поста
Route::type('post')->protect()->get('/post/create')->controller('PostController@createPost');
// Редактирование поста
// Редактирование поста / удаление поста
Route::get('/post/edit/{id}')->controller('PostController@editPost');
Route::type('post')->protect()->get('/post/editpost/{id}')->controller('PostController@editPostRecording');
Route::type('post')->get('/post/del/{id}')->controller('PostController@deletePost')->where(['id' => '[0-9]+']);
// Помещаем свой пост в профиль
Route::type('post')->get('/post/addpostprof/{id}')->controller('PostController@addPostProf')->where(['id' => '[0-9]+']);