Location: PHPKode > projects > AnoBBS 3DES encrypted forum and communication repository > anobbs-3des-encrypted-forum-and-communication-repository/progs/bbsFunctions.php
<?PHP
################################################################################################
## AnoBBS functions. # v. 1.0 mlk #  Coded by Knut Møgster 2008 | http://www.redesign.no      ##
################################################################################################

## Text safing, we don't use it - everything is encypted ##
function htmlxmls($text) {
	$text = str_replace("'", "&apos;", $text);
	return $text;
}

## Check whether a value is hex
function isHex($text) {
	$text = strip_tags($text);
	$tlen = strlen($text);
	if($tlen < 3) {
		return "";
	}
	if(substr($text, 0, 2) != "0x") {
		return "";
	}
	$scl = substr($text, 2, $tlen);
	$snk = preg_match('/^[+-]?[0-f]+$/', $scl);
	if($snk == 1) {
		return $text;
		} else {
		return "";
	}
}

## Clean up the c and z switch input (and other char values) ##
function cleanC($C) {
	$C = substr($C, 0, 7);
	$C = ereg_replace("[^[:alpha:]]", "", $C);
	return(trim(htmlspecialchars($C)));
}

## Check whether a value is md5 ##
function is_md5($cvalue) {
	$cvalue = htmlspecialchars(strip_tags(substr($cvalue, 0, 32)));
	$sbk = preg_match('/^[+-]?[0-f]+$/', $cvalue);
	if($sbk == 1) {
		if(strlen($cvalue) == 32) {
			return $cvalue;
			} else {
			return "";
		}
		} else {
		return "";
	}
}

## Check whether a value is numerical
function xisNum($text) {
	$text = strip_tags($text);
	$text = trim($text);
	if(!is_numeric($text)) {
		return "";
	}
	return $text;
}

## Function for returning one xml field
function ret_xmlfield($tag, $tstr) {
	$dprt1 = explode("</".$tag.">", $tstr);
	$dprt2 = explode("<".$tag.">", $dprt1[0]);
	$rstr = $dprt2[1];
	return trim($rstr);
}

## Function for updating one xml field in a piece of xml where units are unique
function put_xmlfield($tag, $tstr, $tupdate) {
	$tupdate = htmlxmls($tupdate);
	$tupdated = "<".$tag.">".$tupdate."</".$tag.">";
	$dprt1 = explode("</".$tag.">", $tstr);
	$dprt2 = explode("<".$tag.">", $dprt1[0]);
	$rstr = $dprt2[0].$tupdated.$dprt1[1];
	return $rstr;
}

function updateBBS($bbsxmlfile, $bbsxmlstring) {
	if(file_exists($bbsxmlfile)) {
		$fp = fopen($bbsxmlfile, "w");
		$fw = fwrite($fp, $bbsxmlstring);
		fclose($fp);
	}
}

## Some parse functions
function parseforumtopicXML($dxml) {
	$txarr = array();
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumtopics>", $dxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = topics
	$dxmlarr2 = explode("<acforumtopics>", $dxmlarr1[0]);
	## Fetch topics, returns array $dxmlarr3 for loop and return
	$dxmlarr3 = explode("</acforumtopic>", $dxmlarr2[1]);
	return $dxmlarr3;
}

function parseforumXML($dxml) {
	$txarr = array();
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforum>", $dxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = topics
	$dxmlarr2 = explode("<acforum>", $dxmlarr1[0]);
	return $dxmlarr2[1];
}

## Update userdata timestamp and replies
function updUser($xuname, $cxml, $npost) {
	$txarr = array();
	$xtst = time();
	$dchk = 0;
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumusers>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = users
	$dxmlarr2 = explode("<acforumusers>", $dxmlarr1[0]);
	## Produce the user array
	$dxmlarr3 = explode("<acforumuser>", $dxmlarr2[1]);
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("acusername", $dxmlarr3[$o])) == $xuname) {
			$dxmlarr3[$o] =  put_xmlfield("acuserstamp", $dxmlarr3[$o], $xtst);
			if($npost == "new") {
				$rtnum = trim(ret_xmlfield("acusereplies", $dxmlarr3[$o]));
				$dxmlarr3[$o] =  put_xmlfield("acusereplies", $dxmlarr3[$o], $rtnum+1);
			}
			$dchk = 1;
		}
	}
	$dxmlarrstr = implode("<acforumuser>", $dxmlarr3);
	return $dxmlarr2[0]."<acforumusers>".$dxmlarrstr."</acforumusers>".$dxmlarr1[1];
}

## Update userlevel
function updUserlevel($xuname, $ulevel, $cxml) {
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumusers>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = users
	$dxmlarr2 = explode("<acforumusers>", $dxmlarr1[0]);
	## Produce the user array
	$dxmlarr3 = explode("<acforumuser>", $dxmlarr2[1]);
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("acusername", $dxmlarr3[$o])) == $xuname) {
			$dxmlarr3[$o] =  put_xmlfield("acuserlevel", $dxmlarr3[$o], $ulevel);
		}
	}
	$dxmlarrstr = implode("<acforumuser>", $dxmlarr3);
	return $dxmlarr2[0]."<acforumusers>".$dxmlarrstr."</acforumusers>".$dxmlarr1[1];
}

## Update topic status
function updTopicstatus($xtid, $xtstus, $cxml) {
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumtopics>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = topics
	$dxmlarr2 = explode("<acforumtopics>", $dxmlarr1[0]);
	## Produce the topic array
	$dxmlarr3 = explode("<acforumtopic>", $dxmlarr2[1]);
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("actid", $dxmlarr3[$o])) == $xtid) {
			$dxmlarr3[$o] =  put_xmlfield("actopicstatus", $dxmlarr3[$o], $xtstus);
		}
	}
	$dxmlarrstr = implode("<acforumtopic>", $dxmlarr3);
	return $dxmlarr2[0]."<acforumtopics>".$dxmlarrstr."</acforumtopics>".$dxmlarr1[1];
}

## Update topic title in forum file after edit ##
function updForumTopic($xtsubject, $xtid, $cxml) {
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumtopics>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = topics
	$dxmlarr2 = explode("<acforumtopics>", $dxmlarr1[0]);
	## Produce the topic array
	$dxmlarr3 = explode("<acforumtopic>", $dxmlarr2[1]);
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("actid", $dxmlarr3[$o])) == $xtid) {
			$dxmlarr3[$o] =  put_xmlfield("actopictitle", $dxmlarr3[$o], $xtsubject);
		}
	}
	$dxmlarrstr = implode("<acforumtopic>", $dxmlarr3);
	return $dxmlarr2[0]."<acforumtopics>".$dxmlarrstr."</acforumtopics>".$dxmlarr1[1];
}

