Location: PHPKode > projects > iPei Guestbook > ipei-guestbook/guestbook/functions.php
<?PHP

// iPei Guestbook v2.0
// (c) Paley Wu
// www.epistream.com

include "config.php";

function Smile($text)
{
	global $sm,$num;
   	return str_replace($sm, $num, $text);
}

function spaceout($input,$len)
{ 
 $l = 0; 
 $output = ""; 
 for ($i = 0; $i < strlen($input); $i++) { 
  $char = substr($input,$i,1); 
  if ($char != " ") { $l++; } else { $l = 0; } 
  if ($l == $len) { $l = 0; $output .= " "; } 
  $output .= $char; 
 } 
 return($output); 
}

function breaktxt($stringtext)
{
global $width,$sss,$allowed_html_tag;
$limit = ($width - 31)/14;
$limit = ceil($limit);

$stringtext = strip_tags($stringtext, $allowed_html_tag);

$stringtext = str_replace("\n", " <br>", $stringtext);

$stringtext = spaceout($stringtext, $limit);
if ($sss == 1)
	return Smile($stringtext);
else
	return $stringtext;
}

function convert_datetime($datestamp, $format)
{

    if ($datestamp!=0) {

        list($date, $time)=split(" ", $datestamp);

        list($year, $month, $day)=split("-", $date);

        list($hour, $minute, $second)=split(":", $time);

        $stampeddate=mktime($hour,$minute,$second,$month,$day,$year);

        $datestamp=date($format,$stampeddate);

        return $datestamp;
    }

}

function displayEntry ($name,$msg,$comment,$eml,$hp,$entrytime,$br,$entrynum)
{
	global $hptarget,$width,$font,$fcolor,$fsize;
	$topborder = $width - 67;
	$botborder = $width - 31;
	$textwidth = $width - 31;
	$name_res = substr($name,0,$textwidth/9);
	$name_res = strip_tags($name_res);

	$entryinfo = $entrytime;
	if ($entrynum != NULL)
		$entryinfo = $entryinfo . " ($entrynum) <a href=index.php?a=login&e=$entrynum>e</a>";
	
	echo "<table width=$width border=0 cellpadding=0 cellspacing=0><tr>";
	echo "<td><img src=ipei_imgs/top_left_cor.gif width=15 height=25></td>";
	echo "<td width=$topborder valign=center background=ipei_imgs/top_border.gif><img src=ipei_imgs/blank.gif width=$topborder height=1><br><font size=2 face=arial color=black><b> $name_res</b></font></td>";

	if ($eml == "")
		echo "<td background=ipei_imgs/top_border.gif><img src=ipei_imgs/email_less.gif width=19 height=25></td>";
	else
		echo "<td background=ipei_imgs/top_border.gif><a href=\"mailto:$eml\" rel=\"nofollow\"><img src=ipei_imgs/email.gif width=19 height=25 border=0 alt=Email></a></td>";
	
	if (($hp == "") or ($hp == "http://"))
		echo "<td background=ipei_imgs/top_border.gif><img src=ipei_imgs/homepage_less.gif width=17 height=25></td>";
	else
		echo "<td background=ipei_imgs/top_border.gif><a href=\"$hp\" rel=\"nofollow\" target=$hptarget><img src=ipei_imgs/homepage.gif width=17 height=25 border=0 alt=Homepage></a></td>";

	echo "<td><img src=ipei_imgs/top_right_cor.gif width=16 height=25></td></tr>";
	echo "<tr><td background=ipei_imgs/left_border.gif><img src=ipei_imgs/blank.gif width=1 height=1></td>";

	echo "<td colspan=3 valign=top bgcolor=#FFFFFF width=$textwidth><font face=\"$font\" color=$fcolor size=$fsize><img src=ipei_imgs/blank.gif width=1 height=6><br>";
	if ($br == 1)
		echo breaktxt($msg);
	else
		echo $msg;
	echo "<br><img src=ipei_imgs/blank.gif width=1 height=4><br><table width=100% cellpadding=0 cellspacing=0 border=0><tr><td width=100% align=right><font color=gray size=1 face=arial><i>$entryinfo</i></font></td></tr></table>";
	if ($comment != "")
	{
		echo "<table width=100% cellspacing=0 cellpadding=0><tr><td height=6><img src=ipei_imgs/blank.gif height=1></td></tr></table><font size=1 color=GRAY> &nbsp; &nbsp; follow up</font><br><table width=100% cellspacing=0 cellpadding=0><tr><td bgcolor=#CACACA><img src=ipei_imgs/blank.gif height=1></td></tr><tr><td height=6><img src=ipei_imgs/blank.gif height=1></td></tr></table>";
		if ($br == 1)
			echo breaktxt($comment);
		else
			echo $comment;
		
	}
	echo "</font></td><td background=ipei_imgs/right_border.gif><img src=ipei_imgs/blank.gif width=1 height=1></td></tr>";
	
	echo "<tr><td><img src=ipei_imgs/bot_left_cor.gif width=15 height=18></td>";
	echo "<td colspan=3 background=ipei_imgs/bot_border.gif width=$botborder><img src=ipei_imgs/blank.gif width=$botborder height=1></td>";
	echo "<td><img src=ipei_imgs/bot_right_cor.gif width=16 height=18></td></tr></table>";
	echo "<img src=ipei_imgs/blank.gif width=1 height=5><br>\r\n";	

}

