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";
132 echo '<link rel="stylesheet" href="'. $f. '"/>'."\n";
143 * {outputCSSDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)}
146 function outputCSSDir($path)
149 $relpath = $this->rootURL . '/' . $path .'/';
150 $ff = HTML_FlexyFramework::get();
151 $dir = $this->rootDir.'/' . $path;
153 $args = func_get_args();
155 if (count($args) < 2) {
156 $ar = glob($dir . '/*.css');
159 foreach($args as $f) {
160 if (strpos($f,'*') > -1) {
162 $ar = array_merge($ar , glob($dir . '/'. $f));
165 // what if the fiel does not exist???
166 $ar[] = $dir .'/'. $f;
171 echo "<!-- skipping $path - no files found -->\n";
175 // cached version?? - how do we decide if it's expired?
176 // while scanning the directory is slow... - it's faster than serving every file...
179 //$path = $this->rootURL ."/Pman/$mod/";
182 $missing_files = false;
185 $relfiles = array(); // array of files without the path part...
188 foreach($ar as $fn) {
189 $relfiles[] = substr($fn, strlen($dir)+1);
191 // got the 'module file..'
193 if (!file_exists($dir . '/'. $f)) {
194 echo "<!-- missing {$relpath}{$f} -->\n";
195 $files[] = $relpath . $f . '?ts=0';
196 $missing_files = true;
200 $mtime = filemtime($dir . '/'. $f);
201 $maxtime = max($mtime, $maxtime);
202 $arfiles[$fn] = $mtime;
203 $files[] = $relpath . $f . '?ts='.$mtime;
208 if ($missing_files) {
209 $this->assetArrayToHtml($files, 'css');
215 //print_r($relfiles);
217 require_once 'Pman/Core/Asset.php';
218 $compiledir = Pman_Core_Asset::getCompileDir('css', '', true);
221 if (!file_exists($compiledir)) {
222 mkdir($compiledir,0700,true);
228 // yes sort... if includes are used - they have to be in the first file...
229 $lsort = function($a,$b ) {
230 return strlen($a) > strlen($b) ? 1 : -1;
232 usort($files, $lsort);
233 usort($relfiles,$lsort);
234 // print_R($relfiles);
236 $ff = HTML_FlexyFramework::get();
240 if ((!empty($ff->Pman['isDev']) || $_SERVER['HTTP_HOST'] == 'localhost' )&& !empty($_REQUEST['isDev'])) {
241 echo "<!-- CSS compile turned off (isDev on) -->\n";
242 $this->assetArrayToHtml($files,'css');
247 $smod = str_replace('/','.',$path);
249 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize(array($this->baseURL, $arfiles))) .'.css';
251 $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/';
253 // where are we going to write all of this..
254 // This has to be done via a
255 if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
257 //print_r($relfiles);
259 require_once 'HTML/CSS/Minify.php';
260 $x = new HTML_CSS_Minify(substr($relpath,0,-1), $dir, $relfiles);
262 file_put_contents($compiledir.'/'.$output , $x->minify( $this->baseURL.$asset));
264 if (!file_exists($compiledir.'/'.$output) ||
265 !filesize($compiledir.'/'.$routput)) {
266 echo "<!-- compile did not generate files : " . basename($compiledir) . "/{$output} -->\n";
267 $this->assetArrayToHtml($files,'css');
272 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
276 //$this->arrayToJsInclude( $files);
277 $this->assetArrayToHtml( array(
278 $this->baseURL.$asset. $output,
286 function outputSCSS($smod)
288 // we cant output non-cached versions of this....
289 $ff = HTML_FlexyFramework::get();
290 $fp = "{$this->rootDir}/Pman/$smod/scss/{$smod}.scss";
292 if (!file_exists($fp)) {
296 $ar = glob(dirname($fp) . '/*.scss');
298 foreach($ar as $fn) {
299 $maxtime=max($maxtime, filemtime($fn));
304 //print_r($relfiles);
306 require_once 'Pman/Core/Asset.php';
307 $compiledir = Pman_Core_Asset::getCompileDir('css', '', true);
310 if (!file_exists($compiledir)) {
311 mkdir($compiledir,0700,true);
317 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize(array($this->baseURL, $ar))) .'.css';
319 $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/';
321 // where are we going to write all of this..
322 // This has to be done via a
326 if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
330 require_once 'System.php';
331 static $sassc = false;
332 if ($sassc === false) {
333 $sassc = System::which("sassc");
336 die("INSTALL sassc");
342 $cmd = "{$sassc} --style=compressed --sourcemap=auto -I {$fd} -I {$this->rootDir}/roojs1/scss/bootstrap $smod.scss {$compiledir}/{$output}";
343 //echo "$cmd\n"; echo `$cmd`;
348 if (!file_exists($compiledir.'/'.$output) ||
349 !filesize($compiledir.'/'.$routput)) {
350 echo "<!-- compile did not generate files : " . basename($compiledir) . "/{$output} -->\n";
351 echo "<script type=\"text/javascript\">alert('Failed to compile {$fp}');</script>\n";
356 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
360 //$this->arrayToJsInclude( $files);
361 $this->assetArrayToHtml( array(
362 $this->baseURL.$asset. $output,