## Update topic sticky
function updTopicsticky($xtid, $xtstick, $cxml) {
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumtopics>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = topics
	$dxmlarr2 = explode("<acforumtopics>", $dxmlarr1[0]);
	## Produce the topic array
	$dxmlarr3 = explode("<acforumtopic>", $dxmlarr2[1]);
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("actid", $dxmlarr3[$o])) == $xtid) {
			$dxmlarr3[$o] =  put_xmlfield("actopicsticky", $dxmlarr3[$o], $xtstick);
		}
	}
	$dxmlarrstr = implode("<acforumtopic>", $dxmlarr3);
	return $dxmlarr2[0]."<acforumtopics>".$dxmlarrstr."</acforumtopics>".$dxmlarr1[1];
}

function delTopic($xtid, $cxml) {
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumtopics>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = topics
	$dxmlarr2 = explode("<acforumtopics>", $dxmlarr1[0]);
	## Produce the topic array
	$dxmlarr3 = explode("<acforumtopic>", $dxmlarr2[1]);
	$tpcstr = "";
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("actid", $dxmlarr3[$o])) != "") {
			if(trim(ret_xmlfield("actid", $dxmlarr3[$o])) != $xtid) {
				$tpcstr .= "\t\t<acforumtopic>\n\t\t\t".trim($dxmlarr3[$o])."\n";
			}
		}
	}
	return trim($dxmlarr2[0])."\n\t<acforumtopics>\n".$tpcstr."\t</acforumtopics>\n".trim($dxmlarr1[1]);
}

## Logout function ##
function xlogOut($xusername, $seedz, $cxml) {
	## Delete from usersessions
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumessions>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = users
	$dxmlarr2 = explode("<acforumessions>", $dxmlarr1[0]);
	## Produce the user array
	$dxmlarr3 = explode("<acusersession>", $dxmlarr2[1]);
	$tpcstr = "";
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("acusersessname", $dxmlarr3[$o])) != "") {
			if(trim(ret_xmlfield("acusersessname", $dxmlarr3[$o])) != $xusername) {
				$tpcstr .= "\t\t<acusersession>\n\t\t\t".trim($dxmlarr3[$o])."\n";
			}
		}
	}
	return trim($dxmlarr2[0])."\n\t<acforumessions>\n".$tpcstr."\t</acforumessions>\n\t".trim($dxmlarr1[1]);
}

## Check if user session exists ##
function checkSession($xseed, $cxml) {
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumessions>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = sessions
	$dxmlarr2 = explode("<acforumessions>", $dxmlarr1[0]);
	## Produce the sess array
	$dxmlarr3 = explode("<acusersession>", $dxmlarr2[1]);
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("acusersessionid", $dxmlarr3[$o])) != "") {
			if(trim(ret_xmlfield("acusersessionid", $dxmlarr3[$o])) == $xseed) {
				$sessID = trim(ret_xmlfield("acusersessionid", $dxmlarr3[$o]));
				$sessAuth = trim(ret_xmlfield("acusersessionauth", $dxmlarr3[$o]));
				return array($sessID,$sessAuth);
			}
		}
	}
	return array("","");
}

## Delete user ##
function delUser($xusername, $cxml) {
	## Delete from usersessions
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumessions>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = users
	$dxmlarr2 = explode("<acforumessions>", $dxmlarr1[0]);
	## Produce the user array
	$dxmlarr3 = explode("<acusersession>", $dxmlarr2[1]);
	$tpcstr = "";
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("acusersessname", $dxmlarr3[$o])) != "") {
			if(trim(ret_xmlfield("acusersessname", $dxmlarr3[$o])) != $xusername) {
				$tpcstr .= "\t\t<acusersession>\n\t\t\t".trim($dxmlarr3[$o])."\n";
			}
		}
	}
	
	$cxml = trim($dxmlarr2[0])."\n\t<acforumessions>\n".$tpcstr."\t</acforumessions>\n\t".trim($dxmlarr1[1]);
	$dxmlarr3 = "";
	## Delete from usertable
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumusers>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = users
	$dxmlarr2 = explode("<acforumusers>", $dxmlarr1[0]);
	## Produce the user array
	$dxmlarr3 = explode("<acforumuser>", $dxmlarr2[1]);
	$tpcstr = "";
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("acusername", $dxmlarr3[$o])) != "") {
			if(trim(ret_xmlfield("acusername", $dxmlarr3[$o])) != $xusername) {
				$tpcstr .= "\t\t<acforumuser>\n\t\t\t".trim($dxmlarr3[$o])."\n";
			}
		}
	}
	return trim($dxmlarr2[0])."\n\t<acforumusers>\n".$tpcstr."\t</acforumusers>\n\t".trim($dxmlarr1[1]);
}

## Delete topic post (reply) ##
function delTopicpost($xtid, $xtpid, $cxml) {
	$trplies = trim(ret_xmlfield("actopicreplies", $cxml));
	$trplies = ($trplies-1);
	$cxml =  put_xmlfield("actopicreplies", $cxml, $trplies);
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumtopicreplies>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = replies
	$dxmlarr2 = explode("<acforumtopicreplies>", $dxmlarr1[0]);
	## Produce the reply array
	$dxmlarr3 = explode("<acforumtopicreply>", $dxmlarr2[1]);
	$tpcstr = "";
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("actreplyid", $dxmlarr3[$o])) != "") {
			if(trim(ret_xmlfield("actreplyid", $dxmlarr3[$o])) != $xtpid) {
				$tpcstr .= "\t\t<acforumtopicreply>\n\t\t\t".trim($dxmlarr3[$o])."\n";
			}
		}
	}
	return trim($dxmlarr2[0])."\n\t<acforumtopicreplies>\n".$tpcstr."\t</acforumtopicreplies>\n".trim($dxmlarr1[1]);
}

## Check whether a user is within time limit to update his post after edit ##
function chkTopicstamp($xtpid, $xdiff, $xtstate, $xulevel, $cxml) {
	if($xulevel == "user") {
		$chtime = (time()-$xdiff);
		switch($xtstate) {
			case "t":
			$retchkst = trim(ret_xmlfield("actopicdate", $retcontpix));
			if($retchkst > $chtime) {
				$txml = "<actopicedit>0</actopicedit>\n";
				$dxmtarr = explode("</acforumtopic>", $cxml);
				$spltxml = $dxmtarr[0].$txml."</acforumtopic>".$dxmtarr[1];
				return array(1, $spltxml);
				} else {
				return array(0, $cxml);
			}
			break;
			case "p":
			$dxmlarr1 = explode("</acforumtopicreplies>", $cxml);
			$dxmlarr2 = explode("<acforumtopicreplies>", $dxmlarr1[0]);
			$dxmlarr3 = explode("<acforumtopicreply>", $dxmlarr2[1]);
			for($o=0;$o<sizeof($dxmlarr3);$o++) {
				if(trim(ret_xmlfield("actreplyid", $dxmlarr3[$o])) != "") {
					if(trim(ret_xmlfield("actreplyid", $dxmlarr3[$o])) == $xtpid) {
						$pstime = trim(ret_xmlfield("actopicreplydate", $dxmlarr3[$o]));
						if($pstime > $chtime) {
							$txml = "<actopicedit>".$xtpid."</actopicedit>";
							$dxmtarr = explode("</acforumtopic>", $cxml);
							$spltxml = $dxmtarr[0].$txml."</acforumtopic>".$dxmtarr[1];
							return array(1, $spltxml);
							} else {
							return array(0, $cxml);
						}
					}
				}
			}
			break;
			default:
			return array(0, $cxml);
		}
		} else {
		switch($xtstate) {
			case "t":
			$txml = "<actopicedit>0</actopicedit>\n";
			$dxmtarr = explode("</acforumtopic>", $cxml);
			$spltxml = $dxmtarr[0].$txml."</acforumtopic>".$dxmtarr[1];
			return array(1, $spltxml);
			break;
			case "p":
			$txml = "<actopicedit>".$xtpid."</actopicedit>\n";
			$dxmtarr = explode("</acforumtopic>", $cxml);
			$spltxml = $dxmtarr[0].$txml."</acforumtopic>".$dxmtarr[1];
			return array(1, $spltxml);
			break;
			default:
			return array(0, $cxml);
		}
	}
}

