]> git.wh0rd.org - tt-rss.git/blob - twitter.php
fix help not loading on ? press
[tt-rss.git] / twitter.php
1 <?php
2 set_include_path(get_include_path() . PATH_SEPARATOR .
3 dirname(__FILE__) . "/include");
4
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";
10 //require_once "lib/twitteroauth/twitteroauth.php";
11 require_once "lib/tmhoauth/tmhOAuth.php";
12
13 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
14
15 if (!init_connection($link)) return;
16 login_sequence($link);
17
18 $owner_uid = $_SESSION["uid"];
19 $op = $_REQUEST['op'];
20
21 if (!SINGLE_USER_MODE && !$_SESSION['uid']) {
22 render_login_form($link);
23 exit;
24 }
25
26 $callback_url = get_self_url_prefix() . "/twitter.php?op=callback";
27
28 $tmhOAuth = new tmhOAuth(array(
29 'consumer_key' => CONSUMER_KEY,
30 'consumer_secret' => CONSUMER_SECRET,
31 ));
32
33 if ($op == 'clear') {
34 unset($_SESSION['oauth']);
35
36 header("Location: twitter.php");
37 return;
38 }
39
40 if (isset($_REQUEST['oauth_verifier'])) {
41
42 $op = 'callback';
43
44 $tmhOAuth->config['user_token'] = $_SESSION['oauth']['oauth_token'];
45 $tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];
46
47 $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array(
48 'oauth_verifier' => $_REQUEST['oauth_verifier']));
49
50 if ($code == 200) {
51
52 $access_token = json_encode($tmhOAuth->extract_params($tmhOAuth->response['response']));
53
54 unset($_SESSION['oauth']);
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
68 $code = $tmhOAuth->request('POST',
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' : '';
79
80 $location = $tmhOAuth->url("oauth/{$method}", '') .
81 "?oauth_token={$_SESSION['oauth']['oauth_token']}{$force}{$forcewrite}{$forceread}";
82
83 header("Location: $location");
84
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
98 <h1><?php echo __('Register with Twitter') ?></h1>
99
100 <?php if ($op == 'register') { ?>
101
102 <p><?php print_error(__('Could not connect to Twitter. Refresh the page or try again later.')) ?></p>
103
104 <?php } else if ($op == 'callback') { ?>
105
106 <p><?php print_notice(__('Congratulations! You have successfully registered with Twitter.')) ?>
107 </p>
108
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>
112 </form>
113
114 <?php } else { ?>
115
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>
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>
124 </form>
125
126 <?php } ?>
127
128
129 </body>
130 </html>