BxChatPlusModule.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup RocketChat Rocket.Chat integration module
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxChatPlusModule extends BxDolModule
  12. {
  13. function __construct(&$aModule)
  14. {
  15. parent::__construct($aModule);
  16. }
  17. function actionRedirect ()
  18. {
  19. if (!getParam('bx_chat_plus_url')) {
  20. $this->_oTemplate->displayMsg(_t('_bx_chat_plus_not_configured'));
  21. return;
  22. }
  23. header("Location:" . getParam('bx_chat_plus_url'), true, 302);
  24. }
  25. function actionLogo ()
  26. {
  27. if (!($sLogoUrl = BxTemplFunctions::getInstance()->getMainLogoUrl())) {
  28. header("HTTP/1.0 404 Not Found");
  29. echo '404 Not Found';
  30. return;
  31. }
  32. header("Location:" . $sLogoUrl);
  33. }
  34. function serviceChatBlock ()
  35. {
  36. if (!getParam('bx_chat_plus_url'))
  37. return MsgBox(_t('_bx_chat_plus_not_configured'));
  38. $this->_oTemplate->addCss('main.css');
  39. $s = $this->_oTemplate->parseHtmlByName('chat_block.html', array('chat_url' => getParam('bx_chat_plus_url')));
  40. return array(
  41. 'content' => $s,
  42. 'menu' => array (
  43. array (
  44. 'title' => _t('_bx_chat_plus_open_in_separate_window'),
  45. 'link' => getParam('bx_chat_plus_url'),
  46. 'target' => '_blank',
  47. ),
  48. ),
  49. );
  50. }
  51. function serviceHelpdeskCode ()
  52. {
  53. $sChatUrl = getParam('bx_chat_plus_url');
  54. if (!getParam('bx_chat_plus_helpdesk') || !$sChatUrl)
  55. return '';
  56. if (getParam('bx_chat_plus_helpdesk_guest_only') && isLogged())
  57. return '';
  58. $aUrl = parse_url($sChatUrl);
  59. $sChatUrl = $aUrl['scheme'] . '://' . $aUrl['host'] . ($aUrl['port'] ? ':' . $aUrl['port'] : '');
  60. return <<<EOS
  61. <!-- Start of Helpdesk Livechat Script -->
  62. <script type="text/javascript">
  63. (function(w, d, s, u) {
  64. w.RocketChat = function(c) { w.RocketChat._.push(c) }; w.RocketChat._ = []; w.RocketChat.url = u;
  65. var h = d.getElementsByTagName(s)[0], j = d.createElement(s);
  66. j.async = true; j.src = '{$sChatUrl}/packages/rocketchat_livechat/assets/rocket-livechat.js';
  67. h.parentNode.insertBefore(j, h);
  68. })(window, document, 'script', '{$sChatUrl}/livechat');
  69. </script>
  70. <!-- End of Helpdesk Livechat Script -->
  71. EOS;
  72. }
  73. }
  74. /** @} */