index.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. * @author Frank Karlitschek <frank@owncloud.org>
  5. * @author Jakob Sack <mail@jakobsack.de>
  6. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  7. * @author Joas Schilling <nickvergessen@owncloud.com>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <icewind@owncloud.com>
  11. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  12. * @author Roman Geber <rgeber@owncloudapps.com>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. * @author Vincent Petry <pvince81@owncloud.com>
  15. *
  16. * @copyright Copyright (c) 2015, ownCloud, Inc.
  17. * @license AGPL-3.0
  18. *
  19. * This code is free software: you can redistribute it and/or modify
  20. * it under the terms of the GNU Affero General Public License, version 3,
  21. * as published by the Free Software Foundation.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License, version 3,
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>
  30. *
  31. */
  32. use OCA\Files\Appinfo\Application;
  33. // Check if we are a user
  34. OCP\User::checkLoggedIn();
  35. // Load the files we need
  36. OCP\Util::addStyle('files', 'files');
  37. OCP\Util::addStyle('files', 'upload');
  38. OCP\Util::addStyle('files', 'mobile');
  39. OCP\Util::addscript('files', 'app');
  40. OCP\Util::addscript('files', 'file-upload');
  41. OCP\Util::addscript('files', 'jquery.iframe-transport');
  42. OCP\Util::addscript('files', 'jquery.fileupload');
  43. OCP\Util::addscript('files', 'jquery-visibility');
  44. OCP\Util::addscript('files', 'filesummary');
  45. OCP\Util::addscript('files', 'breadcrumb');
  46. OCP\Util::addscript('files', 'filelist');
  47. OCP\Util::addscript('files', 'search');
  48. \OCP\Util::addScript('files', 'favoritesfilelist');
  49. \OCP\Util::addScript('files', 'tagsplugin');
  50. \OCP\Util::addScript('files', 'favoritesplugin');
  51. \OC_Util::addVendorScript('core', 'handlebars/handlebars');
  52. OCP\App::setActiveNavigationEntry('files_index');
  53. $l = \OC::$server->getL10N('files');
  54. $isIE8 = false;
  55. preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
  56. if (count($matches) > 0 && $matches[1] <= 9) {
  57. $isIE8 = true;
  58. }
  59. // if IE8 and "?dir=path&view=someview" was specified, reformat the URL to use a hash like "#?dir=path&view=someview"
  60. if ($isIE8 && (isset($_GET['dir']) || isset($_GET['view']))) {
  61. $hash = '#?';
  62. $dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
  63. $view = isset($_GET['view']) ? $_GET['view'] : 'files';
  64. $hash = '#?dir=' . \OCP\Util::encodePath($dir);
  65. if ($view !== 'files') {
  66. $hash .= '&view=' . urlencode($view);
  67. }
  68. header('Location: ' . OCP\Util::linkTo('files', 'index.php') . $hash);
  69. exit();
  70. }
  71. $user = OC_User::getUser();
  72. $config = \OC::$server->getConfig();
  73. // mostly for the home storage's free space
  74. $dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
  75. $storageInfo=OC_Helper::getStorageInfo('/', $dirInfo);
  76. $nav = new OCP\Template('files', 'appnavigation', '');
  77. function sortNavigationItems($item1, $item2) {
  78. return $item1['order'] - $item2['order'];
  79. }
  80. \OCA\Files\App::getNavigationManager()->add(
  81. array(
  82. 'id' => 'favorites',
  83. 'appname' => 'files',
  84. 'script' => 'simplelist.php',
  85. 'order' => 5,
  86. 'name' => $l->t('Favorites')
  87. )
  88. );
  89. $navItems = \OCA\Files\App::getNavigationManager()->getAll();
  90. usort($navItems, 'sortNavigationItems');
  91. $nav->assign('navigationItems', $navItems);
  92. $contentItems = array();
  93. function renderScript($appName, $scriptName) {
  94. $content = '';
  95. $appPath = OC_App::getAppPath($appName);
  96. $scriptPath = $appPath . '/' . $scriptName;
  97. if (file_exists($scriptPath)) {
  98. // TODO: sanitize path / script name ?
  99. ob_start();
  100. include $scriptPath;
  101. $content = ob_get_contents();
  102. @ob_end_clean();
  103. }
  104. return $content;
  105. }
  106. // render the container content for every navigation item
  107. foreach ($navItems as $item) {
  108. $content = '';
  109. if (isset($item['script'])) {
  110. $content = renderScript($item['appname'], $item['script']);
  111. }
  112. $contentItem = array();
  113. $contentItem['id'] = $item['id'];
  114. $contentItem['content'] = $content;
  115. $contentItems[] = $contentItem;
  116. }
  117. OCP\Util::addscript('files', 'fileactions');
  118. OCP\Util::addscript('files', 'files');
  119. OCP\Util::addscript('files', 'navigation');
  120. OCP\Util::addscript('files', 'keyboardshortcuts');
  121. $tmpl = new OCP\Template('files', 'index', 'user');
  122. $tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']);
  123. $tmpl->assign('isPublic', false);
  124. $tmpl->assign("mailNotificationEnabled", $config->getAppValue('core', 'shareapi_allow_mail_notification', 'no'));
  125. $tmpl->assign("mailPublicNotificationEnabled", $config->getAppValue('core', 'shareapi_allow_public_notification', 'no'));
  126. $tmpl->assign("allowShareWithLink", $config->getAppValue('core', 'shareapi_allow_links', 'yes'));
  127. $tmpl->assign('appNavigation', $nav);
  128. $tmpl->assign('appContents', $contentItems);
  129. $tmpl->printPage();