Location: PHPKode > projects > Admbook > lib.php
<?php
/**
 *	@author "trent" <hide@address.com>
 *	@version 1.2.1
 */

	if (!ini_get('register_globals')) {
		$superglobals = array($_SERVER, $_ENV, $_FILES, $_COOKIE, $_POST, $_GET);
		if (isset($_SESSION)) {
			array_unshift($superglobals, $_SESSION);
		}
		foreach ($superglobals as $superglobal) {
			extract($superglobal, EXTR_SKIP);
		}
		ini_set('register_globals', true);
	}
	if(!isset($page))
		$page = 1;
	if (!isset($login))
		$login = "";
	if (!isset($password))
		$password = "";
	$magic_quotes_gpc = (bool)ini_get("magic_quotes_gpc");
	$magic_quotes_runtime = (bool)ini_get("magic_quotes_runtime");
/**
 *	Check url
 *	@param String url
 *	@return true/false or 'DNS'
 */
	function check_url($url)
	{
		if (eregi('^http://', $url))
		{
			$urlArray = parse_url($url);
			if (!$urlArray[port])
				$urlArray[port] =  '80';
			if (!$urlArray[path])
				$urlArray[path] =  '/';
			$sock = fsockopen($urlArray[host], $urlArray[port], $errnum, $errstr);
			if (!$sock)
				$res =  'DNS';
			else
			{
				$dump =  "GET $urlArray[path] HTTP/1.1\r\n";
				$dump .=  "Host: $urlArray[host]\r\nConnection: close\r\n";
				$dump .=  "Connection: close\r\n\r\n";
				fputs($sock, $dump);
				while ($str = fgets($sock, 1024))
				{
					if (eregi("^http/[0-9]+.[0-9]+ ([0-9]{3}) [a-z ]*", $str))
						$res[code] = trim(eregi_replace('^http/[0-9]+.[0-9]+([0-9]{3})[a-z ]*', "\\1", $str));
					if (eregi("^Content-Type: ", $str))
						$res[contentType] = trim(eregi_replace("^Content-Type: ", "", $str));
				}
				fclose($sock);
				flush();
				return $res[code];
			}
		}
		else
			$res = false;
		return $res;
		return true;
	}

/**
 *	Check e-mail
 * 	@param String
 *	@return true/false
 */
	function validEmail($email)
	{
		return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',$email));
	}

	function validIp($ip)
	{
		if(!is_string($ip))
			return false;
		$ip_long = ip2long($ip);
		$ip_reverse = long2ip($ip_long);
		if($ip == $ip_reverse)
			return true;
		else
			return false;
	}

/**
 *	Ñheck number
 * 	@param String
 *	@return true/false
 */

	function isInteger($content) {
		return ereg("^[0-9]+$", $content);
	}

	function isFloat($content) {
		return ereg("^[0-9.]+$", $content);
	}

/**
 *	Transform html in unicode
 *	@param String
 *	@return String
 */
	function parseHtml($content) {
		global $ini;
		$content = htmlspecialchars($content);
		return $content;
	}

	function translateHtml($content, $additional = true)
	{
		global $constant, $magic_quotes_gpc;
		$p = "";
		if ($additional) {
			$constant['bold-in-message'] ? $p .= "<b>" : $p .= "";
			$constant['italic-in-message'] ? $p .= "<i>" : $p .= "";
		}
		$content = strip_tags($content, $p);
		$charArray = array("\r\n", "\r");
		$content = str_replace($charArray, "\n", $content); // win32
		$content = preg_replace("/[\n]{3,}/", "\n\n", $content);
		$content = str_replace("\n", "<br />", $content); // unix
		$content = preg_replace("/[ ]{2,}/", " ", $content);
		$content = str_replace("\"", "&quot;", $content);
		$content = str_replace("\'", "&#39;", $content);
		$content = str_replace("\$", "&#36;", $content);
		if (!$magic_quotes_gpc) {
			$content = addslashes($content);
		}
		if ($additional) {
			if ($constant['link-in-message']) {
				$content = convertLinks($content);
			}
		}
		$content = wordwrap($content, 50, " ", 1);
		$content = trim($content);
		return $content;
	}

