ADD: Удаленный контент участника (в профиле)

This commit is contained in:
Evg 2022-07-20 21:59:07 +03:00
parent 533198d8d0
commit 6288de176a
19 changed files with 91 additions and 73 deletions

View file

@ -41,6 +41,7 @@ class ProfileController extends Controller
'pNum' => $this->pageNumber,
'created_at' => $profile['created_at'],
'count' => $count,
'delet_count' => UserModel::contentCount($profile['id'], 'remote'),
'topics' => FacetModel::getFacetsAll(1, 10, $profile['id'], 'my', 'topic'),
'blogs' => FacetModel::getOwnerFacet($profile['id'], 'blog'),
'badges' => BadgeModel::getBadgeUserAll($profile['id']),
@ -54,6 +55,7 @@ class ProfileController extends Controller
);
}
// User posts
public function posts()
{
$profile = self::profile();
@ -66,21 +68,12 @@ class ProfileController extends Controller
'base',
[
'meta' => self::metadata('profile_posts_all', $profile),
'data' => [
'pagesCount' => ceil($pagesCount / $this->limit),
'pNum' => $this->pageNumber,
'posts' => $posts,
'profile' => $profile,
'count' => UserModel::contentCount($profile['id']),
'topics' => FacetModel::getFacetsAll(1, 10, $profile['id'], 'my', 'topic'),
'blogs' => FacetModel::getOwnerFacet($profile['id'], 'blog'),
'badges' => BadgeModel::getBadgeUserAll($profile['id']),
'button_pm' => $this->accessPm($profile['id']),
]
'data' => array_merge($this->sidebar($pagesCount, $profile), ['posts' => $posts]),
]
);
}
// User answers
public function answers()
{
$profile = self::profile();
@ -95,22 +88,12 @@ class ProfileController extends Controller
'base',
[
'meta' => self::metadata('profile_answers', $profile),
'data' => [
'pagesCount' => ceil($pagesCount / $this->limit),
'pNum' => $this->pageNumber,
'answers' => $answers,
'profile' => $profile,
'count' => UserModel::contentCount($profile['id']),
'topics' => FacetModel::getFacetsAll(1, 10, $profile['id'], 'my', 'topic'),
'blogs' => FacetModel::getOwnerFacet($profile['id'], 'blog'),
'badges' => BadgeModel::getBadgeUserAll($profile['id']),
'button_pm' => $this->accessPm($profile['id']),
]
'data' => array_merge($this->sidebar($pagesCount, $profile), ['answers' => $answers]),
]
);
}
// Комментарии участника
// User comments
public function comments()
{
$profile = self::profile();
@ -123,20 +106,25 @@ class ProfileController extends Controller
'base',
[
'meta' => self::metadata('profile_comments', $profile),
'data' => [
'data' => array_merge($this->sidebar($pagesCount, $profile), ['comments' => $comments]),
]
);
}
public function sidebar($pagesCount, $profile)
{
return [
'pagesCount' => ceil($pagesCount / $this->limit),
'pNum' => $this->pageNumber,
'comments' => $comments,
'profile' => $profile,
'delet_count' => UserModel::contentCount($profile['id'], 'remote'),
'count' => UserModel::contentCount($profile['id']),
'topics' => FacetModel::getFacetsAll(1, 10, $profile['id'], 'my', 'topic'),
'blogs' => FacetModel::getOwnerFacet($profile['id'], 'blog'),
'badges' => BadgeModel::getBadgeUserAll($profile['id']),
'button_pm' => $this->accessPm($profile['id']),
'login' => $profile['login'],
]
]
);
];
}
public static function profile()

View file

