]>
git.wh0rd.org - tt-rss.git/blob - twitter.php
2 set_include_path(get_include_path() . PATH_SEPARATOR
. "include");
4 require_once "functions.php";
5 require_once "sessions.php";
6 require_once "sanity_check.php";
7 require_once "config.php";
9 //require_once "lib/twitteroauth/twitteroauth.php";
10 require_once "lib/tmhoauth/tmhOAuth.php";
12 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
14 if (!init_connection($link)) return;
15 login_sequence($link);
17 $owner_uid = $_SESSION["uid"];
18 $op = $_REQUEST['op'];
20 if (!SINGLE_USER_MODE
&& !$_SESSION['uid']) {
21 render_login_form($link);
25 $callback_url = get_self_url_prefix() . "/twitter.php?op=callback";
27 $tmhOAuth = new tmhOAuth(array(
28 'consumer_key' => CONSUMER_KEY
,
29 'consumer_secret' => CONSUMER_SECRET
,
33 unset($_SESSION['oauth']);
35 header("Location: twitter.php");
39 if (isset($_REQUEST['oauth_verifier'])) {
43 $tmhOAuth->config
['user_token'] = $_SESSION['oauth']['oauth_token'];
44 $tmhOAuth->config
['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];
46 $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array(
47 'oauth_verifier' => $_REQUEST['oauth_verifier']));
51 $access_token = json_encode($tmhOAuth->extract_params($tmhOAuth->response
['response']));
53 unset($_SESSION['oauth']);
55 db_query($link, "UPDATE ttrss_users SET twitter_oauth = '$access_token'
56 WHERE id = ".$_SESSION['uid']);
59 header('Location: twitter.php?op=clear');
65 if ($op == 'register') {
67 $code = $tmhOAuth->request('POST',
68 $tmhOAuth->url('oauth/request_token', ''), array(
69 'oauth_callback' => $callback));
72 $_SESSION['oauth'] = $tmhOAuth->extract_params($tmhOAuth->response
['response']);
74 $method = isset($_REQUEST['signin']) ?
'authenticate' : 'authorize';
75 $force = isset($_REQUEST['force']) ?
'&force_login=1' : '';
76 $forcewrite = isset($_REQUEST['force_write']) ?
'&oauth_access_type=write' : '';
77 $forceread = isset($_REQUEST['force_read']) ?
'&oauth_access_type=read' : '';
79 $location = $tmhOAuth->url("oauth/{$method}", '') .
80 "?oauth_token={$_SESSION['oauth']['oauth_token']}{$force}{$forcewrite}{$forceread}";
82 header("Location: $location");
90 <title
>Register with Twitter
</title
>
91 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
92 <link rel
="stylesheet" type
="text/css" href
="utility.css">
97 <h1
><?php
echo __('Register with Twitter') ?
></h1
>
99 <?php
if ($op == 'register') { ?
>
101 <p
><?php
print_error(__('Could not connect to Twitter. Refresh the page or try again later.')) ?
></p
>
103 <?php
} else if ($op == 'callback') { ?
>
105 <p
><?php
print_notice(__('Congratulations! You have successfully registered with Twitter.')) ?
>
108 <form method
="GET" action
="prefs.php">
109 <input type
="hidden" name
="tab" value
="feedConfig">
110 <button type
="submit"><?php
echo __('Return to Tiny Tiny RSS') ?
></button
>
115 <form method
="GET" action
="twitter.php" style
='display : inline'>
116 <input type
="hidden" name
="op" value
="register">
117 <button type
="submit"><?php
echo __('Register') ?
></button
>
120 <form method
="GET" action
="prefs.php" style
='display : inline'>
121 <input type
="hidden" name
="tab" value
="feedConfig">
122 <button type
="submit"><?php
echo __('Return to Tiny Tiny RSS') ?
></button
>