## Loop through BBS dir for topics, return javascript array statements ##
function saveTopics($dcode) {
	global $bbsfiledir;
	$rjstr = "";
	if($dir = opendir($bbsfiledir."/".$dcode)) {
			$testbbs = $bbsfiledir."/".$dcode."/".$dcode.".xml";
			while (($file = readdir($dir)) !== false) {
			if (substr($file,-4) == ".xml") {
				if($bbsfiledir."/".$dcode."/".$file != $testbbs) {
					$grstxml = file_get_contents($bbsfiledir."/".$dcode."/".$file);
					$xtid = trim(ret_xmlfield("actid", $grstxml));
					$grstxml = str_replace("\n", "\\\n", $grstxml);
					$rjstr .= "tcxml[".$xtid."] = '".$grstxml."';\n";
				}
			}
		}
	}
	closedir($dir);
	return $rjstr;
}

## Loop through BBS dir for topics export, return xml ##
function exportTopics($dcode) {
	global $bbsfiledir;
	$rjstr = "";
	if($dir = opendir($bbsfiledir."/".$dcode)) {
			$testbbs = $bbsfiledir."/".$dcode."/".$dcode.".xml";
			while (($file = readdir($dir)) !== false) {
			if (substr($file,-4) == ".xml") {
				if($bbsfiledir."/".$dcode."/".$file != $testbbs) {
					$grstxml = file_get_contents($bbsfiledir."/".$dcode."/".$file);
					$dxparr1 = explode("</root>", $grstxml);
					$dxparr2 = explode("<root>", $dxparr1[0]);
					$dxparr3 = explode("</acforumtopic>", $dxparr2[1]);
					$rjstr .= "\n\t\t".trim($dxparr3[0])."\n\t\t".trim($dxparr3[1])."\n\t</acforumtopic>";
				}
			}
		}
	}
	$rjstr .= "\n";
	closedir($dir);
	return $rjstr;
}

## Filter topicdata for export ## 
function filterTopics($cxml) {
	$dxmtarr = explode("</acforumtopics>", $cxml);
	$dxmtarr2 = explode("<acforumtopics>", $dxmtarr[0]);
	return $dxmtarr2[0]."<acforumtopics></acforumtopics>".$dxmtarr[1];
}

## Filter sessondata for export ## 
function filterSessions($cxml) {
	$dxmtarr = explode("</acforumessions>", $cxml);
	$dxmtarr2 = explode("<acforumessions>", $dxmtarr[0]);
	return $dxmtarr2[0]."<acforumessions></acforumessions>".$dxmtarr[1];
}

## Get topics for import ## 
function zingTopics($icxml) {
	$dxmtarr = explode("</acforumtopics>", $icxml);
	$dxmtarr2 = explode("<acforumtopics>", $dxmtarr[0]);
	return trim($dxmtarr2[1]);
}

## Get users for import ## 
function zingUsers($icxml) {
	$dxmtarr = explode("</acforumusers>", $icxml);
	$dxmtarr2 = explode("<acforumusers>", $dxmtarr[0]);
	return trim($dxmtarr2[1]);
}

## Make topics on import ##
function makeTopics($xTopics, $dcode) {
	global $bbsfiledir,$prog_dir,$bbstopictemplate;
	$stickurls = array();
	$retbbstxmltempl = file_get_contents($prog_dir."/".$bbstopictemplate);
	$xtplarr1 = explode("</acforumtopic>", $retbbstxmltempl);
	$xtplarr2 = explode("<acforumtopic>", $xtplarr1[0]);
	## Do topic
	$tdxmlarr3 = explode("</acforumtopic>", $xTopics);
	for($o=0;$o<sizeof($tdxmlarr3);$o++) {
		$tdxmlarrtemp = explode("<acforumtopic>", $tdxmlarr3[$o]);
		$dturl = trim(ret_xmlfield("actopicurl", $tdxmlarrtemp[1]));
		if(file_exists($bbsfiledir."/".$dcode."/".$dturl)) {
			@unlink($bbsfiledir."/".$dcode."/".$dturl);
		}
		$cxml = $xtplarr2[0].$tdxmlarrtemp[1].$xtplarr1[1];
		makeTopicfile($bbsfiledir."/".$dcode."/".$dturl, $cxml);
		array_push($stickurls, $dturl);
	}
	return $stickurls;
}

function makeTopicfile($xfile, $cxml) {
	$fp = @fopen($xfile, "w");
	$fw = fwrite($fp, $cxml);
	fclose($fp);
}

