Location: PHPKode > projects > Backend code/CMS for blizzle.com > v1.x/functions.php
<?
session_start();
dbConnect();
if (!$cookiesEnabled) {
setcookie("cookiesEnabled","true");
}
chkLogin();
if ($frmChangeTheme) {
setUserVariable("theme",$frmChangeTheme);
setcookie("theme",$frmChangeTheme,time()+2592000,"/");
$currentTheme = $frmChangeTheme;
}
if (retLoggedIn()) {
if (!$currentTheme) {
if (!$theme) {
$currentTheme = getUserVariable("theme");
setcookie("theme",$currentTheme,time()+2592000,"/");
} else {
$currentTheme = $theme;
}
}
}
if (!$currentTheme) {
$currentTheme = "default";
}
if (strlen($HTTP_SERVER_VARS['QUERY_STRING'])) {
$here = $HTTP_SERVER_VARS['PHP_SELF']."?".$HTTP_SERVER_VARS['QUERY_STRING'];
} else {
$here = $HTTP_SERVER_VARS['PHP_SELF'];
}

$doc_root = "/home/sites/site10/web";
// CONNECTS TO THE DATABASE

function dbConnect() {
	global $link,$descriptions;
	$link = mysql_connect("localhost", "!!USERNAME!!", "!!PASSWORD!!") or die ("Could not connect");

	mysql_select_db ("blizzle") or die ("Could not select database");

// GRABS DESCRIPTIONS
	$query = "SELECT * FROM descriptions ORDER BY 'index';";
	$result = mysql_query ($query, $link) or die (mysql_error());
	while (list($index, $description) = mysql_fetch_row($result)) {
		$descriptions[trim(strtolower($index))] = $description;
	}

}

// CLOSES DATABASE CONNECTION
function dbClose() {
	global $link;
	mysql_close($link);
}



