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 require_once 'Pman/Core/Asset.php';
70 $compiledir = Pman_Core_Asset::getCompileDir('js', '', true);
74 $lsort = function($a,$b) { return strlen($a) > strlen($b) ? 1 : -1; };
75 usort($files, $lsort);
77 $ff = HTML_FlexyFramework::get();
79 if (!empty($ff->Pman['isDev']) && !empty($_REQUEST['isDev'])) {
80 echo "<!-- Javascript compile turned off (isDev on) -->\n";
81 $this->assetArrayToHtml($files,'js');
86 $smod = str_replace('/','.',$path);
88 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.js';
93 // where are we going to write all of this..
94 // This has to be done via a
95 if (!file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
96 require_once 'Pman/Core/JsCompile.php';
97 $x = new Pman_Core_JsCompile();
99 $x->pack($arfiles,$compiledir.'/'.$output, false);
101 if (!file_exists($compiledir.'/'.$output) ||
102 !filesize($compiledir.'/'.$output)) {
103 echo "<!-- compile did not generate files : ". basename($compiledir) ."/{$output} -->\n";
104 $this->assetArrayToHtml($files,'js');
109 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
112 $asset = $ff->project == 'Pman' ? '/Core/Asset/js/' : '/Asset/js/';
113 //$this->arrayToJsInclude( $files);
114 $this->assetArrayToHtml( array(
115 $this->baseURL.$asset. $output,
121 function assetArrayToHtml($ar, $type)
126 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
129 echo '<link rel="stylesheet" href="'. $f. '"/>'."\n";
140 * {outputCssDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)}
143 function outputCssDir($path)
146 $relpath = $this->rootURL . '/' . $path .'/';
147 $ff = HTML_FlexyFramework::get();
148 $dir = $this->rootDir.'/' . $path;
150 $args = func_get_args();
152 if (count($args) < 2) {
153 $ar = glob($dir . '/*.css');
156 foreach($args as $f) {
157 if (strpos($f,'*') > -1) {
159 $ar = array_merge($ar , glob($dir . '/'. $f));
162 // what if the fiel does not exist???
163 $ar[] = $dir .'/'. $f;
168 echo "<!-- skipping $path - no files found -->\n";
172 // cached version?? - how do we decide if it's expired?
173 // while scanning the directory is slow... - it's faster than serving every file...
176 //$path = $this->rootURL ."/Pman/$mod/";
179 $missing_files = false;
182 $relfiles = array(); // array of files without the path part...
185 foreach($ar as $fn) {
186 $relfiles[] = substr($fn, strlen($dir)+1);
188 // got the 'module file..'
190 if (!file_exists($dir . '/'. $f)) {
191 echo "<!-- missing {$relpath}{$f} -->\n";
192 $files[] = $relpath . $f . '?ts=0';
193 $missing_files = true;
197 $mtime = filemtime($dir . '/'. $f);
198 $maxtime = max($mtime, $maxtime);
199 $arfiles[$fn] = $mtime;
200 $files[] = $relpath . $f . '?ts='.$mtime;
205 if ($missing_files) {
206 $this->assetArrayToHtml($files, 'css');
212 //print_r($relfiles);
214 require_once 'Pman/Core/Asset.php';
215 $compiledir = Pman_Core_Asset::getCompileDir('css', '', true);
218 if (!file_exists($compiledir)) {
219 mkdir($compiledir,0700,true);
225 // yes sort... if includes are used - they have to be in the first file...
226 $lsort = function($a,$b ) {
227 return strlen($a) > strlen($b) ? 1 : -1;
229 usort($files, $lsort);
230 usort($relfiles,$lsort);
231 // print_R($relfiles);
233 $ff = HTML_FlexyFramework::get();
237 if ((!empty($ff->Pman['isDev']) || $_SERVER['HTTP_HOST'] == 'localhost' )&& !empty($_REQUEST['isDev'])) {
238 echo "<!-- CSS compile turned off (isDev on) -->\n";
239 $this->assetArrayToHtml($files,'css');
244 $smod = str_replace('/','.',$path);
246 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize(array($this->baseURL, $arfiles))) .'.css';
248 $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/';
250 // where are we going to write all of this..
251 // This has to be done via a
252 if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
254 //print_r($relfiles);
256 require_once 'HTML/CSS/Minify.php';
257 $x = new HTML_CSS_Minify(substr($relpath,0,-1), $dir, $relfiles);
259 file_put_contents($compiledir.'/'.$output , $x->minify( $this->baseURL.$asset));
261 if (!file_exists($compiledir.'/'.$output) ||
262 !filesize($compiledir.'/'.$routput)) {
263 echo "<!-- compile did not generate files : " . basename($compiledir) . "/{$output} -->\n";
264 $this->assetArrayToHtml($files,'css');
269 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
273 //$this->arrayToJsInclude( $files);
274 $this->assetArrayToHtml( array(
275 $this->baseURL.$asset. $output,