blocks[] = [ 'type' => $type, 'content' => $content, 'options' => $options ]; } return $this; } public function addHeadingBlock($type, $content, $options = []) { $this->headingBlocks[] = [ 'type' => $type, 'content' => $content, 'options' => $options ]; return $this; } private function compileBody() { $html = ''; foreach ($this->blocks as $block) { $html .= $this->compileBlock($block); } return $html; } private function complileHeadingBlocks() { $html = ''; foreach ($this->headingBlocks as $block) { $html .= $this->compileBlock($block); } return $html; } public function compileBlock($block) { if ($block['type'] == 'paragraph') { return '

' . $block['content'] . '

'; } if ($block['type'] == 'heading') { return '

' . $block['content'] . '

'; } if ($block['type'] == 'button') { return (string)App::make('view')->make('email.Default._button', [ 'link' => Arr::get($block['options'], 'link'), 'btnText' => $block['content'] ]); } if ($block['type'] == 'boxed_content') { return (string)App::make('view')->make('email.Default._user_box_content', [ 'user_name' => $block['options']['user']->display_name, 'user_avatar' => !(empty($block['options']['user']->xprofile->avatar)) ? $block['options']['user']->xprofile->avatar : $block['options']['user']->photo, 'content' => $block['content'], 'permalink' => $block['options']['permalink'], 'post_content' => $block['options']['post_content'] ]); } if ($block['type'] == 'post_boxed_content') { return (string)App::make('view')->make('email.Default._user_post_content', [ 'user_name' => $block['options']['user']->display_name, 'user_avatar' => !(empty($block['options']['user']->xprofile->avatar)) ? $block['options']['user']->xprofile->avatar : $block['options']['user']->photo, 'content' => $block['content'], 'title' => Arr::get($block['options'], 'title'), 'permalink' => $block['options']['permalink'], 'space_name' => $block['options']['space_name'] ]); } if ($block['type'] == 'html_content') { return (string)$block['content']; } return $block['content']; } public function setLogo($logo) { if ($logo) { $this->logo = $logo; } return $this; } public function setDefaultLogo() { $emailSettings = Utility::getEmailNotificationSettings(); if (!empty($emailSettings['logo'])) { $this->logo = $emailSettings['logo']; } return $this; } public function addFooterLine($type, $line) { $this->footerBlocks[] = [ 'type' => $type, 'content' => $line ]; return $this; } public function setDefaultFooter($withPlaceHolder = true) { $settings = Utility::getEmailNotificationSettings(); $footerTextHtml = Arr::get($settings, 'email_footer_rendered', ''); if (!$footerTextHtml) { if ($settings['disable_powered_by'] == 'no') { $utmParams = ['utm_campaign' => 'email', 'utm_source' => 'footer', 'utm_medium' => 'email']; $poweredBy = 'Powered by FluentCommunity'; $this->addFooterLine('paragraph', $poweredBy); } return $this; } $generalSettings = Helper::generalSettings(); $replaces = [ '{{site_name_with_url}}' => '' . Arr::get($generalSettings, 'site_title') . '', '{{site_name}}' => Arr::get($generalSettings, 'site_title') ]; $footerTextHtml = str_replace(array_keys($replaces), array_values($replaces), $footerTextHtml); // find pattern like this: {{manage_email_notification_url|Manage Your Email Notifications Preference}} $footerTextHtml = preg_replace_callback('/{{(.*?)\|(.*?)}}/', function ($matches) use ($withPlaceHolder) { $match1 = $matches[1]; if ($match1 != 'manage_email_notification_url') { return $matches[0]; } if ($withPlaceHolder) { $url = '##email_notification_url##'; } else { $url = Helper::baseUrl('fcom_route?route=user_notification_settings&auth=yes'); } $text = $matches[2]; return '' . $text . ''; }, $footerTextHtml); $this->addFooterLine('paragraph', $footerTextHtml); if ($settings['disable_powered_by'] == 'no') { $utmParams = ['utm_campaign' => 'email', 'utm_source' => 'footer', 'utm_medium' => 'email']; $poweredBy = '

Powered by FluentCommunity

'; $this->addFooterLine('paragraph', $poweredBy); } return $this; } public function getHtml() { $generalSettings = Helper::generalSettings(); $data = [ 'logo' => [], 'bodyContent' => $this->compileBody() ]; if ($this->logo) { $data['logo'] = [ 'url' => $this->logo, 'alt' => Arr::get($generalSettings, 'site_title') ]; } $footerLines = []; foreach ($this->footerBlocks as $footerBlock) { $footerLines[] = $footerBlock['content']; } $data['footerLines'] = $footerLines; if ($this->headingBlocks) { $data['headingContent'] = $this->complileHeadingBlocks(); } return (string)App::make('view')->make('email.template', $data); } }