## Insert new user session in session table
function createBBSusess($dcode, $dSeedz) {
	global $servIp,$servAgent,$bbsfiledir,$BBSsessruntime,$BBSsessruntime2,$strictm;
	if(file_exists($bbsfiledir."/".$dcode."/".$dcode.".xml")) {
		$retcontx = file_get_contents($bbsfiledir."/".$dcode."/".$dcode.".xml");
		$acfsessid = md5($servIp.$servAgent.$dSeedz);
		$sessxmltmpl = "\t\t<acusersession>
			<acusersessionid>^ACSID^</acusersessionid>
			<acusersessionauth>^ACSAUTH^</acusersessionauth>
			<acusersessname>^ACSNAME^</acusersessname>
			<acusersesstime>^ACSTIME^</acusersesstime>
			<acusersesstring>^ACSSTR^</acusersesstring>
		</acusersession>\n\t";
		$ir = time();
		$xct = md5($ir) . 
		md5($ir . $dSeedz) . 
		md5($ir . $dSeedz . md5("rockababy!")) .
		md5($ir . $dSeedz . md5("doobeedoobedoo!")) .
		md5($ir . $dSeedz . md5("beboprules?!")) .
		md5($ir . $dSeedz . md5("domeyeah!")) .
		md5($ir . $dSeedz . md5("oah-oah!!")) .
		md5($ir . $dSeedz . md5("digi-digi-digi..")) .
		md5($ir . $dSeedz . md5("hoodi-hoodi!")) .
		md5($ir . $dSeedz . md5("ohyeah!")) .
		md5($ir . $dSeedz . md5("googlegooglegoogle!")) .
		md5($ir . $dSeedz . md5("butitsnowornever!")) .
		md5($ir . $dSeedz . md5("hellno!")) .
		md5($ir . $dSeedz . md5("hellyes!")) .
		md5($ir . $dSeedz . md5("well...?"));
		$ns = md5($dSeedz . $ir);
		$finalgarth = $xct . $ns;
		$sessxmltmpl = str_replace("^ACSID^", $dSeedz, $sessxmltmpl);
		$sessxmltmpl = str_replace("^ACSAUTH^", $acfsessid, $sessxmltmpl);
		$sessxmltmpl = str_replace("^ACSTIME^", time(), $sessxmltmpl);
		$sessxmltmpl = str_replace("^ACSSTR^", $finalgarth, $sessxmltmpl);
		## Shave off the file end, return $dxmlarr1[0]
		$dxmlarr1 = explode("</acforumessions>", $retcontx);
		## $dxmlarr2[0] = header / $dxmlarr2[1] = sessions
		$dxmlarr2 = explode("<acforumessions>", $dxmlarr1[0]);
		$dxmlarr3 = explode("<acusersession>", $dxmlarr2[1]);
		$tpcstr = "\n";
		for($o=0;$o<sizeof($dxmlarr3);$o++) {
			if(trim(ret_xmlfield("acusersessionid", $dxmlarr3[$o])) != "") {
				if(trim(ret_xmlfield("acusersessionauth", $dxmlarr3[$o])) != $acfsessid) {
					if($strictm == "y") {
						if(trim(ret_xmlfield("acusersesstime", $dxmlarr3[$o])) > $BBSsessruntime) {
							$tpcstr .= "\t\t<acusersession>\n\t\t\t".trim($dxmlarr3[$o])."\n";
						}
						} else {
						if(trim(ret_xmlfield("acusersesstime", $dxmlarr3[$o])) > $BBSsessruntime) {
							$tpcstr .= "\t\t<acusersession>\n\t\t\t".trim($dxmlarr3[$o])."\n";
							} else {
							if((trim(ret_xmlfield("acusersessname", $dxmlarr3[$o])) != "^ACSNAME^") && (trim(ret_xmlfield("acusersesstime", $dxmlarr3[$o])) > $BBSsessruntime2)) {
								$tpcstr .= "\t\t<acusersession>\n\t\t\t".trim($dxmlarr3[$o])."\n";
							}
						}
					}
				}
			}
		}
		$tpcstr .= $sessxmltmpl;
		$bbsfilestr = trim($dxmlarr2[0])."\n\t<acforumessions>".$tpcstr."</acforumessions>\n\t".trim($dxmlarr1[1]);
		updateBBS($bbsfiledir."/".$dcode."/".$dcode.".xml", $bbsfilestr);
	}
}

## Create BBS dir & file ##
function createBBS($dcode, $dcsrC, $dcsrK, $dSeedz) {
	global $bbsfiledir,$prog_dir,$bbstemplate,$servIp,$servAgent;
	if(!file_exists($bbsfiledir."/".$dcode."/".$dcode.".xml")) {
		if(!is_dir($bbsfiledir."/".$dcode)){
			mkdir($bbsfiledir."/".$dcode);
		}
		$dcsrCb = hexToString($dcsrC);
		$dcsrCbdc = trim(TripleDES($dcsrK,$dcsrCb,0,0,$iv,""));
		$acfsessid = md5($servIp.$servAgent.$dSeedz);
		$retbbsxmltempl = file_get_contents($prog_dir."/".$bbstemplate);
		$doxmlbbs = str_replace("^ACFID^", $dcode, $retbbsxmltempl);
		$doxmlbbs = str_replace("^ACFTYPE^", "0", $doxmlbbs);
		$doxmlbbs = str_replace("^ACLIFESPAN^", "0", $doxmlbbs);
		$doxmlbbs = str_replace("^ACFILENAME^", $dcode.".xml", $doxmlbbs);
		$doxmlbbs = str_replace("^ACFORUMDATE^", time(), $doxmlbbs);
		$doxmlbbs = str_replace("^ACFORUMKEY^", $dcsrCbdc, $doxmlbbs);
		$sessxmltmpl = "	<acusersession>
			<acusersessionid>^ACSID^</acusersessionid>
			<acusersessionauth>^ACSAUTH^</acusersessionauth>
			<acusersessname>^ACSNAME^</acusersessname>
			<acusersesstime>^ACSTIME^</acusersesstime>
			<acusersesstring>^ACSSTR^</acusersesstring>
		</acusersession>\n\t";
		$sessxmltmpl = "\n\t".$sessxmltmpl;
		$ir = time();
		$xct = md5($ir) . 
		md5($ir . $dSeedz) . 
		md5($ir . $dSeedz . md5("rockababy!")) .
		md5($ir . $dSeedz . md5("doobeedoobedoo!")) .
		md5($ir . $dSeedz . md5("beboprules?!")) .
		md5($ir . $dSeedz . md5("domeyeah!")) .
		md5($ir . $dSeedz . md5("oah-oah!!")) .
		md5($ir . $dSeedz . md5("digi-digi-digi..")) .
		md5($ir . $dSeedz . md5("hoodi-hoodi!")) .
		md5($ir . $dSeedz . md5("ohyeah!")) .
		md5($ir . $dSeedz . md5("googlegooglegoogle!")) .
		md5($ir . $dSeedz . md5("butitsnowornever!")) .
		md5($ir . $dSeedz . md5("hellno!")) .
		md5($ir . $dSeedz . md5("hellyes!")) .
		md5($ir . $dSeedz . md5("well...?"));
		$ns = md5($dSeedz . $ir);
		$finalgarth = $xct . $ns;
		$sessxmltmpl = str_replace("^ACSID^", $dSeedz, $sessxmltmpl);
		$sessxmltmpl = str_replace("^ACSAUTH^", $acfsessid, $sessxmltmpl);
		$sessxmltmpl = str_replace("^ACSTIME^", time(), $sessxmltmpl);
		$sessxmltmpl = str_replace("^ACSSTR^", $finalgarth, $sessxmltmpl);
		## Shave off the file end, return $dxmlarr1[0]
		$dxmlarr1 = explode("</acforumessions>", $doxmlbbs);
		## $dxmlarr2[0] = header / $dxmlarr2[1] = topics
		$dxmlarr2 = explode("<acforumessions>", $dxmlarr1[0]);
		$bbsfilestr = $dxmlarr2[0]."<acforumessions>".$sessxmltmpl."</acforumessions>".$dxmlarr1[1];
		$fp = @fopen($bbsfiledir."/".$dcode."/".$dcode.".xml", "w");
		$fw = fwrite($fp, $bbsfilestr);
		fclose($fp);
	}
}

## Delete BBS ##
function delBBS($dcode) {
	global $bbsfiledir;
	if($dir = opendir($bbsfiledir."/".$dcode)) {
			while (($file = readdir($dir)) !== false) {
			if (substr($file,-4) == ".xml") {
				unlink($bbsfiledir."/".$dcode."/".$file);
			}
		}
	}
	closedir($dir);
	rmdir($bbsfiledir."/".$dcode);
}