@ -72,7 +72,7 @@ class Content
// Getting a piece of text
public static function fragment($str, $lenght = 100, $end = '...', $charset = 'UTF-8', $token = '~')
{
$str = strip_tags($str);
// $str = strip_tags($str);
if (mb_strlen($str, $charset) >= $lenght) {
$wrap = wordwrap($str, $lenght, $token);
$str_cut = mb_substr($wrap, 0, mb_strpos($wrap, $token, 0, $charset), $charset);

View file

@ -19,10 +19,7 @@ class FeedModel extends \Hleb\Scheme\App\Models\MainModel
case 'web.feed':
$string = "WHERE post_url_domain = :qa AND post_draft = 0";
break;
case 'admin.posts.all':
$string = "WHERE post_user_id != :qa AND post_is_deleted = 0 AND post_draft = 0 AND post_type = 'post'";
break;
case 'admin.posts.ban':
case 'admin.posts.user.deleted':
$string = "WHERE post_is_deleted = :qa AND post_draft = 0 AND post_type = 'post'";
break;
case 'profile.posts':
@ -81,24 +78,21 @@ class FeedModel extends \Hleb\Scheme\App\Models\MainModel
fav.tid, fav.user_id, fav.action_type
FROM posts
LEFT JOIN
(
SELECT
relation_post_id,
GROUP_CONCAT(facet_type, '@', facet_slug, '@', facet_title SEPARATOR '@') AS facet_list
FROM facets
LEFT JOIN facets_posts_relation
on facet_id = relation_facet_id
LEFT JOIN facets_posts_relation on facet_id = relation_facet_id
GROUP BY relation_post_id
) AS rel
ON rel.relation_post_id = post_id
) AS rel ON rel.relation_post_id = post_id
INNER JOIN users u ON u.id = post_user_id
LEFT JOIN favorites fav ON fav.tid = post_id AND fav.user_id = " . $user['id'] . "
AND fav.action_type = 'post'
LEFT JOIN votes_post ON votes_post_item_id = post_id
AND votes_post_user_id = " . $user['id'] . "
LEFT JOIN favorites fav ON fav.tid = post_id AND fav.user_id = " . $user['id'] . " AND fav.action_type = 'post'
LEFT JOIN votes_post ON votes_post_item_id = post_id AND votes_post_user_id = " . $user['id'] . "
$string
$display

View file

@ -56,23 +56,24 @@ class HomeModel extends \Hleb\Scheme\App\Models\MainModel
rel.*,
votes_post_item_id, votes_post_user_id,
u.id, u.login, u.avatar, u.created_at,
fav.tid, fav.user_id, fav.action_type
fav.tid
FROM facets_posts_relation
LEFT JOIN posts ON relation_post_id = post_id
FROM posts
LEFT JOIN (
SELECT
relation_facet_id,
relation_post_id,
GROUP_CONCAT(facet_type, '@', facet_slug, '@', facet_title SEPARATOR '@') AS facet_list
FROM facets
LEFT JOIN facets_posts_relation ON facet_id = relation_facet_id
GROUP BY relation_post_id
GROUP BY relation_post_id, relation_facet_id
) AS rel ON rel.relation_post_id= post_id
LEFT JOIN users u ON u.id = post_user_id
LEFT JOIN favorites fav ON fav.tid = post_id AND fav.user_id = :uid AND fav.action_type = 'post'
LEFT JOIN votes_post ON votes_post_item_id = post_id AND votes_post_user_id = :uid2
WHERE post_type != 'page' AND post_draft = 0 $string $display $sort LIMIT :start, :limit";
WHERE post_type = 'post' AND post_draft = 0 $string $display $sort LIMIT :start, :limit";
return DB::run($sql, ['uid' => $user['id'], 'uid2' => $user['id'], 'start' => $start, 'limit' => $limit])->fetchAll();
}

View file

@ -219,27 +219,29 @@ class UserModel extends \Hleb\Scheme\App\Models\MainModel
}
// Количество контента участника
public static function contentCount($user_id)
public static function contentCount($user_id, $type = 0)
{
$type = $type == 'remote' ? 1: 0;
$sql = "SELECT
(SELECT COUNT(post_id)
FROM posts
WHERE post_user_id = $user_id and post_draft = 0 and post_is_deleted = 0)
WHERE post_user_id = $user_id and post_draft = 0 and post_is_deleted = $type)
AS count_posts,
(SELECT COUNT(answer_id)
FROM answers
WHERE answer_user_id = $user_id and answer_is_deleted = 0)
WHERE answer_user_id = $user_id and answer_is_deleted = $type)
AS count_answers,
(SELECT COUNT(comment_id)
FROM comments
WHERE comment_user_id = $user_id and comment_is_deleted = 0)
WHERE comment_user_id = $user_id and comment_is_deleted = $type)
AS count_comments,
(SELECT COUNT(item_id)
FROM items
WHERE item_user_id = $user_id and item_is_deleted = 0)
WHERE item_user_id = $user_id and item_is_deleted = $type)
AS count_items";
return DB::run($sql)->fetch();

View file

