forked from moxi9/phpfox-facebook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.php
More file actions
62 lines (52 loc) · 2.11 KB
/
start.php
File metadata and controls
62 lines (52 loc) · 2.11 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
<?php
/**
* Using the Event handler we add JS & CSS to the <head></head>
*/
new Core\Event([
// event to attach to
'lib_phpfox_template_getheader' => function(Phpfox_Template $Template) {
if (!setting('m9_facebook_enabled')) {
$Template->setHeader('<script>var Fb_Login_Disabled = true;</script>');
$Template->setHeader('<style>.fb_login_go, #header_menu #js_block_border_user_login-block form > .table:first-of-type:before {display:none !important;} #header_menu #js_block_border_user_login-block .title { margin-bottom: 0px; }</style>');
}
}
]);
// Make sure the app is enabled
if (!setting('m9_facebook_enabled')) {
return;
}
// Use the FB SDK to set the apps ID & Secret
Facebook\FacebookSession::setDefaultApplication(setting('m9_facebook_app_id'), setting('m9_facebook_app_secret'));
// We override the main settings page since their account is connected to FB
$Url = new Core\Url();
if (Phpfox::isUser() && $Url->uri() == '/user/setting/' && substr(Phpfox::getUserBy('email'), -3) == '@fb') {
(new Core\Route('/user/setting'))->run(function(\Core\Controller $Controller) {
return $Controller->render('setting.html');
});
}
/**
* Controller for the FB login routine
*/
(new Core\Route('/fb/login'))->run(function(\Core\Controller $Controller) {
$helper = new Facebook\FacebookRedirectLoginHelper($Controller->url->make('/fb/auth'));
$loginUrl = $helper->getLoginUrl();
header('Location: ' . $loginUrl);
exit;
});
/**
* Auth routine for FB Connect. This is where we either create the new user or log them in if they are already a user.
*/
(new Core\Route('/fb/auth'))->run(function(\Core\Controller $Controller) {
$helper = new Facebook\FacebookRedirectLoginHelper($Controller->url->make('/fb/auth'));
$session = $helper->getSessionFromRedirect();
if ($session) {
$request = new Facebook\FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
$user = $response->getGraphObject(Facebook\GraphUser::className());
if ($user instanceof Facebook\GraphUser) {
$Service = new \Apps\PHPfox_Facebook\Model\Service();
$Service->create($user);
$Controller->url->send('/');
}
}
});