Asset.php
[Pman.Core] / Asset.php
index dec2119..8e18ea3 100644 (file)
--- a/Asset.php
+++ b/Asset.php
@@ -36,13 +36,7 @@ class Pman_Core_Asset extends Pman {
     
     function get($s='', $opts = Array())
     {
-        if(
-            !empty($_REQUEST['_clear_cache']) &&
-            !empty($_REQUEST['_clear_module'])
-        ) {
-            $this->clearCompiledFilesCache($_REQUEST['_clear_module']);
-        }
-        
+
         
         $this->sessionState(0);
         
@@ -124,6 +118,10 @@ class Pman_Core_Asset extends Pman {
     }
     
     function post($s='') {
+        if(!empty($_REQUEST['_clear_cache'])) {
+            $this->clearCompiledFilesCache();
+        }
+        
         die('invalid');
     }
      
@@ -167,18 +165,29 @@ class Pman_Core_Asset extends Pman {
         return false;
     }
     
-    function clearCompiledFilesCache($module)
+    function clearCompiledFilesCache()
     {
-        $compile_dir = $this->getCompileDir('js', $module, false);
-        
-        if(empty($compile_dir)) {
-            $this->jok('EMPTY');
+        $au = $this->getAuthUser();
+        if (!$au && !in_array($_SERVER['REMOTE_ADDR'] , array('127.0.0.1','::1'))) {
+            $this->jerr("Cache can only be cleared by authenticated users");
         }
         
-        foreach(glob($compile_dir.'/*.*') as $v){
-            unlink($v);
-        }
+        require_once 'System.php';
+        
+        $mods = $this->modulesList();
+        foreach ($mods as $module) {
+            $compile_dir = $this->getCompileDir('js', $module, false);
         
+            if(!empty($compile_dir)) {
+                System::rm(array('-r', $compiledir));
+            }
+            $compile_dir = $this->getCompileDir('css', $module, false);
+        
+            if(!empty($compile_dir)) {
+                System::rm(array('-r', $compiledir));
+            }
+        }
+         
         $this->jok('DONE');
     }
 }