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 files 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);
81 $ff = HTML_FlexyFramework::get();
83 if (!empty($ff->Pman['isDev']) && !empty($_REQUEST['isDev'])) {
84 echo "<!-- Javascript compile turned off (isDev on) -->\n";
85 $this->assetArrayToHtml($files,'js');
90 $smod = str_replace('/','.',$path);
92 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.js';
97 // where are we going to write all of this..
98 // This has to be done via a
99 if (!file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
100 require_once 'Pman/Core/JsCompile.php';
101 $x = new Pman_Core_JsCompile();
103 $x->pack($arfiles,$compiledir.'/'.$output, false);
105 if (!file_exists($compiledir.'/'.$output) ||
106 !filesize($compiledir.'/'.$output)) {
107 echo "<!-- compile did not generate files : ". basename($compiledir) ."/{$output} -->\n";
108 $this->assetArrayToHtml($files,'js');
113 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
116 $asset = $ff->project == 'Pman' ? '/Core/Asset/js/' : '/Asset/js/';
117 //$this->arrayToJsInclude( $files);
118 $this->assetArrayToHtml( array(
119 $this->baseURL.$asset. $output,
125 function assetArrayToHtml($ar, $type)
130 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
133 echo '<link rel="stylesheet" href="'. $f. '"/>'."\n";
144 * {outputCssDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)}
147 function outputCssDir($path)
150 $relpath = $this->rootURL . '/' . $path .'/';
151 $ff = HTML_FlexyFramework::get();
152 $dir = $this->rootDir.'/' . $path;
154 $args = func_get_args();
156 if (count($args) < 2) {
157 $ar = glob($dir . '/*.css');
160 foreach($args as $f) {
161 if (strpos($f,'*') > -1) {
163 $ar = array_merge($ar , glob($dir . '/'. $f));
166 // what if the fiel does not exist???
167 $ar[] = $dir .'/'. $f;
172 echo "<!-- skipping $path - no files found -->\n";
176 // cached version?? - how do we decide if it's expired?
177 // while scanning the directory is slow... - it's faster than serving every file...
180 //$path = $this->rootURL ."/Pman/$mod/";
183 $missing_files = false;
186 $relfiles = array(); // array of files without the path part...
189 foreach($ar as $fn) {
190 $relfiles[] = substr($fn, strlen($dir)+1);
192 // got the 'module file..'
194 if (!file_exists($dir . '/'. $f)) {
195 echo "<!-- missing {$relpath}{$f} -->\n";
196 $files[] = $relpath . $f . '?ts=0';
197 $missing_files = true;
201 $mtime = filemtime($dir . '/'. $f);
202 $maxtime = max($mtime, $maxtime);
203 $arfiles[$fn] = $mtime;
204 $files[] = $relpath . $f . '?ts='.$mtime;
209 if ($missing_files) {
210 $this->assetArrayToHtml($files, 'css');
216 //print_r($relfiles);
218 $ui = posix_getpwuid(posix_geteuid());
221 $compiledir = session_save_path() . '/' .
222 $ui['name'] . '-' . $ff->project . '-'. $ff->version . '-csscompile';
224 if (!file_exists($compiledir)) {
225 mkdir($compiledir,0700,true);
231 // yes sort... if includes are used - they have to be in the first file...
232 $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
233 usort($files, $lsort);
234 usort($relfiles,$lsort);
235 // print_R($relfiles);
237 $ff = HTML_FlexyFramework::get();
239 if (!empty($ff->Pman['isDev']) && !empty($_REQUEST['isDev'])) {
240 echo "<!-- CSS compile turned off (isDev on) -->\n";
241 $this->assetArrayToHtml($files,'css');
246 $smod = str_replace('/','.',$path);
248 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize(array($this->baseURL, $arfiles))) .'.css';
250 $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/';
252 // where are we going to write all of this..
253 // This has to be done via a
254 if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
256 //print_r($relfiles);
258 require_once 'HTML/CSS/Minify.php';
259 $x = new HTML_CSS_Minify(substr($relpath,0,-1), $dir, $relfiles);
261 file_put_contents($compiledir.'/'.$output , $x->minify( $this->baseURL.$asset));
263 if (!file_exists($compiledir.'/'.$output) ||
264 !filesize($compiledir.'/'.$routput)) {
265 echo "<!-- compile did not generate files : " . basename($compiledir) . "/{$output} -->\n";
266 $this->assetArrayToHtml($files,'css');
271 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
275 //$this->arrayToJsInclude( $files);
276 $this->assetArrayToHtml( array(
277 $this->baseURL.$asset. $output,