index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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::addscript( 'files', 'jquery.iframe-transport' );
  27. OCP\Util::addscript( 'files', 'jquery.fileupload' );
  28. OCP\Util::addscript( 'files', 'files' );
  29. OCP\Util::addscript( 'files', 'filelist' );
  30. OCP\Util::addscript( 'files', 'fileactions' );
  31. if(!isset($_SESSION['timezone'])){
  32. OCP\Util::addscript( 'files', 'timezone' );
  33. }
  34. OCP\App::setActiveNavigationEntry( 'files_index' );
  35. // Load the files
  36. $dir = isset( $_GET['dir'] ) ? stripslashes($_GET['dir']) : '';
  37. // Redirect if directory does not exist
  38. if(!OC_Filesystem::is_dir($dir.'/')) {
  39. header('Location: '.$_SERVER['PHP_SELF'].'');
  40. }
  41. $files = array();
  42. foreach( OC_Files::getdirectorycontent( $dir ) as $i ){
  43. $i['date'] = OCP\Util::formatDate($i['mtime'] );
  44. if($i['type']=='file'){
  45. $fileinfo=pathinfo($i['name']);
  46. $i['basename']=$fileinfo['filename'];
  47. if (!empty($fileinfo['extension'])) {
  48. $i['extension']='.' . $fileinfo['extension'];
  49. }
  50. else {
  51. $i['extension']='';
  52. }
  53. }
  54. if($i['directory']=='/'){
  55. $i['directory']='';
  56. }
  57. $files[] = $i;
  58. }
  59. // Make breadcrumb
  60. $breadcrumb = array();
  61. $pathtohere = '';
  62. foreach( explode( '/', $dir ) as $i ){
  63. if( $i != '' ){
  64. $pathtohere .= '/'.str_replace('+','%20', urlencode($i));
  65. $breadcrumb[] = array( 'dir' => $pathtohere, 'name' => $i );
  66. }
  67. }
  68. // make breadcrumb und filelist markup
  69. $list = new OCP\Template( 'files', 'part.list', '' );
  70. $list->assign( 'files', $files, false );
  71. $list->assign( 'baseURL', OCP\Util::linkTo('files', 'index.php').'&dir=', false);
  72. $list->assign( 'downloadURL', OCP\Util::linkTo('files', 'download.php').'?file=', false);
  73. $breadcrumbNav = new OCP\Template( 'files', 'part.breadcrumb', '' );
  74. $breadcrumbNav->assign( 'breadcrumb', $breadcrumb, false );
  75. $breadcrumbNav->assign( 'baseURL', OCP\Util::linkTo('files', 'index.php').'&dir=', false);
  76. $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize'));
  77. $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
  78. $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
  79. $freeSpace=OC_Filesystem::free_space('/');
  80. $freeSpace=max($freeSpace,0);
  81. $maxUploadFilesize = min($maxUploadFilesize ,$freeSpace);
  82. $tmpl = new OCP\Template( 'files', 'index', 'user' );
  83. $tmpl->assign( 'fileList', $list->fetchPage(), false );
  84. $tmpl->assign( 'breadcrumb', $breadcrumbNav->fetchPage(), false );
  85. $tmpl->assign( 'dir', $dir);
  86. $tmpl->assign( 'readonly', !OC_Filesystem::is_writable($dir.'/'));
  87. $tmpl->assign( 'files', $files );
  88. $tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
  89. $tmpl->assign( 'uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
  90. $tmpl->assign( 'allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
  91. $tmpl->printPage();
  92. ?>