Passed
Push — master ( 925e6d...054ae2 )
by Paul
08:03 queued 03:39
created
plugin/Defaults/ValidateReviewDefaults.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -6,22 +6,22 @@
 block discarded – undo
6 6
 
7 7
 class ValidateReviewDefaults extends Defaults
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    protected function defaults()
13
-    {
14
-        return [
15
-            'assign_to' => '',
16
-            'category' => '',
17
-            'content' => '',
18
-            'email' => '',
19
-            'form_id' => '',
20
-            'ip_address' => '',
21
-            'name' => '',
22
-            'rating' => '0',
23
-            'terms' => '',
24
-            'title' => '',
25
-        ];
26
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	protected function defaults()
13
+	{
14
+		return [
15
+			'assign_to' => '',
16
+			'category' => '',
17
+			'content' => '',
18
+			'email' => '',
19
+			'form_id' => '',
20
+			'ip_address' => '',
21
+			'name' => '',
22
+			'rating' => '0',
23
+			'terms' => '',
24
+			'title' => '',
25
+		];
26
+	}
27 27
 }
Please login to merge, or discard this patch.
plugin/Modules/Console.php 1 patch
Indentation   +433 added lines, -433 removed lines patch added patch discarded remove patch
@@ -10,437 +10,437 @@
 block discarded – undo
10 10
 
11 11
 class Console
