ctucx.git: tinyDAV

[php] Cal-/ CardDAV server with a simple web-GUI based on SabreDAV

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
<?php

abstract class Helpers {
	public static function requestVar ($name) {
		return (isset($_REQUEST[$name])) ? trim($_REQUEST[$name]) : NULL;
	}

	public static function getVar ($name) {
		return (isset($_GET[$name])) ? trim($_GET[$name]) : NULL;
	}

	public static function postVar ($name) {
		return (isset($_POST[$name])) ? trim($_POST[$name]) : NULL;
	}

	public static function isDateValid ($date, $format) {
	    $d = DateTime::createFromFormat($format, $date);
	    return $d && $d->format($format) == $date;
	}

	public static function startsWith ($string, $startString) {
		$len = strlen($startString);
		return (substr($string, 0, $len) === $startString); 
	}

	public static function delete ($target) {
		if(is_dir($target)){
    		$files = glob( $target . '*', GLOB_MARK ); //GLOB_MARK adds a slash to directories returned

			foreach( $files as $file ){
				Helpers::delete($file);      
        	}

        	rmdir($target);
		} elseif(is_file($target)) {
			unlink($target);  
		}
	}
}