Location: PHPKode > projects > KISGB (Keep It Simple Guest Book) > kisgb/functions.php
<?
/*
   KISGB - a Guest Book script written in PHP.
   Copyright (C) 2001-2002 Gaylen Fraley
   hide@address.com

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   License file for more details.
*/
function gethost($ip) {
	global $useGetHostByAddr;
	if (!$useGetHostByAddr) return $ip;
	if (isSet($_SERVER)) {
		if (isSet($_SERVER["HTTP_X_FORWARDED_FOR"])) {
			$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
		} elseif (isSet($_SERVER["HTTP_CLIENT_IP"])) {
			$realip = $_SERVER["HTTP_CLIENT_IP"];
		} else {
			$realip = $_SERVER["REMOTE_ADDR"];
		}

	} else

	if (isSet($HTTP_SERVER_VARS)) {
		if (isSet($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])) {
			$realip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
		} elseif (isSet($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])) {
			$realip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
		} else {
			$realip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
		}

	} else {
		if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
			$realip = getenv( 'HTTP_X_FORWARDED_FOR' );
		} elseif ( getenv( 'HTTP_CLIENT_IP' ) ) {
			$realip = getenv( 'HTTP_CLIENT_IP' );
		} else {
			$realip = getenv( 'REMOTE_ADDR' );
		}
	}
	return @gethostbyaddr($realip);
}

function setupStuff() {
	if (!isset($_GET) && !isset($_POST)) {
	        $_GET = @$HTTP_GET_VARS;
	        $_POST = @$HTTP_POST_VARS;
	        $_COOKIE = @$HTTP_COOKIE_VARS;
	        $_SESSION = @$HTTP_SESSION_VARS;
	        $_ENV = @$HTTP_ENV_VARS;
	        $_SERVER = @$HTTP_SERVER_VARS;
	}
}

function applyNukeTheme() {
	global $REQUEST_URI, $path_to_nuke_directory;
	$x=parse_url($REQUEST_URI);
	$vars = explode('=',$x['query']);
	$nuke_theme = '';
	for ($i=0;$i<count($vars);$i++) {
		if ($vars[$i]=='nuke_theme') $nuke_theme = $vars[$i+1];
	}
	if (!empty($nuke_theme)) {
		$nuke_theme =  "<LINK REL=\"StyleSheet\" HREF=\"$path_to_nuke_directory/themes/$nuke_theme/style/style.css\" TYPE=\"text/css\">";
	}
		echo  "<LINK REL=\"StyleSheet\" HREF=\"$path_to_nuke_directory/themes/Sand_Journey/style/style.css\" TYPE=\"text/css\">";

	return $nuke_theme;
}

function whoami () {
	global $myIP; global $rmt_ip;
	if ($myIP=="*") return true;
	$ips = explode(",",$myIP);
	for ($i=0;$i<count($ips);$i++) {
		if ($ips[$i]==$rmt_ip||$ips[$i]=="*") return true;
	}
	return false;
}

function check_php_version() {
	// check if version is above 4.0.n
	if (ereg( "[4-9]\.[0-9]\.[0-9].*", phpversion() ));
	else {echo "<html><body><form method=\"post\"><table border=\"1\" width=\"75%\" align=\"center\"><tr><td align=\"center\">This version of KISGB requires PHP version 4.0.x or higher.<br /><br />It appears that you do not have the required version.<br /><br />KISGB cannot continue.  Sorry!</td></tr></table></form>";
	exit();}
}

function makeLink($msg) {
	global $id;
	global $Vwindow_url_color1;
	global $Vwindow_url_color2;
	if (strtolower($id)=="td1") $url_color = $Vwindow_url_color1;
	else $url_color = $Vwindow_url_color2;
	$msg = str_replace("\n"," \n",$msg);//Keeps c/r out of links
        $msg = str_replace("<br"," <br",$msg);//Keeps c/r out of links
	// this next line forces a space in the event someone enters just a url and no space after.
	$msg = $msg." ";
	$chkit = explode(" ",$msg);
	for ($i=0;$i<count($chkit);$i++) {
		if (eregi("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",$chkit[$i])) {
			//  do not convert any text that already has href and *:// in it
			if (FALSE!==strpos(strtolower($chkit[$i]),"href=")||FALSE!==strpos(strtolower($chkit[$i]),"src="));
			elseif (!strpos($chkit[$i],"href=")&&!strpos($chkit[$i],"http://")&&!strpos($chkit[$i],"https://")) {
				$chkit[$i] = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])","<a href=\"\\1://\\2\\3\" target=\"_blank\"><span style=\"color:$url_color;\">\\1://\\2\\3</span></a>", $chkit[$i]);
			}
			elseif (strpos($chkit[$i],"href=")===FALSE&&strpos($chkit[$i],"http://")) {
				$chkit[$i] = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])","<a href=\"\\1://\\2\\3\" target=\"_blank\"><span style=\"color:$url_color;\">\\1://\\2\\3</span></a>", $chkit[$i]);
			}
		}
	}
	$msg = implode(" ",$chkit);
	$msg = " ".$msg; /* Needed to force recognition of hyperlinks in preg_replace routine when link starts at beginning of comment. All the routines here can easily step on each other, so some tricks are required to keep a delicate balance.  Modify with caution! */
	$msg = eregi_replace('<',' <',$msg);
	//  convert any text that already has ftp. in it.
	$msg = preg_replace("/[ |\n](ftp\.[^ ]*\.[^ ]*) /i"," <a href='http://\\1' target='_blank'><span style=\"color:$url_color;\">\\1</span></a> ",$msg);
	//  convert any text that already has www. in it, but not ftp
	$msg = preg_replace("/[ |\n](www[^ ]*\.[^ ]*\.[^ ]*) /i"," <a href='http://\\1' target='_blank'><span style=\"color:$url_color;\">\\1</span></a> ",$msg);
	$msg = str_replace(" \n","\n",$msg);
        $msg = str_replace(" <br","<br",$msg);
	return $msg;
}