@ -23,7 +23,7 @@ class MainConnector implements Connector
"App\Commands\*" => "app/Commands/",
// ... or, if a specific class is added,
"Phphleb\Debugpan\DPanel" => "app/ThirdParty/phphleb/debugpan/DPanel.php",
// "Phphleb\Debugpan\DPanel" => "app/ThirdParty/phphleb/debugpan/DPanel.php",
"DB" => "app/Libraries/DB.php",
"Configuration" => "app/Libraries/Configuration.php",

File diff suppressed because one or more lines are too long

View file

@ -13,7 +13,7 @@ define('HLEB_PUBLIC_DIR', __DIR__);
// Общие заголовки.
// Content Security Policy
$_SERVER['nonce'] = bin2hex(random_bytes((int)'12'));
header("Content-Security-Policy: default-src 'self' https://www.google.com https://www.youtube.com https://rutube.ru https://rutube.ru/api https://mc.yandex.ru; style-src 'self' 'nonce-".$_SERVER['nonce']."'; script-src 'self' https://www.google.com https://www.gstatic.com https://mc.yandex.ru https://yastatic.net 'nonce-".$_SERVER['nonce']."'; img-src 'self' data: blob:;");
header("Content-Security-Policy: default-src 'self' https://www.google.com https://www.youtube.com https://rutube.ru https://rutube.ru/api https://mc.yandex.ru; style-src 'self' 'unsafe-inline'; script-src 'self' https://www.google.com https://www.gstatic.com https://mc.yandex.ru https://yastatic.net 'nonce-".$_SERVER['nonce']."'; img-src 'self' data: blob:;");
header("Strict-Transport-Security: max-age=31536000; includeSubDomains; preload;");
header("Referrer-Policy: no-referrer-when-downgrade");
header("X-XSS-Protection: 1; mode=block");

View file

@ -1,7 +1,7 @@
<?php foreach ($facets as $key => $facet) : ?>
<div class="mb20 items-center flex flex-row">
<a title="<?= $facet['translation_title']; ?>" href="<?= url($facet['facet_type'], ['slug' => $facet['facet_slug']]); ?>">
<?= Html::image($facet['facet_img'], $facet['translation_title'], 'img-lg mr10', 'logo', 'max'); ?>
<a title="<?= $facet['facet_title']; ?>" href="<?= url($facet['facet_type'], ['slug' => $facet['facet_slug']]); ?>">
<?= Html::image($facet['facet_img'], $facet['facet_title'], 'img-lg mr10', 'logo', 'max'); ?>
</a>
<div class="w-100">
<a class="black text-xl" title="<?= $facet['facet_title']; ?>" href="<?= url($facet['facet_type'], ['slug' => $facet['facet_slug']]); ?>">
@ -19,7 +19,7 @@
<svg class="icons icon-small sky"><use xlink:href="/assets/svg/icons.svg#mic"></use></svg>
<?php endif; ?>
<div class="mr10 mt5 gray">
<?= Content::fragment(Content::text($facet['translation_short_description'], 'line'), 68); ?>
<?= Content::fragment(Content::text($facet['facet_short_description'], 'line'), 68); ?>
<span class="flex right gray-600 text-sm">
<svg class="icons"><use xlink:href="/assets/svg/icons.svg#post"></use></svg>
<?= $facet['facet_count']; ?>

View file

@ -0,0 +1,17 @@
<?php if ($data['count_posts'] + $data['count_answers'] + $data['count_comments'] > 0) : ?>
<div class="delet-count">
<?= __('app.deleted'); ?>:
<?php if ($data['count_posts'] > 0) : ?>
<span><?= __('app.posts'); ?> <?= $data['count_posts']; ?></span>
<?php endif; ?>
<?php if ($data['count_answers'] > 0) : ?>
<span><?= __('app.answers'); ?> <?= $data['count_answers']; ?></span>
<?php endif; ?>
<?php if ($data['count_comments'] > 0) : ?>
<span><?= __('app.comments'); ?> <?= $data['count_comments']; ?></span>
<?php endif; ?>
</div>
<?php endif; ?>

View file

