]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13766, users can delele their own cache files in fp.
authordongsheng <dongsheng>
Mon, 8 Sep 2008 08:48:07 +0000 (08:48 +0000)
committerdongsheng <dongsheng>
Mon, 8 Sep 2008 08:48:07 +0000 (08:48 +0000)
lang/en_utf8/repository.php
lib/filelib.php
repository/lib.php
repository/ws.php

index bfc932b571653b1ec73bb2c0fe3d2eeb359f05f2..beec7452f4dbf0e04f7c45624c9844bfbba40f00 100644 (file)
@@ -12,7 +12,9 @@ $string['areauserpersonal'] = 'Personal';
 $string['attachment'] = 'Attachment';
 $string['back'] = '&lt; Back';
 $string['cacheexpire'] = 'Cache expire';
+$string['cachecleared'] = 'Cached files are removed';
 $string['close'] = 'Close';
+$string['cleancache'] = 'Clean my cache files';
 $string['copying'] = 'Copying';
 $string['configcacheexpire'] = 'Configurate the cache expired time (in minutes).';
 $string['configsaved'] = 'Configuration saved!';
index 358c25202afaa2f81a11b94af173f59b6d4aff4a..bc493236797054ff5aff25f330b276649a4fac6d 100644 (file)
@@ -1862,9 +1862,9 @@ class curl_cache {
         } 
     }
     public function get($param){
-        global $CFG;
+        global $CFG, $USER;
         $this->cleanup($CFG->repository_cache_expire);
-        $filename = md5(serialize($param));
+        $filename = 'u'.$USER->id.'_'.md5(serialize($param));
         if(file_exists($this->dir.$filename)) {
             $lasttime = filemtime($this->dir.$filename);
             if(time()-$lasttime > $CFG->repository_cache_expire)
@@ -1880,7 +1880,8 @@ class curl_cache {
         return false;
     }
     public function set($param, $val){
-        $filename = md5(serialize($param));
+        global $CFG, $USER;
+        $filename = 'u'.$USER->id.'_'.md5(serialize($param));
         $fp = fopen($this->dir.$filename, 'w');
         fwrite($fp, serialize($val));
         fclose($fp);
@@ -1897,4 +1898,21 @@ class curl_cache {
             }
         }
     }
+    /**
+     * delete current user's cache file
+     *
+     * @return null
+     */
+    public function refresh(){
+        global $CFG, $USER;
+        if($dir = opendir($this->dir)){
+            while (false !== ($file = readdir($dir))) {
+                if(!is_dir($file) && $file != '.' && $file != '..') {
+                    if(strpos($file, 'u'.$USER->id.'_')!==false){
+                        @unlink($this->dir.$file);
+                    }
+                }
+            }
+        }
+    }
 }
index 76562f8abd4493c1933a133ad6eac02e84df803c..c096f1af2d89cb1604f91714e8dafeedaeb53ea3 100644 (file)
@@ -1150,6 +1150,7 @@ function repository_get_client($context){
     $strback      = get_string('back', 'repository');
     $strcancel    = get_string('cancel');
     $strclose     = get_string('close', 'repository');
+    $strccache    = get_string('cleancache', 'repository');
     $strcopying   = get_string('copying', 'repository');
     $strdownbtn   = get_string('getfile', 'repository');
     $strdownload  = get_string('downloadsucc', 'repository');
@@ -1268,7 +1269,7 @@ function _client(){
                         {position: 'top', height: 32, resize: false,
                         body:'<div class="yui-buttongroup" id="repo-viewbar-$suffix"></div><div id="search-div-$suffix"></div>', gutter: '2'},
                         {position: 'left', width: 200, resize: true,
-                        body:'<ul class="repo-list" id="repo-list-$suffix"></ul>', gutter: '0 5 0 2', minWidth: 150, maxWidth: 300 },
+                        body:'<ul class="repo-list" id="repo-list-$suffix"></ul><div id="repo-kit-$suffix"></div>', gutter: '0 5 0 2', minWidth: 150, maxWidth: 300 },
                         {position: 'center', body: '<div id="panel-$suffix"></div>',
                         scroll: true, gutter: '0 2 0 0' }
                     ]
