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 if (!preg_match('/\.js$/', $f)) { // only javascript files... (so XXX.Dialog.YYY* works..)
60 // got the 'module file..'
61 $mtime = filemtime($dir . '/'. $f);
62 $maxtime = max($mtime, $maxtime);
63 $arfiles[$fn] = $mtime;
64 $files[] = $relpath . $f . '?ts='.$mtime;
67 ksort($arfiles); // just sort by name so it's consistant for serialize..
69 $ui = posix_getpwuid(posix_geteuid());
72 $compiledir = session_save_path() . '/' .
73 $ui['name'] . '-' . $ff->project . '-' . $ff->version . '-jscompile';
75 if (!file_exists($compiledir)) {
76 mkdir($compiledir,0700,true);
81 $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
82 usort($files, $lsort);
84 $ff = HTML_FlexyFramework::get();
86 if (!empty($ff->Pman['isDev']) && !empty($_REQUEST['isDev'])) {
87 echo "<!-- Javascript compile turned off (isDev on) -->\n";
88 $this->assetArrayToHtml($files,'js');
93 $smod = str_replace('/','.',$path);
95 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.js';
100 // where are we going to write all of this..
101 // This has to be done via a
102 if (!file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
103 require_once 'Pman/Core/JsCompile.php';
104 $x = new Pman_Core_JsCompile();
106 $x->pack($arfiles,$compiledir.'/'.$output, false);
108 if (!file_exists($compiledir.'/'.$output) ||
109 !filesize($compiledir.'/'.$output)) {
110 echo "<!-- compile did not generate files : ". basename($compiledir) ."/{$output} -->\n";
111 $this->assetArrayToHtml($files,'js');
116 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
119 $asset = $ff->project == 'Pman' ? '/Core/Asset/js/' : '/Asset/js/';
120 //$this->arrayToJsInclude( $files);
121 $this->assetArrayToHtml( array(
122 $this->baseURL.$asset. $output,
128 function assetArrayToHtml($ar, $type)
133 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
136 echo '<link rel="stylesheet" href="'. $f. '"/>'."\n";
147 * {outputCssDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)}
150 function outputCssDir($path)
153 $relpath = $this->rootURL . '/' . $path .'/';
154 $ff = HTML_FlexyFramework::get();
155 $dir = $this->rootDir.'/' . $path;
157 $args = func_get_args();
159 if (count($args) < 2) {
160 $ar = glob($dir . '/*.css');
163 foreach($args as $f) {
164 if (strpos($f,'*') > -1) {
166 $ar = array_merge($ar , glob($dir . '/'. $f));
169 // what if the fiel does not exist???
170 $ar[] = $dir .'/'. $f;
175 echo "<!-- skipping $path - no files found -->\n";
179 // cached version?? - how do we decide if it's expired?
180 // while scanning the directory is slow... - it's faster than serving every file...
183 //$path = $this->rootURL ."/Pman/$mod/";
186 $missing_files = false;
189 $relfiles = array(); // array of files without the path part...
192 foreach($ar as $fn) {
193 $relfiles[] = substr($fn, strlen($dir)+1);
195 // got the 'module file..'
197 if (!file_exists($dir . '/'. $f)) {
198 echo "<!-- missing {$relpath}{$f} -->\n";
199 $files[] = $relpath . $f . '?ts=0';
200 $missing_files = true;
204 $mtime = filemtime($dir . '/'. $f);
205 $maxtime = max($mtime, $maxtime);
206 $arfiles[$fn] = $mtime;
207 $files[] = $relpath . $f . '?ts='.$mtime;
212 if ($missing_files) {
213 $this->assetArrayToHtml($files, 'css');
219 //print_r($relfiles);
221 $ui = posix_getpwuid(posix_geteuid());
224 $compiledir = session_save_path() . '/' .
225 $ui['name'] . '-' . $ff->project . '-'. $ff->version . '-csscompile';
227 if (!file_exists($compiledir)) {
228 mkdir($compiledir,0700,true);
234 // yes sort... if includes are used - they have to be in the first file...
235 $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
236 usort($files, $lsort);
237 usort($relfiles,$lsort);
238 // print_R($relfiles);
240 $ff = HTML_FlexyFramework::get();
244 if ((!empty($ff->Pman['isDev']) || $_SERVER['HTTP_HOST'] == 'localhost' )&& !empty($_REQUEST['isDev'])) {
245 echo "<!-- CSS compile turned off (isDev on) -->\n";
246 $this->assetArrayToHtml($files,'css');
251 $smod = str_replace('/','.',$path);
253 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize(array($this->baseURL, $arfiles))) .'.css';
255 $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/';
257 // where are we going to write all of this..
258 // This has to be done via a
259 if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
261 //print_r($relfiles);
263 require_once 'HTML/CSS/Minify.php';
264 $x = new HTML_CSS_Minify(substr($relpath,0,-1), $dir, $relfiles);
266 file_put_contents($compiledir.'/'.$output , $x->minify( $this->baseURL.$asset));
268 if (!file_exists($compiledir.'/'.$output) ||
269 !filesize($compiledir.'/'.$routput)) {
270 echo "<!-- compile did not generate files : " . basename($compiledir) . "/{$output} -->\n";
271 $this->assetArrayToHtml($files,'css');
276 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
280 //$this->arrayToJsInclude( $files);
281 $this->assetArrayToHtml( array(
282 $this->baseURL.$asset. $output,