PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.4.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.4.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-logger.php

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

837 lines 21.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Logger
4 *
5 * For custom read/write logging file.
6 *
7 * @package MainWP/Dashboard
8 */
9
10 namespace MainWP\Dashboard;
11
12 /**
13 * Class MainWP_Logger
14 *
15 * @package MainWP\Dashboard
16 */
17 class MainWP_Logger {
18
19 // phpcs:disable WordPress.WP.AlternativeFunctions -- for custom read/write logging file.
20
21 const UPDATE_CHECK_LOG_PRIORITY = 10;
22 const EXECUTION_TIME_LOG_PRIORITY = 15;
23
24
25 const DISABLED = - 1;
26 const LOG = 0;
27 const WARNING = 1;
28 const INFO = 2;
29 const DEBUG = 3;
30
31 const LOG_COLOR = '#999999';
32 const DEBUG_COLOR = '#666666';
33 const INFO_COLOR = '#276f86';
34 const WARNING_COLOR = '#9f3a38;';
35
36 /**
37 * Private variable to hold time start.
38 *
39 * @var int
40 */
41 private static $time_start = null;
42
43 /**
44 * Private varibale to hold the log file prefix.
45 *
46 * @var string Default 'mainwp'
47 */
48 private $logFileNamePrefix = 'mainwp';
49
50 /**
51 * Private varibale to hold the log file suffix.
52 *
53 * @var string Default '.log'
54 */
55 private $logFileNameSuffix = '.log';
56
57 /**
58 * Private varibale to hold the log file max size.
59 *
60 * @var int Default 0.5
61 */
62 private $logMaxMB = 0.5;
63
64 /**
65 * Private varibale to hold the log file date format.
66 *
67 * @var string Default 'Y-m-d H:i:s'
68 */
69 private $logDateFormat = 'Y-m-d H:i:s';
70
71 /**
72 * Private varibale to hold the log file output directory.
73 *
74 * @var mixed Default null
75 */
76 private $logDirectory = null;
77
78 /**
79 * Private varibale to hold the log file priotrity.
80 *
81 * @var string Disabled
82 */
83 private $logPriority = self::DISABLED;
84
85 /**
86 * Private varibale to hold the log Specific priotrity.
87 *
88 * @var string Disabled
89 */
90 private $logSpecific = 0;
91
92
93 /**
94 * Private static varibale to hold the instance.
95 *
96 * @var mixed Default null
97 */
98 private static $instance = null;
99
100 /**
101 * Method instance()
102 *
103 * Returns new MainWP_Logger instance.
104 *
105 * @return self MainWP_Logger
106 *
107 * @uses \MainWP\Dashboard\MainWP_Logger
108 */
109 public static function instance() {
110 if ( null == self::$instance ) {
111 self::$instance = new MainWP_Logger();
112 }
113
114 return self::$instance;
115 }
116
117 /**
118 * MainWP_Logger constructor.
119 *
120 * Run each time the class is called.
121 *
122 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_dir()
123 */
124 private function __construct() {
125
126 $enabled = $this->get_log_status();
127 $specific = $this->get_log_specific();
128
129 $enabled = apply_filters( 'mainwp_log_status', $enabled );
130 $specific = apply_filters( 'mainwp_log_specific', $specific );
131
132 $this->set_log_priority( $enabled, $specific );
133 }
134
135 /**
136 * Method set_log_priority()
137 *
138 * Sets the log priority.
139 *
140 * @param mixed $logPriority Log priority value.
141 * @param mixed $spec_log Specific log.
142 */
143 public function set_log_priority( $logPriority, $spec_log = 0 ) {
144 $this->logPriority = $logPriority;
145 $this->logSpecific = $spec_log; // 1 - specific log, 0 - not specific log.
146 }
147
148 /**
149 * Method get_log_status()
150 *
151 * Get log status.
152 *
153 * @return mixed $enabled log status.
154 */
155 public function get_log_status() {
156 $enabled = get_option( 'mainwp_actionlogs' );
157
158 if ( false === $enabled ) {
159 $sites_count = MainWP_DB::instance()->get_websites_count();
160 if ( 0 == $sites_count ) {
161 $enabled = self::DEBUG;
162 set_transient( 'mainwp_transient_action_logs', true, 2 * WEEK_IN_SECONDS );
163 } elseif ( get_transient( 'mainwp_transient_action_logs' ) ) {
164 $enabled = self::DEBUG;
165 } else {
166 $enabled = self::DISABLED;
167 }
168 }
169
170 return $enabled;
171 }
172
173
174 /**
175 * Method get_log_specific()
176 *
177 * Get log specific status.
178 *
179 * @return mixed $enabled log status.
180 */
181 public function get_log_specific() {
182 return get_option( 'mainwp_specific_logs', 0 );
183 }
184
185 /**
186 * Method get_log_type_info()
187 *
188 * Get log type info.
189 *
190 * @param int $type Log type value.
191 * @param int $logcolor Log color value.
192 *
193 * @return int $currentColor log color code.
194 */
195 public function get_log_type_info( $type, $logcolor ) {
196 $currentColor = '';
197 $prefix = '';
198 if ( self::DEBUG == $type || self::DEBUG == $logcolor ) {
199 $currentColor = self::DEBUG_COLOR;
200 $prefix = '[DEBUG]';
201 } elseif ( self::INFO == $type || self::INFO == $logcolor ) {
202 $currentColor = self::INFO_COLOR;
203 $prefix = '[INFO]';
204 } elseif ( self::WARNING == $type || self::WARNING == $logcolor ) {
205 $currentColor = self::WARNING_COLOR;
206 $prefix = '[WARNING]';
207 } elseif ( self::LOG == $type || self::LOG == $logcolor ) {
208 $currentColor = self::LOG_COLOR;
209 $prefix = '[LOG]';
210 }
211 return array(
212 'log_color' => $currentColor,
213 'log_prefix' => $prefix,
214 );
215 }
216
217 /**
218 * Method debug()
219 *
220 * Grab debug.
221 *
222 * @param string $text Debug message text.
223 *
224 * @return string Log debug message.
225 */
226 public function debug( $text ) {
227 return $this->log( $text, self::DEBUG );
228 }
229
230 /**
231 * Method info()
232 *
233 * Grab info.
234 *
235 * @param string $text Info message text.
236 *
237 * @return string Log info message.
238 */
239 public function info( $text ) {
240 return $this->log( $text, self::INFO );
241 }
242
243 /**
244 * Method warning()
245 *
246 * Grab warning information.
247 *
248 * @param string $text Warning message text.
249 *
250 * @return string Log warning message.
251 */
252 public function warning( $text ) {
253 return $this->log( $text, self::WARNING );
254 }
255
256 /**
257 * Method actions()
258 *
259 * Grab actions information.
260 *
261 * @param string $text Warning message text.
262 * @param int $priority priority message.
263 * @param int $log_color Set color: 0 - LOG, 1 - WARNING, 2 - INFO, 3- DEBUG.
264 * @param bool $forced forced logging.
265 *
266 * @return string Log warning message.
267 */
268 public function log_action( $text, $priority, $log_color = 0, $forced = false ) {
269 return $this->log( $text, $priority, $log_color, $forced );
270 }
271
272 /**
273 * Method log_execution_time().
274 *
275 * @param string $text Log record text.
276 *
277 * Log the execution time value.
278 */
279 public function log_execution_time( $text = '' ) {
280 $exec_time = self::get_execution_time();
281 self::instance()->log_action( 'execution time (sec) :: ' . ( ! empty( $text ) ? (string) $text . ' :: ' : '' ) . $exec_time, self::EXECUTION_TIME_LOG_PRIORITY );
282 }
283
284 /**
285 * Method log_update_check().
286 *
287 * @param string $text Log update check.
288 */
289 public function log_update_check( $text = '' ) {
290 self::instance()->log_action( $text, self::UPDATE_CHECK_LOG_PRIORITY );
291 }
292
293 /**
294 * Method debug_for_website()
295 *
296 * Grab website debug and info.
297 *
298 * @param object $website Child site object.
299 * @param string $action Performed action.
300 * @param string $message Debug message.
301 *
302 * @return mixed Website debug info.
303 *
304 * @uses \MainWP\Dashboard\MainWP_Utility::get_nice_url()
305 */
306 public function debug_for_website( $website, $action, $message ) {
307 if ( empty( $website ) ) {
308 return $this->log( '[-] [-] ::' . $action . ':: ' . $message, self::DEBUG );
309 }
310
311 return $this->log( '[' . $website->name . '] [' . MainWP_Utility::get_nice_url( $website->url ) . '] ::' . $action . ':: ' . $message, self::DEBUG );
312 }
313
314 /**
315 * Method info_for_website()
316 *
317 * Grab Website Info.
318 *
319 * @param object $website Child site object.
320 * @param string $action Performed action.
321 * @param string $message Info message.
322 *
323 * @return mixed Website Info.
324 *
325 * @uses \MainWP\Dashboard\MainWP_Utility::get_nice_url()
326 */
327 public function info_for_website( $website, $action, $message ) {
328 if ( empty( $website ) ) {
329 return $this->log( '[-] [-] ::' . $action . ':: ' . $message, self::INFO );
330 }
331
332 return $this->log( '[' . $website->name . '] [' . MainWP_Utility::get_nice_url( $website->url ) . '] ::' . $action . ':: ' . $message, self::INFO );
333 }
334
335 /**
336 * Method warning_for_website()
337 *
338 * Grab Website Warnings.
339 *
340 * @param object $website Child site object.
341 * @param string $action Performed action.
342 * @param string $message Warning message.
343 * @param bool $addStackTrace Add or Don't add stack trace.
344 *
345 * @return string Website warnings.
346 */
347 public function warning_for_website( $website, $action, $message, $addStackTrace = true ) {
348 $stackTrace = '';
349 if ( $addStackTrace ) {
350 ob_start();
351 // phpcs:ignore -- for debugging.
352 debug_print_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS );
353 $stackTrace = "\n" . ob_get_clean();
354 }
355 if ( empty( $website ) ) {
356 return $this->log( '[-] [-] ::' . $action . ':: ' . $message . $stackTrace, self::WARNING );
357 }
358
359 return $this->log( '[' . $website->name . '] [' . MainWP_Utility::get_nice_url( $website->url ) . '] ::' . $action . ':: ' . $message . $stackTrace, self::WARNING );
360 }
361
362 /**
363 * Method log_to_db()
364 *
365 * Log to database.
366 *
367 * @param string $text Log record text.
368 * @param int $priority Set priority.
369 * @param int $log_color Set color.
370 * @param bool $forced forced logging.
371 *
372 * @return bool true|false Default is False.
373 */
374 private function log_to_db( $text, $priority, $log_color = 0, $forced = false ) {
375
376 if ( self::DISABLED === $this->logPriority ) {
377 return;
378 }
379
380 $priority = apply_filters( 'mainwp_log_to_db_priority', $priority );
381
382 $do_log = false;
383
384 if ( 1 == $this->logSpecific ) { // 1 - specific log, 0 - not specific log.
385 if ( $this->logPriority == $priority ) { // specific priority number saved setting.
386 $do_log = true;
387 }
388 } elseif ( $this->logPriority >= $priority ) {
389 $do_log = true;
390 }
391
392 $text = $this->prepare_log_info( $text );
393
394 if ( $forced || $do_log ) {
395
396 $time = gmdate( $this->logDateFormat );
397
398 /**
399 * Current user global.
400 *
401 * @global string
402 */
403 global $current_user;
404
405 $user = '';
406 if ( ! empty( $current_user ) && ! empty( $current_user->user_login ) ) {
407 $user = $current_user->user_login;
408 } elseif ( defined( 'WP_CLI' ) ) {
409 $user = 'WP_CLI';
410 } elseif ( defined( 'DOING_CRON' ) ) {
411 $user = 'DOING_CRON';
412 }
413
414 $data = array();
415
416 $data['log_content'] = $text;
417 $data['log_user'] = $user;
418 $data['log_type'] = $priority;
419 $data['log_color'] = intval( $log_color );
420 $data['log_timestamp'] = time();
421
422 $data = apply_filters( 'mainwp_log_to_db_data', $data );
423
424 MainWP_DB_Common::instance()->insert_action_log( $data );
425
426 return true;
427 }
428 return false;
429 }
430
431 /**
432 * Method log()
433 *
434 * Create Log File.
435 *
436 * @param string $text Log record text.
437 * @param int $priority Set priority.
438 * @param int $log_color Set color.
439 * @param bool $forced forced logging.
440 *
441 * @return bool true|false Default is False.
442 */
443 private function log( $text, $priority, $log_color = 0, $forced = false ) { // phpcs:ignore -- complex function.
444
445 if ( self::DISABLED == $this->logPriority ) {
446 return;
447 }
448
449 $log_to_db = apply_filters( 'mainwp_logger_to_db', true );
450
451 if ( $log_to_db ) {
452 return $this->log_to_db( $text, $priority, $log_color, $forced );
453 }
454
455 $text = $this->prepare_log_info( $text );
456
457 $do_log = false;
458 if ( 1 == $this->logSpecific ) { // 1 - specific log, 0 - not specific log.
459 if ( $this->logPriority == $priority ) { // specific priority number saved setting.
460 $do_log = true;
461 }
462 } elseif ( $this->logPriority >= $priority ) {
463 $do_log = true;
464 }
465
466 if ( $do_log ) {
467 $this->logCurrentFile = $this->get_log_file();
468 $logCurrentHandle = fopen( $this->logCurrentFile, 'a+' );
469
470 if ( $logCurrentHandle ) {
471 $time = gmdate( $this->logDateFormat );
472 $prefix = '[' . $this->get_log_text( $priority ) . ']';
473
474 /**
475 * Current user global.
476 *
477 * @global string
478 */
479 global $current_user;
480
481 if ( ! empty( $current_user ) && ! empty( $current_user->user_login ) ) {
482 $prefix .= ' [administrator]';
483 }
484
485 fwrite( $logCurrentHandle, $time . ' ' . $prefix . ' ' . $text . "\n" );
486 fclose( $logCurrentHandle );
487 }
488
489 if ( filesize( $this->logCurrentFile ) > ( $this->logMaxMB * 1048576 ) ) {
490 $logCurrentHandle = fopen( $this->logCurrentFile, 'a+' );
491 if ( $logCurrentHandle ) {
492 fseek( $logCurrentHandle, 0 );
493 $newLogFile = $this->logCurrentFile . '.tmp';
494 $newLogHandle = false;
495 $chunkSize = filesize( $this->logCurrentFile ) - ( $this->logMaxMB * 1048576 );
496 while ( is_resource( $logCurrentHandle ) && ! feof( $logCurrentHandle ) && ( $chunkSize > 0 ) ) {
497 $content = fread( $logCurrentHandle, $chunkSize );
498 if ( false === $content ) {
499 break;
500 }
501 $pos = strrpos( $content, "\n" );
502 if ( $newLogHandle ) {
503 fwrite( $newLogHandle, $content );
504 } elseif ( $pos ) {
505 if ( ! $newLogHandle ) {
506 $newLogHandle = fopen( $newLogFile, 'w+' );
507 }
508 fwrite( $newLogHandle, substr( $content, $pos + 1 ) );
509 }
510 }
511
512 if ( is_resource( $logCurrentHandle ) ) {
513 fclose( $logCurrentHandle );
514 }
515
516 if ( $newLogHandle ) {
517 fclose( $newLogHandle );
518 unlink( $this->logCurrentFile );
519 if ( file_exists( $newLogFile ) ) {
520 rename( $newLogFile, $this->logCurrentFile );
521 }
522 }
523 }
524 }
525
526 return true;
527 }
528
529 return false;
530 }
531
532
533 /**
534 * Method prepare_log_info()
535 *
536 * Prepare log data.
537 *
538 * @param mixed $data Log data.
539 *
540 * @return mixed $data filtered data.
541 */
542 public function prepare_log_info( $data ) {
543 $patterns[0] = '/user=([^\&]+)\&/';
544 $replacement[0] = 'user=xxxxxx&';
545 $patterns[1] = '/alt_user=([^\&]+)\&/';
546 $replacement[1] = 'alt_user=xxxxxx&';
547 $patterns[2] = '/\&server=([^\&]+)\&/';
548 $replacement[2] = '&server=xxxxxx&';
549 $data = preg_replace( $patterns, $replacement, $data );
550 return $data;
551 }
552
553 /**
554 * Method prepend()
555 *
556 * Prepend content to log file.
557 *
558 * @param mixed $string Custom string.
559 * @param mixed $filename Filename.
560 */
561 public function prepend( $string, $filename ) {
562 $context = stream_context_create();
563 $fp = fopen( $filename, 'r', 1, $context );
564 $tmpname = md5( $string );
565 file_put_contents( $tmpname, $string );
566 file_put_contents( $tmpname, $fp, FILE_APPEND );
567 fclose( $fp );
568 unlink( $filename );
569 rename( $tmpname, $filename );
570 }
571
572 /**
573 * Method init_execution_time().
574 *
575 * @param string $code execution time code.
576 *
577 * Init execution time start value.
578 */
579 public function init_execution_time( $code = '' ) {
580 if ( null === self::$time_start || ! is_array( self::$time_start ) ) {
581 self::$time_start = array( 'start' => microtime( true ) );
582 $this->log_action( 'init execution time :: [code=start]', self::EXECUTION_TIME_LOG_PRIORITY );
583 $code = 'start';
584 }
585
586 if ( ! empty( $code ) && is_string( $code ) && 'start' !== $code ) {
587 self::$time_start[ $code ] = microtime( true );
588 $this->log_action( 'init execution time :: [code=' . $code . ']', self::EXECUTION_TIME_LOG_PRIORITY );
589 }
590 }
591
592 /**
593 * Method get_execution_time().
594 *
595 * Get the execution time value.
596 *
597 * @return int execution time.
598 */
599 private function get_execution_time() {
600 if ( empty( $this->time_start ) ) {
601 return 0;
602 }
603 return round( microtime( true ) - $this->time_start, 6 ); // seconds.
604 }
605
606 /**
607 * Method get_log_file()
608 *
609 * Grab Log File.
610 *
611 * @return mixed Log File.
612 */
613 public function get_log_file() {
614 if ( empty( $this->logDirectory ) ) {
615 $this->logDirectory = MainWP_System_Utility::get_mainwp_dir();
616 $this->logDirectory = $this->logDirectory[0];
617 }
618 return $this->logDirectory . $this->logFileNamePrefix . $this->logFileNameSuffix;
619 }
620
621 /**
622 * Method get_log_text()
623 *
624 * Grab what type of log entry.
625 *
626 * @param mixed $priority Set priority.
627 *
628 * @return string LOG -OR- DISABLED|DEBUG|INFO|WARNING|INFO UPDATE
629 */
630 public function get_log_text( $priority ) {
631 switch ( $priority ) {
632 case self::DISABLED:
633 return 'DISABLED';
634 case self::DEBUG:
635 return 'DEBUG';
636 case self::INFO:
637 return 'INFO';
638 case self::WARNING:
639 return 'WARNING';
640 default:
641 return 'SPEC LOG';
642 }
643 }
644
645 /**
646 * Method check_log_daily()
647 *
648 * Daily checks to clear the log file.
649 *
650 * @param int $days number of days to keep logs.
651 */
652 public function check_log_daily( $days = false ) {
653
654 $enabled = $this->get_log_status();
655 if ( ! $enabled ) {
656 return;
657 }
658
659 $today_m_y = date_i18n( 'd/m/Y' ); //phpcs:ignore -- local time.
660 // one time per day.
661 if ( get_option( 'mainwp_logger_check_daily' ) != $today_m_y ) {
662 $num_days = apply_filters( 'mainwp_logger_keep_days', 7 );
663 MainWP_DB_Common::instance()->delete_action_log( $num_days );
664 MainWP_Utility::update_option( 'mainwp_logger_check_daily', $today_m_y );
665 }
666 }
667
668 /**
669 * Method clear_log_db()
670 *
671 * Clear the log file.
672 */
673 public function clear_log_db() {
674 MainWP_DB_Common::instance()->delete_action_log();
675 }
676
677 /**
678 * Method clear_log()
679 *
680 * Clear the log file.
681 */
682 public function clear_log() {
683 $logFile = $this->get_log_file();
684 if ( ! unlink( $logFile ) ) {
685 $fh = fopen( $logFile, 'w' );
686 if ( false === $fh ) {
687 return;
688 }
689
690 fclose( $fh );
691 }
692 }
693
694 /**
695 * Method show_log_db()
696 *
697 * Grab log file and build output to screen.
698 */
699 public function show_log_db() {
700
701 echo '<div class="ui hidden divider"></div>';
702 echo '<div class="ui divided padded relaxed list" local-datetime="' . date( 'Y-m-d H:i:s' ) . '">'; // phpcs:ignore -- local time.
703
704 $rows = MainWP_DB::instance()->query( MainWP_DB_Common::instance()->get_sql_log() );
705
706 $start_wrapper = '<span class="ui mini label mainwp-action-log-show-more">Click to See Response</span><div class="mainwp-action-log-site-response" style="display: none;">';
707 $end_wrapper = '</div>';
708
709 while ( $rows && ( $row = MainWP_DB::fetch_object( $rows ) ) ) {
710 $type = $row->log_type;
711 $line = $row->log_content;
712
713 $time = gmdate( $this->logDateFormat, $row->log_timestamp );
714
715 $showInfo = $this->get_log_type_info( $row->log_type, $row->log_color );
716 $currentColor = $showInfo['log_color'];
717
718 $prefix = $time . ' ' . $showInfo['log_prefix'];
719
720 $line = htmlentities( $line );
721
722 if ( false !== strpos( $line, '[data-start]' ) ) {
723 $line = str_replace( '[data-start]', $start_wrapper, $line );
724 $line = str_replace( '[data-end]', $end_wrapper, $line );
725 }
726
727 echo '<div class="item" style="color:' . $currentColor . '"><div class="mainwpactionlogsline">';
728
729 echo $prefix . ' ' . $line;
730
731 echo '</div></div>';
732 }
733
734 echo '</div></div>';
735
736 echo '</div>';
737
738 ?>
739 <div class="ui large modal" id="mainwp-action-log-response-modal">
740 <div class="header"><?php esc_html_e( 'Child Site Response', 'mainwp' ); ?></div>
741 <div class="content">
742 <div class="ui info message"><?php esc_html_e( 'To see the response in a more readable way, you can copy it and paste it into some HTML render tool, such as Codepen.io.', 'mainwp' ); ?>
743 </div>
744 </div>
745 <div class="scrolling content content-response"></div>
746 <div class="actions">
747 <button class="ui green button mainwp-response-copy-button"><?php esc_html_e( 'Copy Response', 'mainwp' ); ?></button>
748 <div class="ui cancel button mainwp-reload"><?php esc_html_e( 'Close', 'mainwp' ); ?></div>
749 </div>
750 </div>
751 <?php
752 }
753
754 /**
755 * Method show_log_file()
756 *
757 * Grab log file and build output to screen.
758 */
759 public function show_log_file() {
760 $logFile = $this->get_log_file();
761
762 if ( ! file_exists( $logFile ) ) {
763 return;
764 }
765
766 $fh = fopen( $logFile, 'r' );
767 if ( false === $fh ) {
768 return;
769 }
770
771 $previousColor = '';
772 $fontOpen = false;
773 $firstLinePassedProcessed = false;
774 echo '<div class="ui hidden divider"></div>';
775 echo '<div class="ui divided padded relaxed list">';
776 while ( false !== ( $line = fgets( $fh ) ) ) {
777 $currentColor = $previousColor;
778 if ( stristr( $line, '[DEBUG]' ) ) {
779 $currentColor = self::DEBUG_COLOR;
780 $firstLinePassed = true;
781 } elseif ( stristr( $line, '[INFO]' ) ) {
782 $currentColor = self::INFO_COLOR;
783 $firstLinePassed = true;
784 } elseif ( stristr( $line, '[WARNING]' ) ) {
785 $currentColor = self::WARNING_COLOR;
786 $firstLinePassed = true;
787 } elseif ( stristr( $line, '[LOG]' ) ) {
788 $currentColor = self::LOG_COLOR;
789 $firstLinePassed = true;
790 } else {
791 $firstLinePassed = false;
792 }
793
794 if ( $firstLinePassedProcessed && ! $firstLinePassed ) {
795 echo ' <span class="ui mini label mainwp-action-log-show-more">Click to See Response</span></div><div class="mainwp-action-log-site-response" style="display: none;">';
796 }
797
798 $firstLinePassedProcessed = $firstLinePassed;
799
800 if ( $currentColor != $previousColor ) {
801 if ( $fontOpen ) {
802 echo '</div></div>';
803 }
804
805 echo '<div class="item" style="color:' . $currentColor . '"><div class="mainwpactionlogsline">';
806 $fontOpen = true;
807 }
808
809 echo htmlentities( $line );
810 }
811
812 if ( $fontOpen ) {
813 echo '</div></div>';
814 }
815
816 echo '</div>';
817
818 ?>
819 <div class="ui large modal" id="mainwp-action-log-response-modal">
820 <div class="header"><?php esc_html_e( 'Child Site Response', 'mainwp' ); ?></div>
821 <div class="content">
822 <div class="ui info message"><?php esc_html_e( 'To see the response in a more readable way, you can copy it and paste it into some HTML render tool, such as Codepen.io.', 'mainwp' ); ?>
823 </div>
824 </div>
825 <div class="scrolling content content-response"></div>
826 <div class="actions">
827 <button class="ui green button mainwp-response-copy-button"><?php esc_html_e( 'Copy Response', 'mainwp' ); ?></button>
828 <div class="ui cancel button mainwp-reload"><?php esc_html_e( 'Close', 'mainwp' ); ?></div>
829 </div>
830 </div>
831 <?php
832
833 fclose( $fh );
834 }
835
836 }
837