Site Kit by Google - Version 1.0.4

Version Description

Download this release

Release Info

Developer flixos90
Plugin Icon 128x128 Site Kit by Google
Version 1.0.4
Comparing to
See all releases

Code changes from version 1.0.3 to 1.0.4

Files changed (26) hide show
  1. google-site-kit.php +2 -2
  2. includes/Core/Authentication/Authentication.php +5 -1
  3. includes/Core/Authentication/Clients/OAuth_Client.php +1 -6
  4. includes/Core/Authentication/Profile.php +16 -26
  5. readme.txt +1 -1
  6. third-party/monolog/monolog/src/Monolog/Formatter/FluentdFormatter.php +2 -1
  7. third-party/monolog/monolog/src/Monolog/Formatter/HtmlFormatter.php +3 -2
  8. third-party/monolog/monolog/src/Monolog/Formatter/JsonFormatter.php +2 -2
  9. third-party/monolog/monolog/src/Monolog/Formatter/LineFormatter.php +1 -1
  10. third-party/monolog/monolog/src/Monolog/Formatter/MongoDBFormatter.php +1 -1
  11. third-party/monolog/monolog/src/Monolog/Formatter/NormalizerFormatter.php +4 -106
  12. third-party/monolog/monolog/src/Monolog/Handler/BrowserConsoleHandler.php +5 -4
  13. third-party/monolog/monolog/src/Monolog/Handler/BufferHandler.php +16 -0
  14. third-party/monolog/monolog/src/Monolog/Handler/ChromePHPHandler.php +3 -2
  15. third-party/monolog/monolog/src/Monolog/Handler/CubeHandler.php +3 -2
  16. third-party/monolog/monolog/src/Monolog/Handler/FilterHandler.php +36 -10
  17. third-party/monolog/monolog/src/Monolog/Handler/FingersCrossedHandler.php +39 -13
  18. third-party/monolog/monolog/src/Monolog/Handler/FlowdockHandler.php +2 -1
  19. third-party/monolog/monolog/src/Monolog/Handler/IFTTTHandler.php +2 -1
  20. third-party/monolog/monolog/src/Monolog/Handler/NewRelicHandler.php +2 -1
  21. third-party/monolog/monolog/src/Monolog/Handler/PHPConsoleHandler.php +2 -1
  22. third-party/monolog/monolog/src/Monolog/Handler/SamplingHandler.php +36 -10
  23. third-party/monolog/monolog/src/Monolog/Handler/Slack/SlackRecord.php +6 -1
  24. third-party/monolog/monolog/src/Monolog/Handler/SlackHandler.php +2 -1
  25. third-party/monolog/monolog/src/Monolog/Handler/SlackWebhookHandler.php +2 -1
  26. third-party/monolog/monolog/src/Monolog/Utils.php +114 -0
