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/Asset.php';
71 $compiledir = Pman_Asset::getCompileDir(js, '', true);
75 $lsort = function($a,$b) { return strlen($a) > strlen($b) ? 1 : -1; };
76 usort($files, $lsort);
78 $ff = HTML_FlexyFramework::get();
80 if (!empty($ff->Pman['isDev']) && !empty($_REQUEST['isDev'])) {
81 echo "<!-- Javascript compile turned off (isDev on) -->\n";
82 $this->assetArrayToHtml($files,'js');
87 $smod = str_replace('/','.',$path);
89 $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.js';
94 // where are we going to write all of this..
95 // This has to be done via a
96 if (!file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
97 require_once 'Pman/Core/JsCompile.php';
98 $x = new Pman_Core_JsCompile();
100 $x->pack($arfiles,$compiledir.'/'.$output, false);
102 if (!file_exists($compiledir.'/'.$output) ||
103 !filesize($compiledir.'/'.$output)) {
104 echo "<!-- compile did not generate files : ". basename($compiledir) ."/{$output} -->\n";
105 $this->assetArrayToHtml($files,'js');
110 // echo "<!-- file already exists: {$basedir}/{$output} -->\n";
113 $asset = $ff->project == 'Pman' ? '/Core/Asset/js/' : '/Asset/js/';
114 //$this->arrayToJsInclude( $files);
115 $this->assetArrayToHtml( array(
116 $this->baseURL.$asset. $output,
122 function assetArrayToHtml($ar, $type)
127 echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
130 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 $ui = posix_getpwuid(posix_geteuid());
218 $compiledir = session_save_path() . '/' .
219 $ui['name'] . '-' . $ff->project . '-'. $ff->version . '-csscompile';
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,