mirror of
https://github.com/claradex/nativegallery.git
synced 2024-11-15 03:31:10 +03:00
subscribe to users
This commit is contained in:
parent
ecf87f56ac
commit
005c93ae0e
5 changed files with 90 additions and 17 deletions
45
app/Controllers/Api/Subscribe.php
Normal file
45
app/Controllers/Api/Subscribe.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
namespace App\Controllers\Api;
|
||||
|
||||
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json};
|
||||
use \App\Controllers\ExceptionRegister;
|
||||
use \App\Core\Page;
|
||||
use PDO;
|
||||
|
||||
class Subscribe
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (isset($_GET['id'])) {
|
||||
$sid = $_GET['id'];
|
||||
} else {
|
||||
die();
|
||||
}
|
||||
|
||||
if (Auth::userid() != $sid) {
|
||||
|
||||
if (!DB::query('SELECT follower_id FROM followers WHERE user_id=:userid AND follower_id=:followerid', array(':userid'=>$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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -216,6 +216,46 @@ $userprofile = new User(explode('/', $_SERVER['REQUEST_URI'])[2]);
|
|||
</table>
|
||||
</div>
|
||||
<div style="margin-top: 25px;"><b><a href="/search?id=<?=$userprofile->i('id')?>">Найти все фотографии, сделанные этим пользователем</a></b></div>
|
||||
|
||||
<?php
|
||||
if ($userprofile->i('id') != Auth::userid()) { ?>
|
||||
<script>
|
||||
|
||||
|
||||
$(document).ready(function()
|
||||
{
|
||||
$('.toggle, .toggle-label').on('click', function()
|
||||
{
|
||||
var toggle = $('.toggle').toggleClass('on');
|
||||
|
||||
var subscr_cnt = $('#subscr_cnt');
|
||||
var cnt = parseInt(subscr_cnt.text());
|
||||
subscr_cnt.html(toggle.is('.on') ? cnt+1 : cnt-1);
|
||||
|
||||
$.get('/api/subscribe', { action: 'subscribe', id: <?=$userprofile->i('id')?>, subj: 'a' }, function (r)
|
||||
{
|
||||
if (r != 0 && r != 1)
|
||||
{
|
||||
toggle.toggleClass('on');
|
||||
alert(r);
|
||||
}
|
||||
else toggle.attr('class', (r == 1) ? 'toggle on' : 'toggle');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
<?php
|
||||
if (DB::query('SELECT follower_id FROM followers WHERE user_id=:userid AND follower_id=:followerid', array(':userid' => $userprofile->i('id'), ':followerid' => Auth::userid()))) {
|
||||
$class = 'on';
|
||||
}
|
||||
?>
|
||||
<div><div class="toggle <?=$class?>"><div class="handle"></div></div> <label class="toggle-label"><b>Подписка на новые фотографии этого автора</b> (подписаны: <b id="subscr_cnt"><?=DB::query('SELECT COUNT(*) FROM followers WHERE user_id=:uid', array(':uid'=>$userprofile->i('id')))[0]['COUNT(*)'];?></b>)</label></div>
|
||||
|
||||
<?php } else { ?>
|
||||
<div>Пользователей, подписанных на мои фотографии: <b><?=DB::query('SELECT COUNT(*) FROM followers WHERE user_id=:uid', array(':uid'=>$userprofile->i('id')))[0]['COUNT(*)'];?></b></div>
|
||||
<?php } ?>
|
||||
<?php } else { ?>
|
||||
<center><h1>Пользователь не найден</h1></center>
|
||||
<center><img src="/static/img/404.jpg"></center>
|
||||
|
|
Loading…
Reference in a new issue