Passed
Push — master ( 7f1e4d...e207fc )
by Paul
04:01
created
plugin/Controllers/ListTableController.php 1 patch
Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -14,266 +14,266 @@
 block discarded – undo
14 14
 
15 15
 class ListTableController extends Controller
16 16
 {
17
-    /**
18
-     * @return void
19
-     * @action admin_action_approve
20
-     */
21
-    public function approve()
22
-    {
23
-        if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
24
-            return;
25
-        }
26
-        check_admin_referer('approve-review_'.($postId = $this->getPostId()));
27
-        wp_update_post([
28
-            'ID' => $postId,
29
-            'post_status' => 'publish',
30
-        ]);
31
-        wp_safe_redirect(wp_get_referer());
32
-        exit;
33
-    }
17
+	/**
18
+	 * @return void
19
+	 * @action admin_action_approve
20
+	 */
21
+	public function approve()
22
+	{
23
+		if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
24
+			return;
25
+		}
26
+		check_admin_referer('approve-review_'.($postId = $this->getPostId()));
27
+		wp_update_post([
28
+			'ID' => $postId,
29
+			'post_status' => 'publish',
30
+		]);
31
+		wp_safe_redirect(wp_get_referer());
32
+		exit;
33
+	}
34 34
 
35
-    /**
36
-     * @param array $columns
37
-     * @return array
38
-     * @filter manage_.Application::POST_TYPE._posts_columns
39
-     */
40
-    public function filterColumnsForPostType($columns)
41
-    {
42
-        $columns = Arr::consolidateArray($columns);
43
-        $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE];
44
-        foreach ($postTypeColumns as $key => &$value) {
45
-            if (!array_key_exists($key, $columns) || !empty($value)) {
46
-                continue;
47
-            }
48
-            $value = $columns[$key];
49
-        }
50
-        if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) {
51
-            unset($postTypeColumns['review_type']);
52
-        }
53
-        return array_filter($postTypeColumns, 'strlen');
54
-    }
35
+	/**
36
+	 * @param array $columns
37
+	 * @return array
38
+	 * @filter manage_.Application::POST_TYPE._posts_columns
39
+	 */
40
+	public function filterColumnsForPostType($columns)
41
+	{
42
+		$columns = Arr::consolidateArray($columns);
43
+		$postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE];
44
+		foreach ($postTypeColumns as $key => &$value) {
45
+			if (!array_key_exists($key, $columns) || !empty($value)) {
46
+				continue;
47
+			}
48
+			$value = $columns[$key];
49
+		}
50
+		if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) {
51
+			unset($postTypeColumns['review_type']);
52
+		}
53
+		return array_filter($postTypeColumns, 'strlen');
54
+	}
55 55
 
56
-    /**
57
-     * @param string $status
58
-     * @param WP_Post $post
59
-     * @return string
60
-     * @filter post_date_column_status
61
-     */
62
-    public function filterDateColumnStatus($status, $post)
63
-    {
64
-        if (Application::POST_TYPE == Arr::get($post, 'post_type')) {
65
-            $status = __('Submitted', 'site-reviews');
66
-        }
67
-        return $status;
68
-    }
56
+	/**
57
+	 * @param string $status
58
+	 * @param WP_Post $post
59
+	 * @return string
60
+	 * @filter post_date_column_status
61
+	 */
62
+	public function filterDateColumnStatus($status, $post)
63
+	{
64
+		if (Application::POST_TYPE == Arr::get($post, 'post_type')) {
65
+			$status = __('Submitted', 'site-reviews');
66
+		}
67
+		return $status;
68
+	}
69 69
 
70
-    /**
71
-     * @param array $hidden
72
-     * @param WP_Screen $post
73
-     * @return array
74
-     * @filter default_hidden_columns
75
-     */
76
-    public function filterDefaultHiddenColumns($hidden, $screen)
77
-    {
78
-        if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) {
79
-            $hidden = Arr::consolidateArray($hidden);
80
-            $hidden = array_unique(array_merge($hidden, [
81
-                'email', 'ip_address', 'response', 'reviewer',
82
-            ]));
83
-        }
84
-        return $hidden;
85
-    }
70
+	/**
71
+	 * @param array $hidden
72
+	 * @param WP_Screen $post
73
+	 * @return array
74
+	 * @filter default_hidden_columns
75
+	 */
76
+	public function filterDefaultHiddenColumns($hidden, $screen)
77
+	{
78
+		if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) {
79
+			$hidden = Arr::consolidateArray($hidden);
80
+			$hidden = array_unique(array_merge($hidden, [
81
+				'email', 'ip_address', 'response', 'reviewer',
82
+			]));
83
+		}
84
+		return $hidden;
85
+	}
86 86
 
87
-    /**
88
-     * @param array $actions
89
-     * @param WP_Post $post
90
-     * @return array
91
-     * @filter post_row_actions
92
-     */
93
-    public function filterRowActions($actions, $post)
94
-    {
95
-        if (Application::POST_TYPE != Arr::get($post, 'post_type') || 'trash' == $post->post_status) {
96
-            return $actions;
97
-        }
98
-        unset($actions['inline hide-if-no-js']); //Remove Quick-edit
99
-        $rowActions = [
100
-            'approve' => esc_attr__('Approve', 'site-reviews'),
101
-            'unapprove' => esc_attr__('Unapprove', 'site-reviews'),
102
-        ];
103
-        $newActions = [];
104
-        foreach ($rowActions as $key => $text) {
105
-            $newActions[$key] = glsr(Builder::class)->a($text, [
106
-                'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text),
107
-                'class' => 'glsr-change-status',
108
-                'href' => wp_nonce_url(
109
-                    admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID),
110
-                    $key.'-review_'.$post->ID
111
-                ),
112
-            ]);
113
-        }
114
-        return $newActions + Arr::consolidateArray($actions);
115
-    }
87
+	/**
88
+	 * @param array $actions
89
+	 * @param WP_Post $post
90
+	 * @return array
91
+	 * @filter post_row_actions
92
+	 */
93
+	public function filterRowActions($actions, $post)
94
+	{
95
+		if (Application::POST_TYPE != Arr::get($post, 'post_type') || 'trash' == $post->post_status) {
96
+			return $actions;
97
+		}
98
+		unset($actions['inline hide-if-no-js']); //Remove Quick-edit
99
+		$rowActions = [
100
+			'approve' => esc_attr__('Approve', 'site-reviews'),
101
+			'unapprove' => esc_attr__('Unapprove', 'site-reviews'),
102
+		];
103
+		$newActions = [];
104
+		foreach ($rowActions as $key => $text) {
105
+			$newActions[$key] = glsr(Builder::class)->a($text, [
106
+				'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text),
107
+				'class' => 'glsr-change-status',
108
+				'href' => wp_nonce_url(
109
+					admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID),
110
+					$key.'-review_'.$post->ID
111
+				),
112
+			]);
113
+		}
114
+		return $newActions + Arr::consolidateArray($actions);
115
+	}
116 116
 
117
-    /**
118
-     * @param array $columns
119
-     * @return array
120
-     * @filter manage_edit-.Application::POST_TYPE._sortable_columns
121
-     */
122
-    public function filterSortableColumns($columns)
123
-    {
124
-        $columns = Arr::consolidateArray($columns);
125
-        $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE];
126
-        unset($postTypeColumns['cb']);
127
-        foreach ($postTypeColumns as $key => $value) {
128
-            if (Str::startsWith('taxonomy', $key)) {
129
-                continue;
130
-            }
131
-            $columns[$key] = $key;
132
-        }
133
-        return $columns;
134
-    }
117
+	/**
118
+	 * @param array $columns
119
+	 * @return array
120
+	 * @filter manage_edit-.Application::POST_TYPE._sortable_columns
121
+	 */
122
+	public function filterSortableColumns($columns)
123
+	{
124
+		$columns = Arr::consolidateArray($columns);
125
+		$postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE];
126
+		unset($postTypeColumns['cb']);
127
+		foreach ($postTypeColumns as $key => $value) {
128
+			if (Str::startsWith('taxonomy', $key)) {
129
+				continue;
130
+			}
131
+			$columns[$key] = $key;
132
+		}
133
+		return $columns;
134
+	}
135 135
 
136
-    /**
137
-     * @param string $columnName
138
-     * @param string $postType
139
-     * @return void
140
-     * @action bulk_edit_custom_box
141
-     */
142
-    public function renderBulkEditFields($columnName, $postType)
143
-    {
144
-        if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) {
145
-            glsr()->render('partials/editor/bulk-edit-assigned-to');
146
-        }
147
-    }
136
+	/**
137
+	 * @param string $columnName
138
+	 * @param string $postType
139
+	 * @return void
140
+	 * @action bulk_edit_custom_box
141
+	 */
142
+	public function renderBulkEditFields($columnName, $postType)
143
+	{
144
+		if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) {
145
+			glsr()->render('partials/editor/bulk-edit-assigned-to');
146
+		}
147
+	}
148 148
 
149
-    /**
150
-     * @param string $postType
151
-     * @return void
152
-     * @action restrict_manage_posts
153
-     */
154
-    public function renderColumnFilters($postType)
155
-    {
156
-        glsr(Columns::class)->renderFilters($postType);
157
-    }
149
+	/**
150
+	 * @param string $postType
151
+	 * @return void
152
+	 * @action restrict_manage_posts
153
+	 */
154
+	public function renderColumnFilters($postType)
155
+	{
156
+		glsr(Columns::class)->renderFilters($postType);
157
+	}
158 158
 
159
-    /**
160
-     * @param string $column
161
-     * @param string $postId
162
-     * @return void
163
-     * @action manage_posts_custom_column
164
-     */
165
-    public function renderColumnValues($column, $postId)
166
-    {
167
-        glsr(Columns::class)->renderValues($column, $postId);
168
-    }
159
+	/**
160
+	 * @param string $column
161
+	 * @param string $postId
162
+	 * @return void
163
+	 * @action manage_posts_custom_column
164
+	 */
165
+	public function renderColumnValues($column, $postId)
166
+	{
167
+		glsr(Columns::class)->renderValues($column, $postId);
168
+	}
169 169
 
170
-    /**
171
-     * @param int $postId
172
-     * @return void
173
-     * @action save_post_.Application::POST_TYPE
174
-     */
175
-    public function saveBulkEditFields($postId)
176
-    {
177
-        if (!current_user_can('edit_posts')) {
178
-            return;
179
-        }
180
-        $assignedTo = filter_input(INPUT_GET, 'assigned_to');
181
-        if ($assignedTo && get_post($assignedTo)) {
182
-            glsr(Database::class)->update($postId, 'assigned_to', $assignedTo);
183
-        }
184
-    }
170
+	/**
171
+	 * @param int $postId
172
+	 * @return void
173
+	 * @action save_post_.Application::POST_TYPE
174
+	 */
175
+	public function saveBulkEditFields($postId)
176
+	{
177
+		if (!current_user_can('edit_posts')) {
178
+			return;
179
+		}
180
+		$assignedTo = filter_input(INPUT_GET, 'assigned_to');
181
+		if ($assignedTo && get_post($assignedTo)) {
182
+			glsr(Database::class)->update($postId, 'assigned_to', $assignedTo);
183
+		}
184
+	}
185 185
 
186
-    /**
187
-     * @return void
188
-     * @action pre_get_posts
189
-     */
190
-    public function setQueryForColumn(WP_Query $query)
191
-    {
192
-        if (!$this->hasPermission($query)) {
193
-            return;
194
-        }
195
-        $this->setMetaQuery($query, [
196
-            'rating', 'review_type',
197
-        ]);
198
-        $this->setOrderby($query);
199
-    }
186
+	/**
187
+	 * @return void
188
+	 * @action pre_get_posts
189
+	 */
190
+	public function setQueryForColumn(WP_Query $query)
191
+	{
192
+		if (!$this->hasPermission($query)) {
193
+			return;
194
+		}
195
+		$this->setMetaQuery($query, [
196
+			'rating', 'review_type',
197
+		]);
198
+		$this->setOrderby($query);
199
+	}
200 200
 
201
-    /**
202
-     * @return void
203
-     * @action admin_action_unapprove
204
-     */
205
-    public function unapprove()
206
-    {
207
-        if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
208
-            return;
209
-        }
210
-        check_admin_referer('unapprove-review_'.($postId = $this->getPostId()));
211
-        wp_update_post([
212
-            'ID' => $postId,
213
-            'post_status' => 'pending',
214
-        ]);
215
-        wp_safe_redirect(wp_get_referer());
216
-        exit;
217
-    }
201
+	/**
202
+	 * @return void
203
+	 * @action admin_action_unapprove
204
+	 */
205
+	public function unapprove()
206
+	{
207
+		if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
208
+			return;
209
+		}
210
+		check_admin_referer('unapprove-review_'.($postId = $this->getPostId()));
211
+		wp_update_post([
212
+			'ID' => $postId,
213
+			'post_status' => 'pending',
214
+		]);
215
+		wp_safe_redirect(wp_get_referer());
216
+		exit;
217
+	}
218 218
 