function js_getPointer() {
$js_string = <<<_JAVASCRIPT_
	<script type="text/javascript">
		function get_pointer() {
			var agt=navigator.userAgent.toLowerCase();
			var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
			pointer = 'pointer';
			if (is_ie) pointer = 'hand';
			return pointer;
		}
	</script>
_JAVASCRIPT_;
echo $js_string;
}

function metaTags() {
	global $charset;
	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; $charset\" />\n";
	echo "<meta name=\"Keywords\" content=\"php,PHP,guestbook,guest book,GuestBook,Guest Book\" />\n";
	echo "<meta name=\"Description\" content=\"KISGB is a robust, easy to use, and fully customizable PHP Guest Book!\" />\n";
	echo "<meta name=\"Author\" content=\"Gaylen Fraley\" />\n";
}

function entryErrorCheck($myArray) {
	global $invalid_email_msg, $badwords, $bad_language_msg, $label_back, $require_name, $require_email,$require_nation, $required_field_missing_msg, $field_size_error_msg, $max_smileys_allowed, $label_smiley_message, $max_name_length, $max_email_length, $max_nation_length, $max_comment_length, $label_comment;
	$globalMsg = 'global ';
	for ($i=1;$i<17;$i++) {
		if ($i<16) $globalMsg .= '$col'.$i.', ';
		else $globalMsg .= '$col'.$i.'';
	}
	$globalMsg .= ';';
	eval($globalMsg);
	while (list ($key, $val) = each ($myArray)) {
		$val = trim($val);
		for ($i=0;$i<count($badwords);$i++) {
			$tmpval = strip_tags($val);
			if (strpos(strtolower($tmpval),strtolower($badwords[$i]))===false) {}
			else {
				?>
				<table align="center" border="2" width="50%" bgcolor="lightyellow">
				<tr><td align="center"><?=$bad_language_msg?><br /><font color="red"><b><?="$key = $val"?></b></font>
				<br />
				<br />
				<a href="javascript:history.go(-1)"><?=$label_back?></a>
				</td></tr>
				</table>
				<?
				include_once 'footer.php';
				exit;
			}
		}
		if (($key==$col5&&($require_name||!empty($val)))) {
			if (strlen($val)>$max_name_length) {
				$sub = str_replace('???',$max_name_length,$field_size_error_msg);
				?>
				<table align="center" border="2" width="50%" bgcolor="lightyellow">
				<tr><td align="center"><?=str_replace('\n',"<br />",nl2br($sub));?><br /><font color="red"><b><?="$key"?></b></font>
				<br />
				<br />
				<a href="javascript:history.go(-1)"><?=$label_back?></a>
				</td></tr>
				</table>
				<?
				include_once 'footer.php';
				exit;
			}
			if ($require_name&&(strlen($val)==0||substr($val,0,1)==" "||empty($val))) {
				?>
				<table align="center" border="2" width="50%" bgcolor="lightyellow">
				<tr><td align="center"><?=str_replace('\n',"<br />",nl2br($required_field_missing_msg));?><br /><font color="red"><b><?="$key = $val"?></b></font>
				<br />
				<br />
				<a href="javascript:history.go(-1)"><?=$label_back?></a>
				</td></tr>
				</table>
				<?
				include_once 'footer.php';
				exit;
			}
		}
		if (($key==$col6&&($require_email||!empty($val)))) {
			$re = "/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i";
			if (!preg_match($re,$val)) {
				?>
				<table align="center" border="2" width="50%" bgcolor="lightyellow">
				<tr><td align="center"><?=str_replace('\n',"<br />",nl2br($invalid_email_msg));?><br /><font color="red"><b><?="$key = $val"?></b></font>
				<br />
				<br />
				<a href="javascript:history.go(-1)"><?=$label_back?></a>
				</td></tr>
				</table>
				<?
				include_once 'footer.php';
				exit;
			}
			if (strlen($val)>$max_email_length) {
				$sub = str_replace('???',$max_email_length,$field_size_error_msg);
				?>
				<table align="center" border="2" width="50%" bgcolor="lightyellow">
				<tr><td align="center"><?=str_replace('\n',"<br />",nl2br($sub));?><br /><font color="red"><b><?="$key"?></b></font>
				<br />
				<br />
				<a href="javascript:history.go(-1)"><?=$label_back?></a>
				</td></tr>
				</table>
				<?
				include_once 'footer.php';
				exit;
			}
			if (require_email&&(strlen($val)==0||substr($val,0,1)==" "||empty($val))) {
				?>
				<table align="center" border="2" width="50%" bgcolor="lightyellow">
				<tr><td align="center"><?=str_replace('\n',"<br />",nl2br($required_field_missing_msg));?><br /><font color="red"><b><?="$key = $val"?></b></font>
				<br />
				<br />
				<a href="javascript:history.go(-1)"><?=$label_back?></a>
				</td></tr>
				</table>
				<?
				include_once 'footer.php';
				exit;
			}
		}
		if (($key==$col13&&($require_nation||!empty($val)))) {
			if ($require_nation&&(strlen($val)==0||substr($val,0,1)==" "||$val=="blank.gif"||empty($val))) {
				?>
				<table align="center" border="2" width="50%" bgcolor="lightyellow">
				<tr><td align="center"><?=str_replace('\n',"<br />",nl2br($required_field_missing_msg));?><br /><font color="red"><b><?="$key = $val"?></b></font>
				<br />
				<br />
				<a href="javascript:history.go(-1)"><?=$label_back?></a>
				</td></tr>
				</table>
				<?
				include_once 'footer.php';
				exit;
			}
		}
		if ($key!=$col14) continue;
		if (!(strpos(strtolower($val),'<img')===FALSE&&strpos(strtolower($val),'&lt;img')===FALSE)) {
			$cnt_img = substr_count(strtolower($val),'&lt;img') + substr_count(strtolower($val),'<img');
			if ($cnt_img>$max_smileys_allowed) {
				?>
				<table align="center" border="2" width="50%" bgcolor="lightyellow">
				<tr><td align="center"><?=$label_smiley_message?><br /><font color="red"><b><?="$key = $val"?></b></font>
				<br />
				<br />
				<a href="javascript:history.go(-1)"><?=$label_back?></a>
				</td></tr>
				</table>
				<?
				include_once 'footer.php';
				exit;
			}
		}
		if (strlen($val)>$max_comment_length) {
			?>
			<table align="center" border="2" width="50%" bgcolor="lightyellow">
			<tr><td align="center"><?=$label_comment;?>
			<br />
			<br />
			<a href="javascript:history.go(-1)"><?=$label_back?></a>
			</td></tr>
			</table>
			<?
			include_once 'footer.php';
			exit;
		}
		if (empty($val)||strlen($val)==0||substr($val,0,1)==" ") {
			?>
			<table align="center" border="2" width="50%" bgcolor="lightyellow">
			<tr><td align="center"><?=str_replace('\n',"<br />",nl2br($required_field_missing_msg));?><br /><font color="red"><b><?="$key = $val"?></b></font>
			<br />
			<br />
			<a href="javascript:history.go(-1)"><?=$label_back?></a>
			</td></tr>
			</table>
			<?
			include_once 'footer.php';
			exit;
		}
	}
}