/**
 *	Make string length by param
 *	@param String
 *	@param int default by 50
 *	@return String
 */
	function miniaturize($content, $len = "50")
	{
		if (strlen($content) > $len) {
			$len = ceil($len/2) - 2;
			return substr($content, 0, $len)."...".substr($content, -$len);
		}
		else
			return $content;
	}

/**
 *	Ïðåîáðàçóåò òåñòîâóþ ññûëêó â ññûëêó íà ðåñóðñ	
 *	@param String
 *	@return String
 */
	function convertLinks($content)	{
		$content = preg_replace('/(http|ftp|news|https)(:\/\/)([^<> ])+/ie', "cropLink('\\0')", $content);
		$content = preg_replace('/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?))/ie', "cropMail('\\1')", $content);
		return $content;
	}

/**
 *	Îáðåçàåò äëèííûå ññûëêè
 *	@param String
 *	@return String
 */
	function cropLink($content, $len = "50") {
		if (strlen($content) > $len) {
			$len = ceil($len/2) - 2;
			return "<a href=\"".$content."\">".substr($content, 0, $len)."...".substr($content, -$len)."</a>";
		}
		return "<a href=\"".$content."\">".$content."</a>";
	}

/**
 *	Îáðåçàåò äëèííûå email
 *	@param String
 *	@return String
 */
	function cropMail($content, $len = "50") {
		if (strlen($content) > $len) {
			$len = ceil($len/2) - 2;
			return "<a href=\"mailto:".$content."\">".substr($content, 0, $len)."...".substr($content, -$len)."</a>";
		}
		return "<a href=\"".$content."\">".$content."</a>";
	}

/**
 *	Convert all link to real link
 *	@param String
 *	@return String
 */
	function br2nl($content)
	{
		return str_replace("<br/>", "\n", $content);
	}

/**
 *	Checks length of words and divides long for length in param
 *	@param String
 *	@param int by default 30
 *	@return String
 */
	function divideWord($content,$maxWordLength = "30")
	{
		return wordwrap($content, $maxWordLength, " ", 1);
	}

/**
 *	Rewrites the data in a file
 *	@param String
 *	@param String default by 'content-data.php'
 */
	function reWriteDataInFile($fileData,$fileName = "content-data.php")
	{
		if(!file_exists($fileName))
		{
			@$createFile = fopen($fileName, "w") or die ("Can't create file ".$fileName."");
			fwrite ($createFile,"",0);
			@chmod($fileName, 0666);
			fclose($createFile);
		}
		@$openFile = fopen($fileName,"w+") or die ("Access is denied. Set permission to ".$fileName." by command in console \"chmod 666 ".$fileName."\"");
		if ($openFile && flock($openFile,LOCK_EX)) {
			@fwrite($openFile,$fileData);
		}
		fclose($openFile);
	}

	function createFile($fileName)
	{
		if(!file_exists($fileName))
		{
			@$createFile = fopen($fileName, "w") or die ("Can't create file ".$fileName."");
			fwrite ($createFile,"",0);
			@chmod($fileName, 0666);
			fclose($createFile);
		}
	}

/**
 *	Output content in relation to page number
 *	@param Array
 *	@param int default by '10'
 *	@return String
 */
	function outputPageContent($content,$page,$messageToPage = "10")
	{
		$cnt = sizeof($content);
		$startPos = $messageToPage*($page-1);
		$endPos = $messageToPage*($page-1)+$messageToPage;
		if ($cnt < $startPos)
			$startPos = $cnt;
		if ($cnt < $endPos)
			$endPos = $cnt;
		$z = 0;
		for($i = $startPos; $i < $endPos; $i++)
		{
			$currentContent[$z] = $content[$i];
			$z++;
		}
		return $currentContent;
	}

