]> git.wh0rd.org - tt-rss.git/blame - twitter.php
only enable ob_gzhandler if it exists
[tt-rss.git] / twitter.php
CommitLineData
ff3e303a 1<?php
f03a795d
AD
2 set_include_path(get_include_path() . PATH_SEPARATOR .
3 dirname(__FILE__) . "/include");
107d0cf3 4
ff3e303a
AD
5 require_once "functions.php";
6 require_once "sessions.php";
7 require_once "sanity_check.php";
8 require_once "config.php";
9 require_once "db.php";
54a3dd8d
AD
10 //require_once "lib/twitteroauth/twitteroauth.php";
11 require_once "lib/tmhoauth/tmhOAuth.php";
12
107d0cf3 13 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
ff3e303a 14
5f0a3741 15 if (!init_connection($link)) return;
ff3e303a 16 login_sequence($link);
107d0cf3 17
ff3e303a
AD
18 $owner_uid = $_SESSION["uid"];
19 $op = $_REQUEST['op'];
20
107d0cf3 21 if (!SINGLE_USER_MODE && !$_SESSION['uid']) {
ff3e303a
AD
22 render_login_form($link);
23 exit;
24 }
25
26 $callback_url = get_self_url_prefix() . "/twitter.php?op=callback";
27
54a3dd8d
AD
28 $tmhOAuth = new tmhOAuth(array(
29 'consumer_key' => CONSUMER_KEY,
30 'consumer_secret' => CONSUMER_SECRET,
107d0cf3 31 ));
54a3dd8d 32
ff3e303a 33 if ($op == 'clear') {
54a3dd8d 34 unset($_SESSION['oauth']);
ff3e303a
AD
35
36 header("Location: twitter.php");
37 return;
38 }
39
54a3dd8d 40 if (isset($_REQUEST['oauth_verifier'])) {
ff3e303a 41
54a3dd8d
AD
42 $op = 'callback';
43
44 $tmhOAuth->config['user_token'] = $_SESSION['oauth']['oauth_token'];
45 $tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];
ff3e303a 46
54a3dd8d
AD
47 $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array(
48 'oauth_verifier' => $_REQUEST['oauth_verifier']));
107d0cf3 49
54a3dd8d 50 if ($code == 200) {
ff3e303a 51
54a3dd8d 52 $access_token = json_encode($tmhOAuth->extract_params($tmhOAuth->response['response']));
ff3e303a 53
54a3dd8d 54 unset($_SESSION['oauth']);
ff3e303a
AD
55
56 db_query($link, "UPDATE ttrss_users SET twitter_oauth = '$access_token'
57 WHERE id = ".$_SESSION['uid']);
58
59 } else {
60 header('Location: twitter.php?op=clear');
61 return;
62 }
63
64 }
65
66 if ($op == 'register') {
67
107d0cf3 68 $code = $tmhOAuth->request('POST',
54a3dd8d
AD
69 $tmhOAuth->url('oauth/request_token', ''), array(
70 'oauth_callback' => $callback));
71
72 if ($code == 200) {
73 $_SESSION['oauth'] = $tmhOAuth->extract_params($tmhOAuth->response['response']);
74
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' : '';
107d0cf3
AD
79
80 $location = $tmhOAuth->url("oauth/{$method}", '') .
54a3dd8d
AD
81 "?oauth_token={$_SESSION['oauth']['oauth_token']}{$force}{$forcewrite}{$forceread}";
82
83 header("Location: $location");
ff3e303a 84
ff3e303a
AD
85 }
86 }
87?>
88
89<html>
90<head>
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">
94</head>
95
96<body>
97
6ef0c9c3 98<h1><?php echo __('Register with Twitter') ?></h1>
ff3e303a
AD
99
100<?php if ($op == 'register') { ?>
101
6ef0c9c3 102<p><?php print_error(__('Could not connect to Twitter. Refresh the page or try again later.')) ?></p>
ff3e303a
AD
103
104<?php } else if ($op == 'callback') { ?>
105
e331188f 106 <p><?php print_notice(__('Congratulations! You have successfully registered with Twitter.')) ?>
ff3e303a
AD
107 </p>
108
109 <form method="GET" action="prefs.php">
110 <input type="hidden" name="tab" value="feedConfig">
6ef0c9c3 111 <button type="submit"><?php echo __('Return to Tiny Tiny RSS') ?></button>
ff3e303a
AD
112 </form>
113
114<?php } else { ?>
6ef0c9c3
AD
115
116 <form method="GET" action="twitter.php" style='display : inline'>
ff3e303a 117 <input type="hidden" name="op" value="register">
6ef0c9c3
AD
118 <button type="submit"><?php echo __('Register') ?></button>
119 </form>
120
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>
ff3e303a
AD
124 </form>
125
126<?php } ?>
127
128
129</body>
130</html>