diff --git a/app/Controllers/Api/Images/Comments/Load.php b/app/Controllers/Api/Images/Comments/Load.php index d73d394..f1b81c5 100644 --- a/app/Controllers/Api/Images/Comments/Load.php +++ b/app/Controllers/Api/Images/Comments/Load.php @@ -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 { diff --git a/app/Controllers/Api/Images/Comments/Pin.php b/app/Controllers/Api/Images/Comments/Pin.php new file mode 100644 index 0000000..1f05b8a --- /dev/null +++ b/app/Controllers/Api/Images/Comments/Pin.php @@ -0,0 +1,41 @@ + $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', + ) + ); + } + + + } + + } +} \ No newline at end of file diff --git a/app/Controllers/Api/Images/Upload.php b/app/Controllers/Api/Images/Upload.php index f3e974a..ce660b2 100644 --- a/app/Controllers/Api/Images/Upload.php +++ b/app/Controllers/Api/Images/Upload.php @@ -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) { diff --git a/app/Controllers/Api/Register.php b/app/Controllers/Api/Register.php index a7eb17d..732bd2e 100644 --- a/app/Controllers/Api/Register.php +++ b/app/Controllers/Api/Register.php @@ -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( diff --git a/app/Controllers/ApiController.php b/app/Controllers/ApiController.php index 05e4220..bb2d0c9 100644 --- a/app/Controllers/ApiController.php +++ b/app/Controllers/ApiController.php @@ -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(); } diff --git a/app/Core/Routes.php b/app/Core/Routes.php index fac02d8..6f17358 100644 --- a/app/Core/Routes.php +++ b/app/Core/Routes.php @@ -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'); diff --git a/app/Models/Comment.php b/app/Models/Comment.php index 99298cf..e349de2 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -28,7 +28,15 @@ class Comment { $user = new User($this->c['user_id']); $content = json_decode($this->c['content'], true); - echo '
+ $photo = new \App\Models\Photo($this->c['photo_id']); + + $pinc = 'Закрепить'; + echo '
'; + if ($photo->i('pinnedcomment_id') === $this->c['id']) { + echo 'Комментарий закреплён'; + $pinc = 'Открепить'; + } + echo '
' . Date::zmdate($this->c['posted_at']) . '
Цитировать @@ -97,12 +105,13 @@ class Comment display: block; } '; - if ($this->c['user_id'] === Auth::userid()) { + if ($this->c['user_id'] === Auth::userid() || $photo->i('user_id') === Auth::userid()) { echo '
`; -} + } 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() { diff --git a/views/components/LoadHead.php b/views/components/LoadHead.php index c853c61..d01aff9 100644 --- a/views/components/LoadHead.php +++ b/views/components/LoadHead.php @@ -1,6 +1,6 @@ - NativeGallery + <?=NGALLERY['root']['title']?> diff --git a/views/pages/Photo.php b/views/pages/Photo.php index 8980087..c7105d7 100644 --- a/views/pages/Photo.php +++ b/views/pages/Photo.php @@ -222,6 +222,8 @@ if ($photo->i('id') !== null) { Подробная информация
+ 0) { ?>

Инструменты

@@ -239,6 +241,7 @@ if ($photo->i('id') !== null) {
+ i('moderated') === 1 && $photo->content('rating') != 'disabled') { ?>

Оценка

diff --git a/views/pages/Vehicle.php b/views/pages/Vehicle.php index 6597ed9..8b4b9aa 100644 --- a/views/pages/Vehicle.php +++ b/views/pages/Vehicle.php @@ -49,7 +49,7 @@ $vehicledatavariables = json_decode($data['content'], true); foreach ($photos as $p) { $author = new User($p['user_id']); echo '
-
678 КБ +678 КБ
'; if (DB::query('SELECT COUNT(*) FROM photos_comments WHERE photo_id=:id', array(':id'=>$p['id']))[0]['COUNT(*)'] >= 1) { echo '
'.DB::query('SELECT COUNT(*) FROM photos_comments WHERE photo_id=:id', array(':id'=>$p['id']))[0]['COUNT(*)'].'
';