index.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. $dir = \OC\Files\Filesystem::normalizePath($dir);
  36. $dirInfo = \OC\Files\Filesystem::getFileInfo($dir);
  37. // Redirect if directory does not exist
  38. if (!$dirInfo->getType() === 'dir') {
  39. header('Location: ' . OCP\Util::getScriptName() . '');
  40. exit();
  41. }
  42. $isIE8 = false;
  43. preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
  44. if (count($matches) > 0 && $matches[1] <= 8){
  45. $isIE8 = true;
  46. }
  47. // if IE8 and "?dir=path" was specified, reformat the URL to use a hash like "#?dir=path"
  48. if ($isIE8 && isset($_GET['dir'])){
  49. if ($dir === ''){
  50. $dir = '/';
  51. }
  52. header('Location: ' . OCP\Util::linkTo('files', 'index.php') . '#?dir=' . \OCP\Util::encodePath($dir));
  53. exit();
  54. }
  55. $ajaxLoad = false;
  56. $files = array();
  57. $user = OC_User::getUser();
  58. if (\OC\Files\Cache\Upgrade::needUpgrade($user)) { //dont load anything if we need to upgrade the cache
  59. $needUpgrade = true;
  60. } else {
  61. if ($isIE8){
  62. // after the redirect above, the URL will have a format
  63. // like "files#?dir=path" which means that no path was given
  64. // (dir is not set). In that specific case, we don't return any
  65. // files because the client will take care of switching the dir
  66. // to the one from the hash, then ajax-load the initial file list
  67. $files = array();
  68. $ajaxLoad = true;
  69. }
  70. else{
  71. $files = \OCA\Files\Helper::getFiles($dir);
  72. }
  73. $needUpgrade = false;
  74. }
  75. $config = \OC::$server->getConfig();
  76. // Make breadcrumb
  77. $breadcrumb = \OCA\Files\Helper::makeBreadcrumb($dir);
  78. // make breadcrumb und filelist markup
  79. $list = new OCP\Template('files', 'part.list', '');
  80. $list->assign('files', $files);
  81. $list->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir=');
  82. $list->assign('downloadURL', OCP\Util::linkToRoute('download', array('file' => '/')));
  83. $list->assign('isPublic', false);
  84. $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
  85. $breadcrumbNav->assign('breadcrumb', $breadcrumb);
  86. $breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir=');
  87. $permissions = $dirInfo->getPermissions();
  88. if ($needUpgrade) {
  89. OCP\Util::addscript('files', 'upgrade');
  90. $tmpl = new OCP\Template('files', 'upgrade', 'user');
  91. $tmpl->printPage();
  92. } else {
  93. // information about storage capacities
  94. $storageInfo=OC_Helper::getStorageInfo($dir);
  95. $freeSpace=$storageInfo['free'];
  96. $uploadLimit=OCP\Util::uploadLimit();
  97. $maxUploadFilesize=OCP\Util::maxUploadFilesize($dir);
  98. $publicUploadEnabled = $config->getAppValue('core', 'shareapi_allow_public_upload', 'yes');
  99. // if the encryption app is disabled, than everything is fine (INIT_SUCCESSFUL status code)
  100. $encryptionInitStatus = 2;
  101. if (OC_App::isEnabled('files_encryption')) {
  102. $session = new \OCA\Encryption\Session(new \OC\Files\View('/'));
  103. $encryptionInitStatus = $session->getInitialized();
  104. }
  105. $trashEnabled = \OCP\App::isEnabled('files_trashbin');
  106. $trashEmpty = true;
  107. if ($trashEnabled) {
  108. $trashEmpty = \OCA\Files_Trashbin\Trashbin::isEmpty($user);
  109. }
  110. $isCreatable = \OC\Files\Filesystem::isCreatable($dir . '/');
  111. $fileHeader = (!isset($files) or count($files) > 0);
  112. $emptyContent = ($isCreatable and !$fileHeader) or $ajaxLoad;
  113. OCP\Util::addscript('files', 'fileactions');
  114. OCP\Util::addscript('files', 'files');
  115. OCP\Util::addscript('files', 'keyboardshortcuts');
  116. $tmpl = new OCP\Template('files', 'index', 'user');
  117. $tmpl->assign('fileList', $list->fetchPage());
  118. $tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage());
  119. $tmpl->assign('dir', $dir);
  120. $tmpl->assign('isCreatable', $isCreatable);
  121. $tmpl->assign('permissions', $permissions);
  122. $tmpl->assign('files', $files);
  123. $tmpl->assign('trash', $trashEnabled);
  124. $tmpl->assign('trashEmpty', $trashEmpty);
  125. $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); // minimium of freeSpace and uploadLimit
  126. $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
  127. $tmpl->assign('freeSpace', $freeSpace);
  128. $tmpl->assign('uploadLimit', $uploadLimit); // PHP upload limit
  129. $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
  130. $tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']);
  131. $tmpl->assign('isPublic', false);
  132. $tmpl->assign('publicUploadEnabled', $publicUploadEnabled);
  133. $tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles());
  134. $tmpl->assign("mailNotificationEnabled", $config->getAppValue('core', 'shareapi_allow_mail_notification', 'yes'));
  135. $tmpl->assign("allowShareWithLink", $config->getAppValue('core', 'shareapi_allow_links', 'yes'));
  136. $tmpl->assign("encryptionInitStatus", $encryptionInitStatus);
  137. $tmpl->assign('disableSharing', false);
  138. $tmpl->assign('ajaxLoad', $ajaxLoad);
  139. $tmpl->assign('emptyContent', $emptyContent);
  140. $tmpl->assign('fileHeader', $fileHeader);
  141. $tmpl->printPage();
  142. }