nativegallery/app/Models/Comment.php

137 lines
6.2 KiB
PHP
Raw Normal View History

2024-07-05 11:51:14 +03:00
<?php
2024-07-05 11:51:14 +03:00
namespace App\Models;
2024-10-01 06:31:32 +03:00
use \App\Services\{DB, Date, Auth};
2024-07-06 09:57:51 +03:00
use \App\Models\{User, Photo, Vote};
2024-07-05 11:51:14 +03:00
class Comment
{
2024-07-05 11:51:14 +03:00
public $commentid;
public $c;
2024-07-21 16:58:26 +03:00
public $class;
function __construct($user_id)
{
2024-07-05 11:51:14 +03:00
$this->c = $user_id;
}
public function class($class)
{
2024-07-21 16:58:26 +03:00
$this->class = $class;
}
public function content($table)
{
2024-10-08 21:42:55 +03:00
$content = json_decode($this->c['content'], true);
return $content[$table];
}
public function i()
{
2024-07-05 11:51:14 +03:00
$user = new User($this->c['user_id']);
2024-10-07 17:06:43 +03:00
$content = json_decode($this->c['content'], true);
2025-02-09 03:12:54 +03:00
$photo = new \App\Models\Photo($this->c['photo_id']);
$pinc = 'Закрепить';
echo '<div class="' . $this->class . ' comment" wid="' . $this->c['id'] . '">';
if ($photo->i('pinnedcomment_id') === $this->c['id']) {
echo '<i style="padding-bottom: 15px;">Комментарий закреплён</i>';
$pinc = 'Открепить';
}
echo '
2024-07-05 11:51:14 +03:00
<div style="float:right; text-align:right" class="sm">
<span class="message_date">' . Date::zmdate($this->c['posted_at']) . '</span><br>
2024-07-21 16:58:26 +03:00
<a href="#" class="quoteLink dot">Цитировать</a>
·
<a href="#' . $this->c['id'] . '" class="cmLink dot">Ссылка</a>
2024-10-07 17:06:43 +03:00
';
echo '
2024-07-05 11:51:14 +03:00
</div>
<a name="2681468"></a><a name="last"></a>
<div><img src="' . $user->i('photourl') . '" width="32" style="border-radius: 3px; margin-right: 5px;"><b><a href="/author/' . $this->c['user_id'] . '/" class="message_author">' . htmlspecialchars($user->i('username')) . '</a></b> &middot;
2024-07-05 15:03:35 +03:00
<span class="flag">';
if (json_decode($user->i('content'), true)['aboutrid']['value'] != null) {
echo '<img src="/static/img/flags/' . json_decode($user->i('content'), true)['aboutrid']['value'] . '.gif">';
}
if (json_decode($user->i('content'), true)['aboutlive']['value'] != null) {
echo ' ' . htmlspecialchars(json_decode($user->i('content'), true)['aboutlive']['value']);
}
if ($content['edited'] === 'true') {
echo '<br>(отредактировано)';
}
if ($user->i('admin') === 1) {
$admintype = ' · Администратор сервера';
} else if ($user->i('admin') === 2) {
$admintype = ' · Фотомодератор';
}
if ((int)Vote::countcommrates($this->c['id'], -1) >= 1) {
$commclass = 'pro';
$symb = '+';
} else if ((int)Vote::countcommrates($this->c['id'], -1) < 0) {
$commclass = 'con';
$symb = '';
} else if ((int)Vote::countcommrates($this->c['id'], -1) === 0) {
$commclass = '';
}
echo '</span></div>
<div class="rank">Фото: ' . Photo::fetchAll($this->c['user_id']) . ' ' . $admintype . '</div>
<div class="message-text">' . preg_replace("~(?:[\p{M}]{1})([\p{M}])+?~uis", "", htmlspecialchars($this->c['body'])) . '</div>
';
if ($content['filetype'] === 'img') {
echo '<div class="message-text"><img src="'.$content['src'].'" width="250"></div>';
}
if ($content['filetype'] === 'video') {
echo '<div class="message-text"><video controls src="'.$content['src'].'" width="250"></div>';
}
echo '
2024-07-05 11:51:14 +03:00
<div class="comment-votes-block">
2024-10-01 06:31:32 +03:00
';
echo '<style>
2024-10-01 06:31:32 +03:00
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
}
.dropdown:hover .dropdown-content {
display: block;
}
</style>';
2025-02-09 03:12:54 +03:00
if ($this->c['user_id'] === Auth::userid() || $photo->i('user_id') === Auth::userid()) {
echo '
2024-10-01 06:31:32 +03:00
<div class="dropdown">
<a style="color: #000" class="compl" href="/lk/ticket.php?action=add&amp;wid=3252565">...</a>
<div class="dropdown-content">'; ?>
<a style="margin-bottom: 10px;" href="#" onclick="createModal(<?= $this->c['id'] ?>, 'EDIT_COMMENT', '<?= htmlspecialchars($this->c['body']) ?>', 'modaledit<?= $this->c['id'] ?>'); return false;">Редактировать</a><br>
2025-02-09 03:12:54 +03:00
<a href="#" onclick="pinComment(<?= $this->c['id'] ?>); return false;"><?=$pinc?></a><br>
<a href="#" onclick="createModal(<?= $this->c['id'] ?>, 'DELETE_COMMENT', '', 'modaldel<?= $this->c['id'] ?>'); return false;">Удалить</a>
<?php
echo '
2024-10-01 06:31:32 +03:00
</div>
</div>
';
}
echo '
<div class="wvote" wid="' . $this->c['id'] . '">
2024-07-06 09:57:51 +03:00
<a href="#" vote="1" class="w-btn s2"><span>+</span></a>
2024-10-01 06:31:32 +03:00
<div class="w-rating ' . $commclass . ' active">' . $symb . Vote::countcommrates($this->c['id'], -1) . '</div>
2024-10-01 06:31:32 +03:00
2024-07-05 11:51:14 +03:00
<div class="w-rating-ext">
<div><span class="pro">+' . Vote::countcommrates($this->c['id'], 1) . '</span> / <span class="con">' . Vote::countcommrates($this->c['id'], 0) . '</span></div>
2024-07-05 11:51:14 +03:00
</div>
2024-07-06 09:57:51 +03:00
<a href="#" vote="0" class="w-btn s5"><span></span></a>
2024-07-05 11:51:14 +03:00
</div>
</div>
</div>';
}
}