## Function for filtering the XML return before transfer
function filterXML($cxml) {
	$cxml =  put_xmlfield("acforumpass", $cxml, "^ACFORUMPASS^");
	$cxml =  put_xmlfield("acforumadminpass", $cxml, "^ACFORUMADMINPASS^");
	$cxml =  put_xmlfield("acforumadminsessid", $cxml, "^ACFORUMADMINSESSID^");
	$cxml =  put_xmlfield("acforumkey", $cxml, "^ACFORUMKEY^");
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumusers>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = userlist
	$dxmlarr2 = explode("<acforumusers>", $dxmlarr1[0]);
	## Produce the user array
	$dxmlarr3 = explode("<acforumuser>", $dxmlarr2[1]);
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("acusername", $dxmlarr3[$o])) != "") {
			$dxmlarr3[$o] =  put_xmlfield("acuserpass", $dxmlarr3[$o], "^ACUSERPASS^");
		}
	}
	$dxmlarrstr = implode("<acforumuser>", $dxmlarr3);
	$cxml = $dxmlarr2[0]."<acforumusers>".$dxmlarrstr."</acforumusers>".$dxmlarr1[1];
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlsarr1 = explode("</acforumessions>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = sessions
	$dxmlsarr2 = explode("<acforumessions>", $dxmlsarr1[0]);
	## Produce final xml
	return $dxmlsarr2[0]."<acforumessions></acforumessions>".$dxmlsarr1[1];
}

## Return userdata for auth
function retUserxdata($susercode, $cxml) {
	$dchk = 0;
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumusers>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = topics
	$dxmlarr2 = explode("<acforumusers>", $dxmlarr1[0]);
	## Produce the user array
	$dxmlarr3 = explode("<acforumuser>", $dxmlarr2[1]);
	$retsUsrow = "";
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("acusername", $dxmlarr3[$o])) == $susercode) {
			$retsUsrow .= "<acforumuser>".$dxmlarr3[$o];
			$dchk = 1;
		}
	}
	## No user in usertables, we return 'none'
	if($dchk == 0) {
		$retsUsrow = "none";
	}
	return $retsUsrow;
}

## Return session for auth
function retUsersessdata($xustring, $cxml) {
	$xtst = time();
	$dchk = 0;
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumessions>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = sessions
	$dxmlarr2 = explode("<acforumessions>", $dxmlarr1[0]);
	## Produce the session array
	$dxmlarr3 = explode("<acusersession>", $dxmlarr2[1]);
	## Loop thru array and return userdata xml if present
	$retsUsessx = "";
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		## If we have match, set $dchk and return
		if(trim(ret_xmlfield("acusersessionid", $dxmlarr3[$o])) == $xustring) {
			$retsUsessx .= "\n\t\t<acusersession>".$dxmlarr3[$o];
			$dchk = 1;
		}
	}
	## No session in sessions, we return 'none'
	if($dchk == 0) {
		$retsUsessx = "none";
	}
	return $retsUsessx;
}

## Merge session on user login ##
function mergeSession($cxml, $sessxml, $xustring) {
	$sessxml = trim($sessxml);
	$xtst = time();
	$dchk = 0;
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumessions>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = sessions
	$dxmlarr2 = explode("<acforumessions>", $dxmlarr1[0]);
	## Produce the session array
	$dxmlarr3 = explode("<acusersession>", $dxmlarr2[1]);
	## Loop thru array
	$retsUsess = "\n";
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		## If we have match, return to string
		if(trim(ret_xmlfield("acusersessionid", $dxmlarr3[$o])) != "") {
			if(trim(ret_xmlfield("acusersessionid", $dxmlarr3[$o])) != $xustring) {
				$retsUsess .= "\t\t<acusersession>\n\t\t\t".trim($dxmlarr3[$o])."\n";
			}
		}
	}
	$retsUsess .= "\t\t".$sessxml."\n\t";
	return trim($dxmlarr2[0])."\n\t<acforumessions>".$retsUsess."</acforumessions>\n\t".trim($dxmlarr1[1]);
}

## Check if user is in table
function chkUser($xuname, $cxml) {
	$txarr = array();
	$xtst = time();
	$dchk = 0;
	$uSize = 0;
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumusers>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = topics
	$dxmlarr2 = explode("<acforumusers>", $dxmlarr1[0]);
	## Produce the user array
	$dxmlarr3 = explode("<acforumuser>", $dxmlarr2[1]);
	$uSize = sizeof($dxmlarr3);
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("acusername", $dxmlarr3[$o])) == $xuname) {
			$dchk = 1;
		}
	}
	return array($dchk, $uSize);
}

## Return new user in forum xml - obsolete(?)##
function retnUser($xuname, $xlevel, $numusers, $cxml) {
	$xmltmpl = "	<acforumuser>
			<acusername>^ACUSERNAME^</acusername>
			<acuserpass>^ACUSERPASS^</acuserpass>
			<acuserstamp>^ACUSERSTAMP^</acuserstamp>
			<acuserlevel>^ACUSERLEVEL^</acuserlevel>
			<acusereplies>^ACUSEREPLIES^</acusereplies>
		</acforumuser>\n\t";
	$xtst = time();
	if($numusers == 1) {$xmltmpl = "\n\t".$xmltmpl;}
	$xmltmpl =  put_xmlfield("acusername", $xmltmpl, $xuname);
	//$xmltmpl =  put_xmlfield("acuserpass", $xmltmpl, "");
	$xmltmpl =  put_xmlfield("acuserstamp", $xmltmpl, $xtst);
	$xmltmpl =  put_xmlfield("acuserlevel", $xmltmpl, $xlevel);
	$xmltmpl =  put_xmlfield("acusereplies", $xmltmpl, "0");
	$dxmlarr1 = explode("</acforumusers>", $cxml);
	return $dxmlarr1[0].$xmltmpl."</acforumusers>".$dxmlarr1[1];
}

## Return new user in forum xml ##
function retnxUser($xuname, $xlevel, $xupass, $numusers, $cxml) {
	$xmltmpl = "	<acforumuser>
			<acusername>^ACUSERNAME^</acusername>
			<acuserpass>^ACUSERPASS^</acuserpass>
			<acuserstamp>^ACUSERSTAMP^</acuserstamp>
			<acuserlevel>^ACUSERLEVEL^</acuserlevel>
			<acusereplies>^ACUSEREPLIES^</acusereplies>
		</acforumuser>\n\t";
	$xtst = time();
	if($numusers == 1) {$xmltmpl = "\n\t".$xmltmpl;}
	$xmltmpl =  put_xmlfield("acusername", $xmltmpl, $xuname);
	$xmltmpl =  put_xmlfield("acuserpass", $xmltmpl, $xupass);
	$xmltmpl =  put_xmlfield("acuserstamp", $xmltmpl, $xtst);
	$xmltmpl =  put_xmlfield("acuserlevel", $xmltmpl, $xlevel);
	$xmltmpl =  put_xmlfield("acusereplies", $xmltmpl, "0");
	$dxmlarr1 = explode("</acforumusers>", $cxml);
	return $dxmlarr1[0].$xmltmpl."</acforumusers>".$dxmlarr1[1];
}

