index.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. use OCA\Files\Appinfo\Application;
  23. // Check if we are a user
  24. OCP\User::checkLoggedIn();
  25. // Load the files we need
  26. OCP\Util::addStyle('files', 'files');
  27. OCP\Util::addStyle('files', 'upload');
  28. OCP\Util::addStyle('files', 'mobile');
  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\Util::addscript('files', 'search');
  38. \OCP\Util::addScript('files', 'favoritesfilelist');
  39. \OCP\Util::addScript('files', 'tagsplugin');
  40. \OCP\Util::addScript('files', 'favoritesplugin');
  41. \OC_Util::addVendorScript('core', 'handlebars/handlebars');
  42. OCP\App::setActiveNavigationEntry('files_index');
  43. $l = \OC::$server->getL10N('files');
  44. $isIE8 = false;
  45. preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
  46. if (count($matches) > 0 && $matches[1] <= 9) {
  47. $isIE8 = true;
  48. }
  49. // if IE8 and "?dir=path&view=someview" was specified, reformat the URL to use a hash like "#?dir=path&view=someview"
  50. if ($isIE8 && (isset($_GET['dir']) || isset($_GET['view']))) {
  51. $hash = '#?';
  52. $dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
  53. $view = isset($_GET['view']) ? $_GET['view'] : 'files';
  54. $hash = '#?dir=' . \OCP\Util::encodePath($dir);
  55. if ($view !== 'files') {
  56. $hash .= '&view=' . urlencode($view);
  57. }
  58. header('Location: ' . OCP\Util::linkTo('files', 'index.php') . $hash);
  59. exit();
  60. }
  61. $user = OC_User::getUser();
  62. $config = \OC::$server->getConfig();
  63. // mostly for the home storage's free space
  64. $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
  65. $storageInfo=OC_Helper::getStorageInfo('/', $dirInfo);
  66. // if the encryption app is disabled, than everything is fine (INIT_SUCCESSFUL status code)
  67. $encryptionInitStatus = 2;
  68. if (OC_App::isEnabled('files_encryption')) {
  69. $session = new \OCA\Files_Encryption\Session(new \OC\Files\View('/'));
  70. $encryptionInitStatus = $session->getInitialized();
  71. }
  72. $nav = new OCP\Template('files', 'appnavigation', '');
  73. function sortNavigationItems($item1, $item2) {
  74. return $item1['order'] - $item2['order'];
  75. }
  76. \OCA\Files\App::getNavigationManager()->add(
  77. array(
  78. 'id' => 'favorites',
  79. 'appname' => 'files',
  80. 'script' => 'simplelist.php',
  81. 'order' => 5,
  82. 'name' => $l->t('Favorites')
  83. )
  84. );
  85. $navItems = \OCA\Files\App::getNavigationManager()->getAll();
  86. usort($navItems, 'sortNavigationItems');
  87. $nav->assign('navigationItems', $navItems);
  88. $contentItems = array();
  89. function renderScript($appName, $scriptName) {
  90. $content = '';
  91. $appPath = OC_App::getAppPath($appName);
  92. $scriptPath = $appPath . '/' . $scriptName;
  93. if (file_exists($scriptPath)) {
  94. // TODO: sanitize path / script name ?
  95. ob_start();
  96. include $scriptPath;
  97. $content = ob_get_contents();
  98. @ob_end_clean();
  99. }
  100. return $content;
  101. }
  102. // render the container content for every navigation item
  103. foreach ($navItems as $item) {
  104. $content = '';
  105. if (isset($item['script'])) {
  106. $content = renderScript($item['appname'], $item['script']);
  107. }
  108. $contentItem = array();
  109. $contentItem['id'] = $item['id'];
  110. $contentItem['content'] = $content;
  111. $contentItems[] = $contentItem;
  112. }
  113. OCP\Util::addscript('files', 'fileactions');
  114. OCP\Util::addscript('files', 'files');
  115. OCP\Util::addscript('files', 'navigation');
  116. OCP\Util::addscript('files', 'keyboardshortcuts');
  117. $tmpl = new OCP\Template('files', 'index', 'user');
  118. $tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']);
  119. $tmpl->assign('isPublic', false);
  120. $tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles());
  121. $tmpl->assign("mailNotificationEnabled", $config->getAppValue('core', 'shareapi_allow_mail_notification', 'no'));
  122. $tmpl->assign("mailPublicNotificationEnabled", $config->getAppValue('core', 'shareapi_allow_public_notification', 'no'));
  123. $tmpl->assign("allowShareWithLink", $config->getAppValue('core', 'shareapi_allow_links', 'yes'));
  124. $tmpl->assign("encryptionInitStatus", $encryptionInitStatus);
  125. $tmpl->assign('appNavigation', $nav);
  126. $tmpl->assign('appContents', $contentItems);
  127. $tmpl->printPage();