Location: PHPKode > scripts > ezStats for Medal of Honor > functions.php
<?php
	class ezFunctions {
		/* Elemente eines Ordners in einem Array speichern */
		public function get_objects_in_folder($path, $mode = 'all', $rekursive = true) {
			/*	(array) get_objects_in_folder( (string) $path [,(string) $mode[, (boolean) $rekursive]] )
				$path = Verzeichnispfad relativ zum aufrufenden Script
				$mode = Verzeichnisse und/oder Dateien? ('all', 'folder', 'files')
				$rekursive = Unterfolder mit auflisten? (true, false) */
			$path = preg_replace('~(.*)/$~', '\\1', $path); /* letzten Slash aus dem String entfernen */
			$list = array();
			$read = opendir($path);
			while($item = readdir($read)) {
				switch($mode) {
					case 'files':
					if (is_file("$path/$item"))
					$list[] = $rekursive ? "$path/$item" : $item;
					break;

					case 'folder':
					if (is_dir("$path/$item") && !preg_match('~^\.\.?$~', $item))
					$list[] = $rekursive ? "$path/$item" : $item;
					break;

					default:
					if (!preg_match('~^\.\.?$~', $item))
					$list[] = $rekursive ? "$path/$item" : $item;
				}
				/* Unterfolder? */
				if(!preg_match('~^\.\.?$~', $item) && is_dir("$path/$item") && $rekursive) {
					$list2 = $this->get_objects_in_folder("$path/$item", $mode, $rekursive);
					foreach($list2 as $item2) $list[] = $item2;
				}
			}
			closedir($read);
			sort($list);
			return $list;
		}
		
		
		/* Überprüft ob eine Variable gesetzt und mit Inhalt gefüllt ist */
		public function is_arrayvalue_empty($key, $array) {
			if(array_key_exists($key, $array))  {
				if (empty($array[$key]) OR $array[$key] == " ") {
					return true;
				} else {
					return false;
				}
			} else {
				return true;
			}
		}
		
		
		/* Konvertiert die Statsdaten um für die Verwendung auf der HP */
		public function convert_stats_data($data, $mode) {
			switch ($mode) {
				/* Allgemeine Funktionen */
				case "number":
					if (isset($data[3]) AND $data[3]) $title = $data[3]; else $title = "";
					if (isset($data[2]) AND $data[2]) $suffix = $data[2]; else $suffix = "";
					if (isset($data[1]) AND $data[1]) $decimal = $data[1]; else $decimal = 0;
					if ($data[0]) {
						$value = $data[0];
						
						if ($suffix == "k") {
							$form_value = number_format($value/1000, $decimal, ".", " ");
							$title_value = number_format($value, $decimal, ".", " ");
							if ($title != "") $title = $title.': '.$title_value;
						} elseif ($suffix == "%") {
							$form_value = number_format($value*100, $decimal, ".", " ");
							if ($title != "") $title = $title.': '.$form_value;
						} else {
							$form_value = number_format($value, $decimal, ".", " ");
							if ($title != "") $title = $title.': '.$form_value;
						}
						
					} else {
						$value = 0;
						$form_value = 0;
					}
					
					$value = str_pad($value, 10, "0", STR_PAD_LEFT);
					
					$result  = '<span class="hidden">'.$value.'</span>';
					$result .= '<span class="nowrap" title="'.$title.'">'.$form_value.$suffix.'</span>';
					break;
				
				case "time":
					if (isset($data[3]) AND $data[3]) $title = $data[3]; else $title = "";
					if (isset($data[2]) AND $data[2]) $suffix = $data[2]; else $suffix = "";
					if (isset($data[1]) AND $data[1]) $decimal = $data[1]; else $decimal = 0;
					if ($data[0]) {
						$value = $data[0];
						
						$time = Array();
						$time['sec'] = $value % 60;
						$time['min'] = (($value - $time['sec']) / 60) % 60;
						$time['std'] = (((($value - $time['sec']) /60) - $time['min']) / 60) % 24;
						$time['day'] = floor( ((((($value - $time['sec']) /60) - $time['min']) / 60) / 24) ); 
						$time_string = sprintf('%dd %sh %sm', $time['day'],str_pad($time['std'], 2, "0", STR_PAD_LEFT), str_pad($time['min'], 2, "0", STR_PAD_LEFT));
						
						if ($suffix == "h") 	$form_value = number_format(round($value/3600), $decimal, ".", " ");
						if ($suffix == "min") 	$form_value = number_format(round($value/60), $decimal, ".", " ");
						if ($suffix == "date") {
							$form_value = $time_string;
							$suffix = "";
						}
					} else {
						$value = 0;
						$form_value = 0;
						$time_string = "0 min";
					}
					
					if ($title != "") 		$title = $title.': '.$time_string; else $title = "";
					
					$result  = '<span class="hidden">'.$value.'</span>';
					$result .= '<span title="'.$title.'">'.$form_value.$suffix.'</span>';
					break;
				
				case "ratio":
					if (isset($data[5]) AND $data[5]) $color = $data[5]; else $color = false;
					if (isset($data[4]) AND $data[4]) $title = $data[4]; else $title = "";
					if (isset($data[3]) AND $data[3]) $suffix = $data[3]; else $suffix = "";
					if (isset($data[2]) AND $data[2]) $decimal = $data[2]; else $decimal = 0;
					if ($data[0] AND $data[1]) {
						$value = $data[0] / $data[1];
						$form_value = number_format($value, $decimal, ".", " ");
						if ($color) {
							if ($value > 1) $class = "pos"; else $class = "neg";
						} else $class = "";
						
						if ($suffix == "%") 	$form_value = number_format($value*100, $decimal, ".", " ");
					} else {
						$value = 0;
						$form_value = 0;
						$class = "";
					}
					
					if ($title != "") 		$title = $title.': '.$form_value.$suffix; else $title = "";
					
					$result  = '<span class="hidden">'.$value.'</span>';
					$result .= '<span title="'.$title.'" class="'.$class.'">'.$form_value.$suffix.'</span>';
					break;
				
				/* Besondere Funktionen */
				case "country":
					$country = $data[0];
					$display = $data[1];
					$imgpath = "http://files.mohstats.com/img/flags/";
					
					if ($display == "block") {
						$result  = '<span class="hidden">'.$country.'</span>';
						$result .= '<div style="width: 16px; height: 11px; background: url(\''.$imgpath.$country.'.png\') no-repeat scroll 0 0 transparent"></div>';
					} else  {
						$result = "";
					}
					
					break;
				
				
				case "namelink":
					$name = $data[0];
					$id = $data[1];
					$ezstats = $data[2];
					$title = $data[3];
					$system = $data[4];
					
					if (isset($ezstats['playernames'][$id]) AND $ezstats['playernames'][$id] != "") $playername = $ezstats['playernames'][$id]; else $playername = $name;
					if (isset($ezstats['clantag'])) $playername = $ezstats['clantag'].$playername;
					
					if ($ezstats['detaillink']) {
						$url     = $ezstats['relpath'].'detail.php#'.$id;
						$result  = '<span class="hidden">'.htmlentities($playername).'</span>';
						$result .= '<a rel="ezDetail" href="'.$url.'" alt="'.htmlentities($playername).'" title="'.$title.'">'.htmlentities($playername).'</a>';
						break;
					} else {
						$result  = '<span class="hidden">'.htmlentities($playername).'</span>';
						$result .= '<a href="http://mohstats.com/stats_'.$system.'/'.urlencode($name).'" target="_blank" title="'.$title.'">'.htmlentities($playername).'</a>';
						break;
					}
				
			}
			
			return $result;
		}
		
		
		/* Überprüft ob eine neuere ezStats-Version verfügbar ist */
		public function check_version($version) {
			$ch = curl_init("http://www.ezzemm.de/pages/ezstats/curl.php?version&game=moh");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			$check = curl_exec($ch);
			curl_close($ch);
			if ($check <= $version) {
				return false;
			} else {
				return true;
			}
		}
		
		
		/* CMS-Handbuch-Klasse */
		public function list_available_cms($active, $src) {
			$foldernames = $this->get_objects_in_folder($src, 'folder', false);
			$manuals = $this->get_objects_in_folder($src, 'folder', true);
			$result = "";
			
			for ($i = 0; $i < count($manuals); $i++) {
				$name = file_get_contents($manuals[$i].'/name.txt');
				if ($foldernames[$i] == $active) {
					$result .= '<dd><input type="radio" name="cms" value="'.$foldernames[$i].'" checked />'.$name.'</dd>';
				} else  {
					$result .= '<dd><input type="radio" name="cms" value="'.$foldernames[$i].'" />'.$name.'</dd>';
				}
			}
			return $result;
		}
		
		
		/* Übersetzt die für AJAX maskierten Steuerzeichen */
		public function replace_masked_control_characters($string) {
			$string = str_replace("*PLUS*", "+", $string);
			$string = str_replace("*EQUALS*", "=", $string);
			$string = str_replace("*AMPERSAND*", "&", $string);
			
			return $string;
		}
	}
?>
Return current item: ezStats for Medal of Honor