forked from Kitware/digitalpath-webserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfollow.php
62 lines (56 loc) · 1.23 KB
/
follow.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
52
53
54
55
56
57
58
59
60
61
<?php
header('Content-Type: text/javascript; charset=utf8');
try
{
@$username = $_REQUEST['username'];
if(!isset($username))
{
header("HTTP/1.1 400 Bad Request");
return;
}
require_once("config.php"); # get $server and $database
$conn = new Mongo('mongodb://' . $server);
$collection = $conn->selectDB($database)->selectCollection("follow");
$followDoc = $collection->findOne(array("username" => $username));
if($followDoc != null )
{
$followTimeout = 30;
if (time() - $followDoc['timestamp']->sec <= $followTimeout) # only send data for recently-updated sessions
{
$followProperties = array(
'username',
'img',
'sess',
'zoom',
'cenx',
'ceny',
'rotation',
'bookmarks',
'curx',
'cury'
);
$followData = array();
foreach ($followProperties as $prop)
{
$followData[$prop] = $followDoc[$prop];
}
echo json_encode($followData);
return;
}
else
{
# delete expired sessions
$collection->remove(array("username" => $username));
}
}
# if data wasn't sent
header("HTTP/1.1 204 No Content");
}
# Error handling
catch (Exception $e)
{
# TODO: send a better failure response to client
header("HTTP/1.1 500 Internal Server Error");
return;
}
?>