model.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * The model 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 integrationModel extends model
  15. {
  16. /**
  17. * Fetch hosting/discovery urls from Collabora.
  18. *
  19. * @param string $collaboraPath
  20. * @access public
  21. * @return array
  22. */
  23. public function getCollaboraDiscovery($collaboraPath = '')
  24. {
  25. if(empty($collaboraPath) and !empty($this->config->integration->office->collaboraPath)) $collaboraPath = $this->config->integration->office->collaboraPath;
  26. if(empty($collaboraPath) and isset($this->config->file->collaboraPath)) $collaboraPath = $this->config->file->collaboraPath;
  27. if(empty($collaboraPath)) return array();
  28. $ch = curl_init();
  29. curl_setopt($ch, CURLOPT_URL, trim($collaboraPath, '/') . '/hosting/discovery');
  30. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  31. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  32. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  33. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  34. $discovery = curl_exec($ch);
  35. curl_close($ch);
  36. preg_match_all('|<action(.+)/>|', $discovery, $results);
  37. $files = array();
  38. foreach($results[1] as $key => $action)
  39. {
  40. preg_match_all('|ext="([^"]*)"|', $action, $output);
  41. if($output[1]) $extension = $output[1][0];
  42. if(empty($extension)) continue;
  43. preg_match_all('|name="([^"]*)"|', $action, $output);
  44. if($output[1]) $name = $output[1][0];
  45. preg_match_all('|urlsrc="([^"]*)"|', $action, $output);
  46. if($output[1]) $urlsrc = $output[1][0];
  47. $files[$extension]['action'] = $name;
  48. $files[$extension]['urlsrc'] = $urlsrc;
  49. }
  50. return $files;
  51. }
  52. /**
  53. * Get identifiers for WOPI API on XXD.
  54. *
  55. * @param object $file
  56. * @param string $serverName
  57. * @param bool $enableWrite
  58. * @param string $messageID
  59. * @param string $sessionID
  60. * @param string $userDisplayName
  61. * @param int $userID
  62. * @access public
  63. * @return array
  64. */
  65. public function getOfficeIdentifiers($file, $serverName, $enableWrite = false, $messageID = '', $sessionID = '', $userDisplayName = '', $userID = 0)
  66. {
  67. $fileName = "$file->title.$file->extension";
  68. $fileTime = isset($file->addedDate) ? strtotime($file->addedDate) : strtotime($file->createdDate);
  69. $fileOwner = $file->createdBy;
  70. if($enableWrite && !empty($messageID))
  71. {
  72. $enableWrite = false;
  73. $message = $this->loadModel('im')->messageGetList('', array($messageID));
  74. if(!empty($message)) $message = current($message);
  75. $chat = $this->im->chatGetByGid($message->cgid, false, false);
  76. if((empty($chat->archiveDate) || $chat->archiveDate == null) && $message->contentType == 'file')
  77. {
  78. $content = json_decode($message->content);
  79. if($content->id == $file->id && isset($content->editable) && $content->editable) $enableWrite = true;
  80. }
  81. }
  82. $fileMode = $enableWrite ? 'rw' : 'ro';
  83. $fileSession = md5($sessionID.$fileName);
  84. $fileIdentifier = array($fileName, $fileTime, $file->id, $fileOwner, $serverName, $fileMode);
  85. $userIdentifier = array($fileSession, $userDisplayName, $userID);
  86. $identifiers = array('file' => $fileIdentifier, 'user' => $userIdentifier);
  87. return (object)array_map(function($params)
  88. {
  89. foreach($params as $key => $param) $params[$key] = str_replace(array('/', '+'), array('_', '-'), base64_encode($param));
  90. $params = implode(',', $params);
  91. return str_replace(array('/', '+'), array('_', '-'), base64_encode($params));
  92. }, $identifiers);
  93. }
  94. }