4 * Generic cached assset server... -- No security o this..
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}/PATH';
20 require_once 'Pman.php';
22 class Pman_Core_Asset extends Pman {
27 'js' => 'text/javascript',
39 $bits = explode('/', $s);
41 if (empty($bits[0]) || empty($bits[1]) || !isset($this->types[$bits[0]])) {
42 $this->jerr("invalid url");
45 $s = str_replace('/', '-', $bits[1]);
47 $ui = posix_getpwuid(posix_geteuid());
48 $ff = HTML_FlexyFramework::get();
50 $compile = session_save_path() . '/' .
51 $ui['name'] . '-' . $ff->project . '-' . $ff->version . '-'. $bits[0] . 'compile';
53 $fn = $compile . '/'. $s .'.'. $bits[0];
58 if (!file_exists($fn)) {
59 header('Content-Type: '. $this->types[$bits[0]]);
61 echo "// compiled file not found = $fn";
65 $last_modified_time = filemtime($fn);
70 isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
71 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time
75 isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
76 trim($_SERVER['HTTP_IF_NONE_MATCH']) == md5($fn)
78 header("HTTP/1.1 304 Not Modified");
82 header('Content-Type: '. $this->types[$bits[0]]);
85 header("Pragma: public");
86 header('Content-Length: '. filesize($fn));
87 header('Cache-Control: max-age=2592000, public');
88 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 2592000));
89 header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', $last_modified_time));
90 header('Etag: '. md5($fn));
98 function post($s='') {