@ -1,4 +1,4 @@
<style nonce="<?= $_SERVER['nonce']; ?>">
<style>
.bg-blog {
background-image: linear-gradient(to right, white 0%, transparent 60%), url(<?= Html::coverUrl($data['facet']['facet_cover_art'], 'blog'); ?>);
background-position: 50% 50%;

View file

@ -2,11 +2,9 @@
<?= insert('/content/user/profile/header', ['data' => $data]); ?>
<div class="flex gap">
<main>
<?= __('app.answers'); ?> <b><?= $data['profile']['login']; ?></b>
<div class="mb15"><?= __('app.answers'); ?> <b><?= $data['profile']['login']; ?></b></div>
<?php if (!empty($data['answers'])) : ?>
<div class="box">
<?= insert('/content/answer/answer', ['data' => $data]); ?>
</div>
<?= insert('/content/answer/answer', ['data' => $data]); ?>
<?= Html::pagination($data['pNum'], $data['pagesCount'], false, '/@' . $data['profile']['login'] . '/answers'); ?>
<?php else : ?>
<?= insert('/_block/no-content', ['type' => 'small', 'text' => __('app.no_answers'), 'icon' => 'info']); ?>

View file

@ -2,11 +2,9 @@
<?= insert('/content/user/profile/header', ['data' => $data]); ?>
<div class="flex gap">
<main>
<?= __('app.comments'); ?> <b><?= $data['profile']['login']; ?></b>
<div class="mb15"><?= __('app.comments'); ?> <b><?= $data['profile']['login']; ?></b></div>
<?php if (!empty($data['comments'])) : ?>
<div class="box">
<?= insert('/content/comment/comment', ['answer' => $data['comments']]); ?>
</div>
<?= insert('/content/comment/comment', ['answer' => $data['comments']]); ?>
<?= Html::pagination($data['pNum'], $data['pagesCount'], false, '/@' . $data['profile']['login'] . '/comments'); ?>
<?php else : ?>
<?= insert('/_block/no-content', ['type' => 'small', 'text' => __('app.no_comments'), 'icon' => 'info']); ?>

View file

@ -5,13 +5,20 @@ if ($profile['cover_art'] != 'cover_art.jpeg') :
$css = 'w160 mt90 mb-mt5 mb-w80 profile-ava';
endif;
?>
<style nonce="<?= $_SERVER['nonce']; ?>">
<style>
.bg-profile {
background: <?= $profile['color']; ?>;
min-height: 90px;
}
</style>
<div class="br-gray bg-white mb15">
<div class="br-gray bg-white mb15 relative">
<?php if (UserData::checkAdmin()) : ?>
<?= insert('/_block/number-removed-content', ['data' => $data['delet_count']]); ?>
<?php endif; ?>
<?= Html::image($profile['avatar'], $profile['login'], $css, 'avatar', 'max'); ?>
<?php if ($profile['cover_art'] != 'cover_art.jpeg') : ?>

View file

@ -2,9 +2,8 @@
<?= insert('/content/user/profile/header', ['data' => $data]); ?>
<div class="flex gap">
<main>
<?= __('app.posts'); ?> <b><?= $data['profile']['login']; ?></b>
<div class="mb15"><?= __('app.posts'); ?> <b><?= $data['profile']['login']; ?></b></div>
<?= insert('/content/post/post', ['data' => $data]); ?>
<?= Html::pagination($data['pNum'], $data['pagesCount'], false, '/@' . $data['profile']['login'] . '/posts'); ?>
</main>
<aside>

View file

@ -8,7 +8,6 @@
</svg>
<span class="middle lowercase text-sm">
<?= Html::langDate($profile['created_at']); ?>
<sup class="ml5"><?= __('app.tl' . $profile['trust_level'] . '.title'); ?></sup>
</span>
</div>

View file

@ -15,4 +15,6 @@ code {
pre {
white-space: pre-wrap;
word-wrap: break-word;
}
background: #f5f2f0;
padding: 0.2em 0.5em;
}

View file

@ -360,6 +360,19 @@ iframe {
height:0
}
.delet-count {
z-index: 33;
right: 10px;
font-size: 0.8em;
color: #fff;
background-color: rgba(0, 0, 0, 0.3);
padding: 1px 6px;
position: absolute;
display: flex;
gap: 1rem;
}
/* Сделаем внешние ссылки с иконкой */
.ind-first-p a[rel~="nofollow"]::before,
.post-body a[rel~="nofollow"]::before {

View file

@ -1,7 +1,7 @@
<?php $blog = $data['facet'];
if ($blog['facet_is_deleted'] == 0) : ?>
<style nonce="<?= $_SERVER['nonce']; ?>">
<style>
.bg-blog {
background-image: linear-gradient(to right, white 0%, transparent 60%), url(<?= Html::coverUrl($blog['facet_cover_art'], 'blog'); ?>);
background-position: 50% 50%;