Location: PHPKode > projects > nSys Flat News System > nsys-flat-news-system/include/functions/classes.php
<?php

/**
 *
 * nSys 2.0 Flat - News System by b3.portal
 * HomePage: http://bosniamaj.co.cc
 * Theese are classes and functions required for script to work
 *
 *    DO NOT EDIT THIS FILE
 *
 * @version 2.0
 * @copyright hide@address.com 2010
 */

/* Display HTML */
  class DisplayHtml{
  var $nSysContact="hide@address.com";
  	function DivOpen($id,$class){
  		$go= "<div id=\"$id\" class=\"$class\">\n";
  		return $go;
  	}
  	function DivClose(){
  		$go= "</div>\n";
  		return $go;
  	}

  	function aOpen($href,$target,$text,$class=""){
  		if($target=="")
  		{
  			$target1="";
  		}
  		else
  		{
  			$target1=" target=\"$target\"";
  		}
  		if($class!="")
  		{
  			$class=" class=\"$class\"";
  		}
  		$go= "<a href=\"$href\"$class$target1>$text";
  		return $go;
  	}
  	function aClose(){
  		$go= "</a>";
  		return $go;
  	}

  	function FormOpen($action,$method="post",$name,$target="",$class,$enctype=""){
  		$go="<form action=\"$action\" method=\"$method\" name=\"$name\" target=\"$target\" id=\"$name\" class=\"$class\" enctype=\"$enctype\">\n";
  		return $go;
  	}
  	function FormClose(){
  		$go="</form>\n";
  		return $go;
  	}
  	function InputOpen($type,$name,$value,$class,$selected="",$maxlenght=""){
  		if($selected!="")
  		{
  			$selected=" selected=\"selected\"";
  		}
  		$go="<input type=\"$type\" name=\"$name\" id=\"$name\" value=\"$value\" class=\"$class\" $maxlenght $selected/>\n";
  		return $go;
  	}
  	function TextArea($name,$columns,$rows,$value){
  		$go="<textarea name=\"$name\" id=\"$name\" cols=\"$columns\" rows=\"$rows\">$value</textarea>\n";
  		return $go;
  	}
  	function Heading($h,$text){
  		$go="<$h>$text</$h>\n";
  		return $go;
  	}
  	function Paragraph($text){
  		$go="<p>\n".$text."\n</p>\n";
  		return $go;
  	}

  	/* write to files */
  	function WriteToFiles($file,$mode,$input,$say=1){
  		if(!is_file($file))
  		{


  			$fp=fopen($file,"w");
  			fclose($fp);
  		}
  		if(!is_writable($file))
  		{
  			if(!chmod($file,0751))
  			{
  				$go .= $this->DivOpen("error","Error");
  				$go .= LangCHMODError;
  				$go .= $this->DivClose();
  			}
  		}
  		else
  		{
  			$fp=fopen($file,$mode);
  			if(!fwrite($fp,$input))
  			{
  				$go .= $this->DivOpen("error","Error");
  				$go .= LangWritingError;
  				$go .= $this->DivClose();
  			}
  			else
  			{
  				if($say==1)
  				{
  					$go .= $this->DivOpen("success","Success");
  					$go .= LangWritingSuccess." ".str_replace(".php","",basename($file));
  					$go .= $this->DivClose();
  				}
  				else
  				{
  					$go=1;
  				}
  				chmod($file,0551);
  			}
  			fclose($fp);
  		}
  		return $go;
  	}
  	/* write to files*/
  	/* change num of news */
  	function ChangeNumOfNews($id,$where=1,$comm=NULL){
  		$newsfile="../include/news.php";
  		$file=file($newsfile);
  		$con=file_get_contents($newsfile);
  		foreach($file as $num => $f)
  		{
  			$n=explode("|",$f);
  			if($id==$n[0])
  			{
  				$old = $f;
  				if($comm==NULL)
  				{

  					$n[5]=$n[5]+$where;
  				}
  				elseif($comm==1)
  				{
  					$n[6]=$n[6]+$where;
  				}
  				for($i=0;$i<count($n);$i++)
  				{
  					if($i==count($n)-1)
  					{
  						$sep="";
  					}
  					else
  					{
  						$sep="|";
  					}
  					$new .= $n[$i].$sep;
  				}
  				break;
  			}
  		}
  		$exp = explode("$old",htmlspecialchars($con));
  		$tw .= htmlspecialchars_decode($exp[0]);
  		$tw .= $new;
  		$tw .= $exp[1];
  		$go = $this->WriteToFiles($newsfile,"w",$tw,0);
  		return $go;
  	}
	
	
  	function ReportToMail($to,$subject,$message,$say=0){
  		if(mail($to,$subject,$message))
  		{
  			if($say>0)
			{
			    $this->DivOpen("success","Success")."LangSuccessMailReport $to!".$this->DivClose();
			}
  		}
  		else
  		{
  			$this->DivOpen("error","Error")."LangErrorMailReport".$this->DivClose();
  		}
  	}
	
  	/* change num of news */

  }
