download.html.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * The UI file of file module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Wangy Yidong <yidong@easycorp.ltd>
  8. * @package file
  9. * @link https://www.zentao.net
  10. */
  11. namespace zin;
  12. if(!empty($error))
  13. {
  14. div
  15. (
  16. setID('errorMessage'),
  17. $error
  18. );
  19. }
  20. else
  21. {
  22. modalHeader
  23. (
  24. set::title($lang->file->preview),
  25. $fileType == 'txt' ? to::suffix
  26. (
  27. div
  28. (
  29. select(setID('charset'), set::name('charset'), set::items($config->file->charset), set::required(true), set::value($charset), set('onchange', 'setCharset(this)'), setClass('ml-2'))
  30. )
  31. ) : null
  32. );
  33. $fromOld = !empty($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'ajaxIframeModal') !== false;
  34. if($fileType == 'image')
  35. {
  36. $fileContent = div
  37. (
  38. setID('imageFile'),
  39. h::img(set::src($this->createLink('file', 'read', "fileID={$file->id}")), set::style(array('width' => '100%', 'max-height' => !$fromOld ? 'calc(100vh - 180px)' : '100%', 'object-fit' => 'contain')))
  40. );
  41. }
  42. elseif($fileType == 'video')
  43. {
  44. $fileContent = div
  45. (
  46. setID('videoFile'),
  47. h::video(set::src($file->webPath), set::controls(true), set::autoplay(true), set::controlsList('nodownload'), set::onerror('showError()'), set::onloadedmetadata('loadedmetadata()'), set::style(array('width' => '100%', 'max-height' => !$fromOld ? 'calc(100vh - 180px)' : '100%'))),
  48. div
  49. (
  50. setClass('playfailed hidden'),
  51. $lang->file->playFailed
  52. )
  53. );
  54. }
  55. else
  56. {
  57. $fileContent = trim(file_get_contents($file->realPath));
  58. if($charset != $config->charset)
  59. {
  60. $fileContent = helper::convertEncoding($fileContent, $charset . "//IGNORE", $config->charset);
  61. }
  62. else
  63. {
  64. if(extension_loaded('mbstring'))
  65. {
  66. $encoding = mb_detect_encoding($fileContent, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
  67. if($encoding != 'UTF-8') $fileContent = helper::convertEncoding($fileContent, (string)$encoding, $config->charset);
  68. }
  69. else
  70. {
  71. $encoding = 'UTF-8';
  72. if($config->default->lang == 'zh-cn') $encoding = 'GBK';
  73. if($config->default->lang == 'zh-tw') $encoding = 'BIG5';
  74. $fileContent = helper::convertEncoding($fileContent, $encoding, $config->charset);
  75. }
  76. }
  77. $fileContent = div
  78. (
  79. setID('txtFile'),
  80. h::pre(set::style(array('background-color' => 'rgb(var(--color-gray-200-rgb))')), $fileContent)
  81. );
  82. }
  83. div(setClass('panel-form'), set::style(array('margin-left' => 'auto', 'margin-right' => 'auto')), $fileContent);
  84. $isInModal = isInModal();
  85. h::js
  86. (
  87. <<<JAVASCRIPT
  88. window.setCharset = function(obj)
  89. {
  90. let charset = $(obj).val();
  91. let link = $.createLink('file', 'download', 'fileID={$file->id}&mouse=left');
  92. link += link.indexOf('?') >= 0 ? '&' : '?';
  93. link += 'charset=' + charset;
  94. if("{$isInModal}") loadModal(link, $(obj).closest('.modal.show').attr('id'));
  95. else loadPage(link);
  96. };
  97. function showError()
  98. {
  99. $('.playfailed').removeClass('hidden');
  100. }
  101. function loadedmetadata()
  102. {
  103. var videoElem = $('video')[0];
  104. var metaHeight = videoElem.videoHeight;
  105. var parentHeight = window.parent.innerHeight;
  106. var videoMaxHeight = parentHeight - 190;
  107. if(videoMaxHeight < metaHeight)
  108. {
  109. $(videoElem).css('height', videoMaxHeight);
  110. }
  111. }
  112. JAVASCRIPT
  113. );
  114. }
  115. render();