2 /* Start session and load lib */
6 include_once('lib/twitese.php');
7 foreach ($AUTH_ID as &$id) {
10 if (isset($_REQUEST['oauth_token'])) {
11 if($_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
12 $_SESSION['oauth_status'] = 'oldtoken';
14 header('Location: login.php?oauth=old');exit();
16 /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
17 $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
19 /* Request access tokens from twitter */
20 $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
22 /* Save the access tokens. Normally these would be saved in a database for future use. */
23 $_SESSION['access_token'] = $access_token;
25 /* Remove no longer needed request tokens */
26 unset($_SESSION['oauth_token']);
27 unset($_SESSION['oauth_token_secret']);
29 /* If HTTP response is 200 continue otherwise send to connect page to retry */
30 if (200 == $connection->http_code) {
31 /* The user has been verified and the access tokens can be saved for future use */
32 $_SESSION['login_status'] = 'verified';
34 $user = $t->veverify();
36 if ( ID_AUTH && (!in_array(strtoupper($t->screen_name),$AUTH_ID)) ){
38 header("Location: login.php?oauth=denied");exit;
40 /* And set new cookies */
41 $time = $_SERVER['REQUEST_TIME']+3600*24*365;
42 setEncryptCookie('oauth_token', $access_token['oauth_token'], $time, '/');
43 setEncryptCookie('oauth_token_secret', $access_token['oauth_token_secret'], $time, '/');
44 setcookie('user_id', $access_token['user_id'], $time, '/');
45 setcookie('name', $t->screen_name, $time, '/');
48 if(!isset($_COOKIE['showpic'])){
49 setcookie('showpic', 'true', $time, '/');
51 if(!isset($_COOKIE['shownick'])){
52 setcookie('shownick', 'false', $time, '/');
54 if(!isset($_COOKIE['mediaPre'])){
55 setcookie('mediaPre', 'true', $time, '/');
57 if(!isset($_COOKIE['loginPage'])) {
58 header('Location: index.php');exit();
60 $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") ? 'http' : 'https';
61 $port = $_SERVER['SERVER_PORT'] != 80 ? ':'.$_SERVER['SERVER_PORT'] : '';
62 $login_page = $scheme . '://' . $_SERVER['HTTP_HOST'] . $port . $_COOKIE['loginPage'];
63 header('Location: '. $login_page);exit();
68 header('Location: login.php?oauth=error');exit();
72 /* Create TwitterOAuth object and get request token */
73 $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
75 /* Get callback URL */
76 $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") ? 'http' : 'https';
77 $port = $_SERVER['SERVER_PORT'] != 80 ? ':'.$_SERVER['SERVER_PORT'] : '';
78 $oauth_callback = $scheme . '://' . $_SERVER['HTTP_HOST'] . $port . $_SERVER['REQUEST_URI'];
80 /* Get request token */
81 $request_token = $connection->getRequestToken($oauth_callback);
83 /* Save request token to session */
84 $_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
85 $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
87 /* If last connection fails don't display authorization link */
88 switch ($connection->http_code) {
91 $time = $_SERVER['REQUEST_TIME']+3600*24*365;
92 $url = $connection->getAuthorizeURL($token);
93 if ( isset($_POST['proxify']) ) {
94 $raw= processCurl($url);
95 $formpreg = '/(<form( \w+=\"[^"]*\")* action=\")[^"]*(\"( \w+=\"[^"]*\")*>)/';
96 $new = preg_replace($formpreg, '\1authorize.php\3',$raw);
97 $new = str_replace('html { display:none; }','.error,a.sign-up,input[name="deny"]{display:none !important;}',$new);
98 $new = preg_replace('/https?:\/\/\w+([0-9])\.twimg\.com/i','https://s3.amazonaws.com/twitter_production',$new);
102 header('Location: ' . $url);
106 header('Location: error.php?t=1');exit();