1
0

BxBasePushOneSignal.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * OneSignal integration.
  11. * @see BxDolPush
  12. */
  13. class BxBasePushOneSignal extends BxDolPushOneSignal
  14. {
  15. protected function _getCodePageHeader()
  16. {
  17. if($this->_bCodeAdded || !$this->_sAppId)
  18. return '';
  19. $iProfileId = bx_get_logged_profile_id();
  20. if(empty($iProfileId))
  21. return '';
  22. $aTags = self::getTags($iProfileId);
  23. if(!$aTags)
  24. return '';
  25. $sSubfolder = '/plugins_public/onesignal/';
  26. $aUrl = parse_url(BX_DOL_URL_ROOT);
  27. if(!empty($aUrl['path'])) {
  28. $sPath = trim($aUrl['path'], '/');
  29. if(!empty($sPath))
  30. $sSubfolder = '/' . $sPath . $sSubfolder;
  31. }
  32. $sJsObject = 'oBxDolPushOneSignal';
  33. $this->_oTemplate->addJs([
  34. 'https://cdn.onesignal.com/sdks/OneSignalSDK.js',
  35. 'BxDolPushOneSignal.js',
  36. ]);
  37. $this->_bCodeAdded = true;
  38. return $this->_oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolPushOneSignal(" . json_encode([
  39. 'sObjName' => $sJsObject,
  40. 'sSiteName' => getParam('site_title'),
  41. 'aTags' => $aTags,
  42. 'sAppId' => $this->_sAppId,
  43. 'sShortName' => $this->_sShortName,
  44. 'sSafariWebId' => $this->_sSafariWebId,
  45. 'sSubfolder' => $sSubfolder,
  46. 'sNotificationUrl' => BX_DOL_URL_ROOT,
  47. 'sTxtNotificationRequest' => _t('_sys_push_notification_request', getParam('site_title')),
  48. 'sTxtNotificationRequestYes' => _t('_sys_push_notification_request_yes'),
  49. 'sTxtNotificationRequestNo' => _t('_sys_push_notification_request_no'),
  50. ]) . ");");
  51. }
  52. }
  53. /** @} */