4 * Generic cached assset server...
6 * Hydra generates a url for the compressed files as /Asset/css/xxxx.yyy.zzz
10 require_once 'Pman.php';
12 class Pman_Core_Asset extends Pman {
17 'js' => 'text/javascript',
24 $bits = explode('/', $s);
26 if (empty($bits[0]) || empty($bits[1]) || !isset($this->types[$bits[0]])) {
27 $this->jerr("invalid url");
30 $s = str_replace('/', '-', $bits[1]);
32 $ui = posix_getpwuid(posix_geteuid());
33 $ff = HTML_FlexyFramework::get();
35 $compile = session_save_path() . '/' .
36 $ui['name'] . '-' . $ff->project . '-' . $ff->version . '-'. $bits[0] . 'compile';
38 $fn = $compile . '/'. $s .'.'. $bits[0];
43 if (!file_exists($fn)) {
44 header('Content-Type: '. $this->types[$bits[0]]);
46 echo "// compiled file not found = $fn";
50 $last_modified_time = filemtime($fn);
55 isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
56 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time
60 isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
61 trim($_SERVER['HTTP_IF_NONE_MATCH']) == md5($fn)
63 header("HTTP/1.1 304 Not Modified");
67 header('Content-Type: '. $this->types[$bits[0]]);
70 header("Pragma: public");
71 header('Content-Length: '. filesize($fn));
72 header('Cache-Control: max-age=2592000, public');
73 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 2592000));
74 header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', $last_modified_time));
75 header('Etag: '. md5($fn));
83 function post($s='') {