]> git.mxchange.org Git - friendica.git/blob - addon/facebook/facebook.php
More strings translated for french locale.
[friendica.git] / addon / facebook / facebook.php
1 <?php
2
3 /**
4  * This module needs a lot of work.
5  *
6  * - setting/storing preferences
7  * - documentation on how to obtain FB API keys for your site 
8  * - ensuring a valid FB login session
9  * - requesting permissions within the FB login session to post on your behalf until permission revoked.
10  *
11  */
12
13
14 function facebook_install() {
15         register_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook');
16 }
17
18
19 function facebook_uninstall() {
20         unregister_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook');
21 }
22
23
24
25
26 function facebook_post_hook(&$a,&$b) {
27
28         /**
29          * Post to Facebook stream
30          */
31
32         if((local_user()) && (local_user() == $b['uid']) && (! $b['private'])) {
33
34                 $appid  = get_config('system', 'facebook_appid'  );
35                 $secret = get_config('system', 'facebook_secret' );
36
37                 if($appid && $secret) {
38
39                         $fb_post = get_pconfig(local_user(),'facebook','post');
40
41                         if($fb_post) {
42                                 require_once('library/facebook.php');
43                                 require_once('include/bbcode.php');     
44
45                                 $facebook = new Facebook(array(
46                                         'appId'  => $appid,
47                                         'secret' => $secret,
48                                         'cookie' => true
49                                 ));                     
50                                 try {
51                                         $statusUpdate = $facebook->api('/me/feed', 'post', array('message'=> bbcode($b['body']), 'cb' => ''));
52                                 } 
53                                 catch (FacebookApiException $e) {
54                                         notice( t('Facebook status update failed.') . EOL);
55                                 }
56                         }
57                 }
58         }
59 }
60