rockeditChajian.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * 连接官网在线编辑文档
  4. */
  5. class rockeditChajian extends Chajian{
  6. public $officebj_url = '';
  7. private $officebj_urls = '';
  8. protected function initChajian()
  9. {
  10. //$urs = $this->rock->jm->base64decode('aHR0cHM6Ly9kb2NzLnR1emlvYS5jb20vb2ZmaWNlLw::');
  11. $urs = $this->rock->jm->base64decode('aHR0cDovL29mZmljZS5yb2Nrb2EuY29tLw::');
  12. $url = getconfig('officebj_url', $urs);
  13. $this->agentkey = getconfig('officebj_key');
  14. if(substr($url,-1)!='/')$url.='/';
  15. $this->officebj_url = $url;
  16. $this->officebj_urls = $url.'api.php';
  17. }
  18. public function geturlstr($mod, $act, $can=array())
  19. {
  20. $url = $this->officebj_urls;
  21. $url.= '?m='.$mod.'&a='.$act.'';
  22. $url.= '&host='.$this->rock->jm->base64encode(HOST).'&ip='.$this->rock->ip.'&xinhukey='.getconfig('xinhukey').'';
  23. $url.= '&adminid='.$this->adminid.'';
  24. $url.= '&agentkey='.$this->agentkey.'';
  25. foreach($can as $k=>$v)$url.='&'.$k.'='.$v.'';
  26. return $url;
  27. }
  28. /**
  29. * get获取数据
  30. */
  31. public function getdata($mod, $act, $can=array())
  32. {
  33. $url = $this->geturlstr($mod, $act, $can);
  34. $cont = c('curl')->getcurl($url);
  35. if(!isempt($cont) && contain($cont, 'success')){
  36. $data = json_decode($cont, true);
  37. }else{
  38. $data = returnerror('无法访问,'.$cont.'');
  39. }
  40. return $data;
  41. }
  42. /**
  43. * post发送数据
  44. */
  45. public function postdata($mod, $act, $can=array())
  46. {
  47. $url = $this->geturlstr($mod, $act);
  48. $cont = c('curl')->postcurl($url, $can);
  49. if(!isempt($cont) && contain($cont, 'success')){
  50. $data = json_decode($cont, true);
  51. }else{
  52. $data = returnerror('无法访问,'.$cont.'');
  53. }
  54. return $data;
  55. }
  56. public function sendedit($id, $admintoken='', $otype=0)
  57. {
  58. $frs = m('file')->getone($id);
  59. if(!$frs)return returnerror('文件不存在');
  60. $filepath = $frs['filepath'];
  61. $filepathout= arrvalue($frs, 'filepathout');
  62. $onlynum = $frs['onlynum'];
  63. $recedata = '';
  64. if(substr($filepath,0,4)!='http' && !file_exists($filepath)){
  65. if(isempt($filepathout))return returnerror('文件不存在2');
  66. $filepath = $filepathout;
  67. $recedata = $filepath;
  68. }
  69. if(substr($filepath,0,4)=='http' && !$recedata)$recedata = $filepath;
  70. if(isempt($onlynum)){
  71. $onlynum = md5(''.$this->rock->jm->getRandkey().date('YmdHis').'file'.$id.'');
  72. m('file')->update("`onlynum`='$onlynum'", $id);
  73. }
  74. $stype = '0';//0wps,1onlyoffice
  75. $urs = m('admin')->getone($this->adminid);
  76. $barr = $this->getdata('file','change', array(
  77. 'filenum' => $onlynum,
  78. 'optid' => $this->adminid,
  79. 'stype' => $stype,
  80. 'optname' => $this->rock->jm->base64encode($this->adminname),
  81. 'face' => $this->rock->jm->base64encode(m('admin')->getface($urs['face'])),
  82. ));
  83. //$this->rock->debugs($barr,'rockedit');
  84. if(!$barr['success'])return $barr;
  85. $data = $barr['data'];
  86. $type = $data['type'];
  87. $gokey = $data['gokey'];
  88. $gourl = arrvalue($data,'gourl');
  89. if(isempt($gourl))$gourl = $this->officebj_url;
  90. $bsar = $data;
  91. if($type=='0'){
  92. if($recedata=='')$recedata = $this->rock->jm->base64encode(file_get_contents($filepath));
  93. $barr = $this->postdata('file','recedata', array(
  94. 'data' => $recedata,
  95. 'fileid' => $id,
  96. 'filenum' => $onlynum,
  97. 'fileext' => $frs['fileext'],
  98. 'filename' => $frs['filename'],
  99. 'optid' => $frs['optid'],
  100. 'optname' => $frs['optname'],
  101. 'filesize' => $frs['filesize'],
  102. 'filesizecn'=> $frs['filesizecn'],
  103. ));
  104. if(!$barr['success'])return $barr;
  105. $bsar['type'] = '1';
  106. }
  107. if($bsar['type']=='1'){
  108. $url = $gourl.'api.php?m=file&a=goto&filenum='.$onlynum.'&sign='.md5($this->rock->HTTPweb).'';
  109. $url.= '&optid='.$this->adminid.'';
  110. $url.= '&gokey='.$gokey.'';
  111. $url.= '&otype='.$otype.'';
  112. $url.= '&stype='.$stype.'';
  113. if($otype==0){
  114. $callurl = $this->rock->getouturl().'api.php?m=upload&a=upfilevb&fileid='.$id.'&adminid='.$this->adminid.'&token='.$admintoken.'';
  115. $url.='&callurl='.$this->rock->jm->base64encode($callurl).'';
  116. }
  117. $bsar['url'] = 'index.php?m=public&a=goto&url='.urlencode($url).'';
  118. }
  119. return returnsuccess($bsar);
  120. }
  121. /**
  122. * 获取推送配置
  123. */
  124. public function getwsinfo($cans)
  125. {
  126. $barr = $this->getdata('file','wsinfo', $cans);
  127. if(!$barr['success'])return '';
  128. return $barr['data'];
  129. }
  130. /**
  131. * 跳转地址获取
  132. */
  133. public function gotourl($gourl,$gokey,$filenum, $otype, $token, $id)
  134. {
  135. if(!$gourl)$gourl = $this->officebj_url;
  136. $url = $gourl.'api.php?m=file&a=goto&filenum='.$filenum.'&optid='.$this->adminid.'&gokey='.$gokey.'&otype='.$otype.'';
  137. if($otype==0){
  138. $callurl = $this->rock->getouturl().'api.php?m=upload&a=upfilevb&fileid='.$id.'&adminid='.$this->adminid.'&token='.$token.'';
  139. $url.='&callurl='.$this->rock->jm->base64encode($callurl).'';
  140. }
  141. return 'index.php?m=public&a=goto&url='.urlencode($url).'';
  142. }
  143. }
粤ICP备19079148号