index.xuanxuan.html.hook.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php if(strpos($_SERVER['HTTP_USER_AGENT'], 'xuanxuan') != false): ?>
  2. <?php global $app; $app->setClientTheme('blue'); ?>
  3. <script>
  4. $('html').addClass('xxc-embed');
  5. const appsMenuItems = JSON.parse(`<?php echo json_encode(commonModel::getMainNavList($app->rawModule)); ?>`);
  6. /** Update zentao client app menu */
  7. function updateAppMenu()
  8. {
  9. var menuItems = appsMenuItems.map(function(item)
  10. {
  11. if (item === 'divider') return '-';
  12. var $title = $('<div>' + item.title + '</div>');
  13. return [item.code, ($title.find('.icon').attr('class') || '').replace('icon ', ''),$title.text().trim()];
  14. });
  15. window.open('xxc://extension.zentao-integrated.updateAppMenu/' + encodeURIComponent(JSON.stringify(menuItems)));
  16. }
  17. updateAppMenu();
  18. $(document).on('showapp', function(e, app)
  19. {
  20. window.open('xxc://extension.zentao-integrated.activeAppMenuItem/' + encodeURIComponent(JSON.stringify({id: app.code, openedApps:Object.keys($.apps.openedApps)})));
  21. });
  22. $(document).on('hideapp', function(e, app)
  23. {
  24. window.open('xxc://extension.zentao-integrated.hideAppMenuItem/' + encodeURIComponent(JSON.stringify({id: app.code, openedApps:Object.keys($.apps.openedApps)})));
  25. });
  26. </script>
  27. <?php else: ?>
  28. <?php
  29. global $app;
  30. $im = $app->control->loadModel('im');
  31. $xxdStatus = $im->getXxdStatus();
  32. if(isset($app->config->xuanxuan->turnon) && $app->config->xuanxuan->turnon && $xxdStatus == 'online')
  33. {
  34. $xuanConfig = new stdclass();
  35. $token = $im->userGetAuthToken($app->user->id, 'zentaoweb');
  36. $clientUrl = isset($app->config->webClientUrl) ? $app->config->webClientUrl : 'data/xuanxuan/web/index.html';
  37. $backendUrl = $im->getServer('zentao');
  38. $xuanConfig->clientUrl = $clientUrl;
  39. $xuanConfig->server = ($app->config->xuanxuan->https == 'on' ? 'https' : 'http') . '://' . parse_url($backendUrl, PHP_URL_HOST) . ':' . $app->config->xuanxuan->commonPort;
  40. $xuanConfig->account = $app->user->account;
  41. $xuanConfig->authKey = $token->token;
  42. $xuanConfig->debug = $app->config->debug;
  43. }
  44. ?>
  45. <?php if(isset($xuanConfig)): ?>
  46. <style>
  47. #xx-embed-container {z-index: 1010!important;}
  48. #xx-embed-container .xx-embed-has-animation {transition: min-width .5s ease-out, min-height .5s ease-out, transform, opacity!important;}
  49. #xx-embed-container .xx-embed {width: 330px; height: 100%; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1),0 2px 4px -1px rgba(0,0,0,0.06)!important;}
  50. #xx-embed-container .xx-embed.xx-embed-hidden,
  51. #xx-embed-container .xx-embed.xx-embed-collapsed {width: 330px!important; height: 100%!important; opacity: .7; pointer-events: none; transform: translateY(100%); display: block!important;}
  52. #xx-embed-container .xx-embed.has-chat-view {min-width: 1000px!important;}
  53. #xx-embed-container .xx-embed-body {min-height: initial!important;}
  54. </style>
  55. <?php js::import($app->getWebRoot() . 'data/xuanxuan/sdk/sdk.min.js'); ?>
  56. <script>
  57. /* Toggle xuan client popover */
  58. function toggleXuanClient()
  59. {
  60. if(!window.xuan.shown) window.xuan.show();
  61. else window.xuan.toggleCollapse();
  62. }
  63. /* Handle chat notice change */
  64. function handleXuanNoticeChange(notice)
  65. {
  66. $('#chat-btn .notice-badge').toggleClass('show', !!notice.count).text(notice.count);
  67. }
  68. /* Handle client route change */
  69. function handleXuanRouteChange(route)
  70. {
  71. var hasShowChatView = route.indexOf('#/chats/') === 0 && !!route.split('/')[3];
  72. $('#' + window.xuan.id).toggleClass('has-chat-view', hasShowChatView);
  73. }
  74. window.initXuan = () =>
  75. {
  76. if(window.xuan) return;
  77. const xuanConfig = <?php echo json_encode($xuanConfig); ?>;
  78. if(typeof Xuanxuan === 'undefined')
  79. {
  80. /* Xuan SDK is not loaded at this moment, lets be patient. */
  81. window.xuanInitRetryCount = window.xuanInitRetryCount || 0;
  82. if(window.xuanInitRetryCount++ > 10) return;
  83. return setTimeout(window.initXuan, 500);
  84. }
  85. /* Set client global options*/
  86. Xuanxuan.setGlobalOptions(
  87. {
  88. position: 'right',
  89. width: 280,
  90. preload: true,
  91. showHeader: false,
  92. onNotice: handleXuanNoticeChange,
  93. onRouteChange: handleXuanRouteChange,
  94. lang: '<?php echo $app->getClientLang()?>'
  95. });
  96. /* Create client instance */
  97. window.xuan = new Xuanxuan(xuanConfig);
  98. /* Setup xuan web chat, see zin/wg/chatbtn. */
  99. window.setupXuan();
  100. };
  101. $(() => window.initXuan());
  102. </script>
  103. <?php endif; ?>
  104. <?php endif; ?>