diff --git a/app/Controllers/Api/Images/Favorite.php b/app/Controllers/Api/Images/Favorite.php new file mode 100644 index 0000000..0f28140 --- /dev/null +++ b/app/Controllers/Api/Images/Favorite.php @@ -0,0 +1,25 @@ + $postId, ':uid'=>Auth::userid()])) { + DB::query('DELETE FROM photos_favorite WHERE photo_id = :id AND user_id=:uid', ['id' => $postId, ':uid'=>Auth::userid()]); + echo 0; + } else { + DB::query('INSERT INTO photos_favorite (photo_id, user_id) VALUES (:id, :uid)', ['id' => $postId, ':uid'=>Auth::userid()]); + echo 1; + } + + } +} diff --git a/app/Controllers/ApiController.php b/app/Controllers/ApiController.php index 1e2acef..99870c8 100644 --- a/app/Controllers/ApiController.php +++ b/app/Controllers/ApiController.php @@ -11,6 +11,7 @@ use \App\Controllers\Api\Images\Rate as PhotoVote; use \App\Controllers\Api\Images\Compress as PhotoCompress; use \App\Controllers\Api\Images\CheckAll as PhotoCheckAll; use \App\Controllers\Api\Images\LoadRecent as PhotoLoadRecent; +use \App\Controllers\Api\Images\Favorite as PhotoFavorite; 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; @@ -37,6 +38,9 @@ class ApiController public static function photovote() { return new PhotoVote(); } + public static function photofavorite() { + return new PhotoFavorite(); + } public static function photocomment() { return new PhotoComment(); } diff --git a/app/Controllers/MainController.php b/app/Controllers/MainController.php index 01979ee..18ccb5f 100644 --- a/app/Controllers/MainController.php +++ b/app/Controllers/MainController.php @@ -57,6 +57,11 @@ class MainController { Page::set('Feed'); + } + public static function fav() + { + Page::set('Fav'); + } public static function favauthors() { diff --git a/app/Core/Routes.php b/app/Core/Routes.php index 026b6f5..1e7c09c 100644 --- a/app/Core/Routes.php +++ b/app/Core/Routes.php @@ -46,9 +46,12 @@ class Routes Router::get('/search', 'SearchController@i'); + Router::get('/fav', 'MainController@fav'); + Router::post('/api/upload', 'ApiController@upload'); Router::post('/api/profile/update', 'ApiController@updateprofile'); Router::post('/api/photo/comment', 'ApiController@photocomment'); + Router::get('/api/photo/$id/favorite', 'ApiController@photofavorite'); Router::get('/api/subscribe', 'ApiController@subscribeuser'); Router::post('/api/photo/getcomments/$id', 'ApiController@photocommentload'); Router::get('/api/photo/vote', 'ApiController@photovote'); diff --git a/static/js/photo.js b/static/js/photo.js index 6820b17..f1697d3 100644 --- a/static/js/photo.js +++ b/static/js/photo.js @@ -209,11 +209,14 @@ $(document).ready(function() // Избранное $('#favLink').click(function() { + const url = window.location.pathname; + const segments = url.split('/'); + const id = segments[segments.length - 1]; var faved = parseInt($(this).attr('faved')); - $(this).html(_text[faved ? 'P_ADDFAV' : 'P_DELFAV']).attr('faved', faved ? 0 : 1); - if (!faved && subscr_fav) $('.toggle').attr('class', 'toggle on'); + $(this).html(faved ? 'Добавить фото в Избранное' : 'Удалить фото из Избранного').attr('faved', faved ? 0 : 1); + if (!faved) $('.toggle').attr('class', 'toggle on'); - $.get('/api.php', { action: 'fav-photo', pid : pid }, function (r) { if (r != 0 && r != 1) alert(r); }).fail(function(jx) { if (jx.responseText != '') alert(jx.responseText); }); + $.get('/api/photo/'+id+'/favorite', function (r) { if (r != 0 && r != 1) alert(r); }).fail(function(jx) { if (jx.responseText != '') alert(jx.responseText); }); return false; }); diff --git a/views/components/Navbar.php b/views/components/Navbar.php index 13e715b..6172f2e 100644 --- a/views/components/Navbar.php +++ b/views/components/Navbar.php @@ -108,7 +108,7 @@ if ($noncheckedimgs > 0) {
+ Избранные фотографии+ + + Auth::userid())); + foreach ($photos as $p) { + $photo = new Photo($p['photo_id']); + $user = new User($p['user_id']); + echo '
+
'; + } + ?> + + + + + |
+ ||