<?
session_start();
include 'config.php';
if ($use_conn == 1) {
include $conn;
} else {
$link = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbdatabas, $link);
}
include 'funktioner.php';
include 'admin.php';
if ( isset( $_POST['text'] ) ) {
$namn = $_POST['namn'];
$email = $_POST['email'];
$hemsida = $_POST['hemsida'];
$tid = time();
$text = $_POST['text'];
$ip = getenv('REMOTE_ADDR');
if (in_array($ip, $blocked_ip)) {
die('Din ip är särrad!');
}
$text = str_replace("'",'',$text);
addslashes($namn);
addslashes($email);
addslashes($hemsida);
addslashes($text);
$sql = "INSERT INTO guestbook(namn, email, hemsida, tid, text, ip) VALUES('{$namn}', '{$email}', '{$hemsida}', $tid, '{$text}', '{$ip}')";
mysql_query($sql);
}
ini_set('arg_separator.output', '&');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Gästbok </TITLE>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!--
function valid() {
if ((document.nytt.hemsida.value == "") || (document.nytt.hemsida.value == "http://")) {
document.nytt.hemsida.value = "nosite";
}
<? if ($need_email == 0) { ?>
if (document.nytt.email.value == "") {
document.nytt.email.value = "nomail";
}
<? } ?>
if (document.nytt.namn.value == "") {
alert('Du måste skriva ditt namn!');
return false;
}
<? if ($need_email == 1) { ?>
else if (document.nytt.email.value == "") {
alert('Du måste skriva en giltig e-mail adress!');
return false;
}
<? } ?>
else if (document.nytt.text.value == "") {
alert('Du måste skriva ett meddelande!');
return false;
} else {
return true;
}
}
//-->
</SCRIPT>
<LINK rel="stylesheet" type="text/css" href="layout.css">
</HEAD>
<BODY>
<!-- Här börjar HTML-sidan. Här kan du lägga t.ex. en meny eller liknande. -->
<BR><DIV class="rubrik">
<div align="left">Sätt gärna ett avtryck i Quinns gästbok</div>
</DIV>
<FORM METHOD=POST name="nytt" onSubmit="return valid();" action="guestbook.php">
<TABLE style="font-size:12px;"><TR>
<TD>Namn:</TD>
<TD><INPUT TYPE="text" NAME="namn" maxLength="30"></TD>
</TR><TR>
<TD>E-mail:</TD>
<TD><INPUT TYPE="text" NAME="email" maxLength="50"></TD>
</TR><TR>
<TD>Hemsida:</TD>
<TD><INPUT TYPE="text" NAME="hemsida" maxLength="255" value="http://"></TD>
</TR>
</TABLE>
<TEXTAREA NAME="text" ROWS="6" COLS="40"></TEXTAREA><BR>
<INPUT TYPE="submit" value="Skicka!">
</FORM>
<DIV class="rubrik">
<div align="left"></div>
</DIV><BR>
<?
if ($max_inlagg == 0) {
$sql = "SELECT * FROM guestbook ORDER BY id DESC";
} else {
$sql = "SELECT * FROM guestbook ORDER BY id DESC LIMIT $max_inlagg";
}
$res = mysql_query($sql);
while($ar = mysql_fetch_array($res)) {
$namn = $ar['namn'];
$email = $ar['email'];
$hemsida = $ar['hemsida'];
$tid = $ar['tid'];
$text = $ar['text'];
$ip = $ar['ip'];
$id = $ar['id'];
$tid = date("Y-m-d H:i", $tid);
$namn = stripslashes($namn);
$email = stripslashes($email);
$hemsida = stripslashes($hemsida);
$text = stripslashes($text);
$text = htmlentities($text);
$text = nl2br($text);
if ($bui_tags == 1) {
$text = _bui($text);
}
if ($cs_tags == 1) {
$text = _cs($text);
}
if ($qoute_tag == 1) {
$text = _qoute($text);
}
if ($smileies == 1) {
$text = _smileies($text);
}
if ($links == 1) {
$text = _link($text);
}
if ($img == 1) {
$text = _img($text);
}
echo '<DIV class="tid">';
if ($email == 'nomail' || $email == 'nosite') {
echo $namn;
} else {
echo '<A href="mailto:'.$email.'">'.$namn.'</A>';
}
if ($hemsida == 'nosite' || $hemsida == 'nomail') {
echo ' - ';
} else {
echo ' - <A href="'.$hemsida.'">'.$hemsida.'</A> - ';
}
echo $tid.'</DIV><DIV class="text">'.$text.'</DIV>';
if ($_SESSION['admin på gästboken.'] == 'mm, stämmer') {
echo 'Admin: Detta skrevs av ip: '.$ip.'. <A href="guestbook.php?mode=delete&id='.$id.'">Radera inlägget</A>. <A href="guestbook.php?mode=edit&id='.$id.'">Redigera inlägget</A>.<BR>';
}
echo '<BR><BR>';
}
?>
<!-- Här kan du lägga till info som t.ex. regler osv. -->
</BODY>
</HTML>
sen funktions filen:
<?
function _bui($str) {
while (substr_count($str, '[b]') > substr_count($str, '[/b]')) {
$str .= '[/b]';
} while (substr_count($str, '[u]') > substr_count($str, '[/u]')) {
$str .= '[/u]';
} while (substr_count($str, '[i]') > substr_count($str, '[/i]')) {
$str .= '[/i]';
}
$ett = array('[b]','[/b]','[u]','[/u]','[i]','[/i]');
$tva = array('<B>','</b>','<u>','</u>','<i>','</i>');
$str = str_replace($ett, $tva, $str);
return $str;
}
function _cs($str) {
while (substr_count($str, '[color') > substr_count($str, '[/color]')) {
$str .= '[/color]';
} while (substr_count($str, '[size') > substr_count($str, '[/size]')) {
$str .= '[/size]';
}
$str = preg_replace("/\[color\=#?([abcdefABCDEF0-9]+)\]/","<span style=\"color:#$1\">",$str);
$str = preg_replace("/\[size\=(\d{2})\]/","<span style=\"font-size:$1px\">",$str);
$str = str_replace('[/color]', '</span>', $str);
$str = str_replace('[/size]', '</span>', $str);
return $str;
}
function _qoute($str) {
while (substr_count($str, '[qoute') > substr_count($str, '[/qoute]')) {
$str .= '[/qoute]';
}
$str = preg_replace('/\[quote="(.*)"\](.*?)\[\/quote\]/i', '<blockquote><b>\\1 skrev:</b><br>\\2</blockquote>', $str);
$str = preg_replace('/\[quote="(.*)"\](.*?)\[\/quote\]/i', '<blockquote><b>\\1 skrev:</b><br>\\2</blockquote>', $str);
$str = str_replace('[quote]', '<blockquote><b>Citat:</b><br>', $str);
$str = str_replace('[/quote]', '</blockquote>', $str);
return $str;
}
function _link($text) {
$text = preg_replace( '/(?<![img])(http:\/\/|ftp:\/\/|https:\/\/|mailto:|[url]www.[/url])[\w]+(.[\w]+)([\w\-\.\,\@\?\^\=\%\&\:\/\~\+\#]*[\w\-\@\?\^\=\%\&\/\~\+\#])?/i', "<a href=\"$0\" title=\"$0\" target='_blank'>$0</a>", $text );
$text = str_replace("href=\"www.","href=\"http://www.",$text);
return $text;
}
function _img($str) {
$str = preg_replace("/\[img\](.*)\[\/img\]/i", '<img src="\\1" alt="" />', $str);
return $str;
}
include 'smileys.php';
?>