]>
git.wh0rd.org - tt-rss.git/blob - twitter.php
2 require_once "functions.php";
3 require_once "sessions.php";
4 require_once "sanity_check.php";
5 require_once "config.php";
7 require_once "lib/twitteroauth/twitteroauth.php";
9 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
11 init_connection($link);
12 login_sequence($link);
14 $owner_uid = $_SESSION["uid"];
15 $op = $_REQUEST['op'];
17 if (!SINGLE_USER_MODE
&& !$_SESSION['uid']) {
18 render_login_form($link);
22 $callback_url = get_self_url_prefix() . "/twitter.php?op=callback";
25 /* Remove no longer needed request tokens */
26 unset($_SESSION['oauth_token']);
27 unset($_SESSION['oauth_token_secret']);
28 unset($_SESSION['access_token']);
30 header("Location: twitter.php");
34 if ($op == 'callback') {
35 /* If the oauth_token is old redirect to the connect page. */
36 if (isset($_REQUEST['oauth_token']) &&
37 $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
39 $_SESSION['oauth_status'] = 'oldtoken';
40 header('Location: twitter.php?op=clear');
44 /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
45 $connection = new TwitterOAuth(CONSUMER_KEY
, CONSUMER_SECRET
, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
47 /* Request access tokens from twitter */
48 $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
50 /* If HTTP response is 200 continue otherwise send to connect page to retry */
51 if ($connection->http_code
== 200) {
52 $access_token = db_escape_string(json_encode($access_token));
54 db_query($link, "UPDATE ttrss_users SET twitter_oauth = '$access_token'
55 WHERE id = ".$_SESSION['uid']);
58 header('Location: twitter.php?op=clear');
64 if ($op == 'register') {
66 /* Build TwitterOAuth object with client credentials. */
67 $connection = new TwitterOAuth(CONSUMER_KEY
, CONSUMER_SECRET
);
69 /* Get temporary credentials. */
70 $request_token = $connection->getRequestToken($callback_url);
72 /* Save temporary credentials to session. */
73 $_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
74 $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
76 if ($connection->http_code
== 200) {
77 $url = $connection->getAuthorizeURL($token);
78 header('Location: ' . $url);
86 <title
>Register with Twitter
</title
>
87 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
88 <link rel
="stylesheet" type
="text/css" href
="utility.css">
93 <h1
><?php
echo __('Register with Twitter') ?
></h1
>
95 <?php
if ($op == 'register') { ?
>
97 <p
><?php
print_error(__('Could not connect to Twitter. Refresh the page or try again later.')) ?
></p
>
99 <?php
} else if ($op == 'callback') { ?
>
101 <?php
print_notice(__('Congratulations! You have successfully registered with Twitter.')) ?
>
104 <form method
="GET" action
="prefs.php">
105 <input type
="hidden" name
="tab" value
="feedConfig">
106 <button type
="submit"><?php
echo __('Return to Tiny Tiny RSS') ?
></button
>
111 <form method
="GET" action
="twitter.php" style
='display : inline'>
112 <input type
="hidden" name
="op" value
="register">
113 <button type
="submit"><?php
echo __('Register') ?
></button
>
116 <form method
="GET" action
="prefs.php" style
='display : inline'>
117 <input type
="hidden" name
="tab" value
="feedConfig">
118 <button type
="submit"><?php
echo __('Return to Tiny Tiny RSS') ?
></button
>