219
-    /**
220
-     * Check if the translation string can be modified.
221
-     * @param string $domain
222
-     * @return bool
223
-     */
224
-    protected function canModifyTranslation($domain = 'default')
225
-    {
226
-        $screen = glsr_current_screen();
227
-        return 'default' == $domain
228
-            && 'edit' == $screen->base
229
-            && Application::POST_TYPE == $screen->post_type;
230
-    }
219
+	/**
220
+	 * Check if the translation string can be modified.
221
+	 * @param string $domain
222
+	 * @return bool
223
+	 */
224
+	protected function canModifyTranslation($domain = 'default')
225
+	{
226
+		$screen = glsr_current_screen();
227
+		return 'default' == $domain
228
+			&& 'edit' == $screen->base
229
+			&& Application::POST_TYPE == $screen->post_type;
230
+	}
231 231
 
232
-    /**
233
-     * @return bool
234
-     */
235
-    protected function hasPermission(WP_Query $query)
236
-    {
237
-        global $pagenow;
238
-        return is_admin()
239
-            && $query->is_main_query()
240
-            && Application::POST_TYPE == $query->get('post_type')
241
-            && 'edit.php' == $pagenow;
242
-    }
232
+	/**
233
+	 * @return bool
234
+	 */
235
+	protected function hasPermission(WP_Query $query)
236
+	{
237
+		global $pagenow;
238
+		return is_admin()
239
+			&& $query->is_main_query()
240
+			&& Application::POST_TYPE == $query->get('post_type')
241
+			&& 'edit.php' == $pagenow;
242
+	}
243 243
 
244
-    /**
245
-     * @return void
246
-     */
247
-    protected function setMetaQuery(WP_Query $query, array $metaKeys)
248
-    {
249
-        foreach ($metaKeys as $key) {
250
-            $value = (string) filter_input(INPUT_GET, $key);
251
-            if ('' === $value) {
252
-                continue;
253
-            }
254
-            $metaQuery = (array) $query->get('meta_query');
255
-            $metaQuery[] = [
256
-                'key' => Str::prefix('_', $key, '_'),
257
-                'value' => $value,
258
-            ];
259
-            $query->set('meta_query', array_filter($metaQuery));
260
-        }
261
-    }
244
+	/**
245
+	 * @return void
246
+	 */
247
+	protected function setMetaQuery(WP_Query $query, array $metaKeys)
248
+	{
249
+		foreach ($metaKeys as $key) {
250
+			$value = (string) filter_input(INPUT_GET, $key);
251
+			if ('' === $value) {
252
+				continue;
253
+			}
254
+			$metaQuery = (array) $query->get('meta_query');
255
+			$metaQuery[] = [
256
+				'key' => Str::prefix('_', $key, '_'),
257
+				'value' => $value,
258
+			];
259
+			$query->set('meta_query', array_filter($metaQuery));
260
+		}
261
+	}
262 262
 
263
-    /**
264
-     * @return void
265
-     */
266
-    protected function setOrderby(WP_Query $query)
267
-    {
268
-        $orderby = $query->get('orderby');
269
-        $columns = glsr()->postTypeColumns[Application::POST_TYPE];
270
-        unset($columns['cb'], $columns['title'], $columns['date']);
271
-        if (in_array($orderby, array_keys($columns))) {
272
-            if ('reviewer' == $orderby) {
273
-                $orderby = 'author';
274
-            }
275
-            $query->set('meta_key', Str::prefix('_', $orderby, '_'));
276
-            $query->set('orderby', 'meta_value');
277
-        }
278
-    }
263
+	/**
264
+	 * @return void
265
+	 */
266
+	protected function setOrderby(WP_Query $query)
267
+	{
268
+		$orderby = $query->get('orderby');
269
+		$columns = glsr()->postTypeColumns[Application::POST_TYPE];
270
+		unset($columns['cb'], $columns['title'], $columns['date']);
271
+		if (in_array($orderby, array_keys($columns))) {
272
+			if ('reviewer' == $orderby) {
273
+				$orderby = 'author';
274
+			}
275
+			$query->set('meta_key', Str::prefix('_', $orderby, '_'));
276
+			$query->set('orderby', 'meta_value');
277
+		}
278
+	}
279 279
 }
Please login to merge, or discard this patch.
plugin/Database.php 1 patch
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -12,168 +12,168 @@
 block discarded – undo
12 12
 
13 13
 class Database
14 14
 {
15
-    /**
16
-     * @param int $postId
17
-     * @param string $key
18
-     * @param bool $single
19
-     * @return mixed
20
-     */
21
-    public function get($postId, $key, $single = true)
22
-    {
23
-        $key = Str::prefix('_', $key);
24
-        return get_post_meta(intval($postId), $key, $single);
25
-    }
15
+	/**
16
+	 * @param int $postId
17
+	 * @param string $key
18
+	 * @param bool $single
19
+	 * @return mixed
20
+	 */
21
+	public function get($postId, $key, $single = true)
22
+	{
23
+		$key = Str::prefix('_', $key);
24
+		return get_post_meta(intval($postId), $key, $single);
25
+	}
26 26
 
27
-    /**
28
-     * @param int $postId
29
-     * @param string $assignedTo
30
-     * @return void|WP_Post
31
-     */
32
-    public function getAssignedToPost($postId, $assignedTo = '')
33
-    {
34
-        if (empty($assignedTo)) {
35
-            $assignedTo = $this->get($postId, 'assigned_to');
36
-        }
37
-        if (empty($assignedTo)) {
38
-            return;
39
-        }
40
-        $assignedPost = get_post($assignedTo);
41
-        if ($assignedPost instanceof WP_Post && $assignedPost->ID != $postId) {
42
-            return $assignedPost;
43
-        }
44
-    }
27
+	/**
28
+	 * @param int $postId
29
+	 * @param string $assignedTo
30
+	 * @return void|WP_Post
31
+	 */
32
+	public function getAssignedToPost($postId, $assignedTo = '')
33
+	{
34
+		if (empty($assignedTo)) {
35
+			$assignedTo = $this->get($postId, 'assigned_to');
36
+		}
37
+		if (empty($assignedTo)) {
38
+			return;
39
+		}
40
+		$assignedPost = get_post($assignedTo);
41
+		if ($assignedPost instanceof WP_Post && $assignedPost->ID != $postId) {
42
+			return $assignedPost;
43
+		}
44
+	}
45 45
 
46
-    /**
47
-     * @param string $metaKey
48
-     * @param string $metaValue
49
-     * @return array|int
50
-     */
51
-    public function getReviewCount($metaKey = '', $metaValue = '')
52
-    {
53
-        if (!$metaKey) {
54
-            return (array) wp_count_posts(Application::POST_TYPE);
55
-        }
56
-        $counts = glsr(Cache::class)->getReviewCountsFor($metaKey);
57
-        if (!$metaValue) {
58
-            return $counts;
59
-        }
60
-        return Arr::get($counts, $metaValue, 0);
61
-    }
46
+	/**
47
+	 * @param string $metaKey
48
+	 * @param string $metaValue
49
+	 * @return array|int
50
+	 */
51
+	public function getReviewCount($metaKey = '', $metaValue = '')
52
+	{
53
+		if (!$metaKey) {
54
+			return (array) wp_count_posts(Application::POST_TYPE);
55
+		}
56
+		$counts = glsr(Cache::class)->getReviewCountsFor($metaKey);
57
+		if (!$metaValue) {
58
+			return $counts;
59
+		}
60
+		return Arr::get($counts, $metaValue, 0);
61
+	}
62 62
 
63
-    /**
64
-     * @param string $metaReviewType
65
-     * @return array
66
-     */
67
-    public function getReviewIdsByType($metaReviewType)
68
-    {
69
-        return glsr(SqlQueries::class)->getReviewIdsByType($metaReviewType);
70
-    }
63
+	/**
64
+	 * @param string $metaReviewType
65
+	 * @return array
66
+	 */
67
+	public function getReviewIdsByType($metaReviewType)
68
+	{
69
+		return glsr(SqlQueries::class)->getReviewIdsByType($metaReviewType);
70
+	}
71 71
 
72
-    /**
73
-     * @param string $key
74
-     * @param string $status
75
-     * @return array
76
-     */
77
-    public function getReviewsMeta($key, $status = 'publish')
78
-    {
79
-        return glsr(SqlQueries::class)->getReviewsMeta($key, $status);
80
-    }
72
+	/**
73
+	 * @param string $key
74
+	 * @param string $status
75
+	 * @return array
76
+	 */
77
+	public function getReviewsMeta($key, $status = 'publish')
78
+	{
79
+		return glsr(SqlQueries::class)->getReviewsMeta($key, $status);
80
+	}
81 81
 
82
-    /**
83
-     * @param string $field
84
-     * @return array
85
-     */
86
-    public function getTermIds(array $values, $field)
87
-    {
88
-        $termIds = [];
89
-        foreach ($values as $value) {
90
-            $term = get_term_by($field, $value, Application::TAXONOMY);
91
-            if (!isset($term->term_id)) {
92
-                continue;
93
-            }
94
-            $termIds[] = $term->term_id;
95
-        }
96
-        return $termIds;
97
-    }
82
+	/**
83
+	 * @param string $field
84
+	 * @return array
85
+	 */
86
+	public function getTermIds(array $values, $field)
87
+	{
88
+		$termIds = [];
89
+		foreach ($values as $value) {
90
+			$term = get_term_by($field, $value, Application::TAXONOMY);
91
+			if (!isset($term->term_id)) {
92
+				continue;
93
+			}
94
+			$termIds[] = $term->term_id;
95
+		}
96
+		return $termIds;
97
+	}
98 98
 
99
-    /**
100
-     * @return array
101
-     */
102
-    public function getTerms(array $args = [])
103
-    {
104
-        $args = wp_parse_args($args, [
105
-            'count' => false,
106
-            'fields' => 'id=>name',
107
-            'hide_empty' => false,
108
-            'taxonomy' => Application::TAXONOMY,
109
-        ]);
110
-        $terms = get_terms($args);
111
-        if (is_wp_error($terms)) {
112
-            glsr_log()->error($terms->get_error_message());
113
-            return [];
114
-        }
115
-        return $terms;
116
-    }
99
+	/**
100
+	 * @return array
101
+	 */
102
+	public function getTerms(array $args = [])
103
+	{
104
+		$args = wp_parse_args($args, [
105
+			'count' => false,
106
+			'fields' => 'id=>name',
107
+			'hide_empty' => false,
108
+			'taxonomy' => Application::TAXONOMY,
109
+		]);
110
+		$terms = get_terms($args);
111
+		if (is_wp_error($terms)) {
112
+			glsr_log()->error($terms->get_error_message());
113
+			return [];
114
+		}
115
+		return $terms;
116
+	}
117 117
 
118
-    /**
119
-     * @param string $searchTerm
120
-     * @return void|string
121
-     */
122
-    public function searchPosts($searchTerm)
123
-    {
124
-        $args = [
125
-            'post_status' => 'publish',
126
-            'post_type' => 'any',
127
-        ];
128
-        if (is_numeric($searchTerm)) {
129
-            $args['post__in'] = [$searchTerm];
130
-        } else {
131
-            $args['orderby'] = 'relevance';
132
-            $args['posts_per_page'] = 10;
133
-            $args['s'] = $searchTerm;
134
-        }
135
-        $queryBuilder = glsr(QueryBuilder::class);
136
-        add_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2);
137
-        $search = new WP_Query($args);
138
-        remove_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500);
139
-        if (!$search->have_posts()) {
140
-            return;
141
-        }
142
-        $results = '';
143
-        while ($search->have_posts()) {
144
-            $search->the_post();
145
-            ob_start();
146
-            glsr()->render('partials/editor/search-result', [
147
-                'ID' => get_the_ID(),
148
-                'permalink' => esc_url((string) get_permalink()),
149
-                'title' => esc_attr(get_the_title()),
150
-            ]);
151
-            $results.= ob_get_clean();
152
-        }
153
-        wp_reset_postdata();
154
-        return $results;
155
-    }
118
+	/**
119
+	 * @param string $searchTerm
120
+	 * @return void|string
121
+	 */
122
+	public function searchPosts($searchTerm)
123
+	{
124
+		$args = [
125
+			'post_status' => 'publish',
126
+			'post_type' => 'any',
127
+		];
128
+		if (is_numeric($searchTerm)) {
129
+			$args['post__in'] = [$searchTerm];
130
+		} else {
131
+			$args['orderby'] = 'relevance';
132
+			$args['posts_per_page'] = 10;
133
+			$args['s'] = $searchTerm;
134
+		}
135
+		$queryBuilder = glsr(QueryBuilder::class);
136
+		add_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2);
137
+		$search = new WP_Query($args);
138
+		remove_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500);
139
+		if (!$search->have_posts()) {
140
+			return;
141
+		}
142
+		$results = '';
143
+		while ($search->have_posts()) {
144
+			$search->the_post();
145
+			ob_start();
146
+			glsr()->render('partials/editor/search-result', [
147
+				'ID' => get_the_ID(),
148
+				'permalink' => esc_url((string) get_permalink()),
149
+				'title' => esc_attr(get_the_title()),
150
+			]);
151
+			$results.= ob_get_clean();
152
+		}
153
+		wp_reset_postdata();
154
+		return $results;
155
+	}
156 156
 