@@ -1319,6 +1320,71 @@ function _client(){
         // init repository list
         repo_list = new YAHOO.util.Element('repo-list-$suffix');
         repo_list.on('contentReady', function(e){
+            var searchbar = new YAHOO.util.Element('search-div-$suffix');
+            searchbar.get('element').innerHTML = '<label for="search-input-$suffix">$strsearch: </label><input id="search-input-$suffix" /><button id="search-btn-$suffix">$strsearch</button>';
+            var searchbtn = new YAHOO.util.Element('search-btn-$suffix');
+            searchbtn.callback = {
+                success: function(o) {
+                    var panel = new YAHOO.util.Element('panel-$suffix');
+                    try {
+                        if(!o.responseText){
+                            var panel = new YAHOO.util.Element('panel-$suffix');
+                            panel.get('element').innerHTML = 'no';
+                            return;
+                        }
+                        var json = YAHOO.lang.JSON.parse(o.responseText);
+                    } catch(e) {
+                        alert('$strinvalidjson - '+o.responseText);
+                    }
+                    _client.ds = {};
+                    if(!json.list || json.list.length<1){
+                        var panel = new YAHOO.util.Element('panel-$suffix');
+                        panel.get('element').innerHTML = 'no';
+                        return;
+                    }
+                    _client.ds.list = json.list;
+                    if(_client.ds.list) {
+                        if(_client.viewmode) {
+                            _client.viewthumb();
+                        } else {
+                            _client.viewlist();
+                        }
+                        var input_ctl = new YAHOO.util.Element('search-input-$suffix');
+                        input_ctl.get('element').value='';
+                    }
+                }
+            }
+            searchbtn.input_ctl = new YAHOO.util.Element('search-input-$suffix');
+            searchbtn.on('click', function(e){
+                var keyword = this.input_ctl.get('value');
+                var params = [];
+                params['s'] = keyword;
+                params['env']=_client.env;
+                params['action']='gsearch';
+                params['sesskey']='$sesskey';
+                params['ctx_id']=$context->id;
+                _client.loading('load');
+                var trans = YAHOO.util.Connect.asyncRequest('POST',
+                    '$CFG->httpswwwroot/repository/ws.php?action=gsearch', this.callback, _client.postdata(params));
+            });
+            var repo_kit_div = new YAHOO.util.Element('repo-kit-$suffix');
+            repo_kit_div.get('element').innerHTML = '<button id="repo-kit-ccacle-$suffix">$strccache</button>';
+            var repo_kit_ccache = new YAHOO.util.Element('repo-kit-ccacle-$suffix');      
+            repo_kit_ccache.callback = {
+                success: function(o) {
+                    var panel = new YAHOO.util.Element('panel-$suffix');
+                    panel.get('element').innerHTML = "<h1>"+o.responseText+"</h1>";
+                }
+            }
+            repo_kit_ccache.on('click', function(e){
+                var params = [];
+                params['env']=_client.env;
+                params['sesskey']='$sesskey';
+                params['ctx_id']=$context->id;
+                _client.loading('load');
+                var trans = YAHOO.util.Connect.asyncRequest('POST',
+                    '$CFG->httpswwwroot/repository/ws.php?action=ccache', this.callback, _client.postdata(params));
+            });
             for(var i=0; i<_client.repos.length; i++) {
                 var repo = _client.repos[i];
                 var li = document.createElement('li');
@@ -1344,53 +1410,6 @@ function _client(){
                 li.appendChild(opt);
                 this.appendChild(li);
                 repo = null;
-                var searchbar = new YAHOO.util.Element('search-div-$suffix');
-                searchbar.get('element').innerHTML = '<label for="search-input-$suffix">$strsearch: </label><input id="search-input-$suffix" /><button id="search-btn-$suffix">$strsearch</button>';
-                var searchbtn = new YAHOO.util.Element('search-btn-$suffix');
-                searchbtn.callback = {
-                    success: function(o) {
-                        var panel = new YAHOO.util.Element('panel-$suffix');
-                        try {
-                            if(!o.responseText){
-                                var panel = new YAHOO.util.Element('panel-$suffix');
-                                panel.get('element').innerHTML = 'no';
-                                return;
-                            }
-                            var json = YAHOO.lang.JSON.parse(o.responseText);
-                        } catch(e) {
-                            alert('$strinvalidjson - '+o.responseText);
-                        }
-                        _client.ds = {};
-                        if(!json.list || json.list.length<1){
-                            var panel = new YAHOO.util.Element('panel-$suffix');
-                            panel.get('element').innerHTML = 'no';
-                            return;
-                        }
-                        _client.ds.list = json.list;
-                        if(_client.ds.list) {
-                            if(_client.viewmode) {
-                                _client.viewthumb();
-                            } else {
-                                _client.viewlist();
-                            }
-                            var input_ctl = new YAHOO.util.Element('search-input-$suffix');
-                            input_ctl.get('element').value='';
-                        }
-                    }
-                }
-                searchbtn.input_ctl = new YAHOO.util.Element('search-input-$suffix');
-                searchbtn.on('click', function(e){
-                    var keyword = this.input_ctl.get('value');
-                    var params = [];
-                    params['s'] = keyword;
-                    params['env']=_client.env;
-                    params['action']='gsearch';
-                    params['sesskey']='$sesskey';
-                    params['ctx_id']=$context->id;
-                    _client.loading('load');
-                    var trans = YAHOO.util.Connect.asyncRequest('POST',
-                        '$CFG->httpswwwroot/repository/ws.php?action=gsearch', this.callback, _client.postdata(params));
-                });
             }
             });
     }
index 40becc9c9c9e14a6a44c5ef9aefe2af1907769da..d918864ee8b6f5a5a1d99434e60b8d35199de54b 100644 (file)
@@ -55,6 +55,11 @@ if($action=='gsearch'){
     }
     die(json_encode(array('list'=>$list)));
 }
+if ($action=='ccache') {
+    $cache = new curl_cache;
+    $cache->refresh();
+    die(get_string('cachecleared', 'repository'));
+}
 
 $sql = 'SELECT i.name, i.typeid, r.type FROM {repository} r, {repository_instances} i WHERE i.id='.$repo_id.' AND i.typeid=r.id';
 if(!$repository = $DB->get_record_sql($sql)) {