function registerUser() {
	return;
	/*** 7/19/2002 ***/
	global $path_to_registry,$allow_registering,$password,$registry_msg,$label_back,$name,$label_register;
	if ($allow_registering) {
		if (file_exists($path_to_registry)) {
			$registry = file($path_to_registry);
			$registry = explode('%',$registry[0]);
			$registered = FALSE;
			for ($i=0;$i<count($registry);$i++) {
				$registryx = explode('=',$registry[$i]);
				if (strtolower("$registryx[0]") == strtolower("$name")&&"$registryx[1]"!="$password") {
				?>
					<table align="center" border="2" width="50%" bgcolor="lightyellow">
					<tr><td align="center"><?=$registry_msg?><br /><br />
					<a href="javascript:history.go(-1)"><?=$label_back?></a>
					</td></tr>
					</table>
				<?
				exit;
				}
				else if (strtolower("$registryx[0]") == strtolower("$name")) $registered = TRUE;
			}
/************* NOT YET DEVELOPED -- IN PROGRESS -- DO NOT USE *************
			if (!$registered) { $label_register = "Register";
				?>
					<table align="center" border="2" width="50%" bgcolor="lightyellow">
					<tr><td align="center">This user name is not yet registered.  Would you like to register this name and all information?  Registering a name allows your information to be stored and you will not have to re-enter it on each visit. If you select the <?=$label_register?> link below, the information that you entered on the previous page will be added to the guestbook AND the information will be stored for usage on your next visits.<br /><br />
					<a href="register_user.php"><?=$label_register?></a>&nbsp;&nbsp;&nbsp;<a href="javascript:history.go(-1)"><?=$label_back?></a>
					</td></tr>
					</table>
				<?
				exit;
			}
************* NOT YET DEVELOPED -- IN PROGRESS -- DO NOT USE ************/
		}
	}
}

?>
Return current item: KISGB (Keep It Simple Guest Book)