index.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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::addStyle('files', 'mobile');
  28. OCP\Util::addTranslations('files');
  29. OCP\Util::addscript('files', 'app');
  30. OCP\Util::addscript('files', 'file-upload');
  31. OCP\Util::addscript('files', 'jquery.iframe-transport');
  32. OCP\Util::addscript('files', 'jquery.fileupload');
  33. OCP\Util::addscript('files', 'jquery-visibility');
  34. OCP\Util::addscript('files', 'filesummary');
  35. OCP\Util::addscript('files', 'breadcrumb');
  36. OCP\Util::addscript('files', 'filelist');
  37. OCP\App::setActiveNavigationEntry('files_index');
  38. $isIE8 = false;
  39. preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
  40. if (count($matches) > 0 && $matches[1] <= 9) {
  41. $isIE8 = true;
  42. }
  43. // if IE8 and "?dir=path&view=someview" was specified, reformat the URL to use a hash like "#?dir=path&view=someview"
  44. if ($isIE8 && (isset($_GET['dir']) || isset($_GET['view']))) {
  45. $hash = '#?';
  46. $dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
  47. $view = isset($_GET['view']) ? $_GET['view'] : 'files';
  48. $hash = '#?dir=' . \OCP\Util::encodePath($dir);
  49. if ($view !== 'files') {
  50. $hash .= '&view=' . urlencode($view);
  51. }
  52. header('Location: ' . OCP\Util::linkTo('files', 'index.php') . $hash);
  53. exit();
  54. }
  55. $user = OC_User::getUser();
  56. $config = \OC::$server->getConfig();
  57. // mostly for the home storage's free space
  58. $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
  59. $storageInfo=OC_Helper::getStorageInfo('/', $dirInfo);
  60. // if the encryption app is disabled, than everything is fine (INIT_SUCCESSFUL status code)
  61. $encryptionInitStatus = 2;
  62. if (OC_App::isEnabled('files_encryption')) {
  63. $session = new \OCA\Encryption\Session(new \OC\Files\View('/'));
  64. $encryptionInitStatus = $session->getInitialized();
  65. }
  66. $nav = new OCP\Template('files', 'appnavigation', '');
  67. function sortNavigationItems($item1, $item2) {
  68. return $item1['order'] - $item2['order'];
  69. }
  70. $navItems = \OCA\Files\App::getNavigationManager()->getAll();
  71. usort($navItems, 'sortNavigationItems');
  72. $nav->assign('navigationItems', $navItems);
  73. $contentItems = array();
  74. function renderScript($appName, $scriptName) {
  75. $content = '';
  76. $appPath = OC_App::getAppPath($appName);
  77. $scriptPath = $appPath . '/' . $scriptName;
  78. if (file_exists($scriptPath)) {
  79. // TODO: sanitize path / script name ?
  80. ob_start();
  81. include $scriptPath;
  82. $content = ob_get_contents();
  83. @ob_end_clean();
  84. }
  85. return $content;
  86. }
  87. // render the container content for every navigation item
  88. foreach ($navItems as $item) {
  89. $content = '';
  90. if (isset($item['script'])) {
  91. $content = renderScript($item['appname'], $item['script']);
  92. }
  93. $contentItem = array();
  94. $contentItem['id'] = $item['id'];
  95. $contentItem['content'] = $content;
  96. $contentItems[] = $contentItem;
  97. }
  98. OCP\Util::addscript('files', 'fileactions');
  99. OCP\Util::addscript('files', 'files');
  100. OCP\Util::addscript('files', 'navigation');
  101. OCP\Util::addscript('files', 'keyboardshortcuts');
  102. $tmpl = new OCP\Template('files', 'index', 'user');
  103. $tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']);
  104. $tmpl->assign('isPublic', false);
  105. $tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles());
  106. $tmpl->assign("mailNotificationEnabled", $config->getAppValue('core', 'shareapi_allow_mail_notification', 'no'));
  107. $tmpl->assign("allowShareWithLink", $config->getAppValue('core', 'shareapi_allow_links', 'yes'));
  108. $tmpl->assign("encryptionInitStatus", $encryptionInitStatus);
  109. $tmpl->assign('appNavigation', $nav);
  110. $tmpl->assign('appContents', $contentItems);
  111. $tmpl->printPage();