Blame | Last modification | View Log | Download
<?php
##############################################################################
# Copyright (C) 2004 Ramil ALcibar #
# http://www.triphp.com #
# ralcibar@fastmail.fm #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
##############################################################################
?>
<?php include 'config.php'; ?>
<?php
// replace smileys and bad word filtering
function creplace($msg)
{
// smileys
$msg = str_replace(":)", "<img src='smileys/smile.gif' alt=':)' align='absbottom'>", $msg);
$msg = str_replace(":(", "<img src='smileys/sad.gif' alt=':(' align='absbottom'>", $msg);
$msg = str_replace(":p", "<img src='smileys/tongue.gif' alt=':p' align='absbottom'>", $msg);
$msg = str_replace(":D", "<img src='smileys/biggrin.gif' alt=':)' align='absbottom'>", $msg);
$msg = str_replace(":0", "<img src='smileys/eek.gif' alt=':p' align='absbottom'>", $msg);
$msg = str_replace(":S", "<img src='smileys/confused.gif' alt=':)' align='absbottom'>", $msg);
$msg = str_replace(";)", "<img src='smileys/wink.gif' alt=':(' align='absbottom'>", $msg);
$msg = str_replace("=blush", "<img src='smileys/blush.gif' alt=':p' align='absbottom'>", $msg);
$msg = str_replace("=boggle", "<img src='smileys/boggle.gif' alt=':)' align='absbottom'>", $msg);
$msg = str_replace("=cool", "<img src='smileys/cool.gif' alt=':(' align='absbottom'>", $msg);
$msg = str_replace("=roll", "<img src='smileys/rolleyes.gif' alt=':p' align='absbottom'>", $msg);
$msg = str_replace("=stress", "<img src='smileys/stress.gif' alt=':(' align='absbottom'>", $msg);
$msg = str_replace("=tired", "<img src='smileys/tired.gif' alt=':p' align='absbottom'>", $msg);
$msg = str_replace("=ur", "<img src='smileys/urgh.gif' alt=':)' align='absbottom'>", $msg);
$msg = str_replace("=>", "<img src='smileys/inlove.gif' alt=':(' align='absbottom'>", $msg);
$msg = str_replace("=lol", "<img src='smileys/icon_lol.gif' alt=':p' align='absbottom'>", $msg);
// bad word filter
// add as many bad words as you can
$msg = str_replace("bad", "*", $msg);
$msg = str_replace("shit", "*", $msg);
$msg = str_replace("bitch", "*", $msg);
$msg = str_replace("atay", "*", $msg);
$msg = str_replace("fuck", "*", $msg);
$msg = str_replace("sex", "*", $msg);
$msg = str_replace("ugly", "*", $msg);
$msg = str_replace("hate", "*", $msg);
$msg = str_replace("hatred", "*", $msg);
return $msg;
}
?>
<?php
// check if the form is submitted
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$date = date("Y-m-d");
$ip = $_SERVER['REMOTE_ADDR'];
$name = htmlspecialchars($name);
$email = htmlspecialchars($email);
$message = htmlspecialchars($message);
// insert into database
$strsql = "INSERT INTO myphptag (Name, Email, Message, DatePost, IP)
VALUES ('$name','$email','$message','$date','$ip')";
mysql_query($strsql, $ServerConnect) or die(mysql_error());
header('Location:'.$_SERVER['REQUEST_URI']);
exit;
}
?>
<html>
<head>
<title>MyPHPTag</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
function checkForm()
{
var gname, gmessage;
with(window.document.shout)
{
gname = name;
gmessage = message;
}
if(gname.value == '')
{
alert('Name cannot be null!');
gname.focus;
return false;
}
if(gmessage.value == '')
{
alert('Message cannot be null!');
gmessage.focus;
return false;
}
else if(gmessage.value.length > 255)
{
alert("Please don't abuse our shoutbox!\nEnter only up to 255 characters.");
gmessage.focus;
return false;
}
else
{
return true;
}
}
function addsmiley(code)
{
var pretext = document.shout.message.value;
this.code = code;
document.shout.message.value = pretext + code;
}
</script>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
if(!isset( $_GET ['page' ]))
{
$page =1;
}
else
{
$page =$_GET ['page' ];
}
// Define the number of results per page
$max_results = 5;
// Figure out the limit for the query based on the current page number.
$from = (( $page *$max_results ) - $max_results );
// Perform MySQL query on only the current page number's results
$query = "SELECT * FROM myphptag ORDER BY TagId DESC LIMIT $from, $max_results";
$result = mysql_query($query) or die('Error:'.mysql_error());
$num_rows = mysql_num_rows($result);
?>
<form name="shout" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onSubmit="return checkForm();">
<table width="175" cellspacing="0" cellpadding="2" align="center" style="border:1px solid #333333;">
<?php
if($num_rows == 0)
{
?>
<tr>
<td align="center"><div class="headingfont">No entry!</div></td>
</tr>
<?php
}
else if ($num_rows>0)
{
$x=0;
while($x<$num_rows)
{
if (($x%2)==0) { $bgcolor="#FFFFFF"; } else { $bgcolor="#F0F0F0"; }
$key = mysql_result($result,$x,"TagId");
$name = mysql_result($result,$x,"Name");
$email = mysql_result($result,$x,"Email");
$message = mysql_result($result,$x,"Message");
$nmessage = nl2br($message);
$fmessage = creplace($nmessage);
$finalmessage = wordwrap($fmessage, 15, "\n", 1);
$dateposted = mysql_result($result,$x,"DatePost");
$ip = mysql_result($result,$x,"IP");
?>
<tr bgcolor="<?php echo $bgcolor; ?>">
<td align="left" valign="top" class="content">
<?php
if ($email == "")
{
echo "<div class='headingfont'>" .$name . ":</div>";
}
else
{
echo "<a href='mailto:" . $email . "'>$name</a>:<br>";
}
echo $finalmessage;
?>
</td>
</tr>
<?php
$x++;
}
}
?>
<?php
// Figure out the total number of results in DB:
$total_results =mysql_result (mysql_query ("SELECT COUNT(*) as Num FROM myphptag" ), 0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages =ceil ($total_results /$max_results );
?>
<tr>
<td class="entryheaders" colspan="2" align="center">
<?php
// Build Previous Link
if( $page >1)
{
$prev = ( $page -1);
echo "<a href=\"" .$_SERVER ['PHP_SELF' ]. "?page=$prev \" ><img src='images/previous.gif' border='0' alt='previous' align='middle'></a> " ;
}
for( $i =1;$i <= $total_pages ;$i ++)
{
if(( $page ) == $i )
{
echo "$i ";
}
else
{
echo "<a href=\"" .$_SERVER ['PHP_SELF' ]. "?page=$i \" >$i</a> " ;
}
}
// Build Next Link
if( $page <$total_pages )
{
$next = ( $page +1);
echo "<a href=\"" .$_SERVER ['PHP_SELF' ]. "?page=$next \" ><img src='images/next.gif' border='0' alt='previous' align='middle'></a>" ;
}
?>
</td>
</tr>
<?php
mysql_close($ServerConnect);
?>
<tr>
<td>
Name:<br>
<input type="text" name="name" maxlength="50" size="25"><br>
Email:<br>
<input type="text" name="email" maxlength="50" size="25"><br>
Message:<br>
<textarea name="message" cols="24" rows="4"></textarea><br>
<img src="smileys/smile.gif" alt=":)" border="0" onClick="addsmiley(':)')" style="cursor: pointer;">
<img src="smileys/sad.gif" alt=":(" border="0" onClick="addsmiley(':(')" style="cursor: pointer;">
<img src="smileys/tongue.gif" alt=":p" border="0" onClick="addsmiley(':p')" style="cursor: pointer;">
<img src="smileys/biggrin.gif" alt=":D" border="0" onClick="addsmiley(':D')" style="cursor: pointer;">
<img src="smileys/eek.gif" alt=":0" border="0" onClick="addsmiley(':0')" style="cursor: pointer;">
<img src="smileys/confused.gif" alt=":S" border="0" onClick="addsmiley(':S')" style="cursor: pointer;">
<img src="smileys/wink.gif" alt=";)" border="0" onClick="addsmiley(';)')" style="cursor: pointer;">
<img src="smileys/blush.gif" alt="=blush" border="0" onClick="addsmiley('=blush')" style="cursor: pointer;">
<img src="smileys/boggle.gif" alt="=boggle" border="0" onClick="addsmiley('=boggle')" style="cursor: pointer;">
<img src="smileys/cool.gif" alt="=cool" border="0" onClick="addsmiley('=cool')" style="cursor: pointer;">
<img src="smileys/stress.gif" alt="=stress" border="0" onClick="addsmiley('=stress')" style="cursor: pointer;">
<img src="smileys/tired.gif" alt="=tired" border="0" onClick="addsmiley('=tired')" style="cursor: pointer;">
<img src="smileys/icon_lol.gif" alt="=lol" border="0" onClick="addsmiley('=lol')" style="cursor: pointer;">
<img src="smileys/inlove.gif" alt="=tired" border="0" onClick="addsmiley('=>')" style="cursor: pointer;">
<img src="smileys/rolleyes.gif" alt="=lol" border="0" onClick="addsmiley('=roll')" style="cursor: pointer;">
<img src="smileys/urgh.gif" alt="=tired" border="0" onClick="addsmiley('=ur')" style="cursor: pointer;"><br><br>
<input type="submit" name="submit" value="SHOUT">
</td>
</tr>
</table>
</form>
</body>
</html>