config['facebook']['appid'] = 'xxxxxxxxxxx';
* $a->config['facebook']['appsecret'] = 'xxxxxxxxxxxxxxx';
* Replace with the settings Facebook gives you.
* 2. Enable the facebook plugin by including it in .htconfig.php - e.g.
* $a->config['system']['addon'] = 'plugin1,plugin2,facebook';
* 3. Visit your site url + '/facebook' (e.g. http://example.com/facebook)
* and click 'Install Facebook posting'.
* 4. This will ask you to login to Facebook and grant permission to the
* plugin to do its stuff. Allow it to do so.
* 5. You're done. To turn it off visit your site's /facebook page again and
* 'Remove Facebook posting'.
*
* Turn logging on (see the github Friendika wiki page 'Settings') and
* repeat these steps if you have trouble.
* Vidoes and embeds will not be posted if there is no other content. Links
* and images will be converted to text and long posts truncated - with a link
* to view the full post. Posts with permission settings and comments will
* not be posted to Facebook.
*
*/
define('FACEBOOK_MAXPOSTLEN', 420);
/* declare the facebook_module function so that /facebook url requests will land here */
function facebook_module() {}
/* If a->argv[1] is a nickname, this is a callback from Facebook oauth requests. */
function facebook_init(&$a) {
if($a->argc != 2)
return;
$nick = $a->argv[1];
if(strlen($nick))
$r = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
dbesc($nick)
);
if(! count($r))
return;
$uid = $r[0]['uid'];
$auth_code = (($_GET['code']) ? $_GET['code'] : '');
$error = (($_GET['error_description']) ? $_GET['error_description'] : '');
if($error)
logger('facebook_init: Error: ' . $error);
if($auth_code && $uid) {
$appid = get_config('facebook','appid');
$appsecret = get_config('facebook', 'appsecret');
$x = fetch_url('https://graph.facebook.com/oauth/access_token?client_id='
. $appid . '&client_secret=' . $appsecret . '&redirect_uri='
. urlencode($a->get_baseurl() . '/facebook/' . $nick)
. '&code=' . $auth_code);
logger('facebook_init: returned access token: ' . $x, LOGGER_DATA);
if(strpos($x,'access_token=') !== false) {
$token = str_replace('access_token=', '', $x);
if(strpos($token,'&') !== false)
$token = substr($token,0,strpos($token,'&'));
set_pconfig($uid,'facebook','access_token',$token);
set_pconfig($uid,'facebook','post','1');
}
// todo: is this a browser session or a server session? where do we go?
}
}
function facebook_post(&$a) {
if(local_user()){
$value = ((x($_POST,'post_by_default')) ? intval($_POST['post_by_default']) : 0);
set_pconfig(local_user(),'facebook','post_by_default', $value);
}
return;
}
function facebook_content(&$a) {
if(! local_user()) {
notice( t('Permission denied.') . EOL);
return '';
}
if($a->argc > 1 && $a->argv[1] === 'remove') {
del_pconfig(local_user(),'facebook','post');
notice( t('Facebook disabled') . EOL);
}
$fb_installed = get_pconfig(local_user(),'facebook','post');
$appid = get_config('facebook','appid');
if(! $appid) {
notice( t('Facebook API key is missing.') . EOL);
return '';
}
$a->page['htmlhead'] .= '' . "\r\n";
$o .= '