-
Notifications
You must be signed in to change notification settings - Fork 2
/
post.php
69 lines (53 loc) · 1.44 KB
/
post.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
62
63
64
65
66
67
68
69
<?php
ini_set("display_errors", 1);
error_reporting(E_ALL);
require 'facebooksdk/src/facebook.php';
require 'cfg.php';
require 'db.php';
$facebook = new Facebook(array(
'appId' => Config::appId,
'secret' => Config::secret,
));
$user = $facebook->getUser();
$ext = "";
if(isset($_GET["post"])) {
if ($user) {
$stmt = DB::prepare("SELECT * FROM users WHERE user=?");
$stmt->execute(array($user));
if($stmt->rowCount() > 0) {
$row = $stmt->fetch();
$count = $row["count"];
if($count > 0) {
$ext = "";
if($count > 1) {
$ext = " for the " . addOrdinalNumberSuffix($count) . " time";
}
try {
$facebook->api('/me/feed', 'post', array('message'=> "I just played Social Roulette".$ext." and survived! – http://socialroulette.net"));
//return message
echo "success";
} catch (FacebookApiException $e) {
error_log($e);
echo "Failed";
}
} else {
echo "you need to play first";
}
} else {
echo "you need to play first";
}
} else {
echo "503";
}
}
function addOrdinalNumberSuffix($num) {
if (!in_array(($num % 100),array(11,12,13))){
switch ($num % 10) {
// Handle 1st, 2nd, 3rd
case 1: return $num.'st';
case 2: return $num.'nd';
case 3: return $num.'rd';
}
}
return $num.'th';
}