Passed
Push — feature/rebusify ( 0fe5b2...103190 )
by Paul
08:37 queued 03:55
created
plugin/Controllers/EditorController.php 1 patch
Indentation   +399 added lines, -399 removed lines patch added patch discarded remove patch
@@ -19,430 +19,430 @@
 block discarded – undo
19 19
 
20 20
 class EditorController extends Controller
21 21
 {
22
-    /**
23
-     * @return void
24
-     * @action admin_enqueue_scripts
25
-     */
26
-    public function customizePostStatusLabels()
27
-    {
28
-        glsr(Labels::class)->customizePostStatusLabels();
29
-    }
22
+	/**
23
+	 * @return void
24
+	 * @action admin_enqueue_scripts
25
+	 */
26
+	public function customizePostStatusLabels()
27
+	{
28
+		glsr(Labels::class)->customizePostStatusLabels();
29
+	}
30 30
 
31
-    /**
32
-     * @param array $settings
33
-     * @return array
34
-     * @filter wp_editor_settings
35
-     */
36
-    public function filterEditorSettings($settings)
37
-    {
38
-        return glsr(Customization::class)->filterEditorSettings(
39
-            glsr(Helper::class)->consolidateArray($settings)
40
-        );
41
-    }
31
+	/**
32
+	 * @param array $settings
33
+	 * @return array
34
+	 * @filter wp_editor_settings
35
+	 */
36
+	public function filterEditorSettings($settings)
37
+	{
38
+		return glsr(Customization::class)->filterEditorSettings(
39
+			glsr(Helper::class)->consolidateArray($settings)
40
+		);
41
+	}
42 42
 
43
-    /**
44
-     * Modify the WP_Editor html to allow autosizing without breaking the `editor-expand` script.
45
-     * @param string $html
46
-     * @return string
47
-     * @filter the_editor
48
-     */
49
-    public function filterEditorTextarea($html)
50
-    {
51
-        return glsr(Customization::class)->filterEditorTextarea($html);
52
-    }
43
+	/**
44
+	 * Modify the WP_Editor html to allow autosizing without breaking the `editor-expand` script.
45
+	 * @param string $html
46
+	 * @return string
47
+	 * @filter the_editor
48
+	 */
49
+	public function filterEditorTextarea($html)
50
+	{
51
+		return glsr(Customization::class)->filterEditorTextarea($html);
52
+	}
53 53
 
54
-    /**
55
-     * @param bool $protected
56
-     * @param string $metaKey
57
-     * @param string $metaType
58
-     * @return bool
59
-     * @filter is_protected_meta
60
-     */
61
-    public function filterIsProtectedMeta($protected, $metaKey, $metaType)
62
-    {
63
-        if ('post' == $metaType && Application::POST_TYPE == get_post_type()) {
64
-            $values = glsr(CreateReviewDefaults::class)->unguarded();
65
-            $values = glsr(Helper::class)->prefixArrayKeys($values);
66
-            if (array_key_exists($metaKey, $values)) {
67
-                $protected = false;
68
-            }
69
-        }
70
-        return $protected;
71
-    }
54
+	/**
55
+	 * @param bool $protected
56
+	 * @param string $metaKey
57
+	 * @param string $metaType
58
+	 * @return bool
59
+	 * @filter is_protected_meta
60
+	 */
61
+	public function filterIsProtectedMeta($protected, $metaKey, $metaType)
62
+	{
63
+		if ('post' == $metaType && Application::POST_TYPE == get_post_type()) {
64
+			$values = glsr(CreateReviewDefaults::class)->unguarded();
65
+			$values = glsr(Helper::class)->prefixArrayKeys($values);
66
+			if (array_key_exists($metaKey, $values)) {
67
+				$protected = false;
68
+			}
69
+		}
70
+		return $protected;
71
+	}
72 72
 
73
-    /**
74
-     * @param string $translation
75
-     * @param string $test
76
-     * @param string $domain
77
-     * @return string
78
-     * @filter gettext
79
-     */
80
-    public function filterPostStatusLabels($translation, $text, $domain)
81
-    {
82
-        return glsr(Labels::class)->filterPostStatusLabels($translation, $text, $domain);
83
-    }
73
+	/**
74
+	 * @param string $translation
75
+	 * @param string $test
76
+	 * @param string $domain
77
+	 * @return string
78
+	 * @filter gettext
79
+	 */
80
+	public function filterPostStatusLabels($translation, $text, $domain)
81
+	{
82
+		return glsr(Labels::class)->filterPostStatusLabels($translation, $text, $domain);
83
+	}
84 84
 
85
-    /**
86
-     * @param string $translation
87
-     * @param string $test
88
-     * @param string $domain
89
-     * @return string
90
-     * @filter gettext_with_context
91
-     */
92
-    public function filterPostStatusLabelsWithContext($translation, $text, $context, $domain)
93
-    {
94
-        return glsr(Labels::class)->filterPostStatusLabels($translation, $text, $domain);
95
-    }
85
+	/**
86
+	 * @param string $translation
87
+	 * @param string $test
88
+	 * @param string $domain
89
+	 * @return string
90
+	 * @filter gettext_with_context
91
+	 */
92
+	public function filterPostStatusLabelsWithContext($translation, $text, $context, $domain)
93
+	{
94
+		return glsr(Labels::class)->filterPostStatusLabels($translation, $text, $domain);
95
+	}
96 96
 
97
-    /**
98
-     * @param array $messages
99
-     * @return array
100
-     * @filter post_updated_messages
101
-     */
102
-    public function filterUpdateMessages($messages)
103
-    {
104
-        return glsr(Labels::class)->filterUpdateMessages(
105
-            glsr(Helper::class)->consolidateArray($messages)
106
-        );
107
-    }
97
+	/**
98
+	 * @param array $messages
99
+	 * @return array
100
+	 * @filter post_updated_messages
101
+	 */
102
+	public function filterUpdateMessages($messages)
103
+	{
104
+		return glsr(Labels::class)->filterUpdateMessages(
105
+			glsr(Helper::class)->consolidateArray($messages)
106
+		);
107
+	}
108 108
 
109
-    /**
110
-     * @return void
111
-     * @action add_meta_boxes_{Application::POST_TYPE}
112
-     */
113
-    public function registerMetaBoxes($post)
114
-    {
115
-        add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side');
116
-        add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side');
117
-        if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) {
118
-            return;
119
-        }
120
-        add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal');
121
-    }
109
+	/**
110
+	 * @return void
111
+	 * @action add_meta_boxes_{Application::POST_TYPE}
112
+	 */
113
+	public function registerMetaBoxes($post)
114
+	{
115
+		add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side');
116
+		add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side');
117
+		if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) {
118
+			return;
119
+		}
120
+		add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal');
121
+	}
122 122
 
123
-    /**
124
-     * @return void
125
-     * @action admin_print_scripts
126
-     */
127
-    public function removeAutosave()
128
-    {
129
-        glsr(Customization::class)->removeAutosave();
130
-    }
123
+	/**
124
+	 * @return void
125
+	 * @action admin_print_scripts
126
+	 */
127
+	public function removeAutosave()
128
+	{
129
+		glsr(Customization::class)->removeAutosave();
130
+	}
131 131
 
132
-    /**
133
-     * @return void
134
-     * @action admin_menu
135
-     */
136
-    public function removeMetaBoxes()
137
-    {
138
-        glsr(Customization::class)->removeMetaBoxes();
139
-    }
132
+	/**
133
+	 * @return void
134
+	 * @action admin_menu
135
+	 */
136
+	public function removeMetaBoxes()
137
+	{
138
+		glsr(Customization::class)->removeMetaBoxes();
139
+	}
140 140
 
141
-    /**
142
-     * @return void
143
-     */
144
-    public function removePostTypeSupport()
145
-    {
146
-        glsr(Customization::class)->removePostTypeSupport();
147
-    }
141
+	/**
142
+	 * @return void
143
+	 */
144
+	public function removePostTypeSupport()
145
+	{
146
+		glsr(Customization::class)->removePostTypeSupport();
147
+	}
148 148
 
149
-    /**
150
-     * @param WP_Post $post
151
-     * @return void
152
-     * @callback add_meta_box
153
-     */
154
-    public function renderAssignedToMetabox($post)
155
-    {
156
-        if (!$this->isReviewPostType($post)) {
157
-            return;
158
-        }
159
-        $assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to');
160
-        wp_nonce_field('assigned_to', '_nonce-assigned-to', false);
161
-        glsr()->render('partials/editor/metabox-assigned-to', [
162
-            'id' => $assignedTo,
163
-            'template' => $this->buildAssignedToTemplate($assignedTo, $post),
164
-        ]);
165
-    }
149
+	/**
150
+	 * @param WP_Post $post
151
+	 * @return void
152
+	 * @callback add_meta_box
153
+	 */
154
+	public function renderAssignedToMetabox($post)
155
+	{
156
+		if (!$this->isReviewPostType($post)) {
157
+			return;
158
+		}
159
+		$assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to');
160
+		wp_nonce_field('assigned_to', '_nonce-assigned-to', false);
161
+		glsr()->render('partials/editor/metabox-assigned-to', [
162
+			'id' => $assignedTo,
163
+			'template' => $this->buildAssignedToTemplate($assignedTo, $post),
164
+		]);
165
+	}
166 166
 
167
-    /**
168
-     * @param WP_Post $post
169
-     * @return void
170
-     * @callback add_meta_box
171
-     */
172
-    public function renderDetailsMetaBox($post)
173
-    {
174
-        if (!$this->isReviewPostType($post)) {
175
-            return;
176
-        }
177
-        $review = glsr_get_review($post);
178
-        glsr()->render('partials/editor/metabox-details', [
179
-            'button' => $this->buildDetailsMetaBoxRevertButton($review, $post),
180
-            'metabox' => $this->normalizeDetailsMetaBox($review),
181
-        ]);
182
-    }
167
+	/**
168
+	 * @param WP_Post $post
169
+	 * @return void
170
+	 * @callback add_meta_box
171
+	 */
172
+	public function renderDetailsMetaBox($post)
173
+	{
174
+		if (!$this->isReviewPostType($post)) {
175
+			return;
176
+		}
177
+		$review = glsr_get_review($post);
178
+		glsr()->render('partials/editor/metabox-details', [
179
+			'button' => $this->buildDetailsMetaBoxRevertButton($review, $post),
180
+			'metabox' => $this->normalizeDetailsMetaBox($review),
181
+		]);
182
+	}
183 183
 
184
-    /**
185
-     * @return void
186
-     * @action post_submitbox_misc_actions
187
-     */
188
-    public function renderPinnedInPublishMetaBox()
189
-    {
190
-        if (!$this->isReviewPostType(get_post())) {
191
-            return;
192
-        }
193
-        glsr(Template::class)->render('partials/editor/pinned', [
194
-            'context' => [
195
-                'no' => __('No', 'site-reviews'),
196
-                'yes' => __('Yes', 'site-reviews'),
197
-            ],
198
-            'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')),
199
-        ]);
200
-    }
184
+	/**
185
+	 * @return void
186
+	 * @action post_submitbox_misc_actions
187
+	 */
188
+	public function renderPinnedInPublishMetaBox()
189
+	{
190
+		if (!$this->isReviewPostType(get_post())) {
191
+			return;
192
+		}
193
+		glsr(Template::class)->render('partials/editor/pinned', [
194
+			'context' => [
195
+				'no' => __('No', 'site-reviews'),
196
+				'yes' => __('Yes', 'site-reviews'),
197
+			],
198
+			'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')),
199
+		]);
200
+	}
201 201
 
202
-    /**
203
-     * @param WP_Post $post
204
-     * @return void
205
-     * @callback add_meta_box
206
-     */
207
-    public function renderResponseMetaBox($post)
208
-    {
209
-        if (!$this->isReviewPostType($post)) {
210
-            return;
211
-        }
212
-        wp_nonce_field('response', '_nonce-response', false);
213
-        glsr()->render('partials/editor/metabox-response', [
214
-            'response' => glsr(Database::class)->get($post->ID, 'response'),
215
-        ]);
216
-    }
202
+	/**
203
+	 * @param WP_Post $post
204
+	 * @return void
205
+	 * @callback add_meta_box
206
+	 */
207
+	public function renderResponseMetaBox($post)
208
+	{
209
+		if (!$this->isReviewPostType($post)) {
210
+			return;
211
+		}
212
+		wp_nonce_field('response', '_nonce-response', false);
213
+		glsr()->render('partials/editor/metabox-response', [
214
+			'response' => glsr(Database::class)->get($post->ID, 'response'),
215
+		]);
216
+	}
217 217
 
218
-    /**
219
-     * @param WP_Post $post
220
-     * @return void
221
-     * @action edit_form_after_title
222
-     */
223
-    public function renderReviewEditor($post)
224
-    {
225
-        if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) {
226
-            return;
227
-        }
228
-        glsr()->render('partials/editor/review', [
229
-            'post' => $post,
230
-            'response' => glsr(Database::class)->get($post->ID, 'response'),
231
-        ]);
232
-    }
218
+	/**
219
+	 * @param WP_Post $post
220
+	 * @return void
221
+	 * @action edit_form_after_title
222
+	 */
223
+	public function renderReviewEditor($post)
224
+	{
225
+		if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) {
226
+			return;
227
+		}
228
+		glsr()->render('partials/editor/review', [
229
+			'post' => $post,
230
+			'response' => glsr(Database::class)->get($post->ID, 'response'),
231
+		]);
232
+	}
233 233
 
234
-    /**
235
-     * @return void
236
-     * @action admin_head
237
-     */
238
-    public function renderReviewFields()
239
-    {
240
-        $screen = glsr_current_screen();
241
-        if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) {
242
-            return;
243
-        }
244
-        add_action('edit_form_after_title', [$this, 'renderReviewEditor']);
245
-        add_action('edit_form_top', [$this, 'renderReviewNotice']);
246
-    }
234
+	/**
235
+	 * @return void
236
+	 * @action admin_head
237
+	 */
238
+	public function renderReviewFields()
239
+	{
240
+		$screen = glsr_current_screen();
241
+		if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) {
242
+			return;
243
+		}
244
+		add_action('edit_form_after_title', [$this, 'renderReviewEditor']);
245
+		add_action('edit_form_top', [$this, 'renderReviewNotice']);
246
+	}
247 247
 
248
-    /**
249
-     * @param WP_Post $post
250
-     * @return void
251
-     * @action edit_form_top
252
-     */
253
-    public function renderReviewNotice($post)
254
-    {
255
-        if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) {
256
-            return;
257
-        }
258
-        glsr(Notice::class)->addWarning(sprintf(
259
-            __('%s reviews are read-only.', 'site-reviews'),
260
-            glsr(Columns::class)->buildColumnReviewType($post->ID)
261
-        ));
262
-        glsr(Template::class)->render('partials/editor/notice', [
263
-            'context' => [
264
-                'notices' => glsr(Notice::class)->get(),
265
-            ],
266
-        ]);
267
-    }
248
+	/**
249
+	 * @param WP_Post $post
250
+	 * @return void
251
+	 * @action edit_form_top
252
+	 */
253
+	public function renderReviewNotice($post)
254
+	{
255
+		if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) {
256
+			return;
257
+		}
258
+		glsr(Notice::class)->addWarning(sprintf(
259
+			__('%s reviews are read-only.', 'site-reviews'),
260
+			glsr(Columns::class)->buildColumnReviewType($post->ID)
261
+		));
262
+		glsr(Template::class)->render('partials/editor/notice', [
263
+			'context' => [
264
+				'notices' => glsr(Notice::class)->get(),
265
+			],
266
+		]);
267
+	}
268 268
 
269
-    /**
270
-     * @param WP_Post $post
271
-     * @return void
272
-     * @see glsr_categories_meta_box()
273
-     * @callback register_taxonomy
274
-     */
275
-    public function renderTaxonomyMetabox($post)
276
-    {
277
-        if (!$this->isReviewPostType($post)) {
278
-            return;
279
-        }
280
-        glsr()->render('partials/editor/metabox-categories', [
281
-            'post' => $post,
282
-            'tax_name' => Application::TAXONOMY,
283
-            'taxonomy' => get_taxonomy(Application::TAXONOMY),
284
-        ]);
285
-    }
269
+	/**
270
+	 * @param WP_Post $post
271
+	 * @return void
272
+	 * @see glsr_categories_meta_box()
273
+	 * @callback register_taxonomy
274
+	 */
275
+	public function renderTaxonomyMetabox($post)
276
+	{
277
+		if (!$this->isReviewPostType($post)) {
278
+			return;
279
+		}
280
+		glsr()->render('partials/editor/metabox-categories', [
281
+			'post' => $post,
282
+			'tax_name' => Application::TAXONOMY,
283
+			'taxonomy' => get_taxonomy(Application::TAXONOMY),
284
+		]);
285
+	}
286 286
 
287
-    /**
288
-     * @return void
289
-     * @see $this->filterUpdateMessages()
290
-     * @action admin_action_revert
291
-     */
292
-    public function revertReview()
293
-    {
294
-        if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
295
-            return;
296
-        }
297
-        check_admin_referer('revert-review_'.($postId = $this->getPostId()));
298
-        glsr(ReviewManager::class)->revert($postId);
299
-        $this->redirect($postId, 52);
300
-    }
287
+	/**
288
+	 * @return void
289
+	 * @see $this->filterUpdateMessages()
290
+	 * @action admin_action_revert
291
+	 */
292
+	public function revertReview()
293
+	{
294
+		if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
295
+			return;
296
+		}
297
+		check_admin_referer('revert-review_'.($postId = $this->getPostId()));
298
+		glsr(ReviewManager::class)->revert($postId);
299
+		$this->redirect($postId, 52);
300
+	}
301 301
 
302
-    /**
303
-     * @param int $postId
304
-     * @return void
305
-     * @action save_post_.Application::POST_TYPE
306
-     */
307
-    public function saveMetaboxes($postId)
308
-    {
309
-        glsr(Metaboxes::class)->saveAssignedToMetabox($postId);
310
-        glsr(Metaboxes::class)->saveResponseMetabox($postId);
311
-        do_action('site-reviews/review/saved', glsr_get_review($postId));
312
-    }
302
+	/**
303
+	 * @param int $postId
304
+	 * @return void
305
+	 * @action save_post_.Application::POST_TYPE
306
+	 */
307
+	public function saveMetaboxes($postId)
308
+	{
309
+		glsr(Metaboxes::class)->saveAssignedToMetabox($postId);
310
+		glsr(Metaboxes::class)->saveResponseMetabox($postId);
311
+		do_action('site-reviews/review/saved', glsr_get_review($postId));
312
+	}
313 313
 
314
-    /**
315
-     * @param string $assignedTo
316
-     * @return string
317
-     */
318
-    protected function buildAssignedToTemplate($assignedTo, WP_Post $post)
319
-    {
320
-        $assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo);
321
-        if (!($assignedPost instanceof WP_Post)) {
322
-            return;
323
-        }
324
-        return glsr(Template::class)->build('partials/editor/assigned-post', [
325
-            'context' => [
326
-                'data.url' => (string) get_permalink($assignedPost),
327
-                'data.title' => get_the_title($assignedPost),
328
-            ],
329
-        ]);
330
-    }
314
+	/**
315
+	 * @param string $assignedTo
316
+	 * @return string
317
+	 */
318
+	protected function buildAssignedToTemplate($assignedTo, WP_Post $post)
319
+	{
320
+		$assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo);
321
+		if (!($assignedPost instanceof WP_Post)) {
322
+			return;
323
+		}
324
+		return glsr(Template::class)->build('partials/editor/assigned-post', [
325
+			'context' => [
326
+				'data.url' => (string) get_permalink($assignedPost),
327
+				'data.title' => get_the_title($assignedPost),
328
+			],
329
+		]);
330
+	}
331 331
 
332
-    /**
333
-     * @return string
334
-     */
335
-    protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post)
336
-    {
337
-        $isModified = !glsr(Helper::class)->compareArrays(
338
-            [$review->title, $review->content, $review->date],
339
-            [
340
-                glsr(Database::class)->get($post->ID, 'title'),
341
-                glsr(Database::class)->get($post->ID, 'content'),
342
-                glsr(Database::class)->get($post->ID, 'date'),
343
-            ]
344
-        );
345
-        if ($isModified) {
346
-            $revertUrl = wp_nonce_url(
347
-                admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID),
348
-                'revert-review_'.$post->ID
349
-            );
350
-            return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [
351
-                'class' => 'button button-large',
352
-                'href' => $revertUrl,
353
-                'id' => 'revert',
354
-            ]);
355
-        }
356
-        return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [
357
-            'class' => 'button-large',
358
-            'disabled' => true,
359
-            'id' => 'revert',
360
-        ]);
361
-    }
332
+	/**
333
+	 * @return string
334
+	 */
335
+	protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post)
336
+	{
337
+		$isModified = !glsr(Helper::class)->compareArrays(
338
+			[$review->title, $review->content, $review->date],
339
+			[
340
+				glsr(Database::class)->get($post->ID, 'title'),
341
+				glsr(Database::class)->get($post->ID, 'content'),
342
+				glsr(Database::class)->get($post->ID, 'date'),
343
+			]
344
+		);
345
+		if ($isModified) {
346
+			$revertUrl = wp_nonce_url(
347
+				admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID),
348
+				'revert-review_'.$post->ID
349
+			);
350
+			return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [
351
+				'class' => 'button button-large',
352
+				'href' => $revertUrl,
353
+				'id' => 'revert',
354
+			]);
355
+		}
356
+		return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [
357
+			'class' => 'button-large',
358
+			'disabled' => true,
359
+			'id' => 'revert',
360
+		]);
361
+	}
362 362
 
363
-    /**
364
-     * @param object $review
365
-     * @return string|void
366
-     */
367
-    protected function getReviewType($review)
368
-    {
369
-        if (count(glsr()->reviewTypes) < 2) {
370
-            return;
371
-        }
372
-        $reviewType = array_key_exists($review->review_type, glsr()->reviewTypes)
373
-            ? glsr()->reviewTypes[$review->review_type]
374
-            : __('Unknown', 'site-reviews');
375
-        if (!empty($review->url)) {
376
-            $reviewType = glsr(Builder::class)->a($reviewType, [
377
-                'href' => $review->url,
378
-                'target' => '_blank',
379
-            ]);
380
-        }
381
-        return $reviewType;
382
-    }
363
+	/**
364
+	 * @param object $review
365
+	 * @return string|void
366
+	 */
367
+	protected function getReviewType($review)
368
+	{
369
+		if (count(glsr()->reviewTypes) < 2) {
370
+			return;
371
+		}
372
+		$reviewType = array_key_exists($review->review_type, glsr()->reviewTypes)
373
+			? glsr()->reviewTypes[$review->review_type]
374
+			: __('Unknown', 'site-reviews');
375
+		if (!empty($review->url)) {
376
+			$reviewType = glsr(Builder::class)->a($reviewType, [
377
+				'href' => $review->url,
378
+				'target' => '_blank',
379
+			]);
380
+		}
381
+		return $reviewType;
382
+	}
383 383
 
384
-    /**
385
-     * @return bool
386
-     */
387
-    protected function isReviewEditable($post)
388
-    {
389
-        return $this->isReviewPostType($post)
390
-            && post_type_supports(Application::POST_TYPE, 'title')
391
-            && 'local' == glsr(Database::class)->get($post->ID, 'review_type');
392
-    }
384
+	/**
385
+	 * @return bool
386
+	 */
387
+	protected function isReviewEditable($post)
388
+	{
389
+		return $this->isReviewPostType($post)
390
+			&& post_type_supports(Application::POST_TYPE, 'title')
391
+			&& 'local' == glsr(Database::class)->get($post->ID, 'review_type');
392
+	}
393 393
 
394
-    /**
395
-     * @param mixed $post
396
-     * @return bool
397
-     */
398
-    protected function isReviewPostType($post)
399
-    {
400
-        return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type;
401
-    }
394
+	/**
395
+	 * @param mixed $post
396
+	 * @return bool
397
+	 */
398
+	protected function isReviewPostType($post)
399
+	{
400
+		return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type;
401
+	}
402 402
 
403
-    /**
404
-     * @return array
405
-     */
406
-    protected function normalizeDetailsMetaBox(Review $review)
407
-    {
408
-        $user = empty($review->user_id)
409
-            ? __('Unregistered user', 'site-reviews')
410
-            : glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [
411
-                'href' => get_author_posts_url($review->user_id),
412
-            ]);
413
-        $email = empty($review->email)
414
-            ? '&mdash;'
415
-            : glsr(Builder::class)->a($review->email, [
416
-                'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title),
417
-            ]);
418
-        $metabox = [
419
-            __('Rating', 'site-reviews') => glsr_star_rating($review->rating),
420
-            __('Type', 'site-reviews') => $this->getReviewType($review),
421
-            __('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'),
422
-            __('Name', 'site-reviews') => $review->author,
423
-            __('Email', 'site-reviews') => $email,
424
-            __('User', 'site-reviews') => $user,
425
-            __('IP Address', 'site-reviews') => $review->ip_address,
426
-            __('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar),
427
-        ];
428
-        return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review));
429
-    }
403
+	/**
404
+	 * @return array
405
+	 */
406
+	protected function normalizeDetailsMetaBox(Review $review)
407
+	{
408
+		$user = empty($review->user_id)
409
+			? __('Unregistered user', 'site-reviews')
410
+			: glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [
411
+				'href' => get_author_posts_url($review->user_id),
412
+			]);
413
+		$email = empty($review->email)
414
+			? '&mdash;'
415
+			: glsr(Builder::class)->a($review->email, [
416
+				'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title),
417
+			]);
418
+		$metabox = [
419
+			__('Rating', 'site-reviews') => glsr_star_rating($review->rating),
420
+			__('Type', 'site-reviews') => $this->getReviewType($review),
421
+			__('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'),
422
+			__('Name', 'site-reviews') => $review->author,
423
+			__('Email', 'site-reviews') => $email,
424
+			__('User', 'site-reviews') => $user,
425
+			__('IP Address', 'site-reviews') => $review->ip_address,
426
+			__('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar),
427
+		];
428
+		return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review));
429
+	}
430 430
 
431
-    /**
432
-     * @param int $postId
433
-     * @param int $messageIndex
434
-     * @return void
435
-     */
436
-    protected function redirect($postId, $messageIndex)
437
-    {
438
-        $referer = wp_get_referer();
439
-        $hasReferer = !$referer
440
-            || false !== strpos($referer, 'post.php')
441
-            || false !== strpos($referer, 'post-new.php');
442
-        $redirectUri = $hasReferer
443
-            ? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer)
444
-            : get_edit_post_link($postId);
445
-        wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri));
446
-        exit;
447
-    }
431
+	/**
432
+	 * @param int $postId
433
+	 * @param int $messageIndex
434
+	 * @return void
435
+	 */
436
+	protected function redirect($postId, $messageIndex)
437
+	{
438
+		$referer = wp_get_referer();
439
+		$hasReferer = !$referer
440
+			|| false !== strpos($referer, 'post.php')
441
+			|| false !== strpos($referer, 'post-new.php');
442
+		$redirectUri = $hasReferer
443
+			? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer)
444
+			: get_edit_post_link($postId);
445
+		wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri));
446
+		exit;
447
+	}
448 448
 }
Please login to merge, or discard this patch.
plugin/Modules/Rebusify.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -6,81 +6,81 @@
 block discarded – undo
6 6
 
7 7
 class Rebusify
8 8
 {
9
-    const API_URL = 'https://www.rebusify.com/api/rbs/';
9
+	const API_URL = 'https://www.rebusify.com/api/rbs/';
10 10
 
11
-    /**
12
-     * @return void|array
13
-     */
14
-    public function sendReview(Review $review)
15
-    {
16
-        return $this->send('index.php', [
17
-            'body' => $this->getBodyForReview($review),
18
-            'timeout' => 120,
19
-        ]);
20
-    }
11
+	/**
12
+	 * @return void|array
13
+	 */
14
+	public function sendReview(Review $review)
15
+	{
16
+		return $this->send('index.php', [
17
+			'body' => $this->getBodyForReview($review),
18
+			'timeout' => 120,
19
+		]);
20
+	}
21 21
 
22
-    /**
23
-     * @return void|array
24
-     */
25
-    public function sendReviewResponse(Review $review)
26
-    {
27
-        return $this->send('fetch_customer_reply.php', [
28
-            'body' => $this->getBodyForResponse($review),
29
-        ]);
30
-    }
22
+	/**
23
+	 * @return void|array
24
+	 */
25
+	public function sendReviewResponse(Review $review)
26
+	{
27
+		return $this->send('fetch_customer_reply.php', [
28
+			'body' => $this->getBodyForResponse($review),
29
+		]);
30
+	}
31 31
 
32
-    /**
33
-     * @return array
34
-     */
35
-    protected function getBodyForResponse(Review $review)
36
-    {
37
-        $rebusifyResponse = [
38
-            'reply' => $review->response, // what is the 300 character limit for?
39
-            'review_id' => '', // @todo
40
-            'review_transaction_id' => '', // @todo
41
-            'type' => 'M',
42
-        ];
43
-        return apply_filters('site-reviews/rebusify/response', $rebusifyResponse, $review);
44
-    }
32
+	/**
33
+	 * @return array
34
+	 */
35
+	protected function getBodyForResponse(Review $review)
36
+	{
37
+		$rebusifyResponse = [
38
+			'reply' => $review->response, // what is the 300 character limit for?
39
+			'review_id' => '', // @todo
40
+			'review_transaction_id' => '', // @todo
41
+			'type' => 'M',
42
+		];
43
+		return apply_filters('site-reviews/rebusify/response', $rebusifyResponse, $review);
44
+	}
45 45
 
46
-    /**
47
-     * @return array
48
-     */
49
-    protected function getBodyForReview(Review $review)
50
-    {
51
-        $rebusifyReview = [
52
-            'domain' => get_site_url(),
53
-            'firstname' => $review->name, // what is the 25 character limit for?
54
-            'rate' => $review->rating,
55
-            'review_transaction_id' => '', // @todo
56
-            'reviews' => $review->content, // what is the 280 character limit for?
57
-            'title' => $review->title, // what is the 35 character limit for?
58
-            'transaction' => '', // @todo
59
-        ];
60
-        return apply_filters('site-reviews/rebusify/review', $rebusifyReview, $review);
61
-    }
46
+	/**
47
+	 * @return array
48
+	 */
49
+	protected function getBodyForReview(Review $review)
50
+	{
51
+		$rebusifyReview = [
52
+			'domain' => get_site_url(),
53
+			'firstname' => $review->name, // what is the 25 character limit for?
54
+			'rate' => $review->rating,
55
+			'review_transaction_id' => '', // @todo
56
+			'reviews' => $review->content, // what is the 280 character limit for?
57
+			'title' => $review->title, // what is the 35 character limit for?
58
+			'transaction' => '', // @todo
59
+		];
60
+		return apply_filters('site-reviews/rebusify/review', $rebusifyReview, $review);
61
+	}
62 62
 
63
-    /**
64
-     * @return void|array
65
-     */
66
-    protected function send($endpoint, $args)
67
-    {
68
-        $args = wp_parse_args($args, [
69
-            'blocking' => false,
70
-            'body' => [],
71
-            'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
72
-            'redirection' => 5,
73
-            'sslverify' => false,
74
-            'timeout' => 5,
75
-        ]);
76
-        $response = wp_remote_post(trailingslashit(static::API_URL).$endpoint, $args);
77
-        if (is_wp_error($response)) {
78
-            glsr_log()->error('REBUSIFY: '.$response->get_error_message());
79
-            return;
80
-        }
81
-        if (200 === wp_remote_retrieve_response_code($response)) {
82
-            $responsedata = wp_remote_retrieve_body($response);
83
-            return json_decode($responsedata, true);
84
-        }
85
-    }
63
+	/**
64
+	 * @return void|array
65
+	 */
66
+	protected function send($endpoint, $args)
67
+	{
68
+		$args = wp_parse_args($args, [
69
+			'blocking' => false,
70
+			'body' => [],
71
+			'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
72
+			'redirection' => 5,
73
+			'sslverify' => false,
74
+			'timeout' => 5,
75
+		]);
76
+		$response = wp_remote_post(trailingslashit(static::API_URL).$endpoint, $args);
77
+		if (is_wp_error($response)) {
78
+			glsr_log()->error('REBUSIFY: '.$response->get_error_message());
79
+			return;
80
+		}
81
+		if (200 === wp_remote_retrieve_response_code($response)) {
82
+			$responsedata = wp_remote_retrieve_body($response);
83
+			return json_decode($responsedata, true);
84
+		}
85
+	}
86 86
 }
Please login to merge, or discard this patch.
plugin/Contracts/MultilingualContract.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -4,29 +4,29 @@
 block discarded – undo
4 4
 
5 5
 interface MultilingualContract
6 6
 {
7
-    /**
8
-     * @param int|string $postId
9
-     * @return \WP_Post|void|null
10
-     */
11
-    public function getPost($postId);
7
+	/**
8
+	 * @param int|string $postId
9
+	 * @return \WP_Post|void|null
10
+	 */
11
+	public function getPost($postId);
12 12
 
13
-    /**
14
-     * @return array
15
-     */
16
-    public function getPostIds(array $postIds);
13
+	/**
14
+	 * @return array
15
+	 */
16
+	public function getPostIds(array $postIds);
17 17
 
18
-    /**
19
-     * @return bool
20
-     */
21
-    public function isActive();
18
+	/**
19
+	 * @return bool
20
+	 */
21
+	public function isActive();
22 22
 
23
-    /**
24
-     * @return bool
25
-     */
26
-    public function isEnabled();
23
+	/**
24
+	 * @return bool
25
+	 */
26
+	public function isEnabled();
27 27
 
28
-    /**
29
-     * @return bool
30
-     */
31
-    public function isSupported();
28
+	/**
29
+	 * @return bool
30
+	 */
31
+	public function isSupported();
32 32
 }
Please login to merge, or discard this patch.
plugin/Shortcodes/Shortcode.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -10,223 +10,223 @@
 block discarded – undo
10 10
 
11 11
 abstract class Shortcode implements ShortcodeContract
12 12
 {
13
-    /**
14
-     * @var string
15
-     */
16
-    protected $partialName;
17
-
18
-    /**
19
-     * @var string
20
-     */
21
-    protected $shortcodeName;
22
-
23
-    /**
24
-     * @param string|array $atts
25
-     * @param string $type
26
-     * @return string
27
-     */
28
-    public function build($atts, array $args = [], $type = 'shortcode')
29
-    {
30
-        $this->partialName = $this->getShortcodePartialName();
31
-        $this->shortcodeName = $this->getShortcodeName();
32
-        $args = $this->normalizeArgs($args, $type);
33
-        $atts = $this->normalizeAtts($atts, $type);
34
-        $partial = glsr(Partial::class)->build($this->partialName, $atts);
35
-        $title = !empty($atts['title'])
36
-            ? $args['before_title'].$atts['title'].$args['after_title']
37
-            : '';
38
-        $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']);
39
-        return $args['before_widget'].$title.$partial.$debug.$args['after_widget'];
40
-    }
41
-
42
-    /**
43
-     * @param string|array $atts
44
-     * @return string
45
-     */
46
-    public function buildShortcode($atts = [])
47
-    {
48
-        return $this->build($atts);
49
-    }
50
-
51
-    /**
52
-     * @return array
53
-     */
54
-    public function getDefaults($atts)
55
-    {
56
-        return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts));
57
-    }
58
-
59
-    /**
60
-     * @return array
61
-     */
62
-    public function getHideOptions()
63
-    {
64
-        $options = $this->hideOptions();
65
-        return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName);
66
-    }
67
-
68
-    /**
69
-     * @return string
70
-     */
71
-    public function getShortcodeClassName($replace = '', $search = 'Shortcode')
72
-    {
73
-        return str_replace($search, $replace, (new ReflectionClass($this))->getShortName());
74
-    }
75
-
76
-    /**
77
-     * @return string
78
-     */
79
-    public function getShortcodeDefaultsClassName()
80
-    {
81
-        return glsr(Helper::class)->buildClassName(
82
-            $this->getShortcodeClassName('Defaults'),
83
-            'Defaults'
84
-        );
85
-    }
86
-
87
-    /**
88
-     * @return string
89
-     */
90
-    public function getShortcodeName()
91
-    {
92
-        return glsr(Helper::class)->snakeCase($this->getShortcodeClassName());
93
-    }
94
-
95
-    /**
96
-     * @return string
97
-     */
98
-    public function getShortcodePartialName()
99
-    {
100
-        return glsr(Helper::class)->dashCase($this->getShortcodeClassName());
101
-    }
102
-
103
-    /**
104
-     * @param array|string $args
105
-     * @param string $type
106
-     * @return array
107
-     */
108
-    public function normalizeArgs($args, $type = 'shortcode')
109
-    {
110
-        $args = wp_parse_args($args, [
111
-            'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">',
112
-            'after_widget' => '</div>',
113
-            'before_title' => '<h3 class="glsr-'.$type.'-title">',
114
-            'after_title' => '</h3>',
115
-        ]);
116
-        return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName);
117
-    }
118
-
119
-    /**
120
-     * @param array|string $atts
121
-     * @param string $type
122
-     * @return array
123
-     */
124
-    public function normalizeAtts($atts, $type = 'shortcode')
125
-    {
126
-        $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName);
127
-        $atts = $this->getDefaults($atts);
128
-        array_walk($atts, function (&$value, $key) {
129
-            $methodName = glsr(Helper::class)->buildMethodName($key, 'normalize');
130
-            if (!method_exists($this, $methodName)) {
131
-                return;
132
-            }
133
-            $value = $this->$methodName($value);
134
-        });
135
-        return $atts;
136
-    }
137
-
138
-    /**
139
-     * @return array
140
-     */
141
-    abstract protected function hideOptions();
142
-
143
-    /**
144
-     * @param string $postId
145
-     * @return int|string
146
-     */
147
-    protected function normalizeAssignedTo($postId)
148
-    {
149
-        if ('parent_id' == $postId) {
150
-            $postId = intval(wp_get_post_parent_id(intval(get_the_ID())));
151
-        } elseif ('post_id' == $postId) {
152
-            $postId = intval(get_the_ID());
153
-        }
154
-        return $postId;
155
-    }
156
-
157
-    /**
158
-     * @param string $postId
159
-     * @return int|string
160
-     */
161
-    protected function normalizeAssignTo($postId)
162
-    {
163
-        return $this->normalizeAssignedTo($postId);
164
-    }
165
-
166
-    /**
167
-     * @param string|array $hide
168
-     * @return array
169
-     */
170
-    protected function normalizeHide($hide)
171
-    {
172
-        if (is_string($hide)) {
173
-            $hide = explode(',', $hide);
174
-        }
175
-        $hideKeys = array_keys($this->getHideOptions());
176
-        return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) {
177
-            return in_array($value, $hideKeys);
178
-        });
179
-    }
180
-
181
-    /**
182
-     * @param string $id
183
-     * @return string
184
-     */
185
-    protected function normalizeId($id)
186
-    {
187
-        return sanitize_title($id);
188
-    }
189
-
190
-    /**
191
-     * @param string $labels
192
-     * @return array
193
-     */
194
-    protected function normalizeLabels($labels)
195
-    {
196
-        $defaults = [
197
-            __('Excellent', 'site-reviews'),
198
-            __('Very good', 'site-reviews'),
199
-            __('Average', 'site-reviews'),
200
-            __('Poor', 'site-reviews'),
201
-            __('Terrible', 'site-reviews'),
202
-        ];
203
-        $maxRating = glsr()->constant('MAX_RATING', Rating::class);
204
-        $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, '');
205
-        $labels = array_map('trim', explode(',', $labels));
206
-        foreach ($defaults as $i => $label) {
207
-            if (empty($labels[$i])) {
208
-                continue;
209
-            }
210
-            $defaults[$i] = $labels[$i];
211
-        }
212
-        return array_combine(range($maxRating, 1), $defaults);
213
-    }
214
-
215
-    /**
216
-     * @param string $schema
217
-     * @return bool
218
-     */
219
-    protected function normalizeSchema($schema)
220
-    {
221
-        return wp_validate_boolean($schema);
222
-    }
223
-
224
-    /**
225
-     * @param string $text
226
-     * @return string
227
-     */
228
-    protected function normalizeText($text)
229
-    {
230
-        return trim($text);
231
-    }
13
+	/**
14
+	 * @var string
15
+	 */
16
+	protected $partialName;
17
+
18
+	/**
19
+	 * @var string
20
+	 */
21
+	protected $shortcodeName;
22
+
23
+	/**
24
+	 * @param string|array $atts
25
+	 * @param string $type
26
+	 * @return string
27
+	 */
28
+	public function build($atts, array $args = [], $type = 'shortcode')
29
+	{
30
+		$this->partialName = $this->getShortcodePartialName();
31
+		$this->shortcodeName = $this->getShortcodeName();
32
+		$args = $this->normalizeArgs($args, $type);
33
+		$atts = $this->normalizeAtts($atts, $type);
34
+		$partial = glsr(Partial::class)->build($this->partialName, $atts);
35
+		$title = !empty($atts['title'])
36
+			? $args['before_title'].$atts['title'].$args['after_title']
37
+			: '';
38
+		$debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']);
39
+		return $args['before_widget'].$title.$partial.$debug.$args['after_widget'];
40
+	}
41
+
42
+	/**
43
+	 * @param string|array $atts
44
+	 * @return string
45
+	 */
46
+	public function buildShortcode($atts = [])
47
+	{
48
+		return $this->build($atts);
49
+	}
50
+
51
+	/**
52
+	 * @return array
53
+	 */
54
+	public function getDefaults($atts)
55
+	{
56
+		return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts));
57
+	}
58
+
59
+	/**
60
+	 * @return array
61
+	 */
62
+	public function getHideOptions()
63
+	{
64
+		$options = $this->hideOptions();
65
+		return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName);
66
+	}
67
+
68
+	/**
69
+	 * @return string
70
+	 */
71
+	public function getShortcodeClassName($replace = '', $search = 'Shortcode')
72
+	{
73
+		return str_replace($search, $replace, (new ReflectionClass($this))->getShortName());
74
+	}
75
+
76
+	/**
77
+	 * @return string
78
+	 */
79
+	public function getShortcodeDefaultsClassName()
80
+	{
81
+		return glsr(Helper::class)->buildClassName(
82
+			$this->getShortcodeClassName('Defaults'),
83
+			'Defaults'
84
+		);
85
+	}
86
+
87
+	/**
88
+	 * @return string
89
+	 */
90
+	public function getShortcodeName()
91
+	{
92
+		return glsr(Helper::class)->snakeCase($this->getShortcodeClassName());
93
+	}
94
+
95
+	/**
96
+	 * @return string
97
+	 */
98
+	public function getShortcodePartialName()
99
+	{
100
+		return glsr(Helper::class)->dashCase($this->getShortcodeClassName());
101
+	}
102
+
103
+	/**
104
+	 * @param array|string $args
105
+	 * @param string $type
106
+	 * @return array
107
+	 */
108
+	public function normalizeArgs($args, $type = 'shortcode')
109
+	{
110
+		$args = wp_parse_args($args, [
111
+			'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">',
112
+			'after_widget' => '</div>',
113
+			'before_title' => '<h3 class="glsr-'.$type.'-title">',
114
+			'after_title' => '</h3>',
115
+		]);
116
+		return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName);
117
+	}
118
+
119
+	/**
120
+	 * @param array|string $atts
121
+	 * @param string $type
122
+	 * @return array
123
+	 */
124
+	public function normalizeAtts($atts, $type = 'shortcode')
125
+	{
126
+		$atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName);
127
+		$atts = $this->getDefaults($atts);
128
+		array_walk($atts, function (&$value, $key) {
129
+			$methodName = glsr(Helper::class)->buildMethodName($key, 'normalize');
130
+			if (!method_exists($this, $methodName)) {
131
+				return;
132
+			}
133
+			$value = $this->$methodName($value);
134
+		});
135
+		return $atts;
136
+	}
137
+
138
+	/**
139
+	 * @return array
140
+	 */
141
+	abstract protected function hideOptions();
142
+
143
+	/**
144
+	 * @param string $postId
145
+	 * @return int|string
146
+	 */
147
+	protected function normalizeAssignedTo($postId)
148
+	{
149
+		if ('parent_id' == $postId) {
150
+			$postId = intval(wp_get_post_parent_id(intval(get_the_ID())));
151
+		} elseif ('post_id' == $postId) {
152
+			$postId = intval(get_the_ID());
153
+		}
154
+		return $postId;
155
+	}
156
+
157
+	/**
158
+	 * @param string $postId
159
+	 * @return int|string
160
+	 */
161
+	protected function normalizeAssignTo($postId)
162
+	{
163
+		return $this->normalizeAssignedTo($postId);
164
+	}
165
+
166
+	/**
167
+	 * @param string|array $hide
168
+	 * @return array
169
+	 */
170
+	protected function normalizeHide($hide)
171
+	{
172
+		if (is_string($hide)) {
173
+			$hide = explode(',', $hide);
174
+		}
175
+		$hideKeys = array_keys($this->getHideOptions());
176
+		return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) {
177
+			return in_array($value, $hideKeys);
178
+		});
179
+	}
180
+
181
+	/**
182
+	 * @param string $id
183
+	 * @return string
184
+	 */
185
+	protected function normalizeId($id)
186
+	{
187
+		return sanitize_title($id);
188
+	}
189
+
190
+	/**
191
+	 * @param string $labels
192
+	 * @return array
193
+	 */
194
+	protected function normalizeLabels($labels)
195
+	{
196
+		$defaults = [
197
+			__('Excellent', 'site-reviews'),
198
+			__('Very good', 'site-reviews'),
199
+			__('Average', 'site-reviews'),
200
+			__('Poor', 'site-reviews'),
201
+			__('Terrible', 'site-reviews'),
202
+		];
203
+		$maxRating = glsr()->constant('MAX_RATING', Rating::class);
204
+		$defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, '');
205
+		$labels = array_map('trim', explode(',', $labels));
206
+		foreach ($defaults as $i => $label) {
207
+			if (empty($labels[$i])) {
208
+				continue;
209
+			}
210
+			$defaults[$i] = $labels[$i];
211
+		}
212
+		return array_combine(range($maxRating, 1), $defaults);
213
+	}
214
+
215
+	/**
216
+	 * @param string $schema
217
+	 * @return bool
218
+	 */
219
+	protected function normalizeSchema($schema)
220
+	{
221
+		return wp_validate_boolean($schema);
222
+	}
223
+
224
+	/**
225
+	 * @param string $text
226
+	 * @return string
227
+	 */
228
+	protected function normalizeText($text)
229
+	{
230
+		return trim($text);
231
+	}
232 232
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/SiteReviews.php 1 patch
Indentation   +348 added lines, -348 removed lines patch added patch discarded remove patch
@@ -19,377 +19,377 @@
 block discarded – undo
19 19
 
20 20
 class SiteReviews
21 21
 {
22
-    /**
23
-     * @var array
24
-     */
25
-    public $args;
22
+	/**
23
+	 * @var array
24
+	 */
25
+	public $args;
26 26
 
27
-    /**
28
-     * @var Review
29
-     */
30
-    public $current;
27
+	/**
28
+	 * @var Review
29
+	 */
30
+	public $current;
31 31
 
32
-    /**
33
-     * @var array
34
-     */
35
-    public $options;
32
+	/**
33
+	 * @var array
34
+	 */
35
+	public $options;
36 36
 
37
-    /**
38
-     * @var Reviews
39
-     */
40
-    protected $reviews;
37
+	/**
38
+	 * @var Reviews
39
+	 */
40
+	protected $reviews;
41 41
 
42
-    /**
43
-     * @param Reviews|null $reviews
44
-     * @return ReviewsHtml
45
-     */
46
-    public function build(array $args = [], $reviews = null)
47
-    {
48
-        $this->args = glsr(SiteReviewsDefaults::class)->merge($args);
49
-        $this->options = glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all());
50
-        $this->reviews = $reviews instanceof Reviews
51
-            ? $reviews
52
-            : glsr(ReviewManager::class)->get($args);
53
-        $this->generateSchema();
54
-        return $this->buildReviews();
55
-    }
42
+	/**
43
+	 * @param Reviews|null $reviews
44
+	 * @return ReviewsHtml
45
+	 */
46
+	public function build(array $args = [], $reviews = null)
47
+	{
48
+		$this->args = glsr(SiteReviewsDefaults::class)->merge($args);
49
+		$this->options = glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all());
50
+		$this->reviews = $reviews instanceof Reviews
51
+			? $reviews
52
+			: glsr(ReviewManager::class)->get($args);
53
+		$this->generateSchema();
54
+		return $this->buildReviews();
55
+	}
56 56
 
57
-    /**
58
-     * @return ReviewHtml
59
-     */
60
-    public function buildReview(Review $review)
61
-    {
62
-        $review = apply_filters('site-reviews/review/build/before', $review);
63
-        $this->current = $review;
64
-        $renderedFields = [];
65
-        foreach ($review as $key => $value) {
66
-            $method = glsr(Helper::class)->buildMethodName($key, 'buildOption');
67
-            $field = method_exists($this, $method)
68
-                ? $this->$method($key, $value)
69
-                : false;
70
-            $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $this, $review);
71
-            if (false === $field) {
72
-                continue;
73
-            }
74
-            $renderedFields[$key] = $field;
75
-        }
76
-        $this->wrap($renderedFields, $review);
77
-        $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
78
-        $this->current = null;
79
-        return new ReviewHtml($review, (array) $renderedFields);
80
-    }
57
+	/**
58
+	 * @return ReviewHtml
59
+	 */
60
+	public function buildReview(Review $review)
61
+	{
62
+		$review = apply_filters('site-reviews/review/build/before', $review);
63
+		$this->current = $review;
64
+		$renderedFields = [];
65
+		foreach ($review as $key => $value) {
66
+			$method = glsr(Helper::class)->buildMethodName($key, 'buildOption');
67
+			$field = method_exists($this, $method)
68
+				? $this->$method($key, $value)
69
+				: false;
70
+			$field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $this, $review);
71
+			if (false === $field) {
72
+				continue;
73
+			}
74
+			$renderedFields[$key] = $field;
75
+		}
76
+		$this->wrap($renderedFields, $review);
77
+		$renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
78
+		$this->current = null;
79
+		return new ReviewHtml($review, (array) $renderedFields);
80
+	}
81 81
 
82
-    /**
83
-     * @return ReviewsHtml
84
-     */
85
-    public function buildReviews()
86
-    {
87
-        $renderedReviews = [];
88
-        foreach ($this->reviews as $index => $review) {
89
-            $renderedReviews[] = $this->buildReview($review);
90
-        }
91
-        return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
92
-    }
82
+	/**
83
+	 * @return ReviewsHtml
84
+	 */
85
+	public function buildReviews()
86
+	{
87
+		$renderedReviews = [];
88
+		foreach ($this->reviews as $index => $review) {
89
+			$renderedReviews[] = $this->buildReview($review);
90
+		}
91
+		return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
92
+	}
93 93
 
94
-    /**
95
-     * @return void
96
-     */
97
-    public function generateSchema()
98
-    {
99
-        if (!wp_validate_boolean($this->args['schema'])) {
100
-            return;
101
-        }
102
-        glsr(Schema::class)->store(
103
-            glsr(Schema::class)->build($this->args)
104
-        );
105
-    }
94
+	/**
95
+	 * @return void
96
+	 */
97
+	public function generateSchema()
98
+	{
99
+		if (!wp_validate_boolean($this->args['schema'])) {
100
+			return;
101
+		}
102
+		glsr(Schema::class)->store(
103
+			glsr(Schema::class)->build($this->args)
104
+		);
105
+	}
106 106
 
107
-    /**
108
-     * @param string $key
109
-     * @param string $path
110
-     * @return bool
111
-     */
112
-    public function isHidden($key, $path = '')
113
-    {
114
-        $isOptionEnabled = !empty($path)
115
-            ? $this->isOptionEnabled($path)
116
-            : true;
117
-        return in_array($key, $this->args['hide']) || !$isOptionEnabled;
118
-    }
107
+	/**
108
+	 * @param string $key
109
+	 * @param string $path
110
+	 * @return bool
111
+	 */
112
+	public function isHidden($key, $path = '')
113
+	{
114
+		$isOptionEnabled = !empty($path)
115
+			? $this->isOptionEnabled($path)
116
+			: true;
117
+		return in_array($key, $this->args['hide']) || !$isOptionEnabled;
118
+	}
119 119
 
120
-    /**
121
-     * @param string $key
122
-     * @param string $value
123
-     * @return void|string
124
-     */
125
-    protected function buildOptionAssignedTo($key, $value)
126
-    {
127
-        if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
128
-            return;
129
-        }
130
-        $post = glsr(Polylang::class)->getPost($value);
131
-        if (!($post instanceof WP_Post)) {
132
-            return;
133
-        }
134
-        $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
135
-            'href' => get_the_permalink($post->ID),
136
-        ]);
137
-        $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
138
-        return '<span>'.$assignedTo.'</span>';
139
-    }
120
+	/**
121
+	 * @param string $key
122
+	 * @param string $value
123
+	 * @return void|string
124
+	 */
125
+	protected function buildOptionAssignedTo($key, $value)
126
+	{
127
+		if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
128
+			return;
129
+		}
130
+		$post = glsr(Polylang::class)->getPost($value);
131
+		if (!($post instanceof WP_Post)) {
132
+			return;
133
+		}
134
+		$permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
135
+			'href' => get_the_permalink($post->ID),
136
+		]);
137
+		$assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
138
+		return '<span>'.$assignedTo.'</span>';
139
+	}
140 140
 
141
-    /**
142
-     * @param string $key
143
-     * @param string $value
144
-     * @return void|string
145
-     */
146
-    protected function buildOptionAuthor($key, $value)
147
-    {
148
-        if (!$this->isHidden($key)) {
149
-            return '<span>'.$value.'</span>';
150
-        }
151
-    }
141
+	/**
142
+	 * @param string $key
143
+	 * @param string $value
144
+	 * @return void|string
145
+	 */
146
+	protected function buildOptionAuthor($key, $value)
147
+	{
148
+		if (!$this->isHidden($key)) {
149
+			return '<span>'.$value.'</span>';
150
+		}
151
+	}
152 152
 
153
-    /**
154
-     * @param string $key
155
-     * @param string $value
156
-     * @return void|string
157
-     */
158
-    protected function buildOptionAvatar($key, $value)
159
-    {
160
-        if ($this->isHidden($key, 'settings.reviews.avatars')) {
161
-            return;
162
-        }
163
-        $size = $this->getOption('settings.reviews.avatars_size', 40);
164
-        return glsr(Builder::class)->img([
165
-            'height' => $size,
166
-            'src' => $this->generateAvatar($value),
167
-            'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
168
-            'width' => $size,
169
-        ]);
170
-    }
153
+	/**
154
+	 * @param string $key
155
+	 * @param string $value
156
+	 * @return void|string
157
+	 */
158
+	protected function buildOptionAvatar($key, $value)
159
+	{
160
+		if ($this->isHidden($key, 'settings.reviews.avatars')) {
161
+			return;
162
+		}
163
+		$size = $this->getOption('settings.reviews.avatars_size', 40);
164
+		return glsr(Builder::class)->img([
165
+			'height' => $size,
166
+			'src' => $this->generateAvatar($value),
167
+			'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
168
+			'width' => $size,
169
+		]);
170
+	}
171 171
 
172
-    /**
173
-     * @param string $key
174
-     * @param string $value
175
-     * @return void|string
176
-     */
177
-    protected function buildOptionContent($key, $value)
178
-    {
179
-        $text = $this->normalizeText($value);
180
-        if (!$this->isHiddenOrEmpty($key, $text)) {
181
-            return '<p>'.$text.'</p>';
182
-        }
183
-    }
172
+	/**
173
+	 * @param string $key
174
+	 * @param string $value
175
+	 * @return void|string
176
+	 */
177
+	protected function buildOptionContent($key, $value)
178
+	{
179
+		$text = $this->normalizeText($value);
180
+		if (!$this->isHiddenOrEmpty($key, $text)) {
181
+			return '<p>'.$text.'</p>';
182
+		}
183
+	}
184 184
 
185
-    /**
186
-     * @param string $key
187
-     * @param string $value
188
-     * @return void|string
189
-     */
190
-    protected function buildOptionDate($key, $value)
191
-    {
192
-        if ($this->isHidden($key)) {
193
-            return;
194
-        }
195
-        $dateFormat = $this->getOption('settings.reviews.date.format', 'default');
196
-        if ('relative' == $dateFormat) {
197
-            $date = glsr(Date::class)->relative($value);
198
-        } else {
199
-            $format = 'custom' == $dateFormat
200
-                ? $this->getOption('settings.reviews.date.custom', 'M j, Y')
201
-                : glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
202
-            $date = date_i18n($format, strtotime($value));
203
-        }
204
-        return '<span>'.$date.'</span>';
205
-    }
185
+	/**
186
+	 * @param string $key
187
+	 * @param string $value
188
+	 * @return void|string
189
+	 */
190
+	protected function buildOptionDate($key, $value)
191
+	{
192
+		if ($this->isHidden($key)) {
193
+			return;
194
+		}
195
+		$dateFormat = $this->getOption('settings.reviews.date.format', 'default');
196
+		if ('relative' == $dateFormat) {
197
+			$date = glsr(Date::class)->relative($value);
198
+		} else {
199
+			$format = 'custom' == $dateFormat
200
+				? $this->getOption('settings.reviews.date.custom', 'M j, Y')
201
+				: glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
202
+			$date = date_i18n($format, strtotime($value));
203
+		}
204
+		return '<span>'.$date.'</span>';
205
+	}
206 206
 
207
-    /**
208
-     * @param string $key
209
-     * @param string $value
210
-     * @return void|string
211
-     */
212
-    protected function buildOptionRating($key, $value)
213
-    {
214
-        if (!$this->isHiddenOrEmpty($key, $value)) {
215
-            return glsr_star_rating($value);
216
-        }
217
-    }
207
+	/**
208
+	 * @param string $key
209
+	 * @param string $value
210
+	 * @return void|string
211
+	 */
212
+	protected function buildOptionRating($key, $value)
213
+	{
214
+		if (!$this->isHiddenOrEmpty($key, $value)) {
215
+			return glsr_star_rating($value);
216
+		}
217
+	}
218 218
 
219
-    /**
220
-     * @param string $key
221
-     * @param string $value
222
-     * @return void|string
223
-     */
224
-    protected function buildOptionResponse($key, $value)
225
-    {
226
-        if ($this->isHiddenOrEmpty($key, $value)) {
227
-            return;
228
-        }
229
-        $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
230
-        $text = $this->normalizeText($value);
231
-        $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
232
-        $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
233
-        $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
234
-        return $response.$background;
235
-    }
219
+	/**
220
+	 * @param string $key
221
+	 * @param string $value
222
+	 * @return void|string
223
+	 */
224
+	protected function buildOptionResponse($key, $value)
225
+	{
226
+		if ($this->isHiddenOrEmpty($key, $value)) {
227
+			return;
228
+		}
229
+		$title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
230
+		$text = $this->normalizeText($value);
231
+		$text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
232
+		$response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
233
+		$background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
234
+		return $response.$background;
235
+	}
236 236
 
237
-    /**
238
-     * @param string $key
239
-     * @param string $value
240
-     * @return void|string
241
-     */
242
-    protected function buildOptionTitle($key, $value)
243
-    {
244
-        if ($this->isHidden($key)) {
245
-            return;
246
-        }
247
-        if (empty($value)) {
248
-            $value = __('No Title', 'site-reviews');
249
-        }
250
-        return '<h3>'.$value.'</h3>';
251
-    }
237
+	/**
238
+	 * @param string $key
239
+	 * @param string $value
240
+	 * @return void|string
241
+	 */
242
+	protected function buildOptionTitle($key, $value)
243
+	{
244
+		if ($this->isHidden($key)) {
245
+			return;
246
+		}
247
+		if (empty($value)) {
248
+			$value = __('No Title', 'site-reviews');
249
+		}
250
+		return '<h3>'.$value.'</h3>';
251
+	}
252 252
 
253
-    /**
254
-     * @param string $avatarUrl
255
-     * @return string
256
-     */
257
-    protected function generateAvatar($avatarUrl)
258
-    {
259
-        if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
260
-            return $avatarUrl;
261
-        }
262
-        $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
263
-        if (empty($authorIdOrEmail)) {
264
-            $authorIdOrEmail = $this->current->email;
265
-        }
266
-        if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
267
-            return $newAvatar;
268
-        }
269
-        return $avatarUrl;
270
-    }
253
+	/**
254
+	 * @param string $avatarUrl
255
+	 * @return string
256
+	 */
257
+	protected function generateAvatar($avatarUrl)
258
+	{
259
+		if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
260
+			return $avatarUrl;
261
+		}
262
+		$authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
263
+		if (empty($authorIdOrEmail)) {
264
+			$authorIdOrEmail = $this->current->email;
265
+		}
266
+		if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
267
+			return $newAvatar;
268
+		}
269
+		return $avatarUrl;
270
+	}
271 271
 
272
-    /**
273
-     * @param string $text
274
-     * @return string
275
-     */
276
-    protected function getExcerpt($text)
277
-    {
278
-        $limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
279
-        $split = extension_loaded('intl')
280
-            ? $this->getExcerptIntlSplit($text, $limit)
281
-            : $this->getExcerptSplit($text, $limit);
282
-        $hiddenText = substr($text, $split);
283
-        if (!empty($hiddenText)) {
284
-            $showMore = glsr(Builder::class)->span($hiddenText, [
285
-                'class' => 'glsr-hidden glsr-hidden-text',
286
-                'data-show-less' => __('Show less', 'site-reviews'),
287
-                'data-show-more' => __('Show more', 'site-reviews'),
288
-            ]);
289
-            $text = ltrim(substr($text, 0, $split)).$showMore;
290
-        }
291
-        return $text;
292
-    }
272
+	/**
273
+	 * @param string $text
274
+	 * @return string
275
+	 */
276
+	protected function getExcerpt($text)
277
+	{
278
+		$limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
279
+		$split = extension_loaded('intl')
280
+			? $this->getExcerptIntlSplit($text, $limit)
281
+			: $this->getExcerptSplit($text, $limit);
282
+		$hiddenText = substr($text, $split);
283
+		if (!empty($hiddenText)) {
284
+			$showMore = glsr(Builder::class)->span($hiddenText, [
285
+				'class' => 'glsr-hidden glsr-hidden-text',
286
+				'data-show-less' => __('Show less', 'site-reviews'),
287
+				'data-show-more' => __('Show more', 'site-reviews'),
288
+			]);
289
+			$text = ltrim(substr($text, 0, $split)).$showMore;
290
+		}
291
+		return $text;
292
+	}
293 293
 
294
-    /**
295
-     * @param string $text
296
-     * @param int $limit
297
-     * @return int
298
-     */
299
-    protected function getExcerptIntlSplit($text, $limit)
300
-    {
301
-        $words = IntlRuleBasedBreakIterator::createWordInstance('');
302
-        $words->setText($text);
303
-        $count = 0;
304
-        foreach ($words as $offset) {
305
-            if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
306
-                continue;
307
-            }
308
-            ++$count;
309
-            if ($count != $limit) {
310
-                continue;
311
-            }
312
-            return $offset;
313
-        }
314
-        return strlen($text);
315
-    }
294
+	/**
295
+	 * @param string $text
296
+	 * @param int $limit
297
+	 * @return int
298
+	 */
299
+	protected function getExcerptIntlSplit($text, $limit)
300
+	{
301
+		$words = IntlRuleBasedBreakIterator::createWordInstance('');
302
+		$words->setText($text);
303
+		$count = 0;
304
+		foreach ($words as $offset) {
305
+			if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
306
+				continue;
307
+			}
308
+			++$count;
309
+			if ($count != $limit) {
310
+				continue;
311
+			}
312
+			return $offset;
313
+		}
314
+		return strlen($text);
315
+	}
316 316
 
317
-    /**
318
-     * @param string $text
319
-     * @param int $limit
320
-     * @return int
321
-     */
322
-    protected function getExcerptSplit($text, $limit)
323
-    {
324
-        if (str_word_count($text, 0) > $limit) {
325
-            $words = array_keys(str_word_count($text, 2));
326
-            return $words[$limit];
327
-        }
328
-        return strlen($text);
329
-    }
317
+	/**
318
+	 * @param string $text
319
+	 * @param int $limit
320
+	 * @return int
321
+	 */
322
+	protected function getExcerptSplit($text, $limit)
323
+	{
324
+		if (str_word_count($text, 0) > $limit) {
325
+			$words = array_keys(str_word_count($text, 2));
326
+			return $words[$limit];
327
+		}
328
+		return strlen($text);
329
+	}
330 330
 
331
-    /**
332
-     * @param string $path
333
-     * @param mixed $fallback
334
-     * @return mixed
335
-     */
336
-    protected function getOption($path, $fallback = '')
337
-    {
338
-        if (array_key_exists($path, $this->options)) {
339
-            return $this->options[$path];
340
-        }
341
-        return $fallback;
342
-    }
331
+	/**
332
+	 * @param string $path
333
+	 * @param mixed $fallback
334
+	 * @return mixed
335
+	 */
336
+	protected function getOption($path, $fallback = '')
337
+	{
338
+		if (array_key_exists($path, $this->options)) {
339
+			return $this->options[$path];
340
+		}
341
+		return $fallback;
342
+	}
343 343
 
344
-    /**
345
-     * @param string $key
346
-     * @param string $value
347
-     * @return bool
348
-     */
349
-    protected function isHiddenOrEmpty($key, $value)
350
-    {
351
-        return $this->isHidden($key) || empty($value);
352
-    }
344
+	/**
345
+	 * @param string $key
346
+	 * @param string $value
347
+	 * @return bool
348
+	 */
349
+	protected function isHiddenOrEmpty($key, $value)
350
+	{
351
+		return $this->isHidden($key) || empty($value);
352
+	}
353 353
 
354
-    /**
355
-     * @param string $path
356
-     * @return bool
357
-     */
358
-    protected function isOptionEnabled($path)
359
-    {
360
-        return 'yes' == $this->getOption($path);
361
-    }
354
+	/**
355
+	 * @param string $path
356
+	 * @return bool
357
+	 */
358
+	protected function isOptionEnabled($path)
359
+	{
360
+		return 'yes' == $this->getOption($path);
361
+	}
362 362
 
363
-    /**
364
-     * @param string $text
365
-     * @return string
366
-     */
367
-    protected function normalizeText($text)
368
-    {
369
-        $text = wp_kses($text, wp_kses_allowed_html());
370
-        $text = convert_smilies(strip_shortcodes($text));
371
-        $text = str_replace(']]>', ']]&gt;', $text);
372
-        $text = preg_replace('/(\R){2,}/', '$1', $text);
373
-        if ($this->isOptionEnabled('settings.reviews.excerpts')) {
374
-            $text = $this->getExcerpt($text);
375
-        }
376
-        return wptexturize(nl2br($text));
377
-    }
363
+	/**
364
+	 * @param string $text
365
+	 * @return string
366
+	 */
367
+	protected function normalizeText($text)
368
+	{
369
+		$text = wp_kses($text, wp_kses_allowed_html());
370
+		$text = convert_smilies(strip_shortcodes($text));
371
+		$text = str_replace(']]>', ']]&gt;', $text);
372
+		$text = preg_replace('/(\R){2,}/', '$1', $text);
373
+		if ($this->isOptionEnabled('settings.reviews.excerpts')) {
374
+			$text = $this->getExcerpt($text);
375
+		}
376
+		return wptexturize(nl2br($text));
377
+	}
378 378
 
379
-    /**
380
-     * @return void
381
-     */
382
-    protected function wrap(array &$renderedFields, Review $review)
383
-    {
384
-        $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
385
-        array_walk($renderedFields, function (&$value, $key) use ($review) {
386
-            $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
387
-            if (empty($value)) {
388
-                return;
389
-            }
390
-            $value = glsr(Builder::class)->div($value, [
391
-                'class' => 'glsr-review-'.$key,
392
-            ]);
393
-        });
394
-    }
379
+	/**
380
+	 * @return void
381
+	 */
382
+	protected function wrap(array &$renderedFields, Review $review)
383
+	{
384
+		$renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
385
+		array_walk($renderedFields, function (&$value, $key) use ($review) {
386
+			$value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
387
+			if (empty($value)) {
388
+				return;
389
+			}
390
+			$value = glsr(Builder::class)->div($value, [
391
+				'class' => 'glsr-review-'.$key,
392
+			]);
393
+		});
394
+	}
395 395
 }
Please login to merge, or discard this patch.
plugin/Modules/System.php 1 patch
Indentation   +343 added lines, -343 removed lines patch added patch discarded remove patch
@@ -10,368 +10,368 @@
 block discarded – undo
10 10
 
11 11
 class System
12 12
 {
13
-    const PAD = 40;
13
+	const PAD = 40;
14 14
 
15
-    /**
16
-     * @return string
17
-     */
18
-    public function __toString()
19
-    {
20
-        return $this->get();
21
-    }
15
+	/**
16
+	 * @return string
17
+	 */
18
+	public function __toString()
19
+	{
20
+		return $this->get();
21
+	}
22 22
 
23
-    /**
24
-     * @return string
25
-     */
26
-    public function get()
27
-    {
28
-        $details = [
29
-            'plugin' => 'Plugin Details',
30
-            'addon' => 'Addon Details',
31
-            'browser' => 'Browser Details',
32
-            'server' => 'Server Details',
33
-            'php' => 'PHP Configuration',
34
-            'wordpress' => 'WordPress Configuration',
35
-            'mu-plugin' => 'Must-Use Plugins',
36
-            'multisite-plugin' => 'Network Active Plugins',
37
-            'active-plugin' => 'Active Plugins',
38
-            'inactive-plugin' => 'Inactive Plugins',
39
-            'setting' => 'Plugin Settings',
40
-            'reviews' => 'Review Counts',
41
-        ];
42
-        $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) {
43
-            $methodName = glsr(Helper::class)->buildMethodName('get-'.$key.'-details');
44
-            if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
45
-                return $carry.$this->implode(
46
-                    strtoupper($details[$key]),
47
-                    apply_filters('site-reviews/system/'.$key, $systemDetails)
48
-                );
49
-            }
50
-            return $carry;
51
-        });
52
-        return trim($systemInfo);
53
-    }
23
+	/**
24
+	 * @return string
25
+	 */
26
+	public function get()
27
+	{
28
+		$details = [
29
+			'plugin' => 'Plugin Details',
30
+			'addon' => 'Addon Details',
31
+			'browser' => 'Browser Details',
32
+			'server' => 'Server Details',
33
+			'php' => 'PHP Configuration',
34
+			'wordpress' => 'WordPress Configuration',
35
+			'mu-plugin' => 'Must-Use Plugins',
36
+			'multisite-plugin' => 'Network Active Plugins',
37
+			'active-plugin' => 'Active Plugins',
38
+			'inactive-plugin' => 'Inactive Plugins',
39
+			'setting' => 'Plugin Settings',
40
+			'reviews' => 'Review Counts',
41
+		];
42
+		$systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) {
43
+			$methodName = glsr(Helper::class)->buildMethodName('get-'.$key.'-details');
44
+			if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
45
+				return $carry.$this->implode(
46
+					strtoupper($details[$key]),
47
+					apply_filters('site-reviews/system/'.$key, $systemDetails)
48
+				);
49
+			}
50
+			return $carry;
51
+		});
52
+		return trim($systemInfo);
53
+	}
54 54
 
55
-    /**
56
-     * @return array
57
-     */
58
-    public function getActivePluginDetails()
59
-    {
60
-        $plugins = get_plugins();
61
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
62
-        $inactive = array_diff_key($plugins, array_flip($activePlugins));
63
-        return $this->normalizePluginList(array_diff_key($plugins, $inactive));
64
-    }
55
+	/**
56
+	 * @return array
57
+	 */
58
+	public function getActivePluginDetails()
59
+	{
60
+		$plugins = get_plugins();
61
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
62
+		$inactive = array_diff_key($plugins, array_flip($activePlugins));
63
+		return $this->normalizePluginList(array_diff_key($plugins, $inactive));
64
+	}
65 65
 
66
-    /**
67
-     * @return array
68
-     */
69
-    public function getAddonDetails()
70
-    {
71
-        $details = apply_filters('site-reviews/addon/system-info', []);
72
-        ksort($details);
73
-        return $details;
74
-    }
66
+	/**
67
+	 * @return array
68
+	 */
69
+	public function getAddonDetails()
70
+	{
71
+		$details = apply_filters('site-reviews/addon/system-info', []);
72
+		ksort($details);
73
+		return $details;
74
+	}
75 75
 
76
-    /**
77
-     * @return array
78
-     */
79
-    public function getBrowserDetails()
80
-    {
81
-        $browser = new Browser();
82
-        $name = esc_attr($browser->getName());
83
-        $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
84
-        $version = esc_attr($browser->getVersion());
85
-        return [
86
-            'Browser Name' => sprintf('%s %s', $name, $version),
87
-            'Browser UA' => $userAgent,
88
-        ];
89
-    }
76
+	/**
77
+	 * @return array
78
+	 */
79
+	public function getBrowserDetails()
80
+	{
81
+		$browser = new Browser();
82
+		$name = esc_attr($browser->getName());
83
+		$userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
84
+		$version = esc_attr($browser->getVersion());
85
+		return [
86
+			'Browser Name' => sprintf('%s %s', $name, $version),
87
+			'Browser UA' => $userAgent,
88
+		];
89
+	}
90 90
 
91
-    /**
92
-     * @return array
93
-     */
94
-    public function getInactivePluginDetails()
95
-    {
96
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
97
-        $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
98
-        $multisitePlugins = $this->getMultisitePluginDetails();
99
-        return empty($multisitePlugins)
100
-            ? $inactivePlugins
101
-            : array_diff($inactivePlugins, $multisitePlugins);
102
-    }
91
+	/**
92
+	 * @return array
93
+	 */
94
+	public function getInactivePluginDetails()
95
+	{
96
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
97
+		$inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
98
+		$multisitePlugins = $this->getMultisitePluginDetails();
99
+		return empty($multisitePlugins)
100
+			? $inactivePlugins
101
+			: array_diff($inactivePlugins, $multisitePlugins);
102
+	}
103 103
 
104
-    /**
105
-     * @return array
106
-     */
107
-    public function getMuPluginDetails()
108
-    {
109
-        if (empty($plugins = get_mu_plugins())) {
110
-            return [];
111
-        }
112
-        return $this->normalizePluginList($plugins);
113
-    }
104
+	/**
105
+	 * @return array
106
+	 */
107
+	public function getMuPluginDetails()
108
+	{
109
+		if (empty($plugins = get_mu_plugins())) {
110
+			return [];
111
+		}
112
+		return $this->normalizePluginList($plugins);
113
+	}
114 114
 
115
-    /**
116
-     * @return array
117
-     */
118
-    public function getMultisitePluginDetails()
119
-    {
120
-        $activePlugins = (array) get_site_option('active_sitewide_plugins', []);
121
-        if (!is_multisite() || empty($activePlugins)) {
122
-            return [];
123
-        }
124
-        return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins));
125
-    }
115
+	/**
116
+	 * @return array
117
+	 */
118
+	public function getMultisitePluginDetails()
119
+	{
120
+		$activePlugins = (array) get_site_option('active_sitewide_plugins', []);
121
+		if (!is_multisite() || empty($activePlugins)) {
122
+			return [];
123
+		}
124
+		return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins));
125
+	}
126 126
 
127
-    /**
128
-     * @return array
129
-     */
130
-    public function getPhpDetails()
131
-    {
132
-        $displayErrors = ini_get('display_errors')
133
-            ? 'On ('.ini_get('display_errors').')'
134
-            : 'N/A';
135
-        $intlSupport = extension_loaded('intl')
136
-            ? phpversion('intl')
137
-            : 'false';
138
-        return [
139
-            'cURL' => var_export(function_exists('curl_init'), true),
140
-            'Default Charset' => ini_get('default_charset'),
141
-            'Display Errors' => $displayErrors,
142
-            'fsockopen' => var_export(function_exists('fsockopen'), true),
143
-            'Intl' => $intlSupport,
144
-            'IPv6' => var_export(defined('AF_INET6'), true),
145
-            'Max Execution Time' => ini_get('max_execution_time'),
146
-            'Max Input Nesting Level' => ini_get('max_input_nesting_level'),
147
-            'Max Input Vars' => ini_get('max_input_vars'),
148
-            'Memory Limit' => ini_get('memory_limit'),
149
-            'Post Max Size' => ini_get('post_max_size'),
150
-            'Sendmail Path' => ini_get('sendmail_path'),
151
-            'Session Cookie Path' => esc_html(ini_get('session.cookie_path')),
152
-            'Session Name' => esc_html(ini_get('session.name')),
153
-            'Session Save Path' => esc_html(ini_get('session.save_path')),
154
-            'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true),
155
-            'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true),
156
-            'Upload Max Filesize' => ini_get('upload_max_filesize'),
157
-        ];
158
-    }
127
+	/**
128
+	 * @return array
129
+	 */
130
+	public function getPhpDetails()
131
+	{
132
+		$displayErrors = ini_get('display_errors')
133
+			? 'On ('.ini_get('display_errors').')'
134
+			: 'N/A';
135
+		$intlSupport = extension_loaded('intl')
136
+			? phpversion('intl')
137
+			: 'false';
138
+		return [
139
+			'cURL' => var_export(function_exists('curl_init'), true),
140
+			'Default Charset' => ini_get('default_charset'),
141
+			'Display Errors' => $displayErrors,
142
+			'fsockopen' => var_export(function_exists('fsockopen'), true),
143
+			'Intl' => $intlSupport,
144
+			'IPv6' => var_export(defined('AF_INET6'), true),
145
+			'Max Execution Time' => ini_get('max_execution_time'),
146
+			'Max Input Nesting Level' => ini_get('max_input_nesting_level'),
147
+			'Max Input Vars' => ini_get('max_input_vars'),
148
+			'Memory Limit' => ini_get('memory_limit'),
149
+			'Post Max Size' => ini_get('post_max_size'),
150
+			'Sendmail Path' => ini_get('sendmail_path'),
151
+			'Session Cookie Path' => esc_html(ini_get('session.cookie_path')),
152
+			'Session Name' => esc_html(ini_get('session.name')),
153
+			'Session Save Path' => esc_html(ini_get('session.save_path')),
154
+			'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true),
155
+			'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true),
156
+			'Upload Max Filesize' => ini_get('upload_max_filesize'),
157
+		];
158
+	}
159 159
 
160
-    /**
161
-     * @return array
162
-     */
163
-    public function getReviewsDetails()
164
-    {
165
-        $counts = glsr(CountsManager::class)->getCounts();
166
-        $counts = glsr(Helper::class)->flattenArray($counts);
167
-        array_walk($counts, function (&$ratings) use ($counts) {
168
-            if (!is_array($ratings)) {
169
-                glsr_log()
170
-                    ->error('$ratings is not an array, possibly due to incorrectly imported reviews.')
171
-                    ->debug($ratings)
172
-                    ->debug($counts);
173
-                return;
174
-            }
175
-            $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')';
176
-        });
177
-        ksort($counts);
178
-        return $counts;
179
-    }
160
+	/**
161
+	 * @return array
162
+	 */
163
+	public function getReviewsDetails()
164
+	{
165
+		$counts = glsr(CountsManager::class)->getCounts();
166
+		$counts = glsr(Helper::class)->flattenArray($counts);
167
+		array_walk($counts, function (&$ratings) use ($counts) {
168
+			if (!is_array($ratings)) {
169
+				glsr_log()
170
+					->error('$ratings is not an array, possibly due to incorrectly imported reviews.')
171
+					->debug($ratings)
172
+					->debug($counts);
173
+				return;
174
+			}
175
+			$ratings = array_sum($ratings).' ('.implode(', ', $ratings).')';
176
+		});
177
+		ksort($counts);
178
+		return $counts;
179
+	}
180 180
 
181
-    /**
182
-     * @return array
183
-     */
184
-    public function getServerDetails()
185
-    {
186
-        global $wpdb;
187
-        return [
188
-            'Host Name' => $this->getHostName(),
189
-            'MySQL Version' => $wpdb->db_version(),
190
-            'PHP Version' => PHP_VERSION,
191
-            'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
192
-        ];
193
-    }
181
+	/**
182
+	 * @return array
183
+	 */
184
+	public function getServerDetails()
185
+	{
186
+		global $wpdb;
187
+		return [
188
+			'Host Name' => $this->getHostName(),
189
+			'MySQL Version' => $wpdb->db_version(),
190
+			'PHP Version' => PHP_VERSION,
191
+			'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
192
+		];
193
+	}
194 194
 
195
-    /**
196
-     * @return array
197
-     */
198
-    public function getSettingDetails()
199
-    {
200
-        $helper = glsr(Helper::class);
201
-        $settings = glsr(OptionManager::class)->get('settings', []);
202
-        $settings = $helper->flattenArray($settings, true);
203
-        $settings = $this->purgeSensitiveData($settings);
204
-        ksort($settings);
205
-        $details = [];
206
-        foreach ($settings as $key => $value) {
207
-            if ($helper->startsWith('strings', $key) && $helper->endsWith('id', $key)) {
208
-                continue;
209
-            }
210
-            $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8');
211
-            $details[$key] = $value;
212
-        }
213
-        return $details;
214
-    }
195
+	/**
196
+	 * @return array
197
+	 */
198
+	public function getSettingDetails()
199
+	{
200
+		$helper = glsr(Helper::class);
201
+		$settings = glsr(OptionManager::class)->get('settings', []);
202
+		$settings = $helper->flattenArray($settings, true);
203
+		$settings = $this->purgeSensitiveData($settings);
204
+		ksort($settings);
205
+		$details = [];
206
+		foreach ($settings as $key => $value) {
207
+			if ($helper->startsWith('strings', $key) && $helper->endsWith('id', $key)) {
208
+				continue;
209
+			}
210
+			$value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8');
211
+			$details[$key] = $value;
212
+		}
213
+		return $details;
214
+	}
215 215
 
216
-    /**
217
-     * @return array
218
-     */
219
-    public function getPluginDetails()
220
-    {
221
-        return [
222
-            'Console level' => glsr(Console::class)->humanLevel(),
223
-            'Console size' => glsr(Console::class)->humanSize('0'),
224
-            'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')),
225
-            'Version (current)' => glsr()->version,
226
-            'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'),
227
-        ];
228
-    }
216
+	/**
217
+	 * @return array
218
+	 */
219
+	public function getPluginDetails()
220
+	{
221
+		return [
222
+			'Console level' => glsr(Console::class)->humanLevel(),
223
+			'Console size' => glsr(Console::class)->humanSize('0'),
224
+			'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')),
225
+			'Version (current)' => glsr()->version,
226
+			'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'),
227
+		];
228
+	}
229 229
 
230
-    /**
231
-     * @return array
232
-     */
233
-    public function getWordpressDetails()
234
-    {
235
-        global $wpdb;
236
-        $theme = wp_get_theme();
237
-        return [
238
-            'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version),
239
-            'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1),
240
-            'Home URL' => home_url(),
241
-            'Language' => get_locale(),
242
-            'Memory Limit' => WP_MEMORY_LIMIT,
243
-            'Multisite' => var_export(is_multisite(), true),
244
-            'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'),
245
-            'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'),
246
-            'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'),
247
-            'Post Stati' => implode(', ', get_post_stati()),
248
-            'Remote Post' => glsr(Cache::class)->getRemotePostTest(),
249
-            'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'),
250
-            'Site URL' => site_url(),
251
-            'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('date.timezone').' (PHP)'),
252
-            'Version' => get_bloginfo('version'),
253
-            'WP Debug' => var_export(defined('WP_DEBUG'), true),
254
-            'WP Max Upload Size' => size_format(wp_max_upload_size()),
255
-            'WP Memory Limit' => WP_MEMORY_LIMIT,
256
-        ];
257
-    }
230
+	/**
231
+	 * @return array
232
+	 */
233
+	public function getWordpressDetails()
234
+	{
235
+		global $wpdb;
236
+		$theme = wp_get_theme();
237
+		return [
238
+			'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version),
239
+			'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1),
240
+			'Home URL' => home_url(),
241
+			'Language' => get_locale(),
242
+			'Memory Limit' => WP_MEMORY_LIMIT,
243
+			'Multisite' => var_export(is_multisite(), true),
244
+			'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'),
245
+			'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'),
246
+			'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'),
247
+			'Post Stati' => implode(', ', get_post_stati()),
248
+			'Remote Post' => glsr(Cache::class)->getRemotePostTest(),
249
+			'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'),
250
+			'Site URL' => site_url(),
251
+			'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('date.timezone').' (PHP)'),
252
+			'Version' => get_bloginfo('version'),
253
+			'WP Debug' => var_export(defined('WP_DEBUG'), true),
254
+			'WP Max Upload Size' => size_format(wp_max_upload_size()),
255
+			'WP Memory Limit' => WP_MEMORY_LIMIT,
256
+		];
257
+	}
258 258
 
259
-    /**
260
-     * @return string
261
-     */
262
-    protected function detectWebhostProvider()
263
-    {
264
-        $checks = [
265
-            '.accountservergroup.com' => 'Site5',
266
-            '.gridserver.com' => 'MediaTemple Grid',
267
-            '.inmotionhosting.com' => 'InMotion Hosting',
268
-            '.ovh.net' => 'OVH',
269
-            '.pair.com' => 'pair Networks',
270
-            '.stabletransit.com' => 'Rackspace Cloud',
271
-            '.stratoserver.net' => 'STRATO',
272
-            '.sysfix.eu' => 'SysFix.eu Power Hosting',
273
-            'bluehost.com' => 'Bluehost',
274
-            'DH_USER' => 'DreamHost',
275
-            'Flywheel' => 'Flywheel',
276
-            'ipagemysql.com' => 'iPage',
277
-            'ipowermysql.com' => 'IPower',
278
-            'localhost:/tmp/mysql5.sock' => 'ICDSoft',
279
-            'mysqlv5' => 'NetworkSolutions',
280
-            'PAGELYBIN' => 'Pagely',
281
-            'secureserver.net' => 'GoDaddy',
282
-            'WPE_APIKEY' => 'WP Engine',
283
-        ];
284
-        foreach ($checks as $key => $value) {
285
-            if (!$this->isWebhostCheckValid($key)) {
286
-                continue;
287
-            }
288
-            return $value;
289
-        }
290
-        return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')]));
291
-    }
259
+	/**
260
+	 * @return string
261
+	 */
262
+	protected function detectWebhostProvider()
263
+	{
264
+		$checks = [
265
+			'.accountservergroup.com' => 'Site5',
266
+			'.gridserver.com' => 'MediaTemple Grid',
267
+			'.inmotionhosting.com' => 'InMotion Hosting',
268
+			'.ovh.net' => 'OVH',
269
+			'.pair.com' => 'pair Networks',
270
+			'.stabletransit.com' => 'Rackspace Cloud',
271
+			'.stratoserver.net' => 'STRATO',
272
+			'.sysfix.eu' => 'SysFix.eu Power Hosting',
273
+			'bluehost.com' => 'Bluehost',
274
+			'DH_USER' => 'DreamHost',
275
+			'Flywheel' => 'Flywheel',
276
+			'ipagemysql.com' => 'iPage',
277
+			'ipowermysql.com' => 'IPower',
278
+			'localhost:/tmp/mysql5.sock' => 'ICDSoft',
279
+			'mysqlv5' => 'NetworkSolutions',
280
+			'PAGELYBIN' => 'Pagely',
281
+			'secureserver.net' => 'GoDaddy',
282
+			'WPE_APIKEY' => 'WP Engine',
283
+		];
284
+		foreach ($checks as $key => $value) {
285
+			if (!$this->isWebhostCheckValid($key)) {
286
+				continue;
287
+			}
288
+			return $value;
289
+		}
290
+		return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')]));
291
+	}
292 292
 
293
-    /**
294
-     * @return string
295
-     */
296
-    protected function getHostName()
297
-    {
298
-        return sprintf('%s (%s)',
299
-            $this->detectWebhostProvider(),
300
-            glsr(Helper::class)->getIpAddress()
301
-        );
302
-    }
293
+	/**
294
+	 * @return string
295
+	 */
296
+	protected function getHostName()
297
+	{
298
+		return sprintf('%s (%s)',
299
+			$this->detectWebhostProvider(),
300
+			glsr(Helper::class)->getIpAddress()
301
+		);
302
+	}
303 303
 
304
-    /**
305
-     * @return array
306
-     */
307
-    protected function getWordpressPlugins()
308
-    {
309
-        $plugins = get_plugins();
310
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
311
-        $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
312
-        $active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
313
-        return $active + $inactive;
314
-    }
304
+	/**
305
+	 * @return array
306
+	 */
307
+	protected function getWordpressPlugins()
308
+	{
309
+		$plugins = get_plugins();
310
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
311
+		$inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
312
+		$active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
313
+		return $active + $inactive;
314
+	}
315 315
 
316
-    /**
317
-     * @param string $title
318
-     * @return string
319
-     */
320
-    protected function implode($title, array $details)
321
-    {
322
-        $strings = ['['.$title.']'];
323
-        $padding = max(array_map('strlen', array_keys($details)));
324
-        $padding = max([$padding, static::PAD]);
325
-        foreach ($details as $key => $value) {
326
-            $strings[] = is_string($key)
327
-                ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value)
328
-                : ' - '.$value;
329
-        }
330
-        return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
331
-    }
316
+	/**
317
+	 * @param string $title
318
+	 * @return string
319
+	 */
320
+	protected function implode($title, array $details)
321
+	{
322
+		$strings = ['['.$title.']'];
323
+		$padding = max(array_map('strlen', array_keys($details)));
324
+		$padding = max([$padding, static::PAD]);
325
+		foreach ($details as $key => $value) {
326
+			$strings[] = is_string($key)
327
+				? sprintf('%s : %s', str_pad($key, $padding, '.'), $value)
328
+				: ' - '.$value;
329
+		}
330
+		return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
331
+	}
332 332
 
333
-    /**
334
-     * @param string $key
335
-     * @return bool
336
-     */
337
-    protected function isWebhostCheckValid($key)
338
-    {
339
-        return defined($key)
340
-            || filter_input(INPUT_SERVER, $key)
341
-            || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key)
342
-            || false !== strpos(DB_HOST, $key)
343
-            || false !== strpos(php_uname(), $key);
344
-    }
333
+	/**
334
+	 * @param string $key
335
+	 * @return bool
336
+	 */
337
+	protected function isWebhostCheckValid($key)
338
+	{
339
+		return defined($key)
340
+			|| filter_input(INPUT_SERVER, $key)
341
+			|| false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key)
342
+			|| false !== strpos(DB_HOST, $key)
343
+			|| false !== strpos(php_uname(), $key);
344
+	}
345 345
 
346
-    /**
347
-     * @return array
348
-     */
349
-    protected function normalizePluginList(array $plugins)
350
-    {
351
-        $plugins = array_map(function ($plugin) {
352
-            return sprintf('%s v%s', glsr_get($plugin, 'Name'), glsr_get($plugin, 'Version'));
353
-        }, $plugins);
354
-        natcasesort($plugins);
355
-        return array_flip($plugins);
356
-    }
346
+	/**
347
+	 * @return array
348
+	 */
349
+	protected function normalizePluginList(array $plugins)
350
+	{
351
+		$plugins = array_map(function ($plugin) {
352
+			return sprintf('%s v%s', glsr_get($plugin, 'Name'), glsr_get($plugin, 'Version'));
353
+		}, $plugins);
354
+		natcasesort($plugins);
355
+		return array_flip($plugins);
356
+	}
357 357
 
358
-    /**
359
-     * @return array
360
-     */
361
-    protected function purgeSensitiveData(array $settings)
362
-    {
363
-        $keys = [
364
-            'licenses.', 'submissions.recaptcha.key', 'submissions.recaptcha.secret',
365
-        ];
366
-        array_walk($settings, function (&$value, $setting) use ($keys) {
367
-            foreach ($keys as $key) {
368
-                if (!glsr(Helper::class)->startsWith($key, $setting) || empty($value)) {
369
-                    continue;
370
-                }
371
-                $value = str_repeat('•', 13);
372
-                return;
373
-            }
374
-        });
375
-        return $settings;
376
-    }
358
+	/**
359
+	 * @return array
360
+	 */
361
+	protected function purgeSensitiveData(array $settings)
362
+	{
363
+		$keys = [
364
+			'licenses.', 'submissions.recaptcha.key', 'submissions.recaptcha.secret',
365
+		];
366
+		array_walk($settings, function (&$value, $setting) use ($keys) {
367
+			foreach ($keys as $key) {
368
+				if (!glsr(Helper::class)->startsWith($key, $setting) || empty($value)) {
369
+					continue;
370
+				}
371
+				$value = str_repeat('•', 13);
372
+				return;
373
+			}
374
+		});
375
+		return $settings;
376
+	}
377 377
 }
Please login to merge, or discard this patch.
plugin/Modules/Schema.php 1 patch
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -12,291 +12,291 @@
 block discarded – undo
12 12
 
13 13
 class Schema
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    protected $args;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	protected $args;
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    protected $ratingCounts;
20
+	/**
21
+	 * @var array
22
+	 */
23
+	protected $ratingCounts;
24 24
 
25
-    /**
26
-     * @return array
27
-     */
28
-    public function build(array $args = [])
29
-    {
30
-        $this->args = $args;
31
-        $schema = $this->buildSummary($args);
32
-        $reviews = [];
33
-        foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
34
-            // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
35
-            // @see https://developers.google.com/search/docs/data-types/review
36
-            if ('local' != $review->review_type) {
37
-                continue;
38
-            }
39
-            $reviews[] = $this->buildReview($review);
40
-        }
41
-        if (!empty($reviews)) {
42
-            array_walk($reviews, function (&$review) {
43
-                unset($review['@context']);
44
-                unset($review['itemReviewed']);
45
-            });
46
-            $schema['review'] = $reviews;
47
-        }
48
-        return $schema;
49
-    }
25
+	/**
26
+	 * @return array
27
+	 */
28
+	public function build(array $args = [])
29
+	{
30
+		$this->args = $args;
31
+		$schema = $this->buildSummary($args);
32
+		$reviews = [];
33
+		foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
34
+			// Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
35
+			// @see https://developers.google.com/search/docs/data-types/review
36
+			if ('local' != $review->review_type) {
37
+				continue;
38
+			}
39
+			$reviews[] = $this->buildReview($review);
40
+		}
41
+		if (!empty($reviews)) {
42
+			array_walk($reviews, function (&$review) {
43
+				unset($review['@context']);
44
+				unset($review['itemReviewed']);
45
+			});
46
+			$schema['review'] = $reviews;
47
+		}
48
+		return $schema;
49
+	}
50 50
 
51
-    /**
52
-     * @param array|null $args
53
-     * @return array
54
-     */
55
-    public function buildSummary($args = null)
56
-    {
57
-        if (is_array($args)) {
58
-            $this->args = $args;
59
-        }
60
-        $buildSummary = glsr(Helper::class)->buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
61
-        $count = array_sum($this->getRatingCounts());
62
-        $schema = method_exists($this, $buildSummary)
63
-            ? $this->$buildSummary()
64
-            : $this->buildSummaryForCustom();
65
-        if (!empty($count)) {
66
-            $schema->aggregateRating(
67
-                $this->getSchemaType('AggregateRating')
68
-                    ->ratingValue($this->getRatingValue())
69
-                    ->reviewCount($count)
70
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
71
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
72
-            );
73
-        }
74
-        $schema = $schema->toArray();
75
-        return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
76
-    }
51
+	/**
52
+	 * @param array|null $args
53
+	 * @return array
54
+	 */
55
+	public function buildSummary($args = null)
56
+	{
57
+		if (is_array($args)) {
58
+			$this->args = $args;
59
+		}
60
+		$buildSummary = glsr(Helper::class)->buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
61
+		$count = array_sum($this->getRatingCounts());
62
+		$schema = method_exists($this, $buildSummary)
63
+			? $this->$buildSummary()
64
+			: $this->buildSummaryForCustom();
65
+		if (!empty($count)) {
66
+			$schema->aggregateRating(
67
+				$this->getSchemaType('AggregateRating')
68
+					->ratingValue($this->getRatingValue())
69
+					->reviewCount($count)
70
+					->bestRating(glsr()->constant('MAX_RATING', Rating::class))
71
+					->worstRating(glsr()->constant('MIN_RATING', Rating::class))
72
+			);
73
+		}
74
+		$schema = $schema->toArray();
75
+		return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
76
+	}
77 77
 
78
-    /**
79
-     * @return void
80
-     */
81
-    public function render()
82
-    {
83
-        if (empty(glsr()->schemas)) {
84
-            return;
85
-        }
86
-        printf('<script type="application/ld+json">%s</script>', json_encode(
87
-            apply_filters('site-reviews/schema/all', glsr()->schemas),
88
-            JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
89
-        ));
90
-    }
78
+	/**
79
+	 * @return void
80
+	 */
81
+	public function render()
82
+	{
83
+		if (empty(glsr()->schemas)) {
84
+			return;
85
+		}
86
+		printf('<script type="application/ld+json">%s</script>', json_encode(
87
+			apply_filters('site-reviews/schema/all', glsr()->schemas),
88
+			JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
89
+		));
90
+	}
91 91
 
92
-    /**
93
-     * @return void
94
-     */
95
-    public function store(array $schema)
96
-    {
97
-        $schemas = glsr()->schemas;
98
-        $schemas[] = $schema;
99
-        glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
100
-    }
92
+	/**
93
+	 * @return void
94
+	 */
95
+	public function store(array $schema)
96
+	{
97
+		$schemas = glsr()->schemas;
98
+		$schemas[] = $schema;
99
+		glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
100
+	}
101 101
 
102
-    /**
103
-     * @param Review $review
104
-     * @return array
105
-     */
106
-    protected function buildReview($review)
107
-    {
108
-        $schema = $this->getSchemaType('Review')
109
-            ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
110
-                $schema->name($review->title);
111
-            })
112
-            ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
113
-                $schema->reviewBody($review->content);
114
-            })
115
-            ->datePublished((new DateTime($review->date)))
116
-            ->author($this->getSchemaType('Person')->name($review->author))
117
-            ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
118
-        if (!empty($review->rating)) {
119
-            $schema->reviewRating(
120
-                $this->getSchemaType('Rating')
121
-                    ->ratingValue($review->rating)
122
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
123
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
124
-            );
125
-        }
126
-        return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
127
-    }
102
+	/**
103
+	 * @param Review $review
104
+	 * @return array
105
+	 */
106
+	protected function buildReview($review)
107
+	{
108
+		$schema = $this->getSchemaType('Review')
109
+			->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
110
+				$schema->name($review->title);
111
+			})
112
+			->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
113
+				$schema->reviewBody($review->content);
114
+			})
115
+			->datePublished((new DateTime($review->date)))
116
+			->author($this->getSchemaType('Person')->name($review->author))
117
+			->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
118
+		if (!empty($review->rating)) {
119
+			$schema->reviewRating(
120
+				$this->getSchemaType('Rating')
121
+					->ratingValue($review->rating)
122
+					->bestRating(glsr()->constant('MAX_RATING', Rating::class))
123
+					->worstRating(glsr()->constant('MIN_RATING', Rating::class))
124
+			);
125
+		}
126
+		return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
127
+	}
128 128
 
129
-    /**
130
-     * @param mixed $schema
131
-     * @return mixed
132
-     */
133
-    protected function buildSchemaValues($schema, array $values = [])
134
-    {
135
-        foreach ($values as $value) {
136
-            $option = $this->getSchemaOptionValue($value);
137
-            if (empty($option)) {
138
-                continue;
139
-            }
140
-            $schema->$value($option);
141
-        }
142
-        return $schema;
143
-    }
129
+	/**
130
+	 * @param mixed $schema
131
+	 * @return mixed
132
+	 */
133
+	protected function buildSchemaValues($schema, array $values = [])
134
+	{
135
+		foreach ($values as $value) {
136
+			$option = $this->getSchemaOptionValue($value);
137
+			if (empty($option)) {
138
+				continue;
139
+			}
140
+			$schema->$value($option);
141
+		}
142
+		return $schema;
143
+	}
144 144
 
145
-    /**
146
-     * @return mixed
147
-     */
148
-    protected function buildSummaryForCustom()
149
-    {
150
-        return $this->buildSchemaValues($this->getSchemaType(), [
151
-            'description', 'image', 'name', 'url',
152
-        ]);
153
-    }
145
+	/**
146
+	 * @return mixed
147
+	 */
148
+	protected function buildSummaryForCustom()
149
+	{
150
+		return $this->buildSchemaValues($this->getSchemaType(), [
151
+			'description', 'image', 'name', 'url',
152
+		]);
153
+	}
154 154
 
155
-    /**
156
-     * @return mixed
157
-     */
158
-    protected function buildSummaryForLocalBusiness()
159
-    {
160
-        return $this->buildSchemaValues($this->buildSummaryForCustom(), [
161
-            'address', 'priceRange', 'telephone',
162
-        ]);
163
-    }
155
+	/**
156
+	 * @return mixed
157
+	 */
158
+	protected function buildSummaryForLocalBusiness()
159
+	{
160
+		return $this->buildSchemaValues($this->buildSummaryForCustom(), [
161
+			'address', 'priceRange', 'telephone',
162
+		]);
163
+	}
164 164
 
165
-    /**
166
-     * @return mixed
167
-     */
168
-    protected function buildSummaryForProduct()
169
-    {
170
-        $offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
171
-        $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
172
-            'highPrice', 'lowPrice', 'price', 'priceCurrency',
173
-        ]);
174
-        return $this->buildSummaryForCustom()
175
-            ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
176
-                $schema->offers($offers);
177
-            })
178
-            ->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
179
-    }
165
+	/**
166
+	 * @return mixed
167
+	 */
168
+	protected function buildSummaryForProduct()
169
+	{
170
+		$offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
171
+		$offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
172
+			'highPrice', 'lowPrice', 'price', 'priceCurrency',
173
+		]);
174
+		return $this->buildSummaryForCustom()
175
+			->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
176
+				$schema->offers($offers);
177
+			})
178
+			->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
179
+	}
180 180
 
181
-    /**
182
-     * @return array
183
-     */
184
-    protected function getRatingCounts()
185
-    {
186
-        if (!isset($this->ratingCounts)) {
187
-            $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
188
-        }
189
-        return $this->ratingCounts;
190
-    }
181
+	/**
182
+	 * @return array
183
+	 */
184
+	protected function getRatingCounts()
185
+	{
186
+		if (!isset($this->ratingCounts)) {
187
+			$this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
188
+		}
189
+		return $this->ratingCounts;
190
+	}
191 191
 
192
-    /**
193
-     * @return int|float
194
-     */
195
-    protected function getRatingValue()
196
-    {
197
-        return glsr(Rating::class)->getAverage($this->getRatingCounts());
198
-    }
192
+	/**
193
+	 * @return int|float
194
+	 */
195
+	protected function getRatingValue()
196
+	{
197
+		return glsr(Rating::class)->getAverage($this->getRatingCounts());
198
+	}
199 199
 
200
-    /**
201
-     * @param string $option
202
-     * @param string $fallback
203
-     * @return string
204
-     */
205
-    protected function getSchemaOption($option, $fallback)
206
-    {
207
-        $option = strtolower($option);
208
-        if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
209
-            return $schemaOption;
210
-        }
211
-        $setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
212
-        if (is_array($setting)) {
213
-            return $this->getSchemaOptionDefault($setting, $fallback);
214
-        }
215
-        return !empty($setting)
216
-            ? $setting
217
-            : $fallback;
218
-    }
200
+	/**
201
+	 * @param string $option
202
+	 * @param string $fallback
203
+	 * @return string
204
+	 */
205
+	protected function getSchemaOption($option, $fallback)
206
+	{
207
+		$option = strtolower($option);
208
+		if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
209
+			return $schemaOption;
210
+		}
211
+		$setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
212
+		if (is_array($setting)) {
213
+			return $this->getSchemaOptionDefault($setting, $fallback);
214
+		}
215
+		return !empty($setting)
216
+			? $setting
217
+			: $fallback;
218
+	}
219 219
 
220
-    /**
221
-     * @param string $fallback
222
-     * @return string
223
-     */
224
-    protected function getSchemaOptionDefault(array $setting, $fallback)
225
-    {
226
-        $setting = wp_parse_args($setting, [
227
-            'custom' => '',
228
-            'default' => $fallback,
229
-        ]);
230
-        return 'custom' != $setting['default']
231
-            ? $setting['default']
232
-            : $setting['custom'];
233
-    }
220
+	/**
221
+	 * @param string $fallback
222
+	 * @return string
223
+	 */
224
+	protected function getSchemaOptionDefault(array $setting, $fallback)
225
+	{
226
+		$setting = wp_parse_args($setting, [
227
+			'custom' => '',
228
+			'default' => $fallback,
229
+		]);
230
+		return 'custom' != $setting['default']
231
+			? $setting['default']
232
+			: $setting['custom'];
233
+	}
234 234
 
235
-    /**
236
-     * @param string $option
237
-     * @param string $fallback
238
-     * @return void|string
239
-     */
240
-    protected function getSchemaOptionValue($option, $fallback = 'post')
241
-    {
242
-        $value = $this->getSchemaOption($option, $fallback);
243
-        if ($value != $fallback) {
244
-            return $value;
245
-        }
246
-        if (!is_single() && !is_page()) {
247
-            return;
248
-        }
249
-        $method = glsr(Helper::class)->buildMethodName($option, 'getThing');
250
-        if (method_exists($this, $method)) {
251
-            return $this->$method();
252
-        }
253
-    }
235
+	/**
236
+	 * @param string $option
237
+	 * @param string $fallback
238
+	 * @return void|string
239
+	 */
240
+	protected function getSchemaOptionValue($option, $fallback = 'post')
241
+	{
242
+		$value = $this->getSchemaOption($option, $fallback);
243
+		if ($value != $fallback) {
244
+			return $value;
245
+		}
246
+		if (!is_single() && !is_page()) {
247
+			return;
248
+		}
249
+		$method = glsr(Helper::class)->buildMethodName($option, 'getThing');
250
+		if (method_exists($this, $method)) {
251
+			return $this->$method();
252
+		}
253
+	}
254 254
 
255
-    /**
256
-     * @param string|null $type
257
-     * @return mixed
258
-     */
259
-    protected function getSchemaType($type = null)
260
-    {
261
-        if (!is_string($type)) {
262
-            $type = $this->getSchemaOption('type', 'LocalBusiness');
263
-        }
264
-        $className = glsr(Helper::class)->buildClassName($type, 'Modules\Schema');
265
-        return class_exists($className)
266
-            ? new $className()
267
-            : new UnknownType($type);
268
-    }
255
+	/**
256
+	 * @param string|null $type
257
+	 * @return mixed
258
+	 */
259
+	protected function getSchemaType($type = null)
260
+	{
261
+		if (!is_string($type)) {
262
+			$type = $this->getSchemaOption('type', 'LocalBusiness');
263
+		}
264
+		$className = glsr(Helper::class)->buildClassName($type, 'Modules\Schema');
265
+		return class_exists($className)
266
+			? new $className()
267
+			: new UnknownType($type);
268
+	}
269 269
 
270
-    /**
271
-     * @return string
272
-     */
273
-    protected function getThingDescription()
274
-    {
275
-        $description = strip_shortcodes(wp_strip_all_tags(get_the_excerpt()));
276
-        return wp_trim_words($description, apply_filters('excerpt_length', 55));
277
-    }
270
+	/**
271
+	 * @return string
272
+	 */
273
+	protected function getThingDescription()
274
+	{
275
+		$description = strip_shortcodes(wp_strip_all_tags(get_the_excerpt()));
276
+		return wp_trim_words($description, apply_filters('excerpt_length', 55));
277
+	}
278 278
 
279
-    /**
280
-     * @return string
281
-     */
282
-    protected function getThingImage()
283
-    {
284
-        return (string) get_the_post_thumbnail_url(null, 'large');
285
-    }
279
+	/**
280
+	 * @return string
281
+	 */
282
+	protected function getThingImage()
283
+	{
284
+		return (string) get_the_post_thumbnail_url(null, 'large');
285
+	}
286 286
 
287
-    /**
288
-     * @return string
289
-     */
290
-    protected function getThingName()
291
-    {
292
-        return get_the_title();
293
-    }
287
+	/**
288
+	 * @return string
289
+	 */
290
+	protected function getThingName()
291
+	{
292
+		return get_the_title();
293
+	}
294 294
 
295
-    /**
296
-     * @return string
297
-     */
298
-    protected function getThingUrl()
299
-    {
300
-        return (string) get_the_permalink();
301
-    }
295
+	/**
296
+	 * @return string
297
+	 */
298
+	protected function getThingUrl()
299
+	{
300
+		return (string) get_the_permalink();
301
+	}
302 302
 }
Please login to merge, or discard this patch.
plugin/Database.php 1 patch
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -11,160 +11,160 @@
 block discarded – undo
11 11
 
12 12
 class Database
13 13
 {
14
-    /**
15
-     * @param int $postId
16
-     * @param string $key
17
-     * @param bool $single
18
-     * @return mixed
19
-     */
20
-    public function get($postId, $key, $single = true)
21
-    {
22
-        $key = glsr(Helper::class)->prefix('_', $key);
23
-        return get_post_meta(intval($postId), $key, $single);
24
-    }
14
+	/**
15
+	 * @param int $postId
16
+	 * @param string $key
17
+	 * @param bool $single
18
+	 * @return mixed
19
+	 */
20
+	public function get($postId, $key, $single = true)
21
+	{
22
+		$key = glsr(Helper::class)->prefix('_', $key);
23
+		return get_post_meta(intval($postId), $key, $single);
24
+	}
25 25
 
26
-    /**
27
-     * @param int $postId
28
-     * @param string $assignedTo
29
-     * @return void|WP_Post
30
-     */
31
-    public function getAssignedToPost($postId, $assignedTo = '')
32
-    {
33
-        if (empty($assignedTo)) {
34
-            $assignedTo = $this->get($postId, 'assigned_to');
35
-        }
36
-        if (empty($assignedTo)) {
37
-            return;
38
-        }
39
-        $assignedPost = get_post($assignedTo);
40
-        if ($assignedPost instanceof WP_Post && $assignedPost->ID != $postId) {
41
-            return $assignedPost;
42
-        }
43
-    }
26
+	/**
27
+	 * @param int $postId
28
+	 * @param string $assignedTo
29
+	 * @return void|WP_Post
30
+	 */
31
+	public function getAssignedToPost($postId, $assignedTo = '')
32
+	{
33
+		if (empty($assignedTo)) {
34
+			$assignedTo = $this->get($postId, 'assigned_to');
35
+		}
36
+		if (empty($assignedTo)) {
37
+			return;
38
+		}
39
+		$assignedPost = get_post($assignedTo);
40
+		if ($assignedPost instanceof WP_Post && $assignedPost->ID != $postId) {
41
+			return $assignedPost;
42
+		}
43
+	}
44 44
 
45
-    /**
46
-     * @param string $metaKey
47
-     * @param string $metaValue
48
-     * @return array|int
49
-     */
50
-    public function getReviewCount($metaKey = '', $metaValue = '')
51
-    {
52
-        if (!$metaKey) {
53
-            return (array) wp_count_posts(Application::POST_TYPE);
54
-        }
55
-        $counts = glsr(Cache::class)->getReviewCountsFor($metaKey);
56
-        if (!$metaValue) {
57
-            return $counts;
58
-        }
59
-        return glsr_get($counts, $metaValue, 0);
60
-    }
45
+	/**
46
+	 * @param string $metaKey
47
+	 * @param string $metaValue
48
+	 * @return array|int
49
+	 */
50
+	public function getReviewCount($metaKey = '', $metaValue = '')
51
+	{
52
+		if (!$metaKey) {
53
+			return (array) wp_count_posts(Application::POST_TYPE);
54
+		}
55
+		$counts = glsr(Cache::class)->getReviewCountsFor($metaKey);
56
+		if (!$metaValue) {
57
+			return $counts;
58
+		}
59
+		return glsr_get($counts, $metaValue, 0);
60
+	}
61 61
 
62
-    /**
63
-     * @param string $metaReviewType
64
-     * @return array
65
-     */
66
-    public function getReviewIdsByType($metaReviewType)
67
-    {
68
-        return glsr(SqlQueries::class)->getReviewIdsByType($metaReviewType);
69
-    }
62
+	/**
63
+	 * @param string $metaReviewType
64
+	 * @return array
65
+	 */
66
+	public function getReviewIdsByType($metaReviewType)
67
+	{
68
+		return glsr(SqlQueries::class)->getReviewIdsByType($metaReviewType);
69
+	}
70 70
 
71
-    /**
72
-     * @param string $key
73
-     * @param string $status
74
-     * @return array
75
-     */
76
-    public function getReviewsMeta($key, $status = 'publish')
77
-    {
78
-        if ('all' == $status || empty($status)) {
79
-            $status = get_post_stati(['exclude_from_search' => false]);
80
-        }
81
-        return glsr(SqlQueries::class)->getReviewsMeta($key, $status);
82
-    }
71
+	/**
72
+	 * @param string $key
73
+	 * @param string $status
74
+	 * @return array
75
+	 */
76
+	public function getReviewsMeta($key, $status = 'publish')
77
+	{
78
+		if ('all' == $status || empty($status)) {
79
+			$status = get_post_stati(['exclude_from_search' => false]);
80
+		}
81
+		return glsr(SqlQueries::class)->getReviewsMeta($key, $status);
82
+	}
83 83
 
84
-    /**
85
-     * @param string $field
86
-     * @return array
87
-     */
88
-    public function getTermIds(array $values, $field)
89
-    {
90
-        $termIds = [];
91
-        foreach ($values as $value) {
92
-            $term = get_term_by($field, $value, Application::TAXONOMY);
93
-            if (!isset($term->term_id)) {
94
-                continue;
95
-            }
96
-            $termIds[] = $term->term_id;
97
-        }
98
-        return $termIds;
99
-    }
84
+	/**
85
+	 * @param string $field
86
+	 * @return array
87
+	 */
88
+	public function getTermIds(array $values, $field)
89
+	{
90
+		$termIds = [];
91
+		foreach ($values as $value) {
92
+			$term = get_term_by($field, $value, Application::TAXONOMY);
93
+			if (!isset($term->term_id)) {
94
+				continue;
95
+			}
96
+			$termIds[] = $term->term_id;
97
+		}
98
+		return $termIds;
99
+	}
100 100
 
101
-    /**
102
-     * @return array
103
-     */
104
-    public function getTerms(array $args = [])
105
-    {
106
-        $args = wp_parse_args($args, [
107
-            'count' => false,
108
-            'fields' => 'id=>name',
109
-            'hide_empty' => false,
110
-            'taxonomy' => Application::TAXONOMY,
111
-        ]);
112
-        $terms = get_terms($args);
113
-        if (is_wp_error($terms)) {
114
-            glsr_log()->error($terms->get_error_message());
115
-            return [];
116
-        }
117
-        return $terms;
118
-    }
101
+	/**
102
+	 * @return array
103
+	 */
104
+	public function getTerms(array $args = [])
105
+	{
106
+		$args = wp_parse_args($args, [
107
+			'count' => false,
108
+			'fields' => 'id=>name',
109
+			'hide_empty' => false,
110
+			'taxonomy' => Application::TAXONOMY,
111
+		]);
112
+		$terms = get_terms($args);
113
+		if (is_wp_error($terms)) {
114
+			glsr_log()->error($terms->get_error_message());
115
+			return [];
116
+		}
117
+		return $terms;
118
+	}
119 119
 
120
-    /**
121
-     * @param string $searchTerm
122
-     * @return void|string
123
-     */
124
-    public function searchPosts($searchTerm)
125
-    {
126
-        $args = [
127
-            'post_status' => 'publish',
128
-            'post_type' => 'any',
129
-        ];
130
-        if (is_numeric($searchTerm)) {
131
-            $args['post__in'] = [$searchTerm];
132
-        } else {
133
-            $args['orderby'] = 'relevance';
134
-            $args['posts_per_page'] = 10;
135
-            $args['s'] = $searchTerm;
136
-        }
137
-        $queryBuilder = glsr(QueryBuilder::class);
138
-        add_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2);
139
-        $search = new WP_Query($args);
140
-        remove_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500);
141
-        if (!$search->have_posts()) {
142
-            return;
143
-        }
144
-        $results = '';
145
-        while ($search->have_posts()) {
146
-            $search->the_post();
147
-            ob_start();
148
-            glsr()->render('partials/editor/search-result', [
149
-                'ID' => get_the_ID(),
150
-                'permalink' => esc_url((string) get_permalink()),
151
-                'title' => esc_attr(get_the_title()),
152
-            ]);
153
-            $results.= ob_get_clean();
154
-        }
155
-        wp_reset_postdata();
156
-        return $results;
157
-    }
120
+	/**
121
+	 * @param string $searchTerm
122
+	 * @return void|string
123
+	 */
124
+	public function searchPosts($searchTerm)
125
+	{
126
+		$args = [
127
+			'post_status' => 'publish',
128
+			'post_type' => 'any',
129
+		];
130
+		if (is_numeric($searchTerm)) {
131
+			$args['post__in'] = [$searchTerm];
132
+		} else {
133
+			$args['orderby'] = 'relevance';
134
+			$args['posts_per_page'] = 10;
135
+			$args['s'] = $searchTerm;
136
+		}
137
+		$queryBuilder = glsr(QueryBuilder::class);
138
+		add_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2);
139
+		$search = new WP_Query($args);
140
+		remove_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500);
141
+		if (!$search->have_posts()) {
142
+			return;
143
+		}
144
+		$results = '';
145
+		while ($search->have_posts()) {
146
+			$search->the_post();
147
+			ob_start();
148
+			glsr()->render('partials/editor/search-result', [
149
+				'ID' => get_the_ID(),
150
+				'permalink' => esc_url((string) get_permalink()),
151
+				'title' => esc_attr(get_the_title()),
152
+			]);
153
+			$results.= ob_get_clean();
154
+		}
155
+		wp_reset_postdata();
156
+		return $results;
157
+	}
158 158
 
159
-    /**
160
-     * @param int $postId
161
-     * @param string $key
162
-     * @param mixed $value
163
-     * @return int|bool
164
-     */
165
-    public function update($postId, $key, $value)
166
-    {
167
-        $key = glsr(Helper::class)->prefix('_', $key);
168
-        return update_post_meta($postId, $key, $value);
169
-    }
159
+	/**
160
+	 * @param int $postId
161
+	 * @param string $key
162
+	 * @param mixed $value
163
+	 * @return int|bool
164
+	 */
165
+	public function update($postId, $key, $value)
166
+	{
167
+		$key = glsr(Helper::class)->prefix('_', $key);
168
+		return update_post_meta($postId, $key, $value);
169
+	}
170 170
 }
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
@@ -9,239 +9,239 @@
 block discarded – undo
9 9
 
10 10
 class Settings
11 11
 {
12
-    /**
13
-     * @var array
14
-     */
15
-    public $settings;
16
-
17
-    /**
18
-     * @param string $id
19
-     * @return string
20
-     */
21
-    public function buildFields($id)
22
-    {
23
-        $this->settings = glsr(DefaultsManager::class)->settings();
24
-        $method = glsr(Helper::class)->buildMethodName($id, 'getTemplateDataFor');
25
-        $data = !method_exists($this, $method)
26
-            ? $this->getTemplateData($id)
27
-            : $this->$method($id);
28
-        return glsr(Template::class)->build('pages/settings/'.$id, $data);
29
-    }
30
-
31
-    /**
32
-     * @return string
33
-     */
34
-    protected function getFieldDefault(array $field)
35
-    {
36
-        return glsr_get($field, 'default');
37
-    }
38
-
39
-    /**
40
-     * @return string
41
-     */
42
-    protected function getFieldNameForDependsOn($path)
43
-    {
44
-        $fieldName = glsr(Helper::class)->convertPathToName($path, OptionManager::databaseKey());
45
-        return $this->isMultiDependency($path)
46
-            ? $fieldName.'[]'
47
-            : $fieldName;
48
-    }
49
-
50
-    /**
51
-     * @return array
52
-     */
53
-    protected function getSettingFields($path)
54
-    {
55
-        return array_filter($this->settings, function ($key) use ($path) {
56
-            return glsr(Helper::class)->startsWith($path, $key);
57
-        }, ARRAY_FILTER_USE_KEY);
58
-    }
59
-
60
-    /**
61
-     * @return string
62
-     */
63
-    protected function getSettingRows(array $fields)
64
-    {
65
-        $rows = '';
66
-        foreach ($fields as $name => $field) {
67
-            $field = wp_parse_args($field, [
68
-                'is_setting' => true,
69
-                'name' => $name,
70
-            ]);
71
-            $rows.= new Field($this->normalize($field));
72
-        }
73
-        return $rows;
74
-    }
75
-
76
-    /**
77
-     * @param string $id
78
-     * @return array
79
-     */
80
-    protected function getTemplateData($id)
81
-    {
82
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
83
-        return [
84
-            'context' => [
85
-                'rows' => $this->getSettingRows($fields),
86
-            ],
87
-        ];
88
-    }
89
-
90
-    /**
91
-     * @param string $id
92
-     * @return array
93
-     */
94
-    protected function getTemplateDataForAddons($id)
95
-    {
96
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
97
-        $settings = glsr(Helper::class)->convertDotNotationArray($fields);
98
-        $settingKeys = array_keys($settings['settings']['addons']);
99
-        $results = [];
100
-        foreach ($settingKeys as $key) {
101
-            $addonFields = array_filter($fields, function ($path) use ($key) {
102
-                return glsr(Helper::class)->startsWith('settings.addons.'.$key, $path);
103
-            }, ARRAY_FILTER_USE_KEY);
104
-            $results[$key] = $this->getSettingRows($addonFields);
105
-        }
106
-        ksort($results);
107
-        return [
108
-            'settings' => $results,
109
-        ];
110
-    }
111
-
112
-    /**
113
-     * @param string $id
114
-     * @return array
115
-     */
116
-    protected function getTemplateDataForLicenses($id)
117
-    {
118
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
119
-        ksort($fields);
120
-        return [
121
-            'context' => [
122
-                'rows' => $this->getSettingRows($fields),
123
-            ],
124
-        ];
125
-    }
126
-
127
-    /**
128
-     * @return array
129
-     */
130
-    protected function getTemplateDataForTranslations()
131
-    {
132
-        $translations = glsr(Translation::class)->renderAll();
133
-        $class = empty($translations)
134
-            ? 'glsr-hidden'
135
-            : '';
136
-        return [
137
-            'context' => [
138
-                'class' => $class,
139
-                'database_key' => OptionManager::databaseKey(),
140
-                'translations' => $translations,
141
-            ],
142
-        ];
143
-    }
144
-
145
-    /**
146
-     * @param string $path
147
-     * @param string|array $expectedValue
148
-     * @return bool
149
-     */
150
-    protected function isFieldHidden($path, $expectedValue)
151
-    {
152
-        $optionValue = glsr(OptionManager::class)->get(
153
-            $path,
154
-            glsr(Helper::class)->dataGet(glsr()->defaults, $path)
155
-        );
156
-        if (is_array($expectedValue)) {
157
-            return is_array($optionValue)
158
-                ? 0 === count(array_intersect($optionValue, $expectedValue))
159
-                : !in_array($optionValue, $expectedValue);
160
-        }
161
-        return $optionValue != $expectedValue;
162
-    }
163
-
164
-    /**
165
-     * @return bool
166
-     */
167
-    protected function isMultiDependency($path)
168
-    {
169
-        if (isset($this->settings[$path])) {
170
-            $field = $this->settings[$path];
171
-            return ('checkbox' == $field['type'] && !empty($field['options']))
172
-                || !empty($field['multiple']);
173
-        }
174
-        return false;
175
-    }
176
-
177
-    /**
178
-     * @return array
179
-     */
180
-    protected function normalize(array $field)
181
-    {
182
-        $field = $this->normalizeDependsOn($field);
183
-        $field = $this->normalizeLabelAndLegend($field);
184
-        $field = $this->normalizeValue($field);
185
-        return $field;
186
-    }
187
-
188
-    /**
189
-     * @return array
190
-     */
191
-    protected function normalizeDependsOn(array $field)
192
-    {
193
-        if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
194
-            $isFieldHidden = false;
195
-            $conditions = [];
196
-            foreach ($field['depends_on'] as $path => $value) {
197
-                $conditions[] = [
198
-                    'name' => $this->getFieldNameForDependsOn($path),
199
-                    'value' => $value,
200
-                ];
201
-                if ($this->isFieldHidden($path, $value)) {
202
-                    $isFieldHidden = true;
203
-                }
204
-            }
205
-            $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
206
-            $field['is_hidden'] = $isFieldHidden;
207
-        }
208
-        return $field;
209
-    }
210
-
211
-    /**
212
-     * @return array
213
-     */
214
-    protected function normalizeLabelAndLegend(array $field)
215
-    {
216
-        if (!empty($field['label'])) {
217
-            $field['legend'] = $field['label'];
218
-            unset($field['label']);
219
-        } else {
220
-            $field['is_valid'] = false;
221
-            glsr_log()->warning('Setting field is missing a label')->debug($field);
222
-        }
223
-        return $field;
224
-    }
225
-
226
-    /**
227
-     * @return array
228
-     */
229
-    protected function normalizeValue(array $field)
230
-    {
231
-        if (!isset($field['value'])) {
232
-            $field['value'] = glsr(OptionManager::class)->get(
233
-                $field['name'],
234
-                $this->getFieldDefault($field)
235
-            );
236
-        }
237
-        return $field;
238
-    }
239
-
240
-    /**
241
-     * @return string
242
-     */
243
-    protected function normalizeSettingPath($path)
244
-    {
245
-        return glsr(Helper::class)->prefix('settings.', rtrim($path, '.'));
246
-    }
12
+	/**
13
+	 * @var array
14
+	 */
15
+	public $settings;
16
+
17
+	/**
18
+	 * @param string $id
19
+	 * @return string
20
+	 */
21
+	public function buildFields($id)
22
+	{
23
+		$this->settings = glsr(DefaultsManager::class)->settings();
24
+		$method = glsr(Helper::class)->buildMethodName($id, 'getTemplateDataFor');
25
+		$data = !method_exists($this, $method)
26
+			? $this->getTemplateData($id)
27
+			: $this->$method($id);
28
+		return glsr(Template::class)->build('pages/settings/'.$id, $data);
29
+	}
30
+
31
+	/**
32
+	 * @return string
33
+	 */
34
+	protected function getFieldDefault(array $field)
35
+	{
36
+		return glsr_get($field, 'default');
37
+	}
38
+
39
+	/**
40
+	 * @return string
41
+	 */
42
+	protected function getFieldNameForDependsOn($path)
43
+	{
44
+		$fieldName = glsr(Helper::class)->convertPathToName($path, OptionManager::databaseKey());
45
+		return $this->isMultiDependency($path)
46
+			? $fieldName.'[]'
47
+			: $fieldName;
48
+	}
49
+
50
+	/**
51
+	 * @return array
52
+	 */
53
+	protected function getSettingFields($path)
54
+	{
55
+		return array_filter($this->settings, function ($key) use ($path) {
56
+			return glsr(Helper::class)->startsWith($path, $key);
57
+		}, ARRAY_FILTER_USE_KEY);
58
+	}
59
+
60
+	/**
61
+	 * @return string
62
+	 */
63
+	protected function getSettingRows(array $fields)
64
+	{
65
+		$rows = '';
66
+		foreach ($fields as $name => $field) {
67
+			$field = wp_parse_args($field, [
68
+				'is_setting' => true,
69
+				'name' => $name,
70
+			]);
71
+			$rows.= new Field($this->normalize($field));
72
+		}
73
+		return $rows;
74
+	}
75
+
76
+	/**
77
+	 * @param string $id
78
+	 * @return array
79
+	 */
80
+	protected function getTemplateData($id)
81
+	{
82
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
83
+		return [
84
+			'context' => [
85
+				'rows' => $this->getSettingRows($fields),
86
+			],
87
+		];
88
+	}
89
+
90
+	/**
91
+	 * @param string $id
92
+	 * @return array
93
+	 */
94
+	protected function getTemplateDataForAddons($id)
95
+	{
96
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
97
+		$settings = glsr(Helper::class)->convertDotNotationArray($fields);
98
+		$settingKeys = array_keys($settings['settings']['addons']);
99
+		$results = [];
100
+		foreach ($settingKeys as $key) {
101
+			$addonFields = array_filter($fields, function ($path) use ($key) {
102
+				return glsr(Helper::class)->startsWith('settings.addons.'.$key, $path);
103
+			}, ARRAY_FILTER_USE_KEY);
104
+			$results[$key] = $this->getSettingRows($addonFields);
105
+		}
106
+		ksort($results);
107
+		return [
108
+			'settings' => $results,
109
+		];
110
+	}
111
+
112
+	/**
113
+	 * @param string $id
114
+	 * @return array
115
+	 */
116
+	protected function getTemplateDataForLicenses($id)
117
+	{
118
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
119
+		ksort($fields);
120
+		return [
121
+			'context' => [
122
+				'rows' => $this->getSettingRows($fields),
123
+			],
124
+		];
125
+	}
126
+
127
+	/**
128
+	 * @return array
129
+	 */
130
+	protected function getTemplateDataForTranslations()
131
+	{
132
+		$translations = glsr(Translation::class)->renderAll();
133
+		$class = empty($translations)
134
+			? 'glsr-hidden'
135
+			: '';
136
+		return [
137
+			'context' => [
138
+				'class' => $class,
139
+				'database_key' => OptionManager::databaseKey(),
140
+				'translations' => $translations,
141
+			],
142
+		];
143
+	}
144
+
145
+	/**
146
+	 * @param string $path
147
+	 * @param string|array $expectedValue
148
+	 * @return bool
149
+	 */
150
+	protected function isFieldHidden($path, $expectedValue)
151
+	{
152
+		$optionValue = glsr(OptionManager::class)->get(
153
+			$path,
154
+			glsr(Helper::class)->dataGet(glsr()->defaults, $path)
155
+		);
156
+		if (is_array($expectedValue)) {
157
+			return is_array($optionValue)
158
+				? 0 === count(array_intersect($optionValue, $expectedValue))
159
+				: !in_array($optionValue, $expectedValue);
160
+		}
161
+		return $optionValue != $expectedValue;
162
+	}
163
+
164
+	/**
165
+	 * @return bool
166
+	 */
167
+	protected function isMultiDependency($path)
168
+	{
169
+		if (isset($this->settings[$path])) {
170
+			$field = $this->settings[$path];
171
+			return ('checkbox' == $field['type'] && !empty($field['options']))
172
+				|| !empty($field['multiple']);
173
+		}
174
+		return false;
175
+	}
176
+
177
+	/**
178
+	 * @return array
179
+	 */
180
+	protected function normalize(array $field)
181
+	{
182
+		$field = $this->normalizeDependsOn($field);
183
+		$field = $this->normalizeLabelAndLegend($field);
184
+		$field = $this->normalizeValue($field);
185
+		return $field;
186
+	}
187
+
188
+	/**
189
+	 * @return array
190
+	 */
191
+	protected function normalizeDependsOn(array $field)
192
+	{
193
+		if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
194
+			$isFieldHidden = false;
195
+			$conditions = [];
196
+			foreach ($field['depends_on'] as $path => $value) {
197
+				$conditions[] = [
198
+					'name' => $this->getFieldNameForDependsOn($path),
199
+					'value' => $value,
200
+				];
201
+				if ($this->isFieldHidden($path, $value)) {
202
+					$isFieldHidden = true;
203
+				}
204
+			}
205
+			$field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
206
+			$field['is_hidden'] = $isFieldHidden;
207
+		}
208
+		return $field;
209
+	}
210
+
211
+	/**
212
+	 * @return array
213
+	 */
214
+	protected function normalizeLabelAndLegend(array $field)
215
+	{
216
+		if (!empty($field['label'])) {
217
+			$field['legend'] = $field['label'];
218
+			unset($field['label']);
219
+		} else {
220
+			$field['is_valid'] = false;
221
+			glsr_log()->warning('Setting field is missing a label')->debug($field);
222
+		}
223
+		return $field;
224
+	}
225
+
226
+	/**
227
+	 * @return array
228
+	 */
229
+	protected function normalizeValue(array $field)
230
+	{
231
+		if (!isset($field['value'])) {
232
+			$field['value'] = glsr(OptionManager::class)->get(
233
+				$field['name'],
234
+				$this->getFieldDefault($field)
235
+			);
236
+		}
237
+		return $field;
238
+	}
239
+
240
+	/**
241
+	 * @return string
242
+	 */
243
+	protected function normalizeSettingPath($path)
244
+	{
245
+		return glsr(Helper::class)->prefix('settings.', rtrim($path, '.'));
246
+	}
247 247
 }
Please login to merge, or discard this patch.