index.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * ownCloud - ajax frontend
  4. *
  5. * @author Robin Appelman
  6. * @copyright 2010 Robin Appelman icewind1991@gmail.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. // Check if we are a user
  23. OCP\User::checkLoggedIn();
  24. // Load the files we need
  25. OCP\Util::addStyle('files', 'files');
  26. OCP\Util::addscript('files', 'jquery.iframe-transport');
  27. OCP\Util::addscript('files', 'jquery.fileupload');
  28. OCP\Util::addscript('files', 'jquery-visibility');
  29. OCP\Util::addscript('files', 'filelist');
  30. OCP\App::setActiveNavigationEntry('files_index');
  31. // Load the files
  32. $dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : '';
  33. // Redirect if directory does not exist
  34. if (!\OC\Files\Filesystem::is_dir($dir . '/')) {
  35. header('Location: ' . OCP\Util::getScriptName() . '');
  36. exit();
  37. }
  38. function fileCmp($a, $b) {
  39. if ($a['type'] == 'dir' and $b['type'] != 'dir') {
  40. return -1;
  41. } elseif ($a['type'] != 'dir' and $b['type'] == 'dir') {
  42. return 1;
  43. } else {
  44. return strnatcasecmp($a['name'], $b['name']);
  45. }
  46. }
  47. $files = array();
  48. $user = OC_User::getUser();
  49. if (\OC\Files\Cache\Upgrade::needUpgrade($user)) { //dont load anything if we need to upgrade the cache
  50. $content = array();
  51. $needUpgrade = true;
  52. $freeSpace = 0;
  53. } else {
  54. $content = \OC\Files\Filesystem::getDirectoryContent($dir);
  55. $freeSpace = \OC\Files\Filesystem::free_space($dir);
  56. $needUpgrade = false;
  57. }
  58. foreach ($content as $i) {
  59. $i['date'] = OCP\Util::formatDate($i['mtime']);
  60. if ($i['type'] == 'file') {
  61. $fileinfo = pathinfo($i['name']);
  62. $i['basename'] = $fileinfo['filename'];
  63. if (!empty($fileinfo['extension'])) {
  64. $i['extension'] = '.' . $fileinfo['extension'];
  65. } else {
  66. $i['extension'] = '';
  67. }
  68. }
  69. $i['directory'] = $dir;
  70. $files[] = $i;
  71. }
  72. usort($files, "fileCmp");
  73. // Make breadcrumb
  74. $breadcrumb = array();
  75. $pathtohere = '';
  76. foreach (explode('/', $dir) as $i) {
  77. if ($i != '') {
  78. $pathtohere .= '/' . $i;
  79. $breadcrumb[] = array('dir' => $pathtohere, 'name' => $i);
  80. }
  81. }
  82. // make breadcrumb und filelist markup
  83. $list = new OCP\Template('files', 'part.list', '');
  84. $list->assign('files', $files);
  85. $list->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir=');
  86. $list->assign('downloadURL', OCP\Util::linkToRoute('download', array('file' => '/')));
  87. $list->assign('disableSharing', false);
  88. $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
  89. $breadcrumbNav->assign('breadcrumb', $breadcrumb);
  90. $breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir=');
  91. $permissions = OCP\PERMISSION_READ;
  92. if (\OC\Files\Filesystem::isCreatable($dir . '/')) {
  93. $permissions |= OCP\PERMISSION_CREATE;
  94. }
  95. if (\OC\Files\Filesystem::isUpdatable($dir . '/')) {
  96. $permissions |= OCP\PERMISSION_UPDATE;
  97. }
  98. if (\OC\Files\Filesystem::isDeletable($dir . '/')) {
  99. $permissions |= OCP\PERMISSION_DELETE;
  100. }
  101. if (\OC\Files\Filesystem::isSharable($dir . '/')) {
  102. $permissions |= OCP\PERMISSION_SHARE;
  103. }
  104. if ($needUpgrade) {
  105. OCP\Util::addscript('files', 'upgrade');
  106. $tmpl = new OCP\Template('files', 'upgrade', 'user');
  107. $tmpl->printPage();
  108. } else {
  109. // information about storage capacities
  110. $storageInfo=OC_Helper::getStorageInfo();
  111. $maxUploadFilesize=OCP\Util::maxUploadFilesize($dir);
  112. OCP\Util::addscript('files', 'fileactions');
  113. OCP\Util::addscript('files', 'files');
  114. OCP\Util::addscript('files', 'keyboardshortcuts');
  115. $tmpl = new OCP\Template('files', 'index', 'user');
  116. $tmpl->assign('fileList', $list->fetchPage());
  117. $tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage());
  118. $tmpl->assign('dir', \OC\Files\Filesystem::normalizePath($dir));
  119. $tmpl->assign('isCreatable', \OC\Files\Filesystem::isCreatable($dir . '/'));
  120. $tmpl->assign('permissions', $permissions);
  121. $tmpl->assign('files', $files);
  122. $tmpl->assign('trash', \OCP\App::isEnabled('files_trashbin'));
  123. $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
  124. $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
  125. $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
  126. $tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']);
  127. $tmpl->printPage();
  128. }