## Fetch topic id ##
function retTopicid($dcodesearch) {
	global $bbsfiledir;
	$oFile = $dcodesearch.".xml";
	$xtnum = 0;
	if($dir = @opendir($bbsfiledir."/".$dcodesearch)) {
			while (($file = readdir($dir)) !== false) {
			if(($file != $oFile) && ($file != ".") && ($file != "..")) {
				$xtnum++;
			}
		}
	}
	return $xtnum;
}

## Return template with new topic data ##
function retnfTopic($tid, $tsub, $tuser, $dcodesearch, $tsticky) {
	$xmltmpl = "	<acforumtopic>
			<actid>^ACTOPID^</actid>
			<actopictitle>^ACTOPICTITLE^</actopictitle>
			<actopicdate>^ACTOPICDATE^</actopicdate>
			<actopiclastpost>^ACTOPICLASTPOST^</actopiclastpost>
			<actopiclastpostauthor>^ACTOPICLASTPOSTAUTHOR^</actopiclastpostauthor>
			<actopicurl>^ACTOPICURL^</actopicurl>
			<actopicauthor>^ACTOPICAUTHOR^</actopicauthor>
			<actopicsticky>^ACTOPICSTICKY^</actopicsticky>
			<actopicstatus>^ACTOPICSTATUS^</actopicstatus>
			<actopicreplies>^ACTOPICREPLIES^</actopicreplies>
		</acforumtopic>\n\t";
	if($tid == 1) {$xmltmpl = "\n\t".$xmltmpl;}
	$xtst = time();
	$xmltmpl =  put_xmlfield("actid", $xmltmpl, $tid);
	$xmltmpl =  put_xmlfield("actopictitle", $xmltmpl, $tsub);
	$xmltmpl =  put_xmlfield("actopicdate", $xmltmpl, $xtst);
	$xmltmpl =  put_xmlfield("actopiclastpost", $xmltmpl, $xtst);
	$xmltmpl =  put_xmlfield("actopiclastpostauthor", $xmltmpl, $tuser);
	$xmltmpl =  put_xmlfield("actopicurl", $xmltmpl, $tid."_".$dcodesearch.".xml");
	$xmltmpl =  put_xmlfield("actopicauthor", $xmltmpl, $tuser);
	$xmltmpl =  put_xmlfield("actopicsticky", $xmltmpl, $tsticky);
	$xmltmpl =  put_xmlfield("actopicstatus", $xmltmpl, "open");
	$xmltmpl =  put_xmlfield("actopicreplies", $xmltmpl, "0");
	return $xmltmpl;
}

## Write new topic to file ##
function retntTopic($tid, $tsub, $tmsg, $tuser, $dcodesearch, $tsticky) {
	global $bbsfiledir,$prog_dir,$bbstopictemplate;
	$retbbstxmltempl = file_get_contents($prog_dir."/".$bbstopictemplate);
	$xtst = time();
	$xmltmpl =  put_xmlfield("actid", $retbbstxmltempl, $tid);
	$xmltmpl =  put_xmlfield("acfid", $xmltmpl, $dcodesearch);
	$xmltmpl =  put_xmlfield("actopictitle", $xmltmpl, $tsub);
	$xmltmpl =  put_xmlfield("actopicmessage", $xmltmpl, $tmsg);
	$xmltmpl =  put_xmlfield("actopicdate", $xmltmpl, $xtst);
	$xmltmpl =  put_xmlfield("actopiclastpost", $xmltmpl, $xtst);
	$xmltmpl =  put_xmlfield("actopiclastpostauthor", $xmltmpl, $tuser);
	$xmltmpl =  put_xmlfield("actopicurl", $xmltmpl, $tid."_".$dcodesearch.".xml");
	$xmltmpl =  put_xmlfield("actopicauthor", $xmltmpl, $tuser);
	$xmltmpl =  put_xmlfield("actopicsticky", $xmltmpl, $tsticky);
	$xmltmpl =  put_xmlfield("actopicstatus", $xmltmpl, "open");
	$xmltmpl =  put_xmlfield("actopicreplies", $xmltmpl, "0");
	$fp = @fopen($bbsfiledir."/".$dcodesearch."/".$tid."_".$dcodesearch.".xml", "w");
	$fw = fwrite($fp, $xmltmpl);
	fclose($fp);
}

## Return xmltemplate for topic reply ##
function retTopicreply($trid, $trepid, $trsub, $trmessg, $tuser) {
	$cxmltpl = "\t<acforumtopicreply>
			<actreplyid>^ACTOPREPLYID^</actreplyid>
			<actreplyto>^ACTOPREPLYTO^</actreplyto>
			<actopicreplydate>^ACTOPICDATE^</actopicreplydate>
			<actopicreplyauthor>^ACTOPICREPLYAUTHOR^</actopicreplyauthor>
			<actopicreplytitle>^ACTOPICREPLYTITLE^</actopicreplytitle>
			<actopicreplytext>^ACTOPICREPLYTEXT^</actopicreplytext>
		</acforumtopicreply>\n\t";
	if($trid == 1) {$cxmltpl = "\n\t".$cxmltpl;}
	$xtst = time();
	$cxmltpl =  put_xmlfield("actreplyid", $cxmltpl, $trid);
	$cxmltpl =  put_xmlfield("actreplyto", $cxmltpl, $trepid);
	$cxmltpl =  put_xmlfield("actopicreplydate", $cxmltpl, $xtst);
	$cxmltpl =  put_xmlfield("actopicreplyauthor", $cxmltpl, $tuser);
	$cxmltpl =  put_xmlfield("actopicreplytitle", $cxmltpl, $trsub);
	$cxmltpl =  put_xmlfield("actopicreplytext", $cxmltpl, $trmessg);
	return $cxmltpl;
}

function doReply($xmssnip, $cxml) {
	$dxmlarr1 = explode("</acforumtopicreplies>", $cxml);
	return $dxmlarr1[0].$xmssnip."</acforumtopicreplies>".$dxmlarr1[1];
}

## Insert reply into xml stream ##
function doEdReply($xrtid, $xsubject, $xmessage, $cxml) {
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumtopicreplies>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = replies
	$dxmlarr2 = explode("<acforumtopicreplies>", $dxmlarr1[0]);
	## Produce the reply array
	$dxmlarr3 = explode("<acforumtopicreply>", $dxmlarr2[1]);
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("actreplyid", $dxmlarr3[$o])) == $xrtid) {
			$dxmlarr3[$o] =  put_xmlfield("actopicreplytitle", $dxmlarr3[$o], $xsubject);
			$dxmlarr3[$o] =  put_xmlfield("actopicreplytext", $dxmlarr3[$o], $xmessage);
		}
	}
	$dxmlarrstr = implode("<acforumtopicreply>", $dxmlarr3);
	$cxml = $dxmlarr2[0]."<acforumtopicreplies>".$dxmlarrstr."</acforumtopicreplies>".$dxmlarr1[1];
	return $cxml;
}

