BxChatPlusModule.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. public function serviceGetActions($aWidget)
  35. {
  36. $oInformer = BxDolInformer::getInstance(BxDolStudioTemplate::getInstance());
  37. $oInformer->add('sys-module-discontinued', _t('_adm_txt_modules_discontinued', BX_DOL_URL_STUDIO . 'module.php?name=bx_chat_plus', _t('_bx_chat_plus_adm_stg_cpt_type')), BX_INFORMER_ALERT);
  38. return bx_srv('system', 'get_actions', [$aWidget], 'TemplStudioModules');
  39. }
  40. function serviceChatBlock ()
  41. {
  42. if (!getParam('bx_chat_plus_url'))
  43. return MsgBox(_t('_bx_chat_plus_not_configured'));
  44. $this->_oTemplate->addCss('main.css');
  45. $s = $this->_oTemplate->parseHtmlByName('chat_block.html', array('chat_url' => getParam('bx_chat_plus_url')));
  46. return array(
  47. 'content' => $s,
  48. 'menu' => array (
  49. array (
  50. 'title' => _t('_bx_chat_plus_open_in_separate_window'),
  51. 'link' => getParam('bx_chat_plus_url'),
  52. 'target' => '_blank',
  53. ),
  54. ),
  55. );
  56. }
  57. function serviceHelpdeskCode ()
  58. {
  59. $sChatUrl = getParam('bx_chat_plus_url');
  60. if (!getParam('bx_chat_plus_helpdesk') || !$sChatUrl)
  61. return '';
  62. if (getParam('bx_chat_plus_helpdesk_guest_only') && isLogged())
  63. return '';
  64. $aUrl = parse_url($sChatUrl);
  65. $sChatUrl = $aUrl['scheme'] . '://' . $aUrl['host'] . ($aUrl['port'] ? ':' . $aUrl['port'] : '');
  66. return <<<EOS
  67. <!-- Start of Helpdesk Livechat Script -->
  68. <script language="javascript">
  69. (function(w, d, s, u) {
  70. w.RocketChat = function(c) { w.RocketChat._.push(c) }; w.RocketChat._ = []; w.RocketChat.url = u;
  71. var h = d.getElementsByTagName(s)[0], j = d.createElement(s);
  72. j.async = true; j.src = '{$sChatUrl}/packages/rocketchat_livechat/assets/rocket-livechat.js';
  73. h.parentNode.insertBefore(j, h);
  74. })(window, document, 'script', '{$sChatUrl}/livechat');
  75. </script>
  76. <!-- End of Helpdesk Livechat Script -->
  77. EOS;
  78. }
  79. }
  80. /** @} */