/* Display HTML */


/* Checking files and folders */
  class CheckFilesAndFolders extends DisplayHtml{
	var $ImportantFolders=array(
		"admin",
		"include",
		"include/functions",
		"lang",
	);
	var $ImportantFiles=array(
		"include/InstalledLangs.txt",
		"include/functions/FuncsGlobal.php",
		"lang/en.php",
		"config.php",
	);

	function SetLocation($location=""){
		$where=explode("install",$_SERVER["PHP_SELF"]);
		if(count($where)>0)
		{
			$location="../";
		}
		return $location;
	}

	function CheckFolders($c=0,$report=array()){
  		for($i=0;$i<count($this->ImportantFolders);$i++)
  		{
  			if(!is_dir($this->SetLocation().$this->ImportantFolders[$i]))
  			{
  				$report=array_merge($report,array("".$this->aOpen("","",$this->ImportantFolders[$i]).$this->aClose()."<br />"));
  				$c++;
  			}
  		}
		if($c>0)
		{
			echo $this->DivOpen("error","Error TopFull");
			echo LangMissingFolders."<br />";
			for($i=0;$i<count($report);$i++)
			{
				echo $report[$i];
			}
			if($this->SetLocation()!="../")
			{
				$this->ReportToMail("hide@address.com","Missing Folders","There are some missing folders");
			}
			echo $this->DivClose();
		}
		else
		{
			echo "";
		}
  	}

  	function CheckFiles($c=0,$report=array()){
  		for($j=0;$j<count($this->ImportantFiles);$j++)
  		{
  			if(!is_file($this->SetLocation().$this->ImportantFiles[$j]))
  			{
  				$report=array_merge($report,array("".$this->aOpen("","",$this->ImportantFiles[$j]).$this->aClose()."<br />"));
  				$c++;
  			}
  		}
  		if($c>0&&$this->SetLocation()!="../")
  		{
  			echo $this->DivOpen("error","Error TopFull");
  			echo LangMissingFiles."<br />";
  			for($i=0;$i<count($report);$i++)
  			{
  				echo $report[$i];
  			}
  			if($this->SetLocation()!="../")
  			{
  				$this->ReportToMail("hide@address.com","Missing Files","There are some missing files");

  			}
  			echo $this->DivClose();
  		}
  		else
  		{
  			echo "";
  		}
  	}

  }
/* Checking files and folders */

