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 '
Цитировать @@ -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 '
+ =$pinc?>
Удалить photoid = $user_id; } public function i($table) { diff --git a/app/Models/User.php b/app/Models/User.php index 6587593..a0115d4 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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) { diff --git a/static/js/act.js b/static/js/act.js index c026f9f..005c55a 100644 --- a/static/js/act.js +++ b/static/js/act.js @@ -31,7 +31,7 @@ function createModal(id, type, value, modalid) {