-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter-home.jsp
303 lines (254 loc) · 11.1 KB
/
twitter-home.jsp
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<%@page language="java" %>
<%@page import="java.util.*" %>
<%@page import="java.sql.*" %>
<%@page import="com.mysql.jdbc.*" %>
<%
try {
java.sql.Connection con = null;
String url = "";
String u_id = request.getParameter("key");
ArrayList<Integer> people_following = new ArrayList<Integer>();
//validate using session variable
try {
String session_id = (String)session.getAttribute("u_id");
if(Integer.parseInt(session_id) != Integer.parseInt(u_id))
{
response.sendRedirect("Login.jsp");
}
}
catch(Exception e){
//if this is not true, redirect to signin.
response.sendRedirect("Login.jsp");
}
finally {
//Things being displayed
String username = "";
String first_name = "";
String last_name = "";
String fullname = "";
int tweets_count = 0;
int followers_count = 0;
int following_count = 0;
String tweets = "";
String output = "";
String hash = "";
String tag = "";
String h_id = "";
//query
String user1 = "SELECT username FROM user_t WHERE user_id=" + "'"+ u_id + "'";
String fullname_q = "SELECT fullname FROM user_t WHERE user_id=" + "'"+ u_id + "'";
String total_tweets = "SELECT COUNT(*) FROM tweet_t WHERE user_id=" + "'"+ u_id + "'";
String total_followers = "SELECT COUNT(user_t_user_id_follower) FROM follow_rel where user_t_user_id_followee=" + "'" + u_id + "'";
String total_followees = "SELECT COUNT(user_t_user_id_followee) FROM follow_rel where user_t_user_id_follower=" + "'" + u_id + "'";
String my_tweets = "SELECT tweet FROM tweet_t WHERE user_id=" + "'"+ u_id + "'" ;
String session_tweets = "SELECT tweet_t.tweet, user_t.username, user_t.fullname from tweet_t inner join follow_rel on follow_rel.user_t_user_id_followee=tweet_t.user_id inner join user_t on user_t.user_id=tweet_t.user_id WHERE follow_rel.user_t_user_id_follower=" + "'"+ u_id + "'" + "OR user_t.user_id=" + "'"+ u_id + "'";
//open sql:
Class.forName("com.mysql.jdbc.Driver").newInstance();
url = "jdbc:mysql://localhost:3306/smeeks";
con = DriverManager.getConnection(url, "smeeks", "dalton123");
java.sql.Statement stmt = con.createStatement();
java.sql.Statement stmt1 = con.createStatement();
java.sql.Statement stmt2 = con.createStatement();
java.sql.Statement stmt3 = con.createStatement();
java.sql.Statement stmt6 = con.createStatement();
java.sql.Statement stmt7 = con.createStatement();
//executes the query:
java.sql.ResultSet rs_tweets_count = stmt.executeQuery(total_tweets);
java.sql.ResultSet rs_followers = stmt1.executeQuery(total_followers);
java.sql.ResultSet rs_following = stmt2.executeQuery(total_followees);
java.sql.ResultSet rs_username = stmt3.executeQuery(user1);
java.sql.ResultSet rs_fullname = stmt6.executeQuery(fullname_q);
if(rs_tweets_count.next())
{
//success
tweets_count= Integer.parseInt(rs_tweets_count.getString(1));
}
if(rs_followers.next())
{
//success
followers_count= Integer.parseInt(rs_followers.getString(1));
}
if(rs_following.next())
{
//success
following_count= Integer.parseInt(rs_following.getString(1));
}
if(rs_username.next())
{
username= rs_username.getString(1);
}
if(rs_fullname.next())
{
fullname= rs_fullname.getString(1);
first_name = fullname.split(" ")[0];
last_name = fullname.split(" ")[1];
}
%>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<meta name="description" content="">
<meta name="author" content="">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
.sidebar-nav {
padding: 9px 0;
}
</style>
<link rel="stylesheet" href="css/gordy_bootstrap.min.css">
</head>
<body class="user-style-theme1">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<i class="nav-home"></i> <a href="#" class="brand">!Twitter</a>
<div class="nav-collapse collapse">
<p class="navbar-text pull-right">Logged in as <a href="#" class="navbar-link"><%=fullname%></a>
</p>
<ul class="nav">
<li class="active"><a href="index.html">Home</a></li>
<li><a href="queries.html">Test Queries</a></li>
<li><a href="twitter-signin.html">Main sign-in</a></li>
</ul>
</div><!--/ .nav-collapse -->
</div>
</div>
</div>
<div class="container wrap">
<div class="row">
<!-- left column -->
<div class="span4" id="secondary">
<div class="module mini-profile">
<div class="content">
<div class="account-group">
<a href="#">
<img class="avatar size32" src="images/pirate_normal.jpg" alt="Gordy">
<b class="fullname"><%=fullname%></b>
<small class="metadata">View my profile page</small>
</a>
</div>
</div>
<div class="js-mini-profile-stats-container">
<ul class="stats">
<li><a href="#"><strong><%=tweets_count%></strong>Tweets</a></li>
<li><a href="following_list.jsp?u_id=<%=u_id%>"><strong><%=following_count%></strong>Following</a></li>
<li><a href="followers_list.jsp?u_id=<%=u_id%>"><strong><%=followers_count%></strong>Followers</a></li>
</ul>
</div>
<form action="insert_tweet.jsp" method="get">
<textarea class="tweet-box" name="text" placeholder="Compose new Tweet..." id="tweet-box-mini-home-profile"></textarea>
<input type="Submit" class="btn btn-small btn-primary" value="enter">
<input type="hidden" class="tweet-box" name="user_id" value=<%=u_id%> id="tweet-box-mini-home-profile">
</form>
</div>
<div class="module other-side-content">
<div class="content"
<p>Some other content here</p>
</div>
</div>
</div>
<!-- right column -->
<div class="span8 content-main">
<div class="module">
<div class="content-header">
<div class="header-inner">
<h2 class="js-timeline-title">Tweets</h2>
</div>
</div>
<!-- new tweets alert -->
<div class="stream-item hidden">
<div class="new-tweets-bar js-new-tweets-bar well">
2 new Tweets
</div>
</div>
<!-- all tweets -->
<div class="stream home-stream">
<%
java.sql.Statement stmt4 = con.createStatement();
java.sql.ResultSet rs_tweets = stmt4.executeQuery(session_tweets);
//java.sql.ResultSet rs_followee_tweets = stmt5.executeQuery(tweets_user_follows);
while(rs_tweets.next())
{ //open
tweets= rs_tweets.getString("tweet");
username = rs_tweets.getString("username");
fullname = rs_tweets.getString("fullname");
%>
<!-- start tweet -->
<div class="js-stream-item stream-item expanding-string-item">
<div class="tweet original-tweet">
<div class="content">
<div class="stream-item-header">
<small class="time">
<a href="#" class="tweet-timestamp" title="10:15am - 16 Nov 12">
<span class="_timestamp">6m</span>
</a>
</small>
<a class="account-group">
<img class="avatar" src="images/obama.png" alt="Barak Obama">
<strong class="fullname"><%=fullname%></strong>
<span>‏</span>
<span class="username">
<s>@</s>
<b><%=username%></b>
</span>
</a>
</div>
<p class="js-tweet-text">
<%
String[] words = tweets.split(" "); //split it into words
for(int i = 0; i < words.length; i ++)
{
output = "";
if(words[i].substring(0, 1).equals("#"))
{
hash = words[i].substring(0);
tag = words[i].substring(1);
String hash_q = "SELECT hashtag_id FROM hashtag_t where hashtag=" + "'" + tag + "'";
java.sql.ResultSet rs_hash_s = stmt7.executeQuery(hash_q);
if(rs_hash_s.next()) {
h_id = rs_hash_s.getString(1);
}
//out.println(hash_id_q);
words[i] = "<a href='hashtag_tweets.jsp?u_id=" + u_id + "&hash_id=" + h_id + "'>" + hash + "</a>" + " ";
}//if
output+=words[i];
out.println(output);
} //for
%>
</p>
</div>
</a>
<div class="expanded-content js-tweet-details-dropdown"></div>
</div>
</div><!-- end tweet -->
<%
}//while
%>
<div class="stream-footer"></div>
<div class="hidden-replies-container"></div>
<div class="stream-autoplay-marker"></div>
</div>
</div>
</div>
</div>
</div>
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" src="js/main-ck.js"></script>
</body>
</html>
<%
}
} //try
catch(Exception e){
out.println(e);
}
%>