aboutsummaryrefslogtreecommitdiffstats
path: root/addon/twitter/twitter.php
blob: 9fccefbee0ea1b8b1711ac9d662d2cdbea455241 (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
<?php


function twitter_install() {
	register_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook');
}


function twitter_uninstall() {
	unregister_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook');
}




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

	/**
	 * Post to Twitter
	 */

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

		load_pconfig(local_user(), 'twitter');

		$ckey    = get_pconfig(local_user(), 'twitter', 'consumerkey'  );
		$csecret = get_pconfig(local_user(), 'twitter', 'consumersecret' );
		$otoken  = get_pconfig(local_user(), 'twitter', 'oauthtoken'  );
		$osecret = get_pconfig(local_user(), 'twitter', 'oauthsecret' );

		if($ckey && $csecret && $otoken && $osecret) {

			$twitter_post = get_pconfig(local_user(),'twitter','post');

			if($twitter_post) {
				require_once('addon/twitter/twitteroauth.php');
				require_once('include/bbcode.php');	

				$tweet = new TwitterOAuth($ckey,$csecret,$otoken,$osecret);
				$tweet->post('statuses/update', array('status' => bbcode($b['body'])));
			}
		}
	}
}