<?php
/*
* Copyright 2003 - 2005 Mark O'Sullivan
* This file is part of Lussumo's Software Library.
* Lussumo's Software Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
* Lussumo's Software Library 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 GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* The latest source code is available at www.lussumo.com
* Contact Mark O'Sullivan at mark [at] lussumo [dot] com
*
* Description: Non-application specific helper functions
* Modified by Rob Ford 26/8/2005
*
*/
// Create the html_entity_decode function for users prior to PHP 4.3.0
if(!function_exists("html_entity_decode")) {
function html_entity_decode($String) {
$TranslationTable = get_html_translation_table(HTML_ENTITIES);
$TranslationTable = array_flip($TranslationTable);
return strtr($String, $TranslationTable);
}
}
class Utility {
var $f;
function Utility(&$f) {
$this->f =& $f;
}
function AddDaysToTimeStamp($TimeStamp, $NumberOfDaysToAdd) {
if($NumberOfDaysToAdd == 0) {
return $TimeStamp;
}
else {
return strtotime("+".$NumberOfDaysToAdd." day", $TimeStamp);
}
}
function SubtractDaysFromTimeStamp($TimeStamp, $NumberOfDaysToSubtract) {
if($NumberOfDaysToSubtract == 0) {
return $TimeStamp;
}
else {
return strtotime("-".$NumberOfDaysToSubtract." day", $TimeStamp);
}
}
// Based on the total number of items and the number of items per page,
// this function will calculate how many pages there are.
// Returns the number of pages available
function CalculateNumberOfPages($ItemCount, $ItemsPerPage) {
$TmpCount = ($ItemCount/$ItemsPerPage);
$RoundedCount = intval($TmpCount);
$PageCount = 0;
if($TmpCount > 1) {
if($TmpCount > $RoundedCount) {
$PageCount = $RoundedCount + 1;
}
else {
$PageCount = $RoundedCount;
}
}
else {
$PageCount = 1;
}
return $PageCount;
}
// performs the opposite of htmlentities
function DecodeHtmlEntities($String) {
/*
$TranslationTable = get_html_translation_table(HTML_ENTITIES);
print_r($TranslationTable);
$TranslationTable = array_flip($TranslationTable);
return strtr($String, $TranslationTable);
return html_entity_decode(htmlentities($String, ENT_COMPAT, 'UTF-8'));
*/
$String= html_entity_decode($String, ENT_QUOTES, "ISO-8859-1"); #NOTE: UTF-8 does not work!
$String= preg_replace('/&#(\d+);/me',"chr(\\1)", $String); #decimal notation
$String= preg_replace('/&#x([a-f0-9]+);/mei',"chr(0x\\1)", $String); #hex notation
return $String;
}
// return the opposite of the given boolean value
function FlipBool($Bool) {
$Bool = $this->ForceBool($Bool, 0);
return $Bool?0:1;
}
// Take a value and force it to be an array.
function ForceArray($InValue, $DefaultValue) {
if(is_array($InValue)) {
$aReturn = $InValue;
}
else {
// assume it's a string
$sReturn = trim($InValue);
$length = strlen($sReturn);
if($length == 0) {
$aReturn = $DefaultValue;
}
else {
$aReturn = array($sReturn);
}
}
return $aReturn;
}
// Force a boolean value
// Accept a default value if the input value does not represent a boolean value
function ForceBool($InValue, $DefaultBool) {
// If the invalue doesn't exist (ie an array element that doesn't exist) use the default
if(!$InValue) $InValue = $DefaultBool;
$InValue = strtoupper($InValue);
$bReturn = $DefaultBool;
if($InValue == "TRUE" || $InValue == "FALSE" || $InValue == 1 || $InValue == 0 || $InValue == "Y" || $InValue == "N") {
if($InValue == "TRUE" || $InValue == 1 || $InValue == "Y") {
$bReturn = 1;
}
else {
$bReturn = 0;
}
}
return $bReturn;
}
// Take a value and force it to be a float (decimal) with a specific number of decimal places.
function ForceFloat($InValue, $DefaultValue, $DecimalPlaces = 2) {
$fReturn = floatval($InValue);
if($fReturn == 0) $fReturn = $DefaultValue;
$fReturn = number_format($fReturn, $DecimalPlaces);
return $fReturn;
}
// Check both the get and post incoming data for a variable
function ForceIncomingArray($VariableName, $DefaultValue) {
// First check the querystring
$aReturn = $this->ForceSet(@$_GET[$VariableName], $DefaultValue);
$aReturn = $this->ForceArray($aReturn, $DefaultValue);
// If the default value was defined, then check the post variables
if($aReturn == $DefaultValue) {
$aReturn = $this->ForceSet(@$_POST[$VariableName], $DefaultValue);
$aReturn = $this->ForceArray($aReturn, $DefaultValue);
}
return $aReturn;
}
// Check both the get and post incoming data for a variable
function ForceIncomingBool($VariableName, $DefaultBool) {
// First check the querystring
$bReturn = $this->ForceSet(@$_GET[$VariableName], $DefaultBool);
$bReturn = $this->ForceBool($bReturn, $DefaultBool);
// If the default value was defined, then check the post variables
if($bReturn == $DefaultBool) {
$bReturn = $this->ForceSet(@$_POST[$VariableName], $DefaultBool);
$bReturn = $this->ForceBool($bReturn, $DefaultBool);
}
return $bReturn;
}
function ForceIncomingCookieString($VariableName, $DefaultValue) {
$sReturn = $this->ForceSet(@$_COOKIE[$VariableName], $DefaultValue);
$sReturn = $this->ForceString($sReturn, $DefaultValue);
return $sReturn;
}
// Check both the get and post incoming data for a variable
// Does not allow integers to be less than 0
function ForceIncomingInt($VariableName, $DefaultValue) {
// First check the querystring
$iReturn = $this->ForceSet(@$_GET[$VariableName], $DefaultValue);
$iReturn = $this->ForceInt($iReturn, $DefaultValue);
// If the default value was defined, then check the form variables
if($iReturn == $DefaultValue) {
$iReturn = $this->ForceSet(@$_POST[$VariableName], $DefaultValue);
$iReturn = $this->ForceInt($iReturn, $DefaultValue);
}
// If the value found was less than 0, set it to the default value
if($iReturn < 0) $iReturn == $DefaultValue;
return $iReturn;
}
// Check both the get and post incoming data for a variable
function ForceIncomingString($VariableName, $DefaultValue) {
// First check the querystring
$sReturn = $this->ForceSet(@$_GET[$VariableName], $DefaultValue);
$sReturn = $this->ForceString($sReturn, $DefaultValue);
// If the default value was defined, then check the post variables
if($sReturn == $DefaultValue) {
$sReturn = $this->ForceSet(@$_POST[$VariableName], $DefaultValue);
$sReturn = $this->ForceString($sReturn, $DefaultValue);
}
// And strip slashes from the string
$sReturn = stripslashes($sReturn);
return $sReturn;
}
// Take a value and force it to be an integer.
function ForceInt($InValue, $DefaultValue) {
$iReturn = intval($InValue);
if($iReturn == 0) {
$iReturn = $DefaultValue;
}
return $iReturn;
}
// Takes a variable and checks to see if it's set.
// Returns the value if set, or the default value if not set.
function ForceSet($InValue, $DefaultValue) {
if(isset($InValue)) {
$sReturn = $InValue;
}
else {
$sReturn = $DefaultValue;
}
return $sReturn;
}
// Take a value and force it to be a string.
function ForceString($InValue, $DefaultValue) {
if(is_string($InValue)) {
$sReturn = trim($InValue);
$length = strlen($sReturn);
if($length == 0) {
$sReturn = $DefaultValue;
}
}
else {
$sReturn = $DefaultValue;
}
return $sReturn;
}
// Take date parts and put them in mysql_friendly format
// If no values are supplied, it will return the current date
function FormatDate($Year = "", $Month = "", $Day = "", $Format = "mysql", $Hour = "", $Minute = "", $Second = "") {
// Manipulate year
$Year = $this->ForceInt($Year, 0);
if($Year == 0 || strlen($Year) != 4) {
$Year = date("Y", mktime());
}
// Manipulate month
$Month = $this->ForceInt($Month, 0);
if($Month <= 0 || $Month > 12) {
$Month = date("n", mktime());
}
// Manipulate Day
$Day = $this->ForceInt($Day, 0);
if($Day <= 0 || $Day > 31) {
$Day = date("j", mktime());
}
// Manipulate Hour
$Hour = $this->ForceInt($Hour, 0);
if($Hour <= 0 || $Hour > 23) {
$Hour = 0;
}
// Manipulate Minute
$Minute = $this->ForceInt($Minute, 0);
if($Minute <= 1 || $Minute > 60) {
$Minute = 0;
}
// Manipulate Second
$Second = $this->ForceInt($Second, 0);
if($Second <= 1 || $Second > 60) {
$Second = 0;
}
if($Format == "unixtimestamp") {
return mktime($Hour, $Minute, $Second, $Month, $Day, $Year);
}
else {
$Month = $this->PrefixString($Month, "0", 2);
$Day = $this->PrefixString($Day, "0", 2);
$Hour = $this->PrefixString($Hour, "0", 2);
$Minute = $this->PrefixString($Minute, "0", 2);
$Second = $this->PrefixString($Second, "0", 2);
return $Year."-".$Month."-".$Day." ".$Hour.":".$Minute.":".$Second;
}
}
function formatUrl($url) {
if(substr($testurl, 0, 7) != 'http://') {
$url = 'http://'.$url;
}
return $url;
}
function FormatHyperlink($InString, $ExternalTarget = "1", $LinkText = "") {
$ExternalTarget = ForceBool($ExternalTarget, 0);
$Target = "";
if($ExternalTarget) {
$Target = " onclick=\"window.open(this.href, 'win', '_blank')\"";
}
if(strpos($InString, "http://") == 0 && strpos($InString, "http://") !== false) {
if($LinkText == "") {
$Display = $InString;
if(substr($Display, strlen($Display)-1,1) == "/") {
$Display = substr($Display, 0, strlen($Display)-1);
}
$Display = str_replace("http://", "", $Display);
}
else {
$Display = $LinkText;
}
return "<a href=\"".$InString."\"".$Target.">".$Display."</a>";
}
elseif(strpos($InString, "mailto:") == 0 && strpos($InString, "mailto:") !== false) {
if($LinkText == "") {
$Display = str_replace("mailto:", "", $InString);
}
else {
$Display = $LinkText;
}
return "<a href=\"".$InString."\"".$Target.">".$Display."</a>";
}
elseif(strpos($InString, "ftp://") == 0 && strpos($InString, "ftp://") !== false) {
if($LinkText == "") {
$Display = str_replace("ftp://", "", $InString);
}
else {
$Display = $LinkText;
}
return "<a href=\"".$InString."\"".$Target.">".$Display."</a>";
}
elseif(strpos($InString, "aim:goim?screenname=") == 0 && strpos($InString, "aim:goim?screenname=") !== false) {
if($LinkText == "") {
$Display = str_replace("aim:goim?screenname=", "", $InString);
}
else {
$Display = $LinkText;
}
return "<a href=\"".$InString."\"".$Target.">".$Display."</a>";
}
else {
return ($LinkText == "")?$InString:$LinkText;
}
}
function FormatHtmlStringForNonDisplay($inValue) {
$sReturn = $this->ForceString($inValue, "");
$sReturn = htmlspecialchars($sReturn);
return str_replace("\r\n", "<br />", $sReturn);
}
function FormatHtmlStringInline($inValue, $StripSlashes = "0") {
$sReturn = $this->ForceString($inValue, "");
if($this->ForceBool($StripSlashes, 0)) {
$sReturn = stripslashes($sReturn);
}
$sReturn = htmlspecialchars($sReturn);
$sReturn = str_replace("\r\n", " ", $sReturn);
return $sReturn;
}
function FormatPlural($Number, $Singular, $Plural, $IncludeNumber = "1") {
$IncludeNumber = $this->ForceBool($IncludeNumber, 0);
$Return = "";
if($Number == 1) {
$Return = ($IncludeNumber?$Number." ":"").$Singular;
}
else {
$Return = ($IncludeNumber?$Number." ":"").$Plural;
}
return $Return;
}
function FormatPossessive($String) {
$Possessed = $String;
if($String != "") {
if(strtolower(substr($String, strlen($String)-1, 1)) == "s") {
$Possessed .= "'";
}
else {
$Possessed .= "'s";
}
}
return $Possessed;
}
// Formats a value so it's safe to insert into the database
function FormatStringForDatabaseInput($inValue, $bStripHtml = "0") {
$bStripHtml = $this->ForceBool($bStripHtml, 0);
// $sReturn = stripslashes($inValue);
$sReturn = $inValue;
if($bStripHtml) {
$sReturn = strip_tags($sReturn);
}
$sReturn = $this->ForceString($sReturn, "");
return addslashes($sReturn);
}
// Takes a user defined string and formats it for page display.
// You can optionally remove html from the string.
function FormatStringForDisplay($inValue, $bStripHtml = true) {
$sReturn = $this->ForceString($inValue, "");
$sReturn = stripslashes($sReturn);
if($bStripHtml) {
$sReturn = strip_tags($sReturn);
$sReturn = str_replace("\r\n", "<br />", $sReturn);
}
$sReturn = htmlspecialchars($sReturn);
return $sReturn;
}
function GetBasicCheckBox($Name, $Value = 1, $Checked, $Attributes = "") {
return "<input type=\"checkbox\" name=\"".$Name."\" value=\"".$Value."\" ".(($Checked == 1)?" checked=\"checked\"":"")." $Attributes />";
}
function GetBool($Bool, $True = "Yes", $False = "No") {
return ($Bool ? $True : $False);
}
function GetDynamicCheckBox($Name, $Value = 1, $Checked, $OnClick, $Text, $Attributes = "") {
$CheckBoxID = $Name."ID";
$Attributes .= " id=\"".$CheckBoxID."\" onclick=\"".$OnClick."\"";
// return GetBasicCheckBox($Name, $Value, $Checked, $Attributes)
// ." <a href=\"javascript:CheckBox('".$CheckBoxID."');".$OnClick."\">".$Text."</a>";
return "<label>".$this->GetBasicCheckBox($Name, $Value, $Checked, $Attributes)." ".$Text."</label>";
}
function GetEmail($Email, $LinkText = "") {
if($Email == "") {
return " ";
}
else {
$EmailParts = explode("@", $Email);
if(count($EmailParts) == 2) {
return "<script type=\"text/javascript\">\r\nWriteEmail('".$EmailParts[1]."', '".$EmailParts[0]."', '".$LinkText."');\r\n</script>";
}
else { // Failsafe
return "<a href=\"mailto:".$Email."\">".($LinkText==""?$Email:$LinkText)."</a>";
}
}
}
function GetImage($ImageUrl, $Height = "", $Width = "", $TagIdentifier = "", $EmptyImageReplacement = " ") {
$sReturn = "";
if($this->ReturnNonEmpty($ImageUrl) == " ") {
$sReturn = $EmptyImageReplacement;
}
else {
$sReturn = "<img src=\"$ImageUrl\"";
if($Height != "") $sReturn .= " height=\"$Height\"";
if($Width != "") $sReturn .= " width=\"$Width\"";
if($TagIdentifier != "") $sReturn .= " id=\"$TagIdentifier\"";
$sReturn .= " alt=\"\" border=\"0\" />";
}
return $sReturn;
}
function GetRemoteIp($FormatIpForDatabaseInput = "0") {
$FormatIpForDatabaseInput = $this->ForceBool($FormatIpForDatabaseInput, 0);
$sReturn = $this->ForceString(@$_SERVER['REMOTE_ADDR'], "");
if(strlen($sReturn) > 20) {
$sReturn = substr($sReturn, 0, 19);
}
if($FormatIpForDatabaseInput) {
$sReturn = $this->FormatStringForDatabaseInput($sReturn, 1);
}
return $sReturn;
}
// allows inline if statements
function Iif($Condition, $TruePart, $FalsePart) {
if($Condition) {
return $TruePart;
}
else {
return $FalsePart;
}
}
function PrefixString($string, $prefix, $length) {
if(strlen($string) >= $length) {
return $string;
}
else {
return substr(($prefix.$string),strlen($prefix.$string)-$length, $length);
}
}
function PrependString($Prepend, $String) {
$sPrepend = strtolower($Prepend);
$sString = strtolower($String);
$pos = strpos($sString, $sPrepend);
if(($pos !== false && $pos == 0) || $String == "") {
return $String;
}
else {
return $Prepend.$String;
}
}
// If a value is empty, return the non-empty value
function ReturnNonEmpty($InValue, $NonEmptyValue = " ") {
if(trim($InValue) == "") {
return $NonEmptyValue;
}
else {
return $InValue;
}
}
function SaveAsDialogue($FolderPath, $FileName, $DeleteFile = "0") {
$DeleteFile = ForceBool($DeleteFile, 0);
if($FolderPath != "") {
if(substr($FolderPath,strlen($FolderPath)-1) != "/") $FolderPath = $FolderPath."/";
}
$FolderPath = $FolderPath.$FileName;
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=$FileName");
header("Content-Transfer-Encoding: binary");
readfile($FolderPath);
if($DeleteFile) {
unlink($FolderPath);
}
die();
}
function SerializeArray($InArray) {
$sReturn = "";
if(is_array($InArray)) {
if(count($InArray) > 0) {
$sReturn = serialize($InArray);
$sReturn = addslashes($sReturn);
}
}
return $sReturn;
}
// Cuts a string to the specified length.
// Then moves back to the previous space so words are not sliced half-way through.
function SliceString($InString, $Length) {
$Space = " ";
$sReturn = "";
if(strlen($InString) > $Length) {
$sReturn = substr(trim($InString), 0, $Length);
$sReturn = substr($sReturn, 0, strlen($sReturn) - strpos(strrev($sReturn), $Space));
$sReturn .= "…";
} else {
$sReturn = $InString;
}
return $sReturn;
}
function TimeDiff($Time, $TimeToCompare = "") {
if($TimeToCompare == "") $TimeToCompare = time();
$Difference = $TimeToCompare-$Time;
$Days = floor($Difference/60/60/24);
$Difference -= $Days*60*60*24;
$Hours = floor($Difference/60/60);
$Difference -= $Hours*60*60;
$Minutes = floor($Difference/60);
$Difference -= $Minutes*60;
$Seconds = $Difference;
if($Days > 7) {
return date("jS F Y", $Time);
}
elseif($Days > 0) {
return $this->FormatPlural($Days, "day ago", "days ago");
}
elseif($Hours > 0) {
return $this->FormatPlural($Hours, "hour ago", "hours ago");
}
elseif($Minutes > 0) {
return $this->FormatPlural($Minutes, "minute ago", "minutes ago");
}
else {
return $this->FormatPlural($Seconds, "second ago", "seconds ago");
}
}
// Convert a datetime to a timestamp
function UnixTimestamp($DateTime) {
$Return = "";
if(strlen($DateTime) == 19) {
// Datetime comes in the format: YYYY-MM-DD HH:MM:SS
$Year = substr($DateTime, 0, 4);
$Month = substr($DateTime, 5, 2);
$Day = substr($DateTime, 8, 2);
$Hour = substr($DateTime, 11, 2);
$Minute = substr($DateTime, 14, 2);
$Second = substr($DateTime, 17, 2);
$Return = $this->FormatDate($Year, $Month, $Day, "unixtimestamp", $Hour, $Minute, $Second);
}
return $Return;
}
function MysqlDateTime($Timestamp = "") {
if($Timestamp == "") {
$Timestamp = mktime();
}
return date("Y-m-d H:i:s", $Timestamp);
}
function formatMysqlDateTime($datetime, $time=true, $length='full') {
//Reformat a mySQL datetime into a more readable one
if(strlen($datetime) == 19) { // Datetime comes in the format: YYYY-MM-DD HH:MM:SS
$year = substr($datetime, 0, 4);
$month = substr($datetime, 5, 2);
$day = substr($datetime, 8, 2);
$hour = substr($datetime, 11, 2);
$minute = substr($datetime, 14, 2);
$second = substr($datetime, 17, 2);
if($length == 'short') {
return date('jS F Y', mktime($hour, $minute, $second, $month, $day, $year));
}
elseif($time) { // return time as well
return date('jS F Y g:ia', mktime($hour, $minute, $second, $month, $day, $year));
}
else {
return date('jS F Y', mktime($hour, $minute, $second, $month, $day, $year));
}
}
else {
return $datetime;
}
}
function getDateList($whichlist, $date) {
if(strlen($date) == 19) {
// Datetime comes in the format: YYYY-MM-DD HH:MM:SS
$year = substr($date, 0, 4);
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);
$hour = substr($date, 11, 2);
$minute = substr($date, 14, 2);
}
if($whichlist == 'day') {
for($i=0; $i<32; $i++) {
if($i==$day) {
$sel = ' selected="selected"';
}
else {
$sel = '';
}
if($i !=0) {
$ret .= "<option value=\"".str_pad($i, 2, '0', 0)."\"$sel>".str_pad($i, 2, '0', 0)."</option>\n";
}
else {
$ret .= "<option value=\"".str_pad($i, 2, '0', 0)."\"$sel>None</option>\n";
}
}
}
elseif ($whichlist == 'month') {
for($i=0; $i<13; $i++) {
if($i==$month) {
$sel = ' selected="selected"';
}
else {
$sel = '';
}
switch ($i) {
case '0':
$m = 'None';
break;
case '1':
$m = 'January';
break;
case '2':
$m = 'February';
break;
case '3':
$m = 'March';
break;
case '4':
$m = 'April';
break;
case '5':
$m = 'May';
break;
case '6':
$m = 'June';
break;
case '7':
$m = 'July';
break;
case '8':
$m = 'August';
break;
case '9':
$m = 'September';
break;
case '10':
$m = 'October';
break;
case '11':
$m = 'November';
break;
case '12':
$m = 'December';
break;
}
$ret .= "<option value=\"".str_pad($i, 2, '0', 0)."\"$sel>".$m."</option>\n";
}
}
else {
if($year==0) {
$ret .= "<option value=\"0000\" selected=\"selected\">None</option>\n";
}
else {
$ret .= "<option value=\"0000\">None</option>\n";
}
for($i=2005; $i<(date('Y')+3); $i++) {
if($i==$year) {
$sel = ' selected="selected"';
}
else {
$sel = '';
}
$ret .= "<option value=\"".$i."\"$sel>".$i."</option>\n";
}
}
return $ret;
}
function UnserializeArray($InSerialArray) {
$aReturn = array();
if($InSerialArray != "" && !is_array($InSerialArray)) {
$aReturn = unserialize($InSerialArray);
if(is_array($aReturn)) {
for ($i = 0; $i < count($aReturn); $i++) {
$aReturn[$i] = array_map("stripslashes", $aReturn[$i]);
}
}
}
return $aReturn;
}
function UnserializeAssociativeArray($InSerialArray) {
$aReturn = array();
if($InSerialArray != "" && !is_array($InSerialArray)) {
$aReturn = unserialize($InSerialArray);
}
return $aReturn;
}
function getProperty($return, $table, $column, $value) {
$sql = "SELECT $return FROM $table WHERE $column = '$value'";
$statement = $this->f->conn->createStatement($sql, $this->f);
return $statement->execute('index0');
}
function valid_email($address) {
// check an email address is possibly valid
if (ereg("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $address)) {
return true;
}
else {
return false;
}
}
function valid_postcode($postcode) {
$postcode = strtoupper(str_replace(chr(32), '', $postcode));
if((strlen($postcode)<6) || (strlen($postcode)>8)) {
return false;
}
$suffix = substr($postcode, -3, 3);
$prefix = substr($postcode, 0, (strlen($postcode)-3));
if(preg_match('/(^[A-Z]{1,2}[0-9]{1,2}|^[A-Z]{1,2}[0-9]{1}[A-Z]{1})$/', $prefix) && preg_match('/^[0-9]{1}[ABD-HJLNP-UW-Z]{2}$/', $suffix)) {
return $prefix.chr(32).$suffix;
}
else {
return false;
}
}
function remove_badwords($string) {
$badwords_exact = array (' ahole ', ' ass ', ' cock ', ' cocks ', ' coon ', ' cum ', ' dick ', ' fag ', ' faget ', ' fags ', ' hoar ', ' kunt ', ' packi ', ' paki ', ' penas ', ' phuc ', ' phuck ', ' phuk ', ' pusse ', ' rape ', ' slag ', ' slut ', ' spik ', ' turd ', ' wop ');
$badwords_variations = array ('arsehole', 'arseh0le', 'ash0le', 'ash0les', 'asholes', 'assface', 'assh0le', 'assh0lez', 'asshole', 'assholes', 'assholz', 'asswipe', 'azzhole', 'bastard', 'bastards', 'bastardz', 'basterds', 'basterdz', 'blowjob', 'butthole', 'c0ck', 'c0cks', 'c0k', 'cocksucker', 'cock-sucker', 'dild0', 'dild0s', 'dildo', 'dildos', 'dilld0', 'dilld0s', 'kike', 'koon', 'mothafucker', 'mothafuker', 'mothafukkah', 'mothafukker', 'motherfucker', 'motherfukah', 'motherfuker', 'motherfukkah', 'motherfukker', 'mother-fucker', 'muthafucker', 'muthafukah', 'muthafuker', 'muthafukkah', 'muthafukker', 'pillock', 'sh!t', 'sh1t', 'wank', 'w0p', 'wh00r', 'wh0re', 'whore', 'arse', 'biatch', 'bitch', 'bitches', 'blow job', 'buttwipe', 'cnts', 'cntz', 'cockhead', 'cock-head', 'cripple', 'cunt', 'cunts', 'cuntz', 'dyke', 'f u c k', 'f u c k e r', 'fag1t', 'fagg1t', 'faggit', 'faggot', 'fagit', 'fagz', 'feltch', 'feck', 'fuck', 'fucker', 'fuckin', 'fucking', 'fucks', 'fuk', 'fukah', 'fuken', 'fuker', 'fukin', 'fukk', 'fukkah', 'fukken', 'fukker', 'fukkin', 'g00k', 'h00r', 'h0ar', 'h0re', 'hoor', 'hoore', 'jisim', 'jiss', 'jizm', 'jizz', 'kunts', 'kuntz', 'kyke', 'n1gr', 'nigger', 'nigur', 'niiger', 'niigr', 'packie', 'packy', 'pakie', 'paky', 'peeenus', 'peeenusss', 'peenus', 'peinus', 'pen1s', 'penis', 'penus', 'penuus', 'phucker', 'phuker', 'phukker', 'piss', 'polac', 'polack', 'polak', 'poonani', 'pr1c', 'pr1ck', 'pr1k', 'pussee', 'pussy', 'queerz', 'qweers', 'qweerz', 'recktum', 'rectum', 'retard', 'schlong', 'semen', 'shitty','shitter', 'shity', 'shit', 'slags', 'slutty', 'slutz', 'son-of-a-bitch', 'sperm', 'spiks', 'spunk', 'titties', 'twat', 'va1jina', 'vag1na', 'vagiina', 'vagina', 'vaj1na', 'vajina', 'vullva', 'vulva', 'wog');
$string = str_replace ($badwords_exact, ' !*@#$% ', $string);
$string = str_replace ($badwords_variations, '!*@#$%', $string);
return $string;
}
function string_cut($string, $cut_size) {
$ar = explode(" ",$string);
for($i=0; $i<$cut_size; $i++) {
$string_cut .= ' '.$ar[$i];
}
return trim($string_cut).'…';
}
function ShowSnippit($string, $cut_size) {
$regex = '(<\/[a-z\d]+>)';
$string = preg_replace($regex, ' ', $string);
$string = $this->string_cut(strip_tags($string), $cut_size);
return $string;
}
// Produce an UL from errors array
function list_errors($errors) {
$ret = "";
$ret .= "<ul>\n";
for($i=0; $i<count($errors); $i++) {
$ret .= "\t<li>".$errors[$i]."</li>\n";
}
return $ret."</ul>\n";
}
function WriteEmail($Email, $LinkText = "") {
echo($this->GetEmail($Email, $LinkText));
}
function strHighlight($text, $needle) {
$highlight = '<span class="keyword">\1</span>';
$pattern = '#(?!<.*?)(%s)(?![^<>]*?>)#i';
$needle = (array) $needle;
foreach ($needle as $needle_s) {
$needle_s = preg_quote($needle_s);
$regex = sprintf($pattern, $needle_s);
$text = preg_replace($regex, $highlight, $text);
}
return $text;
}
}
?>