12 12
 {
13
-    const DEBUG = 0;      // Detailed debug information
14
-    const INFO = 1;       // Interesting events
15
-    const NOTICE = 2;     // Normal but significant events
16
-    const WARNING = 4;    // Exceptional occurrences that are not errors
17
-    const ERROR = 8;      // Runtime errors that do not require immediate action
18
-    const CRITICAL = 16;  // Critical conditions
19
-    const ALERT = 32;     // Action must be taken immediately
20
-    const EMERGENCY = 64; // System is unusable
21
-
22
-    protected $file;
23
-    protected $log;
24
-    protected $logOnceKey = 'glsr_log_once';
25
-
26
-    public function __construct()
27
-    {
28
-        $this->file = glsr()->path('console.log');
29
-        $this->log = file_exists($this->file)
30
-            ? file_get_contents($this->file)
31
-            : '';
32
-        $this->reset();
33
-    }
34
-
35
-    /**
36
-     * @return string
37
-     */
38
-    public function __toString()
39
-    {
40
-        return $this->get();
41
-    }
42
-
43
-    /**
44
-     * Action must be taken immediately
45
-     * Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
46
-     * @param mixed $message
47
-     * @param array $context
48
-     * @return static
49
-     */
50
-    public function alert($message, array $context = [])
51
-    {
52
-        return $this->log(static::ALERT, $message, $context);
53
-    }
54
-
55
-    /**
56
-     * @return void
57
-     */
58
-    public function clear()
59
-    {
60
-        $this->log = '';
61
-        file_put_contents($this->file, $this->log);
62
-    }
63
-
64
-    /**
65
-     * Critical conditions
66
-     * Example: Application component unavailable, unexpected exception.
67
-     * @param mixed $message
68
-     * @param array $context
69
-     * @return static
70
-     */
71
-    public function critical($message, array $context = [])
72
-    {
73
-        return $this->log(static::CRITICAL, $message, $context);
74
-    }
75
-
76
-    /**
77
-     * Detailed debug information.
78
-     * @param mixed $message
79
-     * @param array $context
80
-     * @return static
81
-     */
82
-    public function debug($message, array $context = [])
83
-    {
84
-        return $this->log(static::DEBUG, $message, $context);
85
-    }
86
-
87
-    /**
88
-     * System is unusable.
89
-     * @param mixed $message
90
-     * @param array $context
91
-     * @return static
92
-     */
93
-    public function emergency($message, array $context = [])
94
-    {
95
-        return $this->log(static::EMERGENCY, $message, $context);
96
-    }
97
-
98
-    /**
99
-     * Runtime errors that do not require immediate action but should typically be logged and monitored.
100
-     * @param mixed $message
101
-     * @param array $context
102
-     * @return static
103
-     */
104
-    public function error($message, array $context = [])
105
-    {
106
-        return $this->log(static::ERROR, $message, $context);
107
-    }
108
-
109
-    /**
110
-     * @return string
111
-     */
112
-    public function get()
113
-    {
114
-        return empty($this->log)
115
-            ? __('Console is empty', 'site-reviews')
116
-            : $this->log;
117
-    }
118
-
119
-    /**
120
-     * @return int
121
-     */
122
-    public function getLevel()
123
-    {
124
-        return intval(apply_filters('site-reviews/console/level', static::INFO));
125
-    }
126
-
127
-    /**
128
-     * @return array
129
-     */
130
-    public function getLevels()
131
-    {
132
-        $constants = (new ReflectionClass(__CLASS__))->getConstants();
133
-        return array_map('strtolower', array_flip($constants));
134
-    }
135
-
136
-    /**
137
-     * @return string
138
-     */
139
-    public function humanLevel()
140
-    {
141
-        $level = $this->getLevel();
142
-        return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level);
143
-    }
144
-
145
-    /**
146
-     * @param string|null $valueIfEmpty
147
-     * @return string
148
-     */
149
-    public function humanSize($valueIfEmpty = null)
150
-    {
151
-        $bytes = $this->size();
152
-        if (empty($bytes) && is_string($valueIfEmpty)) {
153
-            return $valueIfEmpty;
154
-        }
155
-        $exponent = floor(log(max($bytes, 1), 1024));
156
-        return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent];
157
-    }
158
-
159
-    /**
160
-     * Interesting events
161
-     * Example: User logs in, SQL logs.
162
-     * @param mixed $message
163
-     * @param array $context
164
-     * @return static
165
-     */
166
-    public function info($message, array $context = [])
167
-    {
168
-        return $this->log(static::INFO, $message, $context);
169
-    }
170
-
171
-    /**
172
-     * @param int $level
173
-     * @param mixed $message
174
-     * @param array $context
175
-     * @param string $backtraceLine
176
-     * @return static
177
-     */
178
-    public function log($level, $message, $context = [], $backtraceLine = '')
179
-    {
180
-        if (empty($backtraceLine)) {
181
-            $backtraceLine = $this->getBacktraceLine();
182
-        }
183
-        if ($this->canLogEntry($level, $backtraceLine)) {
184
-            $levelName = Arr::get($this->getLevels(), $level);
185
-            $context = Arr::consolidateArray($context);
186
-            $backtraceLine = $this->normalizeBacktraceLine($backtraceLine);
187
-            $message = $this->interpolate($message, $context);
188
-            $entry = $this->buildLogEntry($levelName, $message, $backtraceLine);
189
-            file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX);
190
-            apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed
191
-            $this->reset();
192
-        }
193
-        return $this;
194
-    }
195
-
196
-    /**
197
-     * @return void
198
-     */
199
-    public function logOnce()
200
-    {
201
-        $once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
202
-        $levels = $this->getLevels();
203
-        foreach ($once as $entry) {
204
-            $levelName = Arr::get($entry, 'level');
205
-            if (!in_array($levelName, $levels)) {
206
-                continue;
207
-            }
208
-            $level = Arr::get(array_flip($levels), $levelName);
209
-            $message = Arr::get($entry, 'message');
210
-            $backtraceLine = Arr::get($entry, 'backtrace');
211
-            $this->log($level, $message, [], $backtraceLine);
212
-        }
213
-        glsr()->{$this->logOnceKey} = [];
214
-    }
215
-
216
-    /**
217
-     * Normal but significant events.
218
-     * @param mixed $message
219
-     * @param array $context
220
-     * @return static
221
-     */
222
-    public function notice($message, array $context = [])
223
-    {
224
-        return $this->log(static::NOTICE, $message, $context);
225
-    }
226
-
227
-    /**
228
-     * @param string $levelName
229
-     * @param string $handle
230
-     * @param mixed $data
231
-     * @return void
232
-     */
233
-    public function once($levelName, $handle, $data)
234
-    {
235
-        $once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
236
-        $filtered = array_filter($once, function ($entry) use ($levelName, $handle) {
237
-            return Arr::get($entry, 'level') == $levelName
238
-                && Arr::get($entry, 'handle') == $handle;
239
-        });
240
-        if (!empty($filtered)) {
241
-            return;
242
-        }
243
-        $once[] = [
244
-            'backtrace' => $this->getBacktraceLineFromData($data),
245
-            'handle' => $handle,
246
-            'level' => $levelName,
247
-            'message' => '[RECURRING] '.$this->getMessageFromData($data),
248
-        ];
249
-        glsr()->{$this->logOnceKey} = $once;
250
-    }
251
-
252
-    /**
253
-     * @return int
254
-     */
255
-    public function size()
256
-    {
257
-        return file_exists($this->file)
258
-            ? filesize($this->file)
259
-            : 0;
260
-    }
261
-
262
-    /**
263
-     * Exceptional occurrences that are not errors
264
-     * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
265
-     * @param mixed $message
266
-     * @param array $context
267
-     * @return static
268
-     */
269
-    public function warning($message, array $context = [])
270
-    {
271
-        return $this->log(static::WARNING, $message, $context);
272
-    }
273
-
274
-    /**
275
-     * @param array $backtrace
276
-     * @param int $index
277
-     * @return string
278
-     */
279
-    protected function buildBacktraceLine($backtrace, $index)
280
-    {
281
-        return sprintf('%s:%s',
282
-            Arr::get($backtrace, $index.'.file'), // realpath
283
-            Arr::get($backtrace, $index.'.line')
284
-        );
285
-    }
286
-
287
-    /**
288
-     * @param string $levelName
289
-     * @param mixed $message
290
-     * @param string $backtraceLine
291
-     * @return string
292
-     */
293
-    protected function buildLogEntry($levelName, $message, $backtraceLine = '')
294
-    {
295
-        return sprintf('[%s] %s [%s] %s',
296
-            current_time('mysql'),
297
-            strtoupper($levelName),
298
-            $backtraceLine,
299
-            $message
300
-        );
301
-    }
302
-
303
-    /**
304
-     * @param int $level
305
-     * @return bool
306
-     */
307
-    protected function canLogEntry($level, $backtraceLine)
308
-    {
309
-        $levelExists = array_key_exists($level, $this->getLevels());
310
-        if (!Str::contains($backtraceLine, glsr()->path())) {
311
-            return $levelExists; // ignore level restriction if triggered outside of the plugin
312
-        }
313
-        return $levelExists && $level >= $this->getLevel();
314
-    }
315
-
316
-    /**
317
-     * @return void|string
318
-     */
319
-    protected function getBacktraceLine()
320
-    {
321
-        $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6);
322
-        $search = array_search('glsr_log', glsr_array_column($backtrace, 'function'));
323
-        if (false !== $search) {
324
-            return $this->buildBacktraceLine($backtrace, (int) $search);
325
-        }
326
-        $search = array_search('log', glsr_array_column($backtrace, 'function'));
327
-        if (false !== $search) {
328
-            $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function')
329
-                ? $search + 4
330
-                : $search + 1;
331
-            return $this->buildBacktraceLine($backtrace, $index);
332
-        }
333
-        return 'Unknown';
334
-    }
335
-
336
-    /**
337
-     * @param mixed $data
338
-     * @return string
339
-     */
340
-    protected function getBacktraceLineFromData($data)
341
-    {
342
-        $backtrace = $data instanceof Throwable
343
-            ? $data->getTrace()
344
-            : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
345
-        return $this->buildBacktraceLine($backtrace, 0);
346
-    }
347
-
348
-    /**
349
-     * @param mixed $data
350
-     * @return string
351
-     */
352
-    protected function getMessageFromData($data)
353
-    {
354
-        return $data instanceof Throwable
355
-            ? $this->normalizeThrowableMessage($data->getMessage())
356
-            : print_r($data, 1);
357
-    }
358
-
359
-    /**
360
-     * Interpolates context values into the message placeholders.
361
-     * @param mixed $message
362
-     * @param array $context
363
-     * @return string
364
-     */
365
-    protected function interpolate($message, $context = [])
366
-    {
367
-        if ($this->isObjectOrArray($message) || !is_array($context)) {
368
-            return print_r($message, true);
369
-        }
370
-        $replace = [];
371
-        foreach ($context as $key => $value) {
372
-            $replace['{'.$key.'}'] = $this->normalizeValue($value);
373
-        }
374
-        return strtr($message, $replace);
375
-    }
376
-
377
-    /**
378
-     * @param mixed $value
379
-     * @return bool
380
-     */
381
-    protected function isObjectOrArray($value)
382
-    {
383
-        return is_object($value) || is_array($value);
384
-    }
385
-
386
-    /**
387
-     * @param string $backtraceLine
388
-     * @return string
389
-     */
390
-    protected function normalizeBacktraceLine($backtraceLine)
391
-    {
392
-        $search = [
393
-            glsr()->path('plugin/'),
394
-            glsr()->path('plugin/', false),
395
-            trailingslashit(glsr()->path()),
396
-            trailingslashit(glsr()->path('', false)),
397
-            WP_CONTENT_DIR,
398
-            ABSPATH,
399
-        ];
400
-        return str_replace(array_unique($search), '', $backtraceLine);
401
-    }
402
-
403
-    /**
404
-     * @param string $message
405
-     * @return string
406
-     */
407
-    protected function normalizeThrowableMessage($message)
408
-    {
409
-        $calledIn = strpos($message, ', called in');
410
-        return false !== $calledIn
411
-            ? substr($message, 0, $calledIn)
412
-            : $message;
413
-    }
414
-
415
-    /**
416
-     * @param mixed $value
417
-     * @return string
418
-     */
419
-    protected function normalizeValue($value)
420
-    {
421
-        if ($value instanceof DateTime) {
422
-            $value = $value->format('Y-m-d H:i:s');
423
-        } elseif ($this->isObjectOrArray($value)) {
424
-            $value = json_encode($value);
425
-        }
426
-        return (string) $value;
427
-    }
428
-
429
-    /**
430
-     * @return void
431
-     */
432
-    protected function reset()
433
-    {
434
-        if ($this->size() <= pow(1024, 2) / 8) {
435
-            return;
436
-        }
437
-        $this->clear();
438
-        file_put_contents(
439
-            $this->file,
440
-            $this->buildLogEntry(
441
-                static::NOTICE,
442
-                __('Console was automatically cleared (128 KB maximum size)', 'site-reviews')
443
-            )
444
-        );
445
-    }
13
+	const DEBUG = 0;      // Detailed debug information
14
+	const INFO = 1;       // Interesting events
15
+	const NOTICE = 2;     // Normal but significant events
16
+	const WARNING = 4;    // Exceptional occurrences that are not errors
17
+	const ERROR = 8;      // Runtime errors that do not require immediate action
18
+	const CRITICAL = 16;  // Critical conditions
19
+	const ALERT = 32;     // Action must be taken immediately
20
+	const EMERGENCY = 64; // System is unusable
21
+
22
+	protected $file;
23
+	protected $log;
24
+	protected $logOnceKey = 'glsr_log_once';
25
+
26
+	public function __construct()
27
+	{
28
+		$this->file = glsr()->path('console.log');
29
+		$this->log = file_exists($this->file)
30
+			? file_get_contents($this->file)
31
+			: '';
32
+		$this->reset();
33
+	}
34
+
35
+	/**
36
+	 * @return string
37
+	 */
38
+	public function __toString()
39
+	{
40
+		return $this->get();
41
+	}
42
+
43
+	/**
44
+	 * Action must be taken immediately
45
+	 * Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
46
+	 * @param mixed $message
47
+	 * @param array $context
48
+	 * @return static
49
+	 */
50
+	public function alert($message, array $context = [])
51
+	{
52
+		return $this->log(static::ALERT, $message, $context);
53
+	}
54
+
55
+	/**
56
+	 * @return void
57
+	 */
58
+	public function clear()
59
+	{
60
+		$this->log = '';
61
+		file_put_contents($this->file, $this->log);
62
+	}
63
+
64
+	/**
65
+	 * Critical conditions
66
+	 * Example: Application component unavailable, unexpected exception.
67
+	 * @param mixed $message
68
+	 * @param array $context
69
+	 * @return static
70
+	 */
71
+	public function critical($message, array $context = [])
72
+	{
73
+		return $this->log(static::CRITICAL, $message, $context);
74
+	}
75
+
76
+	/**
77
+	 * Detailed debug information.
78
+	 * @param mixed $message
79
+	 * @param array $context
80
+	 * @return static
81
+	 */
82
+	public function debug($message, array $context = [])
83
+	{
84
+		return $this->log(static::DEBUG, $message, $context);
85
+	}
86
+
87
+	/**
88
+	 * System is unusable.
89
+	 * @param mixed $message
90
+	 * @param array $context
91
+	 * @return static
92
+	 */
93
+	public function emergency($message, array $context = [])
94
+	{
95
+		return $this->log(static::EMERGENCY, $message, $context);
96
+	}
97
+
98
+	/**
99
+	 * Runtime errors that do not require immediate action but should typically be logged and monitored.
100
+	 * @param mixed $message
101
+	 * @param array $context
102
+	 * @return static
103
+	 */
104
+	public function error($message, array $context = [])
105
+	{
106
+		return $this->log(static::ERROR, $message, $context);
107
+	}
108
+
109
+	/**
110
+	 * @return string
111
+	 */
112
+	public function get()
113
+	{
114
+		return empty($this->log)
115
+			? __('Console is empty', 'site-reviews')
116
+			: $this->log;
117
+	}
118
+
119
+	/**
120
+	 * @return int
121
+	 */
122
+	public function getLevel()
123
+	{
124
+		return intval(apply_filters('site-reviews/console/level', static::INFO));
125
+	}
126
+
127
+	/**
128
+	 * @return array
129
+	 */
130
+	public function getLevels()
131
+	{
132
+		$constants = (new ReflectionClass(__CLASS__))->getConstants();
133
+		return array_map('strtolower', array_flip($constants));
134
+	}
135
+
136
+	/**
137
+	 * @return string
138
+	 */
139
+	public function humanLevel()
140
+	{
141
+		$level = $this->getLevel();
142
+		return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level);
143
+	}
144
+
145
+	/**
146
+	 * @param string|null $valueIfEmpty
147
+	 * @return string
148
+	 */
149
+	public function humanSize($valueIfEmpty = null)
150
+	{
151
+		$bytes = $this->size();
152
+		if (empty($bytes) && is_string($valueIfEmpty)) {
153
+			return $valueIfEmpty;
154
+		}
155
+		$exponent = floor(log(max($bytes, 1), 1024));
156
+		return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent];
157
+	}
158
+
159
+	/**
160
+	 * Interesting events
161
+	 * Example: User logs in, SQL logs.
162
+	 * @param mixed $message
163
+	 * @param array $context
164
+	 * @return static
165
+	 */
166
+	public function info($message, array $context = [])
167
+	{
168
+		return $this->log(static::INFO, $message, $context);
169
+	}
170
+
171
+	/**
172
+	 * @param int $level
173
+	 * @param mixed $message
174
+	 * @param array $context
175
+	 * @param string $backtraceLine
176
+	 * @return static
177
+	 */
178
+	public function log($level, $message, $context = [], $backtraceLine = '')
179
+	{
180
+		if (empty($backtraceLine)) {
181
+			$backtraceLine = $this->getBacktraceLine();
182
+		}
183
+		if ($this->canLogEntry($level, $backtraceLine)) {
184
+			$levelName = Arr::get($this->getLevels(), $level);
185
+			$context = Arr::consolidateArray($context);
186
+			$backtraceLine = $this->normalizeBacktraceLine($backtraceLine);
187
+			$message = $this->interpolate($message, $context);
188
+			$entry = $this->buildLogEntry($levelName, $message, $backtraceLine);
189
+			file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX);
190
+			apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed
191
+			$this->reset();
192
+		}
193
+		return $this;
194
+	}
195
+
196
+	/**
197
+	 * @return void
198
+	 */
199
+	public function logOnce()
200
+	{
201
+		$once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
202
+		$levels = $this->getLevels();
203
+		foreach ($once as $entry) {
204
+			$levelName = Arr::get($entry, 'level');
205
+			if (!in_array($levelName, $levels)) {
206
+				continue;
207
+			}
208
+			$level = Arr::get(array_flip($levels), $levelName);
209
+			$message = Arr::get($entry, 'message');
210
+			$backtraceLine = Arr::get($entry, 'backtrace');
211
+			$this->log($level, $message, [], $backtraceLine);
212
+		}
213
+		glsr()->{$this->logOnceKey} = [];
214
+	}
215
+
216
+	/**
217
+	 * Normal but significant events.
218
+	 * @param mixed $message
219
+	 * @param array $context
220
+	 * @return static
221
+	 */
222
+	public function notice($message, array $context = [])
223
+	{
224
+		return $this->log(static::NOTICE, $message, $context);
225
+	}
226
+
227
+	/**
228
+	 * @param string $levelName
229
+	 * @param string $handle
230
+	 * @param mixed $data
231
+	 * @return void
232
+	 */
233
+	public function once($levelName, $handle, $data)
234
+	{
235
+		$once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
236
+		$filtered = array_filter($once, function ($entry) use ($levelName, $handle) {
237
+			return Arr::get($entry, 'level') == $levelName
238
+				&& Arr::get($entry, 'handle') == $handle;
239
+		});
240
+		if (!empty($filtered)) {
241
+			return;
242
+		}
243
+		$once[] = [
244
+			'backtrace' => $this->getBacktraceLineFromData($data),
245
+			'handle' => $handle,
246
+			'level' => $levelName,
247
+			'message' => '[RECURRING] '.$this->getMessageFromData($data),
248
+		];
249
+		glsr()->{$this->logOnceKey} = $once;
250
+	}
251
+
252
+	/**
253
+	 * @return int
254
+	 */
255
+	public function size()
256
+	{
257
+		return file_exists($this->file)
258
+			? filesize($this->file)
259
+			: 0;
260
+	}
261
+
262
+	/**
263
+	 * Exceptional occurrences that are not errors
264
+	 * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
265
+	 * @param mixed $message
266
+	 * @param array $context
267
+	 * @return static
268
+	 */
269
+	public function warning($message, array $context = [])
270
+	{
271
+		return $this->log(static::WARNING, $message, $context);
272
+	}
273
+
274
+	/**
275
+	 * @param array $backtrace
276
+	 * @param int $index
277
+	 * @return string
278
+	 */
279
+	protected function buildBacktraceLine($backtrace, $index)
280
+	{
281
+		return sprintf('%s:%s',
282
+			Arr::get($backtrace, $index.'.file'), // realpath
283
+			Arr::get($backtrace, $index.'.line')
284
+		);
285
+	}
286
+
287
+	/**
288
+	 * @param string $levelName
289
+	 * @param mixed $message
290
+	 * @param string $backtraceLine
291
+	 * @return string
292
+	 */
293
+	protected function buildLogEntry($levelName, $message, $backtraceLine = '')
294
+	{
295
+		return sprintf('[%s] %s [%s] %s',
296
+			current_time('mysql'),
297
+			strtoupper($levelName),
298
+			$backtraceLine,
299
+			$message
300
+		);
301
+	}
302
+
303
+	/**
304
+	 * @param int $level
305
+	 * @return bool
306
+	 */
307
+	protected function canLogEntry($level, $backtraceLine)
308
+	{
309
+		$levelExists = array_key_exists($level, $this->getLevels());
310
+		if (!Str::contains($backtraceLine, glsr()->path())) {
311
+			return $levelExists; // ignore level restriction if triggered outside of the plugin
312
+		}
313
+		return $levelExists && $level >= $this->getLevel();
314
+	}
315
+
316
+	/**
317
+	 * @return void|string
318
+	 */
319
+	protected function getBacktraceLine()
320
+	{
321
+		$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6);
322
+		$search = array_search('glsr_log', glsr_array_column($backtrace, 'function'));
323
+		if (false !== $search) {
324
+			return $this->buildBacktraceLine($backtrace, (int) $search);
325
+		}
326
+		$search = array_search('log', glsr_array_column($backtrace, 'function'));
327
+		if (false !== $search) {
328
+			$index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function')
329
+				? $search + 4
330
+				: $search + 1;
331
+			return $this->buildBacktraceLine($backtrace, $index);
332
+		}
333
+		return 'Unknown';
334
+	}
335
+
336
+	/**
337
+	 * @param mixed $data
338
+	 * @return string
339
+	 */
340
+	protected function getBacktraceLineFromData($data)
341
+	{
342
+		$backtrace = $data instanceof Throwable
343
+			? $data->getTrace()
344
+			: debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
345
+		return $this->buildBacktraceLine($backtrace, 0);
346
+	}
347
+
348
+	/**
349
+	 * @param mixed $data
350
+	 * @return string
351
+	 */
352
+	protected function getMessageFromData($data)
353
+	{
354
+		return $data instanceof Throwable
355
+			? $this->normalizeThrowableMessage($data->getMessage())
356
+			: print_r($data, 1);
357
+	}
358
+
359
+	/**
360
+	 * Interpolates context values into the message placeholders.
361
+	 * @param mixed $message
362
+	 * @param array $context
363
+	 * @return string
364
+	 */
365
+	protected function interpolate($message, $context = [])
366
+	{
367
+		if ($this->isObjectOrArray($message) || !is_array($context)) {
368
+			return print_r($message, true);
369
+		}
370
+		$replace = [];
371
+		foreach ($context as $key => $value) {
372
+			$replace['{'.$key.'}'] = $this->normalizeValue($value);
373
+		}
374
+		return strtr($message, $replace);
375
+	}
376
+
377
+	/**
378
+	 * @param mixed $value
379
+	 * @return bool
380
+	 */
381
+	protected function isObjectOrArray($value)
382
+	{
383
+		return is_object($value) || is_array($value);
384
+	}
385
+
386
+	/**
387
+	 * @param string $backtraceLine
388
+	 * @return string
389
+	 */
390
+	protected function normalizeBacktraceLine($backtraceLine)
391
+	{
392
+		$search = [
393
+			glsr()->path('plugin/'),
394
+			glsr()->path('plugin/', false),
395
+			trailingslashit(glsr()->path()),
396
+			trailingslashit(glsr()->path('', false)),
397
+			WP_CONTENT_DIR,
398
+			ABSPATH,
399
+		];
400
+		return str_replace(array_unique($search), '', $backtraceLine);
401
+	}
402
+
403
+	/**
404
+	 * @param string $message
405
+	 * @return string
406
+	 */
407
+	protected function normalizeThrowableMessage($message)
408
+	{
409
+		$calledIn = strpos($message, ', called in');
410
+		return false !== $calledIn
411
+			? substr($message, 0, $calledIn)
412
+			: $message;
413
+	}
414
+
415
+	/**
416
+	 * @param mixed $value
417
+	 * @return string
418
+	 */
419
+	protected function normalizeValue($value)
420
+	{
421
+		if ($value instanceof DateTime) {
422
+			$value = $value->format('Y-m-d H:i:s');
423
+		} elseif ($this->isObjectOrArray($value)) {
424
+			$value = json_encode($value);
425
+		}
426
+		return (string) $value;
427
+	}
428
+
429
+	/**
430
+	 * @return void
431
+	 */
432
+	protected function reset()
433
+	{
434
+		if ($this->size() <= pow(1024, 2) / 8) {
435
+			return;
436
+		}
437
+		$this->clear();
438
+		file_put_contents(
439
+			$this->file,
440
+			$this->buildLogEntry(
441
+				static::NOTICE,
442
+				__('Console was automatically cleared (128 KB maximum size)', 'site-reviews')
443
+			)
444
+		);
445
+	}
446 446
 }
