2010-11-22 13:32:07 +00:00
|
|
|
<?php
|
|
|
|
require_once "functions.php";
|
|
|
|
require_once "sessions.php";
|
|
|
|
require_once "sanity_check.php";
|
|
|
|
require_once "config.php";
|
|
|
|
require_once "db.php";
|
2011-03-06 09:05:58 +00:00
|
|
|
//require_once "lib/twitteroauth/twitteroauth.php";
|
|
|
|
require_once "lib/tmhoauth/tmhOAuth.php";
|
|
|
|
|
2010-11-22 13:32:07 +00:00
|
|
|
$link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
|
|
|
|
|
|
|
init_connection($link);
|
|
|
|
login_sequence($link);
|
|
|
|
|
|
|
|
$owner_uid = $_SESSION["uid"];
|
|
|
|
$op = $_REQUEST['op'];
|
|
|
|
|
|
|
|
if (!SINGLE_USER_MODE && !$_SESSION['uid']) {
|
|
|
|
render_login_form($link);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$callback_url = get_self_url_prefix() . "/twitter.php?op=callback";
|
|
|
|
|
2011-03-06 09:05:58 +00:00
|
|
|
$tmhOAuth = new tmhOAuth(array(
|
|
|
|
'consumer_key' => CONSUMER_KEY,
|
|
|
|
'consumer_secret' => CONSUMER_SECRET,
|
|
|
|
));
|
|
|
|
|
2010-11-22 13:32:07 +00:00
|
|
|
if ($op == 'clear') {
|
2011-03-06 09:05:58 +00:00
|
|
|
unset($_SESSION['oauth']);
|
2010-11-22 13:32:07 +00:00
|
|
|
|
|
|
|
header("Location: twitter.php");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-06 09:05:58 +00:00
|
|
|
if (isset($_REQUEST['oauth_verifier'])) {
|
2010-11-22 13:32:07 +00:00
|
|
|
|
2011-03-06 09:05:58 +00:00
|
|
|
$op = 'callback';
|
|
|
|
|
|
|
|
$tmhOAuth->config['user_token'] = $_SESSION['oauth']['oauth_token'];
|
|
|
|
$tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];
|
2010-11-22 13:32:07 +00:00
|
|
|
|
2011-03-06 09:05:58 +00:00
|
|
|
$code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array(
|
|
|
|
'oauth_verifier' => $_REQUEST['oauth_verifier']));
|
|
|
|
|
|
|
|
if ($code == 200) {
|
2010-11-22 13:32:07 +00:00
|
|
|
|
2011-03-06 09:05:58 +00:00
|
|
|
$access_token = json_encode($tmhOAuth->extract_params($tmhOAuth->response['response']));
|
2010-11-22 13:32:07 +00:00
|
|
|
|
2011-03-06 09:05:58 +00:00
|
|
|
unset($_SESSION['oauth']);
|
2010-11-22 13:32:07 +00:00
|
|
|
|
|
|
|
db_query($link, "UPDATE ttrss_users SET twitter_oauth = '$access_token'
|
|
|
|
WHERE id = ".$_SESSION['uid']);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
header('Location: twitter.php?op=clear');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($op == 'register') {
|
|
|
|
|
2011-03-06 09:05:58 +00:00
|
|
|
$code = $tmhOAuth->request('POST',
|
|
|
|
$tmhOAuth->url('oauth/request_token', ''), array(
|
|
|
|
'oauth_callback' => $callback));
|
|
|
|
|
|
|
|
if ($code == 200) {
|
|
|
|
$_SESSION['oauth'] = $tmhOAuth->extract_params($tmhOAuth->response['response']);
|
|
|
|
|
|
|
|
$method = isset($_REQUEST['signin']) ? 'authenticate' : 'authorize';
|
|
|
|
$force = isset($_REQUEST['force']) ? '&force_login=1' : '';
|
|
|
|
$forcewrite = isset($_REQUEST['force_write']) ? '&oauth_access_type=write' : '';
|
|
|
|
$forceread = isset($_REQUEST['force_read']) ? '&oauth_access_type=read' : '';
|
|
|
|
|
|
|
|
$location = $tmhOAuth->url("oauth/{$method}", '') .
|
|
|
|
"?oauth_token={$_SESSION['oauth']['oauth_token']}{$force}{$forcewrite}{$forceread}";
|
|
|
|
|
|
|
|
header("Location: $location");
|
2010-11-22 13:32:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Register with Twitter</title>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
|
|
<link rel="stylesheet" type="text/css" href="utility.css">
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
2010-11-22 16:25:15 +00:00
|
|
|
<h1><?php echo __('Register with Twitter') ?></h1>
|
2010-11-22 13:32:07 +00:00
|
|
|
|
|
|
|
<?php if ($op == 'register') { ?>
|
|
|
|
|
2010-11-22 16:25:15 +00:00
|
|
|
<p><?php print_error(__('Could not connect to Twitter. Refresh the page or try again later.')) ?></p>
|
2010-11-22 13:32:07 +00:00
|
|
|
|
|
|
|
<?php } else if ($op == 'callback') { ?>
|
|
|
|
|
2010-11-22 16:25:15 +00:00
|
|
|
<?php print_notice(__('Congratulations! You have successfully registered with Twitter.')) ?>
|
2010-11-22 13:32:07 +00:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<form method="GET" action="prefs.php">
|
|
|
|
<input type="hidden" name="tab" value="feedConfig">
|
2010-11-22 16:25:15 +00:00
|
|
|
<button type="submit"><?php echo __('Return to Tiny Tiny RSS') ?></button>
|
2010-11-22 13:32:07 +00:00
|
|
|
</form>
|
|
|
|
|
|
|
|
<?php } else { ?>
|
2010-11-22 16:25:15 +00:00
|
|
|
|
|
|
|
<form method="GET" action="twitter.php" style='display : inline'>
|
2010-11-22 13:32:07 +00:00
|
|
|
<input type="hidden" name="op" value="register">
|
2010-11-22 16:25:15 +00:00
|
|
|
<button type="submit"><?php echo __('Register') ?></button>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<form method="GET" action="prefs.php" style='display : inline'>
|
|
|
|
<input type="hidden" name="tab" value="feedConfig">
|
|
|
|
<button type="submit"><?php echo __('Return to Tiny Tiny RSS') ?></button>
|
2010-11-22 13:32:07 +00:00
|
|
|
</form>
|
|
|
|
|
|
|
|
<?php } ?>
|
|
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|