google-site-kit.php CHANGED
@@ -11,7 +11,7 @@
11
* Plugin Name: Site Kit by Google
12
* Plugin URI: https://sitekit.withgoogle.com
13
* Description: Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
14
- * Version: 1.0.3
15
* Author: Google
16
* Author URI: https://opensource.google.com
17
* License: Apache License 2.0
@@ -24,7 +24,7 @@ if ( ! defined( 'ABSPATH' ) ) {
24
}
25
26
// Define most essential constants.
27
- define( 'GOOGLESITEKIT_VERSION', '1.0.3' );
28
define( 'GOOGLESITEKIT_PLUGIN_MAIN_FILE', __FILE__ );
29
30
/**
11
* Plugin Name: Site Kit by Google
12
* Plugin URI: https://sitekit.withgoogle.com
13
* Description: Site Kit is a one-stop solution for WordPress users to use everything Google has to offer to make them successful on the web.
14
+ * Version: 1.0.4
15
* Author: Google
16
* Author URI: https://opensource.google.com
17
* License: Apache License 2.0
24
}
25
26
// Define most essential constants.
27
+ define( 'GOOGLESITEKIT_VERSION', '1.0.4' );
28
define( 'GOOGLESITEKIT_PLUGIN_MAIN_FILE', __FILE__ );
29
30
/**
includes/Core/Authentication/Authentication.php CHANGED
@@ -466,7 +466,11 @@ final class Authentication {
466
*/
467
private function inline_js_admin_data( $data ) {
468
if ( ! isset( $data['userData'] ) ) {
469
- $data['userData'] = array();
470
}
471
$profile_data = $this->profile->get();
472
if ( $profile_data ) {
466
*/
467
private function inline_js_admin_data( $data ) {
468
if ( ! isset( $data['userData'] ) ) {
469
+ $current_user = wp_get_current_user();
470
+ $data['userData'] = array(
471
+ 'email' => $current_user->user_email,
472
+ 'picture' => get_avatar_url( $current_user->user_email ),
473
+ );
474
}
475
$profile_data = $this->profile->get();
476
if ( $profile_data ) {
includes/Core/Authentication/Clients/OAuth_Client.php CHANGED
@@ -287,13 +287,8 @@ final class OAuth_Client {
287
* @since 1.0.0
288
*/
289
public function revoke_token() {
290
- // Stop if google_client not initialized yet.
291
- if ( ! $this->google_client instanceof Google_Client ) {
292
- return;
293
- }
294
-
295
try {
296
- $this->google_client->revokeToken();
297
} catch ( \Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement
298
// No special handling, we just need to make sure this goes through.
299
}
287
* @since 1.0.0
288
*/
289
public function revoke_token() {
290
try {
291
+ $this->get_client()->revokeToken();
292
} catch ( \Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement
293
// No special handling, we just need to make sure this goes through.
294
}
includes/Core/Authentication/Profile.php CHANGED
@@ -10,7 +10,6 @@
10
11
namespace Google\Site_Kit\Core\Authentication;
12
13
- use Google\Site_Kit\Helpers;
14
use Google\Site_Kit\Core\Storage\User_Options;
15
use Google\Site_Kit\Core\Authentication\Clients\OAuth_Client;
16
use Google\Site_Kit_Dependencies\Google_Service_PeopleService;
@@ -54,19 +53,6 @@ final class Profile {
54
public function __construct( User_Options $user_options, OAuth_Client $auth_client ) {
55
$this->user_options = $user_options;
56
$this->auth_client = $auth_client;
57
-
58
- // Ensure we have fresh profile data.
59
- $profile_data = $this->get();
60
- $timestamp = isset( $profile_data['timestamp'] ) ? (int) $profile_data['timestamp'] : 0;
61
- $currenttime = time();
62
-
63
- // If the stored profile data is missing, or older than a week, re-fetch it.
64
- if ( ! $profile_data || ( ( $currenttime - $timestamp ) > ( 7 * DAY_IN_SECONDS ) ) ) {
65
- $profile_data = $this->retrieve_google_profile_from_api();
66
- }
67
- if ( 0 !== $profile_data['timestamp'] ) {
68
- $this->set( $profile_data );
69
- }
70
}
71
72
/**
@@ -77,7 +63,17 @@ final class Profile {
77
* @return array|bool Value set for the profile, or false if not set.
78
*/
79
public function get() {
80
- return $this->user_options->get( self::OPTION );
81
}
82
83
/**
@@ -115,13 +111,7 @@ final class Profile {
115
*/
116
private function retrieve_google_profile_from_api() {
117
118
- // Fall back to the user's WordPress profile information.
119
- $current_user = wp_get_current_user();
120
- $profile_data = array(
121
- 'email' => $current_user->user_email,
122
- 'photo' => get_avatar_url( $current_user->user_email ),
123
- 'timestamp' => 0, // Don't cache WP user data.
124
- );
125
126
// Retrieve and store the user's Google profile data.
127
try {
@@ -129,14 +119,14 @@ final class Profile {
129
$people_service = new Google_Service_PeopleService( $client );
130
$profile = $people_service->people->get( 'people/me', array( 'personFields' => 'emailAddresses,photos' ) );
131
132
- if ( isset( $profile['emailAddresses'][0]['value'] ) && isset( $profile['photos'][0]['url'] ) ) {
133
-
134
- // Success - we have the profile data from the People API.
135
$profile_data = array(
136
'email' => $profile['emailAddresses'][0]['value'],
137
'photo' => $profile['photos'][0]['url'],
138
- 'timestamp' => time(),
139
);
140
}
141
} catch ( \Exception $e ) {
142
return $profile_data;
10
11
namespace Google\Site_Kit\Core\Authentication;
12
13
use Google\Site_Kit\Core\Storage\User_Options;
14
use Google\Site_Kit\Core\Authentication\Clients\OAuth_Client;
15
use Google\Site_Kit_Dependencies\Google_Service_PeopleService;
53
public function __construct( User_Options $user_options, OAuth_Client $auth_client ) {
54
$this->user_options = $user_options;
55
$this->auth_client = $auth_client;
56
}
57
58
/**
63
* @return array|bool Value set for the profile, or false if not set.
64
*/
65
public function get() {
66
+ // Ensure we have fresh profile data.
67
+ $profile_data = $this->user_options->get( self::OPTION );
68
+ $profile_time = isset( $profile_data['timestamp'] ) ? (int) $profile_data['timestamp'] : 0;
69
+ $current_time = current_time( 'timestamp' );
70
+
71
+ // If the stored profile data is missing, or older than a week, re-fetch it.
72
+ if ( ! $profile_data || ( $current_time - $profile_time ) > WEEK_IN_SECONDS ) {
73
+ $profile_data = $this->retrieve_google_profile_from_api();
74
+ }
75
+
76
+ return $profile_data;
77
}
78
79
/**
111
*/
112
private function retrieve_google_profile_from_api() {
113
114
+ $profile_data = false;
115
116
// Retrieve and store the user's Google profile data.
117
try {
119
$people_service = new Google_Service_PeopleService( $client );
120
$profile = $people_service->people->get( 'people/me', array( 'personFields' => 'emailAddresses,photos' ) );
121
122
+ if ( isset( $profile['emailAddresses'][0]['value'], $profile['photos'][0]['url'] ) ) {
123
$profile_data = array(
124
'email' => $profile['emailAddresses'][0]['value'],
125
'photo' => $profile['photos'][0]['url'],
126
+ 'timestamp' => current_time( 'timestamp' ),
127
);
128
+
129
+ $this->set( $profile_data );
130
}
131
} catch ( \Exception $e ) {
132
return $profile_data;
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: google
4
Requires at least: 4.7
5
Tested up to: 5.3
6
Requires PHP: 5.4
7
- Stable tag: 1.0.3
8
License: Apache License 2.0
9
License URI: https://www.apache.org/licenses/LICENSE-2.0
10
Tags: google, search-console, analytics, adsense, pagespeed-insights, optimize, tag-manager, site-kit
4
Requires at least: 4.7
5
Tested up to: 5.3
6
Requires PHP: 5.4
7
+ Stable tag: 1.0.4
8
License: Apache License 2.0
9
License URI: https://www.apache.org/licenses/LICENSE-2.0
10
Tags: google, search-console, analytics, adsense, pagespeed-insights, optimize, tag-manager, site-kit
third-party/monolog/monolog/src/Monolog/Formatter/FluentdFormatter.php CHANGED
@@ -10,6 +10,7 @@
10
*/
11
namespace Google\Site_Kit_Dependencies\Monolog\Formatter;
12
13
/**
14
* Class FluentdFormatter
15
*
@@ -59,7 +60,7 @@ class FluentdFormatter implements \Google\Site_Kit_Dependencies\Monolog\Formatte
59
$message['level'] = $record['level'];
60
$message['level_name'] = $record['level_name'];
61
}
62
- return \json_encode(array($tag, $record['datetime']->getTimestamp(), $message));
63
}
64
public function formatBatch(array $records)
65
{
10
*/
11
namespace Google\Site_Kit_Dependencies\Monolog\Formatter;
12
13
+ use Google\Site_Kit_Dependencies\Monolog\Utils;
14
/**
15
* Class FluentdFormatter
16
*
60
$message['level'] = $record['level'];
61
$message['level_name'] = $record['level_name'];
62
}
63
+ return \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode(array($tag, $record['datetime']->getTimestamp(), $message));
64
}
65
public function formatBatch(array $records)
66
{
third-party/monolog/monolog/src/Monolog/Formatter/HtmlFormatter.php CHANGED
@@ -11,6 +11,7 @@
11
namespace Google\Site_Kit_Dependencies\Monolog\Formatter;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
/**
15
* Formats incoming records into an HTML table
16
*
@@ -111,8 +112,8 @@ class HtmlFormatter extends \Google\Site_Kit_Dependencies\Monolog\Formatter\Norm
111
}
112
$data = $this->normalize($data);
113
if (\version_compare(\PHP_VERSION, '5.4.0', '>=')) {
114
- return \json_encode($data, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
115
}
116
- return \str_replace('\\/', '/', \json_encode($data));
117
}
118
}
11
namespace Google\Site_Kit_Dependencies\Monolog\Formatter;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
+ use Google\Site_Kit_Dependencies\Monolog\Utils;
15
/**
16
* Formats incoming records into an HTML table
17
*
112
}
113
$data = $this->normalize($data);
114
if (\version_compare(\PHP_VERSION, '5.4.0', '>=')) {
115
+ return \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode($data, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE, \true);
116
}
117
+ return \str_replace('\\/', '/', \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode($data, null, \true));
118
}
119
}
third-party/monolog/monolog/src/Monolog/Formatter/JsonFormatter.php CHANGED
@@ -128,7 +128,7 @@ class JsonFormatter extends \Google\Site_Kit_Dependencies\Monolog\Formatter\Norm
128
if ($depth > 9) {
129
return 'Over 9 levels deep, aborting normalization';
130
}
131
- if (\is_array($data) || $data instanceof \Traversable) {
132
$normalized = array();
133
$count = 1;
134
foreach ($data as $key => $value) {
@@ -159,7 +159,7 @@ class JsonFormatter extends \Google\Site_Kit_Dependencies\Monolog\Formatter\Norm
159
if (!$e instanceof \Exception && !$e instanceof \Throwable) {
160
throw new \InvalidArgumentException('Exception/Throwable expected, got ' . \gettype($e) . ' / ' . \Google\Site_Kit_Dependencies\Monolog\Utils::getClass($e));
161
}
162
- $data = array('class' => \Google\Site_Kit_Dependencies\Monolog\Utils::getClass($e), 'message' => $e->getMessage(), 'code' => $e->getCode(), 'file' => $e->getFile() . ':' . $e->getLine());
163
if ($this->includeStacktraces) {
164
$trace = $e->getTrace();
165
foreach ($trace as $frame) {
128
if ($depth > 9) {
129
return 'Over 9 levels deep, aborting normalization';
130
}
131
+ if (\is_array($data)) {
132
$normalized = array();
133
$count = 1;
134
foreach ($data as $key => $value) {
159
if (!$e instanceof \Exception && !$e instanceof \Throwable) {
160
throw new \InvalidArgumentException('Exception/Throwable expected, got ' . \gettype($e) . ' / ' . \Google\Site_Kit_Dependencies\Monolog\Utils::getClass($e));
161
}
162
+ $data = array('class' => \Google\Site_Kit_Dependencies\Monolog\Utils::getClass($e), 'message' => $e->getMessage(), 'code' => (int) $e->getCode(), 'file' => $e->getFile() . ':' . $e->getLine());
163
if ($this->includeStacktraces) {
164
$trace = $e->getTrace();
165
foreach ($trace as $frame) {
third-party/monolog/monolog/src/Monolog/Formatter/LineFormatter.php CHANGED
@@ -135,7 +135,7 @@ class LineFormatter extends \Google\Site_Kit_Dependencies\Monolog\Formatter\Norm
135
if (\version_compare(\PHP_VERSION, '5.4.0', '>=')) {
136
return $this->toJson($data, \true);
137
}
138
- return \str_replace('\\/', '/', @\json_encode($data));
139
}
140
protected function replaceNewlines($str)
141
{
135
if (\version_compare(\PHP_VERSION, '5.4.0', '>=')) {
136
return $this->toJson($data, \true);
137
}
138
+ return \str_replace('\\/', '/', $this->toJson($data, \true));
139
}
140
protected function replaceNewlines($str)
141
{
third-party/monolog/monolog/src/Monolog/Formatter/MongoDBFormatter.php CHANGED
@@ -73,7 +73,7 @@ class MongoDBFormatter implements \Google\Site_Kit_Dependencies\Monolog\Formatte
73
}
74
protected function formatException(\Exception $exception, $nestingLevel)
75
{
76
- $formattedException = array('class' => \Google\Site_Kit_Dependencies\Monolog\Utils::getClass($exception), 'message' => $exception->getMessage(), 'code' => $exception->getCode(), 'file' => $exception->getFile() . ':' . $exception->getLine());
77
if ($this->exceptionTraceAsString === \true) {
78
$formattedException['trace'] = $exception->getTraceAsString();
79
} else {
73
}
74
protected function formatException(\Exception $exception, $nestingLevel)
75
{
76
+ $formattedException = array('class' => \Google\Site_Kit_Dependencies\Monolog\Utils::getClass($exception), 'message' => $exception->getMessage(), 'code' => (int) $exception->getCode(), 'file' => $exception->getFile() . ':' . $exception->getLine());
77
if ($this->exceptionTraceAsString === \true) {
78
$formattedException['trace'] = $exception->getTraceAsString();
79
} else {
third-party/monolog/monolog/src/Monolog/Formatter/NormalizerFormatter.php CHANGED
@@ -104,7 +104,7 @@ class NormalizerFormatter implements \Google\Site_Kit_Dependencies\Monolog\Forma
104
if (!$e instanceof \Exception && !$e instanceof \Throwable) {
105
throw new \InvalidArgumentException('Exception/Throwable expected, got ' . \gettype($e) . ' / ' . \Google\Site_Kit_Dependencies\Monolog\Utils::getClass($e));
106
}
107
- $data = array('class' => \Google\Site_Kit_Dependencies\Monolog\Utils::getClass($e), 'message' => $e->getMessage(), 'code' => $e->getCode(), 'file' => $e->getFile() . ':' . $e->getLine());
108
if ($e instanceof \SoapFault) {
109
if (isset($e->faultcode)) {
110
$data['faultcode'] = $e->faultcode;
@@ -112,8 +112,8 @@ class NormalizerFormatter implements \Google\Site_Kit_Dependencies\Monolog\Forma
112
if (isset($e->faultactor)) {
113
$data['faultactor'] = $e->faultactor;
114
}
115
- if (isset($e->detail)) {
116
- $data['detail'] = $e->detail;
117
}
118
}
119
$trace = $e->getTrace();
@@ -137,108 +137,6 @@ class NormalizerFormatter implements \Google\Site_Kit_Dependencies\Monolog\Forma
137
*/
138
protected function toJson($data, $ignoreErrors = \false)
139
{
140
- // suppress json_encode errors since it's twitchy with some inputs
141
- if ($ignoreErrors) {
142
- return @$this->jsonEncode($data);
143
- }
144
- $json = $this->jsonEncode($data);
145
- if ($json === \false) {
146
- $json = $this->handleJsonError(\json_last_error(), $data);
147
- }
148
- return $json;
149
- }
150
- /**
151
- * @param mixed $data
152
- * @return string JSON encoded data or null on failure
153
- */
154
- private function jsonEncode($data)
155
- {
156
- if (\version_compare(\PHP_VERSION, '5.4.0', '>=')) {
157
- return \json_encode($data, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
158
- }
159
- return \json_encode($data);
160
- }
161
- /**
162
- * Handle a json_encode failure.
163
- *
164
- * If the failure is due to invalid string encoding, try to clean the
165
- * input and encode again. If the second encoding attempt fails, the
166
- * inital error is not encoding related or the input can't be cleaned then
167
- * raise a descriptive exception.
168
- *
169
- * @param int $code return code of json_last_error function
170
- * @param mixed $data data that was meant to be encoded
171
- * @throws \RuntimeException if failure can't be corrected
172
- * @return string JSON encoded data after error correction
173
- */
174
- private function handleJsonError($code, $data)
175
- {
176
- if ($code !== \JSON_ERROR_UTF8) {
177
- $this->throwEncodeError($code, $data);
178
- }
179
- if (\is_string($data)) {
180
- $this->detectAndCleanUtf8($data);
181
- } elseif (\is_array($data)) {
182
- \array_walk_recursive($data, array($this, 'detectAndCleanUtf8'));
183
- } else {
184
- $this->throwEncodeError($code, $data);
185
- }
186
- $json = $this->jsonEncode($data);
187
- if ($json === \false) {
188
- $this->throwEncodeError(\json_last_error(), $data);
189
- }
190
- return $json;
191
- }
192
- /**
193
- * Throws an exception according to a given code with a customized message
194
- *
195
- * @param int $code return code of json_last_error function
196
- * @param mixed $data data that was meant to be encoded
197
- * @throws \RuntimeException
198
- */
199
- private function throwEncodeError($code, $data)
200
- {
201
- switch ($code) {
202
- case \JSON_ERROR_DEPTH:
203
- $msg = 'Maximum stack depth exceeded';
204
- break;
205
- case \JSON_ERROR_STATE_MISMATCH:
206
- $msg = 'Underflow or the modes mismatch';
207
- break;
208
- case \JSON_ERROR_CTRL_CHAR:
209
- $msg = 'Unexpected control character found';
210
- break;
211
- case \JSON_ERROR_UTF8:
212
- $msg = 'Malformed UTF-8 characters, possibly incorrectly encoded';
213
- break;
214
- default:
215
- $msg = 'Unknown error';
216
- }
217
- throw new \RuntimeException('JSON encoding failed: ' . $msg . '. Encoding: ' . \var_export($data, \true));
218
- }
219
- /**
220
- * Detect invalid UTF-8 string characters and convert to valid UTF-8.
221
- *
222
- * Valid UTF-8 input will be left unmodified, but strings containing
223
- * invalid UTF-8 codepoints will be reencoded as UTF-8 with an assumed
224
- * original encoding of ISO-8859-15. This conversion may result in
225
- * incorrect output if the actual encoding was not ISO-8859-15, but it
226
- * will be clean UTF-8 output and will not rely on expensive and fragile
227
- * detection algorithms.
228
- *
229
- * Function converts the input in place in the passed variable so that it
230
- * can be used as a callback for array_walk_recursive.
231
- *
232
- * @param mixed &$data Input to check and convert if needed
233
- * @private
234
- */
235
- public function detectAndCleanUtf8(&$data)
236
- {
237
- if (\is_string($data) && !\preg_match('//u', $data)) {
238
- $data = \preg_replace_callback('/[\\x80-\\xFF]+/', function ($m) {
239
- return \utf8_encode($m[0]);
240
- }, $data);
241
- $data = \str_replace(array('¤', '¦', '¨', '´', '¸', '¼', '½', '¾'), array('€', 'Š', 'š', 'Ž', 'ž', 'Œ', 'œ', 'Ÿ'), $data);
242
- }
243
}
244
}
104
if (!$e instanceof \Exception && !$e instanceof \Throwable) {
105
throw new \InvalidArgumentException('Exception/Throwable expected, got ' . \gettype($e) . ' / ' . \Google\Site_Kit_Dependencies\Monolog\Utils::getClass($e));
106
}
107
+ $data = array('class' => \Google\Site_Kit_Dependencies\Monolog\Utils::getClass($e), 'message' => $e->getMessage(), 'code' => (int) $e->getCode(), 'file' => $e->getFile() . ':' . $e->getLine());
108
if ($e instanceof \SoapFault) {
109
if (isset($e->faultcode)) {
110
$data['faultcode'] = $e->faultcode;
112
if (isset($e->faultactor)) {
113
$data['faultactor'] = $e->faultactor;
114
}
115
+ if (isset($e->detail) && (\is_string($e->detail) || \is_object($e->detail) || \is_array($e->detail))) {
116
+ $data['detail'] = \is_string($e->detail) ? $e->detail : \reset($e->detail);
117
}
118
}
119
$trace = $e->getTrace();
137
*/
138
protected function toJson($data, $ignoreErrors = \false)
139
{
140
+ return \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode($data, null, $ignoreErrors);
141
}
142
}
third-party/monolog/monolog/src/Monolog/Handler/BrowserConsoleHandler.php CHANGED
@@ -141,17 +141,18 @@ class BrowserConsoleHandler extends \Google\Site_Kit_Dependencies\Monolog\Handle
141
}
142
private static function handleStyles($formatted)
143
{
144
- $args = array(static::quote('font-weight: normal'));
145
$format = '%c' . $formatted;
146
\preg_match_all('/\\[\\[(.*?)\\]\\]\\{([^}]*)\\}/s', $format, $matches, \PREG_OFFSET_CAPTURE | \PREG_SET_ORDER);
147
foreach (\array_reverse($matches) as $match) {
148
- $args[] = static::quote(static::handleCustomStyles($match[2][0], $match[1][0]));
149
$args[] = '"font-weight: normal"';
150
$pos = $match[0][1];
151
$format = \substr($format, 0, $pos) . '%c' . $match[1][0] . '%c' . \substr($format, $pos + \strlen($match[0][0]));
152
}
153
- \array_unshift($args, static::quote($format));
154
- return $args;
155
}
156
private static function handleCustomStyles($style, $string)
157
{
141
}
142
private static function handleStyles($formatted)
143
{
144
+ $args = array();
145
$format = '%c' . $formatted;
146
\preg_match_all('/\\[\\[(.*?)\\]\\]\\{([^}]*)\\}/s', $format, $matches, \PREG_OFFSET_CAPTURE | \PREG_SET_ORDER);
147
foreach (\array_reverse($matches) as $match) {
148
$args[] = '"font-weight: normal"';
149
+ $args[] = static::quote(static::handleCustomStyles($match[2][0], $match[1][0]));
150
$pos = $match[0][1];
151
$format = \substr($format, 0, $pos) . '%c' . $match[1][0] . '%c' . \substr($format, $pos + \strlen($match[0][0]));
152
}
153
+ $args[] = static::quote('font-weight: normal');
154
+ $args[] = static::quote($format);
155
+ return \array_reverse($args);
156
}
157
private static function handleCustomStyles($style, $string)
158
{
third-party/monolog/monolog/src/Monolog/Handler/BufferHandler.php CHANGED
@@ -12,6 +12,7 @@ namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
use Google\Site_Kit_Dependencies\Monolog\ResettableInterface;
15
/**
16
* Buffers all records until closing the handler and then pass them as batch.
17
*
@@ -109,4 +110,19 @@ class BufferHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\Abstra
109
$this->handler->reset();
110
}
111
}
112
}
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
use Google\Site_Kit_Dependencies\Monolog\ResettableInterface;
15
+ use Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface;
16
/**
17
* Buffers all records until closing the handler and then pass them as batch.
18
*
110
$this->handler->reset();
111
}
112
}
113
+ /**
114
+ * {@inheritdoc}
115
+ */
116
+ public function setFormatter(\Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface $formatter)
117
+ {
118
+ $this->handler->setFormatter($formatter);
119
+ return $this;
120
+ }
121
+ /**
122
+ * {@inheritdoc}
123
+ */
124
+ public function getFormatter()
125
+ {
126
+ return $this->handler->getFormatter();
127
+ }
128
}
third-party/monolog/monolog/src/Monolog/Handler/ChromePHPHandler.php CHANGED
@@ -12,6 +12,7 @@ namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Formatter\ChromePHPFormatter;
14
use Google\Site_Kit_Dependencies\Monolog\Logger;
15
/**
16
* Handler sending logs to the ChromePHP extension (http://www.chromephp.com/)
17
*
@@ -110,13 +111,13 @@ class ChromePHPHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\Abs
110
}
111
self::$json['request_uri'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
112
}
113
- $json = @\json_encode(self::$json);
114
$data = \base64_encode(\utf8_encode($json));
115
if (\strlen($data) > 3 * 1024) {
116
self::$overflowed = \true;
117
$record = array('message' => 'Incomplete logs, chrome header size limit reached', 'context' => array(), 'level' => \Google\Site_Kit_Dependencies\Monolog\Logger::WARNING, 'level_name' => \Google\Site_Kit_Dependencies\Monolog\Logger::getLevelName(\Google\Site_Kit_Dependencies\Monolog\Logger::WARNING), 'channel' => 'monolog', 'datetime' => new \DateTime(), 'extra' => array());
118
self::$json['rows'][\count(self::$json['rows']) - 1] = $this->getFormatter()->format($record);
119
- $json = @\json_encode(self::$json);
120
$data = \base64_encode(\utf8_encode($json));
121
}
122
if (\trim($data) !== '') {
12
13
use Google\Site_Kit_Dependencies\Monolog\Formatter\ChromePHPFormatter;
14
use Google\Site_Kit_Dependencies\Monolog\Logger;
15
+ use Google\Site_Kit_Dependencies\Monolog\Utils;
16
/**
17
* Handler sending logs to the ChromePHP extension (http://www.chromephp.com/)
18
*
111
}
112
self::$json['request_uri'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
113
}
114
+ $json = \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode(self::$json, null, \true);
115
$data = \base64_encode(\utf8_encode($json));
116
if (\strlen($data) > 3 * 1024) {
117
self::$overflowed = \true;
118
$record = array('message' => 'Incomplete logs, chrome header size limit reached', 'context' => array(), 'level' => \Google\Site_Kit_Dependencies\Monolog\Logger::WARNING, 'level_name' => \Google\Site_Kit_Dependencies\Monolog\Logger::getLevelName(\Google\Site_Kit_Dependencies\Monolog\Logger::WARNING), 'channel' => 'monolog', 'datetime' => new \DateTime(), 'extra' => array());
119
self::$json['rows'][\count(self::$json['rows']) - 1] = $this->getFormatter()->format($record);
120
+ $json = \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode(self::$json, null, \true);
121
$data = \base64_encode(\utf8_encode($json));
122
}
123
if (\trim($data) !== '') {
third-party/monolog/monolog/src/Monolog/Handler/CubeHandler.php CHANGED
@@ -11,6 +11,7 @@
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
/**
15
* Logs to Cube.
16
*
@@ -98,9 +99,9 @@ class CubeHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\Abstract
98
$data['data'] = $record['context'];
99
$data['data']['level'] = $record['level'];
100
if ($this->scheme === 'http') {
101
- $this->writeHttp(\json_encode($data));
102
} else {
103
- $this->writeUdp(\json_encode($data));
104
}
105
}
106
private function writeUdp($data)
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
+ use Google\Site_Kit_Dependencies\Monolog\Utils;
15
/**
16
* Logs to Cube.
17
*
99
$data['data'] = $record['context'];
100
$data['data']['level'] = $record['level'];
101
if ($this->scheme === 'http') {
102
+ $this->writeHttp(\Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode($data));
103
} else {
104
+ $this->writeUdp(\Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode($data));
105
}
106
}
107
private function writeUdp($data)
third-party/monolog/monolog/src/Monolog/Handler/FilterHandler.php CHANGED
@@ -11,6 +11,7 @@
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
/**
15
* Simple handler wrapper that filters records based on a list of levels
16
*
@@ -40,7 +41,7 @@ class FilterHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\Abstra
40
*/
41
protected $bubble;
42
/**
43
- * @param callable|HandlerInterface $handler Handler or factory callable($record, $this).
44
* @param int|array $minLevelOrList A list of levels to accept or a minimum level if maxLevel is provided
45
* @param int $maxLevel Maximum level to accept, only used if $minLevelOrList is not an array
46
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
@@ -93,19 +94,12 @@ class FilterHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\Abstra
93
if (!$this->isHandling($record)) {
94
return \false;
95
}
96
- // The same logic as in FingersCrossedHandler
97
- if (!$this->handler instanceof \Google\Site_Kit_Dependencies\Monolog\Handler\HandlerInterface) {
98
- $this->handler = \call_user_func($this->handler, $record, $this);
99
- if (!$this->handler instanceof \Google\Site_Kit_Dependencies\Monolog\Handler\HandlerInterface) {
100
- throw new \RuntimeException("The factory callable should return a HandlerInterface");
101
- }
102
- }
103
if ($this->processors) {
104
foreach ($this->processors as $processor) {
105
$record = \call_user_func($processor, $record);
106
}
107
}
108
- $this->handler->handle($record);
109
return \false === $this->bubble;
110
}
111
/**
@@ -119,6 +113,38 @@ class FilterHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\Abstra
119
$filtered[] = $record;
120
}
121
}
122
- $this->handler->handleBatch($filtered);
123
}
124
}
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
+ use Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface;
15
/**
16
* Simple handler wrapper that filters records based on a list of levels
17
*
41
*/
42
protected $bubble;
43
/**
44
+ * @param callable|HandlerInterface $handler Handler or factory callable($record|null, $filterHandler).
45
* @param int|array $minLevelOrList A list of levels to accept or a minimum level if maxLevel is provided
46
* @param int $maxLevel Maximum level to accept, only used if $minLevelOrList is not an array
47
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
94
if (!$this->isHandling($record)) {
95
return \false;
96
}
97
if ($this->processors) {
98
foreach ($this->processors as $processor) {
99
$record = \call_user_func($processor, $record);
100
}
101
}
102
+ $this->getHandler($record)->handle($record);
103
return \false === $this->bubble;
104
}
105
/**
113
$filtered[] = $record;
114
}
115
}
116
+ $this->getHandler($filtered[\count($filtered) - 1])->handleBatch($filtered);
117
+ }
118
+ /**
119
+ * Return the nested handler
120
+ *
121
+ * If the handler was provided as a factory callable, this will trigger the handler's instantiation.
122
+ *
123
+ * @return HandlerInterface
124
+ */
125
+ public function getHandler(array $record = null)
126
+ {
127
+ if (!$this->handler instanceof \Google\Site_Kit_Dependencies\Monolog\Handler\HandlerInterface) {
128
+ $this->handler = \call_user_func($this->handler, $record, $this);
129
+ if (!$this->handler instanceof \Google\Site_Kit_Dependencies\Monolog\Handler\HandlerInterface) {
130
+ throw new \RuntimeException("The factory callable should return a HandlerInterface");
131
+ }
132
+ }
133
+ return $this->handler;
134
+ }
135
+ /**
136
+ * {@inheritdoc}
137
+ */
138
+ public function setFormatter(\Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface $formatter)
139
+ {
140
+ $this->getHandler()->setFormatter($formatter);
141
+ return $this;
142
+ }
143
+ /**
144
+ * {@inheritdoc}
145
+ */
146
+ public function getFormatter()
147
+ {
148
+ return $this->getHandler()->getFormatter();
149
}
150
}
third-party/monolog/monolog/src/Monolog/Handler/FingersCrossedHandler.php CHANGED
@@ -14,6 +14,7 @@ use Google\Site_Kit_Dependencies\Monolog\Handler\FingersCrossed\ErrorLevelActiva
14
use Google\Site_Kit_Dependencies\Monolog\Handler\FingersCrossed\ActivationStrategyInterface;
15
use Google\Site_Kit_Dependencies\Monolog\Logger;
16
use Google\Site_Kit_Dependencies\Monolog\ResettableInterface;
17
/**
18
* Buffers all records until a certain level is reached
19
*
@@ -36,7 +37,7 @@ class FingersCrossedHandler extends \Google\Site_Kit_Dependencies\Monolog\Handle
36
protected $stopBuffering;
37
protected $passthruLevel;
38
/**
39
- * @param callable|HandlerInterface $handler Handler or factory callable($record, $fingersCrossedHandler).
40
* @param int|ActivationStrategyInterface $activationStrategy Strategy which determines when this handler takes action
41
* @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
42
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
@@ -79,14 +80,7 @@ class FingersCrossedHandler extends \Google\Site_Kit_Dependencies\Monolog\Handle
79
if ($this->stopBuffering) {
80
$this->buffering = \false;
81
}
82
- if (!$this->handler instanceof \Google\Site_Kit_Dependencies\Monolog\Handler\HandlerInterface) {
83
- $record = \end($this->buffer) ?: null;
84
- $this->handler = \call_user_func($this->handler, $record, $this);
85
- if (!$this->handler instanceof \Google\Site_Kit_Dependencies\Monolog\Handler\HandlerInterface) {
86
- throw new \RuntimeException("The factory callable should return a HandlerInterface");
87
- }
88
- }
89
- $this->handler->handleBatch($this->buffer);
90
$this->buffer = array();
91
}
92
/**
@@ -108,7 +102,7 @@ class FingersCrossedHandler extends \Google\Site_Kit_Dependencies\Monolog\Handle
108
$this->activate();
109
}
110
} else {
111
- $this->handler->handle($record);
112
}
113
return \false === $this->bubble;
114
}
@@ -123,8 +117,8 @@ class FingersCrossedHandler extends \Google\Site_Kit_Dependencies\Monolog\Handle
123
{
124
$this->flushBuffer();
125
parent::reset();
126
- if ($this->handler instanceof \Google\Site_Kit_Dependencies\Monolog\ResettableInterface) {
127
- $this->handler->reset();
128
}
129
}
130
/**
@@ -148,10 +142,42 @@ class FingersCrossedHandler extends \Google\Site_Kit_Dependencies\Monolog\Handle
148
return $record['level'] >= $level;
149
});
150
if (\count($this->buffer) > 0) {
151
- $this->handler->handleBatch($this->buffer);
152
}
153
}
154
$this->buffer = array();
155
$this->buffering = \true;
156
}
157
}
14
use Google\Site_Kit_Dependencies\Monolog\Handler\FingersCrossed\ActivationStrategyInterface;
15
use Google\Site_Kit_Dependencies\Monolog\Logger;
16
use Google\Site_Kit_Dependencies\Monolog\ResettableInterface;
17
+ use Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface;
18
/**
19
* Buffers all records until a certain level is reached
20
*
37
protected $stopBuffering;
38
protected $passthruLevel;
39
/**
40
+ * @param callable|HandlerInterface $handler Handler or factory callable($record|null, $fingersCrossedHandler).
41
* @param int|ActivationStrategyInterface $activationStrategy Strategy which determines when this handler takes action
42
* @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
43
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
80
if ($this->stopBuffering) {
81
$this->buffering = \false;
82
}
83
+ $this->getHandler(\end($this->buffer) ?: null)->handleBatch($this->buffer);
84
$this->buffer = array();
85
}
86
/**
102
$this->activate();
103
}
104
} else {
105
+ $this->getHandler($record)->handle($record);
106
}
107
return \false === $this->bubble;
108
}
117
{
118
$this->flushBuffer();
119
parent::reset();
120
+ if ($this->getHandler() instanceof \Google\Site_Kit_Dependencies\Monolog\ResettableInterface) {
121
+ $this->getHandler()->reset();
122
}
123
}
124
/**
142
return $record['level'] >= $level;
143
});
144
if (\count($this->buffer) > 0) {
145
+ $this->getHandler(\end($this->buffer) ?: null)->handleBatch($this->buffer);
146
}
147
}
148
$this->buffer = array();
149
$this->buffering = \true;
150
}
151
+ /**
152
+ * Return the nested handler
153
+ *
154
+ * If the handler was provided as a factory callable, this will trigger the handler's instantiation.
155
+ *
156
+ * @return HandlerInterface
157
+ */
158
+ public function getHandler(array $record = null)
159
+ {
160
+ if (!$this->handler instanceof \Google\Site_Kit_Dependencies\Monolog\Handler\HandlerInterface) {
161
+ $this->handler = \call_user_func($this->handler, $record, $this);
162
+ if (!$this->handler instanceof \Google\Site_Kit_Dependencies\Monolog\Handler\HandlerInterface) {
163
+ throw new \RuntimeException("The factory callable should return a HandlerInterface");
164
+ }
165
+ }
166
+ return $this->handler;
167
+ }
168
+ /**
169
+ * {@inheritdoc}
170
+ */
171
+ public function setFormatter(\Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface $formatter)
172
+ {
173
+ $this->getHandler()->setFormatter($formatter);
174
+ return $this;
175
+ }
176
+ /**
177
+ * {@inheritdoc}
178
+ */
179
+ public function getFormatter()
180
+ {
181
+ return $this->getHandler()->getFormatter();
182
+ }
183
}
third-party/monolog/monolog/src/Monolog/Handler/FlowdockHandler.php CHANGED
@@ -11,6 +11,7 @@
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
use Google\Site_Kit_Dependencies\Monolog\Formatter\FlowdockFormatter;
15
use Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface;
16
/**
@@ -93,7 +94,7 @@ class FlowdockHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\Sock
93
*/
94
private function buildContent($record)
95
{
96
- return \json_encode($record['formatted']['flowdock']);
97
}
98
/**
99
* Builds the header of the API Call
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
+ use Google\Site_Kit_Dependencies\Monolog\Utils;
15
use Google\Site_Kit_Dependencies\Monolog\Formatter\FlowdockFormatter;
16
use Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface;
17
/**
94
*/
95
private function buildContent($record)
96
{
97
+ return \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode($record['formatted']['flowdock']);
98
}
99
/**
100
* Builds the header of the API Call
third-party/monolog/monolog/src/Monolog/Handler/IFTTTHandler.php CHANGED
@@ -11,6 +11,7 @@
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
/**
15
* IFTTTHandler uses cURL to trigger IFTTT Maker actions
16
*
@@ -44,7 +45,7 @@ class IFTTTHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\Abstrac
44
public function write(array $record)
45
{
46
$postData = array("value1" => $record["channel"], "value2" => $record["level_name"], "value3" => $record["message"]);
47
- $postString = \json_encode($postData);
48
$ch = \curl_init();
49
\curl_setopt($ch, \CURLOPT_URL, "https://maker.ifttt.com/trigger/" . $this->eventName . "/with/key/" . $this->secretKey);
50
\curl_setopt($ch, \CURLOPT_POST, \true);
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
+ use Google\Site_Kit_Dependencies\Monolog\Utils;
15
/**
16
* IFTTTHandler uses cURL to trigger IFTTT Maker actions
17
*
45
public function write(array $record)
46
{
47
$postData = array("value1" => $record["channel"], "value2" => $record["level_name"], "value3" => $record["message"]);
48
+ $postString = \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode($postData);
49
$ch = \curl_init();
50
\curl_setopt($ch, \CURLOPT_URL, "https://maker.ifttt.com/trigger/" . $this->eventName . "/with/key/" . $this->secretKey);
51
\curl_setopt($ch, \CURLOPT_POST, \true);
third-party/monolog/monolog/src/Monolog/Handler/NewRelicHandler.php CHANGED
@@ -11,6 +11,7 @@
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
use Google\Site_Kit_Dependencies\Monolog\Formatter\NormalizerFormatter;
15
/**
16
* Class to record a log on a NewRelic application.
@@ -165,7 +166,7 @@ class NewRelicHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\Abst
165
if (null === $value || \is_scalar($value)) {
166
newrelic_add_custom_parameter($key, $value);
167
} else {
168
- newrelic_add_custom_parameter($key, @\json_encode($value));
169
}
170
}
171
/**
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
+ use Google\Site_Kit_Dependencies\Monolog\Utils;
15
use Google\Site_Kit_Dependencies\Monolog\Formatter\NormalizerFormatter;
16
/**
17
* Class to record a log on a NewRelic application.
166
if (null === $value || \is_scalar($value)) {
167
newrelic_add_custom_parameter($key, $value);
168
} else {
169
+ newrelic_add_custom_parameter($key, \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode($value, null, \true));
170
}
171
}
172
/**
third-party/monolog/monolog/src/Monolog/Handler/PHPConsoleHandler.php CHANGED
@@ -13,6 +13,7 @@ namespace Google\Site_Kit_Dependencies\Monolog\Handler;
13
use Exception;
14
use Google\Site_Kit_Dependencies\Monolog\Formatter\LineFormatter;
15
use Google\Site_Kit_Dependencies\Monolog\Logger;
16
use Google\Site_Kit_Dependencies\PhpConsole\Connector;
17
use Google\Site_Kit_Dependencies\PhpConsole\Handler;
18
use Google\Site_Kit_Dependencies\PhpConsole\Helper;
@@ -191,7 +192,7 @@ class PHPConsoleHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\Ab
191
$tags = $this->getRecordTags($record);
192
$message = $record['message'];
193
if ($record['context']) {
194
- $message .= ' ' . \json_encode($this->connector->getDumper()->dump(\array_filter($record['context'])));
195
}
196
$this->connector->getDebugDispatcher()->dispatchDebug($message, $tags, $this->options['classesPartialsTraceIgnore']);
197
}
13
use Exception;
14
use Google\Site_Kit_Dependencies\Monolog\Formatter\LineFormatter;
15
use Google\Site_Kit_Dependencies\Monolog\Logger;
16
+ use Google\Site_Kit_Dependencies\Monolog\Utils;
17
use Google\Site_Kit_Dependencies\PhpConsole\Connector;
18
use Google\Site_Kit_Dependencies\PhpConsole\Handler;
19
use Google\Site_Kit_Dependencies\PhpConsole\Helper;
192
$tags = $this->getRecordTags($record);
193
$message = $record['message'];
194
if ($record['context']) {
195
+ $message .= ' ' . \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode($this->connector->getDumper()->dump(\array_filter($record['context'])), null, \true);
196
}
197
$this->connector->getDebugDispatcher()->dispatchDebug($message, $tags, $this->options['classesPartialsTraceIgnore']);
198
}
third-party/monolog/monolog/src/Monolog/Handler/SamplingHandler.php CHANGED
@@ -10,6 +10,7 @@
10
*/
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
/**
14
* Sampling handler
15
*
@@ -35,7 +36,7 @@ class SamplingHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\Abst
35
*/
36
protected $factor;
37
/**
38
- * @param callable|HandlerInterface $handler Handler or factory callable($record, $fingersCrossedHandler).
39
* @param int $factor Sample factor
40
*/
41
public function __construct($handler, $factor)
@@ -49,25 +50,50 @@ class SamplingHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\Abst
49
}
50
public function isHandling(array $record)
51
{
52
- return $this->handler->isHandling($record);
53
}
54
public function handle(array $record)
55
{
56
if ($this->isHandling($record) && \mt_rand(1, $this->factor) === 1) {
57
- // The same logic as in FingersCrossedHandler
58
- if (!$this->handler instanceof \Google\Site_Kit_Dependencies\Monolog\Handler\HandlerInterface) {
59
- $this->handler = \call_user_func($this->handler, $record, $this);
60
- if (!$this->handler instanceof \Google\Site_Kit_Dependencies\Monolog\Handler\HandlerInterface) {
61
- throw new \RuntimeException("The factory callable should return a HandlerInterface");
62
- }
63
- }
64
if ($this->processors) {
65
foreach ($this->processors as $processor) {
66
$record = \call_user_func($processor, $record);
67
}
68
}
69
- $this->handler->handle($record);
70
}
71
return \false === $this->bubble;
72
}
73
}
10
*/
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
+ use Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface;
14
/**
15
* Sampling handler
16
*
36
*/
37
protected $factor;
38
/**
39
+ * @param callable|HandlerInterface $handler Handler or factory callable($record|null, $samplingHandler).
40
* @param int $factor Sample factor
41
*/
42
public function __construct($handler, $factor)
50
}
51
public function isHandling(array $record)
52
{
53
+ return $this->getHandler($record)->isHandling($record);
54
}
55
public function handle(array $record)
56
{
57
if ($this->isHandling($record) && \mt_rand(1, $this->factor) === 1) {
58
if ($this->processors) {
59
foreach ($this->processors as $processor) {
60
$record = \call_user_func($processor, $record);
61
}
62
}
63
+ $this->getHandler($record)->handle($record);
64
}
65
return \false === $this->bubble;
66
}
67
+ /**
68
+ * Return the nested handler
69
+ *
70
+ * If the handler was provided as a factory callable, this will trigger the handler's instantiation.
71
+ *
72
+ * @return HandlerInterface
73
+ */
74
+ public function getHandler(array $record = null)
75
+ {
76
+ if (!$this->handler instanceof \Google\Site_Kit_Dependencies\Monolog\Handler\HandlerInterface) {
77
+ $this->handler = \call_user_func($this->handler, $record, $this);
78
+ if (!$this->handler instanceof \Google\Site_Kit_Dependencies\Monolog\Handler\HandlerInterface) {
79
+ throw new \RuntimeException("The factory callable should return a HandlerInterface");
80
+ }
81
+ }
82
+ return $this->handler;
83
+ }
84
+ /**
85
+ * {@inheritdoc}
86
+ */
87
+ public function setFormatter(\Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface $formatter)
88
+ {
89
+ $this->getHandler()->setFormatter($formatter);
90
+ return $this;
91
+ }
92
+ /**
93
+ * {@inheritdoc}
94
+ */
95
+ public function getFormatter()
96
+ {
97
+ return $this->getHandler()->getFormatter();
98
+ }
99
}
third-party/monolog/monolog/src/Monolog/Handler/Slack/SlackRecord.php CHANGED
@@ -11,6 +11,7 @@
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler\Slack;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
use Google\Site_Kit_Dependencies\Monolog\Formatter\NormalizerFormatter;
15
use Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface;
16
/**
@@ -164,9 +165,13 @@ class SlackRecord
164
{
165
$normalized = $this->normalizerFormatter->format($fields);
166
$prettyPrintFlag = \defined('JSON_PRETTY_PRINT') ? \JSON_PRETTY_PRINT : 128;
167
$hasSecondDimension = \count(\array_filter($normalized, 'is_array'));
168
$hasNonNumericKeys = !\count(\array_filter(\array_keys($normalized), 'is_numeric'));
169
- return $hasSecondDimension || $hasNonNumericKeys ? \json_encode($normalized, $prettyPrintFlag) : \json_encode($normalized);
170
}
171
/**
172
* Sets the formatter
11
namespace Google\Site_Kit_Dependencies\Monolog\Handler\Slack;
12
13
use Google\Site_Kit_Dependencies\Monolog\Logger;
14
+ use Google\Site_Kit_Dependencies\Monolog\Utils;
15
use Google\Site_Kit_Dependencies\Monolog\Formatter\NormalizerFormatter;
16
use Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface;
17
/**
165
{
166
$normalized = $this->normalizerFormatter->format($fields);
167
$prettyPrintFlag = \defined('JSON_PRETTY_PRINT') ? \JSON_PRETTY_PRINT : 128;
168
+ $flags = 0;
169
+ if (\PHP_VERSION_ID >= 50400) {
170
+ $flags = \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE;
171
+ }
172
$hasSecondDimension = \count(\array_filter($normalized, 'is_array'));
173
$hasNonNumericKeys = !\count(\array_filter(\array_keys($normalized), 'is_numeric'));
174
+ return $hasSecondDimension || $hasNonNumericKeys ? \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode($normalized, $prettyPrintFlag | $flags) : \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode($normalized, $flags);
175
}
176
/**
177
* Sets the formatter
third-party/monolog/monolog/src/Monolog/Handler/SlackHandler.php CHANGED
@@ -12,6 +12,7 @@ namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface;
14
use Google\Site_Kit_Dependencies\Monolog\Logger;
15
use Google\Site_Kit_Dependencies\Monolog\Handler\Slack\SlackRecord;
16
/**
17
* Sends notifications through Slack API
@@ -94,7 +95,7 @@ class SlackHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\SocketH
94
$dataArray = $this->slackRecord->getSlackData($record);
95
$dataArray['token'] = $this->token;
96
if (!empty($dataArray['attachments'])) {
97
- $dataArray['attachments'] = \json_encode($dataArray['attachments']);
98
}
99
return $dataArray;
100
}
12
13
use Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface;
14
use Google\Site_Kit_Dependencies\Monolog\Logger;
15
+ use Google\Site_Kit_Dependencies\Monolog\Utils;
16
use Google\Site_Kit_Dependencies\Monolog\Handler\Slack\SlackRecord;
17
/**
18
* Sends notifications through Slack API
95
$dataArray = $this->slackRecord->getSlackData($record);
96
$dataArray['token'] = $this->token;
97
if (!empty($dataArray['attachments'])) {
98
+ $dataArray['attachments'] = \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode($dataArray['attachments']);
99
}
100
return $dataArray;
101
}
third-party/monolog/monolog/src/Monolog/Handler/SlackWebhookHandler.php CHANGED
@@ -12,6 +12,7 @@ namespace Google\Site_Kit_Dependencies\Monolog\Handler;
12
13
use Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface;
14
use Google\Site_Kit_Dependencies\Monolog\Logger;
15
use Google\Site_Kit_Dependencies\Monolog\Handler\Slack\SlackRecord;
16
/**
17
* Sends notifications through Slack Webhooks
@@ -65,7 +66,7 @@ class SlackWebhookHandler extends \Google\Site_Kit_Dependencies\Monolog\Handler\
65
protected function write(array $record)
66
{
67
$postData = $this->slackRecord->getSlackData($record);
68
- $postString = \json_encode($postData);
69
$ch = \curl_init();
70
$options = array(\CURLOPT_URL => $this->webhookUrl, \CURLOPT_POST => \true, \CURLOPT_RETURNTRANSFER => \true, \CURLOPT_HTTPHEADER => array('Content-type: application/json'), \CURLOPT_POSTFIELDS => $postString);
71
if (\defined('CURLOPT_SAFE_UPLOAD')) {
12
13
use Google\Site_Kit_Dependencies\Monolog\Formatter\FormatterInterface;
14
use Google\Site_Kit_Dependencies\Monolog\Logger;
15
+ use Google\Site_Kit_Dependencies\Monolog\Utils;
16
use Google\Site_Kit_Dependencies\Monolog\Handler\Slack\SlackRecord;
17
/**
18
* Sends notifications through Slack Webhooks
66
protected function write(array $record)
67
{
68
$postData = $this->slackRecord->getSlackData($record);
69
+ $postString = \Google\Site_Kit_Dependencies\Monolog\Utils::jsonEncode($postData);
70
$ch = \curl_init();
71
$options = array(\CURLOPT_URL => $this->webhookUrl, \CURLOPT_POST => \true, \CURLOPT_RETURNTRANSFER => \true, \CURLOPT_HTTPHEADER => array('Content-type: application/json'), \CURLOPT_POSTFIELDS => $postString);
72
if (\defined('CURLOPT_SAFE_UPLOAD')) {
third-party/monolog/monolog/src/Monolog/Utils.php CHANGED
@@ -20,4 +20,118 @@ class Utils
20
$class = \get_class($object);
21
return 'c' === $class[0] && 0 === \strpos($class, "class@anonymous\0") ? \get_parent_class($class) . '@anonymous' : $class;
22
}
23
}
20
$class = \get_class($object);
21
return 'c' === $class[0] && 0 === \strpos($class, "class@anonymous\0") ? \get_parent_class($class) . '@anonymous' : $class;
22
}
23
+ /**
24
+ * Return the JSON representation of a value
25
+ *
26
+ * @param mixed $data
27
+ * @param int $encodeFlags flags to pass to json encode, defaults to JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
28
+ * @param bool $ignoreErrors whether to ignore encoding errors or to throw on error, when ignored and the encoding fails, "null" is returned which is valid json for null
29
+ * @throws \RuntimeException if encoding fails and errors are not ignored
30
+ * @return string
31
+ */
32
+ public static function jsonEncode($data, $encodeFlags = null, $ignoreErrors = \false)
33
+ {
34
+ if (null === $encodeFlags && \version_compare(\PHP_VERSION, '5.4.0', '>=')) {
35
+ $encodeFlags = \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE;
36
+ }
37
+ if ($ignoreErrors) {
38
+ $json = @\json_encode($data, $encodeFlags);
39
+ if (\false === $json) {
40
+ return 'null';
41
+ }
42
+ return $json;
43
+ }
44
+ $json = \json_encode($data, $encodeFlags);
45
+ if (\false === $json) {
46
+ $json = self::handleJsonError(\json_last_error(), $data);
47
+ }
48
+ return $json;
49
+ }
50
+ /**
51
+ * Handle a json_encode failure.
52
+ *
53
+ * If the failure is due to invalid string encoding, try to clean the
54
+ * input and encode again. If the second encoding attempt fails, the
55
+ * inital error is not encoding related or the input can't be cleaned then
56
+ * raise a descriptive exception.
57
+ *
58
+ * @param int $code return code of json_last_error function
59
+ * @param mixed $data data that was meant to be encoded
60
+ * @param int $encodeFlags flags to pass to json encode, defaults to JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
61
+ * @throws \RuntimeException if failure can't be corrected
62
+ * @return string JSON encoded data after error correction
63
+ */
64
+ public static function handleJsonError($code, $data, $encodeFlags = null)
65
+ {
66
+ if ($code !== \JSON_ERROR_UTF8) {
67
+ self::throwEncodeError($code, $data);
68
+ }
69
+ if (\is_string($data)) {
70
+ self::detectAndCleanUtf8($data);
71
+ } elseif (\is_array($data)) {
72
+ \array_walk_recursive($data, array('Monolog\\Utils', 'detectAndCleanUtf8'));
73
+ } else {
74
+ self::throwEncodeError($code, $data);
75
+ }
76
+ if (null === $encodeFlags && \version_compare(\PHP_VERSION, '5.4.0', '>=')) {
77
+ $encodeFlags = \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE;
78
+ }
79
+ $json = \json_encode($data, $encodeFlags);
80
+ if ($json === \false) {
81
+ self::throwEncodeError(\json_last_error(), $data);
82
+ }
83
+ return $json;
84
+ }
85
+ /**
86
+ * Throws an exception according to a given code with a customized message
87
+ *
88
+ * @param int $code return code of json_last_error function
89
+ * @param mixed $data data that was meant to be encoded
90
+ * @throws \RuntimeException
91
+ */
92
+ private static function throwEncodeError($code, $data)
93
+ {
94
+ switch ($code) {
95
+ case \JSON_ERROR_DEPTH:
96
+ $msg = 'Maximum stack depth exceeded';
97
+ break;
98
+ case \JSON_ERROR_STATE_MISMATCH:
99
+ $msg = 'Underflow or the modes mismatch';
100
+ break;
101
+ case \JSON_ERROR_CTRL_CHAR:
102
+ $msg = 'Unexpected control character found';
103
+ break;
104
+ case \JSON_ERROR_UTF8:
105
+ $msg = 'Malformed UTF-8 characters, possibly incorrectly encoded';
106
+ break;
107
+ default:
108
+ $msg = 'Unknown error';
109
+ }
110
+ throw new \RuntimeException('JSON encoding failed: ' . $msg . '. Encoding: ' . \var_export($data, \true));
111
+ }
112
+ /**
113
+ * Detect invalid UTF-8 string characters and convert to valid UTF-8.
114
+ *
115
+ * Valid UTF-8 input will be left unmodified, but strings containing
116
+ * invalid UTF-8 codepoints will be reencoded as UTF-8 with an assumed
117
+ * original encoding of ISO-8859-15. This conversion may result in
118
+ * incorrect output if the actual encoding was not ISO-8859-15, but it
119
+ * will be clean UTF-8 output and will not rely on expensive and fragile
120
+ * detection algorithms.
121
+ *
122
+ * Function converts the input in place in the passed variable so that it
123
+ * can be used as a callback for array_walk_recursive.
124
+ *
125
+ * @param mixed &$data Input to check and convert if needed
126
+ * @private
127
+ */
128
+ public static function detectAndCleanUtf8(&$data)
129
+ {
130
+ if (\is_string($data) && !\preg_match('//u', $data)) {
131
+ $data = \preg_replace_callback('/[\\x80-\\xFF]+/', function ($m) {
132
+ return \utf8_encode($m[0]);
133
+ }, $data);
134
+ $data = \str_replace(array('¤', '¦', '¨', '´', '¸', '¼', '½', '¾'), array('€', 'Š', 'š', 'Ž', 'ž', 'Œ', 'œ', 'Ÿ'), $data);
135
+ }
136
+ }
137
}