4 * Generic cached assset server... -- No security om this.. should only return compressed CSS/JS
6 * Does a few tricks with headers to improve caching...
9 * Also includes code to generate assets...
11 * methods outputJavascriptDir / outputCssDir generate links to
12 * BASEURL/Asset/css/xxxx.yyy.zzz
13 * BASEURL/Asset/js/xxxx.yyy.zzz
16 * we deliver the file from
17 * SESSION-DIR/{$www-user}-{$ff->project}-$ff->version}-{js|css}-compile/{filename}/PATH';
22 require_once 'Pman.php';
24 class Pman_Core_Asset extends Pman {
28 'js' => 'text/javascript',
40 $bits = explode('/', $s);
42 if (empty($bits[0]) || empty($bits[1]) || !isset($this->types[$bits[0]])) {
43 $this->jerr("invalid url");
46 $s = str_replace('/', '-', $bits[1]);
48 $ui = posix_getpwuid(posix_geteuid());
49 $ff = HTML_FlexyFramework::get();
51 $compile = session_save_path() . '/' .
52 $ui['name'] . '-' . $ff->project . '-' . $ff->version . '-'. $bits[0] . 'compile';
54 $fn = $compile . '/'. $s .'.'. $bits[0];
59 if (!file_exists($fn)) {
60 header('Content-Type: '. $this->types[$bits[0]]);
62 echo "// compiled file not found = $fn";
66 $last_modified_time = filemtime($fn);
71 isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
72 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time
76 isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
77 trim($_SERVER['HTTP_IF_NONE_MATCH']) == md5($fn)
79 header("HTTP/1.1 304 Not Modified");
83 header('Content-Type: '. $this->types[$bits[0]]);
86 header("Pragma: public");
87 header('Content-Length: '. filesize($fn));
88 header('Cache-Control: max-age=2592000, public');
89 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 2592000));
90 header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', $last_modified_time));
91 header('Etag: '. md5($fn));
99 function post($s='') {