<?php
$b = settings('guestbook_page');
$seo_pageTitle = seo_str($site->pageTitle($b['guestbook_page']));
//captca questions and answers
$spamQuestions = array('What is 3 + 1?', 'What colour is the sky?', 'What is 2 + 1?');
$spamAnswers = array(4, 'blue', 3);
//
if($url['pid'] == $b['guestbook_page'])
{
//save comment
if(isset($_POST['name']))
{
$post = $form->clean_fields($_POST);
if(in_array($post['code'], $spamAnswers) && !empty($post['name']) && !empty($post['comment']) && isset($_POST['confirm_email']) && empty($post['confirm_email']))
{
$now = time();
$settings = settings('guestbook_comment_autoapprove');
$post['email'] = md5($_POST['email']);
$post['website'] = str_replace(array('http://', 'https://', 'HTTP://', 'HTTPS://'), "", $post['website']);
//spam check
$isSpam = spamCheck($post['comment'].' '.$post['name']);
if(!$isSpam)
{
$mysql->insert("fs_guestbook", "name,email,website,comment,stamp,approved", "{$post['name']},{$post['email']},{$post['website']},{$post['comment']},$now,{$settings['guestbook_comment_autoapprove']}");
}
}
$_SESSION['commentAdded'] = 'y';
header("Location: /{$b['guestbook_page']}/$seo_pageTitle/");
exit;
}
//show entries
$perpage = 20;
$start = (int)$_GET['junk'];
$query = $mysql->query("name,email,website,comment,stamp", "fs_guestbook", "approved = 'y' ORDER BY `stamp` DESC LIMIT $start, $perpage");
while($data = $mysql->get_array($query))
{
$name = (!empty($data['website'])) ? '<a href="http://'.$data['website'].'" target="_blank">'.$data['name'].'</a>' : $data['name'];
$book_out .= stripslashes('<hr /><blockquote><strong>'.$name.'<small><span>&middot;</span>'.date("d F Y - h:ia", $data['stamp']).'</small></strong>'.nl2br($data['comment']).'</blockquote>');
}
//if moreposts is set in GET, show the contents
if($_GET['page'] == 'moreposts')
{
echo $book_out;
die();
exit;
}
//
if($_SESSION['commentAdded'] == 'y')
{
unset($_SESSION['commentAdded']);
$mainhtml .= '<p style="font-weight:bold;" align="center">Thank you, your comment has been added.</p>';
}
$mainhtml .= '<div id="guestbook_content">'.$book_out.'</div>';
//show more posts
if($mysql->num_rows($mysql->query("ID", "fs_guestbook", "approved = 'y'")) > $perpage)
{
$mainhtml .= '<hr /><h2 id="morelink"><a href="javascript:;" id="load_more_content">Show more</a><input type="hidden" id="loadmore" name="loadmore" value="'.$perpage.'" /></h2>';
$mainhtml .= '<script type="text/javascript">Event.observe(\'load_more_content\', \'click\', function(event){var more = document.getElementById(\'loadmore\').value;new Ajax.Request(\'/'.$b['guestbook_page'].'/moreposts/\'+more+\'/\', {method: \'get\',evalScripts:true,onCreate:function(){$(\'load_more_content\').update(\'Loading\');},onSuccess: function(transport){new Insertion.Bottom(\'guestbook_content\', transport.responseText);$(\'load_more_content\').update(\'Show more\');document.getElementById(\'loadmore\').value = parseInt(more)+'.$perpage.';}});});</script>';
}
else
{
$mainhtml .= '';
}
//add entry form
$rand = rand(0, (sizeof($spamQuestions)-1));
$mainhtml .= '<script type="text/JavaScript">function check_length(my_form){maxLen=500;if(my_form.comment.value.length >= maxLen){var msg = "You have reached your maximum limit of characters allowed";alert(msg);my_form.comment.value = my_form.comment.value.substring(0, maxLen);}else{document.getElementById(\'charcount\').innerHTML = (maxLen - my_form.comment.value.length)+\' characters remaining\';}}</script>
<hr />
<form name="addgb" id="addgb" method="post" action="">
<h2>Add your comment</h2>
<table border="0" cellspacing="0" cellpadding="0">
<tr><th>Your name</th><td><input name="name" type="text" id="name" size="32" class="required" /></td></tr>
<tr><th>Your email address <small>(Will not be published)</small></th><td><input name="email" type="text" id="email" size="32" class="validate-email" /></td></tr>
<tr><th>Website URL</th><td><input name="website" type="text" id="website" size="32" /></td></tr>
<tr><th valign="top">Comment<small id="charcount">(500 characters remaining)</small></th><td><textarea name="comment" rows="7" id="comment" class="required" onkeyup="check_length(this.form);"></textarea></td></tr>
<tr><th>'.$spamQuestions[$rand].'<small>(Anti-spam question)</small></th><td><input name="code" type="text" id="code" size="3" class="required" /></td></tr>
<tr style="display:none;"><td>&nbsp;</td><td><input name="confirm_email" type="text" id="confirm_email" value="" /></td></tr>
<tr><th>&nbsp;</th><td><input type="submit" name="button" id="button'.$blog['ID'].'" value="Post comment" class="button" /></td></tr>
</table>
</form>';
//form validation
$mainhtml .= '<script>new Validation(\'addgb\',{immediate:true});</script>';
//js form validation
$head = '';
if(!strstr($mainhtml, 'blog/src/style.css'))
{
$head .= '<link rel="stylesheet" type="text/css" href="/inc/blog/src/style.css" />';
}
if(!strstr($mainhtml, 'prototype.js'))
{
$head .= '<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js"></script>';
}
if(!strstr($mainhtml, 'scriptaculous.js'))
{
$head .= '<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculous.js?load=effects,builder"></script>';
}
if(!strstr($mainhtml, 'validation.js'))
{
$head .= '<script type="text/javascript" src="/inc/blog/src/validation.js"></script>';
}
$mainhtml = str_replace("</head>", $head.'</head>', $mainhtml);
//include this add-ons's overwrite css file from the template being used, if there is one
$t = settings('template');
if(file_exists('templates/'.$t['template'].'/addons/guestbook.css'))
{
$mainhtml = str_replace("</head>", '<link rel="stylesheet" type="text/css" href="/templates/'.$t['template'].'/addons/guestbook.css" /></head>', $mainhtml);
}
else
{
$mainhtml = str_replace("</head>", '<link rel="stylesheet" type="text/css" href="//www.freesites.com.au/addons/guestbook.css" /></head>', $mainhtml);
}
//end
}
?>