This repository was archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.php
More file actions
48 lines (43 loc) · 1.29 KB
/
util.php
File metadata and controls
48 lines (43 loc) · 1.29 KB
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
41
42
43
44
45
46
47
48
<?php
/**
* Auto loader, will automatically auto load necessary classes, replaces _ with /
* @param string $class The name of the file to auto load
*
*/
function my_autoloader($class) {
include 'lib/' . str_replace('_',DIRECTORY_SEPARATOR,$class) . '.php';
}
spl_autoload_register('my_autoloader');
/**
* Given a file, i.e. /css/base.css, replaces it with a string ending with the
* file's md5 hash, i.e. /css/base.css?[md5 hash]
*
* now instead of <link rel="stylesheet" href="/css/base.css" type="text/css" />
* use <link rel="stylesheet" href="<?php echo auto_version('/css/base.css'); ?>" type="text/css" />
*
* @param $file The file to be loaded. Must be an absolute path (i.e.
* starting with slash).
* @return string
* @author Caleb Nelson <calebnelson@mac.com>
*/
function auto_version($file)
{
if(!file_exists($file))
return $file;
$new_name = $file.'?'.md5_file($file);
return $new_name;
}
/**
* Uses the return from print_r() wrapped in <pre> tags
* @param mixed $var The variable to pretty print
* @return string $var inside
* @author Caleb Nelson <calebnelson@mac.com>
*/
function prettyPrint($var){
$response = "<pre>";
$ob_start();
print_r($var);
$response .= $ob_get_clean()."</pre";
return $response;
}
?>