@@ -8,86 +8,86 @@ |
||
8 | 8 | |
9 | 9 | class BlocksController extends Controller |
10 | 10 | { |
11 | - /** |
|
12 | - * @param array $categories |
|
13 | - * @return array |
|
14 | - * @filter block_categories |
|
15 | - */ |
|
16 | - public function filterBlockCategories($categories) |
|
17 | - { |
|
18 | - $categories = Arr::consolidateArray($categories); |
|
19 | - $categories[] = [ |
|
20 | - 'icon' => null, |
|
21 | - 'slug' => Application::ID, |
|
22 | - 'title' => glsr()->name, |
|
23 | - ]; |
|
24 | - return $categories; |
|
25 | - } |
|
11 | + /** |
|
12 | + * @param array $categories |
|
13 | + * @return array |
|
14 | + * @filter block_categories |
|
15 | + */ |
|
16 | + public function filterBlockCategories($categories) |
|
17 | + { |
|
18 | + $categories = Arr::consolidateArray($categories); |
|
19 | + $categories[] = [ |
|
20 | + 'icon' => null, |
|
21 | + 'slug' => Application::ID, |
|
22 | + 'title' => glsr()->name, |
|
23 | + ]; |
|
24 | + return $categories; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param array $editors |
|
29 | - * @param string $postType |
|
30 | - * @return array |
|
31 | - * @filter classic_editor_enabled_editors_for_post_type |
|
32 | - * @plugin classic-editor/classic-editor.php |
|
33 | - */ |
|
34 | - public function filterEnabledEditors($editors, $postType) |
|
35 | - { |
|
36 | - return Application::POST_TYPE == $postType |
|
37 | - ? ['block_editor' => false, 'classic_editor' => false] |
|
38 | - : $editors; |
|
39 | - } |
|
27 | + /** |
|
28 | + * @param array $editors |
|
29 | + * @param string $postType |
|
30 | + * @return array |
|
31 | + * @filter classic_editor_enabled_editors_for_post_type |
|
32 | + * @plugin classic-editor/classic-editor.php |
|
33 | + */ |
|
34 | + public function filterEnabledEditors($editors, $postType) |
|
35 | + { |
|
36 | + return Application::POST_TYPE == $postType |
|
37 | + ? ['block_editor' => false, 'classic_editor' => false] |
|
38 | + : $editors; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param bool $bool |
|
43 | - * @param string $postType |
|
44 | - * @return bool |
|
45 | - * @filter use_block_editor_for_post_type |
|
46 | - */ |
|
47 | - public function filterUseBlockEditor($bool, $postType) |
|
48 | - { |
|
49 | - return Application::POST_TYPE == $postType |
|
50 | - ? false |
|
51 | - : $bool; |
|
52 | - } |
|
41 | + /** |
|
42 | + * @param bool $bool |
|
43 | + * @param string $postType |
|
44 | + * @return bool |
|
45 | + * @filter use_block_editor_for_post_type |
|
46 | + */ |
|
47 | + public function filterUseBlockEditor($bool, $postType) |
|
48 | + { |
|
49 | + return Application::POST_TYPE == $postType |
|
50 | + ? false |
|
51 | + : $bool; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return void |
|
56 | - * @action init |
|
57 | - */ |
|
58 | - public function registerAssets() |
|
59 | - { |
|
60 | - wp_register_style( |
|
61 | - Application::ID.'/blocks', |
|
62 | - glsr()->url('assets/styles/'.Application::ID.'-blocks.css'), |
|
63 | - ['wp-edit-blocks'], |
|
64 | - glsr()->version |
|
65 | - ); |
|
66 | - wp_register_script( |
|
67 | - Application::ID.'/blocks', |
|
68 | - glsr()->url('assets/scripts/'.Application::ID.'-blocks.js'), |
|
69 | - ['wp-api-fetch', 'wp-blocks', 'wp-i18n', 'wp-editor', 'wp-element', Application::ID], |
|
70 | - glsr()->version |
|
71 | - ); |
|
72 | - } |
|
54 | + /** |
|
55 | + * @return void |
|
56 | + * @action init |
|
57 | + */ |
|
58 | + public function registerAssets() |
|
59 | + { |
|
60 | + wp_register_style( |
|
61 | + Application::ID.'/blocks', |
|
62 | + glsr()->url('assets/styles/'.Application::ID.'-blocks.css'), |
|
63 | + ['wp-edit-blocks'], |
|
64 | + glsr()->version |
|
65 | + ); |
|
66 | + wp_register_script( |
|
67 | + Application::ID.'/blocks', |
|
68 | + glsr()->url('assets/scripts/'.Application::ID.'-blocks.js'), |
|
69 | + ['wp-api-fetch', 'wp-blocks', 'wp-i18n', 'wp-editor', 'wp-element', Application::ID], |
|
70 | + glsr()->version |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return void |
|
76 | - * @action init |
|
77 | - */ |
|
78 | - public function registerBlocks() |
|
79 | - { |
|
80 | - $blocks = [ |
|
81 | - 'form', 'reviews', 'summary', |
|
82 | - ]; |
|
83 | - foreach ($blocks as $block) { |
|
84 | - $id = str_replace('_reviews', '', Application::ID.'_'.$block); |
|
85 | - $blockClass = Helper::buildClassName($id.'-block', 'Blocks'); |
|
86 | - if (!class_exists($blockClass)) { |
|
87 | - glsr_log()->error(sprintf('Class missing (%s)', $blockClass)); |
|
88 | - continue; |
|
89 | - } |
|
90 | - glsr($blockClass)->register($block); |
|
91 | - } |
|
92 | - } |
|
74 | + /** |
|
75 | + * @return void |
|
76 | + * @action init |
|
77 | + */ |
|
78 | + public function registerBlocks() |
|
79 | + { |
|
80 | + $blocks = [ |
|
81 | + 'form', 'reviews', 'summary', |
|
82 | + ]; |
|
83 | + foreach ($blocks as $block) { |
|
84 | + $id = str_replace('_reviews', '', Application::ID.'_'.$block); |
|
85 | + $blockClass = Helper::buildClassName($id.'-block', 'Blocks'); |
|
86 | + if (!class_exists($blockClass)) { |
|
87 | + glsr_log()->error(sprintf('Class missing (%s)', $blockClass)); |
|
88 | + continue; |
|
89 | + } |
|
90 | + glsr($blockClass)->register($block); |
|
91 | + } |
|
92 | + } |
|
93 | 93 | } |
@@ -12,168 +12,168 @@ |
||
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 | } |
@@ -12,190 +12,190 @@ |
||
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 | } |
@@ -14,52 +14,52 @@ |
||
14 | 14 | */ |
15 | 15 | class Multilingual |
16 | 16 | { |
17 | - protected $integration; |
|
17 | + protected $integration; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param string $method |
|
21 | - * @param array $args |
|
22 | - * @return |
|
23 | - */ |
|
24 | - public function __call($method, $args = []) |
|
25 | - { |
|
26 | - if ($this->isIntegrated() && method_exists($this->integration, $method)) { |
|
27 | - return call_user_func_array([$this->integration, $method], $args); |
|
28 | - } |
|
29 | - return Arr::get($args, 0, false); |
|
30 | - } |
|
19 | + /** |
|
20 | + * @param string $method |
|
21 | + * @param array $args |
|
22 | + * @return |
|
23 | + */ |
|
24 | + public function __call($method, $args = []) |
|
25 | + { |
|
26 | + if ($this->isIntegrated() && method_exists($this->integration, $method)) { |
|
27 | + return call_user_func_array([$this->integration, $method], $args); |
|
28 | + } |
|
29 | + return Arr::get($args, 0, false); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param string $integration |
|
34 | - * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml |
|
35 | - */ |
|
36 | - public function getIntegration($integration = '') |
|
37 | - { |
|
38 | - if (empty($integration)) { |
|
39 | - $integration = glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
40 | - } |
|
41 | - if (!empty($integration)) { |
|
42 | - $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.ucfirst($integration); |
|
43 | - if (class_exists($integrationClass)) { |
|
44 | - return glsr($integrationClass); |
|
45 | - } |
|
46 | - glsr_log()->error($integrationClass.' does not exist'); |
|
47 | - } |
|
48 | - return false; |
|
49 | - } |
|
32 | + /** |
|
33 | + * @param string $integration |
|
34 | + * @return false|\GeminiLabs\SiteReviews\Modules\Multilingual\Polylang|\GeminiLabs\SiteReviews\Modules\Multilingual\Wpml |
|
35 | + */ |
|
36 | + public function getIntegration($integration = '') |
|
37 | + { |
|
38 | + if (empty($integration)) { |
|
39 | + $integration = glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
40 | + } |
|
41 | + if (!empty($integration)) { |
|
42 | + $integrationClass = 'GeminiLabs\SiteReviews\Modules\Multilingual\\'.ucfirst($integration); |
|
43 | + if (class_exists($integrationClass)) { |
|
44 | + return glsr($integrationClass); |
|
45 | + } |
|
46 | + glsr_log()->error($integrationClass.' does not exist'); |
|
47 | + } |
|
48 | + return false; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * return bool |
|
53 | - */ |
|
54 | - public function isIntegrated() |
|
55 | - { |
|
56 | - if (!empty($this->integration)) { |
|
57 | - return true; |
|
58 | - } |
|
59 | - if ($integration = $this->getIntegration()) { |
|
60 | - $this->integration = $integration; |
|
61 | - return true; |
|
62 | - } |
|
63 | - return false; |
|
64 | - } |
|
51 | + /** |
|
52 | + * return bool |
|
53 | + */ |
|
54 | + public function isIntegrated() |
|
55 | + { |
|
56 | + if (!empty($this->integration)) { |
|
57 | + return true; |
|
58 | + } |
|
59 | + if ($integration = $this->getIntegration()) { |
|
60 | + $this->integration = $integration; |
|
61 | + return true; |
|
62 | + } |
|
63 | + return false; |
|
64 | + } |
|
65 | 65 | } |
@@ -8,105 +8,105 @@ |
||
8 | 8 | |
9 | 9 | class ReviewLimits |
10 | 10 | { |
11 | - protected $request; |
|
11 | + protected $request; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @return array |
|
15 | - * @filter site-reviews/get/reviews/query |
|
16 | - */ |
|
17 | - public function filterReviewsQuery(array $parameters, array $args) |
|
18 | - { |
|
19 | - if ($authorId = get_current_user_id()) { |
|
20 | - $parameters['author'] = $authorId; |
|
21 | - } |
|
22 | - $parameters['post_status'] = ['pending', 'publish']; |
|
23 | - return apply_filters('site-reviews/review-limits/query', $parameters, $args); |
|
24 | - } |
|
13 | + /** |
|
14 | + * @return array |
|
15 | + * @filter site-reviews/get/reviews/query |
|
16 | + */ |
|
17 | + public function filterReviewsQuery(array $parameters, array $args) |
|
18 | + { |
|
19 | + if ($authorId = get_current_user_id()) { |
|
20 | + $parameters['author'] = $authorId; |
|
21 | + } |
|
22 | + $parameters['post_status'] = ['pending', 'publish']; |
|
23 | + return apply_filters('site-reviews/review-limits/query', $parameters, $args); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public function hasReachedLimit(array $request = []) |
|
30 | - { |
|
31 | - $this->request = $request; |
|
32 | - $method = Helper::buildMethodName( |
|
33 | - glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy' |
|
34 | - ); |
|
35 | - return method_exists($this, $method) |
|
36 | - ? !call_user_func([$this, $method]) |
|
37 | - : false; |
|
38 | - } |
|
26 | + /** |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public function hasReachedLimit(array $request = []) |
|
30 | + { |
|
31 | + $this->request = $request; |
|
32 | + $method = Helper::buildMethodName( |
|
33 | + glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy' |
|
34 | + ); |
|
35 | + return method_exists($this, $method) |
|
36 | + ? !call_user_func([$this, $method]) |
|
37 | + : false; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $value |
|
42 | - * @param string $whitelist |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function isWhitelisted($value, $whitelist) |
|
46 | - { |
|
47 | - if (empty($whitelist)) { |
|
48 | - return false; |
|
49 | - } |
|
50 | - return in_array($value, array_filter(explode("\n", $whitelist), 'trim')); |
|
51 | - } |
|
40 | + /** |
|
41 | + * @param string $value |
|
42 | + * @param string $whitelist |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function isWhitelisted($value, $whitelist) |
|
46 | + { |
|
47 | + if (empty($whitelist)) { |
|
48 | + return false; |
|
49 | + } |
|
50 | + return in_array($value, array_filter(explode("\n", $whitelist), 'trim')); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param string $whitelistName |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - protected function getWhitelist($whitelistName) |
|
58 | - { |
|
59 | - return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName); |
|
60 | - } |
|
53 | + /** |
|
54 | + * @param string $whitelistName |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + protected function getWhitelist($whitelistName) |
|
58 | + { |
|
59 | + return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return bool |
|
64 | - */ |
|
65 | - protected function validate($key, $value, $addMetaQuery = true) |
|
66 | - { |
|
67 | - if ($this->isWhitelisted($value, $this->getWhitelist($key))) { |
|
68 | - return true; |
|
69 | - } |
|
70 | - add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2); |
|
71 | - $args = ['assigned_to' => Arr::get($this->request, 'assign_to')]; |
|
72 | - if ($addMetaQuery) { |
|
73 | - $args[$key] = $value; |
|
74 | - } |
|
75 | - $reviews = glsr_get_reviews($args); |
|
76 | - remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5); |
|
77 | - $result = 0 === count($reviews); |
|
78 | - $result = apply_filters('site-reviews/review-limits/validate', $result, $reviews, $this->request, $key); |
|
79 | - return wp_validate_boolean($result); |
|
80 | - } |
|
62 | + /** |
|
63 | + * @return bool |
|
64 | + */ |
|
65 | + protected function validate($key, $value, $addMetaQuery = true) |
|
66 | + { |
|
67 | + if ($this->isWhitelisted($value, $this->getWhitelist($key))) { |
|
68 | + return true; |
|
69 | + } |
|
70 | + add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2); |
|
71 | + $args = ['assigned_to' => Arr::get($this->request, 'assign_to')]; |
|
72 | + if ($addMetaQuery) { |
|
73 | + $args[$key] = $value; |
|
74 | + } |
|
75 | + $reviews = glsr_get_reviews($args); |
|
76 | + remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5); |
|
77 | + $result = 0 === count($reviews); |
|
78 | + $result = apply_filters('site-reviews/review-limits/validate', $result, $reviews, $this->request, $key); |
|
79 | + return wp_validate_boolean($result); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - protected function validateByEmail() |
|
86 | - { |
|
87 | - glsr_log()->debug('Email is: '.Arr::get($this->request, 'email')); |
|
88 | - return $this->validate('email', Arr::get($this->request, 'email')); |
|
89 | - } |
|
82 | + /** |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + protected function validateByEmail() |
|
86 | + { |
|
87 | + glsr_log()->debug('Email is: '.Arr::get($this->request, 'email')); |
|
88 | + return $this->validate('email', Arr::get($this->request, 'email')); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return bool |
|
93 | - */ |
|
94 | - protected function validateByIpAddress() |
|
95 | - { |
|
96 | - glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address')); |
|
97 | - return $this->validate('ip_address', Arr::get($this->request, 'ip_address')); |
|
98 | - } |
|
91 | + /** |
|
92 | + * @return bool |
|
93 | + */ |
|
94 | + protected function validateByIpAddress() |
|
95 | + { |
|
96 | + glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address')); |
|
97 | + return $this->validate('ip_address', Arr::get($this->request, 'ip_address')); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - protected function validateByUsername() |
|
104 | - { |
|
105 | - $user = wp_get_current_user(); |
|
106 | - if (!$user->exists()) { |
|
107 | - return true; |
|
108 | - } |
|
109 | - glsr_log()->debug('Username is: '.$user->user_login); |
|
110 | - return $this->validate('username', $user->user_login, false); |
|
111 | - } |
|
100 | + /** |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + protected function validateByUsername() |
|
104 | + { |
|
105 | + $user = wp_get_current_user(); |
|
106 | + if (!$user->exists()) { |
|
107 | + return true; |
|
108 | + } |
|
109 | + glsr_log()->debug('Username is: '.$user->user_login); |
|
110 | + return $this->validate('username', $user->user_login, false); |
|
111 | + } |
|
112 | 112 | } |
@@ -10,126 +10,126 @@ |
||
10 | 10 | */ |
11 | 11 | trait ValidationRules |
12 | 12 | { |
13 | - /** |
|
14 | - * Get the size of an attribute. |
|
15 | - * @param string $attribute |
|
16 | - * @param mixed $value |
|
17 | - * @return mixed |
|
18 | - */ |
|
19 | - abstract protected function getSize($attribute, $value); |
|
13 | + /** |
|
14 | + * Get the size of an attribute. |
|
15 | + * @param string $attribute |
|
16 | + * @param mixed $value |
|
17 | + * @return mixed |
|
18 | + */ |
|
19 | + abstract protected function getSize($attribute, $value); |
|
20 | 20 | |
21 | - /** |
|
22 | - * Replace all placeholders. |
|
23 | - * @param string $message |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - protected function replace($message, array $parameters) |
|
27 | - { |
|
28 | - if (!Str::contains($message, '%s')) { |
|
29 | - return $message; |
|
30 | - } |
|
31 | - return preg_replace_callback('/(%s)/', function () use (&$parameters) { |
|
32 | - foreach ($parameters as $key => $value) { |
|
33 | - return array_shift($parameters); |
|
34 | - } |
|
35 | - }, $message); |
|
36 | - } |
|
21 | + /** |
|
22 | + * Replace all placeholders. |
|
23 | + * @param string $message |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + protected function replace($message, array $parameters) |
|
27 | + { |
|
28 | + if (!Str::contains($message, '%s')) { |
|
29 | + return $message; |
|
30 | + } |
|
31 | + return preg_replace_callback('/(%s)/', function () use (&$parameters) { |
|
32 | + foreach ($parameters as $key => $value) { |
|
33 | + return array_shift($parameters); |
|
34 | + } |
|
35 | + }, $message); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Validate that an attribute was "accepted". |
|
40 | - * This validation rule implies the attribute is "required". |
|
41 | - * @param string $attribute |
|
42 | - * @param mixed $value |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function validateAccepted($value) |
|
46 | - { |
|
47 | - $acceptable = ['yes', 'on', '1', 1, true, 'true']; |
|
48 | - return $this->validateRequired($value) && in_array($value, $acceptable, true); |
|
49 | - } |
|
38 | + /** |
|
39 | + * Validate that an attribute was "accepted". |
|
40 | + * This validation rule implies the attribute is "required". |
|
41 | + * @param string $attribute |
|
42 | + * @param mixed $value |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function validateAccepted($value) |
|
46 | + { |
|
47 | + $acceptable = ['yes', 'on', '1', 1, true, 'true']; |
|
48 | + return $this->validateRequired($value) && in_array($value, $acceptable, true); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Validate the size of an attribute is between a set of values. |
|
53 | - * @param string $attribute |
|
54 | - * @param mixed $value |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public function validateBetween($value, $attribute, array $parameters) |
|
58 | - { |
|
59 | - $this->requireParameterCount(2, $parameters, 'between'); |
|
60 | - $size = $this->getSize($attribute, $value); |
|
61 | - return $size >= $parameters[0] && $size <= $parameters[1]; |
|
62 | - } |
|
51 | + /** |
|
52 | + * Validate the size of an attribute is between a set of values. |
|
53 | + * @param string $attribute |
|
54 | + * @param mixed $value |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public function validateBetween($value, $attribute, array $parameters) |
|
58 | + { |
|
59 | + $this->requireParameterCount(2, $parameters, 'between'); |
|
60 | + $size = $this->getSize($attribute, $value); |
|
61 | + return $size >= $parameters[0] && $size <= $parameters[1]; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Validate that an attribute is a valid e-mail address. |
|
66 | - * @param mixed $value |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function validateEmail($value) |
|
70 | - { |
|
71 | - return false !== filter_var($value, FILTER_VALIDATE_EMAIL); |
|
72 | - } |
|
64 | + /** |
|
65 | + * Validate that an attribute is a valid e-mail address. |
|
66 | + * @param mixed $value |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function validateEmail($value) |
|
70 | + { |
|
71 | + return false !== filter_var($value, FILTER_VALIDATE_EMAIL); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Validate the size of an attribute is less than a maximum value. |
|
76 | - * @param string $attribute |
|
77 | - * @param mixed $value |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - public function validateMax($value, $attribute, array $parameters) |
|
81 | - { |
|
82 | - $this->requireParameterCount(1, $parameters, 'max'); |
|
83 | - return $this->getSize($attribute, $value) <= $parameters[0]; |
|
84 | - } |
|
74 | + /** |
|
75 | + * Validate the size of an attribute is less than a maximum value. |
|
76 | + * @param string $attribute |
|
77 | + * @param mixed $value |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + public function validateMax($value, $attribute, array $parameters) |
|
81 | + { |
|
82 | + $this->requireParameterCount(1, $parameters, 'max'); |
|
83 | + return $this->getSize($attribute, $value) <= $parameters[0]; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Validate the size of an attribute is greater than a minimum value. |
|
88 | - * @param string $attribute |
|
89 | - * @param mixed $value |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function validateMin($value, $attribute, array $parameters) |
|
93 | - { |
|
94 | - $this->requireParameterCount(1, $parameters, 'min'); |
|
95 | - return $this->getSize($attribute, $value) >= $parameters[0]; |
|
96 | - } |
|
86 | + /** |
|
87 | + * Validate the size of an attribute is greater than a minimum value. |
|
88 | + * @param string $attribute |
|
89 | + * @param mixed $value |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function validateMin($value, $attribute, array $parameters) |
|
93 | + { |
|
94 | + $this->requireParameterCount(1, $parameters, 'min'); |
|
95 | + return $this->getSize($attribute, $value) >= $parameters[0]; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Validate that an attribute is numeric. |
|
100 | - * @param mixed $value |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - public function validateNumber($value) |
|
104 | - { |
|
105 | - return is_numeric($value); |
|
106 | - } |
|
98 | + /** |
|
99 | + * Validate that an attribute is numeric. |
|
100 | + * @param mixed $value |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + public function validateNumber($value) |
|
104 | + { |
|
105 | + return is_numeric($value); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Validate that a required attribute exists. |
|
110 | - * @param mixed $value |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function validateRequired($value) |
|
114 | - { |
|
115 | - return is_null($value) |
|
116 | - || (is_string($value) && in_array(trim($value), ['', '[]'])) |
|
117 | - || (is_array($value) && empty($value)) |
|
118 | - ? false |
|
119 | - : true; |
|
120 | - } |
|
108 | + /** |
|
109 | + * Validate that a required attribute exists. |
|
110 | + * @param mixed $value |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function validateRequired($value) |
|
114 | + { |
|
115 | + return is_null($value) |
|
116 | + || (is_string($value) && in_array(trim($value), ['', '[]'])) |
|
117 | + || (is_array($value) && empty($value)) |
|
118 | + ? false |
|
119 | + : true; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Require a certain number of parameters to be present. |
|
124 | - * @param int $count |
|
125 | - * @param string $rule |
|
126 | - * @return void |
|
127 | - * @throws InvalidArgumentException |
|
128 | - */ |
|
129 | - protected function requireParameterCount($count, array $parameters, $rule) |
|
130 | - { |
|
131 | - if (count($parameters) < $count) { |
|
132 | - throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters."); |
|
133 | - } |
|
134 | - } |
|
122 | + /** |
|
123 | + * Require a certain number of parameters to be present. |
|
124 | + * @param int $count |
|
125 | + * @param string $rule |
|
126 | + * @return void |
|
127 | + * @throws InvalidArgumentException |
|
128 | + */ |
|
129 | + protected function requireParameterCount($count, array $parameters, $rule) |
|
130 | + { |
|
131 | + if (count($parameters) < $count) { |
|
132 | + throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters."); |
|
133 | + } |
|
134 | + } |
|
135 | 135 | } |
@@ -4,29 +4,29 @@ |
||
4 | 4 | |
5 | 5 | interface MultilingualContract |
6 | 6 | { |
7 | - /** |
|
8 | - * @param int|string $postId |
|
9 | - * @return int |
|
10 | - */ |
|
11 | - public function getPostId($postId); |
|
7 | + /** |
|
8 | + * @param int|string $postId |
|
9 | + * @return int |
|
10 | + */ |
|
11 | + public function getPostId($postId); |
|
12 | 12 | |
13 | - /** |
|
14 | - * @return array |
|
15 | - */ |
|
16 | - public function getPostIds(array $postIds); |
|
13 | + /** |
|
14 | + * @return array |
|
15 | + */ |
|
16 | + public function getPostIds(array $postIds); |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return bool |
|
20 | - */ |
|
21 | - public function isActive(); |
|
18 | + /** |
|
19 | + * @return bool |
|
20 | + */ |
|
21 | + public function isActive(); |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return bool |
|
25 | - */ |
|
26 | - public function isEnabled(); |
|
23 | + /** |
|
24 | + * @return bool |
|
25 | + */ |
|
26 | + public function isEnabled(); |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return bool |
|
30 | - */ |
|
31 | - public function isSupported(); |
|
28 | + /** |
|
29 | + * @return bool |
|
30 | + */ |
|
31 | + public function isSupported(); |
|
32 | 32 | } |
@@ -20,17 +20,17 @@ |
||
20 | 20 | defined('WPINC') || die; |
21 | 21 | |
22 | 22 | if (!class_exists('GL_Plugin_Check_v4')) { |
23 | - require_once __DIR__.'/activate.php'; |
|
23 | + require_once __DIR__.'/activate.php'; |
|
24 | 24 | } |
25 | 25 | if ((new GL_Plugin_Check_v4(__FILE__))->canProceed()) { |
26 | - require_once __DIR__.'/autoload.php'; |
|
27 | - require_once __DIR__.'/compatibility.php'; |
|
28 | - require_once __DIR__.'/deprecated.php'; |
|
29 | - require_once __DIR__.'/helpers.php'; |
|
30 | - $app = new GeminiLabs\SiteReviews\Application(); |
|
31 | - $app->make('Provider')->register($app); |
|
32 | - register_activation_hook(__FILE__, array($app, 'activate')); |
|
33 | - register_deactivation_hook(__FILE__, array($app, 'deactivate')); |
|
34 | - register_shutdown_function(array($app, 'catchFatalError')); |
|
35 | - $app->init(); |
|
26 | + require_once __DIR__.'/autoload.php'; |
|
27 | + require_once __DIR__.'/compatibility.php'; |
|
28 | + require_once __DIR__.'/deprecated.php'; |
|
29 | + require_once __DIR__.'/helpers.php'; |
|
30 | + $app = new GeminiLabs\SiteReviews\Application(); |
|
31 | + $app->make('Provider')->register($app); |
|
32 | + register_activation_hook(__FILE__, array($app, 'activate')); |
|
33 | + register_deactivation_hook(__FILE__, array($app, 'deactivate')); |
|
34 | + register_shutdown_function(array($app, 'catchFatalError')); |
|
35 | + $app->init(); |
|
36 | 36 | } |
@@ -9,65 +9,65 @@ |
||
9 | 9 | |
10 | 10 | class Reviews extends ArrayObject |
11 | 11 | { |
12 | - /** |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - public $args; |
|
12 | + /** |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + public $args; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @var int |
|
19 | - */ |
|
20 | - public $max_num_pages; |
|
17 | + /** |
|
18 | + * @var int |
|
19 | + */ |
|
20 | + public $max_num_pages; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $reviews; |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $reviews; |
|
26 | 26 | |
27 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
28 | - { |
|
29 | - $this->args = $args; |
|
30 | - $this->max_num_pages = $maxPageCount; |
|
31 | - $this->reviews = $reviews; |
|
32 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
33 | - } |
|
27 | + public function __construct(array $reviews, $maxPageCount, array $args) |
|
28 | + { |
|
29 | + $this->args = $args; |
|
30 | + $this->max_num_pages = $maxPageCount; |
|
31 | + $this->reviews = $reviews; |
|
32 | + parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function __toString() |
|
39 | - { |
|
40 | - return (string) $this->build(); |
|
41 | - } |
|
35 | + /** |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function __toString() |
|
39 | + { |
|
40 | + return (string) $this->build(); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return ReviewsHtml |
|
45 | - */ |
|
46 | - public function build() |
|
47 | - { |
|
48 | - $args = glsr(SiteReviewsDefaults::class)->merge($this->args); |
|
49 | - return glsr(SiteReviewsPartial::class)->build($args, $this); |
|
50 | - } |
|
43 | + /** |
|
44 | + * @return ReviewsHtml |
|
45 | + */ |
|
46 | + public function build() |
|
47 | + { |
|
48 | + $args = glsr(SiteReviewsDefaults::class)->merge($this->args); |
|
49 | + return glsr(SiteReviewsPartial::class)->build($args, $this); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param mixed $key |
|
54 | - * @return mixed |
|
55 | - */ |
|
56 | - public function offsetGet($key) |
|
57 | - { |
|
58 | - if (array_key_exists($key, $this->reviews)) { |
|
59 | - return $this->reviews[$key]; |
|
60 | - } |
|
61 | - return property_exists($this, $key) |
|
62 | - ? $this->$key |
|
63 | - : null; |
|
64 | - } |
|
52 | + /** |
|
53 | + * @param mixed $key |
|
54 | + * @return mixed |
|
55 | + */ |
|
56 | + public function offsetGet($key) |
|
57 | + { |
|
58 | + if (array_key_exists($key, $this->reviews)) { |
|
59 | + return $this->reviews[$key]; |
|
60 | + } |
|
61 | + return property_exists($this, $key) |
|
62 | + ? $this->$key |
|
63 | + : null; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public function render() |
|
70 | - { |
|
71 | - echo $this->build(); |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public function render() |
|
70 | + { |
|
71 | + echo $this->build(); |
|
72 | + } |
|
73 | 73 | } |