PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 2.3.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v2.3.5
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / admin / reports / class-betterdocs-email-template.php

class-betterdocs-email-template.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 2.3.5, at admin/reports/class-betterdocs-email-template.php

464 lines 23.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // namespace BetterDocs\BetterDocs_Email_Template;
3 trait BetterDocs_Email_Template {
4
5 /**
6 * Set Email Subject
7 * By Default, subject will be "Weekly Reporting for NotificationX"
8 * Admin can set Custom Subject from NotificationX Advanced Settings Panel
9 * @return subject||String
10 */
11 public function email_subject() {
12 $subject = wp_sprintf( '%s %s %s', __( 'Your Documentation Performance of', 'betterdocs' ), get_bloginfo( 'name' ), __( 'Website', 'betterdocs' ) );
13 return apply_filters( 'betterdocs_reporting_email_subject' , $subject);
14 }
15
16 public function header(){
17 $output = <<<BDTEMHEADER
18 <!DOCTYPE html>
19 <html lang="en">
20 <head>
21 <meta charset="UTF-8">
22 <meta name="viewport" content="width=device-width, initial-scale=1.0">
23 <title>BetterDocs Email Template</title>
24 <link href="https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap" rel="stylesheet">
25 <style type="text/css">
26 .betterdocs-email-body, .betterdocs-wrapper-body {
27 font-size: 14px;
28 font-family: 'Roboto', sans-serif;
29 }
30 .betterdocs-box-analytics-parent {
31 padding: 0px 25px;
32 }
33 .betterdocs-table-heading {
34 background-color: rgb(229, 236, 242);
35 }
36 .betterdocs-table-heading th:first-child {
37 width: 60%;
38 }
39 </style>
40 </head>
41 <body class="betterdocs-wrapper-body" style="background-color: #fff; margin: 0; padding: 0; font-family: 'Roboto';">
42 <table class="betterdocs-email-wrapper" cellpadding="50" cellspacing="0" border="0" width="100%" align="center" bgcolor="#fff">
43 <tbody>
44 <tr>
45 <td align="center" style="padding-top:0px;padding-bottom:20px;">
46 <table class="betterdocs-email-body" cellpadding="35" cellspacing="0" border="0" width="700" align="center" bgcolor="#FFF">
47 <tbody>
48 BDTEMHEADER;
49 return $output;
50 }
51
52 public function footer() {
53 $output = <<<BDTEMFOOTER
54 </tbody>
55 </table> <!-- /.betterdocs-email-body -->
56 </td>
57 </tr>
58 </td> <!-- td table body wrapper end -->
59 </tr> <!-- tr table body wrapper end -->
60 </tbody> <!-- tbody table body wrapper end -->
61 </table> <!-- table table body wrapper end -->
62 </tbody>
63 </table>
64 </body>
65 </html>
66 BDTEMFOOTER;
67 return $output;
68 }
69
70 public function body_header( $args = array(), $frequency = 'betterdocs_weekly' ){
71 $args = current( $args );
72 $from_date = isset( $args['from_date'] ) ? date( 'M j, Y', strtotime( $args['from_date'] ) ) : '';
73 $to_date = isset( $args['to_date'] ) ? date( 'M j, Y', strtotime( $args['to_date'] ) ) : '';
74
75 if ( empty( $from_date ) || empty( $to_date ) ) {
76 return '';
77 }
78
79 $days = $this->frequency($frequency);
80
81 if( $frequency !== 'betterdocs_daily' ) {
82 $to_date = "- " . $to_date;
83 } else {
84 $to_date = '';
85 }
86 $bloginfo = get_bloginfo();
87 $subject = $this->email_subject();
88
89 $output = <<<BDBODYHEADER
90 <tr style="background: #26d67d">
91 <td style="padding: 20px 40px">
92 <table style="width: 100%; border-spacing: 0;">
93 <tr>
94 <td>
95 <img src="https://betterdocs.co/wp-content/uploads/2022/12/BetterDocs-logo-white.png" style="max-width: 100%; height: 35px" alt="logo" />
96 </td>
97 <td align="right">
98 <span style="font-size: 12px; line-height: 1em; text-align: right; color: #fff; flex-direction: column; column-gap: 5px;">
99 <span style="display:block; margin-bottom: 5px; font-weight: 600; font-size: 18px;">Last $days</span>
100 <span>$from_date $to_date</span>
101 </span>
102 </td>
103 </tr>
104 </table>
105 </td>
106 </tr>
107 <tr style="background: #f7f9fb"> <!-- tr table body wrapper start -->
108 <td style="padding: 50px">
109 <table cellpadding="0" cellspacing="0" border="0" align="center">
110 <tbody>
111 <tr>
112 <td style="text-align: center; font-size: 20px; font-weight: bold; padding-bottom: 40px;">
113 $subject
114 </td>
115 </tr>
116 BDBODYHEADER;
117
118 return $output;
119 }
120
121 public function body( $args = array(), $frequency = 'betterdocs_weekly' ){
122 if( empty( $args ) ) {
123 return '';
124 }
125
126 $body_header = $this->body_header( $args, $frequency );
127
128 $analytics = $this->analytics_overview( $args, $frequency );
129 $analytics .= $this->leading_docs( $args['docs']['current_data'], $args['docs']['total_current_reactions'], $frequency );
130 $analytics .= $this->search_keywords( $args['search']['keywords'], $frequency );
131
132 $analytics_tables = apply_filters('betterdocs_analytics_reporting_tables', $analytics, $args, $frequency);
133
134 $pro_msg = $this->pro_message();
135
136 $output = <<<BDTEMBODY
137 $body_header
138 $analytics_tables
139 $pro_msg
140 BDTEMBODY;
141 return $output;
142 }
143
144 public function template_body( $args, $frequency ){
145 $output = $this->header() . $this->body( $args, $frequency ) . $this->footer();
146 return $output;
147 }
148
149 private function percentage ($previous, $current) {
150 if ( $previous == 0 ) {
151 $factor = $current * 100;
152 } else if ( $current == 0 ) {
153 $factor = $previous * 100;
154 } else {
155 $factor = (( $current - $previous ) / $previous) * 100;
156 }
157 return number_format($factor, 2, '.', '');
158 }
159
160 public function leading_docs( $args = array(), $total_reactions = '', $frequency = 'betterdocs_weekly' ) {
161 $output = '';
162 if ( $args ) {
163 $output .= '<tr><td style="text-align: left; font-size: 20px; padding-top: 40px;">Top Performing Docs</td></tr>
164 <tr><td style="padding:0">
165 <table style="width: 100%; border-collapse: separate; border-spacing: 2px; padding-top: 20px;">
166 <tr style="background: #fff;">
167 <th style="text-align: left; font-size: 14px; font-weight: 600; color:#6e6e73; text-transform: capitalize; padding: 8px 15px; width: 48%;">Doc Title</th>
168 <th style="text-align: center; font-size: 14px; font-weight: 600; color:#6e6e73; text-transform: capitalize; padding: 8px 8px;">Total Views</th>
169 <th style="text-align: center; font-size: 14px; font-weight: 600; color:#6e6e73; text-transform: capitalize; padding: 8px 8px;">Unique Views</th>';
170 if ( $total_reactions > 0 ) {
171 $output .= '<th style="text-align: center; font-size: 14px; font-weight: 600; color:#6e6e73; text-transform: capitalize; padding: 8px 15px;">Reactions</th>';
172 }
173 $output .= '</tr>';
174 foreach ($args as $docs) {
175 $output .= '<tr style="background: #fff;">
176 <td style="text-align: left; font-size: 14px; color:#1d1d1f; border-width: 1px; border-style: solid; border: none; padding: 8px 15px;">
177 <a style="text-decoration:none;color:#222;" href="'.get_permalink($docs->ID).'">'. $docs->title .'</a>
178 </td>
179 <td style="text-align: center; font-size: 14px; color:#1d1d1f; border-width: 1px; border-style: solid; border: none; padding: 8px 15px;">
180 '. $docs->total_views .'
181 </td>
182 <td style="text-align: center; font-size: 14px; color:#1d1d1f; border-width: 1px; border-style: solid; border: none; padding: 8px 15px;">
183 '. $docs->total_unique_visit .'
184 </td>';
185 if ( $total_reactions > 0 ) {
186 $output .= '<td style="text-align: center; font-size: 14px; color:#1d1d1f; border-width: 1px; border-style: solid; border: none; padding: 8px 15px;">
187 '. $docs->total_reactions .'
188 </td>';
189 }
190 $output .= '</tr>';
191 }
192 $output .= '</table></td></tr>';
193 }
194 return $output;
195 }
196
197 public function search_keywords( $args = array(), $frequency = 'betterdocs_weekly' ) {
198 $output = '';
199 if ( $args ) {
200 $output .= '<tr><td style="text-align: left; font-size: 20px; padding-top: 40px;">Most Searched Keywords</td></tr>
201 <tr><td><table style="width: 100%; border-collapse: separate; border-spacing: 2px; padding-top: 20px;">
202 <tr style="background: #fff;">
203 <th style="text-align: left; font-size: 14px; font-weight: 600; color:#6e6e73; text-transform: capitalize; padding: 8px 15px; width: 50%;">Search Keyword</th>
204 <th style="text-align: center; font-size: 14px; font-weight: 600; color:#6e6e73; text-transform: capitalize; padding: 8px 15px">Total Search</th>
205 <th style="text-align: center; font-size: 14px; font-weight: 600; color:#6e6e73; text-transform: capitalize; padding: 8px 15px">Result Found</th>
206 </tr>';
207
208 foreach ( $args as $keyword ) {
209 if ( $keyword->count > 0 ) {
210 $found_icon = '<img style="width: 14px;" src="https://betterdocs.co/wp-content/uploads/2022/12/tik.png" alt="" />';
211 } else {
212 $found_icon = '<img style="width: 14px;" src="https://betterdocs.co/wp-content/uploads/2022/12/nontik.png" alt="" />';
213 }
214
215 $output .= '<tr style="background: #fff;">
216 <td style="text-align: left; font-size: 14px; color:#1d1d1f; border-width: 1px; border-style: solid; border: none; padding: 8px 15px;">'. $keyword->keyword .'</td>
217 <td style="text-align: center; font-size: 14px; color:#1d1d1f; border-width: 1px; border-style: solid; border: none; padding: 8px 15px;">'. $keyword->total_search .'</td>
218 <td style="text-align: center; font-size: 14px; color:#1d1d1f; border-width: 1px; border-style: solid; border: none; padding: 8px 15px;">'. $found_icon .'</td>
219 </tr>';
220 }
221 $output .= '</table></td></tr>';
222 }
223 return $output;
224 }
225
226 public function frequency( $frequency = 'betterdocs_weekly' ) {
227
228 switch( $frequency ) {
229 case 'betterdocs_weekly' :
230 $days_ago = '7 days';
231 break;
232 case 'betterdocs_daily' :
233 $days_ago = '1 day';
234 break;
235 case 'betterdocs_monthly' :
236 $initial_timestamp = strtotime('first day of last month', current_time('timestamp'));
237 $days_in_last_month = cal_days_in_month(CAL_GREGORIAN, date( 'm', $initial_timestamp ), date( 'Y', $initial_timestamp ));
238 $days_ago = $days_in_last_month . ' days';
239 break;
240 }
241
242 return $days_ago;
243 }
244
245 protected function analytics_overview( $args = array(), $frequency = 'betterdocs_weekly' ){
246 if( empty( $args ) ) {
247 return false;
248 }
249
250 $up_arrow = $view_arrow = $search_arrow = $reactions_arrow = $docs_arrow = '<img src="https://betterdocs.co/wp-content/uploads/2022/12/polygon-up.png" alt="" />';
251 $down_arrow = '<img src="https://betterdocs.co/wp-content/uploads/2022/12/polygon-down.png" alt="" />';
252 $neutral_arrow = '';
253
254 $views = (isset($args['views']['current_data'][0]->views)) ? number_format( $args['views']['current_data'][0]->views ) : 0;
255 $prev_views = (isset($args['views']['previous_data'][0]->views)) ? number_format( $args['views']['previous_data'][0]->views ) : 0;
256 $percentage_views = $this->percentage( $prev_views, $views );
257
258 $view_color = $search_color = $reactions_color = $docs_color = '#34cf8a';
259 if ( $percentage_views == '0.00' ) {
260 $view_color = '#f7d070';
261 $view_arrow = $neutral_arrow;
262 } else if ( $views < $prev_views ) {
263 $view_color = '#ff616c';
264 $view_arrow = $down_arrow;
265 }
266
267 $reactions = (isset($args['views']['current_data'][0]->reactions)) ? number_format( $args['views']['current_data'][0]->reactions ) : 0;
268 $prev_reactions = (isset($args['views']['previous_data'][0]->reactions)) ? number_format( $args['views']['previous_data'][0]->reactions ) : 0;
269 $percentage_reactions = $this->percentage( $prev_reactions, $reactions );
270
271 if ( $percentage_reactions == '0.00' ) {
272 $reactions_color = '#f7d070';
273 $reactions_arrow = $neutral_arrow;
274 } else if ( $reactions < $prev_reactions ) {
275 $reactions_color = '#ff616c';
276 $reactions_arrow = $down_arrow;
277 }
278
279 $total_search = (isset($args['search']['current_data'][0]->search_count)) ? number_format( $args['search']['current_data'][0]->search_count ) : 0;
280 $prev_total_search = (isset($args['search']['previous_data'][0]->search_count)) ? number_format( $args['search']['previous_data'][0]->search_count ) : 0;
281 $percentage_total_search = $this->percentage( $prev_total_search, $total_search );
282
283 if ( $percentage_total_search == '0.00' ) {
284 $search_color = '#f7d070';
285 $search_arrow = $neutral_arrow;
286 } else if ( $total_search < $prev_total_search ) {
287 $search_color = '#ff616c';
288 $search_arrow = $down_arrow;
289 }
290
291 $total_docs = (isset($args['new_docs']['current_data'])) ? number_format( $args['new_docs']['current_data'] ) : 0;
292 $prev_total_docs = (isset($args['new_docs']['previous_data'])) ? number_format( $args['new_docs']['previous_data'] ) : 0;
293 $percentage_total_docs = $this->percentage( $prev_total_docs, $total_docs );
294
295 if ( $percentage_total_docs == '0.00' ) {
296 $docs_color = '#f7d070';
297 $docs_arrow = $neutral_arrow;
298 } else if ( $total_docs < $prev_total_docs ) {
299 $docs_color = '#ff616c';
300 $docs_arrow = $down_arrow;
301 }
302
303 $days_ago = esc_html( $this->frequency( $frequency ) );
304 $view_color = esc_attr( $view_color );
305 $reactions_color = esc_attr( $reactions_color );
306 $search_color = esc_attr( $search_color );
307
308 $output = <<<BDBOXTEM
309 <tr>
310 <td>
311 <table style="width: 100%; border-spacing: 0;">
312 <tr>
313 <td>
314 <span style="display: flex; align-items: center; background: #fff; margin-right: 7px; height: 100%; padding: 20px;">
315 <span>
316 <img src="https://betterdocs.co/wp-content/uploads/2022/12/eye-solid.png" style="max-width: 100%; width: 45px; height: auto; margin-right: 15px;" alt="eye_logo">
317 </span>
318 <span style="margin-top: 5px;">
319 <h3 style="font-size: 12px; line-height: 1em; color: #6e6e73; font-weight: 600; text-transform: uppercase; padding-bottom: 5px; margin: 0;">Total Views</h3>
320 <h2
321 style="font-size: 22px; line-height: 1em; font-weight: 700; color: #1d1d1f; margin: 0;">$views
322 $view_arrow<span style="font-size: 14px; line-height: 1.1em; font-weight: 600; color: $view_color; margin-left: 5px;">$percentage_views%</span>
323 </h2>
324 </span>
325 </span>
326 </td>
327 <td>
328 <span style="display: flex; align-items: center; background: #fff; margin-left: 7px; height: 100%; padding: 20px;">
329 <span>
330 <img src="https://betterdocs.co/wp-content/uploads/2022/12/search.png" style="max-width: 100%; width: 45px; height: auto; margin-right: 15px;" alt="eye_logo">
331 </span>
332 <span style="margin-top: 5px;">
333 <h3 style="font-size: 12px; line-height: 1em; color: #6e6e73; font-weight: 600; text-transform: uppercase; padding-bottom: 5px; margin: 0;">Total Searches</h3>
334 <h2
335 style="font-size: 22px; line-height: 1em; font-weight: 700; color: #1d1d1f; margin: 0;">$total_search
336 $search_arrow<span style="font-size: 14px; line-height: 1.1em; font-weight: 600; color: $search_color; margin-left: 5px;">$percentage_total_search%</span>
337 </h2>
338 </span>
339
340 </span>
341 </td>
342 </tr>
343 <tr>
344 <td style="padding-top: 15px;">
345 <span style="display: flex; align-items: center; background: #fff; margin-right: 7px; height: 100%; padding: 20px;">
346 <span>
347 <img src="https://betterdocs.co/wp-content/uploads/2022/12/search.png" style="max-width: 100%; width: 45px; height: auto; margin-right: 15px;" alt="eye_logo">
348 </span>
349 <span style="margin-top: 5px;">
350 <h3 style="font-size: 12px; line-height: 1em; color: #6e6e73; font-weight: 600; text-transform: uppercase; padding-bottom: 5px; margin: 0;">Total Reactions</h3>
351 <h2
352 style="font-size: 22px; line-height: 1em; font-weight: 700; color: #1d1d1f; margin: 0;">$reactions
353 $reactions_arrow<span style="font-size: 14px; line-height: 1.1em; font-weight: 600; color: $reactions_color; margin-left: 5px;">$percentage_reactions%</span>
354 </h2>
355 </span>
356
357 </span>
358 </td>
359 <td style="padding-top: 15px;">
360 <span style="display: flex; align-items: center; background: #fff; margin-left: 7px; height: 100%; padding: 20px;">
361 <span>
362 <img src="https://betterdocs.co/wp-content/uploads/2022/12/file-.png" style="max-width: 100%; width: 45px; height: auto; margin-right: 15px;" alt="eye_logo">
363 </span>
364 <span style="margin-top: 5px;">
365 <h3 style="font-size: 12px; line-height: 1em; color: #6e6e73; font-weight: 600; text-transform: uppercase; padding-bottom: 5px; margin: 0;">Newly Created Docs</h3>
366 <h2
367 style="font-size: 22px; line-height: 1em; font-weight: 700; color: #1d1d1f; margin: 0;">$total_docs
368 $docs_arrow<span style="font-size: 14px; line-height: 1.1em; font-weight: 600; color: $docs_color; margin-left: 5px;">$percentage_total_docs%</span>
369 </h2>
370 </span>
371 </span>
372 </td>
373 </tr>
374 </table>
375 </td>
376 </tr>
377 BDBOXTEM;
378 return $output;
379 }
380
381 public static function pro_message() {
382 $is_pro = defined( 'BETTERDOCS_PRO_VERSION' );
383 $graph = 'https://betterdocs.co/wp-content/uploads/2022/11/Analytics.gif';
384 $admin_analytics_url = admin_url( 'admin.php?page=betterdocs-analytics' );
385 if( $is_pro ) {
386 $output = <<<BDPROMSG
387 <tr>
388 <td style="padding-top: 40px;" align="center">
389 <a style="display:inline-block; text-decoration: none; font-size: 12px; font-weight: 600; color: #fff; padding: 16px 22px; border: none; background: #26d67d; border-radius: 10px; cursor: pointer; display: inline-block; letter-spacing: 1px;" href="$admin_analytics_url" target="_blank">View Analytics</a>
390 </td>
391 </tr>
392 <tr>
393 <td style="padding-top: 20px;">
394 <table style="border-spacing: 0;">
395 <tr>
396 <td style="display: flex;">
397 <span style="margin-right: 10px; margin-top: 5px;">📚</span>
398 <p style="text-align: justify; font-size: 14px; line-height: 1.7em; font-weight: 400; margin: 0;"> Want to know what more you can do with BetterDocs? Check out these tutorials:
399 <a href="https://betterdocs.co/blog/improved-betterdocs-analytics/" style="font-weight: 500; color: #1d1d1f; font-style: italic;">Complete Guide To BetterDocs Analytics,</a>
400 <a href="https://betterdocs.co/blog/key-customer-service-metrics/" style="font-weight: 500; color: #1d1d1f; font-style: italic;">Key Customer Service Metrics To Measure Performance</a> &
401 <a href="https://betterdocs.co/blog/internal-documentation-wordpress/" style="font-weight: 500; color: #1d1d1f; font-style: italic;">How To Use BetterDocs Internal Knowledge Base.</a>
402 </p>
403 </td>
404 </tr>
405 </table>
406 </td>
407 </tr>
408 BDPROMSG;
409 } else {
410 $output = <<<BDPROMSG
411 <tr>
412 <td style="padding-top: 40px;">
413 <table style="width: 100%; background: rgba(38, 214, 125, 0.1); padding: 20px 20px 20px 20px; border-radius: 5px; border-spacing: 0;">
414 <tr>
415 <td style="display: flex; gap: 10px;">
416 <span style="margin-top: 4px; margin-right: 3px;">💡</span>
417 <p style="float: right; font-size: 14px; line-height: 1.7em; font-weight: 400; text-align: justify; margin: 0;">
418 This advanced <span style="font-weight: 700; color: #1d1d1f; text-decoration: none;">Email Reporting</span> feature is part of our premium built in Analytics tool available only with BetterDocs PRO, but you
419 are getting it for <span style="font-weight: 700; color: #1d1d1f; text-decoration: none;">FREE!</span>
420 </p>
421 </td>
422 </tr>
423 </table>
424 </td>
425 </tr>
426 <tr>
427 <td style="padding-top: 40px;">
428 <table style="width: 100%; background: #fff; padding: 10px; border-spacing: 0;">
429 <tr>
430 <td>
431 <img style="display: block; max-width: 100%;" src="$graph" alt="View Analytics">
432 </td>
433 </tr>
434 </table>
435 </td>
436 </tr>
437 <tr>
438 <td align="center" style="padding-top: 30px;">
439 <a href="https://betterdocs.co/upgrade" style="text-decoration: none; font-size: 12px; font-weight: 600; color: #fff; padding: 16px 22px; border: none; background: #26d67d; border-radius: 10px; cursor: pointer; display: inline-block; letter-spacing: 1px;">
440 Unlock BetterDocs Analytics <span style="padding-left: 5px;">🔐</span>
441 </a>
442 </td>
443 </tr>
444 <tr>
445 <td style="padding-top: 20px;">
446 <table style="border-spacing: 0;">
447 <tr>
448 <td style="display: flex;">
449 <span style="margin-right: 10px; margin-top: 5px;">📚</span>
450 <p style="text-align: justify; font-size: 14px; line-height: 1.7em; font-weight: 400; margin: 0;"> Want to know what more you can do with BetterDocs? Check out these tutorials:
451 <a href="https://betterdocs.co/blog/improved-betterdocs-analytics/" style="font-weight: 500; color: #1d1d1f; font-style: italic;">Complete Guide To BetterDocs Analytics,</a>
452 <a href="https://betterdocs.co/blog/key-customer-service-metrics/" style="font-weight: 500; color: #1d1d1f; font-style: italic;">Key Customer Service Metrics To Measure Performance</a> &
453 <a href="https://betterdocs.co/blog/internal-documentation-wordpress/" style="font-weight: 500; color: #1d1d1f; font-style: italic;">How To Use BetterDocs Internal Knowledge Base.</a>
454 </p>
455 </td>
456 </tr>
457 </table>
458 </td>
459 </tr>
460 BDPROMSG;
461 }
462 return $output;
463 }
464 }