-
Notifications
You must be signed in to change notification settings - Fork 0
/
likes.php
32 lines (26 loc) · 936 Bytes
/
likes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
require 'inc/bootstrap.php';
$db = App::getDatabase();
App::getAuth()->restrict();
if(!isset($_POST['ref_id']) OR !isset($_POST['user_id'])){
http_response_code(403);
die();
}
$accepted_refs = ['camagru.photo'];
if (!in_array($_POST['ref_photo'], $accepted_refs)){
http_response_code(403);
die();
}
$vote = new Vote();
if ($_POST['vote'] == 1){
$success = $vote->like($db, $_POST['ref_photo'], $_POST['ref_id'], $_SESSION['auth']->id);
}
else{
$success = $vote->dislike($db, $_POST['ref_photo'], $_POST['ref_id'], $_SESSION['auth']->id);
}
$req = $db->query("SELECT like_count, dislike_count FROM {$_POST['ref_photo']} WHERE id_photo = ?", [$_POST['ref_id']]);
header('Content-type: application/json');
$record = $req->fetch(PDO::FETCH_ASSOC);
$record['success'] = $success;
die(json_encode($record));
?>