2013-11-10 13:58:08 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* File utility class
|
|
|
|
*
|
|
|
|
* @author steeffeen & kremsy
|
|
|
|
*/
|
2013-11-27 02:42:39 +01:00
|
|
|
abstract class FileUtil {
|
2013-11-10 13:58:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load config xml-file
|
|
|
|
*
|
|
|
|
* @param string $fileName
|
|
|
|
* @return \SimpleXMLElement
|
|
|
|
*/
|
|
|
|
public static function loadConfig($fileName) {
|
|
|
|
$fileLocation = ManiaControlDir . '/configs/' . $fileName;
|
|
|
|
if (!file_exists($fileLocation)) {
|
|
|
|
trigger_error("Config file doesn't exist! ({$fileName})");
|
|
|
|
return null;
|
|
|
|
}
|
2013-11-24 23:55:54 +01:00
|
|
|
if (!is_readable($fileLocation)) {
|
|
|
|
trigger_error("Config file isn't readable! ({$fileName})");
|
|
|
|
return null;
|
|
|
|
}
|
2013-11-10 13:58:08 +01:00
|
|
|
return simplexml_load_file($fileLocation);
|
|
|
|
}
|
2013-11-27 02:42:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return file name cleared from special characters
|
|
|
|
*
|
|
|
|
* @param string $fileName
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getClearedFileName($fileName) {
|
|
|
|
return str_replace(array('\\', '/', ':', '*', '?', '"', '<', '>', '|'), '_', $fileName);
|
|
|
|
}
|
2013-11-10 13:58:08 +01:00
|
|
|
}
|