<?php
/**
 * la.plume Micro CMS
 * ==================
 * COPYRIGHT Patrick Taylor http://www.mini-print.com/
 */

if (isset($_POST['submitcomment'])) {

	$comment = stripslashes(trim($_POST['comment']));

	if (strlen($comment) < 1) {
		$problem = TRUE;
		$response = "Not sent. You didn't enter a comment.";
	}

	$spam = array('<a href="http:', '[url=http:', '[link=http:');
	$spam_found = FALSE;
	foreach ($spam as $spamword) {
		if (strrpos($comment, $spamword)) {
			$spam_found = TRUE;
			break;
		}
	}
	if ($spam_found) {
		$problem = TRUE;
		unset($comment);
		$response = "Not sent. Please do not submit web addresses.";
	}

	if (!$problem) {
		$ip = $_SERVER['REMOTE_ADDR'];
		$subject = 'Website comment from la.plume Micro CMS';
		$body = "Received on $source: \n\n{$comment}\n\nIP: $ip";
		$body = wordwrap($body, 70);
		mail (EMAIL, $subject, $body) or print "Not sent.";
		$response = 'Your comment has been submitted, thank you.';
		$hideform = TRUE;
	}

	echo '		<div class="response" id="target">';
	echo "\n\n<p>$response</p>\n\n";
	echo '		</div>';
	echo "\n";

}

?>

<?php if ($hideform == FALSE) { ?>
<h4>Leave a comment</h4>

<form method="post" id="contactform" action="#target">

<p><textarea name="comment" id="comment" rows="6" cols="68"></textarea></p>
<input type="hidden" name="commentform" value="go">
<input type="submit" name="submitcomment" class="submit" value="Submit">

</form>

<p>[ No links, please. Comments are pre-moderated. ]</p>
<?php } ?>
