View file XCMS_ver_1_0/moduls/news/add.php

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

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

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'];
        if(empty($message) or strlen($message) < 5) {$err[] = 'Не введено сообщение';}
        if(strlen($message) > 500) {$err[] = 'Слишком длинное сообщение max.500';}


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

$name = html($name);
$message = nl2br(bb_code(html($message)));

$message = preg_replace_callback("|&lt;(\d{1,10})&gt;|", "smile", $message);
$message = str_replace("\r", '', $message);
$message = str_replace('
', '', $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('news.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="add.php">
<div class="navs">
<?php


echo 'Автор: <b>'.$_SESSION['login'].'</b><input type="hidden" name="user" value="'.$_SESSION['login'].'"><br />';


} else { header("Location: ../../index.php?no_admin"); exit();}
?>
	Новость: <small>(min.5)</small><br />
	<textarea cols="25" rows="3" name="mes" maxlength="200"></textarea><br />
	
	<input type="submit" name="go" value="Отправить" class="button">
</form>

<div class=""><a href="/moduls/news">В новости</a> | <a href="help.php?m=smiles">Смайлы</a> | <a href="help.php?m=bbcode">BB-коды</a></div></div>
<?php
include $dir.'system/end.php';

?>