6 |
kaklik |
1 |
<script type="text/javascript">
|
|
|
2 |
<!--
|
|
|
3 |
function addsmiley(code) {
|
|
|
4 |
var pretext = document.forms['shoutbox_form'].shoutbox_message.value;
|
|
|
5 |
this.code = code;
|
|
|
6 |
document.forms['shoutbox_form'].shoutbox_message.value = pretext + code;
|
|
|
7 |
}
|
|
|
8 |
//-->
|
|
|
9 |
</script>
|
|
|
10 |
|
|
|
11 |
<style type="text/css">
|
|
|
12 |
/* Belows is the CSS file with some comments, edit it to your likings. */
|
|
|
13 |
|
|
|
14 |
/* This is to "trap" all shoutbox message into one content box */
|
|
|
15 |
div.shoutbox {
|
|
|
16 |
background: #E5E5E5;
|
|
|
17 |
padding: 5px;
|
|
|
18 |
width: 190px;
|
|
|
19 |
height: 200px;
|
|
|
20 |
border: 1px solid #000000;
|
|
|
21 |
overflow: auto;
|
|
|
22 |
color: #000000;
|
|
|
23 |
font: normal 10px verdana,tahoma,arial }
|
|
|
24 |
|
|
|
25 |
/* Smiley with no border and a cursor pointer */
|
|
|
26 |
img.smileys {
|
|
|
27 |
border: 0;
|
|
|
28 |
cursor: pointer; }
|
|
|
29 |
|
|
|
30 |
/* Just some styling... */
|
|
|
31 |
#shoutbox-message { width: 200px }
|
|
|
32 |
strong {
|
|
|
33 |
color: #000000;
|
|
|
34 |
font: bold 10px verdana,tahoma,arial }
|
|
|
35 |
|
|
|
36 |
/* Dont remove this style property or the messages wont display properly! */
|
|
|
37 |
ul {
|
|
|
38 |
margin: 0;
|
|
|
39 |
padding: 0;
|
|
|
40 |
list-style-type: none;
|
|
|
41 |
color: #000000;
|
|
|
42 |
font: normal 10px verdana,tahoma,arial; }
|
|
|
43 |
|
|
|
44 |
/* This is just to make the form looks nice */
|
|
|
45 |
input {
|
|
|
46 |
padding: 0px;
|
|
|
47 |
border: 1px solid #000000;
|
|
|
48 |
background-color: #E5E5E5;
|
|
|
49 |
color: #000000;
|
|
|
50 |
font: normal 10px verdana,tahoma,arial; }
|
|
|
51 |
textarea {
|
|
|
52 |
width: 195px;
|
|
|
53 |
padding: 0px;
|
|
|
54 |
border: 1px solid #000000;
|
|
|
55 |
background-color: #E5E5E5;
|
|
|
56 |
color: #000000;
|
|
|
57 |
font: normal 10px verdana,tahoma,arial; }
|
|
|
58 |
</style>
|
|
|
59 |
|
|
|
60 |
<?php
|
|
|
61 |
include("config.php");
|
|
|
62 |
if ($_POST['shoutbox_submit']) {
|
|
|
63 |
$name = $_POST['shoutbox_name'];
|
|
|
64 |
$ip = $_POST['shoutbox_ip'];
|
|
|
65 |
$message = $_POST['shoutbox_message'];
|
|
|
66 |
$mlen = strlen($message);
|
|
|
67 |
$date = date("F jS Y");
|
|
|
68 |
if ($name == "") {
|
|
|
69 |
echo "<strong>Error: Please enter your nickname.</strong>";
|
|
|
70 |
}
|
|
|
71 |
else if ($message == "") {
|
|
|
72 |
echo "<strong>Error: No message to be sent.</strong>";
|
|
|
73 |
}
|
|
|
74 |
else if ($mlen > $max_length) {
|
|
|
75 |
echo "<strong>Error: Message too long.</strong>";
|
|
|
76 |
}
|
|
|
77 |
else {
|
|
|
78 |
$db = mysql_connect($db_host,$db_user,$db_pass);
|
|
|
79 |
mysql_select_db($db_name) or die("Cannot connect to database");
|
|
|
80 |
mysql_query("INSERT INTO shoutbox(name,ip,message,date) VALUES('$name','$ip','$message','$date')");
|
|
|
81 |
mysql_close($db);
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
$db = mysql_connect($db_host,$db_user,$db_pass);
|
|
|
85 |
mysql_select_db($db_name) or die("Cannot connect to database");
|
|
|
86 |
$query = "SELECT * FROM shoutbox ORDER BY id DESC LIMIT $dmessage";
|
|
|
87 |
$result = mysql_query($query);
|
|
|
88 |
echo "<div class=\"shoutbox\">\n";
|
|
|
89 |
echo "<ul>\n";
|
|
|
90 |
while($r=mysql_fetch_array($result)) {
|
|
|
91 |
//Strips unwanted HTML from nickname
|
|
|
92 |
$name = $r['name'];
|
|
|
93 |
$name = strip_tags($name);
|
|
|
94 |
//Strips unwanted HTML from message
|
|
|
95 |
$message = $r['message'];
|
|
|
96 |
$message = strip_tags($message);
|
|
|
97 |
// Transform text to smileys =)
|
|
|
98 |
$message = str_replace("=(","<img src=\"/shoutbox/smileys/sad.gif\" alt=\"=(\"/>", $message);
|
|
|
99 |
$message = str_replace(":(","<img src=\"/shoutbox/smileys/sad.gif\" alt=\":(\"/>", $message);
|
|
|
100 |
$message = str_replace(";(","<img src=\"/shoutbox/smileys/cry.gif\" alt=\";(\"/>", $message);
|
|
|
101 |
$message = str_replace(":@","<img src=\"/shoutbox/smileys/mad.gif\" alt=\":@\"/>", $message);
|
|
|
102 |
$message = ereg_replace(":)","<img src=\"/shoutbox/smileys/smile.gif\" alt=\":)\"/>", $message);
|
|
|
103 |
$message = ereg_replace("=)","<img src=\"/shoutbox/smileys/smile.gif\" alt=\"=)\"/>", $message);
|
|
|
104 |
$message = ereg_replace(":D","<img src=\"/shoutbox/smileys/laugh.gif\" alt=\":D\"/>", $message);
|
|
|
105 |
$message = ereg_replace(":d","<img src=\"/shoutbox/smileys/laugh.gif\" alt=\":d\"/>", $message);
|
|
|
106 |
$message = ereg_replace(":p","<img src=\"/shoutbox/smileys/tongue.gif\" alt=\":p\"/>", $message);
|
|
|
107 |
$message = ereg_replace(":P","<img src=\"/shoutbox/smileys/tongue.gif\" alt=\":P\"/>", $message);
|
|
|
108 |
$message = ereg_replace(":O","<img src=\"/shoutbox/smileys/shocked.gif\" alt=\":O\"/>", $message);
|
|
|
109 |
$message = ereg_replace(":o","<img src=\"/shoutbox/smileys/shocked.gif\" alt=\":o\"/>", $message);
|
|
|
110 |
$message = ereg_replace(";)","<img src=\"/shoutbox/smileys/wink.gif\" alt=\";)\"/>", $message);
|
|
|
111 |
$message = ereg_replace(":S","<img src=\"/shoutbox/smileys/sick.gif\" alt=\":S\"/>", $message);
|
|
|
112 |
$message = ereg_replace(":s","<img src=\"/shoutbox/smileys/sick.gif\" alt=\":s\"/>", $message);
|
|
|
113 |
$message = ereg_replace(":roll:","<img src=\"/shoutbox/smileys/roll.gif\" alt=\":roll:\"/>", $message);
|
|
|
114 |
echo "<li title=\"Shouted on $r[date]\" style=\"cursor: pointer\"><strong>$name</strong>: $message</li>\n";
|
|
|
115 |
}
|
|
|
116 |
echo "</ul>\n";
|
|
|
117 |
echo "</div>\n";
|
|
|
118 |
mysql_close($db);
|
|
|
119 |
?>
|
|
|
120 |
|
|
|
121 |
<div>
|
|
|
122 |
<form id="shoutbox_form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
|
|
|
123 |
<strong>Nickname:</strong><br/>
|
|
|
124 |
<input type="text" name="shoutbox_name" size="37" maxlength="20"><br/>
|
|
|
125 |
<strong>Message:</strong><br/>
|
|
|
126 |
<img class="smileys" src="./shoutbox/smileys/smile.gif" alt=":)" onclick="addsmiley(':)')"/>
|
|
|
127 |
<img class="smileys" src="./shoutbox/smileys/laugh.gif" alt=":D" onclick="addsmiley(':D')"/>
|
|
|
128 |
<img class="smileys" src="./shoutbox/smileys/wink.gif" alt=";)" onclick="addsmiley(';)')"/>
|
|
|
129 |
<img class="smileys" src="./shoutbox/smileys/sad.gif" alt=":(" onclick="addsmiley(':(')"/>
|
|
|
130 |
<img class="smileys" src="./shoutbox/smileys/shocked.gif" alt=":O" onclick="addsmiley(':O')"/>
|
|
|
131 |
<img class="smileys" src="./shoutbox/smileys/tongue.gif" alt=":P" onclick="addsmiley(':P')"/>
|
|
|
132 |
<img class="smileys" src="./shoutbox/smileys/sick.gif" alt=":S" onclick="addsmiley(':S')"/>
|
|
|
133 |
<img class="smileys" src="./shoutbox/smileys/roll.gif" alt=":roll:" onclick="addsmiley(':roll:')"/>
|
|
|
134 |
<img class="smileys" src="./shoutbox/smileys/cry.gif" alt=";(" onclick="addsmiley(';(')"/>
|
|
|
135 |
<img class="smileys" src="./shoutbox/smileys/mad.gif" alt=":@" onclick="addsmiley(':@')"/><br/>
|
|
|
136 |
<textarea id="shoutbox-message" cols="20" rows="3" name="shoutbox_message"></textarea><br/>
|
|
|
137 |
<input type="submit" name="shoutbox_submit" value="Shout It!"> <a href="http://www.r2xDesign.net" title="Web Scripting Resources - PHP Scripts, PHP Snippets, PHP Tutorials and Free Templates">www.r2xDesign.net</a>
|
|
|
138 |
<input type="hidden" name="shoutbox_ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>">
|
|
|
139 |
</form>
|
|
|
140 |
</div>
|