publicAction.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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' || $type=='mp3'){
  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')){
  70. if(contain($this->rock->HTTPweb, 'XINHUOAAPP IOS'))$str='';
  71. $this->displayfile = $str;
  72. }
  73. $fobj->addlogs($id,0);//记录预览记录
  74. }
  75. private function getdstr($frs)
  76. {
  77. $fenz = (int)(floatval($frs['filesize'])/(1024*150));
  78. if($fenz<5)$fenz = 5;
  79. c('rockqueue')->senddown($frs['id']);
  80. 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>';
  81. }
  82. private function topdfshow($frs, $lx=0)
  83. {
  84. $officeyl = getconfig('officeyl','0');
  85. if($lx==1){
  86. if($officeyl=='2' || $officeyl=='3'){//用微软文档服务
  87. $filepath = $frs['filepath'];
  88. if(substr($filepath, 0,4)!='http'){
  89. $filepath = ''.getconfig('outurl',URL).''.$filepath.'';
  90. }
  91. $filepathout= arrvalue($frs, 'filepathout');
  92. if(!isempt($filepathout))$filepath = $filepathout;
  93. $url = 'https://view.officeapps.live.com/op/view.aspx?src='.urlencode($filepath).'';
  94. //if($officeyl=='3')$url = 'https://docview.mingdao.com/op/view.aspx?src='.urlencode($filepath).'';
  95. $this->rock->location($url);
  96. return;
  97. }
  98. if($officeyl=='5'){
  99. $url = 'index.php?a=fileedit&m=public&id='.$frs['id'].'&otype=1';
  100. $this->rock->location($url);
  101. return;
  102. }
  103. }
  104. //转pdf预览
  105. if($officeyl=='0' || $officeyl=='1'){
  106. if(contain($this->officedocx, ','.$frs['fileext'].',')){
  107. $filepathout= arrvalue($frs, 'filepathout');
  108. if(!isempt($filepathout) && !file_exists($frs['filepath'])){
  109. $str = $this->getdstr($frs);
  110. exit($str);
  111. }
  112. }
  113. }
  114. $this->displayfile = ''.P.'/public/filetopdf.html';
  115. $this->smartydata['frs'] = $frs;
  116. $this->smartydata['ismobile'] = $this->rock->ismobile()?'1':'0';
  117. }
  118. /**
  119. * 请求转化
  120. */
  121. public function changetopdfAjax()
  122. {
  123. $id = (int)$this->get('id','0');
  124. return c('xinhuapi')->officesend($id);
  125. }
  126. /**
  127. * 获取状态
  128. */
  129. public function officestatusAjax()
  130. {
  131. $id = (int)$this->get('id','0');
  132. return c('xinhuapi')->officestatus($id);
  133. }
  134. /**
  135. * 获取状态
  136. */
  137. public function officedownAjax()
  138. {
  139. $id = (int)$this->get('id','0');
  140. return c('xinhuapi')->officedown($id);
  141. }
  142. /**
  143. * 第三方编辑调用
  144. */
  145. public function fileeditAction()
  146. {
  147. $id = (int)$this->get('id','0');
  148. $otype = (int)$this->get('otype','0');
  149. $this->smartydata['id'] = $id;
  150. $this->smartydata['otype'] = $otype;
  151. $urlbj = getconfig('officebj_url');
  152. //说明是自己部署编辑平台用旧的页面
  153. if(!isempt($urlbj) && !contain($urlbj,'rockoa.com') && getconfig('systype') != 'dev')
  154. $this->displayfile = ''.P.'/public/tpl_public_fileedit_old.html';
  155. }
  156. /**
  157. * 地址跳转
  158. */
  159. public function gotoAction()
  160. {
  161. $url = $this->get('url');
  162. if(!$url)return 'urlerror';
  163. $url = urldecode($url);
  164. //return $url;
  165. $this->rock->location($url);
  166. }
  167. }
粤ICP备19079148号