Location: PHPKode > projects > TxtForum > txtforum/library/posting_new_topic.php
<?
if (!defined("SKIN")) die("Hack attempt!<br />You can't access directly to this file");
#post new topic
// open txt file for reading and writing
$foo = fopen("data/posts.txt","r+") OR die("<b><font color='red'>Unable to read a file /data/stats.txt,make sure you CHMOD 0777 /data/stats.txt</font></b>"); 
flock ($foo, 2);
$id = fread($foo,100);
$new_id = $id + 1; 
fseek($foo,0);
fwrite($foo,"$new_id");
flock ($foo,3); 
fclose($foo);
mkdir("data/$new_id.data",0777)OR die("<b><font color='red'>Unable to write in ./data directory,make sure you CHMOD 0777 ./data</font></b>");
$view_f=fopen("data/$new_id.data/views.txt","w+b");
fwrite($view_f,"0");
fclose($view_f);
// write new post in a new file
$ip_mask = ip(); #new $ip_mask
include "os.php";
$new_file = "data/$new_id.txt";
$fp = fopen("$new_file","w+b");
flock($fp, 2);
$msg = "$new_id
$name
$ip_mask
$subject
$datum
$msg
$loc
$browser
$os
$disable_smiles
$reg_user
$r_status
$r_sig";
fwrite($fp,"$msg");
flock($fp, 3); 
fclose($fp); #done writing new file
$headers=file('data/headers.txt');
$new_line="[new_topic]<|>$new_id<|>$subject<|>$name<|>$datum<|>$reg_user<|>0\n";
$headers=stick($headers,$new_line);
$fo=fopen('data/headers.txt',"w");
flock($fo,LOCK_EX);
fwrite($fo,$headers);
flock($fo,LOCK_UN);
fclose($fo);
$fp = fopen("data/$new_id.data/replies.txt", "ab");
flock ($fp, 2);
fwrite($fp, "$new_id\r\n");
flock ($fp, 3);
fclose($fp);
/* #why we need last.txt ?
$fp = fopen ("data/last.txt", "w+b");
flock ($fp, 2);
fwrite($fp, "$new_id<|>$name<|>$subject<|>$datum<|>$reg_user");
flock ($fp, 3); 
// close file
fclose($fp);
*/
# for topic stats...
$fp = fopen ("data/topics.txt", "r+"); 
flock ($fp,2);
// get the next topic $id ? 
$topic_id = fread($fp, filesize("data/topics.txt"));
$topic_id = $topic_id+1; #for now....
fseek($fp,0); #this is magic word for controling pointer
fwrite($fp,$topic_id);
// close file
fclose($fp); 
#*/ and topic stats
$fp = fopen ("data/$new_id.data/last.txt", "w+b"); #for index.php
flock ($fp, 2);
fwrite($fp, "$new_id<|>$name<|>$subject<|>$datum<|>$reg_user");
flock ($fp, 3); 
// close file
fclose($fp); 
#Forums stats
add_forum_stats(1,1);
// forward user to the topic listing
header("Location: view_topic.php?tid=$new_id") or die("Didn't send header#1");
exit;
 
?>
Return current item: TxtForum