/* Install script */
  class InstallScript extends CheckFilesAndFolders{
  	var $WritableFolders=array(
  		"images",
  		"include",
  		"include/InstalledLangs.txt",
  		"lang",
  		"styles",
	);
  	var $ToChmod=array();
  	var $returnCHMOD;
  	var $ScriptInstalled=0;
  	function CheckCHMOD($c=0)
  	{
  		for($i=0;$i<count($this->WritableFolders);$i++)
  		{
  			if(!is_writable($this->SetLocation().$this->WritableFolders[$i]))
  			{
  				$this->ToChmod=array_merge($this->ToChmod,array("".$this->WritableFolders[$i]));
  				$c++;
  			}
  		}
  		if($c>0)
  		{
  			$this->returnCHMOD .= $this->DivOpen("error","Error TopFull");
  			$this->returnCHMOD .= LangNotWritable."<br />";
  			for($i=0;$i<count($this->ToChmod);$i++)
  			{
  				$this->returnCHMOD .= $this->ToChmod[$i]."<br />";
  			}
  			$this->returnCHMOD .= "<br />".LangClickToCHMODit;
  			$this->returnCHMOD .= ($this->DivClose());

  			return $this->returnCHMOD;
  			return $this->ToChmod;

  		}
  	}

  	function ftpCHMOD($files,$host,$user,$pass,$chmod="0751",$c=0,$e=0){
  		if((!empty($host))&&(!empty($user)))
  		{
  			$ftpconn= ftp_connect($host) or die("Error!");
  			$ftplogin= ftp_login($ftpconn,$user,$pass) or die("Error!");
  			ftp_chdir($ftpconn, dirname($_SERVER["PHP_SELF"]));
  			ftp_cdup($ftpconn);
  			for($i=0;$i<count($files);$i++)
  			{
  				if(ftp_chmod($ftpconn,$chmod,"/".$files[$i]))
  				{
  					$go .= $files[$i]." - ".LangCHMODSuccess."<br />";
  					$c++;
  				}
  				else
  				{
  					$go .= $files[$i]." - ".LangCHMODError."<br />";
  					$e++;
  				}
  			}
  			ftp_close($ftpconn);
  			if($c>0)
  			{
  				echo $this->DivOpen("success","TopFull Success");
  				echo $go."<br />";
  				echo $this->DivClose();
  			}
  			if($e>0)
  			{
  				echo $this->DivOpen("error","TopFull Error");
  				echo $go."<br /><br />".LangCHMODManual;
  				echo $this->DivClose();
  			}
  		}
  		else
  		{
  			echo LangFieldsEmpty;
  		}
  	}

  	function doCHMOD($chmod="0751",$c=0){
  		if(is_array($this->ToChmod))
  		{

  			for($i=0;$i<count($this->ToChmod);$i++)
  			{
  				$fajl=$this->SetLocation().$this->ToChmod[$i];
  				if(!chmod("".$this->SetLocation().$this->ToChmod[$i]."",0751))
  				{
  					$go .= $this->ToChmod[$i]." - ".LangCHMODError."<br />";
					$c++;
  				}
  				else
  				{
  					$go .= $this->ToChmod[$i]." - ".LangCHMODSuccess."<br />";
  				}
  			}
  			if($c>0) { $class="Error"; } else { $class="Success"; }
  			echo $this->DivOpen("ftp_chmod","TopFull $class");
  			echo $go;
  			echo "<br />".LangYouMayProceed."<br />";
  			echo $this->DivClose();
  			if($c>0)
  			{
  				/* FTP CHMOD */
  				echo $this->DivOpen("ftp_chmod","TopFull Success");
  				echo $this->FormOpen("","post","form1","","");
  				echo LangFTPInfoNeeded."<br /> <br /> ";
  				echo "<label>FTP ".LangServer."<br /> ".$this->InputOpen("text","server","","")."</label>";
  				echo "<label>FTP ".LangUsername."<br /> ".$this->InputOpen("text","username","","")."</label>";
  				echo "<label>FTP ".LangPassword."<br /> ".$this->InputOpen("password","password","","")."</label>";
  				echo "<label>".$this->InputOpen("submit","submit",LangSubmit,"")."</label>";
  				echo $this->FormClose();
  				echo $this->DivClose();
                /* FTP CHMOD */
  			}
  		}
  	}

  	function InputInfo(){
  		$url=str_replace("%20"," ",$_SERVER["HTTP_REFERER"]);
  		$url=explode("install",$url);

  		$go .= $this->DivOpen("success","TopFull Forms");
  		$go .= $this->FormOpen("","post","getinfo","","");
  		$go .= LangBasicInfoNeeded.": <br /><br />";
  		$go .= "<label>".LangScriptLocation."<br /> ".$this->InputOpen("text","scriptloc",$url[0],"")."</label>";
  		$go .= "<label>Admin ".LangUsername."<br /> ".$this->InputOpen("text","user","","")."</label>";
  		$go .= "<label>Admin ".LangPassword."<br /> ".$this->InputOpen("password","pass","","")."</label>";
  		$go .= "<label>".LangRetype." ".LangPassword."<br /> ".$this->InputOpen("password","pass1","","")."</label>";
  		$go .= "<label>Admin ".LangEmail."<br /> ".$this->InputOpen("text","email","","")."</label>";
  		$go .= "<label>".$this->InputOpen("submit","infosubmit",LangContinue,"")."</label>";
  		$go .= $this->FormClose();
  		$go .= $this->DivClose();

  		return $go;
  	}

  	function CheckIfInstalled(){
  		if((is_file($this->SetLocation()."include/config.php"))||(is_file($this->SetLocation()."include/users.php")))
  		{
  			$go .= $this->DivOpen("error","Error");
  			$go .= LangSrciptInstalled;
  			$go .= $this->DivClose();
  			$this->ScriptInstalled=1;
  		}
  		return $go;
  	}

	function GetInfo($loc,$user,$pass,$pass1,$email){
		$this->CheckIfInstalled();
		if($this->ScriptInstalled==1)
		{
			$go .= $this->CheckIfInstalled();
		}
		else
		{
			/* else */
  		if((!empty($loc))&&(!empty($user))&&(!empty($pass))&&(!empty($pass1))&&(!empty($email)))
  		{
  			$pass=md5($pass);
  			$pass1=md5($pass1);
  			if($pass==$pass1)
  			{





  				$userfile="<?php die(\"\"); ?>
1|100|$user|$pass|$email|0|0";
  				$lang=basename($_COOKIE["nSysLang"]);
  				$configfile="<?php
\$nSysLoc = \"$loc\";
\$nSysAdminMail = \"$email\";
\$nSysLang = \"$lang\";
\$nSysNewsShow = \"10\";
\$nSysNewsBackup = \"yes\";
\$nSysNewsShort = \"1000\";
\$nSysCommentsAllow =\"yes\";
\$nSysCommentsVerify = \"yes\";
\$nSysCommentsBBcode = \"yes\";
\$nSysSupport = \"yes\";
?>";
  				$go .= $this->WriteToFiles($this->SetLocation()."include/users.php","w",$userfile);
  				$go .= $this->WriteToFiles($this->SetLocation()."include/config.php","w",$configfile);
  				$go .= $this->DivOpen("success","Success");
  				$go .= LangInstallationSuccess."<br /><br />".$this->aOpen("../admin","",LangAdminPanel).$this->aClose();
  				$go .= $this->DivClose();
				$go .= $this->ReportToMail($this->nSysContact,"nSys 2.0 Flat installed","nSys 2.0 installed on $loc\n\r\n Admin e-mail: $email\n\r\n nSys Support Mail");
  			}
  			else



  			{
  				$go .= $this->DivOpen("error","TopFull Error");
				$go .= LangPassNoMatch."! <br />";
  				$go .= $this->DivClose();


  				$go .= $this->InputInfo();
  			}
  		}
  		else
  		{
  			$go .= $this->DivOpen("error","TopFull Error");
			$go .= LangFieldsEmpty." <br />";
  			$go .= $this->DivClose();
  			$go .= $this->InputInfo();
  		}
			/* else */
		}
  		return $go;
  	}

  }
