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));
35 if (!preg_match('/\.js$/', $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) || $fn == '.js' || !file_exists($dir . '/' . $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 require_once 'Pman/Core/Asset.php';
72 $compiledir = Pman_Core_Asset::getCompileDir('js', '', true);
76 $lsort = function($a,$b) { return strlen($a) > strlen($b) ? 1 : -1; };
77 usort($files, $lsort);
79 $ff = HTML_FlexyFramework::get();
81 if (!empty($ff->Pman['isDev']) && !empty($_REQUEST['isDev'])) {
82 echo "<!-- Javascript compile turned off (isDev on) -->\n";
83 $this->assetArrayToHtml($files,'js');
88 $smod = str_replace('/','.',$path);
90 $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";
114 $asset = $ff->project == 'Pman' ? '/Core/Asset/js/' : '/Asset/js/';
115 //$this->arrayToJsInclude( $files);
116 $this->assetArrayToHtml( array(
117 $this->baseURL.$asset. $output,
123 function assetArrayToHtml($ar, $type)
128 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
131 echo '<link rel="stylesheet" href="'. $f. '"/>'."\n";
141 * {outputCSSDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)}
144 function outputCSSDir($path)
147 $relpath = $this->rootURL . '/' . $path .'/';
148 $ff = HTML_FlexyFramework::get();
149 $dir = $this->rootDir.'/' . $path;
151 $args = func_get_args();
153 if (count($args) < 2) {
154 $ar = glob($dir . '/*.css');
157 foreach($args as $f) {
158 if (strpos($f,'*') > -1) {
160 $ar = array_merge($ar , glob($dir . '/'. $f));
163 // what if the fiel does not exist???
164 $ar[] = $dir .'/'. $f;
169 echo "<!-- skipping $path - no files found -->\n";
173 // cached version?? - how do we decide if it's expired?
174 // while scanning the directory is slow... - it's faster than serving every file...
177 //$path = $this->rootURL ."/Pman/$mod/";
180 $missing_files = false;
183 $relfiles = array(); // array of files without the path part...
186 foreach($ar as $fn) {
187 $relfiles[] = substr($fn, strlen($dir)+1);
189 // got the 'module file..'
191 if (!file_exists($dir . '/'. $f)) {
192 echo "<!-- missing {$relpath}{$f} -->\n";
193 $files[] = $relpath . $f . '?ts=0';
194 $missing_files = true;
198 $mtime = filemtime($dir . '/'. $f);
199 $maxtime = max($mtime, $maxtime);
200 $arfiles[$fn] = $mtime;
201 $files[] = $relpath . $f . '?ts='.$mtime;
206 if ($missing_files) {
207 $this->assetArrayToHtml($files, 'css');
213 //print_r($relfiles);
215 require_once 'Pman/Core/Asset.php';
216 $compiledir = Pman_Core_Asset::getCompileDir('css', '', true);
219 if (!file_exists($compiledir)) {
220 mkdir($compiledir,0700,true);
226 // yes sort... if includes are used - they have to be in the first file...
227 $lsort = function($a,$b ) {
228 return strlen($a) > strlen($b) ? 1 : -1;
230 usort($files, $lsort);
231 usort($relfiles,$lsort);
232 // print_R($relfiles);
234 $ff = HTML_FlexyFramework::get();
238 if ((!empty($ff->Pman['isDev']) || $_SERVER['HTTP_HOST'] == 'localhost' )&& !empty($_REQUEST['isDev'])) {
239 echo "<!-- CSS compile turned off (isDev on) -->\n";
240 $this->assetArrayToHtml($files,'css');
245 $smod = str_replace('/','.',$path);
247 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize(array($this->baseURL, $arfiles))) .'.css';
249 $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/';
251 // where are we going to write all of this..
252 // This has to be done via a
253 if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
255 //print_r($relfiles);
257 require_once 'HTML/CSS/Minify.php';
258 $x = new HTML_CSS_Minify(substr($relpath,0,-1), $dir, $relfiles);
260 file_put_contents($compiledir.'/'.$output , $x->minify( $this->baseURL.$asset));
262 if (!file_exists($compiledir.'/'.$output) ||
263 !filesize($compiledir.'/'.$output)) {
264 echo "<!-- compile did not generate files : " . basename($compiledir) . "/{$output} -->\n";
265 $this->assetArrayToHtml($files,'css');
270 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
274 //$this->arrayToJsInclude( $files);
275 $this->assetArrayToHtml( array(
276 $this->baseURL.$asset. $output,
284 function outputSCSS($smod)
286 // we cant output non-cached versions of this....
287 $ff = HTML_FlexyFramework::get();
288 $fp = "{$this->rootDir}/Pman/$smod/scss/{$smod}.scss";
290 if (!file_exists($fp)) {
294 $ar = glob(dirname($fp) . '/*.scss');
296 foreach($ar as $fn) {
297 $maxtime=max($maxtime, filemtime($fn));
302 //print_r($relfiles);
304 require_once 'Pman/Core/Asset.php';
305 $compiledir = Pman_Core_Asset::getCompileDir('css', '', true);
308 if (!file_exists($compiledir)) {
309 mkdir($compiledir,0700,true);
315 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize(array($this->baseURL, $ar))) .'.css';
317 $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/';
319 // where are we going to write all of this..
320 // This has to be done via a
324 if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
328 require_once 'System.php';
329 static $sassc = false;
330 if ($sassc === false) {
331 $sassc = System::which("sassc");
334 die("INSTALL sassc");
339 $ver = `$sassc --version`;
340 $bits = explode("\n", $ver);
341 foreach($bits as $b) {
342 $lr = explode(":", $b);
343 $vers[trim($lr[0])] = trim($lr[1]);
346 $sm = $vers['sass'] > 3.4 ? ' --sourcemap=auto ' : '--sourcemap';
347 $cmd = "{$sassc} --style=compressed {$sm} -I {$fd} -I {$this->rootDir}/roojs1/scss/bootstrap $smod.scss {$compiledir}/{$output}";
348 //echo "$cmd\n"; echo `$cmd`;
353 if (!file_exists($compiledir.'/'.$output) ||
354 !filesize($compiledir.'/'.$routput)) {
355 echo "<!-- compile did not generate files : $cmd -->\n";
356 echo "<script type=\"text/javascript\">alert('Failed to compile {$fp}');</script>\n";
361 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
365 //$this->arrayToJsInclude( $files);
366 $this->assetArrayToHtml( array(
367 $this->baseURL.$asset. $output,