PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.97
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.97
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / app / Services / Libs / EmailComposer.php

EmailComposer.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 1.0.97, at app/Services/Libs/EmailComposer.php

208 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\App\Services\Libs;
4
5 use FluentCommunity\App\App;
6 use FluentCommunity\App\Functions\Utility;
7 use FluentCommunity\App\Services\Helper;
8 use FluentCommunity\Framework\Support\Arr;
9
10 class EmailComposer
11 {
12 private $blocks = [];
13
14 private $headingBlocks = [];
15
16 private $footerBlocks = [];
17
18 private $logo = '';
19
20 public function addBlock($type, $content, $options = [])
21 {
22 if($content) {
23 $this->blocks[] = [
24 'type' => $type,
25 'content' => $content,
26 'options' => $options
27 ];
28 }
29
30 return $this;
31 }
32
33 public function addHeadingBlock($type, $content, $options = [])
34 {
35 $this->headingBlocks[] = [
36 'type' => $type,
37 'content' => $content,
38 'options' => $options
39 ];
40
41 return $this;
42 }
43
44 private function compileBody()
45 {
46 $html = '';
47
48 foreach ($this->blocks as $block) {
49 $html .= $this->compileBlock($block);
50 }
51
52 return $html;
53 }
54
55 private function complileHeadingBlocks()
56 {
57 $html = '';
58
59 foreach ($this->headingBlocks as $block) {
60 $html .= $this->compileBlock($block);
61 }
62
63 return $html;
64 }
65
66 public function compileBlock($block)
67 {
68 if ($block['type'] == 'paragraph') {
69 return '<p style="font-family: Arial, sans-serif; line-height: 1.6; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 10px;">' . $block['content'] . '</p>';
70 }
71
72 if ($block['type'] == 'heading') {
73 return '<h2 style="font-family: Arial, sans-serif; font-size: 20px; font-weight: bold; margin: 0; margin-bottom: 10px;">' . $block['content'] . '</h2>';
74 }
75
76 if ($block['type'] == 'button') {
77 return (string)App::make('view')->make('email.Default._button', [
78 'link' => Arr::get($block['options'], 'link'),
79 'btnText' => $block['content']
80 ]);
81 }
82
83 if ($block['type'] == 'boxed_content') {
84 return (string)App::make('view')->make('email.Default._user_box_content', [
85 'user_name' => $block['options']['user']->display_name,
86 'user_avatar' => $block['options']['user']->photo,
87 'content' => $block['content'],
88 'permalink' => $block['options']['permalink'],
89 'post_content' => $block['options']['post_content']
90 ]);
91 }
92
93 if ($block['type'] == 'post_boxed_content') {
94 return (string)App::make('view')->make('email.Default._user_post_content', [
95 'user_name' => $block['options']['user']->display_name,
96 'user_avatar' => $block['options']['user']->photo,
97 'content' => $block['content'],
98 'title' => Arr::get($block['options'], 'title'),
99 'permalink' => $block['options']['permalink'],
100 'space_name' => $block['options']['space_name']
101 ]);
102 }
103
104 if ($block['type'] == 'html_content') {
105 return $block['content'];
106 }
107
108 return $block['content'];
109 }
110
111 public function setLogo($logo)
112 {
113 $this->logo = $logo;
114 return $this;
115 }
116
117 public function addFooterLine($type, $line)
118 {
119 $this->footerBlocks[] = [
120 'type' => $type,
121 'content' => $line
122 ];
123
124 return $this;
125 }
126
127 public function setDefaultFooter($withPlaceHolder = true)
128 {
129 $settings = Utility::getEmailNotificationSettings();
130 $footerTextHtml = Arr::get($settings, 'email_footer_rendered', '');
131
132 if (!$footerTextHtml) {
133 if ($settings['disable_powered_by'] == 'no') {
134 $poweredBy = '<a href="https://fluentcommunity.com/discount-deal/?utm_campaign=email&utm_source=footer&utm_medium=email" target="_blank" style="font-size: 12px; margin: 10px 0; text-decoration: none;">Powered by FluentCommunity</a>';
135 $this->addFooterLine('paragraph', $poweredBy);
136 }
137 return $this;
138 }
139
140 $generalSettings = Helper::generalSettings();
141
142 $replaces = [
143 '{{site_name_with_url}}' => '<a target="_blank" href="' . Helper::baseUrl('/') . '">' . Arr::get($generalSettings, 'site_title') . '</a>',
144 '{{site_name}}' => Arr::get($generalSettings, 'site_title')
145 ];
146
147 $footerTextHtml = str_replace(array_keys($replaces), array_values($replaces), $footerTextHtml);
148
149 // find pattern like this: {{manage_email_notification_url|Manage Your Email Notifications Preference}}
150 $footerTextHtml = preg_replace_callback('/{{(.*?)\|(.*?)}}/', function ($matches) use ($withPlaceHolder) {
151 $match1 = $matches[1];
152 if ($match1 != 'manage_email_notification_url') {
153 return $matches[0];
154 }
155
156 if ($withPlaceHolder) {
157 $url = '##email_notification_url##';
158 } else {
159 $url = Helper::baseUrl('fcom_route?route=user_notification_settings&auth=yes');
160 }
161
162 $text = $matches[2];
163 return '<a target="_blank" rel="noopenner" href="' . $url . '">' . $text . '</a>';
164 }, $footerTextHtml);
165
166 $this->addFooterLine('paragraph', $footerTextHtml);
167
168 if ($settings['disable_powered_by'] == 'no') {
169 $poweredBy = '<p class="powered_by"><a href="https://fluentcommunity.com/discount-deal/?utm_campaign=email&utm_source=footer&utm_medium=email" target="_blank" style="font-size: 12px; text-decoration: none;">Powered by FluentCommunity</a></p>';
170 $this->addFooterLine('paragraph', $poweredBy);
171 }
172
173 return $this;
174 }
175
176 public function getHtml()
177 {
178 $generalSettings = Helper::generalSettings();
179
180 $data = [
181 'logo' => [],
182 'bodyContent' => $this->compileBody()
183 ];
184
185 if ($this->logo) {
186 $data['logo'] = [
187 'url' => $this->logo,
188 'alt' => Arr::get($generalSettings, 'site_title')
189 ];
190 }
191
192 $footerLines = [];
193 foreach ($this->footerBlocks as $footerBlock) {
194 $footerLines[] = $footerBlock['content'];
195 }
196
197 $data['footerLines'] = $footerLines;
198
199
200 if($this->headingBlocks) {
201 $data['headingContent'] = $this->complileHeadingBlocks();
202 }
203
204 return (string)App::make('view')->make('email.template', $data);
205 }
206
207 }
208