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)
21 $relpath = $this->rootURL . '/' . $path .'/';
22 $ff = HTML_FlexyFramework::get();
23 $dir = $this->rootDir.'/' . $path;
25 $args = func_get_args();
27 if (count($args) < 2) {
28 $ar = glob($dir . '/*.js');
31 foreach($args as $f) {
32 if (strpos($f,'*') > -1) {
34 $ar = array_merge($ar , glob($dir . '/'. $f));
38 $ar[] = $dir .'/'. $f;
42 // cached version?? - how do we decide if it's expired?
43 // while scanning the directory is slow... - it's faster than serving every file...
45 echo "<!-- skipping $path - no files found -->\n";
49 //$path = $this->rootURL ."/Pman/$mod/";
59 if (!preg_match('/\.js$/', $f)) { // only javascript files... (so XXX.Dialog.YYY* works..)
62 // got the 'module file..'
63 $mtime = filemtime($dir . '/'. $f);
64 $maxtime = max($mtime, $maxtime);
65 $arfiles[$fn] = $mtime;
66 $files[] = $relpath . $f . '?ts='.$mtime;
69 ksort($arfiles); // just sort by name so it's consistant for serialize..
71 $ui = posix_getpwuid(posix_geteuid());
74 $compiledir = session_save_path() . '/' .
75 $ui['name'] . '-' . $ff->project . '-' . $ff->version . '-jscompile';
77 if (!file_exists($compiledir)) {
78 mkdir($compiledir,0700,true);
83 $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
84 usort($files, $lsort);
86 $ff = HTML_FlexyFramework::get();
88 if (!empty($ff->Pman['isDev']) && !empty($_REQUEST['isDev'])) {
89 echo "<!-- Javascript compile turned off (isDev on) -->\n";
90 $this->assetArrayToHtml($files,'js');
95 $smod = str_replace('/','.',$path);
97 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.js';
102 // where are we going to write all of this..
103 // This has to be done via a
104 if (!file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
105 require_once 'Pman/Core/JsCompile.php';
106 $x = new Pman_Core_JsCompile();
108 $x->pack($arfiles,$compiledir.'/'.$output, false);
110 if (!file_exists($compiledir.'/'.$output) ||
111 !filesize($compiledir.'/'.$output)) {
112 echo "<!-- compile did not generate files : ". basename($compiledir) ."/{$output} -->\n";
113 $this->assetArrayToHtml($files,'js');
118 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
121 $asset = $ff->project == 'Pman' ? '/Core/Asset/js/' : '/Asset/js/';
122 //$this->arrayToJsInclude( $files);
123 $this->assetArrayToHtml( array(
124 $this->baseURL.$asset. $output,
130 function assetArrayToHtml($ar, $type)
135 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
138 echo '<link rel="stylesheet" href="'. $f. '"/>'."\n";
149 * {outputCssDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)}
152 function outputCssDir($path)
155 $relpath = $this->rootURL . '/' . $path .'/';
156 $ff = HTML_FlexyFramework::get();
157 $dir = $this->rootDir.'/' . $path;
159 $args = func_get_args();
161 if (count($args) < 2) {
162 $ar = glob($dir . '/*.css');
165 foreach($args as $f) {
166 if (strpos($f,'*') > -1) {
168 $ar = array_merge($ar , glob($dir . '/'. $f));
171 // what if the fiel does not exist???
172 $ar[] = $dir .'/'. $f;
177 echo "<!-- skipping $path - no files found -->\n";
181 // cached version?? - how do we decide if it's expired?
182 // while scanning the directory is slow... - it's faster than serving every file...
185 //$path = $this->rootURL ."/Pman/$mod/";
188 $missing_files = false;
191 $relfiles = array(); // array of files without the path part...
194 foreach($ar as $fn) {
195 $relfiles[] = substr($fn, strlen($dir)+1);
197 // got the 'module file..'
199 if (!file_exists($dir . '/'. $f)) {
200 echo "<!-- missing {$relpath}{$f} -->\n";
201 $files[] = $relpath . $f . '?ts=0';
202 $missing_files = true;
206 $mtime = filemtime($dir . '/'. $f);
207 $maxtime = max($mtime, $maxtime);
208 $arfiles[$fn] = $mtime;
209 $files[] = $relpath . $f . '?ts='.$mtime;
214 if ($missing_files) {
215 $this->assetArrayToHtml($files, 'css');
221 //print_r($relfiles);
223 $ui = posix_getpwuid(posix_geteuid());
226 $compiledir = session_save_path() . '/' .
227 $ui['name'] . '-' . $ff->project . '-'. $ff->version . '-csscompile';
229 if (!file_exists($compiledir)) {
230 mkdir($compiledir,0700,true);
236 // yes sort... if includes are used - they have to be in the first file...
237 $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
238 usort($files, $lsort);
239 usort($relfiles,$lsort);
240 // print_R($relfiles);
242 $ff = HTML_FlexyFramework::get();
246 if ((!empty($ff->Pman['isDev']) || $_SERVER['HTTP_HOST'] == 'localhost' )&& !empty($_REQUEST['isDev'])) {
247 echo "<!-- CSS compile turned off (isDev on) -->\n";
248 $this->assetArrayToHtml($files,'css');
253 $smod = str_replace('/','.',$path);
255 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize(array($this->baseURL, $arfiles))) .'.css';
257 $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/';
259 // where are we going to write all of this..
260 // This has to be done via a
261 if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
263 //print_r($relfiles);
265 require_once 'HTML/CSS/Minify.php';
266 $x = new HTML_CSS_Minify(substr($relpath,0,-1), $dir, $relfiles);
268 file_put_contents($compiledir.'/'.$output , $x->minify( $this->baseURL.$asset));
270 if (!file_exists($compiledir.'/'.$output) ||
271 !filesize($compiledir.'/'.$routput)) {
272 echo "<!-- compile did not generate files : " . basename($compiledir) . "/{$output} -->\n";
273 $this->assetArrayToHtml($files,'css');
278 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
282 //$this->arrayToJsInclude( $files);
283 $this->assetArrayToHtml( array(
284 $this->baseURL.$asset. $output,