Please login to merge, or discard this patch.
deprecated.php 1 patch
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -3,134 +3,134 @@
 block discarded – undo
3 3
 defined('WPINC') || die;
4 4
 
5 5
 if (apply_filters('site-reviews/support/deprecated/v4', true)) {
6
-    // Unprotected review meta has been deprecated
7
-    add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) {
8
-        $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults());
9
-        if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) {
10
-            return $data;
11
-        }
12
-        glsr()->deprecated[] = sprintf(
13
-            'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.',
14
-            $metaKey
15
-        );
16
-        return get_post_meta($postId, '_'.$metaKey, $single);
17
-    }, 10, 4);
6
+	// Unprotected review meta has been deprecated
7
+	add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) {
8
+		$metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults());
9
+		if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) {
10
+			return $data;
11
+		}
12
+		glsr()->deprecated[] = sprintf(
13
+			'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.',
14
+			$metaKey
15
+		);
16
+		return get_post_meta($postId, '_'.$metaKey, $single);
17
+	}, 10, 4);
18 18
 
19
-    // Modules/Html/Template.php
20
-    add_filter('site-reviews/interpolate/reviews', function ($context, $template) {
21
-        $search = '{{ navigation }}';
22
-        if (false !== strpos($template, $search)) {
23
-            $context['navigation'] = $context['pagination'];
24
-            glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.';
25
-        }
26
-        return $context;
27
-    }, 10, 2);
19
+	// Modules/Html/Template.php
20
+	add_filter('site-reviews/interpolate/reviews', function ($context, $template) {
21
+		$search = '{{ navigation }}';
22
+		if (false !== strpos($template, $search)) {
23
+			$context['navigation'] = $context['pagination'];
24
+			glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.';
25
+		}
26
+		return $context;
27
+	}, 10, 2);
28 28
 
29
-    // Database/ReviewManager.php
30
-    add_action('site-reviews/review/created', function ($review) {
31
-        if (has_action('site-reviews/local/review/create')) {
32
-            glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.';
33
-            do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID);
34
-        }
35
-    }, 9);
29
+	// Database/ReviewManager.php
30
+	add_action('site-reviews/review/created', function ($review) {
31
+		if (has_action('site-reviews/local/review/create')) {
32
+			glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.';
33
+			do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID);
34
+		}
35
+	}, 9);
36 36
 
37
-    // Handlers/CreateReview.php
38
-    add_action('site-reviews/review/submitted', function ($review) {
39
-        if (has_action('site-reviews/local/review/submitted')) {
40
-            glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.';
41
-            do_action('site-reviews/local/review/submitted', null, $review);
42
-        }
43
-        if (has_filter('site-reviews/local/review/submitted/message')) {
44
-            glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.';
45
-        }
46
-    }, 9);
37
+	// Handlers/CreateReview.php
38
+	add_action('site-reviews/review/submitted', function ($review) {
39
+		if (has_action('site-reviews/local/review/submitted')) {
40
+			glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.';
41
+			do_action('site-reviews/local/review/submitted', null, $review);
42
+		}
43
+		if (has_filter('site-reviews/local/review/submitted/message')) {
44
+			glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.';
45
+		}
46
+	}, 9);
47 47
 
48
-    // Database/ReviewManager.php
49
-    add_filter('site-reviews/create/review-values', function ($values, $command) {
50
-        if (has_filter('site-reviews/local/review')) {
51
-            glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.';
52
-            return apply_filters('site-reviews/local/review', $values, $command);
53
-        }
54
-        return $values;
55
-    }, 9, 2);
48
+	// Database/ReviewManager.php
49
+	add_filter('site-reviews/create/review-values', function ($values, $command) {
50
+		if (has_filter('site-reviews/local/review')) {
51
+			glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.';
52
+			return apply_filters('site-reviews/local/review', $values, $command);
53
+		}
54
+		return $values;
55
+	}, 9, 2);
56 56
 
57
-    // Handlers/EnqueuePublicAssets.php
58
-    add_filter('site-reviews/enqueue/public/localize', function ($variables) {
59
-        if (has_filter('site-reviews/enqueue/localize')) {
60
-            glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.';
61
-            return apply_filters('site-reviews/enqueue/localize', $variables);
62
-        }
63
-        return $variables;
64
-    }, 9);
57
+	// Handlers/EnqueuePublicAssets.php
58
+	add_filter('site-reviews/enqueue/public/localize', function ($variables) {
59
+		if (has_filter('site-reviews/enqueue/localize')) {
60
+			glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.';
61
+			return apply_filters('site-reviews/enqueue/localize', $variables);
62
+		}
63
+		return $variables;
64
+	}, 9);
65 65
 
66
-    // Modules/Rating.php
67
-    add_filter('site-reviews/rating/average', function ($average) {
68
-        if (has_filter('site-reviews/average/rating')) {
69
-            glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.';
70
-        }
71
-        return $average;
72
-    }, 9);
66
+	// Modules/Rating.php
67
+	add_filter('site-reviews/rating/average', function ($average) {
68
+		if (has_filter('site-reviews/average/rating')) {
69
+			glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.';
70
+		}
71
+		return $average;
72
+	}, 9);
73 73
 
74
-    // Modules/Rating.php
75
-    add_filter('site-reviews/rating/ranking', function ($ranking) {
76
-        if (has_filter('site-reviews/bayesian/ranking')) {
77
-            glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.';
78
-        }
79
-        return $ranking;
80
-    }, 9);
74
+	// Modules/Rating.php
75
+	add_filter('site-reviews/rating/ranking', function ($ranking) {
76
+		if (has_filter('site-reviews/bayesian/ranking')) {
77
+			glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.';
78
+		}
79
+		return $ranking;
80
+	}, 9);
81 81
 
82
-    // Modules/Html/Partials/SiteReviews.php
83
-    add_filter('site-reviews/review/build/after', function ($renderedFields) {
84
-        if (has_filter('site-reviews/reviews/review/text')) {
85
-            glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
86
-        }
87
-        if (has_filter('site-reviews/reviews/review/title')) {
88
-            glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
89
-        }
90
-        return $renderedFields;
91
-    }, 9);
82
+	// Modules/Html/Partials/SiteReviews.php
83
+	add_filter('site-reviews/review/build/after', function ($renderedFields) {
84
+		if (has_filter('site-reviews/reviews/review/text')) {
85
+			glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
86
+		}
87
+		if (has_filter('site-reviews/reviews/review/title')) {
88
+			glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
89
+		}
90
+		return $renderedFields;
91
+	}, 9);
92 92
 