function isbanned($ip,$isp)
{
	global $spamfilter;

	$banned_ip = file('ipban.dat');
	$segm_ip = explode(".", $ip);

	if ($banned_ip=="" or count($banned_ip)==0)
		return false;
	for ($h=0;$h<count($banned_ip);$h++)
	{
		$banned_ip[$h] = trim($banned_ip[$h]);
		$segm_banned_ip = explode(".", $banned_ip[$h]);

		$point = 0;

		if ($segm_banned_ip[0]==$segm_ip[0] or $segm_banned_ip[0]=="*")
		{
			$point++;
			if ($segm_banned_ip[1]==$segm_ip[1] or $segm_banned_ip[1]=="*")
			{
				$point++;
				if ($segm_banned_ip[2]==$segm_ip[2] or $segm_banned_ip[2]=="*")
				{
					$point++;
					if ($segm_banned_ip[3]==$segm_ip[3] or $segm_banned_ip[3]=="*")
						$point++;
				}
			}
		}
		if($point>=4)
			return true;
		if($point>=2 and $spamfilter>=2)
			return true;
	}
	
	return false;
}

function hasBannedWord()
{
	global $spamfilter;

	$string = $_POST[email] . $_POST[homepage];

	if ($spamfilter >= 2)
		$string .= $_POST[name] . $_POST[message];

	$slist = file('slist.dat');
	for ($h=0;$h<count($slist);$h++)
	{
		if (stristr($string,trim($slist[$h])))
			return true;
	}
	return false;
}

function cleanup()
{
mysql_close();
echo "<br><br><font face=arial size=1>";
global $home;
if ($home != "")
	echo "<a href=\"$home\">Home</a> | ";
echo "<a href=http://www.epistream.com/ipei/ target=_blank>iPei Guestbook</a></font>";
}

function errinc($type)
{
echo "<font size=2 face=arial><a href=\"javascript:history.back()\"><img src=ipei_imgs/arrow_left.gif border=0></a><br></font>";
/*debug/stats use
		$query="SELECT * FROM `iPei_spam_block` WHERE 1 AND `x0` = 0";
		$blok=mysql_query($query);
		$count = mysql_result($blok,0,$type);

		$count++;

		$Q="UPDATE `iPei_spam_block` SET `$type` = $count WHERE `x0` = 0";
		mysql_query($Q);
*/
}
?>
Return current item: iPei Guestbook