157
-    /**
158
-     * @param int $postId
159
-     * @param string $key
160
-     * @param mixed $value
161
-     * @return int|bool
162
-     */
163
-    public function set($postId, $key, $value)
164
-    {
165
-        $key = Str::prefix('_', $key);
166
-        return update_post_meta($postId, $key, $value);
167
-    }
157
+	/**
158
+	 * @param int $postId
159
+	 * @param string $key
160
+	 * @param mixed $value
161
+	 * @return int|bool
162
+	 */
163
+	public function set($postId, $key, $value)
164
+	{
165
+		$key = Str::prefix('_', $key);
166
+		return update_post_meta($postId, $key, $value);
167
+	}
168 168
 
169
-    /**
170
-     * @param int $postId
171
-     * @param string $key
172
-     * @param mixed $value
173
-     * @return int|bool
174
-     */
175
-    public function update($postId, $key, $value)
176
-    {
177
-        return $this->set($postId, $key, $value);
178
-    }
169
+	/**
170
+	 * @param int $postId
171
+	 * @param string $key
172
+	 * @param mixed $value
173
+	 * @return int|bool
174
+	 */
175
+	public function update($postId, $key, $value)
176
+	{
177
+		return $this->set($postId, $key, $value);
178
+	}
179 179
 }
Please login to merge, or discard this patch.
plugin/Shortcodes/SiteReviewsFormShortcode.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -6,29 +6,29 @@
 block discarded – undo
6 6
 
7 7
 class SiteReviewsFormShortcode extends Shortcode
8 8
 {
9
-    protected function hideOptions()
10
-    {
11
-        return [
12
-            'rating' => __('Hide the rating field', 'site-reviews'),
13
-            'title' => __('Hide the title field', 'site-reviews'),
14
-            'content' => __('Hide the review field', 'site-reviews'),
15
-            'name' => __('Hide the name field', 'site-reviews'),
16
-            'email' => __('Hide the email field', 'site-reviews'),
17
-            'terms' => __('Hide the terms field', 'site-reviews'),
18
-        ];
19
-    }
9
+	protected function hideOptions()
10
+	{
11
+		return [
12
+			'rating' => __('Hide the rating field', 'site-reviews'),
13
+			'title' => __('Hide the title field', 'site-reviews'),
14
+			'content' => __('Hide the review field', 'site-reviews'),
15
+			'name' => __('Hide the name field', 'site-reviews'),
16
+			'email' => __('Hide the email field', 'site-reviews'),
17
+			'terms' => __('Hide the terms field', 'site-reviews'),
18
+		];
19
+	}
20 20
 
21
-    /**
22
-     * @param array|string $atts
23
-     * @param string $type
24
-     * @return array
25
-     */
26
-    public function normalizeAtts($atts, $type = 'shortcode')
27
-    {
28
-        $atts = parent::normalizeAtts($atts, $type);
29
-        if (empty($atts['id'])) {
30
-            $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8);
31
-        }
32
-        return $atts;
33
-    }
21
+	/**
22
+	 * @param array|string $atts
23
+	 * @param string $type
24
+	 * @return array
25
+	 */
26
+	public function normalizeAtts($atts, $type = 'shortcode')
27
+	{
28
+		$atts = parent::normalizeAtts($atts, $type);
29
+		if (empty($atts['id'])) {
30
+			$atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8);
31
+		}
32
+		return $atts;
33
+	}
34 34
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/SiteReviews.php 1 patch
Indentation   +353 added lines, -353 removed lines patch added patch discarded remove patch
@@ -21,382 +21,382 @@
 block discarded – undo
21 21
 
22 22
 class SiteReviews
23 23
 {
24
-    /**
25
-     * @var array
26
-     */
27
-    public $args;
24
+	/**
25
+	 * @var array
26
+	 */
27
+	public $args;
28 28
 
29
-    /**
30
-     * @var Review
31
-     */
32
-    public $current;
29
+	/**
30
+	 * @var Review
31
+	 */
32
+	public $current;
33 33
 
34
-    /**
35
-     * @var array
36
-     */
37
-    public $options;
34
+	/**
35
+	 * @var array
36
+	 */
37
+	public $options;
38 38
 
39
-    /**
40
-     * @var Reviews
41
-     */
42
-    protected $reviews;
39
+	/**
40
+	 * @var Reviews
41
+	 */
42
+	protected $reviews;
43 43
 
44
-    /**
45
-     * @param Reviews|null $reviews
46
-     * @return ReviewsHtml
47
-     */
48
-    public function build(array $args = [], $reviews = null)
49
-    {
50
-        $this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
-        $this->options = Arr::flattenArray(glsr(OptionManager::class)->all());
52
-        $this->reviews = $reviews instanceof Reviews
53
-            ? $reviews
54
-            : glsr(ReviewManager::class)->get($this->args);
55
-        $this->generateSchema();
56
-        return $this->buildReviews();
57
-    }
44
+	/**
45
+	 * @param Reviews|null $reviews
46
+	 * @return ReviewsHtml
47
+	 */
48
+	public function build(array $args = [], $reviews = null)
49
+	{
50
+		$this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
+		$this->options = Arr::flattenArray(glsr(OptionManager::class)->all());
52
+		$this->reviews = $reviews instanceof Reviews
53
+			? $reviews
54
+			: glsr(ReviewManager::class)->get($this->args);
55
+		$this->generateSchema();
56
+		return $this->buildReviews();
57
+	}
58 58
 
59
-    /**
60
-     * @return ReviewHtml
61
-     */
62
-    public function buildReview(Review $review)
63
-    {
64
-        $review = apply_filters('site-reviews/review/build/before', $review);
65
-        $this->current = $review;
66
-        $renderedFields = [];
67
-        foreach ($review as $key => $value) {
68
-            $method = Helper::buildMethodName($key, 'buildOption');
69
-            $field = method_exists($this, $method)
70
-                ? $this->$method($key, $value)
71
-                : false;
72
-            $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
-            if (false === $field) {
74
-                continue;
75
-            }
76
-            $renderedFields[$key] = $field;
77
-        }
78
-        $this->wrap($renderedFields, $review);
79
-        $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
80
-        $this->current = null;
81
-        return new ReviewHtml($review, (array) $renderedFields);
82
-    }
59
+	/**
60
+	 * @return ReviewHtml
61
+	 */
62
+	public function buildReview(Review $review)
63
+	{
64
+		$review = apply_filters('site-reviews/review/build/before', $review);
65
+		$this->current = $review;
66
+		$renderedFields = [];
67
+		foreach ($review as $key => $value) {
68
+			$method = Helper::buildMethodName($key, 'buildOption');
69
+			$field = method_exists($this, $method)
70
+				? $this->$method($key, $value)
71
+				: false;
72
+			$field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
+			if (false === $field) {
74
+				continue;
75
+			}
76
+			$renderedFields[$key] = $field;
77
+		}
78
+		$this->wrap($renderedFields, $review);
79
+		$renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
80
+		$this->current = null;
81
+		return new ReviewHtml($review, (array) $renderedFields);
82
+	}
83 83
 
84
-    /**
85
-     * @return ReviewsHtml
86
-     */
87
-    public function buildReviews()
88
-    {
89
-        $renderedReviews = [];
90
-        foreach ($this->reviews as $index => $review) {
91
-            $renderedReviews[] = $this->buildReview($review);
92
-        }
93
-        return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
94
-    }
84
+	/**
85
+	 * @return ReviewsHtml
86
+	 */
87
+	public function buildReviews()
88
+	{
89
+		$renderedReviews = [];
90
+		foreach ($this->reviews as $index => $review) {
91
+			$renderedReviews[] = $this->buildReview($review);
92
+		}
93
+		return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
94
+	}
95 95
 
96
-    /**
97
-     * @return void
98
-     */
99
-    public function generateSchema()
100
-    {
101
-        if (!wp_validate_boolean($this->args['schema'])) {
102
-            return;
103
-        }
104
-        glsr(Schema::class)->store(
105
-            glsr(Schema::class)->build($this->args)
106
-        );
107
-    }
96
+	/**
97
+	 * @return void
98
+	 */
99
+	public function generateSchema()
100
+	{
101
+		if (!wp_validate_boolean($this->args['schema'])) {
102
+			return;
103
+		}
104
+		glsr(Schema::class)->store(
105
+			glsr(Schema::class)->build($this->args)
106
+		);
107
+	}
108 108
 
109
-    /**
110
-     * @param string $text
111
-     * @return string
112
-     */
113
-    public function getExcerpt($text)
114
-    {
115
-        $limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
116
-        $split = extension_loaded('intl')
117
-            ? $this->getExcerptIntlSplit($text, $limit)
118
-            : $this->getExcerptSplit($text, $limit);
119
-        $hiddenText = substr($text, $split);
120
-        if (!empty($hiddenText)) {
121
-            $showMore = glsr(Builder::class)->span($hiddenText, [
122
-                'class' => 'glsr-hidden glsr-hidden-text',
123
-                'data-show-less' => __('Show less', 'site-reviews'),
124
-                'data-show-more' => __('Show more', 'site-reviews'),
125
-            ]);
126
-            $text = ltrim(substr($text, 0, $split)).$showMore;
127
-        }
128
-        return $text;
129
-    }
109
+	/**
110
+	 * @param string $text
111
+	 * @return string
112
+	 */
113
+	public function getExcerpt($text)
114
+	{
115
+		$limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
116
+		$split = extension_loaded('intl')
117
+			? $this->getExcerptIntlSplit($text, $limit)
118
+			: $this->getExcerptSplit($text, $limit);
119
+		$hiddenText = substr($text, $split);
120
+		if (!empty($hiddenText)) {
121
+			$showMore = glsr(Builder::class)->span($hiddenText, [
122
+				'class' => 'glsr-hidden glsr-hidden-text',
123
+				'data-show-less' => __('Show less', 'site-reviews'),
124
+				'data-show-more' => __('Show more', 'site-reviews'),
125
+			]);
126
+			$text = ltrim(substr($text, 0, $split)).$showMore;
127
+		}
128
+		return $text;
129
+	}
130 130
 
131
-    /**
132
-     * @param string $key
133
-     * @param string $path
134
-     * @return bool
135
-     */
136
-    public function isHidden($key, $path = '')
137
-    {
138
-        $isOptionEnabled = !empty($path)
139
-            ? $this->isOptionEnabled($path)
140
-            : true;
141
-        return in_array($key, $this->args['hide']) || !$isOptionEnabled;
142
-    }
131
+	/**
132
+	 * @param string $key
133
+	 * @param string $path
134
+	 * @return bool
135
+	 */
136
+	public function isHidden($key, $path = '')
137
+	{
138
+		$isOptionEnabled = !empty($path)
139
+			? $this->isOptionEnabled($path)
140
+			: true;
141
+		return in_array($key, $this->args['hide']) || !$isOptionEnabled;
142
+	}
143 143
 
144
-    /**
145
-     * @param string $key
146
-     * @param string $value
147
-     * @return bool
148
-     */
149
-    public function isHiddenOrEmpty($key, $value)
150
-    {
151
-        return $this->isHidden($key) || empty($value);
152
-    }
144
+	/**
145
+	 * @param string $key
146
+	 * @param string $value
147
+	 * @return bool
148
+	 */
149
+	public function isHiddenOrEmpty($key, $value)
150
+	{
151
+		return $this->isHidden($key) || empty($value);
152
+	}
153 153
 
154
-    /**
155
-     * @param string $text
156
-     * @return string
157
-     */
158
-    public function normalizeText($text)
159
-    {
160
-        $text = wp_kses($text, wp_kses_allowed_html());
161
-        $text = convert_smilies(strip_shortcodes($text));
162
-        $text = str_replace(']]>', ']]&gt;', $text);
163
-        $text = preg_replace('/(\R){2,}/', '$1', $text);
164
-        if ($this->isOptionEnabled('settings.reviews.excerpts')) {
165
-            $text = $this->getExcerpt($text);
166
-        }
167
-        return wptexturize(nl2br($text));
168
-    }
154
+	/**
155
+	 * @param string $text
156
+	 * @return string
157
+	 */
158
+	public function normalizeText($text)
159
+	{
160
+		$text = wp_kses($text, wp_kses_allowed_html());
161
+		$text = convert_smilies(strip_shortcodes($text));
162
+		$text = str_replace(']]>', ']]&gt;', $text);
163
+		$text = preg_replace('/(\R){2,}/', '$1', $text);
164
+		if ($this->isOptionEnabled('settings.reviews.excerpts')) {
165
+			$text = $this->getExcerpt($text);
166
+		}
167
+		return wptexturize(nl2br($text));
168
+	}
169 169
 
170
-    /**
171
-     * @param string $key
172
-     * @param string $value
173
-     * @return void|string
174
-     */
175
-    protected function buildOptionAssignedTo($key, $value)
176
-    {
177
-        if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
178
-            return;
179
-        }
180
-        $post = glsr(Multilingual::class)->getPost($value);
181
-        if (!($post instanceof WP_Post)) {
182
-            return;
183
-        }
184
-        $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
185
-            'href' => get_the_permalink($post->ID),
186
-        ]);
187
-        $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
188
-        return '<span>'.$assignedTo.'</span>';
189
-    }
170
+	/**
171
+	 * @param string $key
172
+	 * @param string $value
173
+	 * @return void|string
174
+	 */
175
+	protected function buildOptionAssignedTo($key, $value)
176
+	{
177
+		if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
178
+			return;
179
+		}
180
+		$post = glsr(Multilingual::class)->getPost($value);
181
+		if (!($post instanceof WP_Post)) {
182
+			return;
183
+		}
184
+		$permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
185
+			'href' => get_the_permalink($post->ID),
186
+		]);
187
+		$assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
188
+		return '<span>'.$assignedTo.'</span>';
189
+	}
190 190
 