// CREATE MAIN PAGE HTML
function createPage($body) {
global $excludeHeftyReplace;

$body = heftyReplace($body);

$excludeHeftyReplace = false;

header("Expires: Mon, 26 Jul 1992 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0 

global $currentTheme,$doc_root,$link,$here;
$giblets = parseGiblets();
$blizlets = parseBlizlets();
$feature = insertFeature();
$featurelink = insertFeatureLink();
$pageLinks = pageInfo();

if (retLoggedIn()) {
	$query = "SELECT COUNT(*) FROM user_history WHERE hit = '$here' AND userID = ".retUserID().";";
	$result = mysql_query ($query, $link) or die (mysql_error());
	list($hitcount) = mysql_fetch_row($result);
	if ($hitcount < 1) {
		addModPoints(1);
		$query = "INSERT INTO user_history (userID,hit) VALUES(".retUserID().",'$here');";
		mysql_query ($query, $link) or die (mysql_error());
	}
}



ob_start("ob_gzhandler");

require $doc_root."/themes/$currentTheme/page.php";

ob_end_flush();

}



// PARSE ITEMS
function parseItems() {
global $link,$uid,$sub,$segment,$category,$page,$num_rows;
if ($page) {
$limitSQL = " LIMIT ".($page*10).",".(($page*10)+11);
} else {
$limitSQL = " LIMIT 0,11";
}
$retval = "";
	// FIRST find out if we're displaying an individual item
	if ($uid) {

		if ($sub) {
			global $pagecount;
			$query = "SELECT item_subs.subID, item_subs.itemID, item_subs.subBody, item_subs.subLinks, item_headers.itemTitle, item_headers.itemDate, item_headers.itemCategory, item_headers.itemSegment, item_headers.displayName, item_headers.modpoints FROM item_subs INNER JOIN item_headers ON item_subs.itemID = item_headers.itemID HAVING item_subs.subID = $sub AND item_subs.itemID = $uid;";
			$result = mysql_query ($query, $link) or die (mysql_error());
			list($subID,$itemID,$subBody,$subLinks,$itemTitle,$itemDate,$itemCategory,$itemSegment,$displayName,$modpoints) = mysql_fetch_row($result);
			$retval = createItem($itemTitle." Page ".($sub+1),$itemDate,$subBody,$subLinks,$itemCategory,$itemSegment,$displayName,false,$itemID,false,$modpoints,$pagecount);

		} else {	

			$query = "SELECT item_headers.itemID, item_headers.itemCategory, item_headers.itemSegment, item_headers.itemTitle, item_headers.itemDescription, item_headers.itemBody, item_headers.itemDate, item_headers.itemLinks, item_headers.displayname, item_headers.modpoints, Count(item_subs.subID) AS Number FROM item_headers LEFT JOIN item_subs ON item_headers.itemID = item_subs.itemID GROUP BY item_headers.itemID HAVING item_headers.itemID = $uid;";
			$result = mysql_query ($query, $link) or die (mysql_error());
			list($itemID,$itemCategory,$itemSegment,$itemTitle,$itemDescription,$itemBody,$itemDate,$itemLinks,$displayName,$modpoints,$pagecount) = mysql_fetch_row($result);
			$retval = createItem($itemTitle,$itemDate,$itemDescription."<p>".$itemBody,$itemLinks,$itemCategory,$itemSegment,$displayName,false,$itemID,false,$modpoints,$pagecount);

		}
		$query = "SELECT * FROM comments WHERE itemID = $uid AND modpoints > -1 ORDER BY commentDate DESC;";
		$result = mysql_query ($query, $link) or die (mysql_error());
		while (list($commentID,$itemID,$commentDate,$commentBody,$commentHeaders,$displayname,$modpoints) = mysql_fetch_row($result)) {
			$retval = $retval.createComment($commentDate,$commentBody,$commentHeaders,$displayname,$modpoints,false);
		}
		$retval = $retval.createComment(false,commentForm($uid),false,false,false);


	// IF NOT find out what section we're in and display headers
	} elseif ($category) {

		if ($segment) {


			$query = "SELECT item_headers.itemID, item_headers.itemCategory, item_headers.itemSegment, item_headers.itemTitle, item_headers.itemDescription, item_headers.itemBody, item_headers.itemDate, item_headers.itemLinks, item_headers.displayname, item_headers.modpoints, Count(comments.itemID) AS Number FROM item_headers LEFT JOIN comments ON item_headers.itemID = comments.itemID GROUP BY item_headers.itemID HAVING item_headers.itemCategory = '$category' AND itemSegment = '$segment' AND item_headers.modpoints > -1 ORDER BY DATE_ADD(item_headers.itemDate, INTERVAL (item_headers.modpoints/3) MINUTE) DESC$limitSQL;";
			$result = mysql_query ($query, $link) or die (mysql_error());
			$num_rows = mysql_num_rows($result);
			while (list($itemID,$itemCategory,$itemSegment,$itemTitle,$itemDescription,$itemBody,$itemDate,$itemLinks,$displayName,$modpoints,$comments) = mysql_fetch_row($result)) {
				$loopNum++;
				if ($loopNum < 11) {
					$retval = $retval.createItem($itemTitle,$itemDate,$itemDescription,$itemLinks,$itemCategory,$itemSegment,$displayName,(strlen(trim($itemBody)) ? strlen(trim($itemBody)) : false),$itemID,$comments,$modpoints,false);
				}
			}
		} else {

			$query = "SELECT item_headers.itemID, item_headers.itemCategory, item_headers.itemSegment, item_headers.itemTitle, item_headers.itemDescription, item_headers.itemBody, item_headers.itemDate, item_headers.itemLinks, item_headers.displayname, item_headers.modpoints, Count(comments.itemID) AS Number FROM item_headers LEFT JOIN comments ON item_headers.itemID = comments.itemID GROUP BY item_headers.itemID HAVING item_headers.itemCategory = '$category' AND item_headers.modpoints > -1 ORDER BY DATE_ADD(item_headers.itemDate, INTERVAL (item_headers.modpoints/3) MINUTE) DESC$limitSQL;";
			$result = mysql_query ($query, $link) or die (mysql_error());
			$num_rows = mysql_num_rows($result);
			while (list($itemID,$itemCategory,$itemSegment,$itemTitle,$itemDescription,$itemBody,$itemDate,$itemLinks,$displayName,$modpoints,$comments) = mysql_fetch_row($result)) {
				$loopNum++;
				if ($loopNum < 11) {
					$retval = $retval.createItem($itemTitle,$itemDate,$itemDescription,$itemLinks,$itemCategory,$itemSegment,$displayName,(strlen(trim($itemBody)) ? strlen(trim($itemBody)) : false),$itemID,$comments,$modpoints,false);
				}
			}
		}

	// STILL NOTHING?  display everything
	} else {

$query = "SELECT item_headers.itemID, item_headers.itemCategory, item_headers.itemSegment, item_headers.itemTitle, item_headers.itemDescription, item_headers.itemBody, item_headers.itemDate, item_headers.itemLinks, item_headers.displayname, item_headers.modpoints, Count(comments.itemID) AS Number FROM item_headers LEFT JOIN comments ON item_headers.itemID = comments.itemID GROUP BY item_headers.itemID HAVING item_headers.modpoints > -1 ORDER BY DATE_ADD(item_headers.itemDate, INTERVAL (item_headers.modpoints/3) MINUTE) DESC$limitSQL;";
		$result = mysql_query ($query, $link) or die (mysql_error());
		$num_rows = mysql_num_rows($result);
		while (list($itemID,$itemCategory,$itemSegment,$itemTitle,$itemDescription,$itemBody,$itemDate,$itemLinks,$displayName,$modpoints,$comments) = mysql_fetch_row($result)) {
				$loopNum++;
				if ($loopNum < 11) {
					$retval = $retval.createItem($itemTitle,$itemDate,$itemDescription,$itemLinks,$itemCategory,$itemSegment,$displayName,(strlen(trim($itemBody)) ? strlen(trim($itemBody)) : false),$itemID,$comments,$modpoints,false);
				}
		}

	}
return $retval;

}


function insertFeature() {

	return "/files/images/scibg.jpg";

}

function insertFeatureLink() {

	return "http://blizzle.com/index.php?uid=398";

}

// PARSE BLIZLETS
function parseBlizlets() {
global $link,$doc_root;

	ob_start();
	require $doc_root."/blizlets/completed.php";
	require $doc_root."/blizlets/login.php";
	require $doc_root."/blizlets/releases.php";
	require $doc_root."/blizlets/poll.php";
	require $doc_root."/blizlets/blitzlet.php";
	$output = ob_get_contents();
	ob_end_clean();
	return $output;

}



// PARSE GIBLETS
function parseGiblets() {
global $link,$doc_root;

	ob_start();
	require $doc_root."/giblets/sitelinks.php";
	require $doc_root."/giblets/search.php";
	require $doc_root."/giblets/theme.php";
	require $doc_root."/giblets/resources.php";
	require $doc_root."/giblets/buttons.php";
	$output = ob_get_contents();
	ob_end_clean();
	return $output;
	

}



// CREATE MAIN PAGE ITEM (CENTER OF PAGE)
function createItem($title,$date,$body,$links,$category,$segment,$displayname,$bodysize,$itemid,$comments,$modpoints,$pagecount) {
	global $currentTheme,$doc_root,$sub,$here;
	$displayname = "<a href=\"accountlookup.php?name=".rawurlencode($displayname)."\">$displayname</a>";
	if ($pagecount > 0) {
		if ($sub < $pagecount) {
			$storylink = "<p> [<a href=\"index.php?uid=$itemid&sub=".($sub+1)."&pagecount=$pagecount\">Next Page</a>] ";
		}
		if ($sub > 0) {
			$storylink = $storylink." [<a href=\"index.php?uid=$itemid&sub=".($sub-1)."&pagecount=$pagecount\">Previous Page</a>] ";
		}
		if ($sub > 0) {
			$storylink = $storylink."Page: <a href=\"index.php?uid=$itemid\">1</a> ";
		} else {
			$storylink = $storylink."Page: 1 ";
		}
		for ($i = 1; $i <= $pagecount; $i++) {
			if ($i == $sub) {
				$storylink = $storylink.($i+1)." ";
			} else {
				$storylink = $storylink."<a href=\"index.php?uid=$itemid&sub=$i&pagecount=$pagecount\">".($i+1)."</a> ";
			}
		}
		$storylink = $storylink."<br><table border=0><tr>";
	} else {
		$storylink = "<p><table border=0><tr>";
	}
	if ($bodysize) {
		$storylink = $storylink."<td valign=bottom>[<a href=\"index.php?uid=$itemid\">read full story ($bodysize bytes)</a>]</td>";
	}
	if ($comments > -1) {
		$storylink = $storylink."<td valign=bottom>[<a href=\"index.php?uid=$itemid#comments\">$comments comments</a>]</td>";
	}
	if (!is_null($modpoints)) {
		$futuretime = "<a href=\"/index.php?uid=111\">+".round($modpoints/3)." min</a>";
		if (retLoggedin()) {
			if ((stripNonAN($displayname) == retUserName()) || (retUserFlag() == "@") || (retUserFlag() == "^")) {
				$storylink = $storylink."<form method=post action=moderate.php><input type=hidden name=returnl value=\"$here\"><input type=hidden name=itemid value=$itemid><td valign=bottom>[<a href=\"index.php?uid=111\">$modpoints modpoints</a>] [<a href=\"wizard.php?function=edit&id=$itemid&sub=$sub\">edit</a>] </td></tr></table><table width=100% border=0 cellpadding=0 cellspacing=0><tr><td valign=bottom align=right>Moderate this post: <select name=posneg style=\"font-size: 9px; height: 17px; width: 32px;\"><option value=\"+\">+\n<option value=\"-\">-\n</select><input style=\"font-size: 9px; width: 20px; height: 18px;\" type=text name=points size=3 value=1> point(s) <input style=\"font-size: 9px;\" type=submit value=Vote></td></form>";
			} elseif (retUserFlag() == "%") {
				$storylink = $storylink."<form method=post action=moderate.php><input type=hidden name=returnl value=\"$here\"><input type=hidden name=itemid value=$itemid><td valign=bottom>[<a href=\"index.php?uid=111\">$modpoints modpoints</a>] [<a href=\"wizard.php?function=append&id=$itemid&sub=$sub\">update</a>] </td></tr></table><table width=100% border=0 cellpadding=0 cellspacing=0><tr><td valign=bottom align=right>Moderate this post: <select name=posneg style=\"font-size: 9px; height: 17px; width: 32px;\"><option value=\"+\">+\n<option value=\"-\">-\n</select><input style=\"font-size: 9px; width: 20px; height: 18px;\" type=text name=points size=3 value=1> point(s) <input style=\"font-size: 9px;\" type=submit value=Vote></td></form>";
			} else {
				$storylink = $storylink."<form method=post action=moderate.php><input type=hidden name=returnl value=\"$here\"><input type=hidden name=itemid value=$itemid><td valign=bottom>[<a href=\"index.php?uid=111\">$modpoints modpoints</a>] </td></tr></table><table width=100% border=0 cellpadding=0 cellspacing=0><tr><td valign=bottom align=right>Moderate this post: <select name=posneg style=\"font-size: 9px; height: 17px; width: 32px;\"><option value=\"+\">+\n<option value=\"-\">-\n</select><input style=\"font-size: 9px; width: 20px; height: 18px;\" type=text name=points size=3 value=1> point(s) <input style=\"font-size: 9px;\" type=submit value=Vote></td></form>";
			}
		} else {
			$storylink = $storylink."<td valign=bottom>[<a href=\"index.php?uid=111\">$modpoints modpoints</a>]</td>";
		}
	}
	if ($storylink != "<p><table border=0><tr>") {
		$storylink = $storylink."</tr></table>";
	} else {
		$storylink = "";
	}
	$parsedLinks = parseLinks($links);
	ob_start();
	require $doc_root."/themes/$currentTheme/item.php";
	$output = ob_get_contents();
	ob_end_clean();
	return $output;
}

// CREATE COMMENT ITEM (CENTER OF PAGE)
function createComment($date,$body,$headers,$displayname,$modpoints) {

	global $currentTheme,$doc_root;
	$displayname = "<a href=\"accountlookup.php?name=".rawurlencode($displayname)."\">$displayname</a>";
	ob_start();
	echo "<a name=\"#comments\">";
	require $doc_root."/themes/$currentTheme/comment.php";
	$output = ob_get_contents();
	ob_end_clean();
	return $output;

}

// LINKS IN THE FILE REQUIRED FOR COMMENT FORMS
function commentForm($itemID) {

if (getUserVariable("signature")) {
$signature = "\n\n[*hr][*b][*i]".getUserVariable("signature")."[*/b][*/i]";
}

$cfHtml = "<center><table border=0><tr><form method=post action=postcomment.php><input type=hidden name=itemID value=\"$itemID\"><input type=hidden name=modpoints value=\"".retModpoints()."\"><td>Name: ".retUserNameFormatted("displayName","size=15 class=cmtInputText")."&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Need help?  <a href=\"/index.php?uid=143\">blizcode reference</a>.</td></tr><tr><td colspan=2 align=middle><textarea name=commentText class=cmtTextArea cols=45 rows=6>$signature</textarea></td></tr><tr><td></td><td align=right><input class=cmtSubmit type=submit value=\"Post Comment\"></td></tr></form></table></center>";

return $cfHtml;
}

function retUserID() {
global $HTTP_SESSION_VARS;
return $HTTP_SESSION_VARS['userID'];
}
function retUserName() {
global $HTTP_SESSION_VARS;
return $HTTP_SESSION_VARS['userName'];
}
function retUserFlag() {
global $HTTP_SESSION_VARS;
return $HTTP_SESSION_VARS['userStatus'];
}
function retLoggedin() {
global $HTTP_SESSION_VARS;
if ($HTTP_SESSION_VARS['login'] == 1) {
return true;
} else {
return false;
}
}

function passwordchk($password) {

}

function retModpoints() {
global $HTTP_SESSION_VARS;
if ($HTTP_SESSION_VARS['modpoints']) {
return $HTTP_SESSION_VARS['modpoints'];
} else {
return 0;
}
}

function retUserNameFormatted($inputname,$inputparms) {
global $HTTP_SESSION_VARS;
if (retLoggedin()) {
return "<a href=\"/accountlookup.php?name=".retUserName()."\">".retUserFlag().retUserName()."</a><input type=hidden name=\"$inputname\" value=\"".$HTTP_SESSION_VARS['userStatus'].$HTTP_SESSION_VARS['userName']."\">";
} else {
return "<input name=\"$inputname\" $inputparms type=text>";
}
}

function addModPoints($num) {
global $HTTP_SESSION_VARS;
if (retLoggedin()) {
global $link;

$query = "UPDATE users SET modpoints = modpoints + $num WHERE userID = '".$HTTP_SESSION_VARS['userID']."';";
$result = mysql_query ($query, $link) or die (mysql_error());
$HTTP_SESSION_VARS['modpoints'] = $HTTP_SESSION_VARS['modpoints']+$num;
}
}


function removeModPoints($num) {
global $HTTP_SESSION_VARS;
if (retLoggedin()) {
global $link;

$query = "UPDATE users SET modpoints = modpoints - $num WHERE userID = '".$HTTP_SESSION_VARS['userID']."';";
$result = mysql_query ($query, $link) or die (mysql_error());
$HTTP_SESSION_VARS['modpoints'] = $HTTP_SESSION_VARS['modpoints']-$num;
}
}


function setUserVariable($name,$value) {
if (retLoggedin()) {
global $link;
$query = "DELETE FROM user_variables WHERE userID = ".retUserID()." AND name = '$name';";
$result = mysql_query ($query, $link) or die (mysql_error());
if ($value) {
	$query = "INSERT INTO user_variables (userID,name,value) VALUES(".retUserID().",'$name','$value');";
	$result = mysql_query ($query, $link) or die (mysql_error());
}
}
}

function getUserVariable($name) {
if (retLoggedin()) {
global $link;
$query = "SELECT value FROM user_variables WHERE userID = ".retUserID()." AND name = '$name';";
$result = mysql_query ($query, $link) or die (mysql_error());
list($value) = mysql_fetch_row($result);
return $value;
}
}

function chkLogin() {

	global $frmUsername, $frmUserpassword, $frmRemember, $autologin, $autologinpassword, $frmAction, $link, $HTTP_SESSION_VARS;

	if (($frmUsername) && ($frmUserpassword)) {
		$query = "SELECT userID,userName,userStatus,modpoints FROM users WHERE userName = '$frmUsername' AND userPassword = MD5('$frmUserpassword');";

		$result = mysql_query ($query, $link) or die (mysql_error());

		list($userID, $userName, $userStatus, $modpoints) = mysql_fetch_row($result);

		if ($userID) {

			session_register("userID","userName","userStatus","modpoints","login");
			$HTTP_SESSION_VARS['login'] = 1;
			$HTTP_SESSION_VARS['userID'] = $userID;
			$HTTP_SESSION_VARS['userName'] = $userName;
			$HTTP_SESSION_VARS['userStatus'] = $userStatus;
			$HTTP_SESSION_VARS['modpoints'] = $modpoints;
			$query = "DELETE FROM user_history WHERE userID = $userID;";
			mysql_query ($query, $link) or die (mysql_error());
		}

		if ($frmRemember) {
			setcookie("autologin",md5($frmUserpassword),time()+2592000,"/");
			setcookie("autologinpassword",$frmUsername,time()+2592000,"/");
		}
	} elseif ($autologin) {

		$query = "SELECT userID,userName,userStatus,modpoints FROM users WHERE userName = '$autologinpassword' AND userPassword = '$autologin';";

		$result = mysql_query ($query, $link) or die (mysql_error());

		list($userID, $userName, $userStatus, $modpoints) = mysql_fetch_row($result);

		if ($userID) {

			session_register("userID","userName","userStatus","modpoints","login");
			$HTTP_SESSION_VARS['login'] = 1;
			$HTTP_SESSION_VARS['userID'] = $userID;
			$HTTP_SESSION_VARS['userName'] = $userName;
			$HTTP_SESSION_VARS['userStatus'] = $userStatus;
			$HTTP_SESSION_VARS['modpoints'] = $modpoints;
			$query = "DELETE FROM user_history WHERE userID = $userID;";
			mysql_query ($query, $link) or die (mysql_error());
		}

		setcookie("autologin",$autologin,time()+2592000,"/");
		setcookie("autologinpassword",$autologinpassword,time()+2592000,"/");

	}

	if ($frmAction == "Logout") {
		$HTTP_SESSION_VARS['login'] = null;
		$HTTP_SESSION_VARS['userID'] = null;
		$HTTP_SESSION_VARS['userName'] = null;
		$HTTP_SESSION_VARS['userStatus'] = null;
		$HTTP_SESSION_VARS['modpoints'] = null;
		setcookie("autologin",$autologin,time()-3600,"/");
		setcookie("autologinpassword",$autologinpassword,time()-3600,"/");
	}

}


// CREATES ORANGE-BACK BOX (RIGHT OF PAGE)
function createBlizlet($title,$body) {

	global $currentTheme,$doc_root;
	require $doc_root."/themes/$currentTheme/blizlet.php";

}

// CREATE GRAY BOX (LEFT OF PAGE)
function createGiblet($title,$body) {

	global $currentTheme,$doc_root;
	require $doc_root."/themes/$currentTheme/giblet.php";


}

// WALKS THROUGH LINKS AND OUTPUTS AS LIST

function parseLinks($links) {
	if (strlen($links)) {
		$retval = "Related Links:<ul>";
		$lArray = split(";",$links);
		foreach ($lArray as $linkx) {
			$retval = $retval."<li> ".$linkx."</a><br>";
		}
		$retval = $retval."</ul>";
	}
return $retval;
}


function pageInfo() {
	global $page,$num_rows,$HTTP_SERVER_VARS;

if (strlen($HTTP_SERVER_VARS['QUERY_STRING'])) {
$queryString = "?".$HTTP_SERVER_VARS['QUERY_STRING'];
}

	if ($page>1) {
		$retVal = "<a href=".str_replace("page=".$page,"page=".($page-1),$PHP_SELF.$queryString).">[&lt;&lt;- previous page]</a>";
	} elseif ($page==1) {
		$retVal = "<a href=".str_replace("page=".$page,"",$PHP_SELF.$queryString).">[&lt;&lt;- previous page]</a>";
	}

	if ($num_rows >= 11) {
		if ($retVal) {
			if ($page) {
				$retVal = $retVal." - <a href=".str_replace("page=".$page,"page=".($page+1),$PHP_SELF.$queryString).">[next page -&gt;&gt;]</a>";
			} else {
				if ($queryString) {
					$retVal = $retVal." - <a href=".$PHP_SELF.$queryString."&page=1>[next page -&gt;&gt;]</a>";
				} else {
					$retVal = $retVal." - <a href=".$PHP_SELF."?page=1>[next page -&gt;&gt;]</a>";
				}
			}
		} else {
			if ($page) {
				$retVal = "<a href=".str_replace("page=".$page,"page=".($page+1),$PHP_SELF.$queryString).">[next page -&gt;&gt;]</a>";
			} else {
				if ($queryString) {
					$retVal = "<a href=".$PHP_SELF.$queryString."&page=1>[next page -&gt;&gt;]</a>";
				} else {
					$retVal = "<a href=".$PHP_SELF."?page=1>[next page -&gt;&gt;]</a>";
				}
			}
		}
	}

	return $retVal;
}

// CONVERTS SIMPLE BLIZCODE TO HTML AND REMOVES REMAINING HTML - parsed when added to db
function textReplace($body_text) {

	global $excludeHeftyReplace;

	if (!$excludeHeftyReplace) {

// FIRST WE WILL preg ALLOWED HTML INTO BLIZCODE, and strip other HTML

		$patterns = array (
			"/<a(.+?)href=[\"|\'](.+?)[\"|\']>(.+?)<\/a>/i",
			"/<(p|br|dl|\/dl|dt|ul|\/ul|ol|\/ol|li|strong|\/strong|dd|i|\/i|b|\/b|u|\/u|hr|code|\/code|strike|\/strike)>/i",
			"/<script[^>]*?>.*?<\/script>/si",
			"/<[\/\!]*?[^<>]*?>/si",
		);

		$replace = array (
			"[$2]$3[/]",
			"[$1]",
			"",
			"",
		);

		$body_text = preg_replace($patterns,$replace," $body_text ");


// NEXT WE WILL preg BLIZCODE INTO HTML (redundant eh?)


		$patterns = array (
			"/\[http(s?):\/\/(.+?)\](.+?)\[\/\]/i",
			"/\[mailto:(.+?)\](.+?)\[\/\]/si",
			"/(\n|\s)((f|ht)tp(s?)|news]):\/\/([a-z0-9~#%,\&=?\/\._\-]+:([a-z0-9~#%,\&=?\/\._\-]+@)?)?([0-9a-z][0-9a-z\-]+\.)[a-z]{2,3}(:[\d]+)?([\/\\][a-z0-9~#%,@\&:\.=?_\-]*)*/ie",
			"/(\n|\s)(([\w\.]+))(@)([\w\.]+)\b/i",
			"/\[img\,(\d+?)\,(\d+?)\,(\w+?):(.+?)\](.+?)\[\/\]/i",
			"/\[img\,(\d+?)\,(\d+?)\,(\w+?):(.+?)\]/i",
			"/\[i](.+?)\[\/i\]/si",
			"/\[b](.+?)\[\/b\]/si",
			"/\[strong](.+?)\[\/strong\]/si",
			"/\[u](.+?)\[\/u\]/si",
			"/\[code](.+?)\[\/code\]/si",
			"/\[strike](.+?)\[\/strike\]/si",
		);
		$replace = array (
			"<a target=_new href=\"http$1://$2\">$3</a>",
			"<a target=_new href=\"mailto:$1\">$2</a>",
			"retLink('$0')",
			"$1<a href=\"mailto:$3$4$5\">$3$4$5</a>",
			"<div class=image style=\"float: $3; width: $1px;\"><img border=0 width=\"$1\" height=\"$2\" src=\"$4\"><br>$5</div>",
			"<img border=0 width=\"$1\" align=\"$3\" height=\"$2\" src=\"$4\">",
			"<i>$1</i>",
			"<b>$1</b>",
			"<strong>$1</strong>",
			"<u>$1</u>",
			"<code>$1</code>",
			"<strike>$1</strike>",
		);


		$body_text = preg_replace($patterns,$replace,$body_text);

// FINALLY WE WILL str_replace OTHER SIMPLE BLIZCODE & ENTITIES

		$body_text = str_replace("[ul]","<ul>",str_replace("[dl]","<dl>",str_replace("[ol]","<ol>",str_replace("[/ul]","</ul>",str_replace("[/dl]","</dl>",str_replace("[/ol]","</ol>",str_replace("[dd]","<dd>",str_replace("[dt]","<dt>",str_replace("[br]","<br>",str_replace("[li]","<li>",str_replace("[p]","<p>",str_replace("[hr]","<hr>",str_replace("\n","<br>",str_replace("\n\n","</ul><p>",str_replace("\no ","<li> ",str_replace("\n\no ","<ul><li> ",$body_text))))))))))))))));

		return trim(addslashes($body_text));

	} else {
		return trim($body_text);
	}
}

// CONVERTS REMAINING WEB LINKS TO HTML AND REMOVES REMAINING HTML - parsed at runtime (is this neccessary?)
// OK, it's neccessary for [desc]-- but anything else??  I think everything else can be moved into textReplace
// Just tested it -- the other stuff is neccessary for backwards compatibility with existing links.
// NOW, if we run a script on the entire database to convert those over then it should be ok
function heftyReplace($body_text) {

	global $descriptions,$excludeHeftyReplace;

	if (!$excludeHeftyReplace) {

		$patterns = array (
			"/\[desc:(.*?)\]/ie",
			"/\[http(s?):\/\/(.*?)\](.*?)\[\/\]/i",
			"/\[mailto:(.*?)\](.*?)\[\/\]/i",
			"/(\n|\s)((f|ht)tp(s?)|news]):\/\/([a-z0-9~#%,\&=?\/\._\-]+:([a-z0-9~#%,\&=?\/\._\-]+@)?)?([0-9a-z][0-9a-z\-]+\.)[a-z]{2,3}(:[\d]+)?([\/\\][a-z0-9~#%,@\&:\.=?_\-]*)*/ie",
			"/(\n|\s)(([\w\.]+))(@)([\w\.]+)\b/i",
			"/\[\*(.*?)\]/i",
			"/\*((f|ht)tp(s?)|news]):\/\/([a-z0-9~#%,\&=?\/\._\-]+:([a-z0-9~#%,\&=?\/\._\-]+@)?)?([0-9a-z][0-9a-z\-]+\.)[a-z]{2,3}(:[\d]+)?([\/\\][a-z0-9~#%,@\&:\.=?_\-]*)*/ie",
			"/\*(([\w\.]+))(@)([\w\.]+)\b/i",
		);
		$replace = array (
			"\$descriptions[trim(strtolower('$1'))]",
			"<a target=_new href=\"http$1://$2\">$3</a>",
			"<a target=_new href=\"mailto:$1\">$2</a>",
			"retLink('$0')",
			"$1<a href=\"mailto:$3$4$5\">$3$4$5</a>",
			"[$1]",
			"str_replace('*http:','http:','$0')",
			"$2$3$4",
		);

		return trim(preg_replace($patterns,$replace," $body_text "));
	} else {
		return trim($body_text);
	}
}

function retLink($linkx) {
$linkx = trim($linkx);
if (strlen($linkx) > 50) {
	return " [<a target=_new title=\"$linkx\" href=\"$linkx\">shortened link</a>]";
} elseif (strlen($linkx) > 20) {
	return " <a target=_new title=\"$linkx\" href=\"$linkx\">".str_replace('&','& ',str_replace('=','= ',str_replace('/','/ ',str_replace('http://','',str_replace('http://www.','',$linkx)))))."</a>";
} else {
	return " <a target=_new title=\"$linkx\" href=\"$linkx\">$linkx</a>";
}
}

function stripNonAN($text) {

//strips all non-alpha&numeric characters
return ereg_replace('[^a-zA-Z0-9_\-]','',$text);

}

function stripNick($nick) {
if (retLoggedIn()) {
return $nick;
} else {
return stripNonAN($nick);
}
}


//PHP bugfix, arrgh.
function session_regglobals_workaround() // by Hans Spath
{
  global $HTTP_SESSION_VARS;

  if ( ini_get('register_globals') )
    foreach ( $HTTP_SESSION_VARS as $varname=>$value )
      if ( session_is_registered($varname) )
        $GLOBALS[$varname] = $value;
}


function createWizard($data,$function) {


$retVal = $retVal."<form method=post action=save.php name=f>";
$retVal = $retVal."<table border=0 border=0 cellpadding=0 cellspacing=1 bgcolor=black><tr>";
$count = count($data);
for ($i=0;$i<$count;$i++) {
$retVal = $retVal."<td width=75 height=30 class=wizheader valign=middle id=head".($i+1).">";
$retVal = $retVal."<a onclick=\"swapDisplay(".($i+1).");return false;\" href=\"#".($i+1)."\">".digitmang($i+1)."</a></td>";
}
$retVal = $retVal."</tr></table>";
$retVal = $retVal."<input type=hidden name=function value=$function>";

for ($i=0;$i<$count;$i++) {

$retVal = $retVal.createSlide($data[$i],$i,$count);

}

$retVal = $retVal."</form>
<script>\n";

for ($i=0;$i<$count;$i++) {
if ($i > 0) {
$retVal = $retVal."document.getElementById('body".($i+1)."').style.display = 'none';\n";
}
}

$retVal = $retVal."document.getElementById('head1').style.background = '#FEB900';
function swapDisplay(id) {\n";


for ($i=0;$i<$count;$i++) {
$retVal = $retVal."document.getElementById('body".($i+1)."').style.display = 'none';\n";
$retVal = $retVal."document.getElementById('head".($i+1)."').style.background = '#AE7B00';\n";
}

$retVal = $retVal."document.getElementById('body'+id).style.display = 'block';
document.getElementById('head'+id).style.background = '#FEB900';
if (document.getElementById('body'+id).style.display != 'block') {
document.location.href = '#'+id;
}
}
</script>";

return $retVal;

}

function createSlide($data,$num,$total) {


$retVal = $retVal."<a name=\"".($num+1)."\"></a>";
$retVal = $retVal."<div class=wizbody id=body".($num+1).">";
$retVal = $retVal."<table border=0 width=100% cellpadding=5>";
$retVal = $retVal."<tr><td colspan=2><strong><i>".$data['title']."</i></strong><br>".$data['description'];
$retVal = $retVal."<tr><td width=50%><strong><i>Name</i></strong></td><td width=50%><strong><i>Value</i></strong></td></tr>";
$retVal = $retVal.createItems($data['fields']);

if ($num == $total-1) {
$retVal = $retVal."<tr><td colspan=2 align=right>[<a onclick=\"swapDisplay(".$num.");return false;\" href=\"#".$num."\">previous</a>] [<a href=\"javascript:document.forms['f'].submit();\">finish</a>]</td></tr>";
} elseif ($num == 0) {
$retVal = $retVal."<tr><td colspan=2 align=right>[<a onclick=\"swapDisplay(".($num+2).");return false;\" href=\"#".($num+2)."\">next</a>]</td></tr>";
} else {
$retVal = $retVal."<tr><td colspan=2 align=right>[<a onclick=\"swapDisplay(".($num).");return false;\" href=\"#".($num)."\">previous</a>] [<a onclick=\"swapDisplay(".($num+2).");return false;\" href=\"#".($num+2)."\">next</a>]</td></tr>";
}

$retVal = $retVal."</table></div>";

return $retVal;

}

function createItems($data) {

$count = count($data);
for ($i=0;$i<$count;$i++) {
$retVal = $retVal."<tr><td valign=top>".$data[$i]['name']."</td><td>".$data[$i]['value']."</td></tr>";
}
return $retVal;

}

function digitmang($digit) {

$digits = array(
0 => "zero",
1 => "one",
2 => "two",
3 => "three",
4 => "four",
5 => "five",
6 => "six",
7 => "seven",
8 => "eight",
9 => "nine",
);

return $digits[$digit];

}


// CREATE DROP-DOWN CATEGORY LIST

function categoryList($defaultValue) {

	global $link;
$retVal = "<SELECT NAME=\"category\">\n";
	$query = "SELECT categoryName FROM categories ORDER BY categoryName;";
	$result = mysql_query ($query, $link) or die (mysql_error());
	while (list($categoryName) = mysql_fetch_row($result)) {
		if ($categoryName == $defaultValue) {
			$retVal = $retVal."<OPTION VALUE=\"$categoryName\" selected>$categoryName\n";
		} else {
			$retVal = $retVal."<OPTION VALUE=\"$categoryName\">$categoryName\n";
		}
	}
	$retVal = $retVal."</SELECT>";

return $retVal;

}



// CREATE DROP-DOWN SEGMENT LIST

function segmentList($defaultValue) {

	global $link;
	$retVal = "<SELECT NAME=\"segment\">\n";
	$query = "SELECT segmentName FROM segments ORDER BY segmentName;";
	$result = mysql_query ($query, $link) or die (mysql_error());
	while (list($segmentName) = mysql_fetch_row($result)) {
		if ($segmentName == $defaultValue) {
			$retVal = $retVal."<OPTION VALUE=\"$segmentName\" selected>$segmentName\n";
		} else {
			$retVal = $retVal."<OPTION VALUE=\"$segmentName\">$segmentName\n";
		}
	}
	$retVal = $retVal."</SELECT>";

return $retVal;

}

// CREATE DESCRIPTIONS THINGIE

function descList($defaultValue) {
	global $link;
	$retVal = "<SELECT NAME=\"description\" onChange=\"document.getElementById('descbox').innerHTML = unescape(this.options[this.selectedIndex].label);\">\n";
	$retVal = $retVal."<OPTION VALUE=\"\" selected>New\n";
	$query = "SELECT TRIM(`index`),`description` FROM descriptions ORDER BY 'index';";
	$result = mysql_query ($query, $link) or die (mysql_error());
	while (list($index,$description) = mysql_fetch_row($result)) {
		if ($index == $defaultValue) {
			$retVal = $retVal."<OPTION VALUE=\"$index\" LABEL=\"".rawurlencode($description)."\" selected>$index\n";
		} else {
			$retVal = $retVal."<OPTION VALUE=\"$index\" LABEL=\"".rawurlencode($description)."\">$index\n";
		}
	}
	$retVal = $retVal."</SELECT><div id=descbox></div>";

return $retVal;

}


session_regglobals_workaround();

?>
Return current item: Backend code/CMS for blizzle.com