aboutsummaryrefslogtreecommitdiffstats
path: root/addon/facebook/facebook.php
blob: acf37fcdbb7d1a87d9769200f5b49b5c1d1a9502 (plain) (blame)
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
<?php

/**
 * This module needs a lot of work.
 *
 * - setting/storing preferences
 * - documentation on how to obtain FB API keys for your site 
 * - ensuring a valid FB login session
 * - requesting permissions within the FB login session to post on your behalf until permission revoked.
 *
 */


function facebook_install() {
	register_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook');
}


function facebook_uninstall() {
	unregister_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook');
}




function facebook_post_hook(&$a,&$b) {

	/**
	 * Post to Facebook stream
	 */

	if((local_user()) && (local_user() == $b['uid']) && (! $b['private'])) {

		$appid  = get_config('system', 'facebook_appid'  );
		$secret = get_config('system', 'facebook_secret' );

		if($appid && $secret) {

			$fb_post = get_pconfig(local_user(),'facebook','post');

			if($fb_post) {
				require_once('library/facebook.php');
				require_once('include/bbcode.php');	

				$facebook = new Facebook(array(
					'appId'  => $appid,
					'secret' => $secret,
					'cookie' => true
				));			
				try {
					$statusUpdate = $facebook->api('/me/feed', 'post', array('message'=> bbcode($b['body']), 'cb' => ''));
				} 
				catch (FacebookApiException $e) {
					notice( t('Facebook status update failed.') . EOL);
				}
			}
		}
	}
}