]>
git.wh0rd.org - tt-rss.git/blob - twitter.php
2 set_include_path(get_include_path() . PATH_SEPARATOR
.
3 dirname(__FILE__
) . "/include");
5 require_once "functions.php";
6 require_once "sessions.php";
7 require_once "sanity_check.php";
8 require_once "config.php";
10 //require_once "lib/twitteroauth/twitteroauth.php";
11 require_once "lib/tmhoauth/tmhOAuth.php";
13 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
15 if (!init_connection($link)) return;
16 login_sequence($link);
18 $owner_uid = $_SESSION["uid"];
19 $op = $_REQUEST['op'];
21 if (!SINGLE_USER_MODE
&& !$_SESSION['uid']) {
22 render_login_form($link);
26 $callback_url = get_self_url_prefix() . "/twitter.php?op=callback";
28 $tmhOAuth = new tmhOAuth(array(
29 'consumer_key' => CONSUMER_KEY
,
30 'consumer_secret' => CONSUMER_SECRET
,
34 unset($_SESSION['oauth']);
36 header("Location: twitter.php");
40 if (isset($_REQUEST['oauth_verifier'])) {
44 $tmhOAuth->config
['user_token'] = $_SESSION['oauth']['oauth_token'];
45 $tmhOAuth->config
['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];
47 $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array(
48 'oauth_verifier' => $_REQUEST['oauth_verifier']));
52 $access_token = json_encode($tmhOAuth->extract_params($tmhOAuth->response
['response']));
54 unset($_SESSION['oauth']);
56 db_query($link, "UPDATE ttrss_users SET twitter_oauth = '$access_token'
57 WHERE id = ".$_SESSION['uid']);
60 header('Location: twitter.php?op=clear');
66 if ($op == 'register') {
68 $code = $tmhOAuth->request('POST',
69 $tmhOAuth->url('oauth/request_token', ''), array(
70 'oauth_callback' => $callback));
73 $_SESSION['oauth'] = $tmhOAuth->extract_params($tmhOAuth->response
['response']);
75 $method = isset($_REQUEST['signin']) ?
'authenticate' : 'authorize';
76 $force = isset($_REQUEST['force']) ?
'&force_login=1' : '';
77 $forcewrite = isset($_REQUEST['force_write']) ?
'&oauth_access_type=write' : '';
78 $forceread = isset($_REQUEST['force_read']) ?
'&oauth_access_type=read' : '';
80 $location = $tmhOAuth->url("oauth/{$method}", '') .
81 "?oauth_token={$_SESSION['oauth']['oauth_token']}{$force}{$forcewrite}{$forceread}";
83 header("Location: $location");
91 <title
>Register with Twitter
</title
>
92 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
93 <link rel
="stylesheet" type
="text/css" href
="utility.css">
98 <h1
><?php
echo __('Register with Twitter') ?
></h1
>
100 <?php
if ($op == 'register') { ?
>
102 <p
><?php
print_error(__('Could not connect to Twitter. Refresh the page or try again later.')) ?
></p
>
104 <?php
} else if ($op == 'callback') { ?
>
106 <p
><?php
print_notice(__('Congratulations! You have successfully registered with Twitter.')) ?
>
109 <form method
="GET" action
="prefs.php">
110 <input type
="hidden" name
="tab" value
="feedConfig">
111 <button type
="submit"><?php
echo __('Return to Tiny Tiny RSS') ?
></button
>
116 <form method
="GET" action
="twitter.php" style
='display : inline'>
117 <input type
="hidden" name
="op" value
="register">
118 <button type
="submit"><?php
echo __('Register') ?
></button
>
121 <form method
="GET" action
="prefs.php" style
='display : inline'>
122 <input type
="hidden" name
="tab" value
="feedConfig">
123 <button type
="submit"><?php
echo __('Return to Tiny Tiny RSS') ?
></button
>