Просмотр файла newtopik.php

Размер файла: 11.7Kb
<?php
// MyForum - Сервис форумов 
// Copyright © A'lex и KO. All Rights Reserved
// По всем вопросам обращайтесь на email [email protected] или в асю 376920428

include 'config.php';
include 'functions.php';

$r = mysql_query("SELECT * FROM {$table}{$f}_bannick");
for($i=0; $i<mysql_numrows($r); $i++) {
	$a=mysql_fetch_array($r);
	if (!lastdate($a['Date'], $date)) {mysql_query("DELETE FROM {$table}{$f}_bannick WHERE Nick='{$a['Nick']}'");}
}
$r = mysql_query("SELECT * FROM {$table}{$f}_banip");
for($i=0; $i<mysql_numrows($r); $i++) {
	$a=mysql_fetch_array($r);
	if (!lastdate($a['Date'], $date)) {mysql_query("DELETE FROM {$table}{$f}_banip WHERE IP='{$a['IP']}' AND UserAgent='{$a['UserAgent']}'");}
}

$r = mysql_query("SELECT * FROM {$table}{$f}_forums WHERE ID=$p");
$a=mysql_fetch_array($r);
$ForumTitle=$a['Title'];
$wmode=getwmode($w);
$back="<a href=\"showforum.php?f=$f&p=$p$isid\">Назад в $ForumTitle</a>";
if ($sid!=FALSE) {
	$name=$userinfo['Nick'];
	$namehtml="<input type=\"hidden\" name=\"name\" value=\"$name\"/>$name";
	$namewml="<b>$name</b>";
	$nameincwml=$name;
	} else {
	$namehtml="<input type=\"text\" name=\"name\" cols=\"50\" value=\"$name\"/>\n";
	$namewml="<input name=\"name\" title=\"Имя\" type=\"text\" value=\"$name\"/>";
	$nameincwml='<dol>(name)';
	}
	
if ($t!=FALSE) {
	$r = mysql_query("SELECT * FROM {$table}{$f}_topiks WHERE ID=$t");
	$a=mysql_fetch_array($r);
	$TopikTitle=$a['Title'];
	$topik="RE:$TopikTitle";
	$topikhtml="<input type=\"hidden\" name=\"topik\" value=\"$name\"/>$topik";
	$topikwml="<b>$topik</b>";
	$topikincwml=$topik;
	$inchtml.="<input type=\"hidden\" name=\"t\" value=\"$t\"/>\n";
	$incwml.="<postfield name=\"t\" value=\"$t\"/>";
} else {
	$topikhtml="<input type=\"text\" name=\"topik\" cols=\"50\" value=\"$topik\"/>\n";
	$topikwml="<input name=\"topik\" title=\"Имя\" type=\"text\" value=\"$topik\"/>";
	$topikincwml='<dol>(topik)';
	}

if ($sid!=FALSE) {$inchtml.="<input type=\"hidden\" name=\"sid\" value=\"$sid\"/>\n";}
if ($w!=FALSE) {$inchtml.="<input type=\"hidden\" name=\"w\" value=\"$w\"/>\n";}
if ($show!=FALSE) {$inchtml.="<input type=\"hidden\" name=\"show\" value=\"all\"/>\n";}

if ($sid!=FALSE) {$incwml.="<postfield name=\"sid\" value=\"$sid\"/>";}
if ($w!=FALSE) {$incwml.="<postfield name=\"w\" value=\"$w\"/>";}
if ($show!=FALSE) {$incwml.="<postfield name=\"show\" value=\"all\"/>";}

if ($mode=='insertsmile') {
	$body.="s:$url.gif::";
}
if ($mode=='insertimage') {
	$body.="i:$url::";
}

$formhtml=<<<END
<b>Добавить сообщение в $ForumTitle</b></td></tr>
<tr><td bgcolor="#79EBFB">
<form action="newtopik.php" method="post">
$inchtml<input type="hidden" name="f" value="$f"/>
<input type="hidden" name="p" value="$p"/>
Имя:&nbsp;&nbsp;&nbsp;&nbsp;$namehtml</td></tr>
<tr><td bgcolor="#79EBFB">
Тема:&nbsp;&nbsp;&nbsp;$topikhtml</td></tr>
<tr><td bgcolor="#79EBFB">
Сообщение:<br/>
<textarea name="body" cols="57" rows="10">$body</textarea>
</td></tr>
<tr><td bgcolor="#79EBFB">
<p align="center">
<input type="submit" name="mode" value="Вставить смайл"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" name="mode" value="Вставить картинку"/></p>
</td></tr>
<tr><td bgcolor="#79EBFB">
<p align="center">
<input type="submit" name="mode" value="Отправить"/></p>
</form>
END;

