You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.php 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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::addStyle('files', 'upload');
  27. OCP\Util::addscript('files', 'file-upload');
  28. OCP\Util::addscript('files', 'jquery.iframe-transport');
  29. OCP\Util::addscript('files', 'jquery.fileupload');
  30. OCP\Util::addscript('files', 'jquery-visibility');
  31. OCP\Util::addscript('files', 'filelist');
  32. OCP\App::setActiveNavigationEntry('files_index');
  33. // Load the files
  34. $dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : '';
  35. // Redirect if directory does not exist
  36. if (!\OC\Files\Filesystem::is_dir($dir . '/')) {
  37. header('Location: ' . OCP\Util::getScriptName() . '');
  38. exit();
  39. }
  40. $isIE8 = false;
  41. preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
  42. if (count($matches) > 0 && $matches[1] <= 8){
  43. $isIE8 = true;
  44. }
  45. // if IE8 and "?dir=path" was specified, reformat the URL to use a hash like "#?dir=path"
  46. if ($isIE8 && isset($_GET['dir'])){
  47. if ($dir === ''){
  48. $dir = '/';
  49. }
  50. header('Location: ' . OCP\Util::linkTo('files', 'index.php') . '#?dir=' . \OCP\Util::encodePath($dir));
  51. exit();
  52. }
  53. $ajaxLoad = false;
  54. $files = array();
  55. $user = OC_User::getUser();
  56. if (\OC\Files\Cache\Upgrade::needUpgrade($user)) { //dont load anything if we need to upgrade the cache
  57. $needUpgrade = true;
  58. $freeSpace = 0;
  59. } else {
  60. if ($isIE8){
  61. // after the redirect above, the URL will have a format
  62. // like "files#?dir=path" which means that no path was given
  63. // (dir is not set). In that specific case, we don't return any
  64. // files because the client will take care of switching the dir
  65. // to the one from the hash, then ajax-load the initial file list
  66. $files = array();
  67. $ajaxLoad = true;
  68. }
  69. else{
  70. $files = \OCA\Files\Helper::getFiles($dir);
  71. }
  72. $freeSpace = \OC\Files\Filesystem::free_space($dir);
  73. $needUpgrade = false;
  74. }
  75. // Make breadcrumb
  76. $breadcrumb = \OCA\Files\Helper::makeBreadcrumb($dir);
  77. // make breadcrumb und filelist markup
  78. $list = new OCP\Template('files', 'part.list', '');
  79. $list->assign('files', $files);
  80. $list->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir=');
  81. $list->assign('downloadURL', OCP\Util::linkToRoute('download', array('file' => '/')));
  82. $list->assign('isPublic', false);
  83. $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
  84. $breadcrumbNav->assign('breadcrumb', $breadcrumb);
  85. $breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir=');
  86. $permissions = \OCA\Files\Helper::getDirPermissions($dir);
  87. if ($needUpgrade) {
  88. OCP\Util::addscript('files', 'upgrade');
  89. $tmpl = new OCP\Template('files', 'upgrade', 'user');
  90. $tmpl->printPage();
  91. } else {
  92. // information about storage capacities
  93. $storageInfo=OC_Helper::getStorageInfo($dir);
  94. $maxUploadFilesize=OCP\Util::maxUploadFilesize($dir);
  95. $publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes');
  96. if (OC_App::isEnabled('files_encryption')) {
  97. $publicUploadEnabled = 'no';
  98. }
  99. $trashEnabled = \OCP\App::isEnabled('files_trashbin');
  100. $trashEmpty = true;
  101. if ($trashEnabled) {
  102. $trashEmpty = \OCA\Files_Trashbin\Trashbin::isEmpty($user);
  103. }
  104. OCP\Util::addscript('files', 'fileactions');
  105. OCP\Util::addscript('files', 'files');
  106. OCP\Util::addscript('files', 'keyboardshortcuts');
  107. $tmpl = new OCP\Template('files', 'index', 'user');
  108. $tmpl->assign('fileList', $list->fetchPage());
  109. $tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage());
  110. $tmpl->assign('dir', \OC\Files\Filesystem::normalizePath($dir));
  111. $tmpl->assign('isCreatable', \OC\Files\Filesystem::isCreatable($dir . '/'));
  112. $tmpl->assign('permissions', $permissions);
  113. $tmpl->assign('files', $files);
  114. $tmpl->assign('trash', $trashEnabled);
  115. $tmpl->assign('trashEmpty', $trashEmpty);
  116. $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
  117. $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
  118. $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
  119. $tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']);
  120. $tmpl->assign('isPublic', false);
  121. $tmpl->assign('publicUploadEnabled', $publicUploadEnabled);
  122. $tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles());
  123. $tmpl->assign('disableSharing', false);
  124. $tmpl->assign('ajaxLoad', $ajaxLoad);
  125. $tmpl->printPage();
  126. }