93
-    // Modules/Html/Partials/SiteReviews.php
94
-    add_filter('site-reviews/review/build/before', function ($review) {
95
-        if (has_filter('site-reviews/rendered/review')) {
96
-            glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.';
97
-        }
98
-        if (has_filter('site-reviews/rendered/review/meta/order')) {
99
-            glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
100
-        }
101
-        if (has_filter('site-reviews/rendered/review/order')) {
102
-            glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
103
-        }
104
-        if (has_filter('site-reviews/rendered/review-form/login-register')) {
105
-            glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).';
106
-        }
107
-        if (has_filter('site-reviews/reviews/navigation_links')) {
108
-            glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).';
109
-        }
110
-        return $review;
111
-    }, 9);
93
+	// Modules/Html/Partials/SiteReviews.php
94
+	add_filter('site-reviews/review/build/before', function ($review) {
95
+		if (has_filter('site-reviews/rendered/review')) {
96
+			glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.';
97
+		}
98
+		if (has_filter('site-reviews/rendered/review/meta/order')) {
99
+			glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
100
+		}
101
+		if (has_filter('site-reviews/rendered/review/order')) {
102
+			glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
103
+		}
104
+		if (has_filter('site-reviews/rendered/review-form/login-register')) {
105
+			glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).';
106
+		}
107
+		if (has_filter('site-reviews/reviews/navigation_links')) {
108
+			glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).';
109
+		}
110
+		return $review;
111
+	}, 9);
112 112
 
113
-    add_filter('site-reviews/validate/custom', function ($result, $request) {
114
-        if (has_filter('site-reviews/validate/review/submission')) {
115
-            glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.');
116
-            return apply_filters('site-reviews/validate/review/submission', $result, $request);
117
-        }
118
-        return $result;
119
-    }, 9, 2);
113
+	add_filter('site-reviews/validate/custom', function ($result, $request) {
114
+		if (has_filter('site-reviews/validate/review/submission')) {
115
+			glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.');
116
+			return apply_filters('site-reviews/validate/review/submission', $result, $request);
117
+		}
118
+		return $result;
119
+	}, 9, 2);
120 120
 
121
-    add_filter('site-reviews/views/file', function ($file, $view, $data) {
122
-        if (has_filter('site-reviews/addon/views/file')) {
123
-            glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.';
124
-            $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data);
125
-        }
126
-        return $file;
127
-    }, 9, 3);
121
+	add_filter('site-reviews/views/file', function ($file, $view, $data) {
122
+		if (has_filter('site-reviews/addon/views/file')) {
123
+			glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.';
124
+			$file = apply_filters('site-reviews/addon/views/file', $file, $view, $data);
125
+		}
126
+		return $file;
127
+	}, 9, 3);
128 128
 }
129 129
 
130 130
 add_action('wp_footer', function () {
131
-    $notices = array_keys(array_flip(glsr()->deprecated));
132
-    natsort($notices);
133
-    foreach ($notices as $notice) {
134
-        glsr_log()->warning($notice);
135
-    }
131
+	$notices = array_keys(array_flip(glsr()->deprecated));
132
+	natsort($notices);
133
+	foreach ($notices as $notice) {
134
+		glsr_log()->warning($notice);
135
+	}
136 136
 });
Please login to merge, or discard this patch.
plugin/Modules/Schema.php 1 patch
Indentation   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -12,322 +12,322 @@
 block discarded – undo
12 12
 
13 13
 class Schema
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    protected $args;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	protected $args;
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    protected $keyValues = [];
20
+	/**
21
+	 * @var array
22
+	 */
23
+	protected $keyValues = [];
24 24
 
25
-    /**
26
-     * @var array
27
-     */
28
-    protected $ratingCounts;
25
+	/**
26
+	 * @var array
27
+	 */
28
+	protected $ratingCounts;
29 29
 
30
-    /**
31
-     * @return array
32
-     */
33
-    public function build(array $args = [])
34
-    {
35
-        $this->args = $args;
36
-        $schema = $this->buildSummary($args);
37
-        $reviews = [];
38
-        foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
39
-            // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
40
-            // @see https://developers.google.com/search/docs/data-types/review
41
-            if ('local' != $review->review_type) {
42
-                continue;
43
-            }
44
-            $reviews[] = $this->buildReview($review);
45
-        }
46
-        if (!empty($reviews)) {
47
-            array_walk($reviews, function (&$review) {
48
-                unset($review['@context']);
49
-                unset($review['itemReviewed']);
50
-            });
51
-            $schema['review'] = $reviews;
52
-        }
53
-        return $schema;
54
-    }
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function build(array $args = [])
34
+	{
35
+		$this->args = $args;
36
+		$schema = $this->buildSummary($args);
37
+		$reviews = [];
38
+		foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
39
+			// Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
40
+			// @see https://developers.google.com/search/docs/data-types/review
41
+			if ('local' != $review->review_type) {
42
+				continue;
43
+			}
44
+			$reviews[] = $this->buildReview($review);
45
+		}
46
+		if (!empty($reviews)) {
47
+			array_walk($reviews, function (&$review) {
48
+				unset($review['@context']);
49
+				unset($review['itemReviewed']);
50
+			});
51
+			$schema['review'] = $reviews;
52
+		}
53
+		return $schema;
54
+	}
55 55
 
56
-    /**
57
-     * @param array|null $args
58
-     * @return array
59
-     */
60
-    public function buildSummary($args = null)
61
-    {
62
-        if (is_array($args)) {
63
-            $this->args = $args;
64
-        }
65
-        $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
66
-        $count = array_sum($this->getRatingCounts());
67
-        $schema = method_exists($this, $buildSummary)
68
-            ? $this->$buildSummary()
69
-            : $this->buildSummaryForCustom();
70
-        if (!empty($count)) {
71
-            $schema->aggregateRating(
72
-                $this->getSchemaType('AggregateRating')
73
-                    ->ratingValue($this->getRatingValue())
74
-                    ->reviewCount($count)
75
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
76
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
77
-            );
78
-        }
79
-        $schema = $schema->toArray();
80
-        return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
81
-    }
56
+	/**
57
+	 * @param array|null $args
58
+	 * @return array
59
+	 */
60
+	public function buildSummary($args = null)
61
+	{
62
+		if (is_array($args)) {
63
+			$this->args = $args;
64
+		}
65
+		$buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
66
+		$count = array_sum($this->getRatingCounts());
67
+		$schema = method_exists($this, $buildSummary)
68
+			? $this->$buildSummary()
69
+			: $this->buildSummaryForCustom();
70
+		if (!empty($count)) {
71
+			$schema->aggregateRating(
72
+				$this->getSchemaType('AggregateRating')
73
+					->ratingValue($this->getRatingValue())
74
+					->reviewCount($count)
75
+					->bestRating(glsr()->constant('MAX_RATING', Rating::class))
76
+					->worstRating(glsr()->constant('MIN_RATING', Rating::class))
77
+			);
78
+		}
79
+		$schema = $schema->toArray();
80
+		return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
81
+	}
82 82
 
83
-    /**
84
-     * @return void
85
-     */
86
-    public function render()
87
-    {
88
-        if (empty(glsr()->schemas)) {
89
-            return;
90
-        }
91
-        printf('<script type="application/ld+json">%s</script>', json_encode(
92
-            apply_filters('site-reviews/schema/all', glsr()->schemas),
93
-            JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
94
-        ));
95
-    }
83
+	/**
84
+	 * @return void
85
+	 */
86
+	public function render()
87
+	{
88
+		if (empty(glsr()->schemas)) {
89
+			return;
90
+		}
91
+		printf('<script type="application/ld+json">%s</script>', json_encode(
92
+			apply_filters('site-reviews/schema/all', glsr()->schemas),
93
+			JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
94
+		));
95
+	}
96 96
 
97
-    /**
98
-     * @return void
99
-     */
100
-    public function store(array $schema)
101
-    {
102
-        $schemas = glsr()->schemas;
103
-        $schemas[] = $schema;
104
-        glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
105
-    }
97
+	/**
98
+	 * @return void
99
+	 */
100
+	public function store(array $schema)
101
+	{
102
+		$schemas = glsr()->schemas;
103
+		$schemas[] = $schema;
104
+		glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
105
+	}
106 106
 
107
-    /**
108
-     * @param Review $review
109
-     * @return array
110
-     */
111
-    protected function buildReview($review)
112
-    {
113
-        $schema = $this->getSchemaType('Review')
114
-            ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
115
-                $schema->name($review->title);
116
-            })
117
-            ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
118
-                $schema->reviewBody($review->content);
119
-            })
120
-            ->datePublished((new DateTime($review->date)))
121
-            ->author($this->getSchemaType('Person')->name($review->author))
122
-            ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
123
-        if (!empty($review->rating)) {
124
-            $schema->reviewRating(
125
-                $this->getSchemaType('Rating')
126
-                    ->ratingValue($review->rating)
127
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
128
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
129
-            );
130
-        }
131
-        return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
132
-    }
107
+	/**
108
+	 * @param Review $review
109
+	 * @return array
110
+	 */
111
+	protected function buildReview($review)
112
+	{
113
+		$schema = $this->getSchemaType('Review')
114
+			->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
115
+				$schema->name($review->title);
116
+			})
117
+			->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
118
+				$schema->reviewBody($review->content);
119
+			})
120
+			->datePublished((new DateTime($review->date)))
121
+			->author($this->getSchemaType('Person')->name($review->author))
122
+			->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
123
+		if (!empty($review->rating)) {
124
+			$schema->reviewRating(
125
+				$this->getSchemaType('Rating')
126
+					->ratingValue($review->rating)
127
+					->bestRating(glsr()->constant('MAX_RATING', Rating::class))
128
+					->worstRating(glsr()->constant('MIN_RATING', Rating::class))
129
+			);
130
+		}
131
+		return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
132
+	}
133 133
 
134
-    /**
135
-     * @param mixed $schema
136
-     * @return mixed
137
-     */
138
-    protected function buildSchemaValues($schema, array $values = [])
139
-    {
140
-        foreach ($values as $value) {
141
-            $option = $this->getSchemaOptionValue($value);
142
-            if (empty($option)) {
143
-                continue;
144
-            }
145
-            $schema->$value($option);
146
-        }
147
-        return $schema;
148
-    }
134
+	/**
135
+	 * @param mixed $schema
136
+	 * @return mixed
137
+	 */
138
+	protected function buildSchemaValues($schema, array $values = [])
139
+	{
140
+		foreach ($values as $value) {
141
+			$option = $this->getSchemaOptionValue($value);
142
+			if (empty($option)) {
143
+				continue;
144
+			}
145
+			$schema->$value($option);
146
+		}
147
+		return $schema;
148
+	}
149 149
 
