From 005c93ae0e8aad7767f51bdd9cc569a92c4562c5 Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Fri, 19 Jul 2024 01:37:41 +0300 Subject: [PATCH] subscribe to users --- app/Controllers/Api/Subscribe.php | 45 +++++++++++++++++++++++++++++++ app/Controllers/ApiController.php | 4 +++ app/Core/Routes.php | 1 + static/js/comments.js | 17 ------------ views/pages/Profile/Index.php | 40 +++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 app/Controllers/Api/Subscribe.php diff --git a/app/Controllers/Api/Subscribe.php b/app/Controllers/Api/Subscribe.php new file mode 100644 index 0000000..3aa8248 --- /dev/null +++ b/app/Controllers/Api/Subscribe.php @@ -0,0 +1,45 @@ +$sid, ':followerid'=>Auth::userid()))) { + DB::query('INSERT INTO followers VALUES (\'0\', :userid, :followerid)', array(':userid'=>$sid, ':followerid'=>Auth::userid())); + $countusers = DB::query('SELECT COUNT(1) FROM followers WHERE `user_id`=:id', array(':id'=>$sid))[0]['COUNT(1)']; + + + + + + echo 1; + + } else { + DB::query('DELETE FROM followers WHERE user_id=:userid AND follower_id=:followerid', array(':userid'=>$sid, ':followerid'=>Auth::userid())); + + + echo 0; + } + } + + + } +} \ No newline at end of file diff --git a/app/Controllers/ApiController.php b/app/Controllers/ApiController.php index f74e6dd..4df9d7d 100644 --- a/app/Controllers/ApiController.php +++ b/app/Controllers/ApiController.php @@ -5,6 +5,7 @@ use \App\Services\{Router, Auth, DB, Json}; use \App\Controllers\ExceptionRegister; use \App\Core\Page; use \App\Controllers\Api\{Login, Register}; +use \App\Controllers\Api\Subscribe as SubscribeUser; use \App\Controllers\Api\Images\{Upload}; use \App\Controllers\Api\Images\Rate as PhotoVote; use \App\Controllers\Api\Images\Compress as PhotoCompress; @@ -47,6 +48,9 @@ class ApiController public static function adminsetvis() { return new AdminPhotoSetVisibility(); } + public static function subscribeuser() { + return new SubscribeUser(); + } } \ No newline at end of file diff --git a/app/Core/Routes.php b/app/Core/Routes.php index 97c7915..7d49b49 100644 --- a/app/Core/Routes.php +++ b/app/Core/Routes.php @@ -38,6 +38,7 @@ class Routes Router::post('/api/upload', 'ApiController@upload'); Router::post('/api/profile/update', 'ApiController@updateprofile'); Router::post('/api/photo/comment', 'ApiController@photocomment'); + Router::get('/api/subscribe', 'ApiController@subscribeuser'); Router::get('/api/photo/compress', 'ApiController@photocompress'); Router::post('/api/photo/getcomments/$id', 'ApiController@photocommentload'); Router::get('/api/photo/vote', 'ApiController@photovote'); diff --git a/static/js/comments.js b/static/js/comments.js index 0f15fc2..be86b1f 100644 --- a/static/js/comments.js +++ b/static/js/comments.js @@ -158,21 +158,4 @@ $(document).ready(function() .on('focus', function() { navLock = true; }) .on('blur', function() { navLock = false; }); - - // Переключатель подписки - $('.toggle, .toggle-label').on('click', function(e) - { - if (e.target.tagName == 'A') return; - var toggle = $('.toggle').toggleClass('on'); - - $.get('/api.php', { action: 'subscribe', id: $('#id').val(), subj: $('#subj').val() }, function (r) - { - if (r != 0 && r != 1) - { - toggle.toggleClass('on'); - alert(r); - } - else toggle.attr('class', (r == 1) ? 'toggle on' : 'toggle'); - }); - }); }); \ No newline at end of file diff --git a/views/pages/Profile/Index.php b/views/pages/Profile/Index.php index 7228990..79599a5 100644 --- a/views/pages/Profile/Index.php +++ b/views/pages/Profile/Index.php @@ -216,6 +216,46 @@ $userprofile = new User(explode('/', $_SERVER['REQUEST_URI'])[2]);
+ + i('id') != Auth::userid()) { ?> + + $userprofile->i('id'), ':followerid' => Auth::userid()))) { +$class = 'on'; + } + ?> +