191
-    /**
192
-     * @param string $key
193
-     * @param string $value
194
-     * @return void|string
195
-     */
196
-    protected function buildOptionAuthor($key, $value)
197
-    {
198
-        if (!$this->isHidden($key)) {
199
-            $name = Str::convertName(
200
-                $value,
201
-                glsr_get_option('reviews.name.format'),
202
-                glsr_get_option('reviews.name.initial')
203
-            );
204
-            return '<span>'.$name.'</span>';
205
-        }
206
-    }
191
+	/**
192
+	 * @param string $key
193
+	 * @param string $value
194
+	 * @return void|string
195
+	 */
196
+	protected function buildOptionAuthor($key, $value)
197
+	{
198
+		if (!$this->isHidden($key)) {
199
+			$name = Str::convertName(
200
+				$value,
201
+				glsr_get_option('reviews.name.format'),
202
+				glsr_get_option('reviews.name.initial')
203
+			);
204
+			return '<span>'.$name.'</span>';
205
+		}
206
+	}
207 207
 
208
-    /**
209
-     * @param string $key
210
-     * @param string $value
211
-     * @return void|string
212
-     */
213
-    protected function buildOptionAvatar($key, $value)
214
-    {
215
-        if ($this->isHidden($key, 'settings.reviews.avatars')) {
216
-            return;
217
-        }
218
-        $size = $this->getOption('settings.reviews.avatars_size', 40);
219
-        return glsr(Builder::class)->img([
220
-            'height' => $size,
221
-            'src' => $this->generateAvatar($value),
222
-            'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
223
-            'width' => $size,
224
-        ]);
225
-    }
208
+	/**
209
+	 * @param string $key
210
+	 * @param string $value
211
+	 * @return void|string
212
+	 */
213
+	protected function buildOptionAvatar($key, $value)
214
+	{
215
+		if ($this->isHidden($key, 'settings.reviews.avatars')) {
216
+			return;
217
+		}
218
+		$size = $this->getOption('settings.reviews.avatars_size', 40);
219
+		return glsr(Builder::class)->img([
220
+			'height' => $size,
221
+			'src' => $this->generateAvatar($value),
222
+			'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
223
+			'width' => $size,
224
+		]);
225
+	}
226 226
 
227
-    /**
228
-     * @param string $key
229
-     * @param string $value
230
-     * @return void|string
231
-     */
232
-    protected function buildOptionContent($key, $value)
233
-    {
234
-        $text = $this->normalizeText($value);
235
-        if (!$this->isHiddenOrEmpty($key, $text)) {
236
-            return '<p>'.$text.'</p>';
237
-        }
238
-    }
227
+	/**
228
+	 * @param string $key
229
+	 * @param string $value
230
+	 * @return void|string
231
+	 */
232
+	protected function buildOptionContent($key, $value)
233
+	{
234
+		$text = $this->normalizeText($value);
235
+		if (!$this->isHiddenOrEmpty($key, $text)) {
236
+			return '<p>'.$text.'</p>';
237
+		}
238
+	}
239 239
 
240
-    /**
241
-     * @param string $key
242
-     * @param string $value
243
-     * @return void|string
244
-     */
245
-    protected function buildOptionDate($key, $value)
246
-    {
247
-        if ($this->isHidden($key)) {
248
-            return;
249
-        }
250
-        $dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
-        if ('relative' == $dateFormat) {
252
-            $date = glsr(Date::class)->relative($value);
253
-        } else {
254
-            $format = 'custom' == $dateFormat
255
-                ? $this->getOption('settings.reviews.date.custom', 'M j, Y')
256
-                : glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
257
-            $date = date_i18n($format, strtotime($value));
258
-        }
259
-        return '<span>'.$date.'</span>';
260
-    }
240
+	/**
241
+	 * @param string $key
242
+	 * @param string $value
243
+	 * @return void|string
244
+	 */
245
+	protected function buildOptionDate($key, $value)
246
+	{
247
+		if ($this->isHidden($key)) {
248
+			return;
249
+		}
250
+		$dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
+		if ('relative' == $dateFormat) {
252
+			$date = glsr(Date::class)->relative($value);
253
+		} else {
254
+			$format = 'custom' == $dateFormat
255
+				? $this->getOption('settings.reviews.date.custom', 'M j, Y')
256
+				: glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
257
+			$date = date_i18n($format, strtotime($value));
258
+		}
259
+		return '<span>'.$date.'</span>';
260
+	}
261 261
 
262
-    /**
263
-     * @param string $key
264
-     * @param string $value
265
-     * @return void|string
266
-     */
267
-    protected function buildOptionRating($key, $value)
268
-    {
269
-        if (!$this->isHiddenOrEmpty($key, $value)) {
270
-            return glsr_star_rating($value);
271
-        }
272
-    }
262
+	/**
263
+	 * @param string $key
264
+	 * @param string $value
265
+	 * @return void|string
266
+	 */
267
+	protected function buildOptionRating($key, $value)
268
+	{
269
+		if (!$this->isHiddenOrEmpty($key, $value)) {
270
+			return glsr_star_rating($value);
271
+		}
272
+	}
273 273
 
274
-    /**
275
-     * @param string $key
276
-     * @param string $value
277
-     * @return void|string
278
-     */
279
-    protected function buildOptionResponse($key, $value)
280
-    {
281
-        if ($this->isHiddenOrEmpty($key, $value)) {
282
-            return;
283
-        }
284
-        $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
-        $text = $this->normalizeText($value);
286
-        $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
287
-        $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
288
-        $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
289
-        return $response.$background;
290
-    }
274
+	/**
275
+	 * @param string $key
276
+	 * @param string $value
277
+	 * @return void|string
278
+	 */
279
+	protected function buildOptionResponse($key, $value)
280
+	{
281
+		if ($this->isHiddenOrEmpty($key, $value)) {
282
+			return;
283
+		}
284
+		$title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
+		$text = $this->normalizeText($value);
286
+		$text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
287
+		$response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
288
+		$background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
289
+		return $response.$background;
290
+	}
291 291
 
292
-    /**
293
-     * @param string $key
294
-     * @param string $value
295
-     * @return void|string
296
-     */
297
-    protected function buildOptionTitle($key, $value)
298
-    {
299
-        if ($this->isHidden($key)) {
300
-            return;
301
-        }
302
-        if (empty($value)) {
303
-            $value = __('No Title', 'site-reviews');
304
-        }
305
-        return '<h3>'.$value.'</h3>';
306
-    }
292
+	/**
293
+	 * @param string $key
294
+	 * @param string $value
295
+	 * @return void|string
296
+	 */
297
+	protected function buildOptionTitle($key, $value)
298
+	{
299
+		if ($this->isHidden($key)) {
300
+			return;
301
+		}
302
+		if (empty($value)) {
303
+			$value = __('No Title', 'site-reviews');
304
+		}
305
+		return '<h3>'.$value.'</h3>';
306
+	}
307 307
 
308
-    /**
309
-     * @param string $avatarUrl
310
-     * @return string
311
-     */
312
-    protected function generateAvatar($avatarUrl)
313
-    {
314
-        if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
315
-            return $avatarUrl;
316
-        }
317
-        $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
318
-        if (empty($authorIdOrEmail)) {
319
-            $authorIdOrEmail = $this->current->email;
320
-        }
321
-        if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
322
-            return $newAvatar;
323
-        }
324
-        return $avatarUrl;
325
-    }
308
+	/**
309
+	 * @param string $avatarUrl
310
+	 * @return string
311
+	 */
312
+	protected function generateAvatar($avatarUrl)
313
+	{
314
+		if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
315
+			return $avatarUrl;
316
+		}
317
+		$authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
318
+		if (empty($authorIdOrEmail)) {
319
+			$authorIdOrEmail = $this->current->email;
320
+		}
321
+		if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
322
+			return $newAvatar;
323
+		}
324
+		return $avatarUrl;
325
+	}
326 326
 
327
-    /**
328
-     * @param string $text
329
-     * @param int $limit
330
-     * @return int
331
-     */
332
-    protected function getExcerptIntlSplit($text, $limit)
333
-    {
334
-        $words = IntlRuleBasedBreakIterator::createWordInstance('');
335
-        $words->setText($text);
336
-        $count = 0;
337
-        foreach ($words as $offset) {
338
-            if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
339
-                continue;
340
-            }
341
-            ++$count;
342
-            if ($count != $limit) {
343
-                continue;
344
-            }
345
-            return $offset;
346
-        }
347
-        return strlen($text);
348
-    }
327
+	/**
328
+	 * @param string $text
329
+	 * @param int $limit
330
+	 * @return int
331
+	 */
332
+	protected function getExcerptIntlSplit($text, $limit)
333
+	{
334
+		$words = IntlRuleBasedBreakIterator::createWordInstance('');
335
+		$words->setText($text);
336
+		$count = 0;
337
+		foreach ($words as $offset) {
338
+			if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
339
+				continue;
340
+			}
341
+			++$count;
342
+			if ($count != $limit) {
343
+				continue;
344
+			}
345
+			return $offset;
346
+		}
347
+		return strlen($text);
348
+	}
349 349
 
350
-    /**
351
-     * @param string $text
352
-     * @param int $limit
353
-     * @return int
354
-     */
355
-    protected function getExcerptSplit($text, $limit)
356
-    {
357
-        if (str_word_count($text, 0) > $limit) {
358
-            $words = array_keys(str_word_count($text, 2));
359
-            return $words[$limit];
360
-        }
361
-        return strlen($text);
362
-    }
350
+	/**
351
+	 * @param string $text
352
+	 * @param int $limit
353
+	 * @return int
354
+	 */
355
+	protected function getExcerptSplit($text, $limit)
356
+	{
357
+		if (str_word_count($text, 0) > $limit) {
358
+			$words = array_keys(str_word_count($text, 2));
359
+			return $words[$limit];
360
+		}
361
+		return strlen($text);
362
+	}
363 363
 