/* Install script */

/* Handle news */
  /**
   * Working with news
   *
   */
  class News extends CheckFilesAndFolders{
  	var $path=__FILE__;
  	function DisplayNews($cat="",$newsid=NULL,$c=NULL){
  		global $nSysNewsShort, $nSysLoc, $nSysNewsShow;
  		$newsid=$_GET["newsid"];
  		$path=explode("include",$this->path);
  		$path=$path[0];
  		$file=$path."include/news.php";
  		if ((isset($_SERVER['QUERY_STRING']) && trim($_SERVER['QUERY_STRING']) != ''))
  		{
  			if(stristr($_SERVER['QUERY_STRING'], 'do='))
  			{
  				$query = '?'.preg_replace('/do=\d+/', 'do=', $_SERVER['QUERY_STRING']);
  			}
  			else
  			{
  				$query = '?'.$_SERVER['QUERY_STRING'].'&do=';
  			}
  		}
  		else
  		{
  			$query = '?do=';
  		}
  		if ($_GET["do"]=="archives")
  		{
  			$limit=count(file($file));
  			$older="";
  		}
  		else
  		{
  			$limit=$nSysNewsShow;
  			$older=$this->aOpen($query."archives","",LangArchives).$this->aClose();
  		}
  		$fp=fopen($file,"r");
  		$i=0;
  		if ($cat=="")
  		{
  			$cat = 1;
  		}
  		if($newsid==NULL)
  		{
  			while((!feof($fp))&&($i<$limit))
  			{
  				$n = fgets($fp,filesize($file));
  				if(!preg_match("/^<\?/",$n))
  				{
  					$n = str_replace("\n","<br />",$n);
  					$n = explode("|",$n);
  					if ($n[7]==$cat)
  					{
  						$n[6] = str_replace("<br />","",$n[6]);
  						$link=$query."more&newsid=$n[0]";
  						$lenght=strlen($n[4]); $rmore="";
  						if(($nSysNewsShort>0)&&($nSysNewsShort<$lenght)) { $lenght=$nSysNewsShort; $rmore="... ".$this->aOpen("$link","","[".LangReadMore."]").$this->aClose(); }
  						$n[4] = substr($n[4],0,$lenght).$rmore;
  						$n[4] = stripslashes($n[4]);

  						/*
  						   * $n[1] - News date and time
  						   * $n[2] - News author
  						   * $n[3] - News title
  						   * $n[4] - News text
  						   * $n[5] - Number of Views
  						   * $n[6] - Number of Comments
  						*/
  						$go .= $this->DivOpen("news$i","news");
  						$go .= $this->Heading("h2",$this->aOpen($link,"",$n[3])).$this->aClose();
  						$go .= $this->Paragraph($this->BBCode($n[4]));
  						$go .= $this->DivOpen("datentime","NewsDate").$n[2]." @ ".$n[1]."<br />".$this->CheckCat("name",$cat)." | ".$this->aOpen($link."#comments","",$this->CountComms($n[0]). LangComms ).$this->aClose().$this->DivClose();
  						$go .= $this->DivClose();
  						$i++;
  						$c++;
  					}
  				}
  			}
  			if($c==0)
  			{
  				$go .= $this->DivOpen("error","TopFull Error");
  				$go .= LangNoArticles."! <br />";
  				$go .= $this->DivClose();
  			}
  			else
  			{
  				$go .= $older;
  			}
  		}
  		else
  		{
  			$go = $this->DisplaySingleNews($newsid);
  		}
  		fclose($fp);
		$go .= $this->nSysSupport();
  		return $go;
  	}

  	function DisplaySingleNews($newsid,$c=0){
  		$path=explode("include",$this->path);
  		$path=$path[0];
  		$file="$path/include/news.php";
  		$fajl=file($file);
  		if(!ctype_digit($newsid))
  		{
  			$go .= LangNotNumeric."!";
  		}
  		else
  		{
  			foreach($fajl as $num => $f)
  			{
  				if(!preg_match("/^<\?/",$f))
  				{
  					$n=explode("|",$f);
  					if($n[0]==$newsid)
  					{
						$id = $n[0];
						$time = $n[1];
  						$author = $n[2];
  						$title = $n[3];
  					    $text = $n[4];
  					    $views = $n[5];
  					    $comms = $n[6];
  						$cat = $n[7];
  						$commsallowed = str_replace(" ","",$n[8]);
  						$commsallowed = str_replace("\n","",$n[8]);
  						$commsallowed = str_replace("\r","",$n[8]);
						$c++;
  						break;
  					}
  				}
  			}
  			/**/
  			if($c>1)
  			{
  				$go .= LangMultipleNews."!";
  			}
  			elseif($c<1)
  			{
  				$go .= LangNoSuchNews."!";

  			}
  			else
  			{
  				$go .= $this->DivOpen("news","news");
  				$go .= $this->Heading("h2",$this->aOpen($link,"",$title).$this->aClose());
  				$go .= $this->ShareNews();
  				$go .= $this->Paragraph($this->BBCode($text,0));
  				$go .= $this->DivOpen("datentime","NewsDate").$author." @ ".$time."<br />".$this->CheckCat("name",$cat)." | ".$this->aOpen($link."#comments","",$this->CountComms($id). LangComms ).$this->aClose().$this->DivClose();
  				$go .= $this->DivClose();
  				$go .= $this->DisplayComms($id,$commsallowed);
  			}
  			/**/
  		}
  	return $go;
	}

  	function BBCode($text,$short=1){
	global $nSysNewsShort;
	$len = $nSysNewsShort;
	  /* Decode HTML tags back to normal */
	  $text=htmlspecialchars_decode($text);	
	  if($short==1)
	  {
		if((mb_strlen($text)>$len)) /* If article is longer than num of chars of our short story */
		{
		    $wspos = mb_strpos($text," ",$len)-1; /* Set position of white space, between words */
		    if($wspos>0)
		    {
                $chars = count_chars(mb_substr($text,0,($wspos+1)),1); /* Let's count */
                if ($chars[ord('<')] > $chars[ord('>')]) /* If tags */
				{
				    $wspos = mb_strpos($text,">",$wspos)-1; /* New position */
				}
                $text = mb_substr($text, 0, ($wspos+1)); /* Makse it shorter */
            }

            /* If there are unclosed tags, let's close them */
            if( preg_match_all("|(<([\w]+)[^>]*>)|",$text,$aBuffer) ) 
			{
			    if(!empty($aBuffer[1])) 
				{
				    preg_match_all("|</([a-zA-Z]+)>|",$text,$aBuffer2);
                    if(count($aBuffer[2]) != count($aBuffer2[1])) 
					{
					    $closing_tags = array_diff($aBuffer[2], $aBuffer2[1]);
                        $closing_tags = array_reverse($closing_tags);
					    foreach($closing_tags as $tag) 
						{
                            $text .= '</'.$tag.'>';
                        }
                    }
                }
            }
        }
	  }
  		$search = array(
  		"#\[b\](.*?)\[/b\]#",
  		"#\[i\](.*?)\[/i\]#",
  		"#\[u\](.*?)\[/u\]#",
  		"#\[img\](.*?)\[/img\]#",
  		"#\[url=(.*?)\](.*?)\[/url\]#",
  		"#\[code\](.*?)\[/code\]#",
  		'#\[quote=(.*?)\](.*?)\[/quote\]#',

  		'#\[quote\](.*?)\[/quote\]#',
  		"#\\n#"
	);
  		$replace = array(
  		"<b>\\1</b>",
  		"<i>\\1</i>",
  		"<u>\\1</u>",
  		"<img src=\"\\1\" />",
  		"<a href=\"\\1\" target=\"_blank\" class=\"preview\">\\2</a>",
  		"<code>\\1</code>",
  		'<div id="quote" class="quote"> <span>\\1</span> \\2</div>',
  		'<div id="quote" class="quote"> \\1</div>',
  		"<br />"
	);

  		$text=str_replace("<?php","",$text);
  		$text=str_replace("?>","",$text);
		$text=str_replace("<script","",$text);
  		$text=str_replace("</script>","",$text);
		return preg_replace($search,$replace,$text);
  	}

  	function ShareNews(){
  		$go .= "<div id=\"sharenews\" class=\"sharenews\"><script type=\"text/javascript\" src=\"http://w.sharethis.com/button/sharethis.js#publisher=40acd471-1f27-4147-8b61-2636b4aab672&amp;type=website&amp;embeds=true&amp;style=horizontal\"></script></div>";
  		return $go;
  	}
	function nSysSupport(){
	    global $nSysSupport;
		if ($nSysSupport!="no")
		{
		    $go .="<div id=\"ads\" class=\"ads\"><script type=\"text/javascript\"><!--
google_ad_client = \"pub-9025621163588260\";
/* 728x90, created 8/3/09 */
google_ad_slot = \"6720850444\";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type=\"text/javascript\"
src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script></div>";
		}
		return $go;
	}

  	function CheckCat($what,$id){
  		$path=explode("include",$this->path);
  		$path=$path[0];
  		$catfile="$path/include/categories.php";
  		if($what=="name"){ $what=1; }
  		if($what=="description"){ $what=2; }
  		$file=file($catfile);
  		foreach ($file as $num => $f)
  		{
  			if (!preg_match("/^<\?/",$f))
  			{
  				$n = explode("|",$f);
  				if ($id==$n[0])
  				{
  					$go = $n[$what];
  					break;
  				}
  			}
  		}
  		return $go;
  	}
  	function DisplayComms($id,$allowed=1,$c=0){
  		global $nSysCommentsAllow, $nSysCommentsBBcode, $nSysCommentsVerify;
  		$path=explode("include",$this->path);
  		$path=$path[0];
  		if(($allowed!=1)||($nSysCommentsAllow!="yes"))
  		{
  			$go .= LangCommsNotAllowed;
  		}
  		else
  		{
  			if (isset($_POST["AddComm"]))
  			{
  				if((isset($_POST["name01"]))&&(isset($_POST["text01"])))
  				{
  					$id= (int) $_POST["id01"];
  					$name=htmlspecialchars($_POST["name01"]);
  					$email=htmlspecialchars($_POST["email01"]);
  					$text=htmlspecialchars($_POST["text01"]);
  					$text=str_replace("\n","<br />",$text);
  					$text=str_replace("\r","",$text);
  					if((empty($email))||($email=="E-mail"))
  					{
  						$email="";
  					}
  					if ($nSysCommentsVerify=="yes")
  					{
  						$number=(int)htmlspecialchars($_POST["number01"]);
  					}
  					else
  					{
  						$number=15;
  					}
  					$q=0;
  					if ($number==15)
  					{
  						$fname="$path/include/comments.php";
  						$fp=fopen($fname,"a+");
  						if ($q<1)
  						{
  							if(fwrite($fp,"\n".$id."|".$name."|".$text."|".$email))
  							{
  								echo "<div id=\"Success\"></div>";
  							}
  							else
  							{
  								echo "<div id=\"Success\"></div>";
  							}
  						}
  						fclose($fp);
  						$q++;
  					}
  					else
  					{
  						$go .= "<br/><br/>".LangNotValid;
  					}
  				}
  			}
  			$commsfile="$path/include/comments.php";
  			$go .= "<a name=\"comments\"></a><br /><br />";
			$go .= $this->Heading("h2",LangComms."  <div id=\"xButton\"><a href=\"#bottom\" id=\"comm\">".LangSubmitComm."</a></div>");
  			$file=file($commsfile);
  			$go .= $this->DivOpen("comments","comments");
  			foreach ($file as $num => $f)
  			{
  				if (!preg_match("/^<\?/",$f))
  				{
  					$n=explode("|",$f);
  					if ($n[0]==$id)
  					{
  						$n[2] = str_replace("\'","'",$n[2]);
  						if ($nSysCommentsBBcode=="yes") { $n[2]=$this->BBCode($n[2],0); }
						$go .= $this->DivOpen("commdivs","commdivs");
  						$go .= "<span id=\"commauthor\">".$n[1]."</span>";
  						$go .= "<p id=\"commtext\">".$n[2]."</p>";
  						$go .= $this->DivClose();
  						$c++;
  					}
  				}
  			}
  			$go .= $this->CommsForm();
  			$go .= $this->DivClose();
  			if ($c<1)
  			{
  				$go .= LangNoComms;
  			}
  		}
  		return $go;
  	}

  	function CommsForm(){
  		global $nSysCommentsVerify;
  		$path=explode("include",$this->path);
  		$path=$path[0];
  		$go .= "<a name=\"bottom\"></a><div id=\"YourComm\">";
  		$go .= $this->Heading("h1",LangEnterComm);
  		$go .= "<p id=\"YourCommA\" class=\"YourCommA\">";
  		$go .= $this->FormOpen("","post","AddComm","","","");
  		$go .= $this->InputOpen("hidden","id01",$_GET["newsid"],"");
		$go .= $this->InputOpen("text","name01",LangName,"");
  		$go .= $this->InputOpen("text","email01",LangEmail,"");
  		if ($nSysCommentsVerify=="yes") { $go .= $this->InputOpen("text","number01",LangEnter15,""); }
  		else { $go .= $this->InputOpen("hidden","number01","15",""); }
  		$go .= $this->Textarea("text01","","",LangEnterComm);
  		$go .= $this->InputOpen("submit","AddComm",LangContinue,"submitbutton");
  		$go .= $this->FormClose();
  		$go .= "</p>";
  		$go .= "</div>";
  		return $go;
  	}
  	function CountComms($nid){
  		$path=explode("include",$this->path);
  		$path=$path[0];
  		$c=0;
  		$commfile="$path/include/comments.php";
  		$ff=file($commfile);
  		foreach ($ff as $num => $f)
  		{
  			$n=explode("|",$f);
  			if($n[0]==$nid)
  			{
  				$c++;
  			}
  		}
  		return $c;
  	}

  }
/* Handle news */


?>
Return current item: nSys Flat News System