-
Notifications
You must be signed in to change notification settings - Fork 6
/
redirect.php
63 lines (54 loc) · 2.09 KB
/
redirect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/* Start session and load library. */
ini_set('session.gc_maxlifetime',300);
ini_set('session.gc_probability',1);
ini_set('session.gc_divisor',1);
session_start();
require_once('config.php');
// if magic quotes are on, strip them from the tweet
if (get_magic_quotes_gpc()) {
$_REQUEST['tweetthis'] = stripslashes($_REQUEST['tweetthis']);
}
// check for reqired string
$validatedtweet = true;
if (strlen(REQUIRED_CONTENT) > 0) {
if (stripos($_REQUEST['tweetthis'],REQUIRED_CONTENT) === false) {
$validatedtweet = false;
}
}
if (!$validatedtweet) {
// throw error if required content was not found
$_SESSION['tweet_error'] = "Sorry, but your tweet must contain “". REQUIRED_CONTENT . "” — the rest is up to you.";
header('Location: ./');
} else {
$_SESSION['user_tweet'] = $_REQUEST['tweetthis'];
$_SESSION['chosenfollow'] = AUTO_FOLLOW;
if (isset($_REQUEST['chosenfollow'])) {
$_SESSION['chosenfollow'] = true;
}
require_once('lib/twitteroauth.php');
/* Build TwitterOAuth object with client credentials. */
$connection = new TwitterOAuth(TWITTER_KEY, TWITTER_SECRET);
/* Get temporary credentials. */
$callbackurl = 'http'.((empty($_SERVER['HTTPS'])&&$_SERVER['SERVER_PORT']!=443)?'':'s').'://'.$_SERVER['HTTP_HOST'].strtok($_SERVER['REQUEST_URI'],'?');
$callbackurl = substr($callbackurl,0,strrpos($callbackurl,'/'));
$callbackurl .= '/callback.php';
$request_token = $connection->getRequestToken($callbackurl);
/* Save temporary credentials to session. */
$_SESSION['oauth_token'] = $token = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
/* If last connection failed don't display authorization link. */
switch ($connection->http_code) {
case 200:
$_SESSION['oath_begun'] = true;
/* Build authorize URL and redirect user to Twitter. */
$url = $connection->getAuthorizeURL($token);
header('Location: ' . $url);
break;
default:
/* Show notification if something went wrong. */
$_SESSION['tweet_error'] = 'Could not connect to Twitter. Refresh the page or try again later.';
header('Location: ./');
}
}
?>