fix #8131 - chinese translations
[Pman.Core] / AssetTrait.php
index 2935acb..0067d6f 100644 (file)
@@ -32,7 +32,9 @@ trait Pman_Core_AssetTrait {
                     $ar = array_merge($ar ,  glob($dir . '/'. $f));
                     continue;
                 }
-                
+                if (!preg_match('/\.js$/', $f)) {
+                    $f .= ".js";
+                }
                 $ar[] = $dir .'/'. $f;
             }
           
@@ -54,6 +56,9 @@ trait Pman_Core_AssetTrait {
         $mtime = 0;
         foreach($ar as $fn) {
             $f = basename($fn);
+            if (!preg_match('/\.js$/', $f) || $fn == '.js' || !file_exists($dir . '/' . $f)) { // only javascript files... (so XXX.Dialog.YYY*  works..)
+                continue;
+            }
             // got the 'module file..'
             $mtime = filemtime($dir . '/'. $f);
             $maxtime = max($mtime, $maxtime);
@@ -63,24 +68,18 @@ trait Pman_Core_AssetTrait {
         
         ksort($arfiles); // just sort by name so it's consistant for serialize..
         
-        $ui = posix_getpwuid(posix_geteuid());
-       
-        
-        $compiledir = session_save_path() . '/' .
-                $ui['name'] . '-' . $ff->project . '-' . $ff->version . '-jscompile';
-        
-        if (!file_exists($compiledir)) {
-            mkdir($compiledir,0700,true);
-        }
+        require_once 'Pman/Core/Asset.php';
+        $compiledir = Pman_Core_Asset::getCompileDir('js', '', true);
         
          
         
-        $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
+        $lsort = function($a,$b) { return strlen($a) > strlen($b) ? 1 : -1; };
         usort($files, $lsort);
         
+        $ff = HTML_FlexyFramework::get();
         
-        if (!empty($this->bootLoader->isDev) && !empty($_REQUEST['isDev'])) {
-            echo "<!-- Javascript compile turned off (isDev on) -->\n";
+        if (empty($compiledir) || (!empty($ff->Pman['isDev']) && !empty($_REQUEST['isDev']))) {
+            echo "<!-- Javascript compile turned off (isDev on or mkdir failed) -->\n";
             $this->assetArrayToHtml($files,'js');
             return;
         }
@@ -90,7 +89,8 @@ trait Pman_Core_AssetTrait {
         
         $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.js';
          
-         
+        
+        
         
         // where are we going to write all of this..
         // This has to be done via a 
@@ -132,17 +132,16 @@ trait Pman_Core_AssetTrait {
                     break;
        
             }
-            
         }
     }
     
     
     /**
      * usage in template
-     * {outputCssDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)}
+     * {outputCSSDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)}
      */
     
-    function outputCssDir($path)
+    function outputCSSDir($path)
     {
           
         $relpath = $this->rootURL . '/' . $path .'/';
@@ -212,13 +211,11 @@ trait Pman_Core_AssetTrait {
         
          
         //print_r($relfiles);
+      
+        require_once 'Pman/Core/Asset.php';
+        $compiledir = Pman_Core_Asset::getCompileDir('css', '', true);
         
-        $ui = posix_getpwuid(posix_geteuid());
-       
-        
-        $compiledir = session_save_path() . '/' .
-                $ui['name'] . '-' . $ff->project . '-'. $ff->version . '-csscompile';
-        
+         
         if (!file_exists($compiledir)) {
             mkdir($compiledir,0700,true);
         }
@@ -227,11 +224,18 @@ trait Pman_Core_AssetTrait {
         
         
         // yes sort... if includes are used - they have to be in the first file...
-        $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
+        $lsort = function($a,$b ) {
+                return strlen($a) > strlen($b) ? 1 : -1;
+        };
         usort($files, $lsort);
+        usort($relfiles,$lsort);
+       // print_R($relfiles);
         
+        $ff = HTML_FlexyFramework::get();
+        
+        // isDev set
         
-        if (!empty($this->bootLoader->isDev) && !empty($_REQUEST['isDev'])) {
+        if ((!empty($ff->Pman['isDev']) || $_SERVER['HTTP_HOST'] == 'localhost' )&& !empty($_REQUEST['isDev'])) {
             echo "<!-- CSS compile turned off (isDev on) -->\n";
             $this->assetArrayToHtml($files,'css');
             return;
@@ -240,13 +244,13 @@ trait Pman_Core_AssetTrait {
         
         $smod = str_replace('/','.',$path);
         
-        $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.css';
+        $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize(array($this->baseURL, $arfiles))) .'.css';
          
-         $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/';
+        $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/';
         
         // where are we going to write all of this..
         // This has to be done via a 
-        if (!file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
+        if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
             
             //print_r($relfiles);
             
@@ -256,7 +260,7 @@ trait Pman_Core_AssetTrait {
             file_put_contents($compiledir.'/'.$output , $x->minify( $this->baseURL.$asset));
             clearstatcache();
             if (!file_exists($compiledir.'/'.$output) ||
-                !filesize($compiledir.'/'.$routput)) {
+                !filesize($compiledir.'/'.$output)) {
                 echo "<!-- compile did not generate files : " . basename($compiledir) . "/{$output} -->\n";
                 $this->assetArrayToHtml($files,'css');
                 return;
@@ -277,4 +281,122 @@ trait Pman_Core_AssetTrait {
     
     
     
+    function outputSCSS($smod)
+    {
+        // we cant output non-cached versions of this....
+        
+        // this doesnt really look like it would work!
+        $this->outputSCSSDir("{$this->rootDir}/Pman/{$smod}/scss/{$smod}.scss", $smod);
+        
+    }
+    /*
+     * Pman projects - expect
+     * /Pman/MyProject/scss/MyProject.less  <<
+     *           this should contain includes for the others?
+     *              @import "fonts.less";
+     *              ....
+     * Then all the files go here.
+     * /Pman/MyProject/scss/*.less
+     *
+     * For a Non Pman project
+     *  send:
+     *  /MyProject/scss/base.less << could be anything really...
+     *
+     * 
+     */
+     
+    
+    function outputSCSSDir($file, $smod= '')
+    {
+        
+         
+        $ff = HTML_FlexyFramework::get();
+        $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/';
+        
+        
+        if (!file_exists($file)) {
+            return;
+        }
+        
+        $ar = glob(dirname($file). '/*.scss');
+        $maxtime = filemtime($file);
+        foreach($ar as $fn) {
+            $maxtime= max($maxtime, filemtime($fn));
+        }
+        
+        
+        
+        //print_r($relfiles);
+      
+        require_once 'Pman/Core/Asset.php';
+        $compiledir = Pman_Core_Asset::getCompileDir('css',  '', true);
+        
+         
+        if (!file_exists($compiledir)) {
+            mkdir($compiledir,0700,true);
+        }
+        
+         
+        $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-less-'.md5(serialize(array($this->baseURL, $ar))) .'.css';
+         
+        
+        
+        // where are we going to write all of this..
+        // This has to be done via a
+         
+        
+        if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) {
+            
+            
+            
+            require_once 'System.php';
+            static $sassc = false;
+            if ($sassc === false) {
+                $sassc = System::which("sassc");
+            }
+            if (empty($sassc)) {
+                die("INSTALL sassc");
+            }
+                 
+             
+            $ver = `$sassc --version`;
+            $bits = explode("\n", trim($ver));
+            foreach($bits as $b) {
+                 
+                $lr = explode(":", $b);
+                $vers[trim($lr[0])] = trim($lr[1]);
+            } 
+            
+            $sm = $vers['sass'] > 3.4 ? ' --sourcemap=auto ' : '--sourcemap';
+            $cmd = "{$sassc} --style=compressed  {$sm} -I ". dirname($file) . " -I {$this->rootDir}/roojs1/scss/bootstrap ". basename($file) . " {$compiledir}/{$output}";
+            //echo "$cmd\n";            echo `$cmd`;
+            `$cmd`;
+            
+             
+            clearstatcache();
+            if (!file_exists($compiledir.'/'.$output) ||
+                !filesize($compiledir.'/'.$output)) {
+                echo "<!-- compile did not generate files : $cmd -->\n";
+                echo "<script type=\"text/javascript\">alert('Failed to compile Less Dir: ". basename($file). "');</script>\n";
+                return;
+            } 
+            
+        } else {
+         //   echo "<!-- file already exists: {$basedir}/{$output} -->\n";
+        }
+        
+         
+        //$this->arrayToJsInclude(  $files);
+        $this->assetArrayToHtml(  array(
+            $this->baseURL.$asset. $output,
+          
+        ),'css');
+        
+    }
+    
+    
+    
+     
+    
+    
 }
\ No newline at end of file