tiki-socialnetworks.php 2.99 KB
Newer Older
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
3 4 5 6 7 8 9 10
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

$section = 'mytiki';
require_once ('tiki-setup.php');
require_once ('lib/socialnetworkslib.php');
changi67's avatar
changi67 committed
11
$access->check_feature('feature_socialnetworks');
12 13 14
$access->check_permission('tiki_p_socialnetworks',tra('Social networks'));

if (isset($_REQUEST['request_twitter'])) {
nkoth's avatar
nkoth committed
15
	$access->check_user($user);
16 17 18 19 20 21 22 23 24 25 26 27
	if (!isset($_REQUEST['oauth_verifier'])) {
		// user asked to give us access to twitter
		$socialnetworkslib->getTwitterRequestToken();
	} else {
		if (isset($_SESSION['TWITTER_REQUEST_TOKEN'])) {
			// this is the callback from twitter
			check_ticket('socialnetworks');
			$socialnetworkslib->getTwitterAccessToken($user);
		} // otherwise it is just a reload of this page
	}
}
if (isset($_REQUEST['remove_twitter'])) {
nkoth's avatar
nkoth committed
28
	$access->check_user($user);
29 30 31 32
	// remove user token from tiki
	$tikilib->set_user_preference($user, 'twitter_token','');
	$smarty->assign('show_removal',true);
}
nkoth's avatar
nkoth committed
33 34 35 36
if ($user) {
	$token=$tikilib->get_user_preference($user, 'twitter_token', '');
	$smarty->assign('twitter', ($token!=''));
}
37 38

if (isset($_REQUEST['request_facebook'])) {
nkoth's avatar
nkoth committed
39 40 41
	if ($prefs["socialnetworks_facebook_login"] != 'y') {
		$access->check_user($user);
	}
42
	if (!isset($_REQUEST['code'])) {
nkoth's avatar
nkoth committed
43
		// user asked to give us access to Facebook
44 45
		$socialnetworkslib->getFacebookRequestToken();
	} else {
nkoth's avatar
nkoth committed
46 47 48 49 50 51 52 53 54 55
		// this is the callback from facebook
		check_ticket('socialnetworks');
		if ($user) {
			if ($tikilib->get_user_preference($user, 'facebook_token', '')=='') {
				$socialnetworkslib->getFacebookAccessToken();
			} // if user already has a token, it is just a refresh of the page
		} else {
			// Simply login user with Facebook
			$socialnetworkslib->getFacebookAccessToken();
		}
56 57 58
	}
}
if (isset($_REQUEST['remove_facebook'])) {
nkoth's avatar
nkoth committed
59
	$access->check_user($user);
60 61 62 63
	// remove user token from tiki
	$tikilib->set_user_preference($user, 'facebook_token','');
	$smarty->assign('show_removal',true);
}
64 65

if (isset($_REQUEST['accounts'])) {
nkoth's avatar
nkoth committed
66
	$access->check_user($user);
67 68 69 70 71 72 73 74
	$tikilib->set_user_preference($user, 'bitly_login', $_REQUEST['bitly_login']);
	$smarty->assign('bitly_login',$_REQUEST['bitly_login']);		
	$tikilib->set_user_preference($user, 'bitly_key', $_REQUEST['bitly_key']);
	$smarty->assign('bitly_key',$_REQUEST['bitly_key']);		
} else {
	$smarty->assign('bitly_login',$tikilib->get_user_preference($user, 'bitly_login',''));
	$smarty->assign('bitly_key',$tikilib->get_user_preference($user, 'bitly_key',''));
}
nkoth's avatar
nkoth committed
75 76 77 78
if ($user) {
	$token=$tikilib->get_user_preference($user, 'facebook_token', '');
	$smarty->assign('facebook', ($token!=''));
}
79 80 81
$smarty->assign('twitterRegistered',$socialnetworkslib->twitterRegistered());
$smarty->assign('facebookRegistered',$socialnetworkslib->facebookRegistered());

82 83 84
ask_ticket('socialnetworks');
$smarty->assign('mid', 'tiki-socialnetworks.tpl');
$smarty->display("tiki.tpl");