364
-    /**
365
-     * @param string $path
366
-     * @param mixed $fallback
367
-     * @return mixed
368
-     */
369
-    protected function getOption($path, $fallback = '')
370
-    {
371
-        if (array_key_exists($path, $this->options)) {
372
-            return $this->options[$path];
373
-        }
374
-        return $fallback;
375
-    }
364
+	/**
365
+	 * @param string $path
366
+	 * @param mixed $fallback
367
+	 * @return mixed
368
+	 */
369
+	protected function getOption($path, $fallback = '')
370
+	{
371
+		if (array_key_exists($path, $this->options)) {
372
+			return $this->options[$path];
373
+		}
374
+		return $fallback;
375
+	}
376 376
 
377
-    /**
378
-     * @param string $path
379
-     * @return bool
380
-     */
381
-    protected function isOptionEnabled($path)
382
-    {
383
-        return 'yes' == $this->getOption($path);
384
-    }
377
+	/**
378
+	 * @param string $path
379
+	 * @return bool
380
+	 */
381
+	protected function isOptionEnabled($path)
382
+	{
383
+		return 'yes' == $this->getOption($path);
384
+	}
385 385
 
386
-    /**
387
-     * @return void
388
-     */
389
-    protected function wrap(array &$renderedFields, Review $review)
390
-    {
391
-        $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
392
-        array_walk($renderedFields, function (&$value, $key) use ($review) {
393
-            $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
394
-            if (empty($value)) {
395
-                return;
396
-            }
397
-            $value = glsr(Builder::class)->div($value, [
398
-                'class' => 'glsr-review-'.$key,
399
-            ]);
400
-        });
401
-    }
386
+	/**
387
+	 * @return void
388
+	 */
389
+	protected function wrap(array &$renderedFields, Review $review)
390
+	{
391
+		$renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
392
+		array_walk($renderedFields, function (&$value, $key) use ($review) {
393
+			$value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
394
+			if (empty($value)) {
395
+				return;
396
+			}
397
+			$value = glsr(Builder::class)->div($value, [
398
+				'class' => 'glsr-review-'.$key,
399
+			]);
400
+		});
401
+	}
402 402
 }
Please login to merge, or discard this patch.
plugin/Database/QueryBuilder.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -12,190 +12,190 @@
 block discarded – undo
12 12
 
13 13
 class QueryBuilder
14 14
 {
15
-    /**
16
-     * Build a WP_Query meta_query/tax_query.
17
-     * @return array
18
-     */
19
-    public function buildQuery(array $keys = [], array $values = [])
20
-    {
21
-        $queries = [];
22
-        foreach ($keys as $key) {
23
-            if (!array_key_exists($key, $values)) {
24
-                continue;
25
-            }
26
-            $methodName = Helper::buildMethodName($key, __FUNCTION__);
27
-            if (!method_exists($this, $methodName)) {
28
-                continue;
29
-            }
30
-            $query = call_user_func([$this, $methodName], $values[$key]);
31
-            if (is_array($query)) {
32
-                $queries[] = $query;
33
-            }
34
-        }
35
-        return $queries;
36
-    }
15
+	/**
16
+	 * Build a WP_Query meta_query/tax_query.
17
+	 * @return array
18
+	 */
19
+	public function buildQuery(array $keys = [], array $values = [])
20
+	{
21
+		$queries = [];
22
+		foreach ($keys as $key) {
23
+			if (!array_key_exists($key, $values)) {
24
+				continue;
25
+			}
26
+			$methodName = Helper::buildMethodName($key, __FUNCTION__);
27
+			if (!method_exists($this, $methodName)) {
28
+				continue;
29
+			}
30
+			$query = call_user_func([$this, $methodName], $values[$key]);
31
+			if (is_array($query)) {
32
+				$queries[] = $query;
33
+			}
34
+		}
35
+		return $queries;
36
+	}
37 37
 
38
-    /**
39
-     * @return string
40
-     */
41
-    public function buildSqlLines(array $values, array $conditions)
42
-    {
43
-        $string = '';
44
-        $values = array_filter($values);
45
-        foreach ($conditions as $key => $value) {
46
-            if (!isset($values[$key])) {
47
-                continue;
48
-            }
49
-            $values[$key] = implode(',', (array) $values[$key]);
50
-            $string.= Str::contains($value, '%s')
51
-                ? sprintf($value, strval($values[$key]))
52
-                : $value;
53
-        }
54
-        return $string;
55
-    }
38
+	/**
39
+	 * @return string
40
+	 */
41
+	public function buildSqlLines(array $values, array $conditions)
42
+	{
43
+		$string = '';
44
+		$values = array_filter($values);
45
+		foreach ($conditions as $key => $value) {
46
+			if (!isset($values[$key])) {
47
+				continue;
48
+			}
49
+			$values[$key] = implode(',', (array) $values[$key]);
50
+			$string.= Str::contains($value, '%s')
51
+				? sprintf($value, strval($values[$key]))
52
+				: $value;
53
+		}
54
+		return $string;
55
+	}
56 56
 
57
-    /**
58
-     * Build a SQL 'OR' string from an array.
59
-     * @param string|array $values
60
-     * @param string $sprintfFormat
61
-     * @return string
62
-     */
63
-    public function buildSqlOr($values, $sprintfFormat)
64
-    {
65
-        if (!is_array($values)) {
66
-            $values = explode(',', $values);
67
-        }
68
-        $values = array_filter(array_map('trim', (array) $values));
69
-        $values = array_map(function ($value) use ($sprintfFormat) {
70
-            return sprintf($sprintfFormat, $value);
71
-        }, $values);
72
-        return implode(' OR ', $values);
73
-    }
57
+	/**
58
+	 * Build a SQL 'OR' string from an array.
59
+	 * @param string|array $values
60
+	 * @param string $sprintfFormat
61
+	 * @return string
62
+	 */
63
+	public function buildSqlOr($values, $sprintfFormat)
64
+	{
65
+		if (!is_array($values)) {
66
+			$values = explode(',', $values);
67
+		}
68
+		$values = array_filter(array_map('trim', (array) $values));
69
+		$values = array_map(function ($value) use ($sprintfFormat) {
70
+			return sprintf($sprintfFormat, $value);
71
+		}, $values);
72
+		return implode(' OR ', $values);
73
+	}
74 74
 
75
-    /**
76
-     * Search SQL filter for matching against post title only.
77
-     * @see http://wordpress.stackexchange.com/a/11826/1685
78
-     * @param string $search
79
-     * @return string
80
-     * @filter posts_search
81
-     */
82
-    public function filterSearchByTitle($search, WP_Query $query)
83
-    {
84
-        if (empty($search) || empty($query->get('search_terms'))) {
85
-            return $search;
86
-        }
87
-        global $wpdb;
88
-        $n = empty($query->get('exact'))
89
-            ? '%'
90
-            : '';
91
-        $search = [];
92
-        foreach ((array) $query->get('search_terms') as $term) {
93
-            $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n);
94
-        }
95
-        if (!is_user_logged_in()) {
96
-            $search[] = "{$wpdb->posts}.post_password = ''";
97
-        }
98
-        return ' AND '.implode(' AND ', $search);
99
-    }
75
+	/**
76
+	 * Search SQL filter for matching against post title only.
77
+	 * @see http://wordpress.stackexchange.com/a/11826/1685
78
+	 * @param string $search
79
+	 * @return string
80
+	 * @filter posts_search
81
+	 */
82
+	public function filterSearchByTitle($search, WP_Query $query)
83
+	{
84
+		if (empty($search) || empty($query->get('search_terms'))) {
85
+			return $search;
86
+		}
87
+		global $wpdb;
88
+		$n = empty($query->get('exact'))
89
+			? '%'
90
+			: '';
91
+		$search = [];
92
+		foreach ((array) $query->get('search_terms') as $term) {
93
+			$search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n);
94
+		}
95
+		if (!is_user_logged_in()) {
96
+			$search[] = "{$wpdb->posts}.post_password = ''";
97
+		}
98
+		return ' AND '.implode(' AND ', $search);
99
+	}
100 100
 
101
-    /**
102
-     * Get the current page number from the global query.
103
-     * @param bool $isEnabled
104
-     * @return int
105
-     */
106
-    public function getPaged($isEnabled = true)
107
-    {
108
-        return $isEnabled
109
-            ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR'))))
110
-            : 1;
111
-    }
101
+	/**
102
+	 * Get the current page number from the global query.
103
+	 * @param bool $isEnabled
104
+	 * @return int
105
+	 */
106
+	public function getPaged($isEnabled = true)
107
+	{
108
+		return $isEnabled
109
+			? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR'))))
110
+			: 1;
111
+	}
112 112
 
113
-    /**
114
-     * @param string $value
115
-     * @return void|array
116
-     */
117
-    protected function buildQueryAssignedTo($value)
118
-    {
119
-        if (!empty($value)) {
120
-            $postIds = Arr::convertStringToArray($value, 'is_numeric');
121
-            return [
122
-                'compare' => 'IN',
123
-                'key' => '_assigned_to',
124
-                'value' => glsr(Multilingual::class)->getPostIds($postIds),
125
-            ];
126
-        }
127
-    }
113
+	/**
114
+	 * @param string $value
115
+	 * @return void|array
116
+	 */
117
+	protected function buildQueryAssignedTo($value)
118
+	{
119
+		if (!empty($value)) {
120
+			$postIds = Arr::convertStringToArray($value, 'is_numeric');
121
+			return [
122
+				'compare' => 'IN',
123
+				'key' => '_assigned_to',
124
+				'value' => glsr(Multilingual::class)->getPostIds($postIds),
125
+			];
126
+		}
127
+	}
128 128
 
129
-    /**
130
-     * @param array $value
131
-     * @return void|array
132
-     */
133
-    protected function buildQueryCategory($value)
134
-    {
135
-        if (!empty($value)) {
136
-            return [
137
-                'field' => 'term_id',
138
-                'taxonomy' => Application::TAXONOMY,
139
-                'terms' => $value,
140
-            ];
141
-        }
142
-    }
129
+	/**
130
+	 * @param array $value
131
+	 * @return void|array
132
+	 */
133
+	protected function buildQueryCategory($value)
134
+	{
135
+		if (!empty($value)) {
136
+			return [
137
+				'field' => 'term_id',
138
+				'taxonomy' => Application::TAXONOMY,
139
+				'terms' => $value,
140
+			];
141
+		}
142
+	}
143 143
 
144
-    /**
145
-     * @param string $value
146
-     * @return void|array
147
-     */
148
-    protected function buildQueryEmail($value)
149
-    {
150
-        if (!empty($value)) {
151
-            return [
152
-                'key' => '_email',
153
-                'value' => $value,
154
-            ];
155
-        }
156
-    }
144
+	/**
145
+	 * @param string $value
146
+	 * @return void|array
147
+	 */
148
+	protected function buildQueryEmail($value)
149
+	{
150
+		if (!empty($value)) {
151
+			return [
152
+				'key' => '_email',
153
+				'value' => $value,
154
+			];
155
+		}
156
+	}
157 157
 
158
-    /**
159
-     * @param string $value
160
-     * @return void|array
161
-     */
162
-    protected function buildQueryIpAddress($value)
163
-    {
164
-        if (!empty($value)) {
165
-            return [
166
-                'key' => '_ip_address',
167
-                'value' => $value,
168
-            ];
169
-        }
170
-    }
158
+	/**
159
+	 * @param string $value
160
+	 * @return void|array
161
+	 */
162
+	protected function buildQueryIpAddress($value)
163
+	{
164
+		if (!empty($value)) {
165
+			return [
166
+				'key' => '_ip_address',
167
+				'value' => $value,
168
+			];
169
+		}
170
+	}
171 171
 
172
-    /**
173
-     * @param string $value
174
-     * @return void|array
175
-     */
176
-    protected function buildQueryRating($value)
177
-    {
178
-        if (is_numeric($value)
179
-            && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) {
180
-            return [
181
-                'compare' => '>=',
182
-                'key' => '_rating',
183
-                'value' => $value,
184
-            ];
185
-        }
186
-    }
172
+	/**
173
+	 * @param string $value
174
+	 * @return void|array
175
+	 */
176
+	protected function buildQueryRating($value)
177
+	{
178
+		if (is_numeric($value)
179
+			&& in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) {
180
+			return [
181
+				'compare' => '>=',
182
+				'key' => '_rating',
183
+				'value' => $value,
184
+			];
185
+		}
186
+	}
187 187
 
188
-    /**
189
-     * @param string $value
190
-     * @return void|array
191
-     */
192
-    protected function buildQueryType($value)
193
-    {
194
-        if (!in_array($value, ['', 'all'])) {
195
-            return [
196
-                'key' => '_review_type',
197
-                'value' => $value,
198
-            ];
199
-        }
200
-    }
188
+	/**
189
+	 * @param string $value
190
+	 * @return void|array
191
+	 */
192
+	protected function buildQueryType($value)
193
+	{
194
+		if (!in_array($value, ['', 'all'])) {
195
+			return [
196
+				'key' => '_review_type',
197
+				'value' => $value,
198
+			];
199
+		}
200
+	}
201 201
 }
