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