index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. exit();
  41. }
  42. $files = array();
  43. foreach( OC_Files::getdirectorycontent( $dir ) as $i ){
  44. $i['date'] = OCP\Util::formatDate($i['mtime'] );
  45. if($i['type']=='file'){
  46. $fileinfo=pathinfo($i['name']);
  47. $i['basename']=$fileinfo['filename'];
  48. if (!empty($fileinfo['extension'])) {
  49. $i['extension']='.' . $fileinfo['extension'];
  50. }
  51. else {
  52. $i['extension']='';
  53. }
  54. }
  55. if($i['directory']=='/'){
  56. $i['directory']='';
  57. }
  58. $files[] = $i;
  59. }
  60. // Make breadcrumb
  61. $breadcrumb = array();
  62. $pathtohere = '';
  63. foreach( explode( '/', $dir ) as $i ){
  64. if( $i != '' ){
  65. $pathtohere .= '/'.str_replace('+','%20', urlencode($i));
  66. $breadcrumb[] = array( 'dir' => $pathtohere, 'name' => $i );
  67. }
  68. }
  69. // make breadcrumb und filelist markup
  70. $list = new OCP\Template( 'files', 'part.list', '' );
  71. $list->assign( 'files', $files, false );
  72. $list->assign( 'baseURL', OCP\Util::linkTo('files', 'index.php').'&dir=', false);
  73. $list->assign( 'downloadURL', OCP\Util::linkTo('files', 'download.php').'?file=', false);
  74. $breadcrumbNav = new OCP\Template( 'files', 'part.breadcrumb', '' );
  75. $breadcrumbNav->assign( 'breadcrumb', $breadcrumb, false );
  76. $breadcrumbNav->assign( 'baseURL', OCP\Util::linkTo('files', 'index.php').'&dir=', false);
  77. $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize'));
  78. $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size'));
  79. $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
  80. $freeSpace=OC_Filesystem::free_space('/');
  81. $freeSpace=max($freeSpace,0);
  82. $maxUploadFilesize = min($maxUploadFilesize ,$freeSpace);
  83. $tmpl = new OCP\Template( 'files', 'index', 'user' );
  84. $tmpl->assign( 'fileList', $list->fetchPage(), false );
  85. $tmpl->assign( 'breadcrumb', $breadcrumbNav->fetchPage(), false );
  86. $tmpl->assign( 'dir', $dir);
  87. $tmpl->assign( 'readonly', !OC_Filesystem::is_writable($dir.'/'));
  88. $tmpl->assign( 'files', $files );
  89. $tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize);
  90. $tmpl->assign( 'uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
  91. $tmpl->assign( 'allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
  92. $tmpl->printPage();