mirror of
https://github.com/claradex/nativegallery.git
synced 2025-04-13 03:47:31 +03:00
pin comments and some fixes
This commit is contained in:
parent
cc193f35ab
commit
1caedf698b
13 changed files with 124 additions and 13 deletions
|
@ -5,7 +5,7 @@ namespace App\Controllers\Api\Images\Comments;
|
|||
|
||||
|
||||
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json, EXIF};
|
||||
use App\Models\{User, Vote, Comment};
|
||||
use App\Models\{User, Vote, Comment, Photo};
|
||||
|
||||
|
||||
class Load
|
||||
|
@ -14,10 +14,19 @@ class Load
|
|||
{
|
||||
|
||||
$comments = DB::query('SELECT * FROM photos_comments WHERE photo_id=:pid', array(':pid' => explode('/', $_SERVER['REQUEST_URI'])[4]));
|
||||
$photo = new Photo(explode('/', $_SERVER['REQUEST_URI'])[4]);
|
||||
$number = 1;
|
||||
if ((int)$photo->i('pinnedcomment_id') != 0) {
|
||||
$comm = new Comment(DB::query('SELECT * FROM photos_comments WHERE id=:id', array(':id'=>$photo->i('pinnedcomment_id')))[0]);
|
||||
$class = 's1';
|
||||
$comm->class($class);
|
||||
$number++;
|
||||
$comm->i();
|
||||
}
|
||||
foreach ($comments as $c) {
|
||||
$comm = new Comment($c);
|
||||
if ($comm->content('deleted') != 'true') {
|
||||
$photo = new Photo($c['photo_id']);
|
||||
if ($comm->content('deleted') != 'true' && (int)$photo->i('pinnedcomment_id') != (int)$c['id']) {
|
||||
if ($number % 2 == 0) {
|
||||
$class = 's11';
|
||||
} else {
|
||||
|
|
41
app/Controllers/Api/Images/Comments/Pin.php
Normal file
41
app/Controllers/Api/Images/Comments/Pin.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controllers\Api\Images\Comments;
|
||||
|
||||
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json};
|
||||
|
||||
class Pin
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$postId = explode('/', $_SERVER['REQUEST_URI'])[4];
|
||||
$cpostid = DB::query('SELECT photo_id FROM photos_comments WHERE id=:id', array(':id' => $postId))[0]['photo_id'];
|
||||
if (DB::query('SELECT user_id FROM photos WHERE id=:id', array(':id' => $cpostid))[0]['user_id'] === Auth::userid()) {
|
||||
|
||||
$data = DB::query('SELECT * FROM photos WHERE id=:id', array(':id'=>$cpostid))[0];
|
||||
if ($data['pinnedcomment_id'] === (int)$postId) {
|
||||
DB::query('UPDATE photos SET pinnedcomment_id=0 WHERE id=:id', array(':id'=>$cpostid));
|
||||
echo json_encode(
|
||||
array(
|
||||
'errorcode' => '0',
|
||||
'error' => 0,
|
||||
'action' => 'unpin',
|
||||
)
|
||||
);
|
||||
} else {
|
||||
DB::query('UPDATE photos SET pinnedcomment_id=:pid WHERE id=:id', array(':pid'=>$postId, ':id'=>$cpostid));
|
||||
echo json_encode(
|
||||
array(
|
||||
'errorcode' => '0',
|
||||
'error' => 0,
|
||||
'action' => 'pin',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ class Upload
|
|||
} else {
|
||||
$moderated = 1;
|
||||
}
|
||||
DB::query('INSERT INTO photos VALUES (\'0\', :userid, :postbody, :photourl, :time, :timeup, :exif, 0, :moderated, :place, 0, :gallery, :entityid, :content)', array(':postbody' => $postbody, ':userid' => Auth::userid(), ':time' => mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']), ':content' => $content, ':photourl' => self::$photourl, ':exif' => $exif, ':place' => $_POST['place'], ':timeup' => time(), ':moderated' => $moderated, ':gallery'=>$_POST['gallery'], ':entityid'=>self::$entitydata_id));
|
||||
DB::query('INSERT INTO photos VALUES (\'0\', :userid, :postbody, :photourl, :time, :timeup, :exif, 0, :moderated, :place, 0, :gallery, :entityid, 0, :content)', array(':postbody' => $postbody, ':userid' => Auth::userid(), ':time' => mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']), ':content' => $content, ':photourl' => self::$photourl, ':exif' => $exif, ':place' => $_POST['place'], ':timeup' => time(), ':moderated' => $moderated, ':gallery'=>$_POST['gallery'], ':entityid'=>self::$entitydata_id));
|
||||
if (($moderated === 1) && (self::$subsnotify != 'disabled')) {
|
||||
$followers = DB::query('SELECT * FROM followers WHERE user_id=:uid', array(':uid' => Auth::userid()));
|
||||
foreach ($followers as $f) {
|
||||
|
|
|
@ -318,11 +318,11 @@ class Register
|
|||
'regdate' => time()
|
||||
)
|
||||
);
|
||||
if (NGALLERY['root']['registration']['emailverify'] == 'true') {
|
||||
if (NGALLERY['root']['registration']['emailverify'] === true) {
|
||||
$status === 3;
|
||||
}
|
||||
DB::query('INSERT INTO users VALUES (\'0\', :username, :email, :password, :photourl, 5, :online, 0, :status, :content)', array(':username' => ltrim($username), ':password' => password_hash(ltrim($password), PASSWORD_BCRYPT), ':photourl' => '/static/img/avatar.png', ':email' => $email, ':content' => $content, ':online' => time(), ':status'=>$status));
|
||||
if (NGALLERY['root']['registration']['emailverify'] == 'true') {
|
||||
if (NGALLERY['root']['registration']['emailverify'] === true) {
|
||||
$disposableEmailFilter = new DisposableEmailFilter();
|
||||
if ($disposableEmailFilter->isDisposableEmailAddress($_POST['email'])) {
|
||||
echo json_encode(
|
||||
|
|
|
@ -16,6 +16,7 @@ use \App\Controllers\Api\Images\Stats as PhotoStats;
|
|||
use \App\Controllers\Api\Images\Comments\Create as PhotoComment;
|
||||
use \App\Controllers\Api\Images\Comments\Edit as PhotoCommentEdit;
|
||||
use \App\Controllers\Api\Images\Comments\Delete as PhotoCommentDelete;
|
||||
use \App\Controllers\Api\Images\Comments\Pin as PhotoCommentPin;
|
||||
use \App\Controllers\Api\Images\Comments\Load as PhotoCommentLoad;
|
||||
use \App\Controllers\Api\Images\Comments\Rate as PhotoCommentVote;
|
||||
use \App\Controllers\Api\Vehicles\Load as VehiclesLoad;
|
||||
|
@ -57,6 +58,9 @@ class ApiController
|
|||
public static function photocommentdelete() {
|
||||
return new PhotoCommentDelete();
|
||||
}
|
||||
public static function photocommentpin() {
|
||||
return new PhotoCommentPin();
|
||||
}
|
||||
public static function photocommentvote() {
|
||||
return new PhotoCommentVote();
|
||||
}
|
||||
|
|
|
@ -36,7 +36,8 @@ class Routes
|
|||
Router::get('/api/users/load/$id', 'ApiController@loaduser');
|
||||
Router::get('/api/users/emailverify', 'ApiController@emailverify');
|
||||
Router::get('/article/$id', 'MainController@gallery');
|
||||
|
||||
Router::get('/voting', 'ContestsController@index');
|
||||
Router::get('/voting/results', 'ContestsController@results');
|
||||
|
||||
if (Auth::userid() > 0) {
|
||||
$user = new \App\Models\User(Auth::userid());
|
||||
|
@ -62,6 +63,7 @@ class Routes
|
|||
Router::get('/api/photo/comment/rate', 'ApiController@photocommentvote');
|
||||
Router::post('/api/photo/comment/$id/edit', 'ApiController@photocommentedit');
|
||||
Router::post('/api/photo/comment/$id/delete', 'ApiController@photocommentdelete');
|
||||
Router::post('/api/photo/comment/$id/pin', 'ApiController@photocommentpin');
|
||||
Router::get('/api/vehicles/load', 'ApiController@vehiclesload');
|
||||
if ($user->i('admin') > 0) {
|
||||
Router::any('/admin', 'AdminController@index');
|
||||
|
|
|
@ -28,7 +28,15 @@ class Comment
|
|||
{
|
||||
$user = new User($this->c['user_id']);
|
||||
$content = json_decode($this->c['content'], true);
|
||||
echo '<div class="' . $this->class . ' comment" wid="' . $this->c['id'] . '">
|
||||
$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 '
|
||||
<div style="float:right; text-align:right" class="sm">
|
||||
<span class="message_date">' . Date::zmdate($this->c['posted_at']) . '</span><br>
|
||||
<a href="#" class="quoteLink dot">Цитировать</a>
|
||||
|
@ -97,12 +105,13 @@ class Comment
|
|||
display: block;
|
||||
}
|
||||
</style>';
|
||||
if ($this->c['user_id'] === Auth::userid()) {
|
||||
if ($this->c['user_id'] === Auth::userid() || $photo->i('user_id') === Auth::userid()) {
|
||||
echo '
|
||||
<div class="dropdown">
|
||||
<a style="color: #000" class="compl" href="/lk/ticket.php?action=add&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>
|
||||
<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 '
|
||||
|
|
|
@ -5,7 +5,7 @@ use \App\Services\DB;
|
|||
class Photo {
|
||||
|
||||
public $photoid;
|
||||
function __construct(int $user_id) {
|
||||
function __construct($user_id) {
|
||||
$this->photoid = $user_id;
|
||||
}
|
||||
public function i($table) {
|
||||
|
|
|
@ -5,7 +5,7 @@ use \App\Services\DB;
|
|||
class User {
|
||||
|
||||
public $userid;
|
||||
function __construct(int $user_id) {
|
||||
function __construct($user_id) {
|
||||
$this->userid = $user_id;
|
||||
}
|
||||
public function i($table) {
|
||||
|
|
|
@ -31,7 +31,7 @@ function createModal(id, type, value, modalid) {
|
|||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
}
|
||||
document.body.innerHTML += modal;
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,49 @@ document.addEventListener("click", function(event) {
|
|||
|
||||
|
||||
|
||||
const pinComment = (postId) => {
|
||||
$(document).ready(function() {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '/api/photo/comment/'+postId+'/pin',
|
||||
success: function(response) {
|
||||
var jsonData = JSON.parse(response);
|
||||
|
||||
console.log(response);
|
||||
if (jsonData.errorcode == "1") {
|
||||
Notify.noty('danger', JSON.stringify(response));
|
||||
} else {
|
||||
if (jsonData.action == "pin") {
|
||||
Notify.noty('success', 'Успешно закреплено!');
|
||||
} else {
|
||||
Notify.noty('success', 'Успешно откреплено!');
|
||||
}
|
||||
|
||||
const url = window.location.pathname;
|
||||
const segments = url.split('/');
|
||||
const id = segments[segments.length - 1];
|
||||
$.ajax({
|
||||
|
||||
|
||||
type: "POST",
|
||||
url: "/api/photo/getcomments/"+id,
|
||||
processData: false,
|
||||
async: true,
|
||||
success: function(r) {
|
||||
$('#posts').html(r)
|
||||
|
||||
|
||||
},
|
||||
error: function(r) {
|
||||
console.log(r)
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const editComment = (postId, body, modalid) => {
|
||||
$(document).ready(function() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
|
||||
<meta name="viewport" content="width=1000,user-scalable=yes">
|
||||
<title>NativeGallery</title>
|
||||
<title><?=NGALLERY['root']['title']?></title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=PT+Sans+Narrow:wght@400;700&display=swap" rel="stylesheet">
|
||||
|
|
|
@ -222,6 +222,8 @@ if ($photo->i('id') !== null) {
|
|||
<a href="/photoext?id=<?= $id ?>">Подробная информация</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
if (Auth::userid() > 0) { ?>
|
||||
<div class="p0" id="pp-item-tools">
|
||||
<h4 class="pp-item-header">Инструменты</h4>
|
||||
<div class="pp-item-body" style="margin:7px 5px">
|
||||
|
@ -239,6 +241,7 @@ if ($photo->i('id') !== null) {
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if ($photo->i('moderated') === 1 && $photo->content('rating') != 'disabled') { ?>
|
||||
<div class="p20a" id="pp-item-vote">
|
||||
<h4 class="pp-item-header">Оценка</h4>
|
||||
|
|
|
@ -49,7 +49,7 @@ $vehicledatavariables = json_decode($data['content'], true);
|
|||
foreach ($photos as $p) {
|
||||
$author = new User($p['user_id']);
|
||||
echo '<div class="p20p s11"><table><tbody><tr>
|
||||
<td class="pb_photo" id="p1987895"><a href="/photo/1987895/ target="_blank" class="prw"><img class="f" src="/api/photo/compress?url='.$p['photourl'].'" alt="678 КБ">
|
||||
<td class="pb_photo" id="p1987895"><a href="/photo/'.$p['id'].'/ target="_blank" class="prw"><img class="f" src="/api/photo/compress?url='.$p['photourl'].'" alt="678 КБ">
|
||||
<div class="hpshade">';
|
||||
if (DB::query('SELECT COUNT(*) FROM photos_comments WHERE photo_id=:id', array(':id'=>$p['id']))[0]['COUNT(*)'] >= 1) {
|
||||
echo '<div class="com-icon">'.DB::query('SELECT COUNT(*) FROM photos_comments WHERE photo_id=:id', array(':id'=>$p['id']))[0]['COUNT(*)'].'</div>';
|
||||
|
|
Loading…
Reference in a new issue