150
-    /**
151
-     * @return mixed
152
-     */
153
-    protected function buildSummaryForCustom()
154
-    {
155
-        return $this->buildSchemaValues($this->getSchemaType(), [
156
-            'description', 'image', 'name', 'url',
157
-        ]);
158
-    }
150
+	/**
151
+	 * @return mixed
152
+	 */
153
+	protected function buildSummaryForCustom()
154
+	{
155
+		return $this->buildSchemaValues($this->getSchemaType(), [
156
+			'description', 'image', 'name', 'url',
157
+		]);
158
+	}
159 159
 
160
-    /**
161
-     * @return mixed
162
-     */
163
-    protected function buildSummaryForLocalBusiness()
164
-    {
165
-        return $this->buildSchemaValues($this->buildSummaryForCustom(), [
166
-            'address', 'priceRange', 'telephone',
167
-        ]);
168
-    }
160
+	/**
161
+	 * @return mixed
162
+	 */
163
+	protected function buildSummaryForLocalBusiness()
164
+	{
165
+		return $this->buildSchemaValues($this->buildSummaryForCustom(), [
166
+			'address', 'priceRange', 'telephone',
167
+		]);
168
+	}
169 169
 
170
-    /**
171
-     * @return mixed
172
-     */
173
-    protected function buildSummaryForProduct()
174
-    {
175
-        $offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
176
-        $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
177
-            'highPrice', 'lowPrice', 'price', 'priceCurrency',
178
-        ]);
179
-        return $this->buildSummaryForCustom()
180
-            ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
181
-                $schema->offers($offers);
182
-            })
183
-            ->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
184
-    }
170
+	/**
171
+	 * @return mixed
172
+	 */
173
+	protected function buildSummaryForProduct()
174
+	{
175
+		$offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
176
+		$offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
177
+			'highPrice', 'lowPrice', 'price', 'priceCurrency',
178
+		]);
179
+		return $this->buildSummaryForCustom()
180
+			->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
181
+				$schema->offers($offers);
182
+			})
183
+			->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
184
+	}
185 185
 
186
-    /**
187
-     * @return array
188
-     */
189
-    protected function getRatingCounts()
190
-    {
191
-        if (!isset($this->ratingCounts)) {
192
-            $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
193
-        }
194
-        return $this->ratingCounts;
195
-    }
186
+	/**
187
+	 * @return array
188
+	 */
189
+	protected function getRatingCounts()
190
+	{
191
+		if (!isset($this->ratingCounts)) {
192
+			$this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
193
+		}
194
+		return $this->ratingCounts;
195
+	}
196 196
 
197
-    /**
198
-     * @return int|float
199
-     */
200
-    protected function getRatingValue()
201
-    {
202
-        return glsr(Rating::class)->getAverage($this->getRatingCounts());
203
-    }
197
+	/**
198
+	 * @return int|float
199
+	 */
200
+	protected function getRatingValue()
201
+	{
202
+		return glsr(Rating::class)->getAverage($this->getRatingCounts());
203
+	}
204 204
 
205
-    /**
206
-     * @param string $option
207
-     * @param string $fallback
208
-     * @return string
209
-     */
210
-    protected function getSchemaOption($option, $fallback)
211
-    {
212
-        $option = strtolower($option);
213
-        if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
214
-            return $schemaOption;
215
-        }
216
-        $setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
217
-        if (is_array($setting)) {
218
-            return $this->getSchemaOptionDefault($setting, $fallback);
219
-        }
220
-        return !empty($setting)
221
-            ? $setting
222
-            : $fallback;
223
-    }
205
+	/**
206
+	 * @param string $option
207
+	 * @param string $fallback
208
+	 * @return string
209
+	 */
210
+	protected function getSchemaOption($option, $fallback)
211
+	{
212
+		$option = strtolower($option);
213
+		if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
214
+			return $schemaOption;
215
+		}
216
+		$setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
217
+		if (is_array($setting)) {
218
+			return $this->getSchemaOptionDefault($setting, $fallback);
219
+		}
220
+		return !empty($setting)
221
+			? $setting
222
+			: $fallback;
223
+	}
224 224
 
225
-    /**
226
-     * @param string $fallback
227
-     * @return string
228
-     */
229
-    protected function getSchemaOptionDefault(array $setting, $fallback)
230
-    {
231
-        $setting = wp_parse_args($setting, [
232
-            'custom' => '',
233
-            'default' => $fallback,
234
-        ]);
235
-        return 'custom' != $setting['default']
236
-            ? $setting['default']
237
-            : $setting['custom'];
238
-    }
225
+	/**
226
+	 * @param string $fallback
227
+	 * @return string
228
+	 */
229
+	protected function getSchemaOptionDefault(array $setting, $fallback)
230
+	{
231
+		$setting = wp_parse_args($setting, [
232
+			'custom' => '',
233
+			'default' => $fallback,
234
+		]);
235
+		return 'custom' != $setting['default']
236
+			? $setting['default']
237
+			: $setting['custom'];
238
+	}
239 239
 
240
-    /**
241
-     * @param string $option
242
-     * @param string $fallback
243
-     * @return void|string
244
-     */
245
-    protected function getSchemaOptionValue($option, $fallback = 'post')
246
-    {
247
-        if (array_key_exists($option, $this->keyValues)) {
248
-            return $this->keyValues[$option];
249
-        }
250
-        $value = $this->getSchemaOption($option, $fallback);
251
-        if ($value != $fallback) {
252
-            return $this->setAndGetKeyValue($option, $value);
253
-        }
254
-        if (!is_single() && !is_page()) {
255
-            return;
256
-        }
257
-        $method = Helper::buildMethodName($option, 'getThing');
258
-        if (method_exists($this, $method)) {
259
-            return $this->setAndGetKeyValue($option, $this->$method());
260
-        }
261
-    }
240
+	/**
241
+	 * @param string $option
242
+	 * @param string $fallback
243
+	 * @return void|string
244
+	 */
245
+	protected function getSchemaOptionValue($option, $fallback = 'post')
246
+	{
247
+		if (array_key_exists($option, $this->keyValues)) {
248
+			return $this->keyValues[$option];
249
+		}
250
+		$value = $this->getSchemaOption($option, $fallback);
251
+		if ($value != $fallback) {
252
+			return $this->setAndGetKeyValue($option, $value);
253
+		}
254
+		if (!is_single() && !is_page()) {
255
+			return;
256
+		}
257
+		$method = Helper::buildMethodName($option, 'getThing');
258
+		if (method_exists($this, $method)) {
259
+			return $this->setAndGetKeyValue($option, $this->$method());
260
+		}
261
+	}
262 262
 
263
-    /**
264
-     * @param string|null $type
265
-     * @return mixed
266
-     */
267
-    protected function getSchemaType($type = null)
268
-    {
269
-        if (!is_string($type)) {
270
-            $type = $this->getSchemaOption('type', 'LocalBusiness');
271
-        }
272
-        $className = Helper::buildClassName($type, 'Modules\Schema');
273
-        return class_exists($className)
274
-            ? new $className()
275
-            : new UnknownType($type);
276
-    }
263
+	/**
264
+	 * @param string|null $type
265
+	 * @return mixed
266
+	 */
267
+	protected function getSchemaType($type = null)
268
+	{
269
+		if (!is_string($type)) {
270
+			$type = $this->getSchemaOption('type', 'LocalBusiness');
271
+		}
272
+		$className = Helper::buildClassName($type, 'Modules\Schema');
273
+		return class_exists($className)
274
+			? new $className()
275
+			: new UnknownType($type);
276
+	}
277 277
 
278
-    /**
279
-     * @return string
280
-     */
281
-    protected function getThingDescription()
282
-    {
283
-        $post = get_post();
284
-        $text = Arr::get($post, 'post_excerpt');
285
-        if (empty($text)) {
286
-            $text = Arr::get($post, 'post_content');
287
-        }
288
-        if (function_exists('excerpt_remove_blocks')) {
289
-            $text = excerpt_remove_blocks($text);
290
-        }
291
-        $text = strip_shortcodes($text);
292
-        $text = wpautop($text);
293
-        $text = wptexturize($text);
294
-        $text = wp_strip_all_tags($text);
295
-        $text = str_replace(']]>', ']]&gt;', $text);
296
-        return wp_trim_words($text, apply_filters('excerpt_length', 55));
297
-    }
278
+	/**
279
+	 * @return string
280
+	 */
281
+	protected function getThingDescription()
282
+	{
283
+		$post = get_post();
284
+		$text = Arr::get($post, 'post_excerpt');
285
+		if (empty($text)) {
286
+			$text = Arr::get($post, 'post_content');
287
+		}
288
+		if (function_exists('excerpt_remove_blocks')) {
289
+			$text = excerpt_remove_blocks($text);
290
+		}
291
+		$text = strip_shortcodes($text);
292
+		$text = wpautop($text);
293
+		$text = wptexturize($text);
294
+		$text = wp_strip_all_tags($text);
295
+		$text = str_replace(']]>', ']]&gt;', $text);
296
+		return wp_trim_words($text, apply_filters('excerpt_length', 55));
297
+	}
298 298
 
299
-    /**
300
-     * @return string
301
-     */
302
-    protected function getThingImage()
303
-    {
304
-        return (string) get_the_post_thumbnail_url(null, 'large');
305
-    }
299
+	/**
300
+	 * @return string
301
+	 */
302
+	protected function getThingImage()
303
+	{
304
+		return (string) get_the_post_thumbnail_url(null, 'large');
305
+	}
306 306
 
307
-    /**
308
-     * @return string
309
-     */
310
-    protected function getThingName()
311
-    {
312
-        return get_the_title();
313
-    }
307
+	/**
308
+	 * @return string
309
+	 */
310
+	protected function getThingName()
311
+	{
312
+		return get_the_title();
313
+	}
314 314
 
315
-    /**
316
-     * @return string
317
-     */
318
-    protected function getThingUrl()
319
-    {
320
-        return (string) get_the_permalink();
321
-    }
315
+	/**
316
+	 * @return string
317
+	 */
318
+	protected function getThingUrl()
319
+	{
320
+		return (string) get_the_permalink();
321
+	}
322 322
 
323
-    /**
324
-     * @param string $option
325
-     * @param string $value
326
-     * @return string
327
-     */
328
-    protected function setAndGetKeyValue($option, $value)
329
-    {
330
-        $this->keyValues[$option] = $value;
331
-        return $value;
332
-    }
323
+	/**
324
+	 * @param string $option
325
+	 * @param string $value
326
+	 * @return string
327
+	 */
328
+	protected function setAndGetKeyValue($option, $value)
329
+	{
330
+		$this->keyValues[$option] = $value;
331
+		return $value;
332
+	}
333 333
 }
Please login to merge, or discard this patch.
plugin/Handlers/EnqueuePublicAssets.php 1 patch
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -9,148 +9,148 @@
 block discarded – undo
9 9
 
10 10
 class EnqueuePublicAssets
