-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathajax.php
51 lines (37 loc) · 844 Bytes
/
ajax.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
include('config.php');
$method = optional_param('m');
switch ($method) {
case 'tweet':
saveTweet(optional_param('text'));
break;
case 'follow':
addFollower(optional_param('userid'));
break;
case 'unfollow':
removeFollower(optional_param('userid'));
break;
default:
# code...
break;
}
function saveTweet($message)
{
$tweets = R::dispense('tweets');
$tweets->userid = $_SESSION['user_id'];
$tweets->tweets = $message;
$id = R::store($tweets);
}
function addFollower($userid)
{
$following = R::dispense('following');
$following->userid = $_SESSION['user_id'];
$following->follows = $userid;
$id = R::store($following);
}
function removeFollower($userid)
{
$following = R::findOne('following','userid = ? AND follows = ?', array($_SESSION['user_id'],$userid));
R::trash($following);
}
?>