Please login to merge, or discard this patch.
plugin/Database/CountsManager.php 1 patch
Indentation   +354 added lines, -354 removed lines patch added patch discarded remove patch
@@ -12,385 +12,385 @@
 block discarded – undo
12 12
 
13 13
 class CountsManager
14 14
 {
15
-    const LIMIT = 500;
16
-    const META_AVERAGE = '_glsr_average';
17
-    const META_COUNT = '_glsr_count';
18
-    const META_RANKING = '_glsr_ranking';
15
+	const LIMIT = 500;
16
+	const META_AVERAGE = '_glsr_average';
17
+	const META_COUNT = '_glsr_count';
18
+	const META_RANKING = '_glsr_ranking';
19 19
 
20
-    /**
21
-     * @return array
22
-     * @todo verify the additional type checks are needed
23
-     */
24
-    public function buildCounts(array $args = [])
25
-    {
26
-        $counts = [];
27
-        $query = $this->queryReviews($args);
28
-        while ($query) {
29
-            $types = array_keys(array_flip(glsr_array_column($query->reviews, 'type')));
30
-            $types = array_unique(array_merge(['local'], $types));
31
-            foreach ($types as $type) {
32
-                $type = $this->normalizeType($type);
33
-                if (isset($counts[$type])) {
34
-                    continue;
35
-            }
36
-                $counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
37
-            }
38
-            foreach ($query->reviews as $review) {
39
-                $type = $this->normalizeType($review->type);
40
-                ++$counts[$type][$review->rating];
41
-            }
42
-            $query = $query->has_more
43
-                ? $this->queryReviews($args, end($query->reviews)->ID)
44
-                : false;
45
-        }
46
-        return $counts;
47
-    }
20
+	/**
21
+	 * @return array
22
+	 * @todo verify the additional type checks are needed
23
+	 */
24
+	public function buildCounts(array $args = [])
25
+	{
26
+		$counts = [];
27
+		$query = $this->queryReviews($args);
28
+		while ($query) {
29
+			$types = array_keys(array_flip(glsr_array_column($query->reviews, 'type')));
30
+			$types = array_unique(array_merge(['local'], $types));
31
+			foreach ($types as $type) {
32
+				$type = $this->normalizeType($type);
33
+				if (isset($counts[$type])) {
34
+					continue;
35
+			}
36
+				$counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
37
+			}
38
+			foreach ($query->reviews as $review) {
39
+				$type = $this->normalizeType($review->type);
40
+				++$counts[$type][$review->rating];
41
+			}
42
+			$query = $query->has_more
43
+				? $this->queryReviews($args, end($query->reviews)->ID)
44
+				: false;
45
+		}
46
+		return $counts;
47
+	}
48 48
 
49
-    /**
50
-     * @param int $postId
51
-     * @return array
52
-     */
53
-    public function buildPostCounts($postId)
54
-    {
55
-        return $this->buildCounts(['post_ids' => [$postId]]);
56
-    }
49
+	/**
50
+	 * @param int $postId
51
+	 * @return array
52
+	 */
53
+	public function buildPostCounts($postId)
54
+	{
55
+		return $this->buildCounts(['post_ids' => [$postId]]);
56
+	}
57 57
 
58
-    /**
59
-     * @param int $termTaxonomyId
60
-     * @return array
61
-     */
62
-    public function buildTermCounts($termTaxonomyId)
63
-    {
64
-        return $this->buildCounts(['term_ids' => [$termTaxonomyId]]);
65
-    }
58
+	/**
59
+	 * @param int $termTaxonomyId
60
+	 * @return array
61
+	 */
62
+	public function buildTermCounts($termTaxonomyId)
63
+	{
64
+		return $this->buildCounts(['term_ids' => [$termTaxonomyId]]);
65
+	}
66 66
 
67
-    /**
68
-     * @return void
69
-     */
70
-    public function countAll()
71
-    {
72
-        $terms = glsr(Database::class)->getTerms(['fields' => 'all']);
73
-        foreach ($terms as $term) {
74
-            $this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id));
75
-        }
76
-        $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
77
-        foreach ($postIds as $postId) {
78
-            $this->setPostCounts($postId, $this->buildPostCounts($postId));
79
-        }
80
-        $this->setCounts($this->buildCounts());
81
-    }
67
+	/**
68
+	 * @return void
69
+	 */
70
+	public function countAll()
71
+	{
72
+		$terms = glsr(Database::class)->getTerms(['fields' => 'all']);
73
+		foreach ($terms as $term) {
74
+			$this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id));
75
+		}
76
+		$postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
77
+		foreach ($postIds as $postId) {
78
+			$this->setPostCounts($postId, $this->buildPostCounts($postId));
79
+		}
80
+		$this->setCounts($this->buildCounts());
81
+	}
82 82
 
83
-    /**
84
-     * @return void
85
-     */
86
-    public function decrease(Review $review)
87
-    {
88
-        $this->decreaseCounts($review);
89
-        $this->decreasePostCounts($review);
90
-        $this->decreaseTermCounts($review);
91
-    }
83
+	/**
84
+	 * @return void
85
+	 */
86
+	public function decrease(Review $review)
87
+	{
88
+		$this->decreaseCounts($review);
89
+		$this->decreasePostCounts($review);
90
+		$this->decreaseTermCounts($review);
91
+	}
92 92
 
93
-    /**
94
-     * @return void
95
-     */
96
-    public function decreaseCounts(Review $review)
97
-    {
98
-        $this->setCounts($this->decreaseRating(
99
-            $this->getCounts(),
100
-            $review->review_type,
101
-            $review->rating
102
-        ));
103
-    }
93
+	/**
94
+	 * @return void
95
+	 */
96
+	public function decreaseCounts(Review $review)
97
+	{
98
+		$this->setCounts($this->decreaseRating(
99
+			$this->getCounts(),
100
+			$review->review_type,
101
+			$review->rating
102
+		));
103
+	}
104 104
 
105
-    /**
106
-     * @return void
107
-     */
108
-    public function decreasePostCounts(Review $review)
109
-    {
110
-        if (empty($counts = $this->getPostCounts($review->assigned_to))) {
111
-            return;
112
-        }
113
-        $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
114
-        $this->setPostCounts($review->assigned_to, $counts);
115
-    }
105
+	/**
106
+	 * @return void
107
+	 */
108
+	public function decreasePostCounts(Review $review)
109
+	{
110
+		if (empty($counts = $this->getPostCounts($review->assigned_to))) {
111
+			return;
112
+		}
113
+		$counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
114
+		$this->setPostCounts($review->assigned_to, $counts);
115
+	}
116 116
 
117
-    /**
118
-     * @return void
119
-     */
120
-    public function decreaseTermCounts(Review $review)
121
-    {
122
-        foreach ($review->term_ids as $termId) {
123
-            if (empty($counts = $this->getTermCounts($termId))) {
124
-                continue;
125
-            }
126
-            $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
127
-            $this->setTermCounts($termId, $counts);
128
-        }
129
-    }
117
+	/**
118
+	 * @return void
119
+	 */
120
+	public function decreaseTermCounts(Review $review)
121
+	{
122
+		foreach ($review->term_ids as $termId) {
123
+			if (empty($counts = $this->getTermCounts($termId))) {
124
+				continue;
125
+			}
126
+			$counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
127
+			$this->setTermCounts($termId, $counts);
128
+		}
129
+	}
130 130
 
131
-    /**
132
-     * @return array
133
-     */
134
-    public function flatten(array $reviewCounts, array $args = [])
135
-    {
136
-        $counts = [];
137
-        array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
138
-            $counts[$index] = $num + intval(Arr::get($counts, $index, 0));
139
-        });
140
-        $args = wp_parse_args($args, [
141
-            'max' => glsr()->constant('MAX_RATING', Rating::class),
142
-            'min' => glsr()->constant('MIN_RATING', Rating::class),
143
-        ]);
144
-        foreach ($counts as $index => &$num) {
145
-            if ($index >= intval($args['min']) && $index <= intval($args['max'])) {
146
-                continue;
147
-            }
148
-            $num = 0;
149
-        }
150
-        return $counts;
151
-    }
131
+	/**
132
+	 * @return array
133
+	 */
134
+	public function flatten(array $reviewCounts, array $args = [])
135
+	{
136
+		$counts = [];
137
+		array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
138
+			$counts[$index] = $num + intval(Arr::get($counts, $index, 0));
139
+		});
140
+		$args = wp_parse_args($args, [
141
+			'max' => glsr()->constant('MAX_RATING', Rating::class),
142
+			'min' => glsr()->constant('MIN_RATING', Rating::class),
143
+		]);
144
+		foreach ($counts as $index => &$num) {
145
+			if ($index >= intval($args['min']) && $index <= intval($args['max'])) {
146
+				continue;
147
+			}
148
+			$num = 0;
149
+		}
150
+		return $counts;
151
+	}
152 152
 
153
-    /**
154
-     * @return array
155
-     */
156
-    public function get(array $args = [])
157
-    {
158
-        $args = $this->normalizeArgs($args);
159
-        $counts = [];
160
-        if ($this->isMixedCount($args)) {
161
-            $counts = [$this->buildCounts($args)]; // force query the database
162
-        } else {
163
-            foreach ($args['post_ids'] as $postId) {
164
-                $counts[] = $this->getPostCounts($postId);
165
-        }
166
-            foreach ($args['term_ids'] as $termId) {
167
-                $counts[] = $this->getTermCounts($termId);
168
-            }
169
-            if (empty($counts)) {
170
-                $counts[] = $this->getCounts();
171
-            }
172
-        }
173
-        return in_array($args['type'], ['', 'all'])
174
-            ? $this->normalize([$this->flatten($counts)])
175
-            : $this->normalize(glsr_array_column($counts, $args['type']));
176
-    }
153
+	/**
154
+	 * @return array
155
+	 */
156
+	public function get(array $args = [])
157
+	{
158
+		$args = $this->normalizeArgs($args);
159
+		$counts = [];
160
+		if ($this->isMixedCount($args)) {
161
+			$counts = [$this->buildCounts($args)]; // force query the database
162
+		} else {
163
+			foreach ($args['post_ids'] as $postId) {
164
+				$counts[] = $this->getPostCounts($postId);
165
+		}
166
+			foreach ($args['term_ids'] as $termId) {
167
+				$counts[] = $this->getTermCounts($termId);
168
+			}
169
+			if (empty($counts)) {
170
+				$counts[] = $this->getCounts();
171
+			}
172
+		}
173
+		return in_array($args['type'], ['', 'all'])
174
+			? $this->normalize([$this->flatten($counts)])
175
+			: $this->normalize(glsr_array_column($counts, $args['type']));
176
+	}
177 177
 
178
-    /**
179
-     * @return array
180
-     */
181
-    public function getCounts()
182
-    {
183
-        $counts = glsr(OptionManager::class)->get('counts', []);
184
-        if (!is_array($counts)) {
185
-            glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts);
186
-            return [];
187
-        }
188
-        return $counts;
189
-    }
178
+	/**
179
+	 * @return array
180
+	 */
181
+	public function getCounts()
182
+	{
183
+		$counts = glsr(OptionManager::class)->get('counts', []);
184
+		if (!is_array($counts)) {
185
+			glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts);
186
+			return [];
187
+		}
188
+		return $counts;
189
+	}
190 190
 
191
-    /**
192
-     * @param int $postId
193
-     * @return array
194
-     */
195
-    public function getPostCounts($postId)
196
-    {
197
-        return array_filter((array) get_post_meta($postId, static::META_COUNT, true));
198
-    }
191
+	/**
192
+	 * @param int $postId
193
+	 * @return array
194
+	 */
195
+	public function getPostCounts($postId)
196
+	{
197
+		return array_filter((array) get_post_meta($postId, static::META_COUNT, true));
198
+	}
199 199
 
200
-    /**
201
-     * @param int $termId
202
-     * @return array
203
-     */
204
-    public function getTermCounts($termId)
205
-    {
206
-        return array_filter((array) get_term_meta($termId, static::META_COUNT, true));
207
-    }
200
+	/**
201
+	 * @param int $termId
202
+	 * @return array
203
+	 */
204
+	public function getTermCounts($termId)
205
+	{
206
+		return array_filter((array) get_term_meta($termId, static::META_COUNT, true));
207
+	}
208 208
 