$formwml=<<<END
Имя: $namewml<br/>
Тема: $topikwml<br/>
Сообщение: <input name="body" title="Текст" type="text" value="$body"/><br/>
<anchor>Вставить смайл<go href="newtopik.php" accept-charset="UTF-8" method="post">
$incwml<postfield name="f" value="$f"/>
<postfield name="p" value="$p"/>
<postfield name="name" value="<dol>(name)"/>
<postfield name="topik" value="<dol>(topik)"/>
<postfield name="body" value="<dol>(body)"/>
<postfield name="mode" value="Вставить смайл"/>
</go></anchor><br/>
<anchor>Вставить картинку<go href="newtopik.php" accept-charset="UTF-8" method="post">
$incwml<postfield name="f" value="$f"/>
<postfield name="p" value="$p"/>
<postfield name="name" value="$nameincwml"/>
<postfield name="topik" value="$topikincwml"/>
<postfield name="body" value="<dol>(body)"/>
<postfield name="mode" value="Вставить картинку"/>
</go></anchor><br/>
<anchor>Отправить<go href="newtopik.php" accept-charset="UTF-8" method="post">
$incwml<postfield name="f" value="$f"/>
<postfield name="p" value="$p"/>
<postfield name="name" value="<dol>(name)"/>
<postfield name="topik" value="<dol>(topik)"/>
<postfield name="body" value="<dol>(body)"/>
<postfield name="mode" value="Отправить"/>
</go></anchor><br/>
END;

$smilehtml=<<<END
<form action="newtopik.php" method="post">
$inchtml<input type="hidden" name="f" value="$f"/>
<input type="hidden" name="p" value="$p"/>
<input type="hidden" name="name" value="$name"/>
<input type="hidden" name="topik" value="$topik"/>
<input type="hidden" name="body" value="$body"/></td></tr>
<tr><td bgcolor="#79EBFB">
N:&nbsp;&nbsp;&nbsp;<input type="text" name="url" cols="10"/>&nbsp;&nbsp;&nbsp;
<input type="hidden" name="mode" value="insertsmile"/>
<input type="submit" name="submit" value="Вставить"/>
</form>
END;

$smilewml=<<<END
N: <input name="url" title="N" type="text"/><br/>
<anchor>Вставить<go href="newtopik.php" accept-charset="UTF-8" method="post">
$incwml<postfield name="f" value="$f"/>
<postfield name="p" value="$p"/>
<postfield name="name" value="$name"/>
<postfield name="topik" value="$topik"/>
<postfield name="body" value="$body"/>
<postfield name="url" value="<dol>(url)"/>
<postfield name="mode" value="insertsmile"/>
</go></anchor><br/>
END;

$imagehtml=<<<END
<form action="newtopik.php" method="post">
$inchtml<input type="hidden" name="f" value="$f"/>
<input type="hidden" name="p" value="$p"/>
<input type="hidden" name="name" value="$name"/>
<input type="hidden" name="topik" value="$topik"/>
<input type="hidden" name="body" value="$body"/>
http://<input type="text" name="url" cols="55"/></td></tr>
<tr><td bgcolor="#79EBFB">
<input type="hidden" name="mode" value="insertimage"/>
<p align="center">
<input type="submit" name="submit" value="Вставить"/></p>
</form>
END;

$imagewml=<<<END
http://<input name="url" title="N" type="text"/><br/>
<anchor>Вставить<go href="newtopik.php" accept-charset="UTF-8" method="post">
$incwml<postfield name="f" value="$f"/>
<postfield name="p" value="$p"/>
<postfield name="name" value="$name"/>
<postfield name="topik" value="$topik"/>
<postfield name="body" value="$body"/>
<postfield name="url" value="<dol>(url)"/>
<postfield name="mode" value="insertimage"/>
</go></anchor><br/>
END;