11 11
 {
12
-    /**
13
-     * @return void
14
-     */
15
-    public function handle()
16
-    {
17
-        $this->enqueueAssets();
18
-        $this->enqueuePolyfillService();
19
-        $this->enqueueRecaptchaScript();
20
-        $this->inlineScript();
21
-        $this->inlineStyles();
22
-    }
12
+	/**
13
+	 * @return void
14
+	 */
15
+	public function handle()
16
+	{
17
+		$this->enqueueAssets();
18
+		$this->enqueuePolyfillService();
19
+		$this->enqueueRecaptchaScript();
20
+		$this->inlineScript();
21
+		$this->inlineStyles();
22
+	}
23 23
 
24
-    /**
25
-     * @return void
26
-     */
27
-    public function enqueueAssets()
28
-    {
29
-        if (apply_filters('site-reviews/assets/css', true)) {
30
-            wp_enqueue_style(
31
-                Application::ID,
32
-                $this->getStylesheet(),
33
-                [],
34
-                glsr()->version
35
-            );
36
-        }
37
-        if (apply_filters('site-reviews/assets/js', true)) {
38
-            $dependencies = apply_filters('site-reviews/assets/polyfill', true)
39
-                ? [Application::ID.'/polyfill']
40
-                : [];
41
-            $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies);
42
-            wp_enqueue_script(
43
-                Application::ID,
44
-                glsr()->url('assets/scripts/'.Application::ID.'.js'),
45
-                $dependencies,
46
-                glsr()->version,
47
-                true
48
-            );
49
-        }
50
-    }
24
+	/**
25
+	 * @return void
26
+	 */
27
+	public function enqueueAssets()
28
+	{
29
+		if (apply_filters('site-reviews/assets/css', true)) {
30
+			wp_enqueue_style(
31
+				Application::ID,
32
+				$this->getStylesheet(),
33
+				[],
34
+				glsr()->version
35
+			);
36
+		}
37
+		if (apply_filters('site-reviews/assets/js', true)) {
38
+			$dependencies = apply_filters('site-reviews/assets/polyfill', true)
39
+				? [Application::ID.'/polyfill']
40
+				: [];
41
+			$dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies);
42
+			wp_enqueue_script(
43
+				Application::ID,
44
+				glsr()->url('assets/scripts/'.Application::ID.'.js'),
45
+				$dependencies,
46
+				glsr()->version,
47
+				true
48
+			);
49
+		}
50
+	}
51 51
 
52
-    /**
53
-     * @return void
54
-     */
55
-    public function enqueuePolyfillService()
56
-    {
57
-        if (!apply_filters('site-reviews/assets/polyfill', true)) {
58
-            return;
59
-        }
60
-        wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([
61
-            'features' => 'Array.prototype.findIndex,CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver',
62
-            'flags' => 'gated',
63
-        ], 'https://polyfill.io/v3/polyfill.min.js'));
64
-    }
52
+	/**
53
+	 * @return void
54
+	 */
55
+	public function enqueuePolyfillService()
56
+	{
57
+		if (!apply_filters('site-reviews/assets/polyfill', true)) {
58
+			return;
59
+		}
60
+		wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([
61
+			'features' => 'Array.prototype.findIndex,CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver',
62
+			'flags' => 'gated',
63
+		], 'https://polyfill.io/v3/polyfill.min.js'));
64
+	}
65 65
 
66
-    /**
67
-     * @return void
68
-     */
69
-    public function enqueueRecaptchaScript()
70
-    {
71
-        // wpforms-recaptcha
72
-        // google-recaptcha
73
-        // nf-google-recaptcha
74
-        if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
75
-            return;
76
-        }
77
-        $language = apply_filters('site-reviews/recaptcha/language', get_locale());
78
-        wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([
79
-            'hl' => $language,
80
-            'render' => 'explicit',
81
-        ], 'https://www.google.com/recaptcha/api.js'));
82
-    }
66
+	/**
67
+	 * @return void
68
+	 */
69
+	public function enqueueRecaptchaScript()
70
+	{
71
+		// wpforms-recaptcha
72
+		// google-recaptcha
73
+		// nf-google-recaptcha
74
+		if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
75
+			return;
76
+		}
77
+		$language = apply_filters('site-reviews/recaptcha/language', get_locale());
78
+		wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([
79
+			'hl' => $language,
80
+			'render' => 'explicit',
81
+		], 'https://www.google.com/recaptcha/api.js'));
82
+	}
83 83
 
84
-    /**
85
-     * @return void
86
-     */
87
-    public function inlineScript()
88
-    {
89
-        $variables = [
90
-            'action' => Application::PREFIX.'action',
91
-            'ajaxpagination' => $this->getFixedSelectorsForPagination(),
92
-            'ajaxurl' => admin_url('admin-ajax.php'),
93
-            'nameprefix' => Application::ID,
94
-            'validationconfig' => glsr(Style::class)->validation,
95
-            'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(),
96
-        ];
97
-        $variables = apply_filters('site-reviews/enqueue/public/localize', $variables);
98
-        wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before');
99
-    }
84
+	/**
85
+	 * @return void
86
+	 */
87
+	public function inlineScript()
88
+	{
89
+		$variables = [
90
+			'action' => Application::PREFIX.'action',
91
+			'ajaxpagination' => $this->getFixedSelectorsForPagination(),
92
+			'ajaxurl' => admin_url('admin-ajax.php'),
93
+			'nameprefix' => Application::ID,
94
+			'validationconfig' => glsr(Style::class)->validation,
95
+			'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(),
96
+		];
97
+		$variables = apply_filters('site-reviews/enqueue/public/localize', $variables);
98
+		wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before');
99
+	}
100 100
 
101
-    /**
102
-     * @return void
103
-     */
104
-    public function inlineStyles()
105
-    {
106
-        $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css');
107
-        if (!apply_filters('site-reviews/assets/css', true)) {
108
-            return;
109
-        }
110
-        if (!file_exists($inlineStylesheetPath)) {
111
-            glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath);
112
-            return;
113
-        }
114
-        $inlineStylesheetValues = glsr()->config('inline-styles');
115
-        $stylesheet = str_replace(
116
-            array_keys($inlineStylesheetValues),
117
-            array_values($inlineStylesheetValues),
118
-            file_get_contents($inlineStylesheetPath)
119
-        );
120
-        wp_add_inline_style(Application::ID, $stylesheet);
121
-    }
101
+	/**
102
+	 * @return void
103
+	 */
104
+	public function inlineStyles()
105
+	{
106
+		$inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css');
107
+		if (!apply_filters('site-reviews/assets/css', true)) {
108
+			return;
109
+		}
110
+		if (!file_exists($inlineStylesheetPath)) {
111
+			glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath);
112
+			return;
113
+		}
114
+		$inlineStylesheetValues = glsr()->config('inline-styles');
115
+		$stylesheet = str_replace(
116
+			array_keys($inlineStylesheetValues),
117
+			array_values($inlineStylesheetValues),
118
+			file_get_contents($inlineStylesheetPath)
119
+		);
120
+		wp_add_inline_style(Application::ID, $stylesheet);
121
+	}
122 122
 
123
-    /**
124
-     * @return string
125
-     */
126
-    protected function buildInlineScript(array $variables)
127
-    {
128
-        $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});';
129
-        foreach ($variables as $key => $value) {
130
-            $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
131
-        }
132
-        $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys
133
-        $optimizedScript = preg_replace($pattern, '$1$2', $script);
134
-        return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables);
135
-    }
123
+	/**
124
+	 * @return string
125
+	 */
126
+	protected function buildInlineScript(array $variables)
127
+	{
128
+		$script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});';
129
+		foreach ($variables as $key => $value) {
130
+			$script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
131
+		}
132
+		$pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys
133
+		$optimizedScript = preg_replace($pattern, '$1$2', $script);
134
+		return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables);
135
+	}
136 136
 
137
-    /**
138
-     * @return array
139
-     */
140
-    protected function getFixedSelectorsForPagination()
141
-    {
142
-        $selectors = ['#wpadminbar', '.site-navigation-fixed'];
143
-        return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors);
144
-    }
137
+	/**
138
+	 * @return array
139
+	 */
140
+	protected function getFixedSelectorsForPagination()
141
+	{
142
+		$selectors = ['#wpadminbar', '.site-navigation-fixed'];
143
+		return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors);
144
+	}
145 145
 
146
-    /**
147
-     * @return string
148
-     */
149
-    protected function getStylesheet()
150
-    {
151
-        $currentStyle = glsr(Style::class)->style;
152
-        return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css'))
153
-            ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css')
154
-            : glsr()->url('assets/styles/'.Application::ID.'.css');
155
-    }
146
+	/**
147
+	 * @return string
148
+	 */
149
+	protected function getStylesheet()
150
+	{
151
+		$currentStyle = glsr(Style::class)->style;
152
+		return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css'))
153
+			? glsr()->url('assets/styles/custom/'.$currentStyle.'.css')
154
+			: glsr()->url('assets/styles/'.Application::ID.'.css');
155
+	}
156 156
 }
Please login to merge, or discard this patch.
plugin/Modules/Upgrader.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -8,83 +8,83 @@
 block discarded – undo
8 8
 
9 9
 class Upgrader
10 10
 {
11
-    /**
12
-     * @return string
13
-     */
14
-    public $currentVersion;
11
+	/**
12
+	 * @return string
13
+	 */
14
+	public $currentVersion;
15 15
 
16
-    /**
17
-     * @return void
18
-     */
19
-    public function run()
20
-    {
21
-        $filenames = [];
22
-        $iterator = new DirectoryIterator(dirname(__FILE__).'/Upgrader');
23
-        foreach ($iterator as $fileinfo) {
24
-            if ($fileinfo->isFile()) {
25
-                $filenames[] = $fileinfo->getFilename();
26
-            }
27
-        }
28
-        natsort($filenames);
29
-        $this->currentVersion = $this->currentVersion();
30
-        array_walk($filenames, function ($file) {
31
-            $className = str_replace('.php', '', $file);
32
-            $upgradeFromVersion = str_replace(['Upgrade_', '_'], ['', '.'], $className);
33
-            $suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions
34
-            if (version_compare($this->currentVersion, $upgradeFromVersion.$suffix, '>=')) {
35
-                return;
36
-            }
37
-            glsr('Modules\\Upgrader\\'.$className);
38
-            glsr_log()->notice('Completed Upgrade for v'.$upgradeFromVersion.$suffix);
39
-        });
40
-        $this->finish();
41
-    }
16
+	/**
17
+	 * @return void
18
+	 */
19
+	public function run()
20
+	{
21
+		$filenames = [];
22
+		$iterator = new DirectoryIterator(dirname(__FILE__).'/Upgrader');
23
+		foreach ($iterator as $fileinfo) {
24
+			if ($fileinfo->isFile()) {
25
+				$filenames[] = $fileinfo->getFilename();
26
+			}
27
+		}
28
+		natsort($filenames);
29
+		$this->currentVersion = $this->currentVersion();
30
+		array_walk($filenames, function ($file) {
31
+			$className = str_replace('.php', '', $file);
32
+			$upgradeFromVersion = str_replace(['Upgrade_', '_'], ['', '.'], $className);
33
+			$suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions
34
+			if (version_compare($this->currentVersion, $upgradeFromVersion.$suffix, '>=')) {
35
+				return;
36
+			}
37
+			glsr('Modules\\Upgrader\\'.$className);
38
+			glsr_log()->notice('Completed Upgrade for v'.$upgradeFromVersion.$suffix);
39
+		});
40
+		$this->finish();
41
+	}
42 42
 
43
-    /**
44
-     * @return void
45
-     */
46
-    public function finish()
47
-    {
48
-        if ($this->currentVersion !== glsr()->version) {
49
-            $this->setReviewCounts();
50
-            $this->updateVersionFrom($this->currentVersion);
51
-        } elseif (!glsr(OptionManager::class)->get('last_review_count', false)) {
52
-            $this->setReviewCounts();
53
-        }
54
-    }
43
+	/**
44
+	 * @return void
45
+	 */
46
+	public function finish()
47
+	{
48
+		if ($this->currentVersion !== glsr()->version) {
49
+			$this->setReviewCounts();
50
+			$this->updateVersionFrom($this->currentVersion);
51
+		} elseif (!glsr(OptionManager::class)->get('last_review_count', false)) {
52
+			$this->setReviewCounts();
53
+		}
54
+	}
55 55
 
56
-    /**
57
-     * @return string
58
-     */
59
-    protected function currentVersion()
60
-    {
61
-        $fallback = '0.0.0';
62
-        $majorVersions = [4, 3, 2];
63
-        foreach ($majorVersions as $majorVersion) {
64
-            $settings = get_option(OptionManager::databaseKey($majorVersion));
65
-            $version = Arr::get($settings, 'version', $fallback);
66
-            if (version_compare($version, $fallback, '>')) {
67
-                return $version;
68
-            }
69
-        }
70
-        return $fallback;
71
-    }
56
+	/**
57
+	 * @return string
58
+	 */
59
+	protected function currentVersion()
60
+	{
61
+		$fallback = '0.0.0';
62
+		$majorVersions = [4, 3, 2];
63
+		foreach ($majorVersions as $majorVersion) {
64
+			$settings = get_option(OptionManager::databaseKey($majorVersion));
65
+			$version = Arr::get($settings, 'version', $fallback);
66
+			if (version_compare($version, $fallback, '>')) {
67
+				return $version;
68
+			}
69
+		}
70
+		return $fallback;
71
+	}
72 72
 
73
-    /**
74
-     * @return void
75
-     */
76
-    protected function setReviewCounts()
77
-    {
78
-        add_action('admin_init', 'glsr_calculate_ratings');
79
-    }
73
+	/**
74
+	 * @return void
75
+	 */
76
+	protected function setReviewCounts()
77
+	{
78
+		add_action('admin_init', 'glsr_calculate_ratings');
79
+	}
80 80
 
81
-    /**
82
-     * @param string $previousVersion
83
-     * @return void
84
-     */
85
-    protected function updateVersionFrom($previousVersion)
86
-    {
87
-        glsr(OptionManager::class)->set('version', glsr()->version);
88
-        glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion);
89
-    }
81
+	/**
82
+	 * @param string $previousVersion
83
+	 * @return void
84
+	 */
85
+	protected function updateVersionFrom($previousVersion)
86
+	{
87
+		glsr(OptionManager::class)->set('version', glsr()->version);
88
+		glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion);
89
+	}
90 90
 }
