<?php
/************************************
* Cadence
* Remotely Hosted Guestbook Script.
* (c) 2006, Dennis Pedrie
* www.CadenceBook.com
* add.php
***********************************
* Cadence Guestbook is licensed under
* a Creative Commons License.
* More information is available by visiting
* http://creativecommons.org/licenses/by/3.0/
* or the LICENSE file in the Cadence Root Folder
***********************************/
if(!defined('IN_CADENCE')) {
trigger_error("You may not access this file directly",E_USER_ERROR);
}
//Clean POST variables
$name = $post->clean_var($_POST['name']);
$email = $post->clean_var($_POST['email']);
$content = $post->clean_var($_POST['content']);
// Make sure everything is filled in.
if($name == '' || $email == '' || $content == '') {
$gbook->kill("<strong>All Fields Must Be Completed.</strong>");
}
//Check Banned Users list.
if($post->isbanned($_SERVER['REMOTE_ADDR'],$email)) {
$tpl->assign("header_sent",0);
$gbook->kill("<strong>You appear to have been banned from this guestbook. Contact the management if you have any questions.</strong>");
}
//Check Valid E-Mail
if(!$post->check_email($email)) {
$gbook->kill("Invalid E-Mail Address");
}
//Get Date
$date = date("U");
//Get Browser
$browser = $post->checkbrowser();
//Get Hash
$hash = $post->makehash($date);
//Get IP
$ip = $_SERVER['REMOTE_ADDR'];
//Filter Badwords.
$content = $post->badwords($content);
$approved = ($logged == 1) ? $approved = 1 : $approved = 0;
//Last but not least, check flood control.
$flood = $db->get_results("SELECT post_id, post_ip, post_date FROM ". TABLE_PREFIX ."posts WHERE post_ip = '". $ip ."' ORDER BY post_id desc LIMIT 1");
if($db->num_rows > 0) {
foreach($flood as $flood) {
$timesince = $date - $flood->post_date;
$error = ($timesince < $gbook->flood) ? true : false;
}
}
if($error == true) {
//Header
$tpl->display($gbook->style .'/header.tpl',$book);
echo "<strong>Flood Control Enabled</strong><br />
You must wait ". $gbook->flood ." seconds between posting comments. <br />
Click <a href='javascript:window.location=window.location'>here</a> to try again.";
//Footer
$tpl->display($gbook->style .'/footer.tpl');
exit;
}
//Run Query.
$db->query($q->addcomment($name,$email,$ip,$content,$date,$browser,$hash,$book,$approved,$logged));
$db->query($q->updatepostcount("up"));
$content = "This E-Mail was sent in regards to a comment made on ". $title ."
This E-Mail contains a confirmation link for your comment. Please follow the below link to validate your comment.
Click Here: ". $CONFIG['url'] ."index.php?act=login&code=02&approve=". $hash ."
If you received this message in error, please disregard it.
Thank You.";
//Send Mail. My localhost doesn't have a Mail Server,
//so I'm diabling error reporting on the Mail if it's sent from my computer.
($ip == "127.0.0.1") ? @mail($title ." Guestbook Comment Validation",$content,"From: $email\r\n" . "Reply-To: $email\r\n" . "X-Mailer: PHP/" . phpversion()) : mail($title ." Guestbook Comment Validation",$content,"From: $email\r\n" ."Reply-To: $email\r\n" ."X-Mailer: PHP/" . phpversion()) ;
header("location:index.php?book=$book&act=addcomplete");
//Send E-Mail
?>