publicAction.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. class publicClassAction extends ActionNot{
  3. public function initAction()
  4. {
  5. $this->mweblogin(0, false);
  6. $this->officedocx = ',doc,docx,xls,xlsx,ppt,pptx,';
  7. }
  8. //文档预览的
  9. public function fileviewerAction()
  10. {
  11. $id = (int)$this->get('id','0');
  12. $fobj = m('file');
  13. $frs= $fobj->getone($id);
  14. if(!$frs)exit('文件的记录不存在了1');
  15. $type = $frs['fileext'];
  16. $filepath = $frs['filepath'];
  17. $filepathout= arrvalue($frs, 'filepathout');
  18. if(substr($filepath, 0,4)!='http' && isempt($filepathout) && !file_exists($filepath))exit('文件不存在了2');
  19. $types = ','.$type.',';
  20. if(contain($this->officedocx, $types)){
  21. $filepath = $frs['pdfpath'];
  22. if(isempt($filepath)){
  23. $this->topdfshow($frs, 1);
  24. return;
  25. }
  26. if(!file_exists($filepath)){
  27. $this->topdfshow($frs, 1);
  28. return;
  29. }else{
  30. $exta = substr($filepath, -4);
  31. if($exta=='html')$this->rock->location($filepath);
  32. }
  33. }else if($type=='mp4'){
  34. $this->displayfile = ''.P.'/public/fileopen_mp4.html';
  35. }else if($fobj->isyulan($type)){
  36. $content = '';
  37. if(file_exists($filepath)){
  38. $content = file_get_contents($filepath);
  39. if(substr($filepath,-6)=='uptemp')$content = base64_decode($content);
  40. $bm = c('check')->getencode($content);
  41. if(!contain($bm, 'utf')){
  42. $content = @iconv($bm,'utf-8', $content);
  43. }
  44. }else{
  45. if(!isempt($filepathout)){
  46. return $this->getdstr($frs);
  47. }
  48. }
  49. $this->smartydata['content'] = $content;
  50. $this->smartydata['fileext'] = $type;
  51. $this->smartydata['filesizecn'] = $frs['filesizecn'];
  52. $this->displayfile = ''.P.'/public/fileopen.html';//直接打开文件
  53. }else if($type=='pdf'){
  54. if(!isempt($filepathout) && !file_exists($filepath)){
  55. return $this->getdstr($frs);
  56. }
  57. }else{
  58. $this->topdfshow($frs,0);
  59. return;
  60. }
  61. $str = 'mode/pdfjs/web/viewer.css';
  62. if(!file_exists($str))exit('未安装预览pdf插件,不能预览该文件,可到信呼官网下查看安装方法,<a target="_blank" href="'.URLY.'view_topdf.html">查看帮助?</a>。');
  63. $this->smartydata['filepath'] = $this->jm->base64encode($filepath);
  64. $this->smartydata['filepaths']= $filepath;
  65. $this->smartydata['filename'] = $frs['filename'];
  66. $fobj->addlogs($id,0);//记录预览记录
  67. }
  68. private function getdstr($frs)
  69. {
  70. $fenz = (int)(floatval($frs['filesize'])/(1024*150));
  71. if($fenz<5)$fenz = 5;
  72. c('rockqueue')->senddown($frs['id']);
  73. return '<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0"><img src="images/mloading.gif" align="absmiddle"> '.$frs['filename'].'('.$frs['filesizecn'].')等待从远程文件下载(<span id="mia0shu">'.$fenz.'</span>)...<script>zmian='.$fenz.';function yunshi(){zmian--;if(zmian==0){location.reload();return;};document.getElementById(\'mia0shu\').innerHTML=zmian};setInterval(yunshi,1000);</script>';
  74. }
  75. private function topdfshow($frs, $lx=0)
  76. {
  77. $officeyl = getconfig('officeyl','0');
  78. if($lx==1){
  79. if($officeyl=='2' || $officeyl=='3'){//用微软文档服务
  80. $filepath = $frs['filepath'];
  81. if(substr($filepath, 0,4)!='http'){
  82. $filepath = ''.getconfig('outurl',URL).''.$filepath.'';
  83. }
  84. $filepathout= arrvalue($frs, 'filepathout');
  85. if(!isempt($filepathout))$filepath = $filepathout;
  86. $url = 'https://view.officeapps.live.com/op/view.aspx?src='.urlencode($filepath).'';
  87. //if($officeyl=='3')$url = 'https://docview.mingdao.com/op/view.aspx?src='.urlencode($filepath).'';
  88. $this->rock->location($url);
  89. return;
  90. }
  91. if($officeyl=='5'){
  92. $url = 'index.php?a=fileedit&m=public&id='.$frs['id'].'&otype=1';
  93. $this->rock->location($url);
  94. return;
  95. }
  96. }
  97. //转pdf预览
  98. if($officeyl=='0' || $officeyl=='1'){
  99. if(contain($this->officedocx, ','.$frs['fileext'].',')){
  100. $filepathout= arrvalue($frs, 'filepathout');
  101. if(!isempt($filepathout) && !file_exists($frs['filepath'])){
  102. $str = $this->getdstr($frs);
  103. exit($str);
  104. }
  105. }
  106. }
  107. $this->displayfile = ''.P.'/public/filetopdf.html';
  108. $this->smartydata['frs'] = $frs;
  109. $this->smartydata['ismobile'] = $this->rock->ismobile()?'1':'0';
  110. }
  111. /**
  112. * 请求转化
  113. */
  114. public function changetopdfAjax()
  115. {
  116. $id = (int)$this->get('id','0');
  117. return c('xinhuapi')->officesend($id);
  118. }
  119. /**
  120. * 获取状态
  121. */
  122. public function officestatusAjax()
  123. {
  124. $id = (int)$this->get('id','0');
  125. return c('xinhuapi')->officestatus($id);
  126. }
  127. /**
  128. * 获取状态
  129. */
  130. public function officedownAjax()
  131. {
  132. $id = (int)$this->get('id','0');
  133. return c('xinhuapi')->officedown($id);
  134. }
  135. /**
  136. * 第三方编辑调用
  137. */
  138. public function fileeditAction()
  139. {
  140. $id = (int)$this->get('id','0');
  141. $otype = (int)$this->get('otype','0');
  142. $this->smartydata['id'] = $id;
  143. $this->smartydata['otype'] = $otype;
  144. }
  145. }
粤ICP备19079148号