Please login to merge, or discard this patch.
plugin/Controllers/SettingsController.php 1 patch
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -9,120 +9,120 @@
 block discarded – undo
9 9
 
10 10
 class SettingsController extends Controller
11 11
 {
12
-    /**
13
-     * @param mixed $input
14
-     * @return array
15
-     * @callback register_setting
16
-     */
17
-    public function callbackRegisterSettings($input)
18
-    {
19
-        $settings = Arr::consolidateArray($input);
20
-        if (1 === count($settings) && array_key_exists('settings', $settings)) {
21
-            $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input);
22
-            $options = $this->sanitizeGeneral($input, $options);
23
-            $options = $this->sanitizeSubmissions($input, $options);
24
-            $options = $this->sanitizeTranslations($input, $options);
25
-            $options = apply_filters('site-reviews/settings/callback', $options, $settings);
26
-            if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') {
27
-                glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews'));
28
-            }
29
-            return $options;
30
-        }
31
-        return $input;
32
-    }
12
+	/**
13
+	 * @param mixed $input
14
+	 * @return array
15
+	 * @callback register_setting
16
+	 */
17
+	public function callbackRegisterSettings($input)
18
+	{
19
+		$settings = Arr::consolidateArray($input);
20
+		if (1 === count($settings) && array_key_exists('settings', $settings)) {
21
+			$options = array_replace_recursive(glsr(OptionManager::class)->all(), $input);
22
+			$options = $this->sanitizeGeneral($input, $options);
23
+			$options = $this->sanitizeSubmissions($input, $options);
24
+			$options = $this->sanitizeTranslations($input, $options);
25
+			$options = apply_filters('site-reviews/settings/callback', $options, $settings);
26
+			if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') {
27
+				glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews'));
28
+			}
29
+			return $options;
30
+		}
31
+		return $input;
32
+	}
33 33
 
34
-    /**
35
-     * @return void
36
-     * @action admin_init
37
-     */
38
-    public function registerSettings()
39
-    {
40
-        register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [
41
-            'sanitize_callback' => [$this, 'callbackRegisterSettings'],
42
-        ]);
43
-    }
34
+	/**
35
+	 * @return void
36
+	 * @action admin_init
37
+	 */
38
+	public function registerSettings()
39
+	{
40
+		register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [
41
+			'sanitize_callback' => [$this, 'callbackRegisterSettings'],
42
+		]);
43
+	}
44 44
 
45
-    /**
46
-     * @return array
47
-     */
48
-    protected function sanitizeGeneral(array $input, array $options)
49
-    {
50
-        $key = 'settings.general';
51
-        $inputForm = Arr::get($input, $key);
52
-        if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) {
53
-            $options = Arr::set($options, $key.'.multilingual', '');
54
-        }
55
-        if ('' == trim(Arr::get($inputForm, 'notification_message'))) {
56
-            $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message');
57
-            $options = Arr::set($options, $key.'.notification_message', $defaultValue);
58
-        }
59
-        $defaultValue = Arr::get($inputForm, 'notifications', []);
60
-        $options = Arr::set($options, $key.'.notifications', $defaultValue);
61
-        return $options;
62
-    }
45
+	/**
46
+	 * @return array
47
+	 */
48
+	protected function sanitizeGeneral(array $input, array $options)
49
+	{
50
+		$key = 'settings.general';
51
+		$inputForm = Arr::get($input, $key);
52
+		if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) {
53
+			$options = Arr::set($options, $key.'.multilingual', '');
54
+		}
55
+		if ('' == trim(Arr::get($inputForm, 'notification_message'))) {
56
+			$defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message');
57
+			$options = Arr::set($options, $key.'.notification_message', $defaultValue);
58
+		}
59
+		$defaultValue = Arr::get($inputForm, 'notifications', []);
60
+		$options = Arr::set($options, $key.'.notifications', $defaultValue);
61
+		return $options;
62
+	}
63 63
 
64
-    /**
65
-     * @return array
66
-     */
67
-    protected function sanitizeSubmissions(array $input, array $options)
68
-    {
69
-        $key = 'settings.submissions';
70
-        $inputForm = Arr::get($input, $key);
71
-        $defaultValue = isset($inputForm['required'])
72
-            ? $inputForm['required']
73
-            : [];
74
-        $options = Arr::set($options, $key.'.required', $defaultValue);
75
-        return $options;
76
-    }
64
+	/**
65
+	 * @return array
66
+	 */
67
+	protected function sanitizeSubmissions(array $input, array $options)
68
+	{
69
+		$key = 'settings.submissions';
70
+		$inputForm = Arr::get($input, $key);
71
+		$defaultValue = isset($inputForm['required'])
72
+			? $inputForm['required']
73
+			: [];
74
+		$options = Arr::set($options, $key.'.required', $defaultValue);
75
+		return $options;
76
+	}
77 77
 
78
-    /**
79
-     * @return array
80
-     */
81
-    protected function sanitizeTranslations(array $input, array $options)
82
-    {
83
-        $key = 'settings.strings';
84
-        $inputForm = Arr::consolidateArray(Arr::get($input, $key));
85
-        if (!empty($inputForm)) {
86
-            $options = Arr::set($options, $key, array_values(array_filter($inputForm)));
87
-            $allowedTags = [
88
-                'a' => ['class' => [], 'href' => [], 'target' => []],
89
-                'span' => ['class' => []],
90
-            ];
91
-            array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) {
92
-                if (isset($string['s2'])) {
93
-                    $string['s2'] = wp_kses($string['s2'], $allowedTags);
94
-                }
95
-                if (isset($string['p2'])) {
96
-                    $string['p2'] = wp_kses($string['p2'], $allowedTags);
97
-                }
98
-            });
99
-        }
100
-        return $options;
101
-    }
78
+	/**
79
+	 * @return array
80
+	 */
81
+	protected function sanitizeTranslations(array $input, array $options)
82
+	{
83
+		$key = 'settings.strings';
84
+		$inputForm = Arr::consolidateArray(Arr::get($input, $key));
85
+		if (!empty($inputForm)) {
86
+			$options = Arr::set($options, $key, array_values(array_filter($inputForm)));
87
+			$allowedTags = [
88
+				'a' => ['class' => [], 'href' => [], 'target' => []],
89
+				'span' => ['class' => []],
90
+			];
91
+			array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) {
92
+				if (isset($string['s2'])) {
93
+					$string['s2'] = wp_kses($string['s2'], $allowedTags);
94
+				}
95
+				if (isset($string['p2'])) {
96
+					$string['p2'] = wp_kses($string['p2'], $allowedTags);
97
+				}
98
+			});
99
+		}
100
+		return $options;
101
+	}
102 102
 
103
-    /**
104
-     * @return bool
105
-     */
106
-    protected function hasMultilingualIntegration($integration)
107
-    {
108
-        if (!in_array($integration, ['polylang', 'wpml'])) {
109
-            return false;
110
-        }
111
-        $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst($integration);
112
-        if (!glsr($integrationClass)->isActive()) {
113
-            glsr(Notice::class)->addError(sprintf(
114
-                __('Please install/activate the %s plugin to enable integration.', 'site-reviews'),
115
-                constant($integrationClass.'::PLUGIN_NAME')
116
-            ));
117
-            return false;
118
-        } elseif (!glsr($integrationClass)->isSupported()) {
119
-            glsr(Notice::class)->addError(sprintf(
120
-                __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'),
121
-                constant($integrationClass.'::PLUGIN_NAME'),
122
-                constant($integrationClass.'::SUPPORTED_VERSION')
123
-            ));
124
-            return false;
125
-        }
126
-        return true;
127
-    }
103
+	/**
104
+	 * @return bool
105
+	 */
106
+	protected function hasMultilingualIntegration($integration)
107
+	{
108
+		if (!in_array($integration, ['polylang', 'wpml'])) {
109
+			return false;
110
+		}
111
+		$integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst($integration);
112
+		if (!glsr($integrationClass)->isActive()) {
113
+			glsr(Notice::class)->addError(sprintf(
114
+				__('Please install/activate the %s plugin to enable integration.', 'site-reviews'),
115
+				constant($integrationClass.'::PLUGIN_NAME')
116
+			));
117
+			return false;
118
+		} elseif (!glsr($integrationClass)->isSupported()) {
119
+			glsr(Notice::class)->addError(sprintf(
120
+				__('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'),
121
+				constant($integrationClass.'::PLUGIN_NAME'),
122
+				constant($integrationClass.'::SUPPORTED_VERSION')
123
+			));
124
+			return false;
125
+		}
126
+		return true;
127
+	}
128 128
 }
Please login to merge, or discard this patch.
plugin/Defaults/StyleValidationDefaults.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -6,23 +6,23 @@
 block discarded – undo
6 6
 
