-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowUserPage.cgi
More file actions
executable file
·201 lines (160 loc) · 6.26 KB
/
showUserPage.cgi
File metadata and controls
executable file
·201 lines (160 loc) · 6.26 KB
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
#!/usr/bin/perl -w
use CGI qw/:all/;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use List::MoreUtils qw(uniq);
use DataManipulation;
################# this is user's home page ################################################
$user_zid = param("username") or die "do not have the zid cannot display user page";
if(-e "$users_dir/$user_zid/background.jpg"){
print header(-charset => "utf-8"),start_html(-title => "$user_zid user page",-background=>"$users_dir/$user_zid/background.jpg");
}else{
print header(-charset => "utf-8"),start_html(-title => "$user_zid user page");
}
##welcome information and user profile image
print "<span>".h2(returnUserNameWithZid($user_zid)." user page")."</span>";
$tnjpgfile = returnUserImgWithZid($user_zid);
if($tnjpgfile){
print "<span><img src=\"$tnjpgfile\" alt=\"$user_zid image\" width=\"200\" height=\"200\"></span>","\n";
}
##logout button
print logoutHtml();
print "<br/>";
##edit user information
print "<a href=\"matelook.cgi?editUserProfile=1\">edit user profile</a>","\n";
print "<br/>";
##change user password
print "<a href=\"matelook.cgi?changeUserPassword=1\">change your password</a>","\n";
print "<br/>";
##suspend/delete user account
print "<a href=\"matelook.cgi?suspendOrDelete=1\">suspend or delete your account</a>","\n";
print "<br/>";
##edit notification and privacy info
print "<a href=\"matelook.cgi?notificationAndPrivacySetting=1\">edit user nofication and privacy setting</a>","\n";
print "<br/>";
##the search html part
print "<br/>";
print searchForNameAndPostHtml();
print "<br/>";
##display make post
print "<p><strong>Make A Post:</strong></p>","\n";
print start_form(-method=>'POST',-action=>"makePost.cgi"),"\n";
print textarea(-name=>'myPost',-default=>'Come on, say something',-rows=>5,-columns=>100),"\n";
print submit(-name=>'submit',-value=>'submit'),"\n";
print end_form;
##display user infomation
print "<p> <strong>Your Information: </strong> </p>";
open F,"<$users_dir/$user_zid/user.txt";
while(my $line = <F>){
if($line =~ /password/){
next;
}else{
print "<p>$line</p>","\n";
}
}
close F;
open F,"<$users_dir/$user_zid/user.txt";
##display mate list
my @matesZid;
print p("<strong> MATES: </strong>");
while(my $line = <F>){
if($line =~ /^\s*mates/){
@matesZid = ($line =~ /z[0-9]{7}/g);
#print @matesZid;
foreach my $mateZid (@matesZid){
#print "$mateZid";
my $correspondingName = returnUserNameWithZid($mateZid);
print "<a href=\"matelook.cgi?showUserPage=1&userZid=$mateZid\">$correspondingName</a>";
my $tnjpgfile = returnUserImgWithZid($mateZid);
if($tnjpgfile){
print "<a href=\"matelook.cgi?showUserPage=1&userZid=$mateZid\"><img src=\"$tnjpgfile\" alt=\"go to $mateZid \" width=\"50\" height=\"30\"></a>","\n";
}
print "<a href=\"matelook.cgi?unmate=1&user1=$mateZid&user2=$user_zid\">Unmate</a>\n";
print "<br/>";
}
}
}
close F;
##mate suggestion
##suggest at most 5 mates to user
print "<br/>";
print p("<strong> Mate Suggestion: </strong>");
#mateSuggestion() return an array reference
$suggestedMates=mateSuggestion($user_zid);
$countMateSuggestion=0;
foreach my $suggestedMate (@$suggestedMates){
my $correspondingName = returnUserNameWithZid($suggestedMate);
print "<a href=\"matelook.cgi?showUserPage=1&userZid=$suggestedMate\">$correspondingName</a>";
my $tnjpgfile = returnUserImgWithZid($suggestedMate);
if($tnjpgfile){
print "<a href=\"matelook.cgi?showUserPage=1&userZid=$suggestedMate\"><img src=\"$tnjpgfile\" alt=\"go to $suggestedMate \" width=\"50\" height=\"30\"></a>","\n";
}
if($countMateSuggestion>=4){
last;
}else{
$countMateSuggestion++;
}
}
## pagination, declare some variables used in pagination
## the idea behind this mechenism is , everytime only the $post_count in the range of display_start_num~display_stop_num, add to $outputPosts
## set a page display 8 posts
$display_post_num=8;
if(defined param("pageNum")){
$display_stop_num = scalar(param("pageNum"))*8 || 8;
}else{
$display_stop_num = 8;
}
$display_start_num = $display_stop_num-$display_post_num;
$post_counter=0;
##display his posts
print "<br/>";
print "<p> <strong>POSTS:your posts,and posts from your mate</strong></p>"."\n";
print "<br/>";
$outputPosts="";
if(-d "$users_dir/$user_zid/posts"){
for my $postDir (glob "$users_dir/$user_zid/posts/*"){
if($post_counter >= $display_start_num && $post_counter<$display_stop_num){
$outputPosts .= "<div style=\"background:#F9EECF;border:10px splash black;text-align:left;margin:10px\">".displayPostWithDir($postDir,$user_zid)."</div>"."\n";
}
$post_counter++;
}
}
#display mates' post
foreach my $mateZid (@matesZid){
if(-d "$users_dir/$mateZid/posts"){
for my $postDir (glob "$users_dir/$mateZid/posts/*"){
##still use $user_zid in displayPostWithDir, since it indicates the posts current user can delete
if($post_counter >= $display_start_num && $post_counter<$display_stop_num){
$outputPosts .= "<div style=\"background:#F9EECF;border:10px splash black;text-align:left;margin:10px\">".displayPostWithDir($postDir,$user_zid)."</div>"."\n";
}
$post_counter++;
}
}
}
##eliminate the case, /z5089812/ as a directory in html, as support info transmit to server
@zidsInOutputPosts = ($outputPosts =~ /[^\/]z[0-9]{7}/g);
@uniqZidsInOutputPosts = uniq @zidsInOutputPosts;
foreach my $tempZid (@uniqZidsInOutputPosts){
#print "tempZid:herehere:$tempZid\n";
my $tempZidWithPreceeding= $tempZid;
$tempZid =~ s/.(z[0-9]{7})/$1/;
#print "tempZid:herehere:$tempZid\n";
my $correspondingName = returnUserNameWithZid($tempZid);
#need to care about the special character, so escape all of them
my $substituteString = "<a href=\"matelook.cgi\?showUserPage=1\&userZid=$tempZid\">$correspondingName<\/a>";
#my $pattern = "'$tempZid'";
#print "$tempZid,$substituteString";
$outputPosts =~ s/\Q$tempZidWithPreceeding\E/$substituteString/eg;
}
#display hyper link properly
if($outputPosts =~ /(https)|(http):\/\//){
$outputPosts =~ s/(.*?)(http[^ ,]*)(.*)/$1 \<a href=\"$2\"\>$2\<\/a\> $3/g;
}
print $outputPosts,"\n";
##print out page number
#print $post_counter/$display_post_num;
$outputPageNums="Pages:";
for(my $i=1; $i<=($post_counter/$display_post_num + 1);$i++){
$outputPageNums .= "<a href=\"showUserPage.cgi?username=$user_zid&pageNum=$i\" style=\"border:10px; border:solid;\">$i</a> ";
}
print $outputPageNums;
print end_html;