forked from coollog/yale17
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfbheader.php
More file actions
64 lines (61 loc) · 1.58 KB
/
Copy pathfbheader.php
File metadata and controls
64 lines (61 loc) · 1.58 KB
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
<?php
require 'fbphpsdk/facebook.php';
define('USERLIST', 'userlist.list');
$facebook = new Facebook(array(
'appId' => '642157445814007',
'secret' => '06079d477192bad968a74b4aebc268bb',
));
$user = $facebook->getUser();
$error = null;
$ingroup = false;
if ($user) {
try {
// User is logged in.
// Check if part of Class of 2017 group.
$groups = $facebook->api('me/groups?fields=id');
foreach($groups['data'] as $group) {
if ($group['id'] == 386287368059235) {
$ingroup = true;
$userlist = getusers();
if(!in_array($user, $userlist)){
array_push($userlist, $user);
saveusers($userlist);
}
break;
}
}
if (!$ingroup) {
$error = 'You must be in the <a href="https://www.facebook.com/groups/386287368059235/">Yale College Class of 2017</a> group.';
}
} catch (FacebookApiException $e) {
// User is not logged in.
$loginUrl = $facebook->getLoginUrl();
$error = "Not connected!";
$user = null;
}
} else {
$error = "Not connected!";
}
function isappuser($userid) {
$r = $facebook->api(array(
'method' => 'fql.query',
'query' => "SELECT is_app_user FROM user WHERE uid=$userid"
));
return $r[0]['is_app_user'];
}
function getusers() {
if (file_exists(USERLIST)) {
return file(USERLIST, FILE_IGNORE_NEW_LINES);
} else {
fclose(fopen(USERLIST, 'w'));
return array();
}
}
function saveusers($userlist) {
$f = fopen(USERLIST, 'w');
foreach($userlist as $user) {
fwrite($f, $user.PHP_EOL);
}
fclose($f);
}
?>