<?php
//put file contents function
function putcontents($file, $contents, $method)
{
$file_handle = fopen($file, $method);
fwrite($file_handle, $contents);
fclose($file_handle);
return true;
}
//filterdata function
function filterdata($input)
{
$input = str_replace("<", "<", $input);
$input = str_replace(">", ">", $input);
$input = str_replace("$", "$", $input);
$input = str_replace("\?", "?", $input);
$input = str_replace("\'", "'", $input);
$input = str_replace("\\\"", """, $input);
return $input;
}
//unfilter function
function unfilterdata($input)
{
//$input = str_replace("","", $input);
}
//Emoticon parser
function emoticonParse($input)
{
//$input = str_replace("keyword","<img src=\"gfx/emoticons/filename.gif\">", $input);
$input = str_replace(":angel:","<img src=\"gfx/emoticons/face-angel.gif\" alt=\":angel:\">", $input);
$input = str_replace(":cry:","<img src=\"gfx/emoticons/face-crying.gif\" alt=\":cry:\">", $input);
$input = str_replace(":devil:","<img src=\"gfx/emoticons/face-devil-grin.gif\" alt=\":devil:\">", $input);
$input = str_replace(":glasses:","<img src=\"gfx/emoticons/face-glasses.gif\" alt=\":glasses:\">", $input);
$input = str_replace(":kiss:","<img src=\"gfx/emoticons/face-kiss.gif\" alt=\":kiss:\">", $input);
$input = str_replace(":monkey:","<img src=\"gfx/emoticons/face-monkey.gif\" alt=\":monkey:\">", $input);
$input = str_replace(":mellow:","<img src=\"gfx/emoticons/face-plain.gif\" alt=\":mellow:\">", $input);
$input = str_replace(":(","<img src=\"gfx/emoticons/face-sad.gif\" alt=\":(\">", $input);
$input = str_replace(":)","<img src=\"gfx/emoticons/face-smile.gif\" alt=\":)\">", $input);
$input = str_replace(":D","<img src=\"gfx/emoticons/face-smile-big.gif\" alt=\":D\">", $input);
$input = str_replace(":o","<img src=\"gfx/emoticons/face-surprise.gif\" alt=\":o\">", $input);
$input = str_replace(";)","<img src=\"gfx/emoticons/face-wink.gif\" alt=\";)\">", $input);
return $input;
}
//Special tag parser
function specialParse($input)
{
//$input = str_replace("keyword","tag", $input);
$input = str_replace("[img]","<img src=\"", $input);
$input = str_replace("[/img]","\" alt=\"User posted Image\">", $input);
$input = str_replace("[url]","<a href=\"", $input);
$input = str_replace("[/url]","\">", $input);
$input = str_replace("[aurl]","</a>", $input);
return $input;
}
//filterurl function
function filterurl($input)
{
//removes spaces from a string and replaces it with %20
//returns string
//filtering rules
$input = str_replace(" ","%20",$input);
//http:// , %20, and www. fixing
$input = str_replace("http://","",$input); //first remove http:// if there was an instance of it
$input = str_replace("www.","",$input);// then remove www. if it was in the url
$input = "http://www." . $input;//then adding it back
return $input;
}
function filterurl20p($input)
{
//removes %20 from a string and replaces it with a space
//returns string
//filtering rules
$input = str_replace("%20"," ",$input);
return $input;
}
//Thread Generator
function threadgen($fid, $tid, $title, $fdata, $sitetitle)
{
if($fid!="" && $tid!="" && $title!="" && $fdata!="")
{
if(strlen($title)>=30)
{
$title = substr($title, 0, 29);
}
//Build paths
$forumid = $fid;
$forumpath = "forum/forums/" . $forumid;
$foruminfopath = $forumpath . "/info.php";
$nextpath = $forumpath . "/next.php";
//Build thread paths
$threadlocation = $forumpath . "/threads/" . $tid;
$threadinfolocation = $threadlocation . "/info.php";
mkdir($threadlocation);
//write info.php for thread
$threadinfo = "<?" . "php \n\$threadtitle = \"" . $title . "\";\n\$author = \"" . $_SESSION['username'] . "\";\n\$latest=\"" . $_SESSION['username'] . "\";\n\$latesttime=\"" . date("h:i, j/n/y") ."\";\n\$starttime=\"" . date(" l h:i A O, j/n/y") . "\";\n?" . ">";
putcontents($threadinfolocation,$threadinfo,"w+");
//write first post info
$detailstamp = date("g:i:s A, Y/m/d");
$post = "<?php \$powner = \"" . $_SESSION['username'] . "\"; \$pcontent = \"" . $fdata . "\"; \$detailstamp = \"" . $detailstamp . "\"; ?>";
putcontents($threadlocation . "/" . date(U) . ".php", $post, 'w+');
generatenavigation($fid, $sitetitle);
echo("
<div class=\"editorheader\">
Reply added
</div>
<div class=\"editorstack\">
Your thread has been added successfully.<br />
</div>
<div class=\"editorheader\">
<a class=\"threadtitlelink\" href=\"forum.php?act=6&showforum=" . $fid . "&thread=" . $tid . "\">Return to thread</a> | <a class=\"threadtitlelink\" href=\"forum.php?act=6&showforum=" . $fid . "\">Return to forum</a>
</div>
");
}
else
{
echo("You must enter a title and content.");
}
}
//Reply Generator
function replygen($tid, $fid, $fdata, $sitetitle)
{
if($fid!="" && $tid!="" && $fdata!="")
{
//Build paths
$forumid = $fid;
$forumpath = "forum/forums/" . $forumid;
$foruminfopath = $forumpath . "/info.php";
$nextpath = $forumpath . "/next.php";
//Build thread paths
$threadlocation = $forumpath . "/threads/" . $tid;
$threadinfolocation = $threadlocation . "/info.php";
//write info.php for thread
include_once($threadinfolocation);
$threadinfo = "<?" . "php \n\$threadtitle = \"" . $threadtitle . "\";\n\$author = \"" . $author . "\";\n\$latest=\"" . $_SESSION['username'] . "\";\n\$latesttime=\"" . date("h:i, j/n/y") ."\";\n\$starttime=\"" . $starttime . "\";\n?" . ">";
putcontents($threadinfolocation,$threadinfo,"w+");
//write first post info
$detailstamp = date("g:i:s A, Y/m/d");
$post = "<?php \$powner = \"" . $_SESSION['username'] . "\"; \$pcontent = \"" . $fdata . "\"; \$detailstamp = \"" . $detailstamp . "\"; ?>";
putcontents($threadlocation . "/" . date(U) . ".php", $post, 'w+');
generatenavigation($fid, $sitetitle);
echo("
<div class=\"editorheader\">
Reply added
</div>
<div class=\"editorstack\">
Your reply has been added successfully.<br />
</div>
<div class=\"editorheader\">
<a class=\"threadtitlelink\" href=\"forum.php?act=6&showforum=" . $fid . "&thread=" . $tid . "\">Return to thread</a> | <a class=\"threadtitlelink\" href=\"forum.php?act=6&showforum=" . $fid . "\">Return to forum</a>
</div>
");
}
else
{
echo("You must enter something to post.");
}
}
//Edit Generator
function editpost($forum, $thread, $post, $data, $sitetitle)
{
$path = "forum/forums/$forum/threads/$thread/$post";
include_once($path);
$filecontents = "<?php \$powner = \"" . $powner . "\"; \$pcontent = \"" . $data . "\"; \$detailstamp = \"" . $detailstamp . "\"; ?>";
putcontents($path, $filecontents, 'w+');
generatenavigation($forum, $sitetitle);
echo("
<div class=\"editorheader\">
Post edited
</div>
<div class=\"editorstack\">
Your post has been edited successfully.<br />
</div>
<div class=\"editorheader\">
<a class=\"threadtitlelink\" href=\"forum.php?act=6&showforum=" . $_POST['fid'] . "&thread=" . $_POST['tid'] . "\">Return to thread</a> | <a class=\"threadtitlelink\" href=\"forum.php?act=6&showforum=" . $_POST['fid'] . "\">Return to forum</a>
</div>
");
}
//New Thread Form Generator
function newthread($id, $sitetitle)
{
generatenavigation($id, $sitetitle);
echo("
<div class=\"editorheader\">
Create a thread
</div>
<div class=\"editorstack\">
<a href=\"javascript:formaturl();\"><img src=\"gfx/link.gif\" alt=\"Insert Link\" border=\"0\" /></a>
<a href=\"javascript:formatimg();\"><img src=\"gfx/image.gif\" alt=\"Insert Image\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':angel:');\"><img src=\"gfx/emoticons/face-crying.gif\" alt=\":angel:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':devil:');\"><img src=\"gfx/emoticons/face-devil-grin.gif\" alt=\":devil:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':glasses:');\"><img src=\"gfx/emoticons/face-glasses.gif\" alt=\":glasses:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':kiss:');\"><img src=\"gfx/emoticons/face-kiss.gif\" alt=\":kiss:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':monkey:');\"><img src=\"gfx/emoticons/face-monkey.gif\" alt=\":monkey:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':mellow:');\"><img src=\"gfx/emoticons/face-plain.gif\" alt=\":mellow:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':(');\"><img src=\"gfx/emoticons/face-sad.gif\" alt=\":(\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':D');\"><img src=\"gfx/emoticons/face-smile-big.gif\" alt=\":D\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':)');\"><img src=\"gfx/emoticons/face-smile.gif\" alt=\":)\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':o');\"><img src=\"gfx/emoticons/face-surprise.gif\" alt=\":o\" border=\"0\" /></a>
<a href=\"javascript:formatemo(';)');\"><img src=\"gfx/emoticons/face-wink.gif\" alt=\";)\" border=\"0\" /></a>
<form id=\"editw\" name=\"editw\" action=\"forum.php?act=3\" method=\"post\">
<input name=\"fid\" value=\"$id\"type=\"hidden\" />
Subject:<br>
<input name=\"title\" maxlength=\"30\" type=\"textarea\" />
<br><br>
<textarea name=\"pdata\" id=\"pdata\" style=\"height: 300px; width: 550px; background:#FFFFFF\"></textarea><br><br>
<input type=\"submit\" name=\"psubmit\" value=\"Create\"/>
</form>
</div>
<div class=\"editorheader\">
<a class=\"threadtitlelink\" href=\"forum.php?act=6&showforum=$id\">Cancel new thread</a>
</div>
");
}
//New Reply Form Generator
function newreply($thread, $forum, $sitetitle)
{
generatenavigation($forum, $sitetitle);
echo("
<div class=\"editorheader\">
Reply to a thread
</div>
<div class=\"editorstack\">
<a href=\"javascript:formaturl();\"><img src=\"gfx/link.gif\" alt=\"Insert Link\" border=\"0\" /></a>
<a href=\"javascript:formatimg();\"><img src=\"gfx/image.gif\" alt=\"Insert Image\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':angel:');\"><img src=\"gfx/emoticons/face-crying.gif\" alt=\":angel:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':devil:');\"><img src=\"gfx/emoticons/face-devil-grin.gif\" alt=\":devil:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':glasses:');\"><img src=\"gfx/emoticons/face-glasses.gif\" alt=\":glasses:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':kiss:');\"><img src=\"gfx/emoticons/face-kiss.gif\" alt=\":kiss:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':monkey:');\"><img src=\"gfx/emoticons/face-monkey.gif\" alt=\":monkey:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':mellow:');\"><img src=\"gfx/emoticons/face-plain.gif\" alt=\":mellow:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':(');\"><img src=\"gfx/emoticons/face-sad.gif\" alt=\":(\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':D');\"><img src=\"gfx/emoticons/face-smile-big.gif\" alt=\":D\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':)');\"><img src=\"gfx/emoticons/face-smile.gif\" alt=\":)\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':o');\"><img src=\"gfx/emoticons/face-surprise.gif\" alt=\":o\" border=\"0\" /></a>
<a href=\"javascript:formatemo(';)');\"><img src=\"gfx/emoticons/face-wink.gif\" alt=\";)\" border=\"0\" /></a>
<form id=\"editw\" name=\"editw\" action=\"forum.php?act=4\" method=\"post\">
<br><br>
<textarea name=\"pdata\" id=\"pdata\" style=\"height: 300px; width: 550px; background:#FFFFFF\"></textarea><br><br>
<input type=\"submit\" name=\"psubmit\" value=\"Post\" />
<input name=\"fid\" value=\"$forum\"type=\"hidden\" />
<input name=\"tid\" value=\"$thread\"type=\"hidden\" />
</form>
</div>
<div class=\"editorheader\">
<a class=\"threadtitlelink\" href=\"forum.php?act=6&showforum=$fid&thread=$tid\">Cancel reply</a>
</div>
");
echo("</div>");
}
//Post Edit Form Generator
function newedit($forum, $thread, $post, $sitetitle)
{
$path = "forum/forums/$forum/threads/$thread/$post";
include_once($path);
$pcontent=str_replace("<br />","",$pcontent);
generatenavigation($forum, $sitetitle);
echo("
<div class=\"editorheader\">
Edit a post
</div>
<div class=\"editorstack\">
<a href=\"javascript:formaturl();\"><img src=\"gfx/link.gif\" alt=\"Insert Link\" border=\"0\" /></a>
<a href=\"javascript:formatimg();\"><img src=\"gfx/image.gif\" alt=\"Insert Image\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':angel:');\"><img src=\"gfx/emoticons/face-crying.gif\" alt=\":angel:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':devil:');\"><img src=\"gfx/emoticons/face-devil-grin.gif\" alt=\":devil:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':glasses:');\"><img src=\"gfx/emoticons/face-glasses.gif\" alt=\":glasses:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':kiss:');\"><img src=\"gfx/emoticons/face-kiss.gif\" alt=\":kiss:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':monkey:');\"><img src=\"gfx/emoticons/face-monkey.gif\" alt=\":monkey:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':mellow:');\"><img src=\"gfx/emoticons/face-plain.gif\" alt=\":mellow:\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':(');\"><img src=\"gfx/emoticons/face-sad.gif\" alt=\":(\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':D');\"><img src=\"gfx/emoticons/face-smile-big.gif\" alt=\":D\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':)');\"><img src=\"gfx/emoticons/face-smile.gif\" alt=\":)\" border=\"0\" /></a>
<a href=\"javascript:formatemo(':o');\"><img src=\"gfx/emoticons/face-surprise.gif\" alt=\":o\" border=\"0\" /></a>
<a href=\"javascript:formatemo(';)');\"><img src=\"gfx/emoticons/face-wink.gif\" alt=\";)\" border=\"0\" /></a>
<form id=\"editw\" name=\"editw\" action=\"forum.php?act=10\" method=\"post\">
<input name=\"fid\" value=\"$forum\"type=\"hidden\" />
<input name=\"tid\" value=\"$thread\"type=\"hidden\" />
<input name=\"pid\" value=\"$post\"type=\"hidden\" />
<br><br>
<textarea name=\"pdata\" id=\"pdata\" style=\"height: 300px; width: 550px; background:#FFFFFF\">");
echo($pcontent);
echo("</textarea><br><br>
<input type=\"submit\" name=\"psubmit\" value=\"Edit\" />
</form>
</div>
<div class=\"editorheader\">
<a class=\"threadtitlelink\" href=\"forum.php?act=6&showforum=$fid&thread=$tid\">Cancel edit</a>
</div>
");
}
//Register Form Generator
function newmember()
{
echo("
<br><br><a class=\"headlink\" href=\"forum.php?act=6\">" . $sitetitle . "</a>\n
<div class=\"editorheader\">
Terms and conditions
</div>
<div class=\"editorstack\">
<span class=\"subtitle\">
<b>By registering on this forum you agree to the following:</b><br />
</span>
<span class=\"smallfont\">
\"site\" shall be defined as all documents in the directory and subdirectories that this file is located in.<br />
\"authors\" throughout this site will be defined as the programmers who wrote Scribe.<br />
\"owners\" throughout this site will be defined as the person(s) who have uploaded this copy of Scribe.<br />
<br />
I am 13 years of age or older.<br />
I will not participate in or attempt to exploit any part of this site.<br />
I understand that the authors have taken every precaution to protect my information.<br />
I understand that the authors keep any information I submit, excluding my username and forum contributions in a state that cannot be reversed by anyone.<br />
I will not hold the authors accountable for any loss of data that may occur on this site.<br />
I understand that the owners reserve the right to delete any information I submit without prior notice<br />
Should I experience anything that offends me I agree to not hold the authors or owners of the site accountable.<br />
I understand that the terms and conditions listed above are subject to change without notice.<br />
</span>
</div>
<div class=\"editorheader\">
Register
</div>
<div class=\"editorstack\">
<form id=\"Register\" action=\"forum.php?act=7\" method=\"post\">
<span class=\"smallfont\">Username:</span><input maxlength=\"12\" name=\"username\" type=\"text\" /><br />
<span class=\"smallfont\">Password:</span><input maxlength=\"32\" name=\"password\" type=\"password\" /><br />
<span class=\"smallfont\">Confirm Password:</span><input maxlength=\"32\" name=\"cpassword\" type=\"password\" /><br />
<span class=\"smallfont\">Email:</span><input maxlength=\"50\" name=\"email\" type=\"text\" /><br />
<input type=\"submit\" name=\"confirm\" value=\"Register\" />
</div>
<div class=\"editorheader\">
<a class=\"threadtitlelink\" href=\"forum.php?act=6\">Cancel registration</a>
</div>
</form>
");
}
//Post Lister
function listposts($thread, $forum, $sitetitle)
{
//Open the thread directory and list all the thread folders
$dir = "forum/forums/" . $forum . "/threads/" . $thread;
$dir = str_replace("\'", "'", $dir);
//How many posts per page
$cutoff = 5;
$page = 0;
if(!isset($_GET['page']))
{
$reqpage=1;
}
else
{
$reqpage=$_GET['page'];
}
$now = 0;
if(file_exists($dir))
{
//include info.php file for thread
include_once($dir . "/info.php");
}
//echo navigation and options
generatenavigation($forum, $sitetitle);
//echo threatitle
echo("<div class=\"threadtitle\">" . $threadtitle . "</div>");
if(file_exists($dir))
{
$dh = opendir($dir);
while (($filename = readdir($dh)))
{
if($filename != "." && $filename != ".." && $filename != "info.php")
{
$files[] = $dir . "/" . $filename;
$reached++;
}
}
if($files[0]!=null)
{
while($now < $reached)
{
//filter stuff for edit button
$pdit = str_replace("forums/forum/" . $forum . "/threads/","",$print);
$pdit = str_replace("/" . $thread,"",$pdit);
$pdit = str_replace($thread . "/","",$pdit);
//include post content
$post= $files[$now];
if(file_exists($post))
{
if(is_readable($post))
{
include($post);
}
else
{
echo("File " . $files[now] ." is not readable");
}
}
else
{
echo("File " . $files[now] ." does not exist");
echo($post);
}
include_once($post);
$postfile = str_replace("forum/forums/$forum/threads/$thread/", "", $post);
//Pre display filtering
$pcontent = emoticonParse($pcontent);
$pcontent = specialParse($pcontent);
if($now%$cutoff==0)
{
$page++;
$pages[$now]=$now;
if($page==$reqpage)
{
$canlist = true;
}
else
{
$canlist = false;
}
}
if($canlist == true)
{
if($alternate==0)
{
echo("<div class=\"postinfo\">");
$alternate=1;
}
else
{
echo("<div class=\"postinfolight\">");
$alternate=0;
}
echo("<br><div class=\"postcontent\">" . $pcontent);
echo("<br>posted by " . $powner . " @ " . $detailstamp . "</div>");
//edit button if owner or admin
if($powner == $_SESSION['username'] || $_SESSION['rank']=="admin")
{
echo("<a href=\"forum.php?act=10&forum=" . $forum . "&thread=" . $_GET['thread'] . "&post=" . $postfile . "\"><img src=\"gfx/edit.gif\" alt=\"Edit Post\" border=\"none\"></a> ");
}
//delete button if admin
if($_SESSION['rank']=="admin")
{
echo("<a href=\"forum.php?act=9&forum=$forum&thread=$thread&post=$postfile\"><img src=\"gfx/delete.gif\" alt=\"Delete Post\" border=\"none\"></a> <a href=\"forum.php?act=12&username=" . $powner . "\"><img border=\"0\" src=\"gfx/member.gif\" alt=\" [Moderate]\"></a>");
}
echo("</div>");
}
$now++;
unset($posttitle);
}
}
else
{
echo("<div class=\"postinfo\"><div class=\"postcontent\"><br />There are no posts in this thread.<br /></div></div>");
}
//Page selector
if(!isset($pages))
{
$pages[0]=0;
}
sort($pages);
$pagekey=0;
echo("<div class=\"pagelist\">");
echo("Pages: ");
foreach($pages as $reserved)
{
$pagekey++;
if($pagekey==$reqpage)
{
echo(" <a href=\"forum.php?act=6&showforum=$forum&thread=$thread&page=$pagekey\">[$pagekey]</a>");
}
else
{
echo(" <a href=\"forum.php?act=6&showforum=$forum&thread=$thread&page=$pagekey\">$pagekey</a>");
}
}
echo("</div>"); echo("<div class=\"threadtitle\"><a class=\"threadtitlelink\" href=\"forum.php?act=4&thread=" . $thread . "&forum=" . $forum . "\"><img src=\"gfx/reply.gif\" alt=\"Reply\" border=\"0\" />Reply</a>\n\n<a class=\"threadtitlelink\" href=\"forum.php?act=3&showforum=" . $forum . "\"><img src=\"gfx/document-new.gif\" alt=\"New Thread\" border=\"0\" />New Thread</a>\n\n</div>\n\n");
}
}
//Thread Lister
function listthreads($id, $sitetitle)
{
//Build paths
$forumid = $id;
$forumpath = "forum/forums/" . $forumid . "/threads";
$foruminfopath = $forumpath . "/info.php";
$counter = 0;
//How many threads per page
$cutoff = 20;
if(!isset($_GET['page']))
{
$reqpage=0;
}
else
{
$reqpage=$_GET['page'];
}
$reqpage++;
$now = 0;
//Create array with sorted files
$dh = opendir($forumpath);
while (false !== ($filename = readdir($dh)))
{
if($filename != "." && $filename != "..")
{
$path = $forumpath . "/" . $filename . "/info.php";
$paths[$counter] = $path;
$mod[$counter] = filemtime($path);
$tid[$counter] = $filename;
$counter++;
}
}
if($counter>0)
{
//List pages
echo("<div class=\"pagelist\">");
echo("Pages: ");
for($pagecount=0; $pagecount<$counter/$cutoff; $pagecount++)
{
if($pagecount==$reqpage-1)
{
echo(" <a href=\"forum.php?act=6&showforum=" . $id . "&page=" . $pagecount . "\">[" . $pagecount . "]</a>");
}
else
{
echo(" <a href=\"forum.php?act=6&showforum=" . $id . "&page=" . $pagecount . "\">" . $pagecount . "</a>");
}
}
echo("</div>");
//Thread table headers
?>
<div class="threadheader">
<table class="threadtable">
<tr>
<td class="thread"><b>Thread</b></td>
<td class="lastpost"><b>Last Post</b></td>
</tr>
</table>
</div>
<?
//Sort parallel arrays by modified date
$keys = array_keys($mod);
$tempmod=$mod;
array_multisort($mod, $keys, $paths);
array_multisort($tempmod, $keys, $tid);
$mod=array_reverse($mod);
$paths=array_reverse($paths);
$tid=array_reverse($tid);
//List threads!
for($times=$cutoff*($reqpage-1); $times<$cutoff*$reqpage; $times++)
{
if($times<$counter)
{
$linkto = $tid[$times];
$sincethen = (date("U") - filemtime($paths[$times]))/3600;
$sincethen = round($sincethen,0);
include($paths[$times]);
echo("<div id=\"S" . $linkto . "E\" class=\"threadheader\">");
//Javascript stuff
echo("<table class=\"threadtable\"><tr><td class=\"thread\"><a href=\"forum.php?act=6&showforum=" . $id . "&thread=" . $linkto . "\">" . $threadtitle . "</a> by " . $author);
echo("<a href=\"javascript:mark('S" . $linkto . "E', '" . $id . "')\"><img border=\"0\" src=\"gfx/flag.gif\" alt=\" [Flag]\" /></a>");
if($_SESSION['rank']=="admin")
{
echo("<a href=\"javascript:inlineDelete('" . $forumid . "','" . $linkto . "');\"><img border=\"0\" src=\"gfx/delete.gif\" alt=\" [Delete]\"></a>");
echo(" <a href=\"forum.php?act=12&username=" . $author . "\"><img border=\"0\" src=\"gfx/member.gif\" alt=\" [Moderate]\"></a>");
}
//echo("<span onmouseover=\"tswitch('" . $linkto . "')\"> [Info]</a>");
echo("</td>");
echo("<td class=\"lastpost\">" . $latest . " -" . $sincethen . " hrs");
if($_SESSION['rank']=="admin")
{
echo(" <a href=\"forum.php?act=12&username=" . $latest . "\"><img border=\"0\" src=\"gfx/member.gif\" alt=\" [Moderate]\"></a>");
}
echo("</tr></table></div>");
unset($threadtitle, $linkto, $author);
}
}
//List pages
echo("<div class=\"pagelist\">");
echo("Pages: ");
for($pagecount=0; $pagecount<$counter/$cutoff; $pagecount++)
{
if($pagecount==$reqpage-1)
{
echo(" <a href=\"forum.php?act=6&showforum=" . $id . "&page=" . $pagecount . "\">[" . $pagecount . "]</a>");
}
else
{
echo(" <a href=\"forum.php?act=6&showforum=" . $id . "&page=" . $pagecount . "\">" . $pagecount . "</a>");
}
}
echo("</div>");
}
else
{
echo("<!--No threads to display in this forum-->");
}
}
//Forum Lister
function listforums($id, $sitetitle)
{
//Build paths
$forumid = $id;
$forumpath = "forum/forums/" . $forumid;
$foruminfopath = $forumpath . "/info.php";
//Generate navigation
generatenavigation($id, $sitetitle);
//Echo action bar
echo("<div class=\"threadtitle\">
<a class=\"threadtitlelink\" href=\"forum.php?act=3&showforum=" . $id . "\"><img src=\"gfx/document-new.gif\" alt=\"New Thread\" border=\"0\" />New Thread</a>\n\n</div>\n\n");
//Set up forum information
if(isset($id))
{
if(file_exists($foruminfopath))
{
include($foruminfopath);
if(!isset($children))
{
echo("<!--No subforums to report-->");
}
else
{
//Forum table headers
?>
<div class="forumheader">
<table class="threadtable">
<tr>
<td class="forumtitle"><b>Forum</b></td>
<td class="latestthread"><b>Latest Thread</b></td>
</tr>
</table>
</div>
<?
foreach($children as $index)
{
$subforuminfopath = "forum/forums/" . $index . "/info.php";
if($index!="")
{
if(file_exists($subforuminfopath))
{
unset($forumtitle);
include_once($subforuminfopath);
//Sub forum
echo("<div class=\"forumheader\"><table class=\"forumtable\"><tr><td class=\"forumtitle\"><img src=\"gfx/forum.gif\" alt=\"Forum\" /><a class=\"subforumlink\" href=\"forum.php?act=6&showforum=" . $index . "\">" . $forumtitle . "</a></td><td class=\"latestthread\">");
getlatestthread($index);
echo("</td></tr></table></div>\n\n");
unset($forumtitle);
}
else
{
echo("<!--Subforum info corrupted, unreadable or does not exist at location.-->");
}
}
else
{
echo("<!--Empty children array-->");
}
}
echo("<!--Subforums reported-->");
}
listthreads($id, $sitetitle);
}
else
{
echo("<!--Forum info corrupted, unreadable or does not exist at location.-->");
}
}
else
{
echo("<!--Empty forum id.-->");
}
//Echo action bar
echo("<div class=\"threadtitle\"><a class=\"threadtitlelink\" href=\"forum.php?act=3&showforum=" . $id . "\"><img src=\"gfx/document-new.gif\" alt=\"New Thread\" border=\"0\" />New Thread</a>\n\n</div>\n\n");
}
//Post Deletion
function deletepost($forum, $thread, $post)
{
$path = "forum/forums/$forum/threads/$thread/$post";
unlink($path);
}
//Thread Deletion
function deletethread($forum, $thread)
{
$dir = "forum/forums/" . $forum . "/threads/" . $thread;
if(file_exists($dir))
{
$indent = "";
for($x=$indentation; $x>0; $x--)
{
$indent = $indent . "+-";
}
foreach (glob($dir . "/*") as $file)
{
if(is_dir($file))
{
echo("<br />" . $indent . "<b>Directory: [" . $file . "] deleting...</b>");
$newindent = $indentation + 1;
cleardir($file, $newindent);
if(@rmdir($file)) //@ suppress the warning message
{
echo("<br />" . $indent . "<b>Directory: [" . $file . "] deleted!</b>");
}
else
{
echo("<br />Experienced problems deleting the directory [" . $file . "]");
}
}
else
{
if(@unlink($file))
{
echo("<br />" . $indent . "Deleted file: [" . $file . "]");
}
else
{
echo("<br />" . $indent . "Experienced problems deleting file: [" . $file . "]");
}
}
}
}
else
{
echo("<br />Directory not found. (did you add a trailing \"/\" ?)");
}
}
//Next Thread - Increment forum's thread counter and return new thread id
function nextthread($forum)
{
//Get next thread id
$nextpath = "forum/forums/" . $forum . "/next.php";
require($nextpath);
$counter = $latest;
$counter ++;
putcontents($nextpath,"<" ."?php \$latest=\"" . $counter . "\" ?" . ">","w+");
return $counter;
}
//Navigation Generator
function generatenavigation($id, $sitetitle)
{
//Building paths
$forumpath = "forum/forums/" . $id;
$foruminfopath = $forumpath . "/info.php";
//The site root
echo("<a class=\"headlink\" href=\"forum.php?act=6\"><img src=\"gfx/home.gif\" alt=\"Home\" border=\"0\" />" . $sitetitle . "</a>\n");
if(file_exists($foruminfopath))
{
include($foruminfopath);
//The parents in order
if(isset($parent))
{
foreach($parent as $index)
{
if($index!=0)
{
$infopath = "forum/forums/" . $index . "/info.php";
unset($forumtitle);
include($infopath);
echo("<a class=\"headlink\" href=\"forum.php?act=6&showforum=" . $index . "\"> » " . $forumtitle . "</a>\n");
unset($forumtitle);
}
}
}
}
if($id>0)
{
//The current forum
$myinfopath = "forum/forums/" . $id . "/info.php";
unset($forumtitle);
include($myinfopath);
echo("<a class=\"headlink\" href=\"forum.php?act=6&showforum=" . $id . "\"> » " . $forumtitle . "</a>");
unset($forumtitle);
}
}
//Register New Member
function register($username, $password, $cpassword, $email)
{
/*Registration block
Notes:
1. checks for clashing information
2. if none, it writes new user info
What it outputs:
case "944facfeb153b4f01916a0f166fcc315":
$sorha = "eec187273c161bd619e11a273e3a010a";
$emaha = "Chris";
$accha = "c7b0bb234686117711013e0e1cb8b8ff";
break;
$sorha = stored password hash = password md5 hashed twice
$emaha = email = email of person
$accha = access code = hash of (username . author . password)
*/
if(strlen($username)>=12)
{
$username = substr($username, 0, 11);
}
//calculate stuff and output
$sorha = "<?php \$sorha = \"" . md5(md5($password)) . "\";";
$emaha = "\$emaha = \"" . md5($email) . "\";";
$accha = "\$accha = \"" . md5($username . md5(md5($email)) . $password) . "\";";
//This is the user's rank
$yonk = "\$yonk = \"member\"; ?>";
//Data block to write
$block = $sorha . "\n" . $emaha . "\n" . $accha . "\n" . $yonk . "\n";
$dir = dir("users");
$user = md5($_POST['username']) . ".php";
$path = "users/" . $user;
$exists = file_exists("users/" . $user);
if($_POST['password']!=$_POST['cpassword'])
{
$match = "no";
}
if($_POST['password']=="" || $_POST['username']=="")
{
$ablank = "yes";
}
else
{
$ablank = "no";
}
//Check users directory for existing files
if( $exists == "1")
{
echo("<br><br>Sorry but the username " . $_POST['username'] . " already exists!<br><br>");
}
elseif( $match == "no")
{
echo("<br><br>Passwords did not match!<br><br>");
}
elseif( $ablank == "yes")
{
echo("You need to enter both a username and a password.");
}
else
{
//write to user login file
$lfpath = "users/" . md5($_POST['username']);
$lfpath = $lfpath . ".php";
putcontents($lfpath, $block, 'w+');
//write to user list
$upath="regged/" . $_POST['username'] . ".php";
$data= "\n <br> \n <br> Username: \n <br> " . $_POST['username'];
putcontents($upath, $data, 'w+');
echo(
"<span class=\"smallfont\"><br>Thank you for registering.<br>
You may now log in with your details<br><br></span>
</div>
");
}
$dir->close();
}
function changeranks($member, $rank)
{
if($_SESSION['rank']=="admin")
{
if($member!="" && $rank!="")
{
//Check users directory for existing files
$user = md5($member) . ".php";
$path = "users/" . $user;
$exists = file_exists("users/" . $user);
if( $exists == "1")
{
//including old user data file
include_once("users/" . $user);
$path = "users/" . $user;
//calculate stuff and output
$pha = "<?";
$phb = "php";
$sorha = " \$sorha = \"" . $sorha . "\";";
$emaha = "\$emaha = \"" . $emaha . "\";";
$accha = "\$accha = \"" . $accha . "\";";
$yonk = "\$yonk = \"" . $rank . "\"; ?>";
$block = $sorha . "\n" . $emaha . "\n" . $accha . "\n" . $yonk;
//write to user data file
putcontents($path, $pha, 'w');//First erase and put half <?php
putcontents($path, $phb, 'a');//Append php to the previous <?
putcontents($path, $block, 'a');//Dump the rest of the file
//report success
echo(
$member . "'s rank has been changed to \"" . $rank . "\"");
}
else
{
echo("<div class=\"pagesubtitle\">Error</div>Could not find users/" . $user);
}
}
}
}
function getlatestthread($forum)
{
$dir = "forum/forums/" . $forum . "/threads";
$dir = str_replace("\'", "'", $dir);
$found = false;
$lastlatesttime = 0;
$temp;
if(file_exists($dir))
{
$dh = opendir($dir);
while (($folder = readdir($dh)))
{
if($folder != "." && $folder != "..")
{
$path = "forum/forums/" . $forum . "/threads/" . $folder . "/info.php";
@include($path);
if($latesttime>$lastlatesttime)
{
$temp = $folder;
$found = true;
}
}
}
if($found)
{
include($path);
$sincethen = (date("U") - filemtime($path))/3600;
$sincethen = round($sincethen,2);
echo("<a href=\"forum.php?act=6&showforum=" . $forum ."&thread=" . $temp . "\">" . $threadtitle . "</a><br />");
echo($latest . " -" . $sincethen . " hrs");
}
else
{
echo("No threads in forum");
}
}
}
function getfirstpost($thread, $forum)
{
//Open the thread directory and list all the thread folders
$dir = "forum/forums/" . $forum . "/threads/" . $thread;
$dir = str_replace("\'", "'", $dir);
$continue=true;
if(file_exists($dir))
{
$dh = opendir($dir);
while (($filename = readdir($dh))&&$continue==true)
{
if($filename != "." && $filename != ".." && $filename != "info.php")
{
//Include post file
include_once($dir . "/" . $filename);
if($powner!="" && $pcontent!="")
{
echo($powner . " said:<br />" . emoticonparse(specialparse($pcontent)));
}
else
{
echo("No first post");
}
$continue=false;
}
}
}
}
function getlastpost($thread, $forum)
{
//Open the thread directory and list all the thread folders
$dir = "forum/forums/" . $forum . "/threads/" . $thread;
$dir = str_replace("\'", "'", $dir);
$at=0;
if(file_exists($dir))
{
$dh = opendir($dir);
while (($filename = readdir($dh)))
{
if($filename != "." && $filename != ".." && $filename != "info.php")
{
$filearray[$at] = $filename;
$at++;
}
}
rsort($filearray);
include_once($dir . "/" . $filearray[0]);
if($powner!="" && $pcontent!="")
{
echo($powner . " said:<br />" . emoticonparse(specialparse($pcontent)));
}
else
{
echo("No last post");
}
}
else
{
echo("Directory does not exist: \"" . $dir . "\"");
}
}
function deleteuser($user)
{
//Check if user exists
$userdata = 'users/' . md5($user) . ".php";
if (file_exists($userdata))
{
//Delete main user file
unlink("users/" . md5($user) . ".php");
//Delete user listing
unlink("regged/" . $user . ".php");
echo("
<div class=\"pagesubtitle\">
Account Deleted
</div>" .
$user .
"'s account has been deleted.
");
}
else
{
echo("<div class=\"pagesubtitle\">No such user found</div><br />" . $user . " does not exist.");
}
}
function getForumInfo($forum)
{
include("forum/forums/" . $forum . "/info.php");
$next=0;
$dh = opendir("forum/forums");
while (false !== ($filename = readdir($dh)))
{
if($filename != "." && $filename != "..")
{
$next++;
}
}
echo("<div class=\"pagesubtitle\">Selected</div>" . $forumtitle);
echo("<div class=\"pagesubtitle\">ID</div>");
echo($forumid);
echo("<div class=\"pagesubtitle\">Parents</div>");
if(isset($parent))
{
foreach($parent as $dad)
{
echo("»" . $dad);
}
}
else
{
echo("No parents");
}
echo("<div class=\"pagesubtitle\">Children</div>");
if(isset($children))
{
foreach($children as $mum)
{
echo($mum . "<br />");
}
}
else
{
echo("No children");
}
//Information to create new subforum
echo("<div class=\"pagesubtitle\">New subforum</div>");
echo("To manually create a new subforum here, create a new folder \"forum/forums/" . $next . "\" and \"forum/forums/" . $next . "/threads\". Then, create an next.php file in the \"" . $next . "\" folder with the contents:<br /><br />\"<?php \$latest=\"0\" ?>\"<br /><br />and a \"info.php\" file with the following contents:<br /><br />");
echo("\$forumtitle=\"New Subforum\";<br />");
echo("\$forumid=\"" . $next . "\";<br />");
$index = -1;
if(isset($parent))
{
foreach($parent as $list)
{
$index++;
echo("\$parent[" . $index . "]=" . $list . ";<br />");
}
}
$index++;
echo("\$parent[" . $index . "]=" . $forum . ";<br /><br />Finally, CHMOD all the files you have created to 777.");
//Information to delete forum
echo("<div class=\"pagesubtitle\">Delete forum</div>");
$lowest = @array_pop($parent);
unset($forumtitle, $forumid, $parent, $children);
if($lowest===null)
{
echo("This is your master forum. You cannot delete it.");
}
else
{
include("forum/forums/" . $lowest . "/info.php");
echo("To manually delete this forum, locate \"forum/forums/" . $forum . "\" and delete it. Then, locate \"forum/forums/" . $lowest . "/info.php\" and change its contents to:<br /><br />");
echo("\$forumtitle=\"" . $forumtitle . "\";<br />");
echo("\$forumid=\"" . $lowest . "\";<br />");
$tindex = 0;
if(isset($parent))
{
foreach($parent as $list)
{
echo("\$parent[" . $tindex . "]=" . $list . ";<br />");
$tindex++;
}
}
$childcount=0;
if(isset($children))
{
foreach($children as $mum)
{
if($mum!=$forum)
{
echo("\$children[" . $childcount . "]=" . $mum . ";<br />");
$childcount++;
}
}
}
}
}
function forumlist()
{
$dh = opendir("forum/forums");
while (false !== ($filename = readdir($dh)))
{
if($filename != "." && $filename != "..")
{
include("forum/forums/" . $filename . "/info.php");
echo("<a href=\"forum.php?act=14&target=" . $filename . "\">" . $filename . " - " . $forumtitle . "</a><br />");
unset($forumtitle, $forumid, $parent, $children);
}
}
}
?>