]>
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";
8 require_once "lib/tmhoauth/tmhOAuth.php";
10 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
12 init_connection($link);
13 login_sequence($link);
15 $owner_uid = $_SESSION["uid"];
16 $op = $_REQUEST['op'];
18 if (!SINGLE_USER_MODE
&& !$_SESSION['uid']) {
19 render_login_form($link);
23 $callback_url = get_self_url_prefix() . "/twitter.php?op=callback";
25 $tmhOAuth = new tmhOAuth(array(
26 'consumer_key' => CONSUMER_KEY
,
27 'consumer_secret' => CONSUMER_SECRET
,
31 unset($_SESSION['oauth']);
33 header("Location: twitter.php");
37 if (isset($_REQUEST['oauth_verifier'])) {
41 $tmhOAuth->config
['user_token'] = $_SESSION['oauth']['oauth_token'];
42 $tmhOAuth->config
['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];
44 $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array(
45 'oauth_verifier' => $_REQUEST['oauth_verifier']));
49 $access_token = json_encode($tmhOAuth->extract_params($tmhOAuth->response
['response']));
51 unset($_SESSION['oauth']);
53 db_query($link, "UPDATE ttrss_users SET twitter_oauth = '$access_token'
54 WHERE id = ".$_SESSION['uid']);
57 header('Location: twitter.php?op=clear');
63 if ($op == 'register') {
65 $code = $tmhOAuth->request('POST',
66 $tmhOAuth->url('oauth/request_token', ''), array(
67 'oauth_callback' => $callback));
70 $_SESSION['oauth'] = $tmhOAuth->extract_params($tmhOAuth->response
['response']);
72 $method = isset($_REQUEST['signin']) ?
'authenticate' : 'authorize';
73 $force = isset($_REQUEST['force']) ?
'&force_login=1' : '';
74 $forcewrite = isset($_REQUEST['force_write']) ?
'&oauth_access_type=write' : '';
75 $forceread = isset($_REQUEST['force_read']) ?
'&oauth_access_type=read' : '';
77 $location = $tmhOAuth->url("oauth/{$method}", '') .
78 "?oauth_token={$_SESSION['oauth']['oauth_token']}{$force}{$forcewrite}{$forceread}";
80 header("Location: $location");
88 <title
>Register with Twitter
</title
>
89 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
90 <link rel
="stylesheet" type
="text/css" href
="utility.css">
95 <h1
><?php
echo __('Register with Twitter') ?
></h1
>
97 <?php
if ($op == 'register') { ?
>
99 <p
><?php
print_error(__('Could not connect to Twitter. Refresh the page or try again later.')) ?
></p
>
101 <?php
} else if ($op == 'callback') { ?
>
103 <?php
print_notice(__('Congratulations! You have successfully registered with Twitter.')) ?
>
106 <form method
="GET" action
="prefs.php">
107 <input type
="hidden" name
="tab" value
="feedConfig">
108 <button type
="submit"><?php
echo __('Return to Tiny Tiny RSS') ?
></button
>
113 <form method
="GET" action
="twitter.php" style
='display : inline'>
114 <input type
="hidden" name
="op" value
="register">
115 <button type
="submit"><?php
echo __('Register') ?
></button
>
118 <form method
="GET" action
="prefs.php" style
='display : inline'>
119 <input type
="hidden" name
="tab" value
="feedConfig">
120 <button type
="submit"><?php
echo __('Return to Tiny Tiny RSS') ?
></button
>