-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·134 lines (122 loc) · 3.51 KB
/
index.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
//start session
session_start();
//just simple session reset on logout click
if($_GET["reset"]==1)
{
if($_GET["reset"]==1){
session_destroy();
header('Location: ./index.php');
}
}
function writeTweets($my_tweets){
foreach ($my_tweets as $my_tweet) {
$arrTw = '<li>'.$my_tweet->text.' <br />-<i>'.$my_tweet->created_at.'</i></li>';
echo '<script>$("ul#tweets").append("'.$arrTw.'");</script>';
}
}
// Include config file and twitter PHP Library by Abraham Williams (abraham@abrah.am)
include_once("config.php");
include_once("inc/twitteroauth.php");
?>
<html>
<head>
<title>Sign-in with Twitter</title>
<style type="text/css">
<!--
.wrapper{width:600px; margin-left:auto;margin-right:auto;}
.welcome_txt{
margin: 20px;
background-color: #EBEBEB;
padding: 10px;
border: #D6D6D6 solid 1px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
}
.tweet_box{
margin: 20px;
background-color: #FFF0DD;
padding: 10px;
border: #F7CFCF solid 1px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
}
.tweet_box textarea{
width: 500px;
border: #F7CFCF solid 1px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
}
.tweet_list{
margin: 20px;
padding:20px;
background-color: #E2FFF9;
border: #CBECCE solid 1px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
}
.tweet_list ul{
padding: 0px;
font-family: verdana;
font-size: 12px;
color: #5C5C5C;
}
.tweet_list li{
border-bottom: silver dashed 1px;
list-style: none;
padding: 5px;
}
-->
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.min.js"></script>
</head>
<body>
<div class="wrapper">
<?php
if(isset($_SESSION['status']) && $_SESSION['status']=='verified')
{ //Success, redirected back from process.php with varified status.
//retrive variables
$screenname = $_SESSION['request_vars']['screen_name'];
$screenname2 = "mydearbadguy";
$twitterid = $_SESSION['request_vars']['user_id'];
$oauth_token = "768175776-F1voaPLT7c3oNNevEoQzE5jjzg6PS892vq2lvjMI";
$oauth_token_secret = "TlcOf8Qy9ESnmRQyCIdAG64VT9EhJdRkKKnVB3d1JI";
//Show welcome message
echo '<div class="welcome_txt">Welcome <strong>'.$screenname.'</strong> (Twitter ID : '.$twitterid.'). <a href="index.php?reset=1">Logout</a>!</div>';
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);
//see if user wants to tweet using form.
if(isset($_POST["updateme"]))
{
//Post text to twitter
$my_update = $connection->post('statuses/update', array('status' => $_POST["updateme"]));
$my_tweets = $connection->get('statuses/user_timeline', array('screen_name' => $screenname2, 'count' => 5));
writeTweets($my_tweets);
}
//show tweet form
echo '<div class="tweet_box">';
echo '<form method="post" action="index.php"><table width="200" border="0" cellpadding="3">';
echo '<tr>';
echo '<td><textarea name="updateme" cols="60" rows="4"></textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="submit" value="Tweet" /></td>';
echo '</tr></table></form>';
echo '</div>';
//Get latest tweets
$my_tweets = $connection->get('statuses/user_timeline', array('screen_name' => $screenname2, 'count' => 5));
echo '<div class="tweet_list"><strong>Latest Tweets (@mydearbadguy): </strong>';
echo '<ul id="tweets">';
echo '</ul></div>';
writeTweets($my_tweets);
}else{
//login button
echo '<a href="process.php"><img src="images/sign-in-with-twitter-l.png" width="151" height="24" border="0" /></a>';
}
?>
</div>
</body>
</html>