209
-    /**
210
-     * @return void
211
-     */
212
-    public function increase(Review $review)
213
-    {
214
-        $this->increaseCounts($review);
215
-        $this->increasePostCounts($review);
216
-        $this->increaseTermCounts($review);
217
-    }
209
+	/**
210
+	 * @return void
211
+	 */
212
+	public function increase(Review $review)
213
+	{
214
+		$this->increaseCounts($review);
215
+		$this->increasePostCounts($review);
216
+		$this->increaseTermCounts($review);
217
+	}
218 218
 
219
-    /**
220
-     * @return void
221
-     */
222
-    public function increaseCounts(Review $review)
223
-    {
224
-        if (empty($counts = $this->getCounts())) {
225
-            $counts = $this->buildCounts();
226
-        }
227
-        $this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating));
228
-    }
219
+	/**
220
+	 * @return void
221
+	 */
222
+	public function increaseCounts(Review $review)
223
+	{
224
+		if (empty($counts = $this->getCounts())) {
225
+			$counts = $this->buildCounts();
226
+		}
227
+		$this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating));
228
+	}
229 229
 
230
-    /**
231
-     * @return void
232
-     */
233
-    public function increasePostCounts(Review $review)
234
-    {
235
-        if (!(get_post($review->assigned_to) instanceof WP_Post)) {
236
-            return;
237
-        }
238
-        $counts = $this->getPostCounts($review->assigned_to);
239
-        $counts = empty($counts)
240
-            ? $this->buildPostCounts($review->assigned_to)
241
-            : $this->increaseRating($counts, $review->review_type, $review->rating);
242
-        $this->setPostCounts($review->assigned_to, $counts);
243
-    }
230
+	/**
231
+	 * @return void
232
+	 */
233
+	public function increasePostCounts(Review $review)
234
+	{
235
+		if (!(get_post($review->assigned_to) instanceof WP_Post)) {
236
+			return;
237
+		}
238
+		$counts = $this->getPostCounts($review->assigned_to);
239
+		$counts = empty($counts)
240
+			? $this->buildPostCounts($review->assigned_to)
241
+			: $this->increaseRating($counts, $review->review_type, $review->rating);
242
+		$this->setPostCounts($review->assigned_to, $counts);
243
+	}
244 244
 
245
-    /**
246
-     * @return void
247
-     */
248
-    public function increaseTermCounts(Review $review)
249
-    {
250
-        $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
251
-        foreach ($terms as $term) {
252
-            $counts = $this->getTermCounts($term['term_id']);
253
-            $counts = empty($counts)
254
-                ? $this->buildTermCounts($term['term_taxonomy_id'])
255
-                : $this->increaseRating($counts, $review->review_type, $review->rating);
256
-            $this->setTermCounts($term['term_id'], $counts);
257
-        }
258
-    }
245
+	/**
246
+	 * @return void
247
+	 */
248
+	public function increaseTermCounts(Review $review)
249
+	{
250
+		$terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
251
+		foreach ($terms as $term) {
252
+			$counts = $this->getTermCounts($term['term_id']);
253
+			$counts = empty($counts)
254
+				? $this->buildTermCounts($term['term_taxonomy_id'])
255
+				: $this->increaseRating($counts, $review->review_type, $review->rating);
256
+			$this->setTermCounts($term['term_id'], $counts);
257
+		}
258
+	}
259 259
 
260
-    /**
261
-     * @return void
262
-     */
263
-    public function setCounts(array $reviewCounts)
264
-    {
265
-        glsr(OptionManager::class)->set('counts', $reviewCounts);
266
-    }
260
+	/**
261
+	 * @return void
262
+	 */
263
+	public function setCounts(array $reviewCounts)
264
+	{
265
+		glsr(OptionManager::class)->set('counts', $reviewCounts);
266
+	}
267 267
 
268
-    /**
269
-     * @param int $postId
270
-     * @return void
271
-     */
272
-    public function setPostCounts($postId, array $reviewCounts)
273
-    {
274
-        $ratingCounts = $this->flatten($reviewCounts);
275
-        update_post_meta($postId, static::META_COUNT, $reviewCounts);
276
-        update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
277
-        update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
278
-    }
268
+	/**
269
+	 * @param int $postId
270
+	 * @return void
271
+	 */
272
+	public function setPostCounts($postId, array $reviewCounts)
273
+	{
274
+		$ratingCounts = $this->flatten($reviewCounts);
275
+		update_post_meta($postId, static::META_COUNT, $reviewCounts);
276
+		update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
277
+		update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
278
+	}
279 279
 
280
-    /**
281
-     * @param int $termId
282
-     * @return void
283
-     */
284
-    public function setTermCounts($termId, array $reviewCounts)
285
-    {
286
-        $term = get_term($termId, Application::TAXONOMY);
287
-        if (!isset($term->term_id)) {
288
-            return;
289
-        }
290
-        $ratingCounts = $this->flatten($reviewCounts);
291
-        update_term_meta($termId, static::META_COUNT, $reviewCounts);
292
-        update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
293
-        update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
294
-    }
280
+	/**
281
+	 * @param int $termId
282
+	 * @return void
283
+	 */
284
+	public function setTermCounts($termId, array $reviewCounts)
285
+	{
286
+		$term = get_term($termId, Application::TAXONOMY);
287
+		if (!isset($term->term_id)) {
288
+			return;
289
+		}
290
+		$ratingCounts = $this->flatten($reviewCounts);
291
+		update_term_meta($termId, static::META_COUNT, $reviewCounts);
292
+		update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
293
+		update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
294
+	}
295 295
 
296
-    /**
297
-     * @param string $type
298
-     * @param int $rating
299
-     * @return array
300
-     */
301
-    protected function decreaseRating(array $reviewCounts, $type, $rating)
302
-    {
303
-        if (isset($reviewCounts[$type][$rating])) {
304
-            $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
305
-        }
306
-        return $reviewCounts;
307
-    }
296
+	/**
297
+	 * @param string $type
298
+	 * @param int $rating
299
+	 * @return array
300
+	 */
301
+	protected function decreaseRating(array $reviewCounts, $type, $rating)
302
+	{
303
+		if (isset($reviewCounts[$type][$rating])) {
304
+			$reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
305
+		}
306
+		return $reviewCounts;
307
+	}
308 308
 
309
-    /**
310
-     * @param string $type
311
-     * @param int $rating
312
-     * @return array
313
-     */
314
-    protected function increaseRating(array $reviewCounts, $type, $rating)
315
-    {
316
-        if (!array_key_exists($type, glsr()->reviewTypes)) {
317
-            return $reviewCounts;
318
-        }
319
-        if (!array_key_exists($type, $reviewCounts)) {
320
-            $reviewCounts[$type] = [];
321
-        }
322
-        $reviewCounts = $this->normalize($reviewCounts);
323
-        $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
324
-        return $reviewCounts;
325
-    }
309
+	/**
310
+	 * @param string $type
311
+	 * @param int $rating
312
+	 * @return array
313
+	 */
314
+	protected function increaseRating(array $reviewCounts, $type, $rating)
315
+	{
316
+		if (!array_key_exists($type, glsr()->reviewTypes)) {
317
+			return $reviewCounts;
318
+		}
319
+		if (!array_key_exists($type, $reviewCounts)) {
320
+			$reviewCounts[$type] = [];
321
+		}
322
+		$reviewCounts = $this->normalize($reviewCounts);
323
+		$reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
324
+		return $reviewCounts;
325
+	}
326 326
 
327
-    /**
328
-     * @return bool
329
-     */
330
-    protected function isMixedCount(array $args)
331
-    {
332
-        return !empty($args['post_ids']) && !empty($args['term_ids']);
333
-    }
327
+	/**
328
+	 * @return bool
329
+	 */
330
+	protected function isMixedCount(array $args)
331
+	{
332
+		return !empty($args['post_ids']) && !empty($args['term_ids']);
333
+	}
334 334
 
335
-    /**
336
-     * @return array
337
-     */
338
-    protected function normalize(array $reviewCounts)
339
-    {
340
-        if (empty($reviewCounts)) {
341
-            $reviewCounts = [[]];
342
-        }
343
-        foreach ($reviewCounts as &$counts) {
344
-            foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) {
345
-                if (isset($counts[$index])) {
346
-                    continue;
347
-                }
348
-                $counts[$index] = 0;
349
-            }
350
-            ksort($counts);
351
-        }
352
-        return $reviewCounts;
353
-    }
335
+	/**
336
+	 * @return array
337
+	 */
338
+	protected function normalize(array $reviewCounts)
339
+	{
340
+		if (empty($reviewCounts)) {
341
+			$reviewCounts = [[]];
342
+		}
343
+		foreach ($reviewCounts as &$counts) {
344
+			foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) {
345
+				if (isset($counts[$index])) {
346
+					continue;
347
+				}
348
+				$counts[$index] = 0;
349
+			}
350
+			ksort($counts);
351
+		}
352
+		return $reviewCounts;
353
+	}
354 354
 
355
-    /**
356
-     * @return array
357
-     */
358
-    protected function normalizeArgs(array $args)
359
-    {
360
-        $args = wp_parse_args(array_filter($args), [
361
-            'post_ids' => [],
362
-            'term_ids' => [],
363
-            'type' => 'local',
364
-        ]);
365
-        $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']);
366
-        $args['type'] = $this->normalizeType($args['type']);
367
-        return $args;
368
-    }
355
+	/**
356
+	 * @return array
357
+	 */
358
+	protected function normalizeArgs(array $args)
359
+	{
360
+		$args = wp_parse_args(array_filter($args), [
361
+			'post_ids' => [],
362
+			'term_ids' => [],
363
+			'type' => 'local',
364
+		]);
365
+		$args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']);
366
+		$args['type'] = $this->normalizeType($args['type']);
367
+		return $args;
368
+	}
369 369
 
370
-    /**
371
-     * @param string $type
372
-     * @return string
373
-     */
374
-    protected function normalizeType($type)
375
-    {
376
-        return empty($type) || !is_string($type)
377
-            ? 'local'
378
-            : $type;
379
-    }
370
+	/**
371
+	 * @param string $type
372
+	 * @return string
373
+	 */
374
+	protected function normalizeType($type)
375
+	{
376
+		return empty($type) || !is_string($type)
377
+			? 'local'
378
+			: $type;
379
+	}
380 380
 
381
-    /**
382
-     * @param int $lastPostId
383
-     * @return object
384
-     */
385
-    protected function queryReviews(array $args = [], $lastPostId = 0)
386
-    {
387
-        $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
388
-        $hasMore = is_array($reviews)
389
-            ? count($reviews) == static::LIMIT
390
-            : false;
391
-        return (object) [
392
-            'has_more' => $hasMore,
393
-            'reviews' => $reviews,
394
-        ];
395
-    }
381
+	/**
382
+	 * @param int $lastPostId
383
+	 * @return object
384
+	 */
385
+	protected function queryReviews(array $args = [], $lastPostId = 0)
386
+	{
387
+		$reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
388
+		$hasMore = is_array($reviews)
389
+			? count($reviews) == static::LIMIT
390
+			: false;
391
+		return (object) [
392
+			'has_more' => $hasMore,
393
+			'reviews' => $reviews,
394
+		];
395
+	}
396 396
 }
Please login to merge, or discard this patch.
plugin/Modules/Multilingual/Wpml.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -7,83 +7,83 @@
 block discarded – undo
7 7
 
8 8
 class Wpml implements Contract
