<?php
/**
 * Sammlung von diversen Sicherheitsfunktionen
 * 
 * @license myHP, the construct for every webpage you want.
    Copyright (C) 2010  Stefan 'Eichi' Eichhorst <eichi@blubbbel.de>
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    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
    GNU Lesser General Public License for more details.
    
    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @package EoT-Clan BC2 Leaderboard
 * @copyright Eichi (Stefan Eichhorst)
 * @author Eichi - eichi@blubbbel.eu
 */

class security {
	
	/**
	 * Kodiert ein Array oder einen String in den angegebenen Zeichensatz.
	 *
	 * @param Mixed $mValues
	 * @param String $sType = 'UTF-8'
	 *
	 * @return $mValues
	 */
	public static function convert ($mValues, $sType = 'UTF-8'){
		if (is_array($mValues)){
			foreach ($mValues as $key=>$value) {
				$mValues[$key] = self::convert($value, $sType);
			}
		}else{
			if (is_string($mValues)){
				switch($sType) {
					case 'UTF-8':
						return utf8_encode(str_replace("€","EUR",$mValues));
					case 'ISO-8859-1':
						return utf8_decode($mValues);
					default:
						return iconv('', $sType, $mValues);
				}
			}else{
				return $mValues;
			}
		}
		return $mValues;
	}
	
	/**
	 * Maskiert Variablen bis zum "gehtnichtmehr"
	 *
	 * @param Mixed $mValues
	 * @param String $sType = 'sql'
	 *
	 * @return $mValues
	 */
	public static function escape ($mValues, $sType = 'sql'){
		if (is_array($mValues)){
			foreach ($mValues as $key => $value) {
				$mValues[$key] = self::escape($value, $sType);
			}
		}else{
			if (is_string($mValues)){
				switch($sType) {
					case 'sql':
						return mysql_real_escape_string(trim($mValues));
					case 'html':
						return htmlentities(trim($mValues), ENT_QUOTES);
					case 'uri':
						return urlencode(trim($mValues));
					case 'strip':
						return stripslashes(trim($mValues));
				}
			}else{
				return $mValues;
			}
		}
		return $mValues;
	}
	
}
