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";
142 * {outputCSSDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)}
145 function outputCSSDir($path)
148 $relpath = $this->rootURL . '/' . $path .'/';
149 $ff = HTML_FlexyFramework::get();
150 $dir = $this->rootDir.'/' . $path;
152 $args = func_get_args();
154 if (count($args) < 2) {
155 $ar = glob($dir . '/*.css');
158 foreach($args as $f) {
159 if (strpos($f,'*') > -1) {
161 $ar = array_merge($ar , glob($dir . '/'. $f));
164 // what if the fiel does not exist???
165 $ar[] = $dir .'/'. $f;
170 echo "<!-- skipping $path - no files found -->\n";
174 // cached version?? - how do we decide if it's expired?
175 // while scanning the directory is slow... - it's faster than serving every file...
178 //$path = $this->rootURL ."/Pman/$mod/";
181 $missing_files = false;
184 $relfiles = array(); // array of files without the path part...
187 foreach($ar as $fn) {
188 $relfiles[] = substr($fn, strlen($dir)+1);
190 // got the 'module file..'
192 if (!file_exists($dir . '/'. $f)) {
193 echo "<!-- missing {$relpath}{$f} -->\n";
194 $files[] = $relpath . $f . '?ts=0';
195 $missing_files = true;
199 $mtime = filemtime($dir . '/'. $f);
200 $maxtime = max($mtime, $maxtime);
201 $arfiles[$fn] = $mtime;
202 $files[] = $relpath . $f . '?ts='.$mtime;
207 if ($missing_files) {
208 $this->assetArrayToHtml($files, 'css');
214 //print_r($relfiles);
216 require_once 'Pman/Core/Asset.php';
217 $compiledir = Pman_Core_Asset::getCompileDir('css', '', true);
220 if (!file_exists($compiledir)) {
221 mkdir($compiledir,0700,true);
227 // yes sort... if includes are used - they have to be in the first file...
228 $lsort = function($a,$b ) {
229 return strlen($a) > strlen($b) ? 1 : -1;
231 usort($files, $lsort);
232 usort($relfiles,$lsort);
233 // print_R($relfiles);
235 $ff = HTML_FlexyFramework::get();
239 if ((!empty($ff->Pman['isDev']) || $_SERVER['HTTP_HOST'] == 'localhost' )&& !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,
285 function outputSCSS($smod)
287 // we cant output non-cached versions of this....
288 $ff = HTML_FlexyFramework::get();
289 $fp = "{$this->rootDir}/Pman/$smod/scss/{$smod}.scss";
291 if (!file_exists($fp)) {
295 $ar = glob(dirname($fp) . '/*.scss');
297 foreach($ar as $fn) {
298 $maxtime=max($maxtime, filemtime($fn));
303 //print_r($relfiles);
305 require_once 'Pman/Core/Asset.php';
306 $compiledir = Pman_Core_Asset::getCompileDir('scss', $smod, true);
309 if (!file_exists($compiledir)) {
310 mkdir($compiledir,0700,true);
316 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize(array($this->baseURL, $ar))) .'.css';
318 $asset = $ff->project == 'Pman' ? '/Core/Asset/scss/' : '/Asset/scss/';
320 // where are we going to write all of this..
321 // This has to be done via a
325 if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
326 require_once 'HTML/Scss.php';
327 $scss = new HTML_Scss();
329 $scss->setSourceMap(HTML_Scss::SOURCE_MAP_FILE);
330 $scss->setSourceMapOptions(array(
331 //'sourceRoot' => $file['sourceMapRootpath'],
333 // an optional name of the generated code that this source map is associated with.
334 //'sourceMapFilename' => "{$file['baseDir']}/{$file['name']}.map",
337 //'sourceMapURL' => "{$file['name']}.map",
339 // absolute path to a file to write the map to
340 //'sourceMapWriteTo' => "{$file['baseDir']}/{$file['name']}.map",
342 // output source contents?
343 'outputSourceFiles' => false,
345 // this is added to the file path.
346 // 'sourceMapRootpath' => '../',
348 // this is removed from the filepath.
349 //'sourceMapBasepath' => $rootDir .'/roojs1/scss'
350 // 'sourceMapBasepath' => dirname($fp)
354 $scss->setImportPaths($this->rootDir .'/roojs1/scss');
355 $scss->setFormatter('Expanded');
357 echo $scss->compile("@import \"{$smod}.scss\";");
360 file_put_contents($compiledir.'/'.$output, $scss->compile("@import \"{$smod}.scss\";"));
362 //print_r($relfiles);
364 require_once 'HTML/SCSS.php';
366 require_once 'HTML/CSS/Minify.php';
367 $x = new HTML_CSS_Minify(substr($relpath,0,-1), $dir, $relfiles);
369 file_put_contents($compiledir.'/'.$output , $x->minify( $this->baseURL.$asset));
371 if (!file_exists($compiledir.'/'.$output) ||
372 !filesize($compiledir.'/'.$routput)) {
373 echo "<!-- compile did not generate files : " . basename($compiledir) . "/{$output} -->\n";
374 $this->assetArrayToHtml($files,'css');
379 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
383 //$this->arrayToJsInclude( $files);
384 $this->assetArrayToHtml( array(
385 $this->baseURL.$asset. $output,