7 7
 class StyleValidationDefaults extends Defaults
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    protected function defaults()
13
-    {
14
-        return [
15
-            'error_tag' => 'div',
16
-            'error_tag_class' => 'glsr-field-error',
17
-            'field_class' => 'glsr-field',
18
-            'field_error_class' => 'glsr-has-error',
19
-            'input_error_class' => 'glsr-is-invalid',
20
-            'input_valid_class' => 'glsr-is-valid',
21
-            'message_error_class' => 'glsr-has-errors',
22
-            'message_initial_class' => 'glsr-is-visible',
23
-            'message_success_class' => 'glsr-has-success',
24
-            'message_tag' => 'div',
25
-            'message_tag_class' => 'glsr-form-message',
26
-        ];
27
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	protected function defaults()
13
+	{
14
+		return [
15
+			'error_tag' => 'div',
16
+			'error_tag_class' => 'glsr-field-error',
17
+			'field_class' => 'glsr-field',
18
+			'field_error_class' => 'glsr-has-error',
19
+			'input_error_class' => 'glsr-is-invalid',
20
+			'input_valid_class' => 'glsr-is-valid',
21
+			'message_error_class' => 'glsr-has-errors',
22
+			'message_initial_class' => 'glsr-is-visible',
23
+			'message_success_class' => 'glsr-has-success',
24
+			'message_tag' => 'div',
25
+			'message_tag_class' => 'glsr-form-message',
26
+		];
27
+	}
28 28
 }
Please login to merge, or discard this patch.
plugin/Handlers/EnqueueAdminAssets.php 1 patch
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -10,158 +10,158 @@
 block discarded – undo
10 10
 
11 11
 class EnqueueAdminAssets
12 12
 {
13
-    /**
14
-     * @var array
15
-     */
16
-    protected $pointers;
13
+	/**
14
+	 * @var array
15
+	 */
16
+	protected $pointers;
17 17
 
18
-    /**
19
-     * @return void
20
-     */
21
-    public function handle(Command $command)
22
-    {
23
-        $this->generatePointers($command->pointers);
24
-        $this->enqueueAssets();
25
-        $this->localizeAssets();
26
-    }
18
+	/**
19
+	 * @return void
20
+	 */
21
+	public function handle(Command $command)
22
+	{
23
+		$this->generatePointers($command->pointers);
24
+		$this->enqueueAssets();
25
+		$this->localizeAssets();
26
+	}
27 27
 
28
-    /**
29
-     * @return void
30
-     */
31
-    public function enqueueAssets()
32
-    {
33
-        if (!$this->isCurrentScreen()) {
34
-            return;
35
-        }
36
-        wp_enqueue_style(
37
-            Application::ID,
38
-            glsr()->url('assets/styles/'.Application::ID.'-admin.css'),
39
-            [],
40
-            glsr()->version
41
-        );
42
-        wp_enqueue_script(
43
-            Application::ID,
44
-            glsr()->url('assets/scripts/'.Application::ID.'-admin.js'),
45
-            $this->getDependencies(),
46
-            glsr()->version,
47
-            true
48
-        );
49
-        if (!empty($this->pointers)) {
50
-            wp_enqueue_style('wp-pointer');
51
-            wp_enqueue_script('wp-pointer');
52
-        }
53
-    }
28
+	/**
29
+	 * @return void
30
+	 */
31
+	public function enqueueAssets()
32
+	{
33
+		if (!$this->isCurrentScreen()) {
34
+			return;
35
+		}
36
+		wp_enqueue_style(
37
+			Application::ID,
38
+			glsr()->url('assets/styles/'.Application::ID.'-admin.css'),
39
+			[],
40
+			glsr()->version
41
+		);
42
+		wp_enqueue_script(
43
+			Application::ID,
44
+			glsr()->url('assets/scripts/'.Application::ID.'-admin.js'),
45
+			$this->getDependencies(),
46
+			glsr()->version,
47
+			true
48
+		);
49
+		if (!empty($this->pointers)) {
50
+			wp_enqueue_style('wp-pointer');
51
+			wp_enqueue_script('wp-pointer');
52
+		}
53
+	}
54 54
 
55
-    /**
56
-     * @return void
57
-     */
58
-    public function localizeAssets()
59
-    {
60
-        $variables = [
61
-            'action' => Application::PREFIX.'action',
62
-            'addons' => [],
63
-            'ajaxurl' => admin_url('admin-ajax.php'),
64
-            'hideoptions' => [
65
-                'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(),
66
-                'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(),
67
-                'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(),
68
-            ],
69
-            'nameprefix' => Application::ID,
70
-            'nonce' => [
71
-                'change-status' => wp_create_nonce('change-status'),
72
-                'clear-console' => wp_create_nonce('clear-console'),
73
-                'count-reviews' => wp_create_nonce('count-reviews'),
74
-                'fetch-console' => wp_create_nonce('fetch-console'),
75
-                'mce-shortcode' => wp_create_nonce('mce-shortcode'),
76
-                'sync-reviews' => wp_create_nonce('sync-reviews'),
77
-                'toggle-pinned' => wp_create_nonce('toggle-pinned'),
78
-            ],
79
-            'pointers' => $this->pointers,
80
-            'shortcodes' => [],
81
-            'tinymce' => [
82
-                'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'),
83
-            ],
84
-        ];
85
-        if (user_can_richedit()) {
86
-            $variables['shortcodes'] = $this->localizeShortcodes();
87
-        }
88
-        $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables);
89
-        wp_localize_script(Application::ID, 'GLSR', $variables);
90
-    }
55
+	/**
56
+	 * @return void
57
+	 */
58
+	public function localizeAssets()
59
+	{
60
+		$variables = [
61
+			'action' => Application::PREFIX.'action',
62
+			'addons' => [],
63
+			'ajaxurl' => admin_url('admin-ajax.php'),
64
+			'hideoptions' => [
65
+				'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(),
66
+				'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(),
67
+				'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(),
68
+			],
69
+			'nameprefix' => Application::ID,
70
+			'nonce' => [
71
+				'change-status' => wp_create_nonce('change-status'),
72
+				'clear-console' => wp_create_nonce('clear-console'),
73
+				'count-reviews' => wp_create_nonce('count-reviews'),
74
+				'fetch-console' => wp_create_nonce('fetch-console'),
75
+				'mce-shortcode' => wp_create_nonce('mce-shortcode'),
76
+				'sync-reviews' => wp_create_nonce('sync-reviews'),
77
+				'toggle-pinned' => wp_create_nonce('toggle-pinned'),
78
+			],
79
+			'pointers' => $this->pointers,
80
+			'shortcodes' => [],
81
+			'tinymce' => [
82
+				'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'),
83
+			],
84
+		];
85
+		if (user_can_richedit()) {
86
+			$variables['shortcodes'] = $this->localizeShortcodes();
87
+		}
88
+		$variables = apply_filters('site-reviews/enqueue/admin/localize', $variables);
89
+		wp_localize_script(Application::ID, 'GLSR', $variables);
90
+	}
91 91
 
92
-    /**
93
-     * @return array
94
-     */
95
-    protected function getDependencies()
96
-    {
97
-        $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []);
98
-        $dependencies = array_merge($dependencies, [
99
-            'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util',
100
-        ]);
101
-        return $dependencies;
102
-    }
92
+	/**
93
+	 * @return array
94
+	 */
95
+	protected function getDependencies()
96
+	{
97
+		$dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []);
98
+		$dependencies = array_merge($dependencies, [
99
+			'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util',
100
+		]);
101
+		return $dependencies;
102
+	}
103 103
 
104
-    /**
105
-     * @return array
106
-     */
107
-    protected function generatePointer(array $pointer)
108
-    {
109
-        return [
110
-            'id' => $pointer['id'],
111
-            'options' => [
112
-                'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>',
113
-                'position' => $pointer['position'],
114
-            ],
115
-            'screen' => $pointer['screen'],
116
-            'target' => $pointer['target'],
117
-        ];
118
-    }
104
+	/**
105
+	 * @return array
106
+	 */
107
+	protected function generatePointer(array $pointer)
108
+	{
109
+		return [
110
+			'id' => $pointer['id'],
111
+			'options' => [
112
+				'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>',
113
+				'position' => $pointer['position'],
114
+			],
115
+			'screen' => $pointer['screen'],
116
+			'target' => $pointer['target'],
117
+		];
118
+	}
119 119
 
120
-    /**
121
-     * @return void
122
-     */
123
-    protected function generatePointers(array $pointers)
124
-    {
125
-        $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true);
126
-        $dismissedPointers = explode(',', (string) $dismissedPointers);
127
-        $generatedPointers = [];
128
-        foreach ($pointers as $pointer) {
129
-            if ($pointer['screen'] != glsr_current_screen()->id) {
130
-                continue;
131
-            }
132
-            if (in_array($pointer['id'], $dismissedPointers)) {
133
-                continue;
134
-            }
135
-            $generatedPointers[] = $this->generatePointer($pointer);
136
-        }
137
-        $this->pointers = $generatedPointers;
138
-    }
120
+	/**
121
+	 * @return void
122
+	 */
123
+	protected function generatePointers(array $pointers)
124
+	{
125
+		$dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true);
126
+		$dismissedPointers = explode(',', (string) $dismissedPointers);
127
+		$generatedPointers = [];
128
+		foreach ($pointers as $pointer) {
129
+			if ($pointer['screen'] != glsr_current_screen()->id) {
130
+				continue;
131
+			}
132
+			if (in_array($pointer['id'], $dismissedPointers)) {
133
+				continue;
134
+			}
135
+			$generatedPointers[] = $this->generatePointer($pointer);
136
+		}
137
+		$this->pointers = $generatedPointers;
138
+	}
139 139
 
140
-    /**
141
-     * @return bool
142
-     */
143
-    protected function isCurrentScreen()
144
-    {
145
-        $screen = glsr_current_screen();
146
-        return Application::POST_TYPE == $screen->post_type
147
-            || 'dashboard' == $screen->id
148
-            || 'plugins_page_'.Application::ID == $screen->id
149
-            || 'post' == $screen->base
150
-            || 'widgets' == $screen->id;
151
-    }
140
+	/**
141
+	 * @return bool
142
+	 */
143
+	protected function isCurrentScreen()
144
+	{
145
+		$screen = glsr_current_screen();
146
+		return Application::POST_TYPE == $screen->post_type
147
+			|| 'dashboard' == $screen->id
148
+			|| 'plugins_page_'.Application::ID == $screen->id
149
+			|| 'post' == $screen->base
150
+			|| 'widgets' == $screen->id;
151
+	}
152 152
 
153
-    /**
154
-     * @return array
155
-     */
156
-    protected function localizeShortcodes()
157
-    {
158
-        $variables = [];
159
-        foreach (glsr()->mceShortcodes as $tag => $args) {
160
-            if (empty($args['required'])) {
161
-                continue;
162
-            }
163
-            $variables[$tag] = $args['required'];
164
-        }
165
-        return $variables;
166
-    }
153
+	/**
154
+	 * @return array
155
+	 */
156
+	protected function localizeShortcodes()
157
+	{
158
+		$variables = [];
159
+		foreach (glsr()->mceShortcodes as $tag => $args) {
160
+			if (empty($args['required'])) {
161
+				continue;
162
+			}
163
+			$variables[$tag] = $args['required'];
164
+		}
165
+		return $variables;
166
+	}
167 167
 }
Please login to merge, or discard this patch.