-
Notifications
You must be signed in to change notification settings - Fork 1
/
handle-me-too.php
48 lines (37 loc) · 1.32 KB
/
handle-me-too.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
<?php
try {
# POST to /topics/$sfn_id/me_toos
require_once('Sprinkles.php');
$sprink = new Sprinkles();
$sfn_id = request_param('sfn_id');
$creds = $sprink->current_user_session();
if (!$creds) {
$target_page = $preview_after_login # setting in config.php
? 'topic.php' : 'handle-me-too.php';
$args = 'sfn_id=' . urlencode($sfn_id);
redirect('user-login.php?return=' .
urlencode($target_page . '?' . $args));
exit(0);
}
$POST_URL = $sprink->api_url("topics/" . $sfn_id . "/me_toos");
$req = $sprink->oauthed_request('POST', $POST_URL, $creds, null, array("askdjnaksjdbas" => "aksjhdaksjdnaksjdnka"));
$responseCode = $req->getResponseCode();
if (0 == $responseCode) {
die("Timeout accessing the API, while posting to $POST_URL."); # FIXME: recover for user
} else if (400 == $responseCode) {
redirect('topic.php?sfn_id=' . $sfn_id .
'&me_too_failed=true');
exit(0);
} else if (201 != $responseCode) {
die("API Error $responseCode me-tooing topic $sfn_id.");
}
$topic_url = $sprink->api_url("topics/" . $sfn_id);
invalidate_http_cache($topic_url);
redirect('topic.php?sfn_id=' . $sfn_id .
'&me_tood_topic=true');
exit(0);
} catch (Exception $e) {
error_log("Exception thrown while preparing page: " . $e->getMessage());
$smarty->display('error.t');
}
?>