2 // a little experimental... we are going to use the same name as the class. for these..
4 trait Pman_Core_AssetTrait {
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...
43 echo "<!-- skipping $path - no file found -->\n";
47 //$path = $this->rootURL ."/Pman/$mod/";
57 // got the 'module file..'
58 $mtime = filemtime($dir . '/'. $f);
59 $maxtime = max($mtime, $maxtime);
60 $arfiles[$fn] = $mtime;
61 $files[] = $relpath . $f . '?ts='.$mtime;
64 ksort($arfiles); // just sort by name so it's consistant for serialize..
66 $ui = posix_getpwuid(posix_geteuid());
69 $compiledir = session_save_path() . '/' .
70 $ui['name'] . '-' . $ff->project . '-' . $ff->version . '-jscompile';
72 if (!file_exists($compiledir)) {
73 mkdir($compiledir,0700,true);
78 $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
79 usort($files, $lsort);
82 if (!empty($this->bootLoader->isDev) && !empty($_REQUEST['isDev'])) {
83 echo "<!-- Javascript compile turned off (isDev on) -->\n";
84 $this->assetArrayToHtml($files,'js');
89 $smod = str_replace('/','.',$path);
91 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.js';
95 // where are we going to write all of this..
96 // This has to be done via a
97 if (!file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
98 require_once 'Pman/Core/JsCompile.php';
99 $x = new Pman_Core_JsCompile();
101 $x->pack($arfiles,$compiledir.'/'.$output, false);
103 if (!file_exists($compiledir.'/'.$output) ||
104 !filesize($compiledir.'/'.$output)) {
105 echo "<!-- compile did not generate files : ". basename($compiledir) ."/{$output} -->\n";
106 $this->assetArrayToHtml($files,'js');
111 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
113 //$this->arrayToJsInclude( $files);
114 $this->assetArrayToHtml( array(
115 $this->baseURL.'/Asset/js/'. $output,
121 function assetArrayToHtml($ar, $type)
126 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
129 echo '<link rel="stylesheet" href="'. $f. '"/>'."\n";
140 * {outputCssDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)}
143 function outputCssDir($path)
146 $relpath = $this->rootURL . '/' . $path .'/';
147 $ff = HTML_FlexyFramework::get();
148 $dir = $this->rootDir.'/' . $path;
150 $args = func_get_args();
152 if (count($args) < 2) {
153 $ar = glob($dir . '/*.css');
156 foreach($args as $f) {
157 if (strpos($f,'*') > -1) {
159 $ar = array_merge($ar , glob($dir . '/'. $f));
162 // what if the fiel does not exist???
163 $ar[] = $dir .'/'. $f;
169 // cached version?? - how do we decide if it's expired?
170 // while scanning the directory is slow... - it's faster than serving every file...
173 //$path = $this->rootURL ."/Pman/$mod/";
176 $missing_files = false;
179 $relfiles = array(); // array of files without the path part...
182 foreach($ar as $fn) {
183 $relfiles[] = substr($fn, strlen($dir)+1);
185 // got the 'module file..'
187 if (!file_exists($dir . '/'. $f)) {
188 echo "<!-- missing {$relpath}{$f} -->\n";
189 $files[] = $relpath . $f . '?ts=0';
190 $missing_files = true;
194 $mtime = filemtime($dir . '/'. $f);
195 $maxtime = max($mtime, $maxtime);
196 $arfiles[$fn] = $mtime;
197 $files[] = $relpath . $f . '?ts='.$mtime;
202 if ($missing_files) {
203 $this->assetArrayToHtml($files, 'css');
209 //print_r($relfiles);
211 $ui = posix_getpwuid(posix_geteuid());
214 $compiledir = session_save_path() . '/' .
215 $ui['name'] . '-' . $ff->project . '-'. $ff->version . '-csscompile';
217 if (!file_exists($compiledir)) {
218 mkdir($compiledir,0700,true);
223 //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
224 //usort($files, $lsort);
227 if (!empty($this->bootLoader->isDev) && !empty($_REQUEST['isDev'])) {
228 echo "<!-- CSS compile turned off (isDev on) -->\n";
229 $this->assetArrayToHtml($files,'css');
234 $smod = str_replace('/','.',$path);
236 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.css';
240 // where are we going to write all of this..
241 // This has to be done via a
242 if (true || !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
246 require_once 'HTML/CSS/Minify.php';
247 $x = new HTML_CSS_Minify(substr($relpath,0,-1), $dir, $relfiles);
249 file_put_contents($compiledir.'/'.$output , $x->minify( $this->baseURL.'/Asset/css'));
251 if (!file_exists($compiledir.'/'.$output) ||
252 !filesize($compiledir.'/'.$routput)) {
253 echo "<!-- compile did not generate files : " . basename($compiledir) . "/{$output} -->\n";
254 $this->assetArrayToHtml($files,'css');
259 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
261 //$this->arrayToJsInclude( $files);
262 $this->assetArrayToHtml( array(
263 $this->baseURL.'/Asset/css/'. $output,