/**
 *	Output all number of page
 *	@param int
 *	@param int
 *	@param int
 *	@param int default by 10
 *	@param String default by 'page: '
 *	@param String default by 'total: '
 *	@return String
 */
	function pagesNumber($quantityMessages, $messageToPage = "10", $page = "1", $pageLink = "index.php", $activePage = "15", $pageDecriptor = "page: ", $pageTotalDecriptor = "total: ", $class = "link")
	{
		@$quantityPages = ceil($quantityMessages/$messageToPage);
		$pageToLine = floor($activePage/2);
		if ($quantityPages >= 2)
		{
			if (($page - $pageToLine) <= ($quantityPages) && ($page - $pageToLine) > 0 && $pageToLine*2+1 < $quantityPages)
			{
				if ($page + $pageToLine <= $quantityPages)
				{
					$x = $page - $pageToLine;
					$y = $page + $pageToLine;
				}
				else
				{
					$x = $page - $pageToLine;
					$y = $quantityPages;
				}
			}
			else
			{
				$x = 1;
				if ($pageToLine*2+1 < $quantityPages)
					$y = $pageToLine*2+1;
				else
					$y = $quantityPages;
			}
			$pageNumberString = "";
			for ($i = $x; $i <= $y; $i++)
			{
				if ($i == $page)
					$pageNumberString .= "<b>".$i."</b> ";
				else
					$pageNumberString .= "<a href=\"".$pageLink."?page=".$i."\" class=\"".$class."\">".$i."</a> ";
			}
			if ($page < $quantityPages)
				$rightNavPoint = "<span>&nbsp;<a href=\"".$pageLink."?page=".($page+1)."\" title=\"next page\" class=\"".$class."\">&gt;</a>&nbsp;&nbsp;<a href=\"".$pageLink."?page=".$quantityPages."\" title=\"last page\" class=\"".$class."\">&gt;&gt;&gt;</a>&nbsp;</span>";
			else
				$rightNavPoint = "&nbsp;";
			if ($page > 1)
				$leftNavPoint = "&nbsp;<a href=\"".$pageLink."?page=1\" title=\"first page\" class=\"".$class."\">&lt;&lt;&lt;</a>&nbsp;&nbsp;<a href=\"".$pageLink."?page=".($page-1)."\" title=\"previous page\" class=\"".$class."\">&lt;</a>&nbsp;";
			else
				$leftNavPoint = "";
			return $pageDecriptor.$leftNavPoint.$pageNumberString.$rightNavPoint."&nbsp;".$pageTotalDecriptor. "<a href=\"".$pageLink."?page=".$quantityPages."\" title=\"last page\" class=\"".$class."\">".$quantityPages."</a>";
		}
		else
			return false;
	}

/**
 *	Convert censored word in string
 *	@param String
 *	@param String by default '<censored>'
 *	@param String by default dictionary-data.php
 *	@return String
 */
	function censoredData($content, $censoredSign = "&lt;censored&gt;", $dictionaryFile = "dictionary-data.php")
	{
		if(!file_exists($dictionaryFile))
			return $content;
		else
			include($dictionaryFile);
		$contains = false;
		if (!isset($censor))
			$censor = null;
		for($i = 0; $i < sizeof($censor);$i++)
		{
			$currCensor = addslashes($censor[$i]);
			$content = preg_replace("/(.*)(".$currCensor.")(.*)/Ui","\\1".$censoredSign." \\3", $content);
		}
		return $content;
	}

