|
| 1 | +# Facebook Connect Integration Module |
| 2 | + |
| 3 | +## Maintainer Contact |
| 4 | + * Will Rossiter |
| 5 | + <will (at) fullscreen (dot) io> |
| 6 | + |
| 7 | +## Requirements |
| 8 | + * SilverStripe 3.0 |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +The module provides a **basic** interface for implementing Facebook connect on |
| 13 | +a website. Facebook connect allows users to login to your website using their |
| 14 | +Facebook account. This module integrates that single sign-on within the existing |
| 15 | +SilverStripe member system. |
| 16 | + |
| 17 | +This has been designed to use the Javascript SDK rather than the OAuth interface. |
| 18 | + |
| 19 | +### What it provides |
| 20 | + |
| 21 | + * Loads and setups Facebook Connect for Single Sign on via the Javascript SDK |
| 22 | + |
| 23 | + * Authenticates users visiting the site - if they are logged into Facebook then |
| 24 | + you can access their information via the following controls. You can also |
| 25 | + optionally set whether to save visitors information as members on your site |
| 26 | + (for example if you need to cache their information) |
| 27 | + |
| 28 | + If you haven't disabled the FacebookConnect::$create_member variable you can |
| 29 | + access the Facebook's member information by using: |
| 30 | + |
| 31 | + ``` |
| 32 | + <% control CurrentMember %> |
| 33 | + $FirstName $LastName $Avatar(small) |
| 34 | + <% end_control %> |
| 35 | + ``` |
| 36 | + |
| 37 | + If you have disabled the creation of members you can use the Facebook specific |
| 38 | + member control. This still returns a member object the only difference is that |
| 39 | + it won't save the information to the database |
| 40 | + |
| 41 | + ``` |
| 42 | + <% control CurrentFacebookMember %> |
| 43 | + $FirstName $LastName $Avatar(small) |
| 44 | + <% end_control %> |
| 45 | + ``` |
| 46 | + |
| 47 | +### What it does not provide (yet) |
| 48 | + |
| 49 | + * This current iteration only provides the backbone. In future updates I am aiming |
| 50 | + to integrate things like publishing stories to a users wall, interacting with events, |
| 51 | + groups and other things like friends. |
| 52 | + * More controls over the logged in members information (eg status updates, events, |
| 53 | + groups). If you need this functionality you can build this on top of the Facebook API |
| 54 | + which is exposed: |
| 55 | + |
| 56 | + ```php |
| 57 | + function foo() { |
| 58 | + // returns the likes |
| 59 | + $likes = $this->getFacebook()->api('/me/likes'); |
| 60 | + } |
| 61 | + ``` |
| 62 | + |
| 63 | +### How to use |
| 64 | + |
| 65 | + * To setup Facebook connect your first need to download this and put it in your |
| 66 | + SilverStripe sites root folder. |
| 67 | + * You need to register your website / application at |
| 68 | + https://developers.facebook.com/apps/?action=create |
| 69 | + * Once you have registered your app set the following in your mysite/_config.php |
| 70 | + file. Replace the values with the ones you should get after registering your app. |
| 71 | + |
| 72 | + ```php |
| 73 | + FacebookConnect::set_app_id('app-id'); |
| 74 | + FacebookConnect::set_api_secret('api-secret'); |
| 75 | + FacebookConnect::set_lang('en_US'); |
| 76 | + ``` |
| 77 | + |
| 78 | + * Update the database by running `/dev/build` to add the additional fields to |
| 79 | + the `Member` table. |
| 80 | + |
| 81 | + * Include the `ConnectInit.ss` template in the `<body>` part of every site you |
| 82 | + wish to call a Facebook function. This includes the Facebook JavaScript SDK. |
| 83 | + E.g. on `FrontendPage.ss` |
| 84 | + |
| 85 | + ``` |
| 86 | + <body> |
| 87 | + <% include ConnectInit %> |
| 88 | + ``` |
| 89 | + |
| 90 | +Once you have done that you should be able to use the includes provided in this module. |
| 91 | + |
| 92 | +``` |
| 93 | +<% if CurrentFacebookMember %> |
| 94 | + <p>Hi $CurrentFacebookMember.FirstName</p> |
| 95 | + <% include ConnectLogout %> |
| 96 | +<% else %> |
| 97 | + <% include ConnectLogin %> |
| 98 | +<% end_if %> |
| 99 | +``` |
| 100 | +
|
| 101 | +You can also access the Facebook member information in your PHP code. The Facebook API |
| 102 | +connection and current member are cached on the controller object. So for example if |
| 103 | +this is in your Page_Controller class |
| 104 | +
|
| 105 | +```php |
| 106 | +// returns the current facebook member (wrapped in a SS Member Object) |
| 107 | +$this->getCurrentFacebookMember(); |
| 108 | +
|
| 109 | +// returns the API connection which you can use to write your own query |
| 110 | +$this->getFacebook(); |
| 111 | +``` |
| 112 | + |
| 113 | +### License |
| 114 | + |
| 115 | +Released under the BSD License. |
| 116 | + |
0 commit comments