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