This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet.php
114 lines (112 loc) · 4.42 KB
/
tweet.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
require_once "api.php";
require_once "banned.php";
require_once "vendor/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
if(!empty($_REQUEST['submission']) && !empty($_REQUEST['uname'])) {
$submission = $_REQUEST['submission'];
$uname = htmlentities($_REQUEST['uname']);
$tweet = "$submission - @$uname";
// Banned word check
$check = false;
foreach ($bannedWords as $word) {
if (strpos(strtolower($tweet), $word) !== false) {
$check = true;
}
}
if($check == true) {
unset($submission); unset($uname);
?>
<html>
<head>
<title>tweet</title>
<style>
/* CSS Cleanup */
body {padding-top: 200px;padding-left: 200px;padding-right:200px;background-color: black;color: white;} div.b {word-wrap: break-word;color: red;}a {color: white;}a:hover {background-color: red;}a:visited {text-decoration: none;color: white;}
</style>
</head>
<body>
<center>
<!-- Recovery -->
<p><div class="b"><b>Your submission contains a banned word.</div></b><br><a href="index.php">Try Again</a></p>
</center>
</body>
</html>
<?php
} else {
// Post to Twitter with Abraham\TwitterOAuth
// Define Keys,
define('CONSUMER_KEY', $apiKey);
define('CONSUMER_SECRET', $apiKeySecret);
define('ACCESS_TOKEN', $accessToken);
define('ACCESS_TOKEN_SECRET', $accessTokenSecret);
// Make Connection & Tweet
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$result = $connection->post("statuses/update", ["status" => $tweet]);
if($connection->getLastHttpCode() != 200) {
// HTTP Error
?>
<html>
<head>
<title>Unexpected Error</title>
<style>body {padding-top: 200px;padding-left: 200px;padding-right:200px;background-color: black;color: white;} div.b {word-wrap: break-word;color: red;}a {color: white;}a:hover {background-color: red;}a:visited {text-decoration: none;color: white;}
</style>
</head>
<body>
<center>
<!-- Recovery -->
<p>An unrecoverable error has occured.<br>If you're a regular user, please DM me on <a href="https://twitter.com:443/">Twitter</a> with the following error code:<br>
<div class="b">ERROR NO. <?php echo base64_encode($result->errors[0]->message);?></div><br><br>
<?php die("\nPHP terminated."); unset($submission); unset($uname);?></p><br><br>
</center>
</body>
</html>
<?php
} else {
// Success
?>
<html>
<head>
<title>tweet</title>
<style>body {;padding-top: 200px;padding-left: 200px;padding-right:200px;background-color: black;color: white;}div.a {color: #32CD32}a {color: white;}a:hover {background-color: red;}a:visited {text-decoration: none;color: white;}
</style>
</head>
<body>
<center>
<p><div class="a"><b>Successfully posted to Twitter!</div><br><a href="https://twitter.com/">Checkout your tweet here</a></b></p>
<?php unset($submission); unset($uname); unset($tweet); ?>
<p><a href="index.php">Post Another?</a></p>
</center>
</body>
</html>
<?php die(); ?>
<?php
}
}
} else {
?>
<!DOCTYPE html>
<html>
<head>
<title>tweet</title>
<style>
body {padding-top: 200px;background-color: black;color: white;}
</style>
</head>
<body>
<center>
<h3>##### Enter Your Tweet #####</h3>
<form method="POST">
<p><b>Input submission:</b><br>max character length: <b>262</b></p>
<textarea type="text" rows="5" cols="60" name="submission" maxlength="262" required></textarea>
<p><b>Input Twitter username:</b><br>no special characters allowed</p>
<input type="text" name="uname" value="" placeholder="twitterUsername" pattern="[a-zA-Z0-9]+" minlength="4" maxlength="15" required>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</center>
<?php
}
?>
</body>
</html>