4 * Generic cached assset server...
7 * Also includes code to generate assets...
9 * methods outputJavascriptDir / outputCssDir generate links to
10 * BASEURL/Asset/css/xxxx.yyy.zzz
11 * BASEURL/Asset/js/xxxx.yyy.zzz
14 * we deliver the file from
15 * SESSION-DIR/{$www-user}-{$ff->project}-$ff->version}-{js|css}-compile/{filename}';
20 require_once 'Pman.php';
22 class Pman_Core_Asset extends Pman {
27 'js' => 'text/javascript',
34 $bits = explode('/', $s);
36 if (empty($bits[0]) || empty($bits[1]) || !isset($this->types[$bits[0]])) {
37 $this->jerr("invalid url");
40 $s = str_replace('/', '-', $bits[1]);
42 $ui = posix_getpwuid(posix_geteuid());
43 $ff = HTML_FlexyFramework::get();
45 $compile = session_save_path() . '/' .
46 $ui['name'] . '-' . $ff->project . '-' . $ff->version . '-'. $bits[0] . 'compile';
48 $fn = $compile . '/'. $s .'.'. $bits[0];
53 if (!file_exists($fn)) {
54 header('Content-Type: '. $this->types[$bits[0]]);
56 echo "// compiled file not found = $fn";
60 $last_modified_time = filemtime($fn);
65 isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
66 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time
70 isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
71 trim($_SERVER['HTTP_IF_NONE_MATCH']) == md5($fn)
73 header("HTTP/1.1 304 Not Modified");
77 header('Content-Type: '. $this->types[$bits[0]]);
80 header("Pragma: public");
81 header('Content-Length: '. filesize($fn));
82 header('Cache-Control: max-age=2592000, public');
83 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 2592000));
84 header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', $last_modified_time));
85 header('Etag: '. md5($fn));
93 function post($s='') {