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

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