/**
 *	Convert smile to image
 *	@param String
 *	@param String by default 'img/'
 *	@return String
 */
	function convertSmile($content, $path = "img/")
	{
		global $constant;
		if ($constant['smile-in-message'])
		{
			$content = ereg_replace("[)]{2,}", ")", $content);
			$content = ereg_replace("[(]{2,}", "(", $content);

			$content = str_replace(":)", returnImgTag("smile", $path), $content);
			$content = str_replace(":o)", returnImgTag("smile", $path), $content);
			$content = str_replace(":-)", returnImgTag("smile", $path), $content);
			$content = str_replace(":0)", returnImgTag("smile", $path), $content);

			$content = str_replace(";)", returnImgTag("wink", $path), $content);
			$content = str_replace(";-)", returnImgTag("wink", $path), $content);

			$content = str_replace(":(", returnImgTag("frown", $path), $content);
			$content = str_replace(";(", returnImgTag("frown", $path), $content);
			$content = str_replace(";-(", returnImgTag("frown", $path), $content);
			$content = str_replace(":-(", returnImgTag("frown", $path), $content);

			$content = str_replace(":[]", returnImgTag("fright", $path), $content);
			$content = str_replace(":J", returnImgTag("curve-smile", $path), $content);

			$content = str_replace(":o", returnImgTag("astonish", $path), $content);
			$content = str_replace(":-o", returnImgTag("astonish", $path), $content);
			$content = str_replace(":0", returnImgTag("astonish", $path), $content);
			$content = str_replace(":-0", returnImgTag("astonish", $path), $content);

			$content = str_replace(":-0", returnImgTag("astonish", $path), $content);

			$content = str_replace(":p", returnImgTag("tongue", $path), $content);
			$content = str_replace(":-p", returnImgTag("tongue", $path), $content);
			$content = str_replace(":P", returnImgTag("tongue", $path), $content);
			$content = str_replace(":-P", returnImgTag("tongue", $path), $content);
			$content = str_replace(":-b", returnImgTag("tongue", $path), $content);
			$content = str_replace(":b", returnImgTag("tongue", $path), $content);

			$content = str_replace(":D", returnImgTag("biggrin", $path), $content);
			$content = str_replace(":-D", returnImgTag("biggrin", $path), $content);

			$content = str_replace("%-)", returnImgTag("crazy", $path), $content);
			$content = str_replace("%)", returnImgTag("crazy", $path), $content);

			$content = str_replace("8-)", returnImgTag("cool", $path), $content);
			$content = str_replace("8)", returnImgTag("cool", $path), $content);

			$content = str_replace(":smoke:", returnImgTag("smoke", $path, 21, 20), $content);
			$content = str_replace(":evil:", returnImgTag("evil", $path), $content);
			$content = str_replace(":apple:", returnImgTag("apple", $path), $content);
			$content = str_replace(":moo:", returnImgTag("moo", $path, 16, 16), $content);
		}
		return $content;
	}

/**
 *	Transofm image path
 *	@param String
 *	@return String
 */
	function returnImgTag($imgName, $path, $width = "15", $height = "15")
	{
		return "<img src=\"".$path.$imgName.".gif\" width=\"".$width."\" height=\"".$height."\" alt=\"".$imgName."\" border=\"0\"/>";
	}

/**
 *	Return current formated date
 *	@param String by default 'gb'
 *	@return String
 */
	function getFullDate($timestamp, $locale = "gb")
	{
		setlocale (LC_ALL, $locale);
		$currDay = strftime ("%d",$timestamp);
		$currMonth = strftime ("%B",$timestamp);
		$currYear = strftime ("%Y",$timestamp);
		$currWeek = strftime ("%a",$timestamp);
		$currFullWeek = strftime ("%A",$timestamp);
		return $currDay." ".strtolower($currMonth).", ".ucfirst($currFullWeek).", ".$currYear;
	}

/**
 *	Return current formated time
 *	@return String
 */
	function getTime($timestamp)
	{
		return strftime("%H:%M:%S", $timestamp);
	}

/**
 *	Return Operation System from user agent string
 *	@param Array
 *	@param String
 *	@return String
 */
	function getSystem($arrSystem,$userAgent)
	{
		$system = 'Other';
		foreach($arrSystem as $key => $value)
		{
			if (strpos($userAgent, $key) !== false)
			{
				$system = $value;
				break;
			}
		}
		return $system;
	}