## Return list of forum users, for online merge with topic file
function retFUlist($cxml1, $cxml2) {
	$rxt = time();
	$dxmlarr1 = explode("</acforumusers>", $cxml1);
	$dxmlarr2 = explode("<acforumusers>", $dxmlarr1[0]);
	$dxmlarr3 = explode("</acforumtopic>", $cxml2);
	$ustr = "<acforumusers>\n\t".$dxmlarr2[1]."</acforumusers>\n";
	$timstr = "<acforumtstamp>".$rxt."</acforumtstamp>\n";
	$timstr .= "<aexec>^AEXEC^</aexec>\n";
	return $dxmlarr3[0].$timstr."</acforumtopic>".$ustr.$dxmlarr3[1];
}

## Update forumdata timestamp
function updForumonreply($xuname, $xtid, $cxml, $statex) {
	$txarr = array();
	$xtst = time();
	$cxml = put_xmlfield("acforumlastact", $cxml, $xtst);
	## Shave off the file end, return $dxmlarr1[0]
	$dxmlarr1 = explode("</acforumusers>", $cxml);
	## $dxmlarr2[0] = header / $dxmlarr2[1] = topics
	$dxmlarr2 = explode("<acforumusers>", $dxmlarr1[0]);
	## Produce the user array
	$dxmlarr3 = explode("<acforumuser>", $dxmlarr2[1]);
	for($o=0;$o<sizeof($dxmlarr3);$o++) {
		if(trim(ret_xmlfield("acusername", $dxmlarr3[$o])) == $xuname) {
			$dxmlarr3[$o] =  put_xmlfield("acuserstamp", $dxmlarr3[$o], $xtst);
			$usrepl = trim(ret_xmlfield("acusereplies", $dxmlarr3[$o]));
			if($statex == "pos") {
				$usrepl = ($usrepl+1);
			}
			$dxmlarr3[$o] =  put_xmlfield("acusereplies", $dxmlarr3[$o], $usrepl);
		}
	}
	$dxmlarrstr = implode("<acforumuser>", $dxmlarr3);
	$cxml = $dxmlarr2[0]."<acforumusers>".$dxmlarrstr."</acforumusers>".$dxmlarr1[1];
	
	## Do topic
	$tdxmlarr1 = explode("</acforumtopics>", $cxml);
	$tdxmlarr2 = explode("<acforumtopics>", $tdxmlarr1[0]);
	$tdxmlarr3 = explode("<acforumtopic>", $tdxmlarr2[1]);
	for($o=0;$o<sizeof($tdxmlarr3);$o++) {
		if(trim(ret_xmlfield("actid", $tdxmlarr3[$o])) == $xtid) {
			$tdxmlarr3[$o] =  put_xmlfield("actopiclastpost", $tdxmlarr3[$o], $xtst);
			$tdxmlarr3[$o] =  put_xmlfield("actopiclastpostauthor", $tdxmlarr3[$o], $xuname);
			$trepl = trim(ret_xmlfield("actopicreplies", $tdxmlarr3[$o]));
			if($statex == "neg") {
				$trepl = ($trepl-1);
				} else {
				$trepl = ($trepl+1);
			}
			$tdxmlarr3[$o] =  put_xmlfield("actopicreplies", $tdxmlarr3[$o], $trepl);
		}
	}
	$tdxmlarrstr = implode("<acforumtopic>", $tdxmlarr3);
	return $tdxmlarr2[0]."<acforumtopics>".$tdxmlarrstr."</acforumtopics>".$tdxmlarr1[1];
}

## Return new topic in xml stream ##
function newTopic($cxml, $tcxml) {
	$dxmlarr1 = explode("</acforumtopics>", $cxml);
	return $dxmlarr1[0].$tcxml."</acforumtopics>".$dxmlarr1[1];
}

## Query and create bbs, and return loginlink ##
function qUerycode($dcode, $gstate, $dcrpt, $dckey) {
	global $bbsfiledir,$bbs_url,$sessruntime,$bbskin_dir,$root_dir,$bbslang,$BBSskinlock,$BBSskinlocktext;
	$bbseedz = md5(uniqid("tobeornottobe"));
	if(!empty($BBSskinlock)) {
		if(is_dir($root_dir."/".$bbskin_dir."/".$BBSskinlock)) {
			if(file_exists($bbsfiledir."/".$dcode."/".$dcode.".xml")) {
				createBBSusess($dcode, $bbseedz);
				if(!empty($BBSskinlocktext)) {
					return array($bbslang[27]."<br><br><a href=\"javascript:void(0);\" onClick=\"retBBSz('".$dcode."', '".$BBSskinlock."', '".$bbseedz."');resetMain();\" class=\"boldlink\">".$BBSskinlocktext."</a>&nbsp;&nbsp;", "3");
					} else {
					return array($bbslang[27]."<br><br><a href=\"javascript:void(0);\" onClick=\"retBBSz('".$dcode."', '".$BBSskinlock."', '".$bbseedz."');resetMain();\"><img src=\"".$bbskin_dir."/".$BBSskinlock."/skinthumb.jpg\" width=\"150\" height=\"137\" border=\"0\" style=\"border:#AAAAAA 1px solid;\" alt=\"".strtoupper($skin_array[$i])."\"></a>&nbsp;&nbsp;", "3");
				}
				} else {
				if($gstate == "crcht") {
					createBBS($dcode, $dcrpt, $dckey, $bbseedz);
					if(!empty($BBSskinlocktext)) {
						return array($bbslang[27]."<br><br><a href=\"javascript:void(0);\" onClick=\"retBBSz('".$dcode."', '".$BBSskinlock."', '".$bbseedz."');resetMain();\" class=\"boldlink\">".$BBSskinlocktext."</a>&nbsp;&nbsp;", "2");
						} else {
						return array($bbslang[27]."<br><br><a href=\"javascript:void(0);\" onClick=\"retBBSz('".$dcode."', '".$BBSskinlock."', '".$bbseedz."');resetMain();\"><img src=\"".$bbskin_dir."/".$BBSskinlock."/skinthumb.jpg\" width=\"150\" height=\"137\" border=\"0\" style=\"border:#AAAAAA 1px solid;\" alt=\"".strtoupper($skin_array[$i])."\"></a>&nbsp;&nbsp;", "2");
					}
					} else {
					return array($bbslang[29]."&nbsp;&nbsp;&nbsp;<a href=\"#\" class=\"printstatez\" onClick=\"qUery_bcode();return false\">&nbsp;&nbsp;&nbsp;&nbsp;".$bbslang[30]."&nbsp;&nbsp;&nbsp;&nbsp;</a>&nbsp;&nbsp;<a href=\"".$bbs_url."\" class=\"printstatez\">&nbsp;&nbsp;&nbsp;&nbsp;".$bbslang[31]."&nbsp;&nbsp;&nbsp;&nbsp;</a>", "1");
				}
			}
			} else {
			return array($bbslang[33]." ".$BBSskinlock."<br><br>", "0");
		}
		} else {
		if(file_exists($bbsfiledir."/".$dcode."/".$dcode.".xml")) {
			createBBSusess($dcode, $bbseedz);
			$inskins = returnSkins($bbskin_dir);
			$skinbutstr = returnSkinbuttons($inskins, $dcode, $bbseedz);
			return array($bbslang[27]."<br><br>".$skinbutstr, "3");
			} else {
			if($gstate == "crcht") {
				createBBS($dcode, $dcrpt, $dckey, $bbseedz);
				$inskins = returnSkins($bbskin_dir);
				$skinbutstr = returnSkinbuttons($inskins, $dcode, $bbseedz);
				return array($chdels.$bbslang[28]."<br><br>".$skinbutstr, "2");
				} else {
				return array($bbslang[29]."&nbsp;&nbsp;&nbsp;<a href=\"#\" class=\"printstatez\" onClick=\"qUery_bcode();return false\">&nbsp;&nbsp;&nbsp;&nbsp;".$bbslang[30]."&nbsp;&nbsp;&nbsp;&nbsp;</a>&nbsp;&nbsp;<a href=\"".$bbs_url."\" class=\"printstatez\">&nbsp;&nbsp;&nbsp;&nbsp;".$bbslang[31]."&nbsp;&nbsp;&nbsp;&nbsp;</a>", "1");
			}
		}
	}
}

