View file XCMS_ver_1_0/gbook/goo.php

File size: 4.41Kb
<?
#######################################################
#  [Автор скрипта: ]                                 #
#  [Роман Гринько aka Nominal]                        #
#  [ICQ:  405-623-516] [E-Mail: [email protected]]    #
#######################################################
// Модуль by Shell
@session_start();

$dir = '../';
include_once ($dir.'system/func.php');


function num($str)
{
		return abs(intval($str));
}

function html($str)
{
		return strtr(htmlspecialchars(stripcslashes($str),ENT_QUOTES,'UTF-8'), array('$'=>'&#36;','%'=>'&#37;','_'=>'&#95;'));
}

function bb_code($text){
		$text = preg_replace('#\[b\](.*?)\[/b\]#si', '<b>\1</b>', $text);
		$text = preg_replace('#\[i\](.*?)\[/i\]#si', '<i>\1</i>', $text);
		$text = preg_replace('#\[u\](.*?)\[/u\]#si', '<u>\1</u>', $text);
		$text = preg_replace('#\[red\](.*?)\[/red\]#si', '<font color="#FF0000">\1</font>', $text);
		$text = preg_replace('#\[green\](.*?)\[/green\]#si', '<font color="#00FF00">\1</font>', $text);
		$text = preg_replace('#\[blue\](.*?)\[/blue\]#si', '<font color="#0000FF">\1</font>', $text);
	    $text = preg_replace("#(?:http?|ftp)://[^<\s\n]+#", '<a href="\\0" target=\"_blank\">\\0</a>', $text);
		return $text;
}
function smile($matches)
	{
	static $c;
	$arr = array('&lt;1&gt;',
                   '&lt;2&gt;',
                   '&lt;3&gt;',
                   '&lt;4&gt;',
                   '&lt;5&gt;',
                   '&lt;6&gt;',
                   '&lt;7&gt;',
                   '&lt;8&gt;',
                   '&lt;9&gt;',
                   '&lt;10&gt;');

		if($c == 1) return $matches[0];
		if(!in_array($matches[0], $arr)) return $matches[0];

		$c++;

    	$smiles = array(
 		'<img src="smiles/1.gif" alt="{smile}" />',
		'<img src="smiles/2.gif" alt="{smile}" />',
		'<img src="smiles/3.gif" alt="{smile}" />',
		'<img src="smiles/4.gif" alt="{smile}" />',
		'<img src="smiles/5.gif" alt="{smile}" />',
		'<img src="smiles/6.gif" alt="{smile}" />',
		'<img src="smiles/7.gif" alt="{smile}" />',
		'<img src="smiles/8.gif" alt="{smile}" />',
		'<img src="smiles/9.gif" alt="{smile}" />',
		'<img src="smiles/10.gif" alt="{smile}" />'
		);

		return str_replace($arr, $smiles, $matches[0]);
	}


if (!empty($_POST['go']))
	{
		$name = $_POST['user'];
		$message = $_POST['mes'];
		$captcha = substr(intval($_POST['captcha']),0,5);
		if($_SESSION['captcha_keystring'] !== $captcha) {$err[] = 'Неверный код';}
        if(empty($name) or strlen($name) < 3) {$err[] = 'Не введено имя';}
        if(empty($message) or strlen($message) < 5) {$err[] = 'Не введено сообщение';}
        if(strlen($message) > 500) {$err[] = 'Слишком длинное сообщение max.200';}


if(count(@$err)==0){

$name = html($name);
$message = str_replace("\r", '', $message);
$message = nl2br(bb_code(html($message)));
$message = str_replace('
', '', $message);
$message = preg_replace_callback("|&lt;(\d{1,10})&gt;|", "smile", $message);


$time = time();

	$ip = html(getenv("HTTP_X_FORWARDED_FOR"));
	if (empty($ip) || $ip=='unknown') { $ip=html(getenv("REMOTE_ADDR"));}
	$user_agent = getenv("HTTP_USER_AGENT");
	$browser = strtok($user_agent," ");
	$browser = html(str_replace('|', '', $browser));

	$fopen=fopen('base.dat','a');
		   fputs($fopen,"$name::$time::$message::$ip::$browser\r\n");
		   fclose($fopen);

header('location: index.php');
exit;
}

}
include $dir.'system/head.php';
?>

<?
if(count(@$err)>0){

  echo '<div class="error">';
  for($i=0;$i<count($err);$i++)
  	{
  		echo $err[$i] . '<br />';
  	}
  echo '</div>';
}
?>
<form method="post" action="goo.php">
<div class="navs">
<?php
if(is_user()) {
echo 'Имя: <b>'.$_SESSION['login'].'</b><input type="hidden" name="user" value="'.$_SESSION['login'].'"><br />';
} else {
	echo 'Имя: <small>(min.5)</small><br />
	<input type="text" name="user" maxlength="10"><br />';
}
?>
	Сообщение: <small>(min.5)</small><br />
	<textarea cols="25" rows="3" name="mes" maxlength="200"></textarea><br />
	Код с картинки:<br/>
	<img src="captcha/index.php" id="image_captcha" alt="Loading..."/><br/>
	<input type="text" size="10" name="captcha" maxlength="4"/><br/>
	<input type="submit" name="go" value="Отправить" class="button">
</form>

<div class="navi"><a href="/gbook/">Гостевая</a> | <a href="help.php?m=smiles">Смайлы</a> | <a href="help.php?m=bbcode">BB-коды</a></div></div>
<?php
include $dir.'system/end.php';
?>