root / class / utils.class.php @ 3a832cbc
1 |
<?php
|
---|---|
2 |
|
3 |
abstract class utils { |
4 |
static public function init() { |
5 |
function __autoload($class) { |
6 |
$class_loc = 'class/'.$class.'.class.php'; |
7 |
if (is_readable($class_loc)) { |
8 |
require_once($class_loc); |
9 |
} |
10 |
} |
11 |
|
12 |
function errorToException($code, $msg, $file, $line) { |
13 |
throw new Exception($msg); |
14 |
} |
15 |
set_error_handler('errorToException'); |
16 |
} |
17 |
|
18 |
static public function list_available_panos($base_dir) { |
19 |
/** Lists all that can be turned into a panorama
|
20 |
*/
|
21 |
$dir = opendir($base_dir); |
22 |
$ret = array(); |
23 |
$finfo = finfo_open(FILEINFO_MIME_TYPE); // Retourne le type mime du fichier |
24 |
|
25 |
while(false !== ($filename = readdir($dir))) { |
26 |
if (!preg_match('/^\.\.?$/', $filename)) { |
27 |
$ftype = finfo_file($finfo, $base_dir.'/'.$filename); |
28 |
if (isset($ftype)) { |
29 |
$pano = array( |
30 |
'comment' => $filename, |
31 |
'title' => sprintf('fichier de type %s', $ftype) |
32 |
); |
33 |
} else {
|
34 |
$pano = array( |
35 |
'comment' => sprintf('<samp>%s</samp>', $filename), |
36 |
'title' => '' |
37 |
); |
38 |
} |
39 |
$pano['filename'] = $filename; |
40 |
$ret[] = $pano; |
41 |
} |
42 |
} |
43 |
return $ret; |
44 |
} |
45 |
public static function strip_extension($filename) { |
46 |
/** Removes the extension from a file name
|
47 |
* @return the stripped name
|
48 |
*/
|
49 |
return preg_replace('/\.[^.]+$/', '', $filename); |
50 |
} |
51 |
|
52 |
public static function php2ini($v) { |
53 |
/** convert php var to a string representing it in an ini file.
|
54 |
* @return a string, ready to be inserted into a ini file.
|
55 |
*/
|
56 |
if (is_numeric($v)) { |
57 |
return $v; |
58 |
} |
59 |
$type = gettype($v); |
60 |
switch($type) { |
61 |
case 'boolean': return $v ? "true" : "false"; |
62 |
default: return '"'.$v.'"'; |
63 |
} |
64 |
return $v; |
65 |
} |
66 |
} |
67 |
|
68 |
?>
|