Location: PHPKode > projects > TxtForum > txtforum/library/replying.php
<?
if (!defined("SKIN")) die("Hack attempt!<br />You can't access directly to this file");
if (file_exists("data/$tid.data/locked.txt") AND !$arraj[a]) {
	die("You can't reply, topic is locked!");
} 	
#replaying
#all of those "repeated" code we should put in classes/functions
// open txt file for reading and writing
$fp = fopen ("data/posts.txt", "r+"); 
flock ($fp,2);
$id = fread($fp, 100);
$new_id = $id + 1; 
fseek($fp,0);
fwrite($fp,$new_id);
flock ($fp,3); 
// close file
fclose($fp); 
$ip_mask = ip();
include "os.php";
// write new post in file
$new_file = "data/".$new_id.".txt";
$fp = fopen ("$new_file", "wb");
flock ($fp,2);
$msg = "$tid
$name
$ip_mask
$subject
$datum
$msg
$loc
$browser
$os
$disable_smiles
$reg_user
$r_status
$r_sig";
// write new post in file
fwrite($fp,"$msg");
flock ($fp,3); 
// close file
fclose($fp);
$fp = fopen("data/$tid.data/replies.txt", "ab");
flock ($fp, 2);
fwrite($fp, "$new_id\r\n");
flock ($fp, 3);
$subject = strip_nl($subject);
/* why last.txt?
$fp = fopen ("data/last.txt", "r+b"); 
// memorize this id
flock ($fp, 2);
fwrite($fp, "$tid<|>$name<|>Re: $subject<|>$datum<|>$reg_user");
flock ($fp, 3); 
// close file
fclose($fp);
*/
$fp = fopen("data/$tid.data/last.txt","r+b"); 
// memorize this id
flock ($fp, 2);
fwrite($fp, "$new_id1<|>$name<|>$subject<|>$datum<|>$reg_user");
flock ($fp, 3); 
// close file
fclose($fp);
#we need to check if topic is sticked, if it's then put it on top of headers.txt if it's not then put it after sticked topics
$topics=file('data/headers.txt');
$sticky = get_sticky_topics($topics);
#let's first check if topic is sticked
for($i=0;is_string($topics[$i]);$i++){
	list($s_unknow,$s_tid,$s_subject,$s_author,$s_date,$s_is_register,$is_stick)=explode('<|>',$topics[$i]);
	if ($s_tid==$tid) { #we found our topic in headers.txt
		$secure_id_isin_headers=1;
		if($is_stick==1) { #now let's put this topic in top of stick topics
			$headers="$s_unknow<|>$s_tid<|>$s_subject<|>$s_author<|>$s_date<|>$s_is_register<|>$is_stick";
			$headers.=get_sticky_without_tid($topics,$s_tid);
			$headers.=$sticky[1];
#			echo "Headers: $headers";
		}
		else {
			#it's not sticky topic... let's make list of sticky topics and then 'normal' topics
			$headers=$sticky[0];
			$headers.="$s_unknow<|>$s_tid<|>$s_subject<|>$s_author<|>$s_date<|>$s_is_register<|>$is_stick";
			$headers.=get_nonsticky_without_tid($topics,$s_tid);
#			echo "Headers: $headers";
		}
	}
}
if (!$secure_id_isin_headers) { die("This topic is deleted"); } #we need to control error msgz
$fo=fopen('data/headers.txt',"w");
flock($fo,LOCK_EX);
fwrite($fo,$headers);
flock($fo,LOCK_UN);
fclose($fo);
add_forum_stats(1);
/*  Get the number of pages for the current topic  */
		$other = file("data/$tid.data/replies.txt");
		$s1 = sizeof($other);
		if ($s1<=$posts_per_page)
		{
			$pages_='1';
		}
		else
		{
			$pages_ = $s1/$posts_per_page;
			$pages_ = round($pages_,1);
			$z = explode('.', $pages_);
			if ($z[1]>'0')
			{
				$pages_=$z[0]+1;
			}
			else
			{
				$pages_=$z[0];
			}
		}
/*  Get a new thread id  */  
$freplies = file("data/$tid.data/replies.txt");
$sr = sizeof($freplies);
$replies = $sr;
$last_reply=$freplies[$sr-1];

/*  Forward user to the thread they've just posted to  */

header("Location: view_topic.php?tid=$tid&page=$pages_#$last_reply") or die("didn't send header #2");
exit;
?>
Return current item: TxtForum