PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.3
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.3
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 5.3, at class/class-mainwp-format.php

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