2 // a little experimental... we are going to use the same name as the class. for these..
4 trait Pman_Core_Asset_Trait {
10 * {outputJavascriptDir(#Hydra#,#Hydra.js",#.......#)}
16 function outputJavascriptDir($path)
19 $relpath = $this->rootURL . '/' . $path .'/';
20 $ff = HTML_FlexyFramework::get();
21 $dir = $this->rootDir.'/' . $path;
23 $args = func_get_args();
25 if (count($args) < 2) {
26 $ar = glob($dir . '/*.js');
29 foreach($args as $f) {
30 if (strpos($f,'*') > -1) {
32 $ar = array_merge($ar , glob($dir . '/'. $f));
36 $ar[] = $dir .'/'. $f;
40 // cached version?? - how do we decide if it's expired?
41 // while scanning the directory is slow... - it's faster than serving every file...
44 //$path = $this->rootURL ."/Pman/$mod/";
54 // got the 'module file..'
55 $mtime = filemtime($dir . '/'. $f);
56 $maxtime = max($mtime, $maxtime);
57 $arfiles[$fn] = $mtime;
58 $files[] = $relpath . $f . '?ts='.$mtime;
61 ksort($arfiles); // just sort by name so it's consistant for serialize..
63 $ui = posix_getpwuid(posix_geteuid());
66 $compiledir = session_save_path() . '/' .
67 $ui['name'] . '-' . $ff->project . '-' . $ff->version . '-jscompile';
69 if (!file_exists($compiledir)) {
70 mkdir($compiledir,0700,true);
75 $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
76 usort($files, $lsort);
79 if (!empty($this->bootLoader->isDev) && !empty($_REQUEST['isDev'])) {
80 echo "<!-- Javascript compile turned off (isDev on) -->\n";
81 $this->assetArrayToHtml($files,'js');
86 $smod = str_replace('/','.',$path);
88 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.js';
92 // where are we going to write all of this..
93 // This has to be done via a
94 if (!file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
95 require_once 'Pman/Core/JsCompile.php';
96 $x = new Pman_Core_JsCompile();
98 $x->pack($arfiles,$compiledir.'/'.$output, false);
100 if (!file_exists($compiledir.'/'.$output) ||
101 !filesize($compiledir.'/'.$output)) {
102 echo "<!-- compile did not generate files : ". basename($compiledir) ."/{$output} -->\n";
103 $this->assetArrayToHtml($files,'js');
108 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
110 //$this->arrayToJsInclude( $files);
111 $this->assetArrayToHtml( array(
112 $this->baseURL.'/Asset/js/'. $output,
118 function assetArrayToHtml($ar, $type)
123 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
126 echo '<link rel="stylesheet" href="'. $f. '"/>'."\n";
137 * {outputCssDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)}
140 function outputCssDir($path)
143 $relpath = $this->rootURL . '/' . $path .'/';
144 $ff = HTML_FlexyFramework::get();
145 $dir = $this->rootDir.'/' . $path;
147 $args = func_get_args();
149 if (count($args) < 2) {
150 $ar = glob($dir . '/*.css');
153 foreach($args as $f) {
154 if (strpos($f,'*') > -1) {
156 $ar = array_merge($ar , glob($dir . '/'. $f));
159 // what if the fiel does not exist???
160 $ar[] = $dir .'/'. $f;
166 // cached version?? - how do we decide if it's expired?
167 // while scanning the directory is slow... - it's faster than serving every file...
170 //$path = $this->rootURL ."/Pman/$mod/";
173 $missing_files = false;
176 $relfiles = array(); // array of files without the path part...
179 foreach($ar as $fn) {
180 $relfiles[] = substr($fn, strlen($dir)+1);
182 // got the 'module file..'
184 if (!file_exists($dir . '/'. $f)) {
185 echo "<!-- missing {$relpath}{$f} -->\n";
186 $files[] = $relpath . $f . '?ts=0';
187 $missing_files = true;
191 $mtime = filemtime($dir . '/'. $f);
192 $maxtime = max($mtime, $maxtime);
193 $arfiles[$fn] = $mtime;
194 $files[] = $relpath . $f . '?ts='.$mtime;
199 if ($missing_files) {
200 $this->assetArrayToHtml($files, 'css');
206 //print_r($relfiles);
208 $ui = posix_getpwuid(posix_geteuid());
211 $compiledir = session_save_path() . '/' .
212 $ui['name'] . '-' . $ff->project . '-'. $ff->version . '-csscompile';
214 if (!file_exists($compiledir)) {
215 mkdir($compiledir,0700,true);
220 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
221 //usort($files, $lsort);
224 if (!empty($this->bootLoader->isDev) && !empty($_REQUEST['isDev'])) {
225 echo "<!-- CSS compile turned off (isDev on) -->\n";
226 $this->assetArrayToHtml($files,'css');
231 $smod = str_replace('/','.',$path);
233 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.css';
237 // where are we going to write all of this..
238 // This has to be done via a
239 if (true || !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
243 require_once 'HTML/CSS/Minify.php';
244 $x = new HTML_CSS_Minify(substr($relpath,0,-1), $dir, $relfiles);
246 file_put_contents($compiledir.'/'.$output , $x->minify( $this->baseURL.'/Asset/css'));
248 if (!file_exists($compiledir.'/'.$output) ||
249 !filesize($compiledir.'/'.$routput)) {
250 echo "<!-- compile did not generate files : " . basename($compiledir) . "/{$output} -->\n";
251 $this->assetArrayToHtml($files,'css');
256 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
258 //$this->arrayToJsInclude( $files);
259 $this->assetArrayToHtml( array(
260 $this->baseURL.'/Asset/css/'. $output,