PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.1.6
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.1.6
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-format.php

class-mainwp-format.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.1.6, at class/class-mainwp-format.php

590 lines 24.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Format Utility
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 // Exit if accessed directly.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Class MainWP_Format
17 *
18 * @package MainWP\Dashboard
19 */
20 class MainWP_Format { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
21
22 /**
23 * Method get_class_name()
24 *
25 * Get Class Name.
26 *
27 * @return object
28 */
29 public static function get_class_name() {
30 return __CLASS__;
31 }
32
33 /**
34 * Method get_update_plugins_items().
35 *
36 * Get plugins update.
37 *
38 * @return array $update_items Plugins update items.
39 *
40 * @uses \MainWP\Dashboard\MainWP_Utility::array_merge()
41 */
42 public static function get_update_plugins_items() {
43
44 $pluginsNewUpdate = get_option( 'mainwp_updatescheck_mail_update_plugins_new' );
45 if ( ! is_array( $pluginsNewUpdate ) ) {
46 $pluginsNewUpdate = array();
47 }
48 $pluginsToUpdate = get_option( 'mainwp_updatescheck_mail_update_plugins' );
49 if ( ! is_array( $pluginsToUpdate ) ) {
50 $pluginsToUpdate = array();
51 }
52 $notTrustedPluginsNewUpdate = get_option( 'mainwp_updatescheck_mail_ignore_plugins_new' );
53 if ( ! is_array( $notTrustedPluginsNewUpdate ) ) {
54 $notTrustedPluginsNewUpdate = array();
55 }
56 $notTrustedPluginsToUpdate = get_option( 'mainwp_updatescheck_mail_ignore_plugins' );
57 if ( ! is_array( $notTrustedPluginsToUpdate ) ) {
58 $notTrustedPluginsToUpdate = array();
59 }
60
61 $pluginsNewUpdate = static::remove_duplicate_updates( $pluginsNewUpdate, $pluginsToUpdate );
62 $pluginsToUpdate = static::remove_duplicate_updates( $pluginsToUpdate );
63 $notTrustedPluginsNewUpdate = static::remove_duplicate_updates( $notTrustedPluginsNewUpdate, $notTrustedPluginsToUpdate );
64 $notTrustedPluginsToUpdate = static::remove_duplicate_updates( $notTrustedPluginsToUpdate );
65
66 $update_items = array();
67 $update_items = MainWP_Utility::array_merge( $pluginsNewUpdate, $pluginsToUpdate );
68 $update_items = MainWP_Utility::array_merge( $update_items, $notTrustedPluginsNewUpdate );
69 $update_items = MainWP_Utility::array_merge( $update_items, $notTrustedPluginsToUpdate );
70
71 return $update_items;
72 }
73
74
75 /**
76 * Method remove_duplicate_updates
77 *
78 * @param array $checks checks.
79 * @param array $inputs inputs.
80 * @return mixed
81 */
82 public static function remove_duplicate_updates( $checks, $inputs = array() ) {
83 $tmp = array();
84 $filters = array();
85 $done = false;
86 if ( is_array( $inputs ) ) {
87 foreach ( $inputs as $item ) {
88 if ( isset( $item['slug'] ) && isset( $item['id'] ) && isset( $item['current'] ) && ! isset( $filters[ $item['id'] . '_' . $item['slug'] . '_' . $item['current'] ] ) ) {
89 $filters[ $item['id'] . '_' . $item['slug'] . '_' . $item['current'] ] = 1;
90 $done = true;
91 }
92 }
93 }
94 // check not duplicate item in both arrays, for $checks array.
95 foreach ( $checks as $item ) {
96 if ( isset( $item['slug'] ) && isset( $item['id'] ) && isset( $item['current'] ) && ! isset( $filters[ $item['id'] . '_' . $item['slug'] . '_' . $item['current'] ] ) ) {
97 $filters[ $item['id'] . '_' . $item['slug'] . '_' . $item['current'] ] = 1;
98 $tmp[] = $item;
99 $done = true;
100 }
101 }
102 return $done ? $tmp : $checks; // to prevent bad format data.
103 }
104
105 /**
106 * Method get_update_themes_items().
107 *
108 * Get themes update items to email.
109 *
110 * @return array $update_items Update themes.
111 *
112 * @uses \MainWP\Dashboard\MainWP_Utility::array_merge()
113 */
114 public static function get_update_themes_items() {
115
116 $themesNewUpdate = get_option( 'mainwp_updatescheck_mail_update_themes_new' );
117 if ( ! is_array( $themesNewUpdate ) ) {
118 $themesNewUpdate = array();
119 }
120 $themesToUpdate = get_option( 'mainwp_updatescheck_mail_update_themes' );
121 if ( ! is_array( $themesToUpdate ) ) {
122 $themesToUpdate = array();
123 }
124 $notTrustedThemesNewUpdate = get_option( 'mainwp_updatescheck_mail_ignore_themes_new' );
125 if ( ! is_array( $notTrustedThemesNewUpdate ) ) {
126 $notTrustedThemesNewUpdate = array();
127 }
128 $notTrustedThemesToUpdate = get_option( 'mainwp_updatescheck_mail_ignore_themes' );
129 if ( ! is_array( $notTrustedThemesToUpdate ) ) {
130 $notTrustedThemesToUpdate = array();
131 }
132
133 $themesNewUpdate = static::remove_duplicate_updates( $themesNewUpdate, $themesToUpdate );
134 $themesToUpdate = static::remove_duplicate_updates( $themesToUpdate );
135 $notTrustedThemesNewUpdate = static::remove_duplicate_updates( $notTrustedThemesNewUpdate, $notTrustedThemesToUpdate );
136 $notTrustedThemesToUpdate = static::remove_duplicate_updates( $notTrustedThemesToUpdate );
137
138 $update_items = array();
139
140 $update_items = MainWP_Utility::array_merge( $themesNewUpdate, $themesToUpdate );
141 $update_items = MainWP_Utility::array_merge( $update_items, $notTrustedThemesNewUpdate );
142 $update_items = MainWP_Utility::array_merge( $update_items, $notTrustedThemesToUpdate );
143
144 return $update_items;
145 }
146
147 /**
148 * Method get_update_wp_items().
149 *
150 * Get WP update to email.
151 *
152 * @return array $update_items WP update items.
153 *
154 * @uses \MainWP\Dashboard\MainWP_Utility::array_merge()
155 */
156 public static function get_update_wp_items() {
157
158 $coreNewUpdate = get_option( 'mainwp_updatescheck_mail_update_core_new' );
159 if ( ! is_array( $coreNewUpdate ) ) {
160 $coreNewUpdate = array();
161 }
162 $coreToUpdate = get_option( 'mainwp_updatescheck_mail_update_core' );
163 if ( ! is_array( $coreToUpdate ) ) {
164 $coreToUpdate = array();
165 }
166 $ignoredCoreNewUpdate = get_option( 'mainwp_updatescheck_mail_ignore_core_new' );
167 if ( ! is_array( $ignoredCoreNewUpdate ) ) {
168 $ignoredCoreNewUpdate = array();
169 }
170 $ignoredCoreToUpdate = get_option( 'mainwp_updatescheck_mail_ignore_core' );
171 if ( ! is_array( $ignoredCoreToUpdate ) ) {
172 $ignoredCoreToUpdate = array();
173 }
174
175 $update_items = array();
176
177 $update_items = MainWP_Utility::array_merge( $coreNewUpdate, $coreToUpdate );
178 $update_items = MainWP_Utility::array_merge( $update_items, $ignoredCoreNewUpdate );
179 $update_items = MainWP_Utility::array_merge( $update_items, $ignoredCoreToUpdate );
180
181 return $update_items;
182 }
183
184 /**
185 * Method get_site_updates_items().
186 *
187 * Get Updates items of websites.
188 *
189 * @param string $what values: plugin, theme, wpcore.
190 * @param array $sites_ids Websites ids filter (option).
191 *
192 * @return array $update_items WP update items.
193 */
194 public static function get_site_updates_items( $what, $sites_ids = false ) {
195
196 $items = array();
197 if ( 'plugin' === $what ) {
198 $items = static::get_update_plugins_items();
199 } elseif ( 'theme' === $what ) {
200 $items = static::get_update_themes_items();
201 } elseif ( 'wpcore' === $what ) {
202 $items = static::get_update_wp_items();
203 }
204
205 $filters = array();
206 foreach ( $items as $item ) {
207 if ( isset( $item['id'] ) ) { // to valid and compatible data.
208 if ( ! empty( $sites_ids ) && ! in_array( $item['id'], $sites_ids ) ) {
209 continue;
210 }
211 $filters[] = $item;
212 }
213 }
214 return $filters;
215 }
216
217 /**
218 * Method format_email()
219 *
220 * Format email.
221 *
222 * @param string $to_email Send to emails.
223 * @param string $body Email's body.
224 * @param string $title Email's title.
225 * @param bool $plain_text text format.
226 *
227 * @return string Formatted content
228 */
229 public static function format_email( $to_email = null, $body = '', $title = '', $plain_text = false ) { //phpcs:ignore -- NOSONAR - long function.
230 unset( $to_email );
231 $current_year = gmdate( 'Y' );
232 if ( $plain_text ) {
233 $mail_send['header'] = '';
234 $mail_send['body'] = 'Hi,' . "\r\n\r\n" .
235 ( ( ! empty( $title ) ) ? $title . "\r\n\r\n" : '' ) .
236 $body . "\r\n\r\n";
237 $mail_send['footer'] = 'MainWP: https://mainwp.com' . "\r\n" .
238 'Add-ons: https://mainwp.com/mainwp-add-ons/' . "\r\n" .
239 'Documentation: https://docs.mainwp.com/' . "\r\n" .
240 'Blog: https://mainwp.com/mainwp-blog/' . "\r\n" .
241 'Codex: https://mainwp.dev/' . "\r\n" .
242 'Support: https://mainwp.com/support/' . "\r\n\r\n" .
243 'Follow us on X: https://x.com/mymainwp' . "\r\n" .
244 'Friend us on Facebook: https://www.facebook.com/mainwp' . "\r\n\r\n" .
245 "Copyright {$current_year} MainWP, All rights reserved.";
246 } else {
247 // phpcs:disable PluginCheck.CodeAnalysis.Heredoc.NotAllowed -- Email HTML templates; refactoring 250+ lines of HTML to string concatenation carries high regression risk with no security benefit as content is not browser-rendered.
248 $mail_send['header'] = <<<EOT
249 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
250 <html>
251 <head>
252 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
253 <title> {$title} </title>
254 <style type="text/css">
255 outlook a{padding:0;}
256 body{width:100% !important;}
257 .ReadMsgBody{width:100%;}
258 .ExternalClass{width:100%;}
259 body{-webkit-text-size-adjust:none;}
260 body{margin:0;padding:0;}
261 img{
262 border:0;
263 height:auto;
264 line-height:100%;
265 outline:none;
266 text-decoration:none;
267 }
268 table td{
269 border-collapse:collapse;
270 }
271 #backgroundTable{
272 height:100% !important;
273 margin:0;
274 padding:0;
275 width:100% !important;
276 }
277 body,#backgroundTable{
278 background-color:#FAFAFA;
279 }
280 #templateContainer{
281 border:1px solid #DDDDDD;
282 }
283 h1,.h1{
284 color:#202020;
285 display:block;
286 font-family:Arial;
287 font-size:34px;
288 font-weight:bold;
289 line-height:100%;
290 margin-top:0;
291 margin-right:0;
292 margin-bottom:10px;
293 margin-left:0;
294 text-align:left;
295 }
296 h2,.h2{
297 color:#202020;
298 display:block;
299 font-family:Arial;
300 font-size:30px;
301 font-weight:bold;
302 line-height:100%;
303 margin-top:0;
304 margin-right:0;
305 margin-bottom:10px;
306 margin-left:0;
307 text-align:left;
308 }
309 h3,.h3{
310 color:#202020;
311 display:block;
312 font-family:Arial;
313 font-size:26px;
314 font-weight:bold;
315 line-height:100%;
316 margin-top:0;
317 margin-right:0;
318 margin-bottom:10px;
319 margin-left:0;
320 text-align:left;
321 }
322 h4,.h4{
323 color:#202020;
324 display:block;
325 font-family:Arial;
326 font-size:22px;
327 font-weight:bold;
328 line-height:100%;
329 margin-top:0;
330 margin-right:0;
331 margin-bottom:10px;
332 margin-left:0;
333 text-align:left;
334 }
335 #templatePreheader{
336 background-color:#FAFAFA;
337 }
338 .preheaderContent div{
339 color:#505050;
340 font-family:Arial;
341 font-size:10px;
342 line-height:100%;
343 text-align:left;
344 }
345 .preheaderContent div a:link,.preheaderContent div a:visited,.prehead=
346 erContent div a .yshortcuts {
347 color:#446200;
348 font-weight:normal;
349 text-decoration:underline;
350 }
351 #templateHeader{
352 background-color:#FFFFFF;
353 border-bottom:0;
354 }
355 .headerContent{
356 color:#202020;
357 font-family:Arial;
358 font-size:34px;
359 font-weight:bold;
360 line-height:100%;
361 padding:0;
362 text-align:center;
363 vertical-align:middle;
364 }
365 .headerContent a:link,.headerContent a:visited,.headerContent a .ysho=
366 rtcuts {
367 color:#446200;
368 font-weight:normal;
369 text-decoration:underline;
370 }
371 #headerImage{
372 height:auto;
373 max-width:600px !important;
374 }
375 #templateContainer,.bodyContent{
376 background-color:#FFFFFF;
377 }
378 .bodyContent div{
379 color:#505050;
380 font-family:Arial;
381 font-size:14px;
382 line-height:150%;
383 text-align:left;
384 }
385 .bodyContent div a:link,.bodyContent div a:visited,.bodyContent div a=
386 .yshortcuts {
387 color:#446200;
388 font-weight:bold;
389 text-decoration:underline;
390 }
391 .bodyContent img{
392 display:inline;
393 height:auto;
394 }
395 #templateFooter{
396 background-color:#1d1b1c;
397 border-top:4px solid #7fb100;
398 }
399 .footerContent div{
400 color:#b8b8b8;
401 font-family:Arial;
402 font-size:12px;
403 line-height:125%;
404 text-align:center;
405 }
406 .footerContent div a:link,.footerContent div a:visited,.footerContent=
407 div a .yshortcuts {
408 color:#336699;
409 font-weight:normal;
410 text-decoration:underline;
411 }
412 .footerContent img{
413 display:inline;
414 }
415 #social{
416 background-color:#1d1b1c;
417 border:0;
418 }
419 #social div{
420 text-align:center;
421 }
422 #utility{
423 background-color:#1d1b1c;
424 border:0;
425 }
426 #utility div{
427 text-align:center;
428 }
429 #monkeyRewards img{
430 max-width:190px;
431 }
432 </style>
433 </head>
434 <body offset="0" style="-webkit-text-size-adjust: none;margin: 0;padding: 0;background-color: #FAFAFA;width: 100% !important;">
435 <center>
436 <table id="backgroundTable" style="margin 0;border-spacing:0;width:100%;height:100%;padding:0;background-color: #FAFAFA;height: 100% !important;width: 100% !important;">
437 <tr>
438 <td style="text-align:center;border-collapse: collapse;vertical-align:top;">
439
440 <!-- // Begin: Template Pre-header \\ -->
441
442 <table id="templatePreheader" style="padding:10px;border-spacing:0;width:600px;background-color: #FAFAFA;">
443 <tr>
444 <td class="preheaderContent" style="border-collapse: collapse;vertical-align:top;">
445
446 <!-- // Begin: Standard Preheader \ -->
447
448 <table style="border:0;padding:10px;border-spacing:0;width:100%">
449 <tr>
450 <td style="border-collapse: collapse;vertical-align:top;">
451 <div style="color: #505050;font-family: Arial;font-size: 10px;line-height: 100%;text-align: left;"></div>
452 </td>
453 <td style="border-collapse: collapse;vertical-align:top;width:190px;">
454 <div style="color: #505050;font-family: Arial;font-size: 10px;line-height: 100%;text-align: left;"></div>
455 </td>
456 </tr>
457 </table>
458
459 <!-- // End: Standard Preheader \ -->
460
461 </td>
462 </tr>
463 </table>
464
465 <!-- // End: Template Preheader \\ -->
466
467 <table id="templateContainer" style="width:600px;padding:0;border-spacing:0;border: 1px solid #DDDDDD;background-color: #FFFFFF;">
468 <tr>
469 <td style="text-align:center;vertical-align:top;border-collapse: collapse;">
470
471 <!-- // Begin: Template Header \\ -->
472
473 <table id="templateHeader" style="width:600px;padding:0;border-spacing:0;background-color: #FFFFFF;border-bottom: 0;">
474 <tr>
475 <td class="headerContent" style="border-collapse: collapse;color: #202020;font-family: Arial;font-size: 34px;font-weight: bold;line-height: 100%;padding: 0;text-align: center;vertical-align: middle;">
476
477 <!-- // Begin: Standard Header Image \\ -->
478
479 <a href="https://mainwp.com" target="_blank" style="color: #446200;font-size:45px;font-weight: normal;text-decoration: underline;">MainWP</a>
480
481 <!-- // End: Standard Header Image \\ -->
482
483 </td>
484 </tr>
485 </table>
486
487 <!-- // End: Template Header \\ -->
488
489 </td>
490 </tr>
491 <tr>
492 <td style="align:center;vertical-align:top;border-collapse: collapse;">
493
494 <!-- // Begin: Template Body \\ -->
495
496 <tableid="templateBody" style="border:0;padding:0;border-spacing:0;width:600px;">
497 <tr>
498 <td class="bodyContent" style="vertical-align:top;border-collapse: collapse;background-color: #FFFFFF;">
499
500 <!-- // Begin: Standard Content \\ -->
501 EOT;
502
503 $title_content = ! empty( $title ) ? '<b style="color: rgb(127, 177, 0); font-family: Helvetica, Sans; font-size: medium; line-height: normal;"> ' . $title . ' </b><br>' : '';
504
505 $mail_send['body'] = <<<EOT
506 <table style="vertical-align:top;border:0;padding:20px;border-spacing:0;width:100%;">
507 <tr>
508 <td style="vertical-align:top;border-collapse: collapse;">
509 <div style="color: #505050;font-family: Arial;font-size: 14px;line-height: 150%;text-align: left;"> Hi, <br><br>
510 {$title_content}
511 <br>{$body}<br>
512 </div>
513 </td>
514 </tr>
515 </table>
516 EOT;
517
518 $mail_send['footer'] = <<<EOT
519 <!-- // End: Standard Content \\ -->
520
521 </td>
522 </tr>
523 </table>
524
525 <!-- // End: Template Body \\ -->
526
527 </td>
528 </tr>
529 <tr>
530 <td style="text-align:center;vertical-align:top;border-collapse: collapse;">
531
532 <!-- // Begin: Template Footer \\ -->
533
534 <table id="templateFooter" style="padding:10px;border-spacing:0;width:600px;background-color: #1d1b1c;border-top: 4px solid #7fb100;">
535 <tr>
536 <td class="footerContent" style="vertical-align:top;border-collapse: collapse;">
537
538 <!-- // Begin: Standard Footer \\ -->
539
540 <table width="100%" style="border:0;padding:10px;border-spacing:0;width:100%;">
541 <tr>
542 <td valign="middle" id="social" style="border-collapse: collapse;background-color: #1d1b1c;border: 0;">
543 <div style="color: #b8b8b8;font-family: Arial;font-size: 12px;line-height: 125%;text-align: center;">
544 <style type="text/css">
545 #mainwp-links a {
546 text-transform: uppercase;
547 text-decoration: none;
548 color: #7fb100 ;
549 }
550 </style>
551 <div class="tpl-content-highlight" id="mainwp-links" style="color: #b8b8b8;font-family: Arial;font-size: 12px;line-height: 125%;text-align: center;">
552 <a href="https://mainwp.com" target="_self" style="color: #7fb100;font-weight: normal;text-decoration: none;text-transform: uppercase;">MainWP</a> | <a href="https://mainwp.com/mainwp-add-ons/" target="_self" style="color: #7fb100;font-weight: normal;text-decoration: none;text-transform: uppercase;">Add-ons</a> | <a href="https://docs.mainwp.com/" target="_self" style="color: #7fb100;font-weight: normal;text-decoration:none;text-transform: uppercase;">Documentation</a> | <a href="https://mainwp.com/mainwp-blog/" target="_self" style="color: #7fb100;font-weight: normal;text-decoration: none;text-transform: uppercase;">Blog</a> | <a href="https://mainwp.dev/" target="_self" style="color: #7fb100;font-weight: normal;text-decoration: none;text-transform: uppercase;">Codex</a> | <a href="https://mainwp.com/support/" target="_self" style="color: #7fb100;font-weight: normal;text-decoration: none;text-transform: uppercase;">Support</a></div>
553
554 <hr><br>
555 <a href="https://x.com/mymainwp" target="_blank" style="color: #336699;font-weight: normal;text-decoration: underline;">Follow us on X</a> | <a href="https://www.facebook.com/mainwp" style="color:#336699;font-weight: normal;text-decoration: underline;">Friend us on Facebook</a>
556 </td>
557 </tr>
558 <tr>
559 <td style="vertical-align:top;border-collapse: collapse;">
560 <div style="color: #b8b8b8;font-family: Arial;font-size: 12px;line-height: 125%;text-align: center;"><div style="text-align: left;color: #b8b8b8;font-family: Arial;font-size: 12px;line-height: 125%;"><em>Copyright &copy; {$current_year} MainWP, All rights reserved.</em><br></div></div>
561 </td>
562 </tr>
563 </table>
564
565 <!-- // End: Standard Footer \\ -->
566
567 </td>
568 </tr>
569 </table>
570
571 <!-- // End: Template Footer \\ -->
572
573 </td>
574 </tr>
575 </table>
576 <br>
577 </td>
578 </tr>
579 </table>
580 </center>
581 </body>
582 </html>
583 EOT;
584 // phpcs:enable PluginCheck.CodeAnalysis.Heredoc.NotAllowed
585 }
586 $mail_send = apply_filters( 'mainwp_format_email', $mail_send );
587 return $mail_send['header'] . $mail_send['body'] . $mail_send['footer'];
588 }
589 }
590