Skip to content

Instantly share code, notes, and snippets.

@takuma7
Created April 24, 2011 01:53
Show Gist options
  • Save takuma7/939234 to your computer and use it in GitHub Desktop.
Save takuma7/939234 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use CGI;
use HTML::Entities;
$form = CGI->new();
$handle = $form->param("handle");
$speech = $form->param("speech");
print "Content-type: text/html; charset=UTF-8\n\n";
print <<DOC;
<html>
<head>
<title>chat room - TaKUMA7</title>
<link href='http://fonts.googleapis.com/css?family=The+Girl+Next+Door' rel='stylesheet' type='text/css'>
<style type="text/css">
<!--
html{
background:#d8f8cf;
font-family: 'The Girl Next Door', arial, serif;
}
body{
width:800px;
margin: 20px auto;
background:#ffffff;
text-align: center;
border-radius: 20px; /* CSS3草案 */
-webkit-border-radius: 20px; /* Safari,Google Chrome用 */
-moz-border-radius: 20px; /* Firefox用 */
}
div#time_line{
padding:30px;
padding-top: 0;
}
h1 {
font-family: 'The Girl Next Door', arial, serif;
}
input{
padding : 3px;
border: 1px solid;
border-radius: 10px; /* CSS3草案 */
-webkit-border-radius: 10px; /* Safari,Google Chrome用 */
-moz-border-radius: 10px; /* Firefox用 */
}
div.statement{
width : 100%;
margin:3px auto;
padding:5px;
height : auto;
display : inline-block;
border : 1px solid #efefef;
background : #efefef;
color : #3e3e3e;
border-radius: 10px; /* CSS3草案 */
-webkit-border-radius: 10px; /* Safari,Google Chrome用 */
-moz-border-radius: 10px; /* Firefox用 */
}
.statement:after{
content: "";
display : block;
clear: both;
}
div.statement div{
}
div.speaker{
width : 100px;
float : left;
padding : 10px;
text-align : right;
font-weight : bold;
#border : 1px solid red;
#background : #ffeeee;
}
div.content{
width : 580px;
float : left;
margin-left: 3px;
padding : 10px;
text-align:left;
#border : 1px solid blue;
#background : #eeeeff;
}
-->
</style>
</head>
<body>
<h1>chat room</h1>
<form id="form" method="post" action="chat.cgi">
statement:<input class="text" name="speech" type="text" size="100">
<input name="handle" type="hidden" value="$handle">
<input type="submit" value="say">
<input type="reset" value="reset">
</form>
<div id="time_line">
DOC
if($speech ne ""){
open LOG, ">>/Applications/MAMP/cgi-bin/chat.log";
my $encoded_speech = encode_entities("$speech");
$_ = <<STATEMENT;
<div class="statement">
<div class="speaker">
$handle
</div>
<div class="content">
$encoded_speech
</div>
</div>
STATEMENT
s/\n|\t//g;
$_ = $_ . "\n";
print LOG $_;
close LOG;
}
open LOG, "/Applications/MAMP/cgi-bin/chat.log";
@stats=();
while(<LOG>){
push @stats, $_;
}
for $x (reverse @stats){
print $x;
}
close LOG;
print <<DOC;
</div>
</body>
</html>
DOC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment