Passed
Push — master ( 6b35fa...ccb079 )
by Paul
10:24 queued 05:13
created
plugin/Database/DefaultsManager.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -6,60 +6,60 @@
 block discarded – undo
6 6
 
7 7
 class DefaultsManager
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function defaults()
13
-    {
14
-        $settings = $this->settings();
15
-        $defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default'));
16
-        return wp_parse_args($defaults, [
17
-            'version' => '',
18
-            'version_upgraded_from' => '',
19
-        ]);
20
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function defaults()
13
+	{
14
+		$settings = $this->settings();
15
+		$defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default'));
16
+		return wp_parse_args($defaults, [
17
+			'version' => '',
18
+			'version_upgraded_from' => '',
19
+		]);
20
+	}
21 21
 
22
-    /**
23
-     * @return array
24
-     */
25
-    public function get()
26
-    {
27
-        return Arr::convertDotNotationArray($this->defaults());
28
-    }
22
+	/**
23
+	 * @return array
24
+	 */
25
+	public function get()
26
+	{
27
+		return Arr::convertDotNotationArray($this->defaults());
28
+	}
29 29
 
30
-    /**
31
-     * @return array
32
-     */
33
-    public function set()
34
-    {
35
-        $settings = glsr(OptionManager::class)->all();
36
-        $currentSettings = Arr::removeEmptyArrayValues($settings);
37
-        $defaultSettings = array_replace_recursive($this->get(), $currentSettings);
38
-        $updatedSettings = array_replace_recursive($settings, $defaultSettings);
39
-        update_option(OptionManager::databaseKey(), $updatedSettings);
40
-        return $defaultSettings;
41
-    }
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function set()
34
+	{
35
+		$settings = glsr(OptionManager::class)->all();
36
+		$currentSettings = Arr::removeEmptyArrayValues($settings);
37
+		$defaultSettings = array_replace_recursive($this->get(), $currentSettings);
38
+		$updatedSettings = array_replace_recursive($settings, $defaultSettings);
39
+		update_option(OptionManager::databaseKey(), $updatedSettings);
40
+		return $defaultSettings;
41
+	}
42 42
 
43
-    /**
44
-     * @return array
45
-     */
46
-    public function settings()
47
-    {
48
-        $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings'));
49
-        return $this->normalize($settings);
50
-    }
43
+	/**
44
+	 * @return array
45
+	 */
46
+	public function settings()
47
+	{
48
+		$settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings'));
49
+		return $this->normalize($settings);
50
+	}
51 51
 
52
-    /**
53
-     * @return array
54
-     */
55
-    protected function normalize(array $settings)
56
-    {
57
-        array_walk($settings, function (&$setting) {
58
-            if (isset($setting['default'])) {
59
-                return;
60
-            }
61
-            $setting['default'] = '';
62
-        });
63
-        return $settings;
64
-    }
52
+	/**
53
+	 * @return array
54
+	 */
55
+	protected function normalize(array $settings)
56
+	{
57
+		array_walk($settings, function (&$setting) {
58
+			if (isset($setting['default'])) {
59
+				return;
60
+			}
61
+			$setting['default'] = '';
62
+		});
63
+		return $settings;
64
+	}
65 65
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Settings.php 1 patch
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -11,239 +11,239 @@
 block discarded – undo
11 11
 
12 12
 class Settings
13 13
 {
14
-    /**
15
-     * @var array
16
-     */
17
-    public $settings;
18
-
19
-    /**
20
-     * @param string $id
21
-     * @return string
22
-     */
23
-    public function buildFields($id)
24
-    {
25
-        $this->settings = glsr(DefaultsManager::class)->settings();
26
-        $method = Helper::buildMethodName($id, 'getTemplateDataFor');
27
-        $data = !method_exists($this, $method)
28
-            ? $this->getTemplateData($id)
29
-            : $this->$method($id);
30
-        return glsr(Template::class)->build('pages/settings/'.$id, $data);
31
-    }
32
-
33
-    /**
34
-     * @return string
35
-     */
36
-    protected function getFieldDefault(array $field)
37
-    {
38
-        return Arr::get($field, 'default');
39
-    }
40
-
41
-    /**
42
-     * @return string
43
-     */
44
-    protected function getFieldNameForDependsOn($path)
45
-    {
46
-        $fieldName = Str::convertPathToName($path, OptionManager::databaseKey());
47
-        return $this->isMultiDependency($path)
48
-            ? $fieldName.'[]'
49
-            : $fieldName;
50
-    }
51
-
52
-    /**
53
-     * @return array
54
-     */
55
-    protected function getSettingFields($path)
56
-    {
57
-        return array_filter($this->settings, function ($key) use ($path) {
58
-            return Str::startsWith($path, $key);
59
-        }, ARRAY_FILTER_USE_KEY);
60
-    }
61
-
62
-    /**
63
-     * @return string
64
-     */
65
-    protected function getSettingRows(array $fields)
66
-    {
67
-        $rows = '';
68
-        foreach ($fields as $name => $field) {
69
-            $field = wp_parse_args($field, [
70
-                'is_setting' => true,
71
-                'name' => $name,
72
-            ]);
73
-            $rows.= new Field($this->normalize($field));
74
-        }
75
-        return $rows;
76
-    }
77
-
78
-    /**
79
-     * @param string $id
80
-     * @return array
81
-     */
82
-    protected function getTemplateData($id)
83
-    {
84
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
85
-        return [
86
-            'context' => [
87
-                'rows' => $this->getSettingRows($fields),
88
-            ],
89
-        ];
90
-    }
91
-
92
-    /**
93
-     * @param string $id
94
-     * @return array
95
-     */
96
-    protected function getTemplateDataForAddons($id)
97
-    {
98
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
99
-        $settings = Arr::convertDotNotationArray($fields);
100
-        $settingKeys = array_keys($settings['settings']['addons']);
101
-        $results = [];
102
-        foreach ($settingKeys as $key) {
103
-            $addonFields = array_filter($fields, function ($path) use ($key) {
104
-                return Str::startsWith('settings.addons.'.$key, $path);
105
-            }, ARRAY_FILTER_USE_KEY);
106
-            $results[$key] = $this->getSettingRows($addonFields);
107
-        }
108
-        ksort($results);
109
-        return [
110
-            'settings' => $results,
111
-        ];
112
-    }
113
-
114
-    /**
115
-     * @param string $id
116
-     * @return array
117
-     */
118
-    protected function getTemplateDataForLicenses($id)
119
-    {
120
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
121
-        ksort($fields);
122
-        return [
123
-            'context' => [
124
-                'rows' => $this->getSettingRows($fields),
125
-            ],
126
-        ];
127
-    }
128
-
129
-    /**
130
-     * @return array
131
-     */
132
-    protected function getTemplateDataForTranslations()
133
-    {
134
-        $translations = glsr(Translation::class)->renderAll();
135
-        $class = empty($translations)
136
-            ? 'glsr-hidden'
137
-            : '';
138
-        return [
139
-            'context' => [
140
-                'class' => $class,
141
-                'database_key' => OptionManager::databaseKey(),
142
-                'translations' => $translations,
143
-            ],
144
-        ];
145
-    }
146
-
147
-    /**
148
-     * @param string $path
149
-     * @param string|array $expectedValue
150
-     * @return bool
151
-     */
152
-    protected function isFieldHidden($path, $expectedValue)
153
-    {
154
-        $optionValue = glsr(OptionManager::class)->get(
155
-            $path,
156
-            Arr::get(glsr()->defaults, $path)
157
-        );
158
-        if (is_array($expectedValue)) {
159
-            return is_array($optionValue)
160
-                ? 0 === count(array_intersect($optionValue, $expectedValue))
161
-                : !in_array($optionValue, $expectedValue);
162
-        }
163
-        return $optionValue != $expectedValue;
164
-    }
165
-
166
-    /**
167
-     * @return bool
168
-     */
169
-    protected function isMultiDependency($path)
170
-    {
171
-        if (isset($this->settings[$path])) {
172
-            $field = $this->settings[$path];
173
-            return ('checkbox' == $field['type'] && !empty($field['options']))
174
-                || !empty($field['multiple']);
175
-        }
176
-        return false;
177
-    }
178
-
179
-    /**
180
-     * @return array
181
-     */
182
-    protected function normalize(array $field)
183
-    {
184
-        $field = $this->normalizeDependsOn($field);
185
-        $field = $this->normalizeLabelAndLegend($field);
186
-        $field = $this->normalizeValue($field);
187
-        return $field;
188
-    }
189
-
190
-    /**
191
-     * @return array
192
-     */
193
-    protected function normalizeDependsOn(array $field)
194
-    {
195
-        if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
196
-            $isFieldHidden = false;
197
-            $conditions = [];
198
-            foreach ($field['depends_on'] as $path => $value) {
199
-                $conditions[] = [
200
-                    'name' => $this->getFieldNameForDependsOn($path),
201
-                    'value' => $value,
202
-                ];
203
-                if ($this->isFieldHidden($path, $value)) {
204
-                    $isFieldHidden = true;
205
-                }
206
-            }
207
-            $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
208
-            $field['is_hidden'] = $isFieldHidden;
209
-        }
210
-        return $field;
211
-    }
212
-
213
-    /**
214
-     * @return array
215
-     */
216
-    protected function normalizeLabelAndLegend(array $field)
217
-    {
218
-        if (!empty($field['label'])) {
219
-            $field['legend'] = $field['label'];
220
-            unset($field['label']);
221
-        } else {
222
-            $field['is_valid'] = false;
223
-            glsr_log()->warning('Setting field is missing a label')->debug($field);
224
-        }
225
-        return $field;
226
-    }
227
-
228
-    /**
229
-     * @return array
230
-     */
231
-    protected function normalizeValue(array $field)
232
-    {
233
-        if (!isset($field['value'])) {
234
-            $field['value'] = glsr(OptionManager::class)->get(
235
-                $field['name'],
236
-                $this->getFieldDefault($field)
237
-            );
238
-        }
239
-        return $field;
240
-    }
241
-
242
-    /**
243
-     * @return string
244
-     */
245
-    protected function normalizeSettingPath($path)
246
-    {
247
-        return Str::prefix('settings.', rtrim($path, '.'));
248
-    }
14
+	/**
15
+	 * @var array
16
+	 */
17
+	public $settings;
18
+
19
+	/**
20
+	 * @param string $id
21
+	 * @return string
22
+	 */
23
+	public function buildFields($id)
24
+	{
25
+		$this->settings = glsr(DefaultsManager::class)->settings();
26
+		$method = Helper::buildMethodName($id, 'getTemplateDataFor');
27
+		$data = !method_exists($this, $method)
28
+			? $this->getTemplateData($id)
29
+			: $this->$method($id);
30
+		return glsr(Template::class)->build('pages/settings/'.$id, $data);
31
+	}
32
+
33
+	/**
34
+	 * @return string
35
+	 */
36
+	protected function getFieldDefault(array $field)
37
+	{
38
+		return Arr::get($field, 'default');
39
+	}
40
+
41
+	/**
42
+	 * @return string
43
+	 */
44
+	protected function getFieldNameForDependsOn($path)
45
+	{
46
+		$fieldName = Str::convertPathToName($path, OptionManager::databaseKey());
47
+		return $this->isMultiDependency($path)
48
+			? $fieldName.'[]'
49
+			: $fieldName;
50
+	}
51
+
52
+	/**
53
+	 * @return array
54
+	 */
55
+	protected function getSettingFields($path)
56
+	{
57
+		return array_filter($this->settings, function ($key) use ($path) {
58
+			return Str::startsWith($path, $key);
59
+		}, ARRAY_FILTER_USE_KEY);
60
+	}
61
+
62
+	/**
63
+	 * @return string
64
+	 */
65
+	protected function getSettingRows(array $fields)
66
+	{
67
+		$rows = '';
68
+		foreach ($fields as $name => $field) {
69
+			$field = wp_parse_args($field, [
70
+				'is_setting' => true,
71
+				'name' => $name,
72
+			]);
73
+			$rows.= new Field($this->normalize($field));
74
+		}
75
+		return $rows;
76
+	}
77
+
78
+	/**
79
+	 * @param string $id
80
+	 * @return array
81
+	 */
82
+	protected function getTemplateData($id)
83
+	{
84
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
85
+		return [
86
+			'context' => [
87
+				'rows' => $this->getSettingRows($fields),
88
+			],
89
+		];
90
+	}
91
+
92
+	/**
93
+	 * @param string $id
94
+	 * @return array
95
+	 */
96
+	protected function getTemplateDataForAddons($id)
97
+	{
98
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
99
+		$settings = Arr::convertDotNotationArray($fields);
100
+		$settingKeys = array_keys($settings['settings']['addons']);
101
+		$results = [];
102
+		foreach ($settingKeys as $key) {
103
+			$addonFields = array_filter($fields, function ($path) use ($key) {
104
+				return Str::startsWith('settings.addons.'.$key, $path);
105
+			}, ARRAY_FILTER_USE_KEY);
106
+			$results[$key] = $this->getSettingRows($addonFields);
107
+		}
108
+		ksort($results);
109
+		return [
110
+			'settings' => $results,
111
+		];
112
+	}
113
+
114
+	/**
115
+	 * @param string $id
116
+	 * @return array
117
+	 */
118
+	protected function getTemplateDataForLicenses($id)
119
+	{
120
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
121
+		ksort($fields);
122
+		return [
123
+			'context' => [
124
+				'rows' => $this->getSettingRows($fields),
125
+			],
126
+		];
127
+	}
128
+
129
+	/**
130
+	 * @return array
131
+	 */
132
+	protected function getTemplateDataForTranslations()
133
+	{
134
+		$translations = glsr(Translation::class)->renderAll();
135
+		$class = empty($translations)
136
+			? 'glsr-hidden'
137
+			: '';
138
+		return [
139
+			'context' => [
140
+				'class' => $class,
141
+				'database_key' => OptionManager::databaseKey(),
142
+				'translations' => $translations,
143
+			],
144
+		];
145
+	}
146
+
147
+	/**
148
+	 * @param string $path
149
+	 * @param string|array $expectedValue
150
+	 * @return bool
151
+	 */
152
+	protected function isFieldHidden($path, $expectedValue)
153
+	{
154
+		$optionValue = glsr(OptionManager::class)->get(
155
+			$path,
156
+			Arr::get(glsr()->defaults, $path)
157
+		);
158
+		if (is_array($expectedValue)) {
159
+			return is_array($optionValue)
160
+				? 0 === count(array_intersect($optionValue, $expectedValue))
161
+				: !in_array($optionValue, $expectedValue);
162
+		}
163
+		return $optionValue != $expectedValue;
164
+	}
165
+
166
+	/**
167
+	 * @return bool
168
+	 */
169
+	protected function isMultiDependency($path)
170
+	{
171
+		if (isset($this->settings[$path])) {
172
+			$field = $this->settings[$path];
173
+			return ('checkbox' == $field['type'] && !empty($field['options']))
174
+				|| !empty($field['multiple']);
175
+		}
176
+		return false;
177
+	}
178
+
179
+	/**
180
+	 * @return array
181
+	 */
182
+	protected function normalize(array $field)
183
+	{
184
+		$field = $this->normalizeDependsOn($field);
185
+		$field = $this->normalizeLabelAndLegend($field);
186
+		$field = $this->normalizeValue($field);
187
+		return $field;
188
+	}
189
+
190
+	/**
191
+	 * @return array
192
+	 */
193
+	protected function normalizeDependsOn(array $field)
194
+	{
195
+		if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
196
+			$isFieldHidden = false;
197
+			$conditions = [];
198
+			foreach ($field['depends_on'] as $path => $value) {
199
+				$conditions[] = [
200
+					'name' => $this->getFieldNameForDependsOn($path),
201
+					'value' => $value,
202
+				];
203
+				if ($this->isFieldHidden($path, $value)) {
204
+					$isFieldHidden = true;
205
+				}
206
+			}
207
+			$field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
208
+			$field['is_hidden'] = $isFieldHidden;
209
+		}
210
+		return $field;
211
+	}
212
+
213
+	/**
214
+	 * @return array
215
+	 */
216
+	protected function normalizeLabelAndLegend(array $field)
217
+	{
218
+		if (!empty($field['label'])) {
219
+			$field['legend'] = $field['label'];
220
+			unset($field['label']);
221
+		} else {
222
+			$field['is_valid'] = false;
223
+			glsr_log()->warning('Setting field is missing a label')->debug($field);
224
+		}
225
+		return $field;
226
+	}
227
+
228
+	/**
229
+	 * @return array
230
+	 */
231
+	protected function normalizeValue(array $field)
232
+	{
233
+		if (!isset($field['value'])) {
234
+			$field['value'] = glsr(OptionManager::class)->get(
235
+				$field['name'],
236
+				$this->getFieldDefault($field)
237
+			);
238
+		}
239
+		return $field;
240
+	}
241
+
242
+	/**
243
+	 * @return string
244
+	 */
245
+	protected function normalizeSettingPath($path)
246
+	{
247
+		return Str::prefix('settings.', rtrim($path, '.'));
248
+	}
249 249
 }
Please login to merge, or discard this patch.
plugin/Modules/Style.php 1 patch
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -12,144 +12,144 @@
 block discarded – undo
12 12
 
13 13
 class Style
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    public $fields;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	public $fields;
19 19
 
20
-    /**
21
-     * @var string
22
-     */
23
-    public $style;
20
+	/**
21
+	 * @var string
22
+	 */
23
+	public $style;
24 24
 
25
-    /**
26
-     * @var array
27
-     */
28
-    public $pagination;
25
+	/**
26
+	 * @var array
27
+	 */
28
+	public $pagination;
29 29
 
30
-    /**
31
-     * @var array
32
-     */
33
-    public $validation;
30
+	/**
31
+	 * @var array
32
+	 */
33
+	public $validation;
34 34
 
35
-    public function __construct()
36
-    {
37
-        $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default');
38
-        $this->setConfig();
39
-    }
35
+	public function __construct()
36
+	{
37
+		$this->style = glsr(OptionManager::class)->get('settings.general.style', 'default');
38
+		$this->setConfig();
39
+	}
40 40
 
41
-    /**
42
-     * @param string $view
43
-     * @return string
44
-     */
45
-    public function filterView($view)
46
-    {
47
-        $styledViews = [
48
-            'templates/form/field',
49
-            'templates/form/response',
50
-            'templates/form/submit-button',
51
-            'templates/reviews-form',
52
-        ];
53
-        if (!preg_match('('.implode('|', $styledViews).')', $view)) {
54
-            return $view;
55
-        }
56
-        $views = $this->generatePossibleViews($view);
57
-        foreach ($views as $possibleView) {
58
-            if (!file_exists(glsr()->file($possibleView))) {
59
-                continue;
60
-            }
61
-            return Str::removePrefix('views/', $possibleView);
62
-        }
63
-        return $view;
64
-    }
41
+	/**
42
+	 * @param string $view
43
+	 * @return string
44
+	 */
45
+	public function filterView($view)
46
+	{
47
+		$styledViews = [
48
+			'templates/form/field',
49
+			'templates/form/response',
50
+			'templates/form/submit-button',
51
+			'templates/reviews-form',
52
+		];
53
+		if (!preg_match('('.implode('|', $styledViews).')', $view)) {
54
+			return $view;
55
+		}
56
+		$views = $this->generatePossibleViews($view);
57
+		foreach ($views as $possibleView) {
58
+			if (!file_exists(glsr()->file($possibleView))) {
59
+				continue;
60
+			}
61
+			return Str::removePrefix('views/', $possibleView);
62
+		}
63
+		return $view;
64
+	}
65 65
 
66
-    /**
67
-     * @return string
68
-     */
69
-    public function get()
70
-    {
71
-        return apply_filters('site-reviews/style', $this->style);
72
-    }
66
+	/**
67
+	 * @return string
68
+	 */
69
+	public function get()
70
+	{
71
+		return apply_filters('site-reviews/style', $this->style);
72
+	}
73 73
 
74
-    /**
75
-     * @return array
76
-     */
77
-    public function setConfig()
78
-    {
79
-        $config = shortcode_atts(
80
-            array_fill_keys(['fields', 'pagination', 'validation'], []),
81
-            glsr()->config('styles/'.$this->style)
82
-        );
83
-        $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']);
84
-        $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']);
85
-        $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']);
86
-    }
74
+	/**
75
+	 * @return array
76
+	 */
77
+	public function setConfig()
78
+	{
79
+		$config = shortcode_atts(
80
+			array_fill_keys(['fields', 'pagination', 'validation'], []),
81
+			glsr()->config('styles/'.$this->style)
82
+		);
83
+		$this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']);
84
+		$this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']);
85
+		$this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']);
86
+	}
87 87
 
88
-    /**
89
-     * @return void
90
-     */
91
-    public function modifyField(Builder $instance)
92
-    {
93
-        if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) {
94
-            return;
95
-        }
96
-        call_user_func_array([$this, 'customize'], [$instance]);
97
-    }
88
+	/**
89
+	 * @return void
90
+	 */
91
+	public function modifyField(Builder $instance)
92
+	{
93
+		if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) {
94
+			return;
95
+		}
96
+		call_user_func_array([$this, 'customize'], [$instance]);
97
+	}
98 98
 
99
-    /**
100
-     * @return array
101
-     */
102
-    public function paginationArgs(array $args)
103
-    {
104
-        return wp_parse_args($args, $this->pagination);
105
-    }
99
+	/**
100
+	 * @return array
101
+	 */
102
+	public function paginationArgs(array $args)
103
+	{
104
+		return wp_parse_args($args, $this->pagination);
105
+	}
106 106
 
107
-    /**
108
-     * @return void
109
-     */
110
-    protected function customize(Builder $instance)
111
-    {
112
-        if (!array_key_exists($instance->tag, $this->fields)) {
113
-            return;
114
-        }
115
-        $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], ''));
116
-        $key = $instance->tag.'_'.$args['type'];
117
-        $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag));
118
-        $instance->args['class'] = trim($args['class'].' '.$classes);
119
-        do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]);
120
-    }
107
+	/**
108
+	 * @return void
109
+	 */
110
+	protected function customize(Builder $instance)
111
+	{
112
+		if (!array_key_exists($instance->tag, $this->fields)) {
113
+			return;
114
+		}
115
+		$args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], ''));
116
+		$key = $instance->tag.'_'.$args['type'];
117
+		$classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag));
118
+		$instance->args['class'] = trim($args['class'].' '.$classes);
119
+		do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]);
120
+	}
121 121
 
122
-    /**
123
-     * @param string $view
124
-     * @return array
125
-     */
126
-    protected function generatePossibleViews($view)
127
-    {
128
-        $basename = basename($view);
129
-        $basepath = rtrim($view, $basename);
130
-        $customPath = 'views/partials/styles/'.$this->style.'/';
131
-        $parts = explode('_', $basename);
132
-        $views = [
133
-            $customPath.$basename,
134
-            $customPath.$parts[0],
135
-            $view,
136
-            $basepath.$parts[0],
137
-        ];
138
-        return array_filter($views);
139
-    }
122
+	/**
123
+	 * @param string $view
124
+	 * @return array
125
+	 */
126
+	protected function generatePossibleViews($view)
127
+	{
128
+		$basename = basename($view);
129
+		$basepath = rtrim($view, $basename);
130
+		$customPath = 'views/partials/styles/'.$this->style.'/';
131
+		$parts = explode('_', $basename);
132
+		$views = [
133
+			$customPath.$basename,
134
+			$customPath.$parts[0],
135
+			$view,
136
+			$basepath.$parts[0],
137
+		];
138
+		return array_filter($views);
139
+	}
140 140
 
141
-    /**
142
-     * @return bool
143
-     */
144
-    protected function isPublicInstance(Builder $instance)
145
-    {
146
-        $args = wp_parse_args($instance->args, [
147
-            'is_public' => false,
148
-            'is_raw' => false,
149
-        ]);
150
-        if (is_admin() || !$args['is_public'] || $args['is_raw']) {
151
-            return false;
152
-        }
153
-        return true;
154
-    }
141
+	/**
142
+	 * @return bool
143
+	 */
144
+	protected function isPublicInstance(Builder $instance)
145
+	{
146
+		$args = wp_parse_args($instance->args, [
147
+			'is_public' => false,
148
+			'is_raw' => false,
149
+		]);
150
+		if (is_admin() || !$args['is_public'] || $args['is_raw']) {
151
+			return false;
152
+		}
153
+		return true;
154
+	}
155 155
 }
Please login to merge, or discard this patch.
plugin/Review.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -12,173 +12,173 @@
 block discarded – undo
12 12
 
13 13
 class Review implements \ArrayAccess
14 14
 {
15
-    public $assigned_to;
16
-    public $author;
17
-    public $avatar;
18
-    public $content;
19
-    public $custom;
20
-    public $date;
21
-    public $email;
22
-    public $ID;
23
-    public $ip_address;
24
-    public $modified;
25
-    public $pinned;
26
-    public $rating;
27
-    public $response;
28
-    public $review_id;
29
-    public $review_type;
30
-    public $status;
31
-    public $term_ids;
32
-    public $title;
33
-    public $url;
34
-    public $user_id;
15
+	public $assigned_to;
16
+	public $author;
17
+	public $avatar;
18
+	public $content;
19
+	public $custom;
20
+	public $date;
21
+	public $email;
22
+	public $ID;
23
+	public $ip_address;
24
+	public $modified;
25
+	public $pinned;
26
+	public $rating;
27
+	public $response;
28
+	public $review_id;
29
+	public $review_type;
30
+	public $status;
31
+	public $term_ids;
32
+	public $title;
33
+	public $url;
34
+	public $user_id;
35 35
 
36
-    public function __construct(WP_Post $post)
37
-    {
38
-        if (Application::POST_TYPE != $post->post_type) {
39
-            return;
40
-        }
41
-        $this->content = $post->post_content;
42
-        $this->date = $post->post_date;
43
-        $this->ID = intval($post->ID);
44
-        $this->status = $post->post_status;
45
-        $this->title = $post->post_title;
46
-        $this->user_id = intval($post->post_author);
47
-        $this->setProperties($post);
48
-        $this->setTermIds($post);
49
-    }
36
+	public function __construct(WP_Post $post)
37
+	{
38
+		if (Application::POST_TYPE != $post->post_type) {
39
+			return;
40
+		}
41
+		$this->content = $post->post_content;
42
+		$this->date = $post->post_date;
43
+		$this->ID = intval($post->ID);
44
+		$this->status = $post->post_status;
45
+		$this->title = $post->post_title;
46
+		$this->user_id = intval($post->post_author);
47
+		$this->setProperties($post);
48
+		$this->setTermIds($post);
49
+	}
50 50
 
51
-    /**
52
-     * @return mixed
53
-     */
54
-    public function __get($key)
55
-    {
56
-        return $this->offsetGet($key);
57
-    }
51
+	/**
52
+	 * @return mixed
53
+	 */
54
+	public function __get($key)
55
+	{
56
+		return $this->offsetGet($key);
57
+	}
58 58
 
59
-    /**
60
-     * @return string
61
-     */
62
-    public function __toString()
63
-    {
64
-        return (string) $this->build();
65
-    }
59
+	/**
60
+	 * @return string
61
+	 */
62
+	public function __toString()
63
+	{
64
+		return (string) $this->build();
65
+	}
66 66
 
67
-    /**
68
-     * @return ReviewHtml
69
-     */
70
-    public function build(array $args = [])
71
-    {
72
-        if (empty($this->ID)) {
73
-            return new ReviewHtml($this);
74
-        }
75
-        $partial = glsr(SiteReviewsPartial::class);
76
-        $partial->args = glsr(SiteReviewsDefaults::class)->merge($args);
77
-        $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all());
78
-        return $partial->buildReview($this);
79
-    }
67
+	/**
68
+	 * @return ReviewHtml
69
+	 */
70
+	public function build(array $args = [])
71
+	{
72
+		if (empty($this->ID)) {
73
+			return new ReviewHtml($this);
74
+		}
75
+		$partial = glsr(SiteReviewsPartial::class);
76
+		$partial->args = glsr(SiteReviewsDefaults::class)->merge($args);
77
+		$partial->options = Arr::flattenArray(glsr(OptionManager::class)->all());
78
+		return $partial->buildReview($this);
79
+	}
80 80
 
81
-    /**
82
-     * @param mixed $key
83
-     * @return bool
84
-     */
85
-    public function offsetExists($key)
86
-    {
87
-        return property_exists($this, $key) || array_key_exists($key, (array) $this->custom);
88
-    }
81
+	/**
82
+	 * @param mixed $key
83
+	 * @return bool
84
+	 */
85
+	public function offsetExists($key)
86
+	{
87
+		return property_exists($this, $key) || array_key_exists($key, (array) $this->custom);
88
+	}
89 89
 
90
-    /**
91
-     * @param mixed $key
92
-     * @return mixed
93
-     */
94
-    public function offsetGet($key)
95
-    {
96
-        return property_exists($this, $key)
97
-            ? $this->$key
98
-            : Arr::get($this->custom, $key, null);
99
-    }
90
+	/**
91
+	 * @param mixed $key
92
+	 * @return mixed
93
+	 */
94
+	public function offsetGet($key)
95
+	{
96
+		return property_exists($this, $key)
97
+			? $this->$key
98
+			: Arr::get($this->custom, $key, null);
99
+	}
100 100
 
101
-    /**
102
-     * @param mixed $key
103
-     * @param mixed $value
104
-     * @return void
105
-     */
106
-    public function offsetSet($key, $value)
107
-    {
108
-        if (property_exists($this, $key)) {
109
-            $this->$key = $value;
110
-            return;
111
-        }
112
-        if (!is_array($this->custom)) {
113
-            $this->custom = array_filter((array) $this->custom);
114
-        }
115
-        $this->custom[$key] = $value;
116
-    }
101
+	/**
102
+	 * @param mixed $key
103
+	 * @param mixed $value
104
+	 * @return void
105
+	 */
106
+	public function offsetSet($key, $value)
107
+	{
108
+		if (property_exists($this, $key)) {
109
+			$this->$key = $value;
110
+			return;
111
+		}
112
+		if (!is_array($this->custom)) {
113
+			$this->custom = array_filter((array) $this->custom);
114
+		}
115
+		$this->custom[$key] = $value;
116
+	}
117 117
 
118
-    /**
119
-     * @param mixed $key
120
-     * @return void
121
-     */
122
-    public function offsetUnset($key)
123
-    {
124
-        $this->offsetSet($key, null);
125
-    }
118
+	/**
119
+	 * @param mixed $key
120
+	 * @return void
121
+	 */
122
+	public function offsetUnset($key)
123
+	{
124
+		$this->offsetSet($key, null);
125
+	}
126 126
 
127
-    /**
128
-     * @return void
129
-     */
130
-    public function render()
131
-    {
132
-        echo $this->build();
133
-    }
127
+	/**
128
+	 * @return void
129
+	 */
130
+	public function render()
131
+	{
132
+		echo $this->build();
133
+	}
134 134
 
135
-    /**
136
-     * @return bool
137
-     */
138
-    protected function isModified(array $properties)
139
-    {
140
-        return $this->date != $properties['date']
141
-            || $this->content != $properties['content']
142
-            || $this->title != $properties['title'];
143
-    }
135
+	/**
136
+	 * @return bool
137
+	 */
138
+	protected function isModified(array $properties)
139
+	{
140
+		return $this->date != $properties['date']
141
+			|| $this->content != $properties['content']
142
+			|| $this->title != $properties['title'];
143
+	}
144 144
 
145
-    /**
146
-     * @return void
147
-     */
148
-    protected function setProperties(WP_Post $post)
149
-    {
150
-        $defaults = [
151
-            'author' => __('Anonymous', 'site-reviews'),
152
-            'date' => '',
153
-            'review_id' => '',
154
-            'review_type' => 'local',
155
-        ];
156
-        $meta = array_filter(
157
-            array_map('array_shift', array_filter((array) get_post_meta($post->ID))),
158
-            'strlen'
159
-        );
160
-        $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta));
161
-        $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta));
162
-        $this->modified = $this->isModified($properties);
163
-        array_walk($properties, function ($value, $key) {
164
-            if (!property_exists($this, $key) || isset($this->$key)) {
165
-                return;
166
-            }
167
-            $this->$key = maybe_unserialize($value);
168
-        });
169
-    }
145
+	/**
146
+	 * @return void
147
+	 */
148
+	protected function setProperties(WP_Post $post)
149
+	{
150
+		$defaults = [
151
+			'author' => __('Anonymous', 'site-reviews'),
152
+			'date' => '',
153
+			'review_id' => '',
154
+			'review_type' => 'local',
155
+		];
156
+		$meta = array_filter(
157
+			array_map('array_shift', array_filter((array) get_post_meta($post->ID))),
158
+			'strlen'
159
+		);
160
+		$meta = array_merge($defaults, Arr::unprefixArrayKeys($meta));
161
+		$properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta));
162
+		$this->modified = $this->isModified($properties);
163
+		array_walk($properties, function ($value, $key) {
164
+			if (!property_exists($this, $key) || isset($this->$key)) {
165
+				return;
166
+			}
167
+			$this->$key = maybe_unserialize($value);
168
+		});
169
+	}
170 170
 
171
-    /**
172
-     * @return void
173
-     */
174
-    protected function setTermIds(WP_Post $post)
175
-    {
176
-        $this->term_ids = [];
177
-        if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) {
178
-            return;
179
-        }
180
-        foreach ($terms as $term) {
181
-            $this->term_ids[] = $term->term_id;
182
-        }
183
-    }
171
+	/**
172
+	 * @return void
173
+	 */
174
+	protected function setTermIds(WP_Post $post)
175
+	{
176
+		$this->term_ids = [];
177
+		if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) {
178
+			return;
179
+		}
180
+		foreach ($terms as $term) {
181
+			$this->term_ids[] = $term->term_id;
182
+		}
183
+	}
184 184
 }
Please login to merge, or discard this patch.
plugin/Blocks/SiteReviewsBlock.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -6,124 +6,124 @@
 block discarded – undo
6 6
 
7 7
 class SiteReviewsBlock extends BlockGenerator
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function attributes()
13
-    {
14
-        return [
15
-            'assigned_to' => [
16
-                'default' => '',
17
-                'type' => 'string',
18
-            ],
19
-            'category' => [
20
-                'default' => '',
21
-                'type' => 'string',
22
-            ],
23
-            'className' => [
24
-                'default' => '',
25
-                'type' => 'string',
26
-            ],
27
-            'display' => [
28
-                'default' => 5,
29
-                'type' => 'number',
30
-            ],
31
-            'hide' => [
32
-                'default' => '',
33
-                'type' => 'string',
34
-            ],
35
-            'id' => [
36
-                'default' => '',
37
-                'type' => 'string',
38
-            ],
39
-            'pagination' => [
40
-                'default' => '',
41
-                'type' => 'string',
42
-            ],
43
-            'post_id' => [
44
-                'default' => '',
45
-                'type' => 'string',
46
-            ],
47
-            'rating' => [
48
-                'default' => 0,
49
-                'type' => 'number',
50
-            ],
51
-            'schema' => [
52
-                'default' => false,
53
-                'type' => 'boolean',
54
-            ],
55
-            'type' => [
56
-                'default' => 'local',
57
-                'type' => 'string',
58
-            ],
59
-        ];
60
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function attributes()
13
+	{
14
+		return [
15
+			'assigned_to' => [
16
+				'default' => '',
17
+				'type' => 'string',
18
+			],
19
+			'category' => [
20
+				'default' => '',
21
+				'type' => 'string',
22
+			],
23
+			'className' => [
24
+				'default' => '',
25
+				'type' => 'string',
26
+			],
27
+			'display' => [
28
+				'default' => 5,
29
+				'type' => 'number',
30
+			],
31
+			'hide' => [
32
+				'default' => '',
33
+				'type' => 'string',
34
+			],
35
+			'id' => [
36
+				'default' => '',
37
+				'type' => 'string',
38
+			],
39
+			'pagination' => [
40
+				'default' => '',
41
+				'type' => 'string',
42
+			],
43
+			'post_id' => [
44
+				'default' => '',
45
+				'type' => 'string',
46
+			],
47
+			'rating' => [
48
+				'default' => 0,
49
+				'type' => 'number',
50
+			],
51
+			'schema' => [
52
+				'default' => false,
53
+				'type' => 'boolean',
54
+			],
55
+			'type' => [
56
+				'default' => 'local',
57
+				'type' => 'string',
58
+			],
59
+		];
60
+	}
61 61
 
62
-    /**
63
-     * @return string
64
-     */
65
-    public function render(array $attributes)
66
-    {
67
-        $attributes['class'] = $attributes['className'];
68
-        $shortcode = glsr(Shortcode::class);
69
-        if ('edit' == filter_input(INPUT_GET, 'context')) {
70
-            $attributes = $this->normalize($attributes);
71
-            $this->filterReviewLinks();
72
-            $this->filterShortcodeClass();
73
-            $this->filterShowMoreLinks('content');
74
-            $this->filterShowMoreLinks('response');
75
-            if (!$this->hasVisibleFields($shortcode, $attributes)) {
76
-                $this->filterInterpolation();
77
-            }
78
-        }
79
-        return $shortcode->buildShortcode($attributes);
80
-    }
62
+	/**
63
+	 * @return string
64
+	 */
65
+	public function render(array $attributes)
66
+	{
67
+		$attributes['class'] = $attributes['className'];
68
+		$shortcode = glsr(Shortcode::class);
69
+		if ('edit' == filter_input(INPUT_GET, 'context')) {
70
+			$attributes = $this->normalize($attributes);
71
+			$this->filterReviewLinks();
72
+			$this->filterShortcodeClass();
73
+			$this->filterShowMoreLinks('content');
74
+			$this->filterShowMoreLinks('response');
75
+			if (!$this->hasVisibleFields($shortcode, $attributes)) {
76
+				$this->filterInterpolation();
77
+			}
78
+		}
79
+		return $shortcode->buildShortcode($attributes);
80
+	}
81 81
 
82
-    /**
83
-     * @return void
84
-     */
85
-    protected function filterInterpolation()
86
-    {
87
-        add_filter('site-reviews/interpolate/reviews', function ($context) {
88
-            $context['class'] = 'glsr-default glsr-block-disabled';
89
-            $context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews');
90
-            return $context;
91
-        });
92
-    }
82
+	/**
83
+	 * @return void
84
+	 */
85
+	protected function filterInterpolation()
86
+	{
87
+		add_filter('site-reviews/interpolate/reviews', function ($context) {
88
+			$context['class'] = 'glsr-default glsr-block-disabled';
89
+			$context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews');
90
+			return $context;
91
+		});
92
+	}
93 93
 
94
-    /**
95
-     * @return void
96
-     */
97
-    protected function filterReviewLinks()
98
-    {
99
-        add_filter('site-reviews/rendered/template/reviews', function ($template) {
100
-            return str_replace('<a', '<a tabindex="-1"', $template);
101
-        });
102
-    }
94
+	/**
95
+	 * @return void
96
+	 */
97
+	protected function filterReviewLinks()
98
+	{
99
+		add_filter('site-reviews/rendered/template/reviews', function ($template) {
100
+			return str_replace('<a', '<a tabindex="-1"', $template);
101
+		});
102
+	}
103 103
 
104
-    /**
105
-     * @return void
106
-     */
107
-    protected function filterShortcodeClass()
108
-    {
109
-        add_filter('site-reviews/style', function () {
110
-            return 'default';
111
-        });
112
-    }
104
+	/**
105
+	 * @return void
106
+	 */
107
+	protected function filterShortcodeClass()
108
+	{
109
+		add_filter('site-reviews/style', function () {
110
+			return 'default';
111
+		});
112
+	}
113 113
 
114
-    /**
115
-     * @param string $field
116
-     * @return void
117
-     */
118
-    protected function filterShowMoreLinks($field)
119
-    {
120
-        add_filter('site-reviews/review/wrap/'.$field, function ($value) {
121
-            $value = preg_replace(
122
-                '/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/s',
123
-                '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5',
124
-                $value
125
-            );
126
-            return $value;
127
-        });
128
-    }
114
+	/**
115
+	 * @param string $field
116
+	 * @return void
117
+	 */
118
+	protected function filterShowMoreLinks($field)
119
+	{
120
+		add_filter('site-reviews/review/wrap/'.$field, function ($value) {
121
+			$value = preg_replace(
122
+				'/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/s',
123
+				'$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5',
124
+				$value
125
+			);
126
+			return $value;
127
+		});
128
+	}
129 129
 }
Please login to merge, or discard this patch.
plugin/Defaults/DefaultsAbstract.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -8,137 +8,137 @@
 block discarded – undo
8 8
 
9 9
 abstract class DefaultsAbstract
10 10
 {
11
-    /**
12
-     * @var array
13
-     */
14
-    protected $callable = [
15
-        'defaults', 'filter', 'merge', 'restrict', 'unguarded',
16
-    ];
17
-
18
-    /**
19
-     * @var array
20
-     */
21
-    protected $guarded = [];
22
-
23
-    /**
24
-     * @var array
25
-     */
26
-    protected $mapped = [];
27
-
28
-    /**
29
-     * @param string $name
30
-     * @return void|array
31
-     */
32
-    public function __call($name, array $args = [])
33
-    {
34
-        if (!method_exists($this, $name) || !in_array($name, $this->callable)) {
35
-            return;
36
-        }
37
-        $args[0] = $this->mapKeys(Arr::get($args, 0, []));
38
-        $defaults = call_user_func_array([$this, $name], $args);
39
-        $hookName = (new ReflectionClass($this))->getShortName();
40
-        $hookName = str_replace('Defaults', '', $hookName);
41
-        $hookName = Str::dashCase($hookName);
42
-        return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name);
43
-    }
44
-
45
-    /**
46
-     * @return array
47
-     */
48
-    abstract protected function defaults();
49
-
50
-    /**
51
-     * @return array
52
-     */
53
-    protected function filter(array $values = [])
54
-    {
55
-        return $this->normalize($this->merge(array_filter($values)), $values);
56
-    }
57
-
58
-    /**
59
-     * @return string
60
-     */
61
-    protected function filteredJson(array $values = [])
62
-    {
63
-        $defaults = $this->flattenArray(
64
-            array_diff_key($this->defaults(), array_flip($this->guarded))
65
-        );
66
-        $values = $this->flattenArray(
67
-            shortcode_atts($defaults, $values)
68
-        );
69
-        $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) {
70
-            return !$this->isEmpty($value);
71
-        });
72
-        return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
73
-    }
74
-
75
-    /**
76
-     * @return array
77
-     */
78
-    protected function flattenArray(array $values)
79
-    {
80
-        array_walk($values, function (&$value) {
81
-            if (!is_array($value)) {
82
-                return;
83
-            }
84
-            $value = implode(',', $value);
85
-        });
86
-        return $values;
87
-    }
88
-
89
-    /**
90
-     * @param mixed $var
91
-     * @return bool
92
-     */
93
-    protected function isEmpty($var)
94
-    {
95
-        return !is_numeric($var) && !is_bool($var) && empty($var);
96
-    }
97
-
98
-    /**
99
-     * @return array
100
-     */
101
-    protected function mapKeys(array $args)
102
-    {
103
-        foreach ($this->mapped as $old => $new) {
104
-            if (array_key_exists($old, $args)) {
105
-                $args[$new] = $args[$old];
106
-                unset($args[$old]);
107
-            }
108
-        }
109
-        return $args;
110
-    }
111
-
112
-    /**
113
-     * @return array
114
-     */
115
-    protected function merge(array $values = [])
116
-    {
117
-        return $this->normalize(wp_parse_args($values, $this->defaults()), $values);
118
-    }
119
-
120
-    /**
121
-     * @return array
122
-     */
123
-    protected function normalize(array $values, array $originalValues)
124
-    {
125
-        $values['json'] = $this->filteredJson($originalValues);
126
-        return $values;
127
-    }
128
-
129
-    /**
130
-     * @return array
131
-     */
132
-    protected function restrict(array $values = [])
133
-    {
134
-        return $this->normalize(shortcode_atts($this->defaults(), $values), $values);
135
-    }
136
-
137
-    /**
138
-     * @return array
139
-     */
140
-    protected function unguarded()
141
-    {
142
-        return array_diff_key($this->defaults(), array_flip($this->guarded));
143
-    }
11
+	/**
12
+	 * @var array
13
+	 */
14
+	protected $callable = [
15
+		'defaults', 'filter', 'merge', 'restrict', 'unguarded',
16
+	];
17
+
18
+	/**
19
+	 * @var array
20
+	 */
21
+	protected $guarded = [];
22
+
23
+	/**
24
+	 * @var array
25
+	 */
26
+	protected $mapped = [];
27
+
28
+	/**
29
+	 * @param string $name
30
+	 * @return void|array
31
+	 */
32
+	public function __call($name, array $args = [])
33
+	{
34
+		if (!method_exists($this, $name) || !in_array($name, $this->callable)) {
35
+			return;
36
+		}
37
+		$args[0] = $this->mapKeys(Arr::get($args, 0, []));
38
+		$defaults = call_user_func_array([$this, $name], $args);
39
+		$hookName = (new ReflectionClass($this))->getShortName();
40
+		$hookName = str_replace('Defaults', '', $hookName);
41
+		$hookName = Str::dashCase($hookName);
42
+		return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name);
43
+	}
44
+
45
+	/**
46
+	 * @return array
47
+	 */
48
+	abstract protected function defaults();
49
+
50
+	/**
51
+	 * @return array
52
+	 */
53
+	protected function filter(array $values = [])
54
+	{
55
+		return $this->normalize($this->merge(array_filter($values)), $values);
56
+	}
57
+
58
+	/**
59
+	 * @return string
60
+	 */
61
+	protected function filteredJson(array $values = [])
62
+	{
63
+		$defaults = $this->flattenArray(
64
+			array_diff_key($this->defaults(), array_flip($this->guarded))
65
+		);
66
+		$values = $this->flattenArray(
67
+			shortcode_atts($defaults, $values)
68
+		);
69
+		$filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) {
70
+			return !$this->isEmpty($value);
71
+		});
72
+		return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
73
+	}
74
+
75
+	/**
76
+	 * @return array
77
+	 */
78
+	protected function flattenArray(array $values)
79
+	{
80
+		array_walk($values, function (&$value) {
81
+			if (!is_array($value)) {
82
+				return;
83
+			}
84
+			$value = implode(',', $value);
85
+		});
86
+		return $values;
87
+	}
88
+
89
+	/**
90
+	 * @param mixed $var
91
+	 * @return bool
92
+	 */
93
+	protected function isEmpty($var)
94
+	{
95
+		return !is_numeric($var) && !is_bool($var) && empty($var);
96
+	}
97
+
98
+	/**
99
+	 * @return array
100
+	 */
101
+	protected function mapKeys(array $args)
102
+	{
103
+		foreach ($this->mapped as $old => $new) {
104
+			if (array_key_exists($old, $args)) {
105
+				$args[$new] = $args[$old];
106
+				unset($args[$old]);
107
+			}
108
+		}
109
+		return $args;
110
+	}
111
+
112
+	/**
113
+	 * @return array
114
+	 */
115
+	protected function merge(array $values = [])
116
+	{
117
+		return $this->normalize(wp_parse_args($values, $this->defaults()), $values);
118
+	}
119
+
120
+	/**
121
+	 * @return array
122
+	 */
123
+	protected function normalize(array $values, array $originalValues)
124
+	{
125
+		$values['json'] = $this->filteredJson($originalValues);
126
+		return $values;
127
+	}
128
+
129
+	/**
130
+	 * @return array
131
+	 */
132
+	protected function restrict(array $values = [])
133
+	{
134
+		return $this->normalize(shortcode_atts($this->defaults(), $values), $values);
135
+	}
136
+
137
+	/**
138
+	 * @return array
139
+	 */
140
+	protected function unguarded()
141
+	{
142
+		return array_diff_key($this->defaults(), array_flip($this->guarded));
143
+	}
144 144
 }
Please login to merge, or discard this patch.
plugin/Controllers/TranslationController.php 1 patch
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -10,228 +10,228 @@
 block discarded – undo
10 10
 
11 11
 class TranslationController
12 12
 {
13
-    /**
14
-     * @var Translator
15
-     */
16
-    public $translator;
17
-
18
-    public function __construct(Translator $translator)
19
-    {
20
-        $this->translator = $translator;
21
-    }
22
-
23
-    /**
24
-     * @param array $messages
25
-     * @return array
26
-     * @filter bulk_post_updated_messages
27
-     */
28
-    public function filterBulkUpdateMessages($messages, array $counts)
29
-    {
30
-        $messages = Arr::consolidateArray($messages);
31
-        $messages[Application::POST_TYPE] = [
32
-            'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'),
33
-            'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'),
34
-            'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'),
35
-            'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'),
36
-            'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'),
37
-        ];
38
-        return $messages;
39
-    }
40
-
41
-    /**
42
-     * @param string $translation
43
-     * @param string $text
44
-     * @param string $domain
45
-     * @return string
46
-     * @filter gettext
47
-     */
48
-    public function filterGettext($translation, $text, $domain)
49
-    {
50
-        return apply_filters('site-reviews/gettext/'.$domain, $translation, $text);
51
-    }
52
-
53
-    /**
54
-     * @param string $translation
55
-     * @param string $text
56
-     * @return string
57
-     * @filter site-reviews/gettext/site-reviews
58
-     */
59
-    public function filterGettextSiteReviews($translation, $text)
60
-    {
61
-        return $this->translator->translate($translation, Application::ID, [
62
-            'single' => $text,
63
-        ]);
64
-    }
65
-
66
-    /**
67
-     * @param string $translation
68
-     * @param string $text
69
-     * @param string $context
70
-     * @param string $domain
71
-     * @return string
72
-     * @filter gettext_with_context
73
-     */
74
-    public function filterGettextWithContext($translation, $text, $context, $domain)
75
-    {
76
-        return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context);
77
-    }
78
-
79
-    /**
80
-     * @param string $translation
81
-     * @param string $text
82
-     * @param string $context
83
-     * @return string
84
-     * @filter site-reviews/gettext_with_context/site-reviews
85
-     */
86
-    public function filterGettextWithContextSiteReviews($translation, $text, $context)
87
-    {
88
-        return $this->translator->translate($translation, Application::ID, [
89
-            'context' => $context,
90
-            'single' => $text,
91
-        ]);
92
-    }
93
-
94
-    /**
95
-     * @param string $translation
96
-     * @param string $single
97
-     * @param string $plural
98
-     * @param int $number
99
-     * @param string $domain
100
-     * @return string
101
-     * @filter ngettext
102
-     */
103
-    public function filterNgettext($translation, $single, $plural, $number, $domain)
104
-    {
105
-        return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number);
106
-    }
107
-
108
-    /**
109
-     * @param string $translation
110
-     * @param string $single
111
-     * @param string $plural
112
-     * @param int $number
113
-     * @return string
114
-     * @filter site-reviews/ngettext/site-reviews
115
-     */
116
-    public function filterNgettextSiteReviews($translation, $single, $plural, $number)
117
-    {
118
-        return $this->translator->translate($translation, Application::ID, [
119
-            'number' => $number,
120
-            'plural' => $plural,
121
-            'single' => $single,
122
-        ]);
123
-    }
124
-
125
-    /**
126
-     * @param string $translation
127
-     * @param string $single
128
-     * @param string $plural
129
-     * @param int $number
130
-     * @param string $context
131
-     * @param string $domain
132
-     * @return string
133
-     * @filter ngettext_with_context
134
-     */
135
-    public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain)
136
-    {
137
-        return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context);
138
-    }
139
-
140
-    /**
141
-     * @param string $translation
142
-     * @param string $single
143
-     * @param string $plural
144
-     * @param int $number
145
-     * @param string $context
146
-     * @return string
147
-     * @filter site-reviews/ngettext_with_context/site-reviews
148
-     */
149
-    public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context)
150
-    {
151
-        return $this->translator->translate($translation, Application::ID, [
152
-            'context' => $context,
153
-            'number' => $number,
154
-            'plural' => $plural,
155
-            'single' => $single,
156
-        ]);
157
-    }
158
-
159
-    /**
160
-     * @param array $postStates
161
-     * @param \WP_Post $post
162
-     * @return array
163
-     * @filter display_post_states
164
-     */
165
-    public function filterPostStates($postStates, $post)
166
-    {
167
-        $postStates = Arr::consolidateArray($postStates);
168
-        if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) {
169
-            $postStates['pending'] = __('Unapproved', 'site-reviews');
170
-        }
171
-        return $postStates;
172
-    }
173
-
174
-    /**
175
-     * @param string $translation
176
-     * @param string $text
177
-     * @return string
178
-     * @filter site-reviews/gettext/default
179
-     * @filter site-reviews/gettext_with_context/default
180
-     */
181
-    public function filterPostStatusLabels($translation, $text)
182
-    {
183
-        return $this->canModifyTranslation()
184
-            ? glsr(Labels::class)->filterPostStatusLabels($translation, $text)
185
-            : $translation;
186
-    }
187
-
188
-    /**
189
-     * @param string $translation
190
-     * @param string $single
191
-     * @param string $plural
192
-     * @param int $number
193
-     * @return string
194
-     * @filter site-reviews/ngettext/default
195
-     */
196
-    public function filterPostStatusText($translation, $single, $plural, $number)
197
-    {
198
-        if ($this->canModifyTranslation()) {
199
-            $strings = [
200
-                'Published' => __('Approved', 'site-reviews'),
201
-                'Pending' => __('Unapproved', 'site-reviews'),
202
-            ];
203
-            foreach ($strings as $search => $replace) {
204
-                if (!Str::contains($single, $search)) {
205
-                    continue;
206
-                }
207
-                return $this->translator->getTranslation([
208
-                    'number' => $number,
209
-                    'plural' => str_replace($search, $replace, $plural),
210
-                    'single' => str_replace($search, $replace, $single),
211
-                ]);
212
-            }
213
-        }
214
-        return $translation;
215
-    }
216
-
217
-    /**
218
-     * @return void
219
-     * @action admin_enqueue_scripts
220
-     */
221
-    public function translatePostStatusLabels()
222
-    {
223
-        if ($this->canModifyTranslation()) {
224
-            glsr(Labels::class)->translatePostStatusLabels();
225
-        }
226
-    }
227
-
228
-    /**
229
-     * @return bool
230
-     */
231
-    protected function canModifyTranslation()
232
-    {
233
-        $screen = glsr_current_screen();
234
-        return Application::POST_TYPE == $screen->post_type 
235
-            && in_array($screen->base, ['edit', 'post']);
236
-    }
13
+	/**
14
+	 * @var Translator
15
+	 */
16
+	public $translator;
17
+
18
+	public function __construct(Translator $translator)
19
+	{
20
+		$this->translator = $translator;
21
+	}
22
+
23
+	/**
24
+	 * @param array $messages
25
+	 * @return array
26
+	 * @filter bulk_post_updated_messages
27
+	 */
28
+	public function filterBulkUpdateMessages($messages, array $counts)
29
+	{
30
+		$messages = Arr::consolidateArray($messages);
31
+		$messages[Application::POST_TYPE] = [
32
+			'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'),
33
+			'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'),
34
+			'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'),
35
+			'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'),
36
+			'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'),
37
+		];
38
+		return $messages;
39
+	}
40
+
41
+	/**
42
+	 * @param string $translation
43
+	 * @param string $text
44
+	 * @param string $domain
45
+	 * @return string
46
+	 * @filter gettext
47
+	 */
48
+	public function filterGettext($translation, $text, $domain)
49
+	{
50
+		return apply_filters('site-reviews/gettext/'.$domain, $translation, $text);
51
+	}
52
+
53
+	/**
54
+	 * @param string $translation
55
+	 * @param string $text
56
+	 * @return string
57
+	 * @filter site-reviews/gettext/site-reviews
58
+	 */
59
+	public function filterGettextSiteReviews($translation, $text)
60
+	{
61
+		return $this->translator->translate($translation, Application::ID, [
62
+			'single' => $text,
63
+		]);
64
+	}
65
+
66
+	/**
67
+	 * @param string $translation
68
+	 * @param string $text
69
+	 * @param string $context
70
+	 * @param string $domain
71
+	 * @return string
72
+	 * @filter gettext_with_context
73
+	 */
74
+	public function filterGettextWithContext($translation, $text, $context, $domain)
75
+	{
76
+		return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context);
77
+	}
78
+
79
+	/**
80
+	 * @param string $translation
81
+	 * @param string $text
82
+	 * @param string $context
83
+	 * @return string
84
+	 * @filter site-reviews/gettext_with_context/site-reviews
85
+	 */
86
+	public function filterGettextWithContextSiteReviews($translation, $text, $context)
87
+	{
88
+		return $this->translator->translate($translation, Application::ID, [
89
+			'context' => $context,
90
+			'single' => $text,
91
+		]);
92
+	}
93
+
94
+	/**
95
+	 * @param string $translation
96
+	 * @param string $single
97
+	 * @param string $plural
98
+	 * @param int $number
99
+	 * @param string $domain
100
+	 * @return string
101
+	 * @filter ngettext
102
+	 */
103
+	public function filterNgettext($translation, $single, $plural, $number, $domain)
104
+	{
105
+		return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number);
106
+	}
107
+
108
+	/**
109
+	 * @param string $translation
110
+	 * @param string $single
111
+	 * @param string $plural
112
+	 * @param int $number
113
+	 * @return string
114
+	 * @filter site-reviews/ngettext/site-reviews
115
+	 */
116
+	public function filterNgettextSiteReviews($translation, $single, $plural, $number)
117
+	{
118
+		return $this->translator->translate($translation, Application::ID, [
119
+			'number' => $number,
120
+			'plural' => $plural,
121
+			'single' => $single,
122
+		]);
123
+	}
124
+
125
+	/**
126
+	 * @param string $translation
127
+	 * @param string $single
128
+	 * @param string $plural
129
+	 * @param int $number
130
+	 * @param string $context
131
+	 * @param string $domain
132
+	 * @return string
133
+	 * @filter ngettext_with_context
134
+	 */
135
+	public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain)
136
+	{
137
+		return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context);
138
+	}
139
+
140
+	/**
141
+	 * @param string $translation
142
+	 * @param string $single
143
+	 * @param string $plural
144
+	 * @param int $number
145
+	 * @param string $context
146
+	 * @return string
147
+	 * @filter site-reviews/ngettext_with_context/site-reviews
148
+	 */
149
+	public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context)
150
+	{
151
+		return $this->translator->translate($translation, Application::ID, [
152
+			'context' => $context,
153
+			'number' => $number,
154
+			'plural' => $plural,
155
+			'single' => $single,
156
+		]);
157
+	}
158
+
159
+	/**
160
+	 * @param array $postStates
161
+	 * @param \WP_Post $post
162
+	 * @return array
163
+	 * @filter display_post_states
164
+	 */
165
+	public function filterPostStates($postStates, $post)
166
+	{
167
+		$postStates = Arr::consolidateArray($postStates);
168
+		if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) {
169
+			$postStates['pending'] = __('Unapproved', 'site-reviews');
170
+		}
171
+		return $postStates;
172
+	}
173
+
174
+	/**
175
+	 * @param string $translation
176
+	 * @param string $text
177
+	 * @return string
178
+	 * @filter site-reviews/gettext/default
179
+	 * @filter site-reviews/gettext_with_context/default
180
+	 */
181
+	public function filterPostStatusLabels($translation, $text)
182
+	{
183
+		return $this->canModifyTranslation()
184
+			? glsr(Labels::class)->filterPostStatusLabels($translation, $text)
185
+			: $translation;
186
+	}
187
+
188
+	/**
189
+	 * @param string $translation
190
+	 * @param string $single
191
+	 * @param string $plural
192
+	 * @param int $number
193
+	 * @return string
194
+	 * @filter site-reviews/ngettext/default
195
+	 */
196
+	public function filterPostStatusText($translation, $single, $plural, $number)
197
+	{
198
+		if ($this->canModifyTranslation()) {
199
+			$strings = [
200
+				'Published' => __('Approved', 'site-reviews'),
201
+				'Pending' => __('Unapproved', 'site-reviews'),
202
+			];
203
+			foreach ($strings as $search => $replace) {
204
+				if (!Str::contains($single, $search)) {
205
+					continue;
206
+				}
207
+				return $this->translator->getTranslation([
208
+					'number' => $number,
209
+					'plural' => str_replace($search, $replace, $plural),
210
+					'single' => str_replace($search, $replace, $single),
211
+				]);
212
+			}
213
+		}
214
+		return $translation;
215
+	}
216
+
217
+	/**
218
+	 * @return void
219
+	 * @action admin_enqueue_scripts
220
+	 */
221
+	public function translatePostStatusLabels()
222
+	{
223
+		if ($this->canModifyTranslation()) {
224
+			glsr(Labels::class)->translatePostStatusLabels();
225
+		}
226
+	}
227
+
228
+	/**
229
+	 * @return bool
230
+	 */
231
+	protected function canModifyTranslation()
232
+	{
233
+		$screen = glsr_current_screen();
234
+		return Application::POST_TYPE == $screen->post_type 
235
+			&& in_array($screen->base, ['edit', 'post']);
236
+	}
237 237
 }
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.