From 558a5cb4c0c74d1e1a9971d96e39516306dbde59 Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Tue, 11 Feb 2025 20:38:42 +0300 Subject: [PATCH] fix pin --- app/Controllers/Api/Images/Comments/Load.php | 11 ++------- static/js/act.js | 7 +++--- static/js/core_lk.js | 25 +++++++++++--------- views/pages/Photo.php | 2 +- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/app/Controllers/Api/Images/Comments/Load.php b/app/Controllers/Api/Images/Comments/Load.php index f1b81c5..b81862b 100644 --- a/app/Controllers/Api/Images/Comments/Load.php +++ b/app/Controllers/Api/Images/Comments/Load.php @@ -13,20 +13,13 @@ class Load public function __construct() { - $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]); + $comments = DB::query('SELECT * FROM photos_comments WHERE photo_id=:pid ORDER BY CASE WHEN id = :pinnedid THEN 0 ELSE 1 END, id ASC', array(':pid' => explode('/', $_SERVER['REQUEST_URI'])[4], ':pinnedid' => $photo->i('pinnedcomment_id'))); $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); $photo = new Photo($c['photo_id']); - if ($comm->content('deleted') != 'true' && (int)$photo->i('pinnedcomment_id') != (int)$c['id']) { + if ($comm->content('deleted') != 'true') { if ($number % 2 == 0) { $class = 's11'; } else { diff --git a/static/js/act.js b/static/js/act.js index 005c55a..73471d6 100644 --- a/static/js/act.js +++ b/static/js/act.js @@ -78,8 +78,9 @@ const pinComment = (postId) => { } const url = window.location.pathname; - const segments = url.split('/'); - const id = segments[segments.length - 1]; + const segments = url.split('/'); + const id = segments[2]; + console.log(segments); $.ajax({ @@ -121,7 +122,7 @@ const editComment = (postId, body, modalid) => { Notify.noty('success', 'Успешно отредактировано!'); const url = window.location.pathname; const segments = url.split('/'); - const id = segments[segments.length - 1]; + const id = segments[2]; $.ajax({ diff --git a/static/js/core_lk.js b/static/js/core_lk.js index cab2587..f51e0ab 100644 --- a/static/js/core_lk.js +++ b/static/js/core_lk.js @@ -165,17 +165,20 @@ $(document).ready(function() - - $('#place').autocompleteHL({ - minLength: 3, - source: function(request, response) - { - var cid = $('#search_cid').val(); - if (cid != 0) - $.getJSON('/api/geodb/search', { place: request.term }, response).fail(function(jx) { alert(jx.responseText); }); - else response(null); - } - }); + var placeElement = document.getElementById('place'); + if (placeElement) { + $('#place').autocompleteHL({ + minLength: 3, + source: function(request, response) + { + var cid = $('#search_cid').val(); + if (cid != 0) + $.getJSON('/api/geodb/search', { place: request.term }, response).fail(function(jx) { alert(jx.responseText); }); + else response(null); + } + }); + } + $('#image').click(function() diff --git a/views/pages/Photo.php b/views/pages/Photo.php index f85dfda..0e9ca32 100644 --- a/views/pages/Photo.php +++ b/views/pages/Photo.php @@ -587,7 +587,7 @@ if ($photo->i('id') !== null) { i('moderated') === 1) { - $comments = DB::query('SELECT * FROM photos_comments WHERE photo_id=:pid', array(':pid' => $id)); + $comments = DB::query('SELECT * FROM photos_comments WHERE photo_id=:pid ORDER BY CASE WHEN id = :pinnedid THEN 0 ELSE 1 END, id ASC', array(':pid' => $id, ':pinnedid' => $photo->i('pinnedcomment_id'))); $commcount = 0; foreach ($comments as $c) { if (json_decode($c['content'], true)['deleted'] != 'true') {