cached.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. /**
  9. * get data from the filecache without checking for updates
  10. */
  11. class OC_FileCache_Cached{
  12. public static $savedData=array();
  13. public static function get($path,$root=false){
  14. if($root===false){
  15. $root=OC_Filesystem::getRoot();
  16. }
  17. $path=$root.$path;
  18. $query=OC_DB::prepare('SELECT path,ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE path_hash=?');
  19. $result=$query->execute(array(md5($path)))->fetchRow();
  20. if(is_array($result)){
  21. if(isset(self::$savedData[$path])){
  22. $result=array_merge($result,self::$savedData[$path]);
  23. }
  24. return $result;
  25. }else{
  26. if(isset(self::$savedData[$path])){
  27. return self::$savedData[$path];
  28. }else{
  29. return array();
  30. }
  31. }
  32. }
  33. /**
  34. * get all files and folders in a folder
  35. * @param string path
  36. * @param string root (optional)
  37. * @return array
  38. *
  39. * returns an array of assiciative arrays with the following keys:
  40. * - path
  41. * - name
  42. * - size
  43. * - mtime
  44. * - ctime
  45. * - mimetype
  46. * - encrypted
  47. * - versioned
  48. */
  49. public static function getFolderContent($path,$root=false,$mimetype_filter=''){
  50. if($root===false){
  51. $root=OC_Filesystem::getRoot();
  52. }
  53. $parent=OC_FileCache::getId($path,$root);
  54. if($parent==-1){
  55. return array();
  56. }
  57. $query=OC_DB::prepare('SELECT path,name,ctime,mtime,mimetype,size,encrypted,versioned,writable FROM *PREFIX*fscache WHERE parent=? AND (mimetype LIKE ? OR mimetype = ?)');
  58. $result=$query->execute(array($parent, $mimetype_filter.'%', 'httpd/unix-directory'))->fetchAll();
  59. if(is_array($result)){
  60. return $result;
  61. }else{
  62. OC_Log::write('files','getFolderContent(): file not found in cache ('.$path.')',OC_Log::DEBUG);
  63. return false;
  64. }
  65. }
  66. }