<?php
////////////////////////////////////////////////////
/// ///
/// Vz Forum 1.0 ///
/// Author : Luca Penzo <hide@address.com> ///
/// ///
////////////////////////////////////////////////////
include("config.inc.php");
$posts_dir="posts";
$replies_dir="replies";
$db = mysql_connect($db_host, $db_user, $db_password) or die ("$mysql_error");
//////////////////////////////////////////////
//functions
function txtread($filename, $mess_dir){
$fileread = fopen("$mess_dir/$filename", "r");
$file = fread($fileread, filesize("$mess_dir/$filename"));
fclose($fileread);
return($file);
}
function txtwrite($filename, $mess_dir, $file_to_write){
$filewrite = fopen("$mess_dir/$filename", "w");
fputs($filewrite , "$file_to_write");
fclose($filewrite );
}
function DBW($db_query, $db_name, $db){
$sql=$db_query;
$result=mysql_db_query($db_name,$sql,$db);
return($result);
}
function DBR($db_query, $db_name, $db){
$sql=$db_query;
$result=mysql_db_query($db_name,$sql,$db);
$row=mysql_fetch_array($result);
return($row);
}
function string1($string){
$string = str_replace("\n", "<br>", $string);
return($string);
}
function string2($string){
$string = str_replace("'","´", $string);
$string = str_replace("\"",""", $string);
return($string);
}
function gettemplate($pagename,$ext="htm") {
$pagesfolder="html";
return str_replace("\"","\\\"",implode("",file($pagesfolder."/".$pagename.".".$ext)));
}
function gettemplate1($pagename,$ext) {
$pagesfolder="html";
return str_replace("\"","\\\"",implode("",file($pagesfolder."/".$pagename.".".$ext)));
}
function CLink($testo){
$testo = explode("<br>", $testo);
$testo_array=array();
while (list ($k, $v) = each ($testo)) {
$v = eregi_replace("( |^)((http|telnet|https|ftp)://(([a-zA-Z0-9&\.\-]{3,})(\.[a-zA-Z]{2,4}))(/([a-zA-Z0-9\.&~\?=#_\-\\%]*))*)", " <a href=\"\\2\" style=\"color:#0000CC;\" target=\"_blank\">\\2</a>", $v);
$v = eregi_replace("( |^)((www\.([a-zA-Z0-9&\.\-]{3,})(\.[a-zA-Z]{2,4}))(/([a-zA-Z0-9\.&~\?=#_\-\\%]*))*)", " <a href=\"http://\\2\" style=\"color:#0000CC;\" target=\"_blank\">\\2</a>", $v);
$testo_array[]=$v;
}
$testo=implode("<br>",$testo_array);
return($testo);
}
/////////////////////////////////////////////
if(!isset($mode)){$mode="index";}
switch($mode){
case("index"):
eval("echo(\"".gettemplate1("header",$ext)."\");");
eval("echo(\"".gettemplate("top")."\");");
eval("echo(\"".gettemplate("menu_index")."\");");
if(!isset($p)){$p=1;}
$last=($p*$pxp);
$first=$last-$pxp;
if($DB==1){
$counting=DBW("SELECT * from posts ORDER by id DESC", $db_name, $db);
$npost=mysql_num_rows($counting);
$result=DBW("SELECT * from posts ORDER by id DESC LIMIT $first,$pxp", $db_name, $db);
while($row=mysql_fetch_array($result)){
$id=$row["id"];
if(isset($vzforum) and $password==$vzforum){$del_link="<a href=\"$index_page?mode=admin&id=$id\" style=\"$link\"><center><b>X</b></center></a>";}
else{$del_link="<center><img src=\"ico.gif\" border=\"0\"></center>";}
$query_replies=mysql_db_query($db_name,"SELECT * from replies WHERE post_id='$id'",$db);
$nr=mysql_num_rows($query_replies);
$name=$row["name"];
$subject=$row["subject"];
if($subject==""){$subject=$no_subject;}
$date=$row["date"];
$time=$row["time"];
if($row["email"]==""){}else{$name="<a href=\"mailto:$row[email]\" style=\"$link_mail\"><u>$name</u></a>";}
eval("echo(\"".gettemplate("index")."\");");
}
}
if($DB==0){
$handle=opendir("$posts_dir");
$post_array=array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {$post_array[]=$file;}}closedir($handle);
natsort($post_array);
$npost=count($post_array);
$post_array=array_reverse($post_array);
$array_to_show=array();
for($n=$first;$n<=$last;$n++){
if($post_array[$n]==""){}else{
$array_to_show[]=$post_array[$n];
}
}
while (list ($key, $value) = each ($array_to_show)) {
if(file_exists("$posts_dir/$value")){
$post_data=txtread($value, $posts_dir);
$post_data=explode("\n",$post_data);
$id=$value;
if(isset($vzforum) and $password==$vzforum){$del_link="<a href=\"$index_page?mode=admin&id=$id\" style=\"$link\"><center><b>X</b></center></a>";}
else{$del_link="<center><img src=\"ico.gif\" border=\"0\"></center>";}
$np=$post_data[0];
$handler=opendir("$replies_dir");
$rep_array=array();
while (false !== ($file = readdir($handler))) {
if ($file != "." && $file != "..") {
if(file_exists("$replies_dir/$file")){
$reply_data=txtread($file, $replies_dir);
$reply_data=explode("\n",$reply_data);
if($reply_data[0]==$np){$rep_array[]=$file;}
}
}}closedir($handler);
$nr=count($rep_array);
$name=$post_data[1];
$name=stripslashes($name);
$subject=$post_data[3];
if($subject==""){$subject=$no_subject;}
$subject=stripslashes($subject);
$post=$post_data[4];
$date=$post_data[5];
$time=$post_data[6];
if($post_data[2]==""){}else{$name="<a href=\"mailto:$post_data[2]\" style=\"$link_mail\"><u>$name</u></a>";}
eval("echo(\"".gettemplate("index")."\");");
}
}
}
eval("echo(\"".gettemplate("bottom")."\");");
echo"<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">";
echo"<tr>";
echo"<td width=\"100%\" align=\"center\"><br><font style=\"$link\">";
$pages=($npost/$pxp)+1;
for($i=1;$i<$pages;$i++){
if($p==$i){echo"<b>$i</b> ";}
else{echo"<a href=\"$index_page?p=$i\" style=\"$link\"><u>$i</u></a> ";}
}
echo"</font></td>";
echo"</tr>";
echo"</table>";
eval("echo(\"".gettemplate1("footer",$ext)."\");");
break;
case("post"):
eval("echo(\"".gettemplate1("header",$ext)."\");");
eval("echo(\"".gettemplate("top")."\");");
eval("echo(\"".gettemplate("post")."\");");
eval("echo(\"".gettemplate("bottom")."\");");
eval("echo(\"".gettemplate1("footer",$ext)."\");");
break;
case("reply"):
eval("echo(\"".gettemplate1("header",$ext)."\");");
eval("echo(\"".gettemplate("top")."\");");
eval("echo(\"".gettemplate("reply")."\");");
eval("echo(\"".gettemplate("bottom")."\");");
eval("echo(\"".gettemplate1("footer",$ext)."\");");
break;
case("show_post"):
eval("echo(\"".gettemplate1("header",$ext)."\");");
eval("echo(\"".gettemplate("top")."\");");
if($DB==1){
$row=DBR("SELECT * from posts WHERE id='$id'", $db_name, $db);
$name=$row["name"];
$subject=$row["subject"];
eval("echo(\"".gettemplate("menu_thread")."\");");
$postcont=$row["post"];
$postcont=string1($postcont);
$postcont=CLink($postcont);
$date=$row["date"];
$time=$row["time"];
if($row["email"]==""){}
else{$name="<a href=\"mailto:$row[email]\" style=\"$link_mail\"><u>$name</u></a>";}
eval("echo(\"".gettemplate("thread")."\");");
// replies
$result=DBW("SELECT * from replies WHERE post_id='$id'", $db_name, $db);
$col=0;
while($row=mysql_fetch_array($result)){
$name=$row["name"];
$subject=$row["subject"];
$postcont=$row["post"];
$postcont=string1($postcont);
$postcont=CLink($postcont);
$date=$row["date"];
$time=$row["time"];
if($row["email"]==""){}
else{$name="<a href=\"mailto:$row[email]\" style=\"$link_mail\"><u>$name</u></a>";}
if($col==0){$bgcol=$bgcolor3;$col++;}else{$bgcol=$bgcolor2;$col--;}
eval("echo(\"".gettemplate("replies")."\");");
}
}
if($DB==0){
$post_data=txtread($id, $posts_dir);
$post_data=explode("\n",$post_data);
$id=$post_data[0];
$name=$post_data[1];
$name=stripslashes($name);
if($post_data[2]==""){}
else{$name="<a href=\"mailto:$post_data[2]\" style=\"$link_mail\"><u>$name</u></a>";}
$subject=$post_data[3];
$subject=stripslashes($subject);
eval("echo(\"".gettemplate("menu_thread")."\");");
$postcont=$post_data[4];
$postcont=stripslashes($postcont);
$postcont=CLink($postcont);
$date=$post_data[5];
$time=$post_data[6];
eval("echo(\"".gettemplate("thread")."\");");
//replies
$handle=opendir("$replies_dir");
$replies_array=array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$post_data=txtread($file, $replies_dir);
$post_data=explode("\n",$post_data);
if($post_data[0]==$id){$replies_array[]=$file;}
}
}
natsort($replies_array);
$col=0;
while (list ($key, $value) = each ($replies_array)) {
if(file_exists("$replies_dir/$value")){
$post_data=txtread($value, $replies_dir);
$post_data=explode("\n",$post_data);
$id=$post_data[0];
$name=$post_data[1];
$name=stripslashes($name);
if($post_data[2]==""){}
else{$name="<a href=\"mailto:$post_data[2]\" style=\"$link_mail\"><u>$name</u></a>";}
$subject=$post_data[3];
$subject=stripslashes($subject);
$postcont=$post_data[4];
$postcont=stripslashes($postcont);
$postcont=CLink($postcont);
$date=$post_data[5];
$time=$post_data[6];
if($col==0){$bgcol=$bgcolor3;$col++;}else{$bgcol=$bgcolor2;$col--;}
eval("echo(\"".gettemplate("replies")."\");");
}
}
}
eval("echo(\"".gettemplate("bottom")."\");");
eval("echo(\"".gettemplate1("footer",$ext)."\");");
break;
case("post_submit"):
$message=string2($message);
if($DB==1){
$date=$date_format;
$time=$time_format;
$sql="INSERT into posts (name,email,subject,post,date,time) VALUES ('".$name."','".$email."','".$subject."','".$message."','".$date."','".$time."')";
mysql_db_query($db_name,$sql,$db);
$id=mysql_insert_id();
}
if($DB==0){
$message=string1($message);
$time_cod=time();
$date=$date_format;
$time=$time_format;
$filename="$time_cod.txt";
$file_to_write="$time_cod\n$name\n$email\n$subject\n$message\n$date\n$time";
txtwrite($filename,$posts_dir,$file_to_write);
$id=$filename;
}
header("Location: $index_page?mode=show_post&id=$id");
break;
case("reply_submit"):
if($DB==1){
$message=string2($message);
$date=$date_format;
$time=$time_format;
$code=time();
$sql="INSERT into replies (code,post_id,name,email,subject,post,date,time) VALUES ('".$code."','".$post_id."','".$name."','".$email."','".$subject."','".$message."','".$date."','".$time."')";
mysql_db_query($db_name,$sql,$db) or die("error");
$id=$post_id;
}
if($DB==0){
$message=string1($message);
$time_cod=time();
$date=$date_format;
$time=$time_format;
$filename="$time_cod.txt";
$file_to_write="$post_id\n$name\n$email\n$subject\n$message\n$date\n$time";
txtwrite($filename,$replies_dir,$file_to_write);
$id="$post_id.txt";
}
header("Location: $index_page?mode=show_post&id=$id");
break;
case("admin"):
if(isset($vzforum)){header("Location: $index_page?mode=delete_post&id=$id");}
eval("echo(\"".gettemplate1("header",$ext)."\");");
eval("echo(\"".gettemplate("top")."\");");
eval("echo(\"".gettemplate("admin")."\");");
eval("echo(\"".gettemplate("bottom")."\");");
eval("echo(\"".gettemplate1("footer",$ext)."\");");
break;
case("set_cookie"):
if($admin_password==$password or $vzforum==$password){
setcookie ("vzforum", $password, 50000, $forumdir, "", 0);
header("Location: index.php");
}else{header("Location: $index_page");exit;}
break;
case("delete_post"):
if($admin_password==$password or $vzforum==$password){
}else{header("Location: $index_page");exit;}
if($DB==1){
$sql="DELETE from posts WHERE id='$id'";
mysql_db_query($db_name,$sql,$db);
}
if($DB==0){
unlink("$posts_dir/$id");
$id=explode(".",$id);
$handler=opendir("$replies_dir");
$rep_array=array();
while (false !== ($file = readdir($handler))) {
if ($file != "." && $file != "..") {
if(file_exists("$replies_dir/$file")){
$reply_data=txtread($file, $replies_dir);
$reply_data=explode("\n",$reply_data);
if($reply_data[0]==$id[0]){unlink("$replies_dir/$file");}
}
}}closedir($handler);
}
header("Location: $index_page");
break;
}
mysql_close($db);
?>