<?php
if(isset($_v[$_lk['pt']]) && file_exists($_s['ids_dir'].'/'.$_v[$_lk['pt']]))
{
		$_v['nick'] = (@trim($_v['nick']) ? $_v['nick'] : $_l['guest']);

		if ($_s['comments']) {
		if (eregi(trim($_s['authorname']),trim($_v['nick'])) && !isset($_s['name']) && !is_admin()) {
		e($_l['ncikden']);
		redirect(plink($_v[$_lk['pt']]));
		} else {
		if (@trim($_v['text']))
		{
			$text = $rt = substr($_v['text'], 0, $_s['maxcmt']);
			$nick = substr($_v['nick'], 0, $_s['maxnick']);

			if(!is_admin()) $text = htmlspecialchars($text, ENT_QUOTES);
			if($_s['bbcomm'] && !is_admin()) $text = bbcode($text);

			$a=0;
			$text = str_replace("\n", '<br>', $text);
			$nick = str_replace('>', '&gt;', $nick);
			$nick = str_replace('<', '&lt;', $nick);
			$nick = str_replace('¦¦', '', $nick);
			$ip=getenv('REMOTE_ADDR');
			if(is_admin()) $a=1;
			$cmnt_date = time();

			$_v['www'] = @trim($_v['www'])!='www' ? @trim($_v['www']) : '';
			$_v['mail'] = @trim($_v['mail'])!='e@mail' ? @trim($_v['mail']) : '';

			$_v['www']=@str_replace('http://','',$_v['www']);
 			if(@preg_match('#^[-a-z0-9]+(\.[-a-z0-9]+)*(\.[a-z]+)(|\/|\/([a-z0-9-_\(\)!\&\#\.\/\~]+(\.[a-z0-9\_\-]+)?(\?([a-zа-я0-9-_\%]*|([a-z0-9_-]+=[a-zа-я0-9-_\%\&]*)+))?(\#[a-z0-9]*)?)?)$#i', $w=strtolower(trim($_v['www'])))) $_v['cwww']=$w;
 			if(@trim($_v['mail']) && ereg("^[a-z0-9]+@[a-z0-9]+\.[a-z0-9]{2,4}$", $m=strtolower(trim($_v['mail'])))) $_v['cmail']=$m;

			if ($_s['email']!="") {
				post_info($_v[$_lk['pt']]);
				if(empty($post['title'])) $subj = $_s['blogname'];
				else $subj = $_l['comment'].' "'.$post['title'].'"';
				$mailtpl=file_get_contents($_s['pages_dir'].'/n.tpl.comm2mail');
				@$mailtpl=str_replace('%post%',$post['title'],$mailtpl);
				@$mailtpl=str_replace('%name%',$nick,$mailtpl);
				@$mailtpl=str_replace('%text%',$rt,$mailtpl);
				@$mailtpl=str_replace('%link%',plink($_v[$_lk['pt']]),$mailtpl);
				@$mailtpl=str_replace('%blog%',$_s['title'],$mailtpl);
				@$mailtpl=str_replace('%mail%',$_v['cmail'],$mailtpl);
				@$mailtpl=str_replace('%www%',$_v['cwww'],$mailtpl);
				@$mailtpl=str_replace('%ip%',$ip,$mailtpl);
				@$mailtpl=str_replace('%date%',date($_s['datecmt'], $cmnt_date+$_s['time_offset']),$mailtpl);
				mail($_s['email'], $subj, $mailtpl, 'Content-Type: text/plain; charset='.$_s['enc']."\nFrom: ".$nick."<noreply-$_s[email]>\r\n");
				}
				fsave($_s['comm_dir'].'/'.$_v[$_lk['pt']],"a+",$nick.'¦¦'.@$s_['uid'].'¦¦'.@$_v['cwww'].'¦¦'.@$_v['cmail'].'¦¦'.$ip.'¦¦'.$cmnt_date.'¦¦'.$text.'¦¦'.$a.'¦¦'.@$_s['comore']."\n");
				e($_l['cmnt_add']);
				redirect(plink($_v[$_lk['pt']]));
		} else {
			e($_l['emptycomm']);
			redirect(plink($_v[$_lk['pt']]));
		}
	}
	} else {
	if(isset($_l['comm_error'])) e($_l['comm_error']);
	redirect(plink($_v[$_lk['pt']]));
	}
}
?>