control.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * The control file of integration module of XXB.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd., www.zentao.net)
  6. * @license ZOSL (https://zpl.pub/page/zoslv1.html)
  7. * @author Wenrui LI <liwenrui@easycorp.ltd>
  8. * @package integration
  9. * @version $Id$
  10. * @link https://xuanim.com
  11. */
  12. ?>
  13. <?php
  14. class integration extends control
  15. {
  16. /**
  17. * Configure office integrations, currently supports Collabora Office.
  18. *
  19. * @access public
  20. * @return void
  21. */
  22. public function office()
  23. {
  24. if($_POST)
  25. {
  26. $data = fixer::input('post')->get();
  27. if($data->officeEnabled)
  28. {
  29. $collaboraDiscovery = $this->integration->getCollaboraDiscovery($data->collaboraPath);
  30. if(empty($collaboraDiscovery)) $this->send(array('result' => 'fail', 'message' => $this->lang->integration->error->cannotConnectToCollabora));
  31. }
  32. $this->loadModel('setting')->setItems('system.integration.office', $data);
  33. $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('office')));
  34. }
  35. $this->view->title = $this->lang->integration->office;
  36. $this->view->position[] = $this->lang->integration->office;
  37. $this->display();
  38. }
  39. /**
  40. * Generate and redirect to collabora view url of file for user.
  41. *
  42. * @param int $fileID
  43. * @param string $serverName serverName set on XXD server
  44. * @param string $protocol
  45. * @param string $hostname
  46. * @param string $port
  47. * @param string $sessionID user's sessionID on XXD server
  48. * @param string $mode ro | rw, rw enables collabora editing if file is marked as editable
  49. * @param int $messageID required if mode is set to rw
  50. * @param int $userID
  51. * @access public
  52. * @return void redirects user to collabora view url
  53. */
  54. public function wopi($fileID, $serverName, $protocol, $hostname, $port, $sessionID, $mode = 'ro', $messageID = 0, $userID = 0)
  55. {
  56. /* Fix params for older clients. */
  57. if(is_numeric($mode))
  58. {
  59. $userID = $mode;
  60. $mode = 'ro';
  61. }
  62. if(method_exists($this->app, 'loadConfig'))
  63. {
  64. $this->app->loadConfig('file');
  65. if(!zget($this->config->integration->office, 'officeEnabled') && empty($this->config->file->collaboraPath)) die($this->lang->integration->error->officeNotEnabled);
  66. }
  67. elseif(!zget($this->config->integration->office, 'officeEnabled')) die($this->lang->integration->error->officeNotEnabled);
  68. $user = $this->dao->select('account,realname')->from(TABLE_USER)->where('id')->eq($userID)->fetch();
  69. if(!$user) die($this->lang->integration->error->userNotFoundForRequest);
  70. $file = $this->loadModel('file')->getByID($fileID);
  71. if(!$file) die($this->lang->integration->error->fileNotFoundForRequest);
  72. $discovery = isset($this->file->getCollaboraDiscovery) ? $this->file->getCollaboraDiscovery() : $this->integration->getCollaboraDiscovery();
  73. if(!$discovery) die($this->lang->integration->error->cannotConnectToCollabora);
  74. if(!isset($discovery[$file->extension])) die($this->lang->integration->error->filePreviewNotSupported);
  75. $identifiers = $this->integration->getOfficeIdentifiers($file, $serverName, $mode == 'rw', $messageID, $sessionID, $user->realname, $userID);
  76. if(empty($identifiers)) die($this->lang->integration->error->buildIdentifierFail);
  77. $serverAddress = $protocol . '://' . $hostname . ':' . $port;
  78. $xxdWopiUrl = $serverAddress . '/wopi/files/' . $identifiers->file;
  79. $collaboraUrl = $discovery[$file->extension]['urlsrc'] . 'WOPISrc=' . $xxdWopiUrl . '&access_token=' . $identifiers->user;
  80. /* Change theme with css variables */
  81. $cssVariables = '';
  82. $docTheme = $this->config->collaboraThemes[$file->extension];
  83. if(isset($docTheme))
  84. {
  85. foreach($docTheme as $varName => $varValue)
  86. {
  87. $cssVariables .= "--$varName=$varValue;";
  88. }
  89. }
  90. if(!empty($cssVariables)) $collaboraUrl .= '&css_variables=' . urlencode($cssVariables);
  91. header("Location: $collaboraUrl", true, 302);
  92. }
  93. }