if (($mode==FALSE) || ($mode=='insertsmile') || ($mode=='insertimage')) {
	if (($foruminfo['RegisterOnly']==0) && ($sid==FALSE)) {displaytext('Ошибка', $Banner, "Необходимо <a href=\"forumreg.php?f=$f$isid\">зарегестрироваться</a>, чтобы писать в этом форуме.", $back, $w);exit;}
	if ($wmode=='html') {
		displayHTML('Новая тема', $Banner, $formhtml, $back);
	} else {
		displayWML('Новая тема', $Banner, $formwml, $back);
	}
}
if ($mode=='Вставить смайл') {
	for ($i=1; $i<=38; $i+=2) {
	$s=$i+1;
		$smiles.="<img src=\"${forumdir}smile/$i.gif\" alt=\"s\"/>&nbsp;$i&nbsp;&nbsp;&nbsp;&nbsp;" .
		"&nbsp;<img src=\"${forumdir}smile/$s.gif\" alt=\"s\"/>&nbsp;$s<br/>\n";
	}
	if ($wmode=='html') {
		displayHTML('Вставить смайл', $Banner, $smiles . $smilehtml, $back);
	} else {
		displayWML('Вставить смайл', $Banner, $smiles . $smilewml, $back);
	}
}
if ($mode=='Вставить картинку') {
	if ($wmode=='html') {
		displayHTML('Вставить картинку', $Banner, $imagehtml, $back);
	} else {
		displayWML('Вставить картинку', $Banner, $imagewml, $back);
	}
}
if ($mode=='Отправить') {
	if (($name=="") || ($name==" ")) {displaytext('Ошибка', $Banner, 'Что, нет имени?', $back, $w);exit;}
	if (($topik=="") || ($body=="")) {displaytext('Ошибка', $Banner, 'Что, нечего писать?', $back, $w);exit;}
	if (strstr($name, '  ') != FALSE) {displaytext('Ошибка', $Banner, 'Назовись попроще!', $back, $w);exit;}
	$UserAgent = $_SERVER["HTTP_USER_AGENT"];
	$IP = $_SERVER ["REMOTE_ADDR"];
	$date = date('j.m G:i');
	$k = mysql_query("SELECT * FROM {$table}{$f}_bannick WHERE Nick='$name'");
	if (mysql_numrows($k)!=0) {
		header("Location: ban.php?nick=$name");
		exit;
	}
	$k = mysql_query("SELECT * FROM {$table}{$f}_banip WHERE IP='$IP' AND UserAgent='$UserAgent'");
	if (mysql_numrows($k)!=0) {
		header("Location: ban.php?mode=ip");
		exit;
	}
	$k = mysql_query("SELECT * FROM {$table}{$f}_banip WHERE IP='$IP' AND UserAgent='all'");
	if (mysql_numrows($k)!=0) {
		header("Location: ban.php?mode=ip");
		exit;
	}
	$name = ereg_replace('<','&lt;',$name);
	$name = ereg_replace('>','&gt;',$name);
	$name = ereg_replace("'","&#39;",$name);
	$topik = ereg_replace('<','&lt;',$topik);
	$topik = ereg_replace('>','&gt;',$topik);
	$topik = ereg_replace("'","&#39;",$topik);
	
	$body = ereg_replace('<','&lt;',$body);
	$body = ereg_replace('>','&gt;',$body);
	$body = ereg_replace("\n",'<br/>',$body);
	$body = ereg_replace("'","&#39;",$body);
	$body = ereg_replace('s:',"<img src=\"${forumdir}smile/", $body);
	$body = ereg_replace('i:','<img src="<http>', $body);
	$body = ereg_replace('::','" alt="i"/>', $body);
	
	while(strstr($body, 'http://')!=FALSE) {
	
		$nc=strpos($body, 'http://');
		$furl=substr($body, $nc);
		$curl=substr($body, $nc, strpos($furl, ' '));
		if ($curl=="") {$curl=substr($body, $nc);};
		$nurl = ereg_replace('http://','<http>', $curl);
		$body = ereg_replace($curl,"<a href=\"$nurl\">$nurl</a>", $body);
	}
	$body = ereg_replace('<http>','http://', $body);
	
	$k = mysql_query("SELECT * FROM {$table}{$f}_users WHERE Nick='$name'");
	$b = mysql_fetch_array($k);
	if ((mysql_numrows($k)==0) || ($b['FSID']==$sid)) {
		if (($foruminfo['RegisterOnly']==0) && ($sid==FALSE)) {displaytext('Ошибка', $Banner, "Необходимо <a href=\"forumreg.php?f=$f$isid\">зарегестрироваться</a>, чтобы писать в этом форуме.", $back, $w);exit;}
		if ($t!=FALSE) {
			$r = mysql_query("SELECT * FROM {$table}{$f}_topiks WHERE ID=$t");
			if (mysql_numrows($r)==0) {
				displaytext('Ошибка', $Banner, 'Тема закрыта или не сущесвует', $back, $w);
				exit;
			}
			$a = mysql_fetch_array($r);
			$ID = $a['ID'];
			mysql_query("INSERT INTO {$table}{$f}_messages (`ID` ,`Cop` ,`Body` ,`ForumID` ,`TopikID` ,`Date` ,`Visible` ,`IP` ,`UserAgent` )VALUES (NULL , '$name', '$body', $p, $ID, '$date', 0, '$IP', '$UserAgent')");
		} else {
			mysql_query("INSERT INTO {$table}{$f}_topiks (`ID` ,`Cop` ,`Title` ,`ForumID` ,`Date` ,`Visible` ,`Enabled` )VALUES (NULL , '$name', '$topik', $p, '$date', 0, 0)");
		
			$r = mysql_query("SELECT * FROM {$table}{$f}_topiks WHERE Title='$topik' AND Cop='$name'AND Date='$date'");
			$a = mysql_fetch_array($r);
			$ID = $a['ID'];
		
			mysql_query("INSERT INTO {$table}{$f}_messages (`ID` ,`Cop` ,`Body` ,`ForumID` ,`TopikID` ,`Date` ,`Visible` ,`IP` ,`UserAgent` )VALUES (NULL , '$name', '$body', $p, $ID, '$date', 0, '$IP', '$UserAgent')");
		}
		header("Location: showtopik.php?f=$f&p=$p&mes=1000&t=$ID$isid");
	} else {
		displaytext('Ошибка', $Banner, 'Этот nick уже занят. Авторизируйтесь, если Вы владелец этого nicka', $back, $w);
		exit;
	}
}
mysql_close($lnk);
?>