/**
 *	Return Browser from user agent string
 *	@param Array
 *	@param String
 *	@return Associative Array
 */
	function getBrowser($arrBrowser,$userAgent)
	{
		$version = "";
		$browser = "Other";
		if (($pos = strpos($userAgent, 'Opera')) !== false && (strpos($userAgent, 'Mozilla')) !== false) {
			$browser = 'Opera';
			if (($pos = strpos($userAgent, 'Opera ')) !== false) {
				if ($posEnd = strpos($userAgent, ' ', $pos) !== false) {
					$posEnd = strpos($userAgent, ' ', $pos);
					$version = trim(substr($userAgent, $posEnd, $pos - $posEnd));
				}
			}
		} else if (($pos = strpos($userAgent, 'Opera')) !== false) {
			$browser = 'Opera';
			if (($pos = strpos($userAgent, 'Opera/6')) !== false) {
				if ($posEnd = strpos($userAgent, '/', $pos) !== false) {
					$posEnd = strpos($userAgent, ' ', $pos);
					$pos += 6;
					$version = trim(substr($userAgent, $pos, $posEnd - $pos));
				}
			} else {
				$pos += 6;
				if ((($posEnd = strpos($userAgent, ';', $pos)) !== false) || (($posEnd = strpos($userAgent, ' ', $pos)) !== false)) {
					$version = trim(substr($userAgent, $pos, $posEnd - $pos));
				}
			}
		} elseif (($pos = strpos($userAgent, 'MSIE')) !== false) {
			$browser = 'Internet Explorer';
			$posEnd = strpos($userAgent, ';', $pos);
			if ($posEnd !== false) {
				$pos += 4;
				$version = trim(substr($userAgent, $pos, $posEnd - $pos));
			}
		} elseif (((strpos($userAgent, 'Gecko')) !== false) && ((strpos($userAgent, 'Netscape')) === false)) {
			$browser = 'Mozila';
			if (($pos = strpos($userAgent, 'rv:')) !== false) {
				$posEnd = strpos($userAgent, ')', $pos);
				if ($posEnd !== false) {
					$pos += 3;
					$version = trim(substr($userAgent, $pos, $posEnd - $pos));
				}
			}
		} elseif ((strpos($userAgent, ' I;') !== false) || (strpos($userAgent, ' U;') !== false) || (strpos($userAgent, ' U ;') !== false) || (strpos($userAgent, ' I)') !== false) || (strpos($userAgent, ' U)') !== false)) {
			$browser = 'Netscape Navigator';
			if (($pos = strpos($userAgent, 'Netscape6')) !== false) {
				$pos += 10;
				$version = trim(substr($userAgent, $pos, strlen($userAgent) - $pos));
			} else {
				if (($pos = strpos($userAgent, 'Mozilla/')) !== false) {
					if (($posEnd = strpos($userAgent, ' ', $pos)) !== false) {
						$pos += 8;
						$version = trim(substr($userAgent, $pos, $posEnd - $pos));
					}
				}
			}
		} else {
			foreach($arrBrowser as $key => $value) {
				if (strpos($userAgent, $key) !== false) {
					$browser = $value;
					break;
				}
			}
		}
		$userAgentArr['browser'] = $browser;
		$userAgentArr['version'] = $version;
		return $userAgentArr;
	}

/**
 *	Register admin in session
 *	@param String
 *	@param String
 *	@param File
 *	@return false on error
 */
	function login($currentLogin, $currentPassword, $permissionsFile = "../settings-data.php")
	{
		include($permissionsFile);
		//session_register("login");
		//session_register("password");
		if($currentLogin == $constant['admin-name'] && $constant['admin-password'] == md5($currentPassword))
		{
			$_SESSION['login'] = $currentLogin;
			$_SESSION['password'] = md5($currentPassword);
			return true;
		}
		else
		{
			unset($_SESSION['login']);
			unset($_SESSION['password']);
			//session_unregister("login");
			//session_unregister("password");
			@sleep(1);
			return false;
		}
	}

