PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.7.1
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.7.1
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / rosell-dk / webp-convert / src / Loggers / BufferLogger.php

BufferLogger.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.7.1, at vendor/rosell-dk/webp-convert/src/Loggers/BufferLogger.php

114 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WebPConvert\Loggers;
4
5 use WebPConvert\Loggers\BaseLogger;
6
7 /**
8 * Collect the logging and retrieve it later in HTML or plain text format.
9 *
10 * @package WebPConvert
11 * @author Bjørn Rosell <[email protected]>
12 * @since Class available since Release 2.0.0
13 */
14 class BufferLogger extends BaseLogger
15 {
16 public $entries = array();
17
18 /**
19 * Write a message to the buffer - all entries can later be retrieved with getText() or getHtlm().
20 *
21 * @param string $msg message to log
22 * @param string $style style (null | bold | italic)
23 * @return void
24 */
25 public function log($msg, $style = '')
26 {
27 $this->entries[] = [$msg, $style];
28 }
29
30 /**
31 * Write a new line to the buffer.
32 *
33 * @return void
34 */
35 public function ln()
36 {
37 $this->entries[] = '';
38 }
39
40 /**
41 * Get everything logged - as HTML.
42 *
43 * @return string The log, formatted as HTML.
44 */
45 public function getHtml()
46 {
47 $html = '';
48 foreach ($this->entries as $entry) {
49 if ($entry == '') {
50 $html .= '<br>';
51 } else {
52 list($msg, $style) = $entry;
53 $msg = htmlspecialchars($msg);
54 if ($style == 'bold') {
55 $html .= '<b>' . $msg . '</b>';
56 } elseif ($style == 'italic') {
57 $html .= '<i>' . $msg . '</i>';
58 } else {
59 $html .= $msg;
60 }
61 }
62 }
63 return $html;
64 }
65
66 /**
67 * Get everything logged - as markdown.
68 *
69 * @return string The log, formatted as MarkDown.
70 */
71 public function getMarkDown($newLineChar = "\n\r")
72 {
73 $md = '';
74 foreach ($this->entries as $entry) {
75 if ($entry == '') {
76 $md .= $newLineChar;
77 } else {
78 list($msg, $style) = $entry;
79 if ($style == 'bold') {
80 $md .= '**' . $msg . '** ';
81 } elseif ($style == 'italic') {
82 $md .= '*' . $msg . '* ';
83 } else {
84 $md .= $msg;
85 }
86 }
87 }
88 return $md;
89 }
90
91 /**
92 * Get everything logged - as plain text.
93 *
94 * @param string $newLineChar. The character used for new lines.
95 * @return string The log, formatted as plain text.
96 */
97 public function getText($newLineChar = ' ')
98 {
99 $text = '';
100 foreach ($this->entries as $entry) {
101 if ($entry == '') { // empty string means new line
102 if (substr($text, -2) != '.' . $newLineChar) {
103 $text .= '.' . $newLineChar;
104 }
105 } else {
106 list($msg, $style) = $entry;
107 $text .= $msg;
108 }
109 }
110
111 return $text;
112 }
113 }
114