View file NuclearCMS_v.1.0.0/forum/include/mnewt.php

File size: 14Kb
<?
if( in_array($status, array('admin', 'moderator')) )
			{
$f = intval($_GET['f']);
@$back = mysql_fetch_assoc(mysql_query("SELECT name, id FROM `mforums` WHERE id=".$f));
$ip = empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['REMOTE_ADDR'] : $_SERVER['HTTP_X_FORWARDED_FOR'] ;
$ip = htmlspecialchars(addslashes($ip));
if($status == "admin") $user = "Admin"; else $user = htmlspecialchars(sql($_SERVER['HTTP_USER_AGENT']));
	if(!mysql_result(mysql_query("SELECT COUNT(*) FROM mforums WHERE id=".$f), 0))
	{
		if($version == "wml")
			{
				header('Content-type: text/vnd.wap.wml; charset=utf-8');
				header("Cache-Control: no-cache");
				echo(doctype("Ошибка").$tag.'
Ошибка! Подфорума не существует! <br />

<a href="./?p=1&amp;v=wml&amp;sid='.$sid.'">Форумы</a>
'.$tagC.'</p></card></wml>');
			} elseif($version == "xhtml")
				{
					header("Content-type: text/html; charset=utf-8");
					header("Last-Modified:".gmdate("D, d M Y H:i:s")." GMT");
   header("Cache-Control: no-cache, must-relative");
					echo('<html>
<head>
<title>Ошибка</title>
</head>
<body bgcolor="'.$style['background'].'" link="'.$style['link'].'" vlink="'.$style['link'].'" text="#000000">
<table align="center" border="0" cellspacing="1" cellpadding="5" width="350">
<tr><td align="center" bgcolor="'.$style['title'].'">
<font color="#FFFFFF"><b>Ошибка</b></font>
<tr bgcolor="'.$style['text'].'"><td>'.$tag.'Ошибка! Подфорума не существует! '.$tagC.' </td></tr>
<tr bgcolor="'.$style['bottom'].'"><td>'.$tag.'
<a href="./?p=1&amp;v=xhtml&amp;sid='.$sid.'">Форумы</a>
'.$tagC.'</td></tr></table>
</body></html>');
				}
	} elseif(ban($username, $user, $ip))
	{
			if($version == "wml")
			{
				header('Content-type: text/vnd.wap.wml; charset=utf-8');
				header("Cache-Control: no-cache");
				echo(doctype("Ошибка").$tag.'
Ошибка! Вы заблокированы модератором '.$modername.'. <br />
Причина: '.$banmess.'! <br />
-
<a href="'.$_SERVER['HTTP_REFERER'].'">Назад</a><br />
<a href="./?p=1&amp;v=wml&amp;sid='.$sid.'">Форумы</a>
'.$tagC.'</p></card></wml>');
			} elseif($version == "xhtml")
				{
					header("Content-type: text/html; charset=utf-8");
					header("Last-Modified:".gmdate("D, d M Y H:i:s")." GMT");
   header("Cache-Control: no-cache, must-relative");
					echo('<html>
<head>
<title>Ошибка</title>
</head>
<body bgcolor="'.$style['background'].'" link="'.$style['link'].'" vlink="'.$style['link'].'" text="#000000">
<table align="center" border="0" cellspacing="1" cellpadding="5" width="350">
<tr align="center" bgcolor="'.$style['title'].'"><td colspan="2">
<font color="#FFFFFF"><b>Ошибка</b></font>
<tr bgcolor="'.$style['text'].'"><td colspan="2">'.$tag.'Вы заблокированы модератором '.$modername.'</td></tr>
<tr bgcolor="'.$style['text'].'"><td>'.$tag.'Причина:'.$tagC.'</td><td>'.$tag.$banmess.$tagC.'</td></tr>
<tr bgcolor="'.$style['bottom'].'"><td colspan="2">'.$tag.'
<a href="./?p=1&amp;v=xhtml&amp;sid='.$sid.'">Форумы</a>
'.$tagC.'</td></tr></table>
</body></html>');
				}
	} elseif(!$authorize)
	{    if($version == "wml")
			{
				header('Content-type: text/vnd.wap.wml; charset=utf-8');
				header("Cache-Control: no-cache");
				echo(doctype("Ошибка").$tag.'
Вы не авторизованы! <br />
-
<a href="./?p=1&amp;v=wml&amp;sid='.$sid.'">Форумы</a>
'.$tagC.'</p></card></wml>');
			} elseif($version == "xhtml")
				{
					header("Content-type: text/html; charset=utf-8");
					header("Last-Modified:".gmdate("D, d M Y H:i:s")." GMT");
   header("Cache-Control: no-cache, must-relative");
					echo('<html>
<head>
<title>Ошибка</title>
</head>
<body bgcolor="'.$style['background'].'" link="'.$style['link'].'" vlink="'.$style['link'].'" text="#000000">
<table align="center" border="0" cellspacing="1" cellpadding="5" width="350">
<tr align="center" bgcolor="'.$style['title'].'"><td>
<font color="#FFFFFF"><b>Ошибка</b></font>
<tr bgcolor="'.$style['text'].'"><td>'.$tag.'Вы не авторизованы!'.$tagC.'</td></tr>
<tr bgcolor="'.$style['bottom'].'"><td> '.$tag.'
<a href="./?p=1&amp;v=xhtml&amp;sid='.$sid.'">Форумы</a>
'.$tagC.'</td></tr></table>
</body></html>');
				}
 	}  else
	{
		if(empty($_POST['nt']))
		{
			$r = "";
				 for($i=0; $i<strlen($username); $i++)
				{
					$r .= "_";
				}
			if($version == "wml")
			{
				header("Content-type: text/vnd.wap.wml; charset=utf-8");
				header("Cache-Control: no-cache");
				echo(doctype("Новая тема").$tag.'
<b>Добавить тему в "'.$back['name'].'"</b><br /> <br />
Имя: ['.$username.']<br />
Тема: '.$tagC.'<br />
<input type="text" name="topic'.$ref.'" /><br />
'.$tag.'Сообщение:'.$tagC.' <br />
<input type="text" name="mess'.$ref.'" maxlength="600" /><br />');
		if($status == "admin")
		{
			echo($tag.'Закрепить тему: '.$tagC.'<br />
<select name="b'.$ref.'">
<option value="0">Нет</option>
<option value="1">Да</option>
</select><br />');
		}
echo('<anchor>[Добавить]
<go href="./?p=10&amp;v=wml&amp;sid='.$sid.'&amp;f='.$f.'" method="post">
<postfield name="mess" value="$(mess'.$ref.')" />');
	if($status == "admin")
	{
		echo('<postfield name="b" value="$(b'.$ref.')" />');
	}
echo('
<postfield name="topic" value="$(topic'.$ref.')" />
<postfield name="nt" value="1" />
</go></anchor><br />
'.$tag.'-
<a href="./?p=14&amp;v=wml&amp;sid='.$sid.'&amp;f=4">Смайлы</a><br />
<a href="./?p=3&amp;v=wml&amp;sid='.$sid.'&amp;f='.$f.'">Назад в «'.$back['name'].'»</a><br />
'.$tagC.'</p></card></wml>');
			} elseif($version == "xhtml")
			{
				header("Content-type: text/html; charset=utf-8");
				header("Last-Modified:".gmdate("D, d M Y H:i:s")." GMT");
   header("Cache-Control: no-cache, must-relative");
				echo('<html>
<head>
<title>Новая тема</title>
</head>
<body bgcolor="'.$style['background'].'" link="'.$style['link'].'" vlink="'.$style['link'].'" text="#000000">
<form action="./?p=10&amp;v=xhtml&amp;sid='.$sid.'&amp;f='.$f.'" method="post">
<table align="center" border="0" cellspacing="1" cellpadding="5" width="350">
<tr><td align="center" bgcolor="'.$style['title'].'" colspan="2">
<font color="#FFFFFF"><b>Новая тема</b></font>
</td></tr>
<tr bgcolor="'.$style['bottom'].'"><td colspan="2"><b>'.$tag.'Добавить тему в "'.$back['name'].'"'.$tagC.'</b></td></tr>
<tr bgcolor="#deebf1"><td colspan="2"></td></tr>
<tr bgcolor="'.$style['text'].'"><td>'.$tag.'Имя:'.$tagC.'</td><td>'.$tag.'['.$username.']'.$tagC.'</td></tr>
<tr bgcolor="'.$style['text'].'"><td>'.$tag.'Тема:'.$tagC.'</td><td><input type="text" name="topic"></td></tr>
<tr bgcolor="'.$style['text'].'"><td>'.$tag.'Сообщение:'.$tagC.'</td><td><textarea name="mess" cols="30" rows="5"></textarea></td></tr>');
	if($status == "admin")
	{
		echo('<tr bgcolor="'.$style['text'].'"><td nowrap>'.$tag.'Закрепить тему:'.$tagC.'</td>
<td><select name="b">
<option value="0">Нет</option>
<option value="1">Да</option>
</select></td></tr>');
	}
echo('
<tr bgcolor="'.$style['text'].'"><td align="center" colspan="2">
<input type="hidden" name="nt" value="1">
<input type="submit" value="Ответить" /></td></tr>
<tr bgcolor="'.$style['bottom'].'"><td colspan="2"> '.$tag.'
<a href="./?p=14&amp;v=xhtml&amp;sid='.$sid.'&amp;f=4">Смайлы</a><br />
<a href="./?p=3&amp;v=xhtml&amp;sid='.$sid.'&amp;f='.$back['id'].'">Назад в '.$back['name'].'</a><br />
'.$tagC.'</td></tr></table>
</form>
</body></html>');
				}
    	} else
    	{
    		$error = "";
    		$topic = $_POST['topic'];
    		if($transl == "on")
  			{
  				$topic = translate($topic);
  			}
    		$topic = sql(trim(htmlspecialchars(chop($topic))));
    		$topic = cutString($topic, 100);
    		$topic = preg_replace("|[\r\n]+|", "\r\n", $topic);
 			$topic = preg_replace("|[\n]+|", "\n", $topic);
  			$message = $_POST['mess'];
  			if($transl == "on")
  			{
                $message = translate($message);
  			}
			$message = preg_replace("|[\r\n]+|", " \r\n", $message);
 			$message = preg_replace("|[\n]+|", "\n", $message);
    		$message = sql(htmlspecialchars(trim(chop(cutString($message, 1024)))));
            $message = preg_replace_callback("|&lt;(\d{1,20})&gt;|", "smile", $message);
            $sesss = mysql_query("SELECT * FROM `users` WHERE `username`='".$username."'");
				$sesRR = mysql_fetch_array($sesss);
			    $upd = $sesRR['upd'];
				$rz = time() - $upd;
  			if($status == "admin" or $status == "moderator")
				{
					$message= preg_replace("|\[b\](.*)\[/b\]|i", "<b>\\1</b>", $message);
					$message = preg_replace("|\[i\](.*)\[/i\]|i", "<i>\\1</i>", $message);
				}
				if(strpos($message, "http://") !== false)
				{
					$message = preg_replace("|(http://[^\s]+)|i", "<a href=\"go/?\\1\">\\1</a>", $message);
				}
				else if(strpos($message, "HTTP://") !== false)
				{
					$message = preg_replace("|(HTTP://[^\s]+)|i", "<a href=\"go/?\\1\">\\1</a>", $message);
				} 
				else
				{
					$message = preg_replace("|\[url=(.*)\](.*)\[/url\]|is", "<a href=\"go/?http://\\1\">\\2</a>", $message);
				}
    			if(empty($message))
    			{
    				$error .= "Поле \"Сообщение\" не заполнено! <br />";
    			}
    			if(empty($topic))
    			{
    				$error .= "Поле \"Тема\" не заполнено! <br />";
    			}
    			if(!preg_match("|^[-a-z0-9а-яё_!?№#;:%^&*()+=~\|\\\/ @.,\[\]\{\}\"'<>\s]*$|iu", $message))
    			{
    				$error .= "Сообщение содержит плохие символы!<br />";
    			}

    			if(!preg_match("|^[-a-z0-9а-яё_!?№#;:%^&*()+=~\|\\\/ @.,\[\]\{\}\"'<>]*$|iu", $topic))
    			{
    				$error .= "Тема содержит плохие символы!<br />";
    			}

				/*if ($rz <= 21600)
				{
					$error .= "Не стоит создавать столько тем! <br />";
    			}*/
    		if(!empty($error))
    		{
    		$r = "";
				 for($i=0; $i<strlen($username); $i++)
				{
					$r .= "_";
				}
    			if($version == "wml")
				{
					header("Content-type: text/vnd.wap.wml; charset=utf-8");
					header("Cache-Control: no-cache");
					echo(doctype("Новая тема").$tag.$error.'
<b>Добавить тему в "'.$back['name'].'"</b><br /> <br />
Имя: ['.$username.']<br />
Тема:'.$tagC.' <br />
<input type="text" name="topic'.$ref.'" /><br />
'.$tag.'Сообщение:'.$tagC.' <br />
<input type="text" name="mess'.$ref.'" maxlength="600" /><br />');
		if($status == "admin")
		{
			echo($tag.'Закрепить тему: '.$tagC.'<br />
<select name="b'.$ref.'">
<option value="0">Нет</option>
<option value="1">Да</option>
</select><br />');
		}
echo('
<anchor>[Ответить]
<go href="./?p=10&amp;v=wml&amp;sid='.$sid.'&amp;f='.$f.'" method="post">
<postfield name="mess" value="$(mess'.$ref.')" /> ');
	if($status == "admin")
	{
		echo('<postfield name="b" value="$(b'.$ref.')" />');
	}
echo('
<postfield name="topic" value="$(topic'.$ref.')" />
<postfield name="nt" value="1" />
</go></anchor><br />
'.$tag.'-
<a href="./?p=14&amp;v=wml&amp;sid='.$sid.'&amp;f=4">Смайлы</a><br />
<a href="./?p=3&amp;v=wml&amp;sid='.$sid.'&amp;f='.$f.'">Назад в '.$back['name'].'</a><br />
'.$tagC.'</p></card></wml>');
				} elseif($version == "xhtml")
				{
					header("Content-type: text/html; charset=utf-8");
					header("Last-Modified:".gmdate("D, d M Y H:i:s")." GMT");
   header("Cache-Control: no-cache, must-relative");
					echo('<html>
<head>
<title>Новая тема</title>
</head>
<body bgcolor="'.$style['background'].'" link="'.$style['link'].'" vlink="'.$style['link'].'" text="#000000">
<form action="./?p=10&amp;v=xhtml&amp;sid='.$sid.'&amp;f='.$f.'" method="post">
<table align="center" border="0" cellspacing="1" cellpadding="5" width="350">
<tr><td align="center" bgcolor="'.$style['title'].'" colspan="2">
<font color="#FFFFFF"><b>Новая тема</b></font>
</td></tr>
<tr bgcolor="'.$style['bottom'].'"><td colspan="2"><b>Добавить тему в "'.$back['name'].'"</b></td></tr>
<tr bgcolor="#deebf1"><td colspan="2">'.$tag.'<b>'.$error.'</b>'.$tagC.'</td></tr>
<tr bgcolor="'.$style['text'].'"><td>'.$tag.'Имя:'.$tagC.'</td><td>'.$tag.'['.$username.']'.$tagC.'</td></tr>
<tr bgcolor="'.$style['text'].'"><td>'.$tag.'Тема:'.$tagC.'</td><td><input type="text" name="topic"></td></tr>
<tr bgcolor="'.$style['text'].'"><td>'.$tag.'Сообщение:'.$tagC.'</td><td><textarea name="mess" cols="30" rows="5"></textarea></td></tr>');
	if($status == "admin")
	{
		echo('<tr bgcolor="'.$style['text'].'"><td nowrap>'.$tag.'Закрепить тему:'.$tagC.'</td>
<td><select name="b">
<option value="0">Нет</option>
<option value="1">Да</option>
</select></td></tr>');
	}
echo('
<tr bgcolor="'.$style['text'].'"><td align="center" colspan="2">
<input type="hidden" name="nt" value="1">
<input type="submit" value="Ответить" /></td></tr>
<tr bgcolor="'.$style['bottom'].'"><td colspan="2">'.$tag.'
<a href="./?p=14&amp;v=xhtml&amp;sid='.$sid.'&amp;f=4">Смайлы</a><br />
<a href="./?p=3&amp;v=xhtml&amp;sid='.$sid.'&amp;f='.$back['id'].'">Назад в '.$back['name'].'</a><br />
'.$tagC.'
</td></tr>
</table>
</form>
</body></html>');
				}
			} else
			{
				if(mysql_result(
				   mysql_query("SELECT COUNT(*)
				                FROM `mthemes`
				                WHERE `tname` = '".$topic."'
				                AND `name` = '".$username."'"), 0))
				{
				     header("Location: ".$forumdir."p=3&v=".$version."&f=".$f."&sid=".$sid);
				     exit();
				}

				if(($status == "admin") and $_POST['b'] == "1")
				{
					$SQL = "INSERT INTO `mthemes` VALUES(0, '".$topic."', '".$username."', 'off', ".$f.", ".time().", 0, 0, '')";
				} else
				{
					$SQL = "INSERT INTO `mthemes` VALUES(0, '".$topic."', '".$username."', 'off', ".$f.", ".time().", 1, 0, '')";
				}
				mysql_query($SQL);
				mysql_query("INSERT INTO `mposts` VALUES (0, '".$username."', '".$message."', ".crc32($message).", '".mysql_insert_id()."', '".time()."', '".$user."', '".$ip."')");
  				header("Location: ".$forumdir."p=3&v=".$version."&f=".$f."&sid=".$sid);
    }

		}
	}
	}
?>