Location: PHPKode > scripts > GalleryShuffle > v1.0/php/FUNCTIONS.php
<?php

/**
* FUNCTIONS DIVERS
**/
	
abstract class FUNCTIONS 
{
	
	//Parse a csv file & return an array
	public function parseCSV($fileUrl)
	{
		$content = Array();
		
		$file = fopen($fileUrl, 'r');
		while($line = fgets($file)){
			if(preg_match("#^\"[a-zA-Z0-9]+\", \".+\"\r$#", $line)){
				
				preg_match("#^\"[a-zA-Z0-9]+\", #", $line, $match);
				$key = preg_replace("#(^\"|\", $)#", "", $match[0]);
				preg_match("# \".+\"\r$#", $line, $match);
				$value = preg_replace("#(^ \"|\"\r$)#", "", $match[0]);
				
				$content[$key] = $value;
			}
		}
		fclose($file);
		
		return $content;
	}
	
	
	//crypte/decrypte a string
	public function crypte($value)
	{
		/*srand((double)microtime() * 1000000);
		$key = rand(0, 5);
		$count = 0;
		$buffer = "";
		
		for ($i=0; $i < strlen($value); $i++){
			if($count == strlen($key)) $count = 0;
			$buffer .= substr($key, $count, 1).(substr($value, $i, 1) ^ substr($key, $count, 1) );
			$count++;
		}
		
		return base64_encode(FUNCTIONS::keyGenerate($buffer, '111'));
		*/
		return base64_encode($value);
	}
	public function decrypte($value)
	{
		/*$value = FUNCTIONS::keyGenerate(base64_decode($value), '111');
		$buffer = "";
		
		for ($i=0; $i < strlen($value); $i++){
			$md5 = substr($value, $i, 1);
			$i++;
			$buffer .= (substr($value, $i, 1) ^ $md5);
		}
		
		return $buffer;
		*/
		return base64_decode($value);
	}
	public function keyGenerate($value, $key)
	{
		//$key = md5($key);
		$count = 0;
		$buffer = "";
		
		for ($i=0; $i < strlen($value); $i++){
			if($count == strlen($key)) $count = 0;
			$buffer .= substr($value, $i, 1) ^ substr($key, $count, 1);
			$count++;
		}
		
		return utf8_encode($buffer);
	}
	
	public function getCurrentDateTime()
	{
	
		return date("Y-m-d H:i:s");
		
	}
	public function getIntDate($date)
	{
		
		return str_replace(Array('-',':',' '), '', $date);
		
	}
	
	public function getTinyIntFromCheckbox($checkboxValue)
	{
	
		if($checkboxValue == 1) return 1;
		else return 0;
		
	}
	
	public function getAjaxRequest($action, $objectId="", $formId="")
	{
	
		return "javascript: " . FUNCTIONS::getAjaxRequestEval($action, $objectId, $formId);
		
	}
	public function getAjaxRequestEval($action, $objectId="", $formId="")
	{
	
		return "ajaxRequest('" . FUNCTIONS::crypte($action) . "', '" . $objectId . "', '" . $formId . "');";
		
	}
	
	public function writeBase64Image($fileName, $base64)
	{
		
		$fp = fopen($fileName . CONFIG::picturesExtension, "wb");
		$file = str_replace(' ', '+', $base64);
		$file = str_replace("data:image/png;base64,", "", $file);
		fwrite($fp, base64_decode($file));
		fclose($fp ); 
		
	}
	
	public function stringNoWrap($string)
	{
		
		return str_replace(" ", "&nbsp;", $string);
		
	}
	
	public function encodePost()
	{
		
		foreach($_POST as $key => $value)
			$_POST[$key] = FUNCTIONS::encodeString($value);
		
	}
	
	public function encodeGet()
	{
		
		foreach($_GET as $key => $value)
			$_GET[$key] = FUNCTIONS::encodeString($value);
		
	}
	
	public function encodeString($string)
	{
		
		$string = nl2br($string);
		return htmlentities($string, ENT_QUOTES, "UTF-8");
		
	}
	
	public function isMailAddress($string)
	{
	
		if(preg_match('#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#', $string)) return true; 
		else return false; 
		
	}
	
	public function isInt($string)
	{
	
		if(preg_match('#^[0-9]+$#', $string)) return true; 
		else return false; 
		
	}
	
	public function troncString($string, $limit)
	{
		
		$stringLength = mb_strlen(html_entity_decode($string, ENT_QUOTES, "UTF-8"));

		if($stringLength >  $limit) $string = substr($string, 0,  $limit) . "...";
		return $string;
		
	}
	
}

	
?>
Return current item: GalleryShuffle