## Query directly for bbs, and return loginlink ##
function entrycode($dcode, $dckey) {
	global $bbsfiledir,$bbs_url,$sessruntime,$bbskin_dir,$root_dir,$bbslang,$BBSskinlock,$BBSskinlocktext;
	$bbseedz = md5(uniqid("tobeornottobe"));
	if(file_exists($bbsfiledir."/".$dcode."/".$dcode.".xml")) {
		createBBSusess($dcode, $bbseedz);
		if(!empty($BBSskinlock)) {
			if(!empty($BBSskinlocktext)) {
				return array($bbslang[27]."<br><br><a href=\"javascript:void(0);\" onClick=\"retBBSz('".$dcode."', '".$BBSskinlock."', '".$bbseedz."');resetMain();\" class=\"boldlink\">".$BBSskinlocktext."</a>&nbsp;&nbsp;", "3");
				} else {
				return array($bbslang[27]."<br><br><a href=\"javascript:void(0);\" onClick=\"retBBSz('".$dcode."', '".$BBSskinlock."', '".$bbseedz."');resetMain();\"><img src=\"".$bbskin_dir."/".$BBSskinlock."/skinthumb.jpg\" width=\"150\" height=\"137\" border=\"0\" style=\"border:#AAAAAA 1px solid;\" alt=\"".strtoupper($BBSskinlock)."\"></a>&nbsp;&nbsp;", "3");
			}
			} else {
			$inskins = returnSkins($bbskin_dir);
			$skinbutstr = returnSkinbuttons($inskins, $dcode, $bbseedz);
			return array($bbslang[27]."<br><br>".$skinbutstr, "3");
		}
		} else {
		return array($bbslang[32],"1");
	}
}

## Loop through skin dir and return dir names##
function returnSkins($bbskin_dir) {
	global $root_dir;
	$retskins = array();
	if($dir = opendir($root_dir."/".$bbskin_dir)) {
			while (($file = readdir($dir)) !== false) {
			if(is_dir($root_dir."/".$bbskin_dir."/".$file) && $file != "." && $file != ".." && $file != ".svn") {
				array_push($retskins, $file);
			}
		}
	}
	closedir($dir);
	return $retskins;
}

## Returns skin array as buttons ##
function returnSkinbuttons($skin_array, $dcode, $seedz) {
	global $root_dir,$bbskin_dir,$BBSreturn,$bbslang;
	$retskinstring = "";
	if($BBSreturn == 4) {
		$retskinstring = "<select name=\"maBBS\" id=\"maBBS\" class=\"mainwin_iselect\" onChange=\"doSelectedi('".$dcode."', '".$seedz."')\"><option value=\"none\">".$bbslang[26]."</option>";
	}
	for($i=0;$i<sizeof($skin_array);$i++) {
		## Return for BBS search ##
		switch($BBSreturn) {
			case "4":
			$retskinstring .= "<option value=\"".$skin_array[$i]."\">".strtoupper($skin_array[$i])."</option>";
			break;
			case "3":
			$retskinstring .= "<a href=\"javascript:void(0);\" onClick=\"retBBSz('".$dcode."', '".$skin_array[$i]."', '".$seedz."');resetMain();\" class=\"boldlink\">".strtoupper($skin_array[$i])."</a>&nbsp;&nbsp;";
			break;
			case "2":
			$chkskinsts = $bbskin_dir."/".$skin_array[$i]."/skinicon.jpg";
			if(file_exists($chkskinsts)) {
				$retskinstring .= "<a href=\"javascript:void(0);\" onClick=\"retBBSz('".$dcode."', '".$skin_array[$i]."', '".$seedz."');resetMain();\"><img src=\"".$bbskin_dir."/".$skin_array[$i]."/skinicon.jpg\" width=\"113\" height=\"33\" border=\"0\" style=\"border:#AAAAAA 1px solid;\" alt=\"".strtoupper($skin_array[$i])."\"></a>&nbsp;&nbsp;";
			}
			break;
			default:
			$chkskinsts = $bbskin_dir."/".$skin_array[$i]."/skinthumb.jpg";
			if(file_exists($chkskinsts)) {
				$retskinstring .= "<a href=\"javascript:void(0);\" onClick=\"retBBSz('".$dcode."', '".$skin_array[$i]."', '".$seedz."');resetMain();\"><img src=\"".$bbskin_dir."/".$skin_array[$i]."/skinthumb.jpg\" width=\"150\" height=\"137\" border=\"0\" style=\"border:#AAAAAA 1px solid;\" alt=\"".strtoupper($skin_array[$i])."\"></a>&nbsp;&nbsp;";
			}
		}
	}
	if($BBSreturn == 4) {
		$retskinstring .= "</select>";
	}
	return $retskinstring;
}

## Loop through chat dir and delete files older than sessruntime ##
function cleanChats($sessruntime) {
	global $bbsfiledir;
	if($dir = opendir($bbsfiledir)) {
			while (($file = readdir($dir)) !== false) {
			if (substr($file,-4) == ".xml") {
				if(filemtime($bbsfiledir."/".$file) < $sessruntime) {
					unlink($bbsfiledir."/".$file);
				}
			}
		}
	}
	closedir($dir);
}

## For future use ##

## Clean up id ##
function cleanMe($text) {
	$text = ereg_replace("[^[:digit:]]", "", $text);
	return(trim($text));
}
?>
Return current item: AnoBBS 3DES encrypted forum and communication repository