/**
 *	Register user in session
 *	@param String
 *	@param String
 *	@param File
 *	@return false on error
 */
	function loginUser($currentLogin, $currentPassword, $permissionsFile = "users-data.php")
	{
		global $userId, $userLogin, $userPassword;
		include($permissionsFile);
		session_register("userId");
		session_register("userLogin");
		session_register("userPassword");
		$userLogin = $currentLogin;
		$userPassword = md5($currentPassword);
		$userKey = 0;
		if (!isset($user) || !is_array($user))
		 return false; 
		foreach($user as $key1 => $value1)
		{
			foreach ($value1 as $key2 => $value2)
			{
				if ($key2 == "name" && toLower(convertName($userLogin)) == toLower(convertName($value2)))
				{
					$userKey = $key1;
					break 2;
				}
			}
		}
		if (toLower(convertName($userLogin)) == toLower(convertName($user[$userKey]['name'])) && $userPassword == $user[$userKey]['password'] && $user[$userKey]['status'])
		{
			setUserCookie(stripslashes($user[$userKey]['name']), "cookie[name]");
			setUserCookie(stripslashes($user[$userKey]['url']), "cookie[url]");
			setUserCookie(stripslashes($user[$userKey]['mail']), "cookie[mail]");
			setUserCookie(stripslashes($user[$userKey]['icq']), "cookie[icq]");
			$userId = $userKey;
			return true;
		}
		else
		{
			session_unregister("userId");
			session_unregister("userLogin");
			session_unregister("userPassword");
			@sleep(1);
			return false;
		}
	}

/**
 *	Destroy all data in session
 *	return redirect
 */
	function logout()
	{
		session_start();
		session_destroy();
		Header("Location: ../index.php");exit; 
	}

/**
 *	Destroy user data in session and user cookie
 *	return redirect
 */
	function logoutUser()
	{
		setUserCookie("", "cookie[name]");
		setUserCookie("", "cookie[url]");
		setUserCookie("", "cookie[mail]");
		setUserCookie("", "cookie[icq]");
		session_start();
		session_destroy();
		Header("Location: index.php");exit; 
	}

/**
 *	Check admin permission
 *	return redirect on false
 */
	function checkPermissions($currentLogin, $currentPassword, $permissionsFile = "../settings-data.php", $path = "")
	{
		include($permissionsFile);
		if($currentLogin != $constant['admin-name'] && $currentPassword != $constant['admin-password'])
		{
			session_destroy();
			Header("Location: ".$path."login.php");
			exit;
		}
	}

/**
 *	Check user permission
 *	return redirect on false
 */
	function checkUserPermissions($currentLogin, $currentPassword, $permissionsFile = "users-data.php")
	{
		global $userId;
		include($permissionsFile);
		$currentContent = $user[$userId];
		if (toLower(convertName($currentContent['name'])) != toLower(convertName($currentLogin)) || $currentContent['password'] != $currentPassword || !$currentContent['status'])
		{
			session_destroy();
			Header("Location: user-login.php");
			exit;
		}
	}

/**
 *	Set cookie
 */
	function setUserCookie($name, $cookieName)
	{
		setcookie($cookieName, $name, time() + 86400*366);
	}

/**
 *	Check last publish date for user
 *	return boolean
 */
	function checkLastPublish($ip, $login, $password, $content, $minutes, $permissionsFile = "settings-data.php")
	{
		include($permissionsFile);
		$check['status'] = true;
		$check['time'] = "";
		if($login == $constant['admin-name'] && $password == $constant['admin-password'])
		{
			return $check;
		}
		else
		{
			for ($i = 0; $i < sizeof($content); $i++)
			{
				if ($ip == $content[$i]['ip'] && $content[$i]['time'] + 60 * $minutes > time())
				{
					$check['status'] = false;
					$check['time'] = $content[$i]['time'] + 60 * $minutes - time();
					break;
				}
			}
			return $check;
		}
	}

/**
 *	Check publish name for user
 *	return boolean
 */
	function checkPublishName($currentName, $currentLogin, $permissionsFile = "users-data.php")
	{
		$check['status'] = true;
		$check['id'] = -1;
		if (toLower(convertName($currentName)) == toLower(convertName($currentLogin)))
			return $check;
		else
		{
			include($permissionsFile);
			$userId = 0;
			if (!isset($user))
				$user = array();
			foreach($user as $key1 => $value1)
			{
				foreach ($value1 as $key2 => $value2)
				{
					if ($key2 == "name" && toLower(convertName($currentName)) == toLower(convertName($value2)))
					{
						$check['id'] = $userId;
						$check['status'] = false;
						break 2;
					}
				}
				$userId++;
			}
			return $check;
		}
	}