9 9
 {
10
-    public $pluginName = 'WPML';
11
-    public $supportedVersion = '3.3.5';
10
+	public $pluginName = 'WPML';
11
+	public $supportedVersion = '3.3.5';
12 12
 
13
-    /**
14
-     * {@inheritdoc}
15
-     */
16
-    public function getPost($postId)
17
-    {
18
-        $postId = trim($postId);
19
-        if (!is_numeric($postId)) {
20
-            return;
21
-        }
22
-        if ($this->isEnabled()) {
23
-            $postId = apply_filters('wpml_object_id', $postId, 'any', true);
24
-        }
25
-        return get_post(intval($postId));
26
-    }
13
+	/**
14
+	 * {@inheritdoc}
15
+	 */
16
+	public function getPost($postId)
17
+	{
18
+		$postId = trim($postId);
19
+		if (!is_numeric($postId)) {
20
+			return;
21
+		}
22
+		if ($this->isEnabled()) {
23
+			$postId = apply_filters('wpml_object_id', $postId, 'any', true);
24
+		}
25
+		return get_post(intval($postId));
26
+	}
27 27
 
28
-    /**
29
-     * {@inheritdoc}
30
-     */
31
-    public function getPostIds(array $postIds)
32
-    {
33
-        if (!$this->isEnabled()) {
34
-            return $postIds;
35
-        }
36
-        $newPostIds = [];
37
-        foreach ($this->cleanIds($postIds) as $postId) {
38
-            $postType = get_post_type($postId);
39
-            if (!$postType) {
40
-                continue;
41
-            }
42
-            $elementType = 'post_'.$postType;
43
-            $trid = apply_filters('wpml_element_trid', null, $postId, $elementType);
44
-            $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType);
45
-            if (!is_array($translations)) {
46
-                $translations = [];
47
-            }
48
-            $newPostIds = array_merge(
49
-                $newPostIds,
50
-                array_column($translations, 'element_id')
51
-            );
52
-        }
53
-        return $this->cleanIds($newPostIds);
54
-    }
28
+	/**
29
+	 * {@inheritdoc}
30
+	 */
31
+	public function getPostIds(array $postIds)
32
+	{
33
+		if (!$this->isEnabled()) {
34
+			return $postIds;
35
+		}
36
+		$newPostIds = [];
37
+		foreach ($this->cleanIds($postIds) as $postId) {
38
+			$postType = get_post_type($postId);
39
+			if (!$postType) {
40
+				continue;
41
+			}
42
+			$elementType = 'post_'.$postType;
43
+			$trid = apply_filters('wpml_element_trid', null, $postId, $elementType);
44
+			$translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType);
45
+			if (!is_array($translations)) {
46
+				$translations = [];
47
+			}
48
+			$newPostIds = array_merge(
49
+				$newPostIds,
50
+				array_column($translations, 'element_id')
51
+			);
52
+		}
53
+		return $this->cleanIds($newPostIds);
54
+	}
55 55
 
56
-    /**
57
-     * {@inheritdoc}
58
-     */
59
-    public function isActive()
60
-    {
61
-        return defined('ICL_SITEPRESS_VERSION');
62
-    }
56
+	/**
57
+	 * {@inheritdoc}
58
+	 */
59
+	public function isActive()
60
+	{
61
+		return defined('ICL_SITEPRESS_VERSION');
62
+	}
63 63
 
64
-    /**
65
-     * {@inheritdoc}
66
-     */
67
-    public function isEnabled()
68
-    {
69
-        return $this->isActive()
70
-            && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual');
71
-    }
64
+	/**
65
+	 * {@inheritdoc}
66
+	 */
67
+	public function isEnabled()
68
+	{
69
+		return $this->isActive()
70
+			&& 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual');
71
+	}
72 72
 
73
-    /**
74
-     * {@inheritdoc}
75
-     */
76
-    public function isSupported()
77
-    {
78
-        return $this->isActive()
79
-            && version_compare(ICL_SITEPRESS_VERSION, $this->supportedVersion, '>=');
80
-    }
73
+	/**
74
+	 * {@inheritdoc}
75
+	 */
76
+	public function isSupported()
77
+	{
78
+		return $this->isActive()
79
+			&& version_compare(ICL_SITEPRESS_VERSION, $this->supportedVersion, '>=');
80
+	}
81 81
 
82
-    /**
83
-     * @return array
84
-     */
85
-    protected function cleanIds(array $postIds)
86
-    {
87
-        return array_filter(array_unique($postIds));
88
-    }
82
+	/**
83
+	 * @return array
84
+	 */
85
+	protected function cleanIds(array $postIds)
86
+	{
87
+		return array_filter(array_unique($postIds));
88
+	}
89 89
 }
Please login to merge, or discard this patch.
plugin/Modules/Multilingual/Polylang.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -7,79 +7,79 @@
 block discarded – undo
7 7
 
8 8
 class Polylang implements Contract
9 9
 {
10
-    public $pluginName = 'Polylang';
11
-    public $supportedVersion = '2.3';
10
+	public $pluginName = 'Polylang';
11
+	public $supportedVersion = '2.3';
12 12
 
13
-    /**
14
-     * {@inheritdoc}
15
-     */
16
-    public function getPost($postId)
17
-    {
18
-        $postId = trim($postId);
19
-        if (!is_numeric($postId)) {
20
-            return;
21
-        }
22
-        if ($this->isEnabled()) {
23
-            $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID()));
24
-        }
25
-        if (!empty($polylangPostId)) {
26
-            $postId = $polylangPostId;
27
-        }
28
-        return get_post(intval($postId));
29
-    }
13
+	/**
14
+	 * {@inheritdoc}
15
+	 */
16
+	public function getPost($postId)
17
+	{
18
+		$postId = trim($postId);
19
+		if (!is_numeric($postId)) {
20
+			return;
21
+		}
22
+		if ($this->isEnabled()) {
23
+			$polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID()));
24
+		}
25
+		if (!empty($polylangPostId)) {
26
+			$postId = $polylangPostId;
27
+		}
28
+		return get_post(intval($postId));
29
+	}
30 30
 
31
-    /**
32
-     * {@inheritdoc}
33
-     */
34
-    public function getPostIds(array $postIds)
35
-    {
36
-        if (!$this->isEnabled()) {
37
-            return $postIds;
38
-        }
39
-        $newPostIds = [];
40
-        foreach ($this->cleanIds($postIds) as $postId) {
41
-            $newPostIds = array_merge(
42
-                $newPostIds,
43
-                array_values(pll_get_post_translations($postId))
44
-            );
45
-        }
46
-        return $this->cleanIds($newPostIds);
47
-    }
31
+	/**
32
+	 * {@inheritdoc}
33
+	 */
34
+	public function getPostIds(array $postIds)
35
+	{
36
+		if (!$this->isEnabled()) {
37
+			return $postIds;
38
+		}
39
+		$newPostIds = [];
40
+		foreach ($this->cleanIds($postIds) as $postId) {
41
+			$newPostIds = array_merge(
42
+				$newPostIds,
43
+				array_values(pll_get_post_translations($postId))
44
+			);
45
+		}
46
+		return $this->cleanIds($newPostIds);
47
+	}
48 48
 
49
-    /**
50
-     * {@inheritdoc}
51
-     */
52
-    public function isActive()
53
-    {
54
-        return function_exists('PLL')
55
-            && function_exists('pll_get_post')
56
-            && function_exists('pll_get_post_language')
57
-            && function_exists('pll_get_post_translations');
58
-    }
49
+	/**
50
+	 * {@inheritdoc}
51
+	 */
52
+	public function isActive()
53
+	{
54
+		return function_exists('PLL')
55
+			&& function_exists('pll_get_post')
56
+			&& function_exists('pll_get_post_language')
57
+			&& function_exists('pll_get_post_translations');
58
+	}
59 59
 
60
-    /**
61
-     * {@inheritdoc}
62
-     */
63
-    public function isEnabled()
64
-    {
65
-        return $this->isActive()
66
-            && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual');
67
-    }
60
+	/**
61
+	 * {@inheritdoc}
62
+	 */
63
+	public function isEnabled()
64
+	{
65
+		return $this->isActive()
66
+			&& 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual');
67
+	}
68 68
 
69
-    /**
70
-     * {@inheritdoc}
71
-     */
72
-    public function isSupported()
73
-    {
74
-        return defined('POLYLANG_VERSION')
75
-            && version_compare(POLYLANG_VERSION, $this->supportedVersion, '>=');
76
-    }
69
+	/**
70
+	 * {@inheritdoc}
71
+	 */
72
+	public function isSupported()
73
+	{
74
+		return defined('POLYLANG_VERSION')
75
+			&& version_compare(POLYLANG_VERSION, $this->supportedVersion, '>=');
76
+	}
77 77
 
78
-    /**
79
-     * @return array
80
-     */
81
-    protected function cleanIds(array $postIds)
82
-    {
83
-        return array_filter(array_unique($postIds));
84
-    }
78
+	/**
79
+	 * @return array
80
+	 */
81
+	protected function cleanIds(array $postIds)
82
+	{
83
+		return array_filter(array_unique($postIds));
84
+	}
85 85
 }
Please login to merge, or discard this patch.
plugin/Modules/Multilingual.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -7,87 +7,87 @@
 block discarded – undo
7 7
 
8 8
 class Multilingual implements Contract
9 9
 {
10
-    protected $integration;
10
+	protected $integration;
11 11
 
12
-    /**
13
-     * @param string $integration
14
-     * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml
15
-     */
16
-    public function getIntegration($integration = '')
17
-    {
18
-        if (empty($integration)) {
19
-            $integration = ucfirst(glsr(OptionManager::class)->get('settings.general.multilingual'));
20
-        }
21
-        $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.$integration;
22
-        if (class_exists($integrationClass)) {
23
-            return glsr($integrationClass);
24
-        }
25
-        return false;
26
-    }
12
+	/**
13
+	 * @param string $integration
14
+	 * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml
15
+	 */
16
+	public function getIntegration($integration = '')
17
+	{
18
+		if (empty($integration)) {
19
+			$integration = ucfirst(glsr(OptionManager::class)->get('settings.general.multilingual'));
20
+		}
21
+		$integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.$integration;
22
+		if (class_exists($integrationClass)) {
23
+			return glsr($integrationClass);
24
+		}
25
+		return false;
26
+	}
27 27
 
28
-    /**
29
-     * {@inheritdoc}
30
-     */
31
-    public function getPost($postId)
32
-    {
33
-        return $this->isIntegrated()
34
-            ? $this->integration->getPostIds($postId)
35
-            : $postId;
36
-    }
28
+	/**
29
+	 * {@inheritdoc}
30
+	 */
31
+	public function getPost($postId)
32
+	{
33
+		return $this->isIntegrated()
34
+			? $this->integration->getPostIds($postId)
35
+			: $postId;
36
+	}
37 37
 
38
-    /**
39
-     * {@inheritdoc}
40
-     */
41
-    public function getPostIds(array $postIds)
42
-    {
43
-        return $this->isIntegrated()
44
-            ? $this->integration->getPostIds($postIds)
45
-            : $postIds;
46
-    }
38
+	/**
39
+	 * {@inheritdoc}
40
+	 */
41
+	public function getPostIds(array $postIds)
42
+	{
43
+		return $this->isIntegrated()
44
+			? $this->integration->getPostIds($postIds)
45
+			: $postIds;
46
+	}
47 47
 
48
-    /**
49
-     * {@inheritdoc}
50
-     */
51
-    public function isActive()
52
-    {
53
-        return $this->isIntegrated()
54
-            ? $this->integration->isActive()
55
-            : false;
56
-    }
48
+	/**
49
+	 * {@inheritdoc}
50
+	 */
51
+	public function isActive()
52
+	{
53
+		return $this->isIntegrated()
54
+			? $this->integration->isActive()
55
+			: false;
56
+	}
57 57
 
58
-    /**
59
-     * {@inheritdoc}
60
-     */
61
-    public function isEnabled()
62
-    {
63
-        return $this->isIntegrated()
64
-            ? $this->integration->isEnabled()
65
-            : false;
66
-    }
58
+	/**
59
+	 * {@inheritdoc}
60
+	 */
61
+	public function isEnabled()
62
+	{
63
+		return $this->isIntegrated()
64
+			? $this->integration->isEnabled()
65
+			: false;
66
+	}
67 67
 
68
-    /**
69
-     * {@inheritdoc}
70
-     */
71
-    public function isSupported()
72
-    {
73
-        return $this->isIntegrated()
74
-            ? $this->integration->isSupported()
75
-            : false;
76
-    }
68
+	/**
69
+	 * {@inheritdoc}
70
+	 */
71
+	public function isSupported()
72
+	{
73
+		return $this->isIntegrated()
74
+			? $this->integration->isSupported()
75
+			: false;
76
+	}
77 77
 
78
-    /**
79
-     * return bool
80
-     */
81
-    protected function isIntegrated()
82
-    {
83
-        if (!empty($this->integration)) {
84
-            return true;
85
-        }
86
-        if ($integration = $this->getIntegration()) {
87
-            $this->integration = $integration;
88
-            return true;
89
-        }
90
-        glsr_log()->error($integrationClass.' does not exist');
91
-        return false;
92
-    }
78
+	/**
79
+	 * return bool
80
+	 */
81
+	protected function isIntegrated()
82
+	{
83
+		if (!empty($this->integration)) {
84
+			return true;
85
+		}
86
+		if ($integration = $this->getIntegration()) {
87
+			$this->integration = $integration;
88
+			return true;
89
+		}
90
+		glsr_log()->error($integrationClass.' does not exist');
91
+		return false;
92
+	}
93 93
 }
Please login to merge, or discard this patch.