Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 311 lines (267 sloc) 11.004 kB
db64cd4 @wesleyzhao first commit
authored
1 <?php
2 session_start();
3 require_once('lib2/EpiCurl.php');
4 require_once('lib2/EpiOAuth.php');
5 require_once('lib2/EpiTwitter.php');
6 require_once('lib/secret.php');
7 require_once('mysql_connect.php');
8
9 $twitterObj = new EpiTwitter($consumer_key,$consumer_secret);
10 $oauth_token = $_GET['oauth_token'];
11 if ($oauth_token == '' && $_SESSION['ot']==''){
12 header("location: http://grimtweeper.com");
13 }
14 else{
15 //$_SESSION['oauth_token'] = $_GET['oauth_token'];
16 try{
17 if ($_SESSION['ot']==''){
18 $twitterObj->setToken($_GET['oauth_token']);
19 $token = $twitterObj->getAccessToken();
20 $twitterObj->setToken($token->oauth_token,$token->oauth_token_secret);
21 $_SESSION['ot'] = $token->oauth_token;
22 $_SESSION['ots'] = $token->oauth_token_secret;
23
24 }
25 else{
26 $twitterObj->setToken($_SESSION['ot'],$_SESSION['ots']);
27 }
28 mysqlConnect();
29 $twitterInfo = $twitterObj->get_accountVerify_credentials();
30 $twitterInfo->response;
31 $username = $twitterInfo->screen_name;
32 mysql_query("INSERT INTO logins (username) VALUES ('$username')");
33
34 $user_id =$twitterInfo->id;
35 //$user_id = $twitterInfo->user_id;
36 $profilepic = $twitterInfo->profile_image_url;
37 $followers_count = $twitterInfo->followers_count;
38 $friends_count = $twitterInfo->friends_count;
39 $_SESSION['user_id'] = $user_id;
40 mysql_query("INSERT INTO scores (username,user_id,image_url) VALUES ('$username','$user_id','$profilepic')");
41 $res = mysql_query("SELECT score FROM scores WHERE user_id='$user_id'");
42 $row = mysql_fetch_array($res);
43 $score = intval($row['score']);
44 $resp = $twitterObj->get('/friends/ids.json',array('username'=>$username));
45 $friend_ids = $resp->response;
46
47 $res = mysql_query("SELECT user_id FROM views WHERE viewed_by_id='$user_id'");
48 if (mysql_num_rows($res)){
49 while($row =mysql_fetch_array($res)){
50 $index = array_search($row['user_id'],$friend_ids);
51 if ($index!= false) unset($friend_ids[$index]);
52
53 }
54 $friend_ids = array_values($friend_ids);
55 }
56
57 $is_error = false;
58 }
59 catch (EpiTwitterServiceUnavailableException $e){
60 //echo "You have eliminated a lot of friends! The Grim Tweeper is tired... come back in about an hour.<br><br><em>AKA: Twitter rate limited us...</em>";
61 $is_error = true;
62 }
63 catch (EpiTwitterBadRequestException $e){
64 $is_error = true;
65 }
66
67
68 }
69 ?>
70 <html>
71 <head>
72 <link rel="stylesheet" href="main.css" type="text/css"/>
73 <link rel='SHORTCUT ICON' href='favicon.ico'/>
74 <script type="text/javascript"
75 src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
76 </script>
77 <script type="text/javascript">
78 function unhide(div_id) {
79 var item = document.getElementById(div_id);
80 if (item) {
81 item.className=(item.className=='hidden')?'unhidden':'hidden';
82 }
83 }
84 </script>
85
86 <script type="text/javascript">
87
88 var _gaq = _gaq || [];
89 _gaq.push(['_setAccount', 'UA-1108031-19']);
90 _gaq.push(['_trackPageview']);
91
92 (function() {
93 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
94 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
95 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
96 })();
97
98 </script>
99 <script type="text/javascript">var _sf_startpt=(new Date()).getTime()</script>
100 <title>The Grim Tweeper</title>
101 </head>
102
103 <body>
104 <div id = "header">
105 <div id = "headwrap">
106 <h1>Th<span class = "ar">e</span> Grim Tw<span class = "ar">ee</span>p<span class = "ar">e</span>r</h1>
107 <div id = "you">
108
109 <img class='profile-image' src ='<?=$profilepic?>' /> <!--<a href = "http://twitter.com/<?=$username?>" class = inherit>@<?=$username?></a>-->
110 <a href='logout.php'>log out</a>
111 </div>
112 </div>
113
114 </div>
115
116 <div class = "wrapper">
117 <div id = "content">
118 Who do you have on the chopping block now? <br /><br />
119
120
121 <div id = "controls">
122 <div id='message-div'></div>
123 <a href = "#" id = "kill" onclick='javascript:destroyFriendship();'>KILL</a>
124 <a href = "#" id = "keep" onclick='javascript:replacePerson();'>KEEP</a>
125 <div id="last-rejected"></div>
126 </div>
127 <div id = "them">
128 <?php
129 if ($is_error){
130 echo "<b>Me thinks you slayed a few too many followers!</b><br><br><br>
131 The Grim Tweeper is tired <em>(aka Twitter rate limited us...)</em>!<br><br><br>
132 Come back in about an hour :). Thanks, and sorry for the inconvenience we caused.";
133 }
134 ?>
135 </div><!--end of them-->
136 </div>
137
138 <div id = "promo">
139 <div id="float-right">
140 <div class='tweet-button'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://grimtweeper.com" data-text="The Grim Tweeper - a new way to clean up your following list. Start cutting down now! #grimtweeper" data-counturl="http://www.grimtweeper.com" data-count="horizontal" data-via="thetweeper" >Tweet</a></div><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
141
142 <iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fgrimtweeper.com&amp;layout=standard&amp;show_faces=false&amp;width=300&amp;action=like&amp;font&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:300px; height:35px;" allowTransparency="true"></iframe>
143 </div>
144 You've killed <span id = "kill_count">10</span> follows with The Grim Tweeper.
145
146
147 </div>
148 <iframe src="leaderboard.php" width="100%" height="300px" frameborder = "0">
149 <p>Your browser does not support iframes.</p>
150 </iframe>
151 <center>
152 <script type="text/javascript">var adNumber = 1;</script>
153 <script language="JavaScript" src="http://admore.heroku.com/javascripts/embed.js"></script>
154 </center>
155 <!--<br><br> -->
156 <div class="footer">
157 <span id = "about">The Grim Tweeper is Copyright 2011 <a href="http://twitter.com/weslayzhao">Wesley Zhao</a>, <a href="http://twitter.com/temiri">Tess Rinearson</a>, <a href="http://twitter.com/danshipper">Dan Shipper</a> and <a href="http://twitter.com/ajaymehta">Ajay Mehta</a></span>
158 </div>
159 </div>
160
161
162 <script type="text/javascript">
163 var _sf_async_config={uid:19911,domain:"grimtweeper.com"};
164 (function(){
165 function loadChartbeat() {
166 window._sf_endpt=(new Date()).getTime();
167 var e = document.createElement('script');
168 e.setAttribute('language', 'javascript');
169 e.setAttribute('type', 'text/javascript');
170 e.setAttribute('src',
171 (("https:" == document.location.protocol) ? "https://a248.e.akamai.net/chartbeat.download.akamai.com/102508/" : "http://static.chartbeat.com/") +
172 "js/chartbeat.js");
173 document.body.appendChild((e));
174 }
175 var oldonload = window.onload;
176 window.onload = (typeof window.onload != 'function') ?
177 loadChartbeat : function() { oldonload(); loadChartbeat(); };
178 })();
179
180 </script>
181 </body>
182
183
184 <script type='text/javascript'>
185 var friend_ids = <?php echo json_encode($friend_ids);?>;
186 var friend_ids_copy = <?php echo json_encode($resp->response);?>;
187 var friends_count = <?php echo $friends_count;?>;
188 var followers_count = <?php echo $followers_count;?>;
189 var user_id = <?php echo $user_id;?>;
190 var friends_count_changed = <?=$score ?>;
191 var curFriendId = 0;
192 var last_user_reject = '';
193
194 var last_user_reject_id = 0;
195 replacePerson();
196 $("#user-followers").html(followers_count);
197 $("#user-following").html(friends_count);
198 $("#kill_count").html(friends_count_changed);
199 function tweet_click(){
200 var v='thetweeper';
201 var r='thetweeper';
202 var u = 'http://www.grimtweeper.com';
203 var t = 'I feel liberated! I just slayed '+friends_count_changed+ ' tweeps with @thetweeper! #grimtweeper';
204 var ref = 'http://twitter.com/share?related='+encodeURIComponent(r)+'&url='+encodeURIComponent(u)+'&text='+encodeURIComponent(t)+'&via='+encodeURIComponent(v);
205 window.open(ref,'sharer','toolbar=0,status=0,width=535,height=355');
206 return false;
207 }
208 function updateFriendsCount(){
209 //subtracts one from friends_count and then updates the span id tag
210 if (friends_count>0){
211 friends_count = friends_count-1;
212 friends_count_changed+=1;
213 if (friends_count_changed>0 && (friends_count_changed%10)==0){
214 tweet_click();
215 }
216 }
217 $("#user-following").html(friends_count);
218 $("#kill_count").html(friends_count_changed);
219 }
220
221 function undoRejection(){
222 if (last_user_reject!=''){
223 //last_user_reject = $("#friend-username").html();
224 var url = encodeURI('create_friendship.php?friend_screen_name='+last_user_reject);
225 var url2 = encodeURI("undo_kill.php?friend_id="+last_user_reject_id);
226 $.get(url2,function (data){});
227 $.get(url,function(data){
228 $("#last-rejected").html("You are friends with "+last_user_reject+" again!");
229 friends_count_changed-=1;
230 $("#kill_count").html(friends_count_changed);
231 });
232
233
234 }
235 }
236
237 function updateLastUserReject(){
238 last_user_reject = $("#friend-username").html();
239 }
240
241 function updateLastUserRejectMessage(){
242 $("#last-rejected").html("Last kill: @"+last_user_reject+". <b><a href='#' onclick='javascript:undoRejection();'>Click to re-friend.</a></b>");
243 }
244 function getNewId(){
245 if (friend_ids.length<=0){
246 friend_ids = friend_ids_copy.slice(0);
247 var url2 = encodeURI("reset_user.php");
248 $.get(url2,function(data){});
249 }
250
251 var newIdIndex = Math.floor(Math.random()*friend_ids.length);
252 var newId = friend_ids[newIdIndex];
253 friend_ids.splice(newIdIndex,1);
254 return newId;
255
256 }
257 /*
258 function replacePerson(){
259 var beenSeen = '1';
260 //while (beenSeen == '1'){
261 curFriendId = getNewId();
262 var url = encodeURI("has_been_viewed.php?user_id="+user_id+"&friend_id="+curFriendId);
263 alert(url);
264 $.get(url,function(data){
265 alert("data:" + data);
266 beenSeen = data;
267 alert(beenSeen);
268 });
269 if (beenSeen =='1' && friend_ids.length<=0){
270 var url2 = encodeURI("reset_user.php");
271 $.get(url2,function(data){});
272 }
273 //}
274
275 var url = encodeURI('get_new_friend.php?friend_id='+curFriendId+"&user_id="+user_id);
276 setMessage('');
277 $("#them").load(url);
278
279 }
280 */
281 function replacePerson(){
282
283 curFriendId = getNewId();
284 var url = encodeURI('get_new_friend.php?friend_id='+curFriendId+"&user_id="+user_id);
285 var url2 = encodeURI("has_been_viewed.php?user_id="+user_id+"&friend_id="+curFriendId);
286 setMessage('');
287 $("#them").load(url);
288
289 $.get(url2,function(data){});
290
291 }
292
293 function destroyFriendship(){
294 var url = encodeURI('destroy_friendship.php?friend_id='+curFriendId);
295 var url2 = encodeURI("make_kill.php?friend_id="+curFriendId);
296 updateLastUserReject();
297 last_user_reject_id = curFriendId;
298 replacePerson();
299 $('#message-div').load(url);
300 $.get(url2,function (data){});
301 setMessage('Friendship destroyed!');
302
303 updateLastUserRejectMessage();
304
305 updateFriendsCount();
306 }
307
308 function setMessage(text){
309 $("#message-div").html(text);
310 }
311 </script>
Something went wrong with that request. Please try again.