'Доступ закрыт',1=>'Только чтение',2=>'Разрешено добавлять ответы',3=>'Разрешено создовать топики',4=>'Разрешено добавлять ответы и создавать топики');
public function paginator($t,$pagers=0){
if(isset($_GET['search'])) {
$where = '( `text` LIKE "%'.mysql_real_escape_string($_GET['search']).'%" OR `title` LIKE "%'.mysql_real_escape_string($_GET['search']).'%" OR `login` LIKE "%'.mysql_real_escape_string($_GET['search']).'%" ) AND `topic` < "0" AND `delete` = "0"' ;
$pre_url='search='.htmlspecialchars($_GET['search'],NULL,'cp1251').'&read='.$pagers.'&';
$idpaginator=$pagers;
}elseif($pagers!=0){
$where = '`topic` = "'.$pagers.'" AND `delete` = "0"' ;
$pre_url='read='.$pagers.'&';
$idpaginator=$pagers;
}elseif($t==1){
$where = '`topic` < "0" AND `fid` = "'.$this->r.'" AND `delete` = "0"';
$pre_url='r='.$this->r.'&';
$idpaginator=$this->r;
}elseif($t==2){
$where = '`topic` = "'.$this->see['id'].'" AND `delete` = "0"' ;
$pre_url='read='.$this->see['id'].'&';
$idpaginator=$this->see['id'];
}
$q="SELECT count(*) FROM forum_msg WHERE ".$where;
$res=mysql_query($q);
$row=mysql_fetch_row($res);
$total_rows=$row[0];
$num_pages=ceil($total_rows/20);
$plist='';
for($i=1;$i<=$num_pages;$i++) {
if( (!isset($_GET['page']) || round((int)$_GET['page']) < 1) && $i == 1 && ($t!=2 || isset($_GET['read']))) {
$plist.=''.$i."";
}elseif( ( $_GET['page']!=$i || $pagers!=0 ) ){
$plist.=''.$i."";
}else{
$plist.=''.$i.'';
}
}
if($plist == '') {
$plist = '1';
}
return ''.$plist.'';
}
public function testAnswer($text) {
$r = str_replace('[/?]','[?]',$text);
$r = explode('[?]',$r);
$i = 1;
$pr_us_all = 0;
while($i != -1) {
if(isset($r[$i])) {
$ra = explode('[:]',$r[$i]);
$j = 0;
if(isset($this->user['id'])) {
$yg = mysql_fetch_array(mysql_query('SELECT * FROM `forum_answers` WHERE `msg_id` = "'.$this->see['id'].'" AND `q_id` = "'.$i.'" AND `uid` = "'.$this->user['id'].'" AND `delete` = "0" LIMIT 1'));
if(!isset($yg['id'],$_GET['q_now'],$_GET['answer_now']) && $_GET['q_now'] == $i) {
$_GET['answer_now'] = round((int)$_GET['answer_now']);
$_GET['q_now'] = round((int)$_GET['q_now']);
if(isset($ra[$_GET['answer_now']])) {
mysql_query('INSERT INTO `forum_answers` (`uid`,`msg_id`,`q_id`,`answer`,`time`,`city`) VALUES
("'.$this->user['id'].'","'.$this->see['id'].'","'.mysql_real_escape_string($_GET['q_now']).'","'.mysql_real_escape_string($_GET['answer_now']).'",
"'.time().'","'.$this->user['city'].'")');
die('');
}
}
}
$pr_all = mysql_fetch_array(mysql_query('SELECT COUNT(`id`) FROM `forum_answers` WHERE `msg_id` = "'.$this->see['id'].'" AND `q_id` = "'.$i.'" AND `delete` = "0" LIMIT 1'));
$pr_all = $pr_all[0];
$pr_us_all += $pr_all;
$pr_lst = 0;
$pr_asw = 0;
while($j != -1) {
if(isset($ra[$j]) && $ra[$j] != '') {
if($j > 0) {
$prc = mysql_fetch_array(mysql_query('SELECT COUNT(`id`) FROM `forum_answers` WHERE `msg_id` = "'.$this->see['id'].'" AND `answer` = "'.$j.'" AND `q_id` = "'.$i.'" AND `delete` = "0" LIMIT 1'));
$prc = 0+$prc[0];
$pr_asw += $prc;
if( $pr_asw == $pr_all ) {
$prc = 100-$pr_lst;
$pr_lst += $prc;
if($prc > 0) {
$prc = ''.$prc.'';
}
}else{
$prc = floor($prc/$pr_all*100);
if($prc > 0) {
$pr_lst += $prc;
$prc = ''.$prc.'';
}
}
if(isset($this->user['id'])) {
if(isset($yg['id'])) {
if($yg['answer'] == $j) {
$zm = '
• '.$ra[$j].' | - '.$prc.'% (Ваш голос) |
';
}else{
$zm = '• '.$ra[$j].' | - '.$prc.'% |
';
}
}else{
$zm = '• '.$ra[$j].' | - '.$prc.'% |
';
}
}else{
$zm = '• '.$ra[$j].' | - '.$prc.'% |
';
}
$text = str_replace('[:]'.$ra[$j],$zm,$text);
}else{
$zm = ''.$ra[$j].'
';
$text = str_replace(str_replace('
','',$ra[$j]),$zm,$text);
}
}else{
$j = -2;
}
$j++;
}
$text = str_replace('[?]','',$text);
}else{
$i = -2;
}
$i++;
}
$text = str_replace('[/?]','
Всего проголосовало людей '.$pr_us_all.'',$text);
return $text;
}
public function startForum()
{
//Выделяем пользователя
$ufr = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `login` = "'.mysql_real_escape_string($_COOKIE['login']).'" AND `pass` = "'.mysql_real_escape_string($_COOKIE['pass']).'" AND `banned` = "0" LIMIT 1'));
if(!isset($ufr['id']) || $ufr['banned']>0)
{
unset($u);
}else{
$ufr['sl'] = ''.$ufr['login'].' ['.$ufr['level'].']';
$this->user = $ufr;
}
//Выделяем раздел который просматривает пользователь
if(isset($_GET['read']))
{
//читаем сообщение
$see = mysql_fetch_array(mysql_query('SELECT * FROM `forum_msg` WHERE `id` = "'.mysql_real_escape_string($_GET['read']).'" AND `delete` = "0" LIMIT 1'));
if(!isset($see['id']) || ($see['fid']==65 && $this->user['admin']==0 && ($this->user['align']<=1 || $this->user['align']>=2)) || ($see['fid']==75 && $this->user['admin']==0 && ($this->user['align']<=3 || $this->user['align']>=4)))
{
$this->r = -2;
$this->error = 'Топик форума не найден.';
}else{
$this->r = -1;
$see['goodAdd'] = 1;
if($see['nocom']>0)
{
if($this->user['align']>1 && $this->user['align']<2)
{
if($see['nocom']==2 || $see['nocom']==4)
{
$see['goodAdd'] = 0;
}
}
if($this->user['align']>3 && $this->user['align']<4)
{
if($see['nocom']==2 || $see['nocom']==3)
{
$see['goodAdd'] = 0;
}
}
if($this->user['admin']>0)
{
$see['goodAdd'] = 1;
}
}
$this->see = $see;
$this->fm = mysql_fetch_array(mysql_query('SELECT * FROM `forum_menu` WHERE `id` = "'.mysql_real_escape_string($see['fid']).'" LIMIT 1'));
}
}else{
if(isset($_GET['r']))
{
$this->r = (int)$_GET['r'];
}else{
$this->r = 1;
}
$fm = mysql_fetch_array(mysql_query('SELECT * FROM `forum_menu` WHERE `id` = "'.mysql_real_escape_string($this->r).'" LIMIT 1'));
if(!isset($fm['id']) || ($fm['id']==65 && $this->user['admin']==0 && ($this->user['align']<=1 || $this->user['align']>=2)) || ($fm['id']==75 && $this->user['admin']==0 && ($this->user['align']<=3 || $this->user['align']>=4)) )
{
$this->r = -2;
$this->fm = false;
$this->error = 'Раздел форума не найден.';
}else{
$this->fm = $fm;
}
}
$this->genMenu();
$this->lst = mysql_fetch_array(mysql_query('SELECT `id`,`time` FROM `forum_msg` WHERE `uid` = "'.$this->user['id'].'" AND `delete` = "0" ORDER BY `time` DESC LIMIT 1'));
//Проверяем форум на доступность
if($this->gd[$this->fm['id']]==0 && $ufr['admin']==0)
{
//просмотр закрыт
$this->r = -2;
$this->error = 'Вы не можете читать данную конференцию.';
}elseif($this->fm['only_admin']==1 && $this->user['admin']==0)
{
//просмотр закрыт
$this->r = -2;
$this->error = 'Вы не можете читать данную конференцию.';
}
}
public function seeTopic()
{
global $c;
$fd_limit=20;
if(isset($_GET['page'])){
$start=$_GET['page']*$fd_limit-$fd_limit;
}else{
$start=0;
//echo 'SELECT * FROM `forum_msg` WHERE `topic` < "0" AND `fid` = "'.$this->r.'" AND `delete` = "0" ORDER BY `id` DESC LIMIT '.$start.','.$fd_limit;
}
if($this->see['fid']==65 && $this->user['admin']==0 && ($this->user['align']<=1 || $this->user['align']>=2)){
}elseif($this->see['fid']==75 && $this->user['admin']==0 && ($this->user['align']<=3 || $this->user['align']>=4)){
}elseif(isset($this->see['id']))
{
//Выводим заголовок
echo $this->genuser($this->see['uid'],$this->see['login'],$this->see['level'],$this->see['align'],$this->see['clan'],$this->see['invis'],$this->see['city'],$this->see['cityreg']);
if($this->user['admin']>0 || ($this->user['align'] > 1 && $this->user['align'] < 2) || ($this->user['align'] > 3 && $this->user['align'] < 4))
{
echo ' ';
if($this->user['admin']>0) {
echo '
';
}
echo '
';
echo '
';
echo '
';
}
echo ' ('.date('d.m.Y H:i',$this->see['time']).')
';
$this->see['text'] = str_replace("\n", "
", $this->see['text']);
$this->see['text'] = $this->testAnswer($this->see['text']);
$this->see['text'] = $this->parse_bb_code($this->see['text']);
/*
if($this->see['id'] ==1608) {
$uslist = ''; $xu1 = 0;
$su1 = mysql_query('SELECT `i`.`uid`,`u`.`login`,`u`.`level`,`u`.`online`,`u`.`clan`,`u`.`align` FROM `items_users` AS `i` LEFT JOIN `users` AS `u` ON `i`.`uid` = `u`.`id` WHERE `i`.`item_id` = "2852" LIMIT 25');
$usrs = array();
while($pu1 = mysql_fetch_array($su1)) {
if(!isset($usrs[$pu1['uid']])) {
$xu1++;
$usrs[$pu1['uid']] = $xu1;
$uslist .= $xu1.'. '.$pu1['login'].'['.$pu1['level'].']';
if($pu1['online']>time()-520) {
$uslist .= ' online';
}
$uslist .= '
';
}
}
$this->see['text'] = str_replace("{users-list}", 'Список участников ['.$xu1.'/25]:
'.$uslist.'
', $this->see['text']);
unset($uslist,$pu1,$su1,$xu1,$usrs);
}*/
$rtrn = '';
$rtrn .= 'see['fixed'] > 0) {
$rtrn .= ' class="fixed_topik"';
}
$rtrn .= ' style="margin-left:31px;">';
if($this->see['clear']==0){
$rtrn .= $this->see['text'];
}else{
if($this->user['admin'] > 0) {
$rtrn .= '
'.$this->see['text'].'
';
}
$rtrn .= '
Запись была удалена';
if($this->user['del_admin'] == 0) {
$rtrn .= ', '.$this->see['del_login'].'';
}
$rtrn .= ' ';
}
//Записи модераторов и ангелов
$sp1 = mysql_query('SELECT * FROM `forum_msg_mod` WHERE `msg_id` = "'.$this->see['id'].'"');
while($pl1 = mysql_fetch_array($sp1)) {
$rtrn .= '
';
if($pl1['from_admin'] == 1) {
$pl1['login'] = '<Администрация>';
$pl1['city'] = '';
$pl1['cityreg'] = '';
$pl1['clan'] = '';
$pl1['level'] = '??';
$pl1['uid'] = 0;
}
$rtrn .= $this->genuser($pl1['uid'],$pl1['login'],$pl1['level'],$pl1['align'],$pl1['clan'],$pl1['invis'],$pl1['city'],$pl1['cityreg']);
$rtrn .= ' ('.date('d.m.y H:i',$pl1['time']).'): ';
$pl1['text'] = str_replace("\n", "
", $pl1['text']);
$rtrn .= $this->link_it($pl1['text']).'
';
}
$rtrn .= '
';
//Выводим комментарии
$sp = mysql_query('SELECT * FROM `forum_msg` WHERE `topic` = "'.$this->see['id'].'" AND `delete` = "0" ORDER BY `time` ASC LIMIT '.$start.','.$fd_limit );
while($pl = mysql_fetch_array($sp))
{
$rtrn .= $this->genuser($pl['uid'],$pl['login'],$pl['level'],$pl['align'],$pl['clan'],$pl['invis'],$pl['city'],$pl['cityreg']);
if($this->user['admin']>0 || ($this->user['align'] > 1 && $this->user['align'] < 2) || ($this->user['align'] > 3 && $this->user['align'] < 4))
{
$rtrn .= ' ';
if($this->user['admin']>0) {
$rtrn .= '
';
}
$rtrn .= '
';
$rtrn .= '
';
$rtrn .= '
';
}
$rtrn .= ' ('.date('d.m.Y H:i',$pl['time']).')
';
$pl['text'] = $this->parse_bb_code($pl['text']);
$pl['text'] = str_replace("\n", "
", $pl['text']);
if($pl['clear']==0){
$rtrn .= ''.$pl['text'].'
';
}else{
if($this->user['admin'] > 0) {
$rtrn .= ''.$pl['text'].'
';
}
$rtrn .= 'Комментарий удален';
if($this->user['del_admin'] == 0) {
$rtrn .= ', '.$pl['del_login'].'';
}
$rtrn .= ' ';
}
//Записи модераторов и ангелов
$sp1 = mysql_query('SELECT * FROM `forum_msg_mod` WHERE `msg_id` = "'.$pl['id'].'"');
while($pl1 = mysql_fetch_array($sp1)) {
$rtrn .= '';
if($pl1['from_admin'] == 1) {
$pl1['login'] = '<Администрация>';
$pl1['city'] = '';
$pl1['cityreg'] = '';
$pl1['clan'] = '';
$pl1['level'] = '??';
$pl1['uid'] = 0;
}
$rtrn .= $this->genuser($pl1['uid'],$pl1['login'],$pl1['level'],$pl1['align'],$pl1['clan'],$pl1['invis'],$pl1['city'],$pl1['cityreg']);
$rtrn .= ' ('.date('d.m.y H:i',$pl1['time']).'): ';
$pl1['text'] = str_replace("\n", "
", $pl1['text']);
$rtrn .= $this->link_it($pl1['text']).'
';
}
$rtrn .= '';
}
echo $rtrn;
}
}
public function link_it($text) {
$text= preg_replace("/(^|[\n ])([\w]*?)((ht|f)tp(s)?:\/\/[\w]+[^ \,\"\n\r\t<]*)/is", "$1$2$3", $text);
$text= preg_replace("/(^|[\n ])([\w]*?)((www|ftp)\.[^ \,\"\t\n\r<]*)/is", "$1$2$3", $text);
$text= preg_replace("/(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+)+)/i", "$1$2@$3", $text);
return($text);
}
public function genuser($id,$login,$level,$align,$clan,$invis,$city,$cityreg)
{
global $c,$code;
$ufr = '';
if($align>0)
{
$u .= '';
}
if($clan>0)
{
$clan = mysql_fetch_array(mysql_query('SELECT * FROM `clan` WHERE `id` = "'.((int)$clan).'" LIMIT 1'));
if(isset($clan['id']))
{
$u .= '';
}
}
if($login == '<Администрация>')
{
$login = 'Администрация';
}
$u .= ''.$login.' ['.$level.']';
if($city!='')
{
$ufr = ' '.$u;
}
return $u;
}
public function pravasee()
{
$prava = 1; //можно добавлять и просматривать
if($this->see['fid']==65 && $this->user['admin']==0 && ($this->user['align']<=1 || $this->user['align']>=2))
{
//топик ОС
$prava = 0;
}elseif($this->see['fid']==75 && $this->user['admin']==0 && ($this->user['align']<=3 || $this->user['align']>=4))
{
//топик Армады
$prava = 0;
}elseif(isset($this->see['id']) && $this->see['nocom']==3 && $this->user['admin']==0 && ($this->user['align']<=3 || $this->user['align']>=4))
{
$prava = 0;
}elseif(isset($this->see['id']) && $this->see['nocom']==2 && $this->user['admin']==0 && ($this->user['align']<=1 || $this->user['align']>=2))
{
$prava = 0;
}elseif(isset($this->see['id']) && $this->see['nocom']==1 && $this->user['admin']==0)
{
$prava = 0;
}elseif($this->user['level']<1)
{
$prava = 0;
}elseif($this->lst['time']>time()-60)
{
$prava = 0;
}
return $prava;
}
public function admintopmsg($read,$id,$text,$color,$adm) {
$msg = mysql_fetch_array(mysql_query('SELECT `id` FROM `forum_msg` WHERE `id` = "'.mysql_real_escape_string($id).'" LIMIT 1'));
if(!isset($msg['id'])) {
$this->error = 'Сообщение не найдено';
}elseif(trim($text,' ')=='' || iconv_strlen(trim($text,' '))<2)
{
$this->error = 'Минимальная длина сообщения должна быть не менее 2-х символов';
}elseif($this->user['molch2']>time())
{
$this->error = 'Вы не можете писать сообщения и создавать топики на форуме, на вас наложено заклятие молчания';
}elseif(isset($this->see['id']) && $this->see['nocom']==3 && $this->user['admin']==0 && ($this->user['align']<=3 || $this->user['align']>=4))
{
$this->error = 'В этом топике запрещено оставлять ответы';
}elseif(isset($this->see['id']) && $this->see['nocom']==2 && $this->user['admin']==0 && ($this->user['align']<=1 || $this->user['align']>=2))
{
$this->error = 'В этом топике запрещено оставлять ответы';
}elseif(isset($this->see['id']) && $this->see['nocom']==1 && $this->user['admin']==0)
{
$this->error = 'В этом топике запрещено оставлять ответы';
}elseif($this->user['level'] < 8)
{
$this->error = 'Вы не можете писать сообщения и создавать топики на форуме, это возможно с 8-го уровня';
}else{
mysql_query('INSERT INTO `forum_msg_mod` (`uid`,`login`,`align`,`level`,`admin`,`clan`,`time`,`text`,`msg_id`,`delete`,`color`,`city`,`cityreg`,`from_admin`) VALUES
("'.$this->user['id'].'","'.$this->user['login'].'","'.$this->user['align'].'","'.$this->user['level'].'","'.$this->user['admin'].'","'.$this->user['clan'].'",
"'.time().'","'.mysql_real_escape_string($text).'","'.mysql_real_escape_string($msg['id']).'","0","red","'.$this->user['city'].'","'.$this->user['cityreg'].'",
"'.mysql_real_escape_string(round((int)$adm)).'") ');
if(!isset($this->see['id'])) {
header('location: ?r='.round((int)$_GET['r']).'&page='.round((int)$_GET['page']));
}else{
header('location: ?read='.$this->see['id'].'&page='.round((int)$_GET['page']));
}
}
}
public function parse_bb_code($text) {
$text = preg_replace('/\[(\/?)(b|i|u|s)\s*\]/', "<$1$2>", $text);
$text = preg_replace('/\[code\]/', '', $text);
$text = preg_replace('/\[\/code\]/', '
', $text);
$text = preg_replace('/\[(\/?)quote\]/', "<$1blockquote>", $text);
$text = preg_replace('/\[(\/?)quote(\s*=\s*([\'"]?)([^\'"]+)\3\s*)?\]/', "<$1blockquote>Цитата $4:
", $text);
//$text = preg_replace('/\[url\](?:https:\/\/)?([a-z0-9-.]+\.\w{2,4})\[\/url\]/', "$1", $text);
$text = preg_replace('/\[url=(.+?)\](.+?)\[\/url\]/', "$2", $text);
$text = preg_replace('/\[url\s?=\s?([\'"]?)(?:https:\/\/)?([a-z0-9-.]+\.\w{2,4})\1\](.*?)\[\/url\]/', "$3", $text);
$text = preg_replace('/\[img\s*\]([^\]\[]+)\[\/img\]/', "", $text);
$text = preg_replace('/\[img\s*=\s*([\'"]?)([^\'"\]]+)\1\]/', "", $text);
$text = $this->close_dangling_tags($text);
return $text;
}
// $s - строка, в которой необходимо закрыть теги
// $tags - список тегов для закрытия через символ | (b|u|i)
public function close_dangling_tags($html){
#put all opened tags into an array
preg_match_all("#<([a-z]+)( .*)?(?!/)>#iU",$html,$result);
$openedtags=$result[1];
#put all closed tags into an array
preg_match_all("#([a-z]+)>#iU",$html,$result);
$closedtags=$result[1];
$len_opened = count($openedtags);
# all tags are closed
if(count($closedtags) == $len_opened){
return $html;
}
$openedtags = array_reverse($openedtags);
# close tags
for($i=0;$i < $len_opened;$i++) {
if (!in_array($openedtags[$i],$closedtags)){
if( $openedtags[$i] != 'br' ) {
$html .= ''.$openedtags[$i].'>';
}
} else {
unset($closedtags[array_search($openedtags[$i],$closedtags)]);
}
}
return $html;
}
public function addnewtop($title,$text,$ico,$time,$login,$uid,$fid,$topic)
{
if(trim($text,' ')=='' || iconv_strlen(trim($text,' '))<5)
{
$this->error = 'Минимальная длина сообщения должна быть не менее 5-ти символов';
}elseif($this->user['molch2']>time())
{
$this->error = 'Вы не можете писать сообщения и создавать топики на форуме, на вас наложено заклятие молчания';
}elseif((trim($title,' ')=='' || iconv_strlen(trim($title,' '))<5) && $topic == -1)
{
$this->error = 'Минимальная длина заголовка должна быть не менее 5-ти символов';
}elseif(isset($this->see['id']) && $this->see['nocom']==3 && $this->user['admin']==0 && ($this->user['align']<=3 || $this->user['align']>=4))
{
$this->error = 'В этом топике запрещено оставлять ответы';
}elseif(isset($this->see['id']) && $this->see['nocom']==2 && $this->user['admin']==0 && ($this->user['align']<=1 || $this->user['align']>=2))
{
$this->error = 'В этом топике запрещено оставлять ответы';
}elseif(isset($this->see['id']) && $this->see['nocom']==1 && $this->user['admin']==0)
{
$this->error = 'В этом топике запрещено оставлять ответы';
}elseif($this->user['level'] < 2)
{
$this->error = 'Общение на форуме доступно с 2-го уровня';
}elseif($this->gd[$fid]>0 && $this->lst['time']