-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeCommentAndReply.cgi
More file actions
executable file
·93 lines (70 loc) · 2.51 KB
/
makeCommentAndReply.cgi
File metadata and controls
executable file
·93 lines (70 loc) · 2.51 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
#!/usr/bin/perl -w
use CGI qw/:all/;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use File::Path qw(make_path);
use DataManipulation;
#warningsToBrowser(1);
$content = param("content") or die "no post";
$currentDir = param("currentDir") or die "no directory comes in";
#since zid will be changed, i have to recover it here
$currentDir =~ s/(.*?)<a.*?(z[0-9]{7}).*?a>(.*)/$1$2$3/;
$currentDir =~ s/\"//g;
#it indicates who is commenting or replying
$zidCurrentUser = cookie("zid");
if(defined param("makeComment")){
#currentDir like "dataset-medium/zid/posts/0"
if(! -d "$currentDir/comments"){
make_path("$currentDir/comments");
}
print "\$currentDir/comments:$currentDir/comments","\n";
my $comment_num=0;
for my $commentDir (glob "$currentDir/comments/*"){
$comment_num++;
}
make_path("$currentDir/comments/$comment_num");
print "\$currentDir/comments/\$comment_num:$currentDir/comments/$comment_num","\n";
my $filename="$currentDir/comments/$comment_num/comment.txt";
open F,'>',$filename;
print F "from=$zidCurrentUser\n";
print F "message=$content\n";
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
print F "time="."$year\-$mon\-$mday"."T"."$hour:$min:$sec\+0000";
close F;
#send notification, if the notification flag is set to 1
if($content=~/z[0-9]{7}/){
my @matesZid = ($content =~ /z[0-9]{7}/g);
foreach my $mateZid (@matesZid){
sendNotificationWhenZidMentioned($mateZid,"$currentDir/comments/$comment_num/comment.txt");
}
}
print redirect("matelook.cgi?showUserPage=1");
}elsif(defined param("makeReply")){
#currentDir like "dataset-medium/zid/posts/0/comments/0"
if(! -d "$currentDir/replies"){
make_path("$currentDir/replies");
}
my $reply_num=0;
for my $replyDir (glob "$currentDir/replies/*"){
#print "$post_num\n";
$reply_num++;
}
make_path("$currentDir/replies/$reply_num");
my $filename="$currentDir/replies/$reply_num/reply.txt";
open F,'>',$filename;
print F "from=$zidCurrentUser\n";
print F "message=$content\n";
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
print F "time="."$year\-$mon\-$mday"."T"."$hour:$min:$sec\+0000";
close F;
#send notification, if the notification flag is set to 1
if($content=~/z[0-9]{7}/){
my @matesZid = ($content =~ /z[0-9]{7}/g);
foreach my $mateZid (@matesZid){
sendNotificationWhenZidMentioned($mateZid,"$currentDir/replies/$reply_num/reply.txt");
}
}
print redirect("matelook.cgi?showUserPage=1");
}else{
die "neither makeComment or makeReply";
}
#print end_html;