publicAction.php 5.1 KB

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