/**
 *	Check ip from 'black list'
 *	return boolean
 */
	function checkBannedIp($ip, $login, $password, $bannedData = "banned-ip-data.php", $permissionsFile = "settings-data.php")
	{
		include($permissionsFile);
		$check = true;
		if($login == $constant['admin-name'] && $password == $constant['admin-password'])
		{
			return $check;
		}
		else if ($ip == "")
		{
			return $check;
		}
		else
		{
			include($bannedData);
			$ip = ip2long($ip);
			if (!isset($banned))
			{
				$banned = array();
			}
			if (in_array ($ip, $banned))
			{
				$check = false;
			}
			return $check;
		}
	}

/**
 *	Convert name for latin
 *	@param String
 *	return boolean
 */
	function convertName($name)
	{
		$arr1 = array("à", "ñ", "å", "î", "ð", "À", "Â", "Å", "Ç", "Ê", "Ì", "Î", "Ð", "Ñ", "Ò", "Õ");
		$arr2 = array("a", "c", "e", "o", "p", "A", "B", "E", "3", "K", "M", "O", "P", "C", "T", "X");
		$arr1Size = sizeof($arr1);
		$nameSize = strlen($name);
		for ($i = 0; $i < $nameSize; $i++)
		{
			for ($z = 0; $z < $arr1Size; $z++)
			{
				if ($name[$i] == $arr1[$z])
					$name[$i] = $arr2[$z];
			}
		}
		return $name;
	}

/**
 *	Make string lower case
 *	@param String
 *	return String
 */
	function toLower($content) {
		$content = strtr($content, "ÀÁÂÃÄŨÆÇÈÉÊËÌÍÎÐÏÑÒÓÔÕÖ×ØÙÚÜÛÝÞß", "àáâãäå¸æçèéêëìíîðïñòóôõö÷øùúüûýþÿ");
		return strtolower($content);
	}

/**
 *	Make string upper case
 *	@param String
 *	return String
 */
	function toUpper($content) {
			$content = strtr($content, "àáâãäå¸æçèéêëìíîðïñòóôõö÷øùúüûýþÿ", "ÀÁÂÃÄŨÆÇÈÉÊËÌÍÎÐÏÑÒÓÔÕÖ×ØÙÚÜÛÝÞß");
			return strtoupper($content);
	}

/**
 *	Check last publish date for user
 *	@param String
 *	@param Array
 *	return boolean
 */
	function checkPublishContent($message, $content) {
		if (!isset($content))
			$content[0]['message'] = "";
		$check = true;
		if (isset($content[0]['message']) && toLower($message) == toLower($content[0]['message']))
			$check = false;
		return $check;
	}

/**
 *	Convert seconds in (hh:mm:ss)
 *	@param int
 *	return String
 */
	function convertTimeFormate($time) {
		if ($time < 60)
			$time = "00:00:".$time;
		if (59 < $time && $time < 3600)
			$time = "00:".floor($time/60).":".((($time % 60) < 10)?  "0" : "").($time % 60);
		else if (3600 < $time && $time < 86400)
			$time = floor($time/3600).":".floor($time/1440).":".((($time % 60) < 10)? "0" : "").($time % 60);
		return $time;
	}

/**
 *	Generate random password
 *	@param int by default 8
 *	@param Array by default 'alpha'
 *	return String
 */
	function generatePassword($passwordLength = 8, $passwordCharArray = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "o", "p", "q", "r", "s", "t", "v", "u", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "J", "H", "I", "J", "K", "L", "M", "O", "P", "Q", "R", "S", "T", "V", "U", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0")) {
		srand((double)microtime()*1000000);
		$password = "";
		for ($i = 0; $i < $passwordLength; $i++) {
			$password .= $passwordCharArray[mt_rand(0,sizeof($passwordCharArray)-1)];
		}
		return $password;
	}
?>
Return current item: Admbook