/** * @param PageDisplayEvent $event */ public function onPageDisplay(PageDisplayEvent $event) { if (!$this->coreParametersHelper->getParameter('notification_enabled')) { return; } $appId = $this->coreParametersHelper->getParameter('notification_app_id'); $safariWebId = $this->coreParametersHelper->getParameter('notification_safari_web_id'); $this->assetsHelper->addScript($this->router->generate('mautic_js', [], UrlGeneratorInterface::ABSOLUTE_URL), 'onPageDisplay_headClose', true, 'mautic_js'); $this->assetsHelper->addScript('https://cdn.onesignal.com/sdks/OneSignalSDK.js', 'onPageDisplay_headClose'); $manifestUrl = $this->router->generate('mautic_onesignal_manifest'); $this->assetsHelper->addCustomDeclaration('<link rel="manifest" href="' . $manifestUrl . '" />', 'onPageDisplay_headClose'); $leadAssociationUrl = $this->router->generate('mautic_subscribe_notification', [], UrlGeneratorInterface::ABSOLUTE_URL); $oneSignalInit = <<<JS var OneSignal = OneSignal || []; OneSignal.push(["init", { appId: "{$appId}", safari_web_id: "{$safariWebId}", autoRegister: true, notifyButton: { enable: false // Set to false to hide } }]); var postUserIdToMautic = function(userId) { var xhr = new XMLHttpRequest(); xhr.open('post', '{$leadAssociationUrl}', true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.send('osid=' + userId); }; OneSignal.getUserId(function(userId) { if (! userId) { OneSignal.on('subscriptionChange', function(isSubscribed) { if (isSubscribed) { OneSignal.getUserId(function(newUserId) { postUserIdToMautic(newUserId); }); } }); } else { postUserIdToMautic(userId); } }); // Just to be sure we've grabbed the ID window.onbeforeunload = function() { OneSignal.getUserId(function(userId) { if (userId) { postUserIdToMautic(userId); } }); }; JS; $this->assetsHelper->addScriptDeclaration($oneSignalInit, 'onPageDisplay_headClose'); }
/** * Add mauticForms in js script tag for Froala. * * @param FilterControllerEvent $event */ public function onKernelRequestAddGlobalJS(FilterControllerEvent $event) { if (defined('MAUTIC_INSTALLER') || $this->userHelper->getUser()->isGuest || !$event->isMasterRequest()) { return; } $list = $this->em->getRepository('MauticFormBundle:Form')->getSimpleList(); $mauticForms = json_encode($list, JSON_FORCE_OBJECT | JSON_PRETTY_PRINT); $this->assetsHelper->addScriptDeclaration("var mauticForms = {$mauticForms};"); }