index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. // Check if we are a user
  3. OCP\User::checkLoggedIn();
  4. OCP\App::setActiveNavigationEntry('files_index');
  5. OCP\Util::addScript('files_trashbin', 'trash');
  6. OCP\Util::addScript('files_trashbin', 'disableDefaultActions');
  7. OCP\Util::addScript('files', 'fileactions');
  8. $tmpl = new OCP\Template('files_trashbin', 'index', 'user');
  9. $user = \OCP\User::getUser();
  10. $view = new OC_Filesystemview('/'.$user.'/files_trashbin/files');
  11. OCP\Util::addStyle('files', 'files');
  12. OCP\Util::addScript('files', 'filelist');
  13. $dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : '';
  14. $result = array();
  15. if ($dir) {
  16. $dirlisting = true;
  17. $fullpath = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath($dir);
  18. $dirContent = opendir($fullpath);
  19. $i = 0;
  20. while($entryName = readdir($dirContent)) {
  21. if ( $entryName != '.' && $entryName != '..' ) {
  22. $pos = strpos($dir.'/', '/', 1);
  23. $tmp = substr($dir, 0, $pos);
  24. $pos = strrpos($tmp, '.d');
  25. $timestamp = substr($tmp, $pos+2);
  26. $result[] = array(
  27. 'id' => $entryName,
  28. 'timestamp' => $timestamp,
  29. 'mime' => $view->getMimeType($dir.'/'.$entryName),
  30. 'type' => $view->is_dir($dir.'/'.$entryName) ? 'dir' : 'file',
  31. 'location' => $dir,
  32. );
  33. }
  34. }
  35. closedir($dirContent);
  36. } else {
  37. $dirlisting = false;
  38. $query = \OC_DB::prepare('SELECT `id`,`location`,`timestamp`,`type`,`mime` FROM `*PREFIX*files_trash` WHERE `user` = ?');
  39. $result = $query->execute(array($user))->fetchAll();
  40. }
  41. $files = array();
  42. foreach ($result as $r) {
  43. $i = array();
  44. $i['name'] = $r['id'];
  45. $i['date'] = OCP\Util::formatDate($r['timestamp']);
  46. $i['timestamp'] = $r['timestamp'];
  47. $i['mimetype'] = $r['mime'];
  48. $i['type'] = $r['type'];
  49. if ($i['type'] == 'file') {
  50. $fileinfo = pathinfo($r['id']);
  51. $i['basename'] = $fileinfo['filename'];
  52. $i['extension'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : '';
  53. }
  54. $i['directory'] = $r['location'];
  55. if ($i['directory'] == '/') {
  56. $i['directory'] = '';
  57. }
  58. $i['permissions'] = OCP\PERMISSION_READ;
  59. $files[] = $i;
  60. }
  61. function fileCmp($a, $b) {
  62. if ($a['type'] == 'dir' and $b['type'] != 'dir') {
  63. return -1;
  64. } elseif ($a['type'] != 'dir' and $b['type'] == 'dir') {
  65. return 1;
  66. } else {
  67. return strnatcasecmp($a['name'], $b['name']);
  68. }
  69. }
  70. usort($files, "fileCmp");
  71. // Make breadcrumb
  72. $pathtohere = '';
  73. $breadcrumb = array();
  74. foreach (explode('/', $dir) as $i) {
  75. if ($i != '') {
  76. if ( preg_match('/^(.+)\.d[0-9]+$/', $i, $match) ) {
  77. $name = $match[1];
  78. } else {
  79. $name = $i;
  80. }
  81. $pathtohere .= '/' . $i;
  82. $breadcrumb[] = array('dir' => $pathtohere, 'name' => $name);
  83. }
  84. }
  85. $breadcrumbNav = new OCP\Template('files_trashbin', 'part.breadcrumb', '');
  86. $breadcrumbNav->assign('breadcrumb', $breadcrumb);
  87. $breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php') . '?dir=');
  88. $breadcrumbNav->assign('home', OCP\Util::linkTo('files', 'index.php'));
  89. $list = new OCP\Template('files_trashbin', 'part.list', '');
  90. $list->assign('files', $files);
  91. $list->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php'). '?dir='.$dir);
  92. $list->assign('downloadURL', OCP\Util::linkTo('files_trashbin', 'download.php') . '?file='.$dir);
  93. $list->assign('disableSharing', true);
  94. $list->assign('dirlisting', $dirlisting);
  95. $tmpl->assign('dirlisting', $dirlisting);
  96. $list->assign('disableDownloadActions', true);
  97. $tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage());
  98. $tmpl->assign('fileList', $list->fetchPage());
  99. $tmpl->assign('files', $files);
  100. $tmpl->assign('dir', \OC\Files\Filesystem::normalizePath($view->getAbsolutePath()));
  101. $tmpl->printPage();