@@ -11,165 +11,165 @@ |
||
11 | 11 | |
12 | 12 | class QueryBuilder |
13 | 13 | { |
14 | - /** |
|
15 | - * Build a WP_Query meta_query/tax_query. |
|
16 | - * @return array |
|
17 | - */ |
|
18 | - public function buildQuery(array $keys = [], array $values = []) |
|
19 | - { |
|
20 | - $queries = []; |
|
21 | - foreach ($keys as $key) { |
|
22 | - if (!array_key_exists($key, $values)) { |
|
23 | - continue; |
|
24 | - } |
|
25 | - $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
26 | - if (!method_exists($this, $methodName)) { |
|
27 | - continue; |
|
28 | - } |
|
29 | - $query = call_user_func([$this, $methodName], $values[$key]); |
|
30 | - if (is_array($query)) { |
|
31 | - $queries[] = $query; |
|
32 | - } |
|
33 | - } |
|
34 | - return $queries; |
|
35 | - } |
|
14 | + /** |
|
15 | + * Build a WP_Query meta_query/tax_query. |
|
16 | + * @return array |
|
17 | + */ |
|
18 | + public function buildQuery(array $keys = [], array $values = []) |
|
19 | + { |
|
20 | + $queries = []; |
|
21 | + foreach ($keys as $key) { |
|
22 | + if (!array_key_exists($key, $values)) { |
|
23 | + continue; |
|
24 | + } |
|
25 | + $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
26 | + if (!method_exists($this, $methodName)) { |
|
27 | + continue; |
|
28 | + } |
|
29 | + $query = call_user_func([$this, $methodName], $values[$key]); |
|
30 | + if (is_array($query)) { |
|
31 | + $queries[] = $query; |
|
32 | + } |
|
33 | + } |
|
34 | + return $queries; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function buildSqlLines(array $values, array $conditions) |
|
41 | - { |
|
42 | - $string = ''; |
|
43 | - $values = array_filter($values); |
|
44 | - foreach ($conditions as $key => $value) { |
|
45 | - if (!isset($values[$key])) { |
|
46 | - continue; |
|
47 | - } |
|
48 | - $values[$key] = implode(',', (array) $values[$key]); |
|
49 | - $string.= false !== strpos($value, '%s') |
|
50 | - ? sprintf($value, strval($values[$key])) |
|
51 | - : $value; |
|
52 | - } |
|
53 | - return $string; |
|
54 | - } |
|
37 | + /** |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function buildSqlLines(array $values, array $conditions) |
|
41 | + { |
|
42 | + $string = ''; |
|
43 | + $values = array_filter($values); |
|
44 | + foreach ($conditions as $key => $value) { |
|
45 | + if (!isset($values[$key])) { |
|
46 | + continue; |
|
47 | + } |
|
48 | + $values[$key] = implode(',', (array) $values[$key]); |
|
49 | + $string.= false !== strpos($value, '%s') |
|
50 | + ? sprintf($value, strval($values[$key])) |
|
51 | + : $value; |
|
52 | + } |
|
53 | + return $string; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Build a SQL 'OR' string from an array. |
|
58 | - * @param string|array $values |
|
59 | - * @param string $sprintfFormat |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function buildSqlOr($values, $sprintfFormat) |
|
63 | - { |
|
64 | - if (!is_array($values)) { |
|
65 | - $values = explode(',', $values); |
|
66 | - } |
|
67 | - $values = array_filter(array_map('trim', (array) $values)); |
|
68 | - $values = array_map(function ($value) use ($sprintfFormat) { |
|
69 | - return sprintf($sprintfFormat, $value); |
|
70 | - }, $values); |
|
71 | - return implode(' OR ', $values); |
|
72 | - } |
|
56 | + /** |
|
57 | + * Build a SQL 'OR' string from an array. |
|
58 | + * @param string|array $values |
|
59 | + * @param string $sprintfFormat |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function buildSqlOr($values, $sprintfFormat) |
|
63 | + { |
|
64 | + if (!is_array($values)) { |
|
65 | + $values = explode(',', $values); |
|
66 | + } |
|
67 | + $values = array_filter(array_map('trim', (array) $values)); |
|
68 | + $values = array_map(function ($value) use ($sprintfFormat) { |
|
69 | + return sprintf($sprintfFormat, $value); |
|
70 | + }, $values); |
|
71 | + return implode(' OR ', $values); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Search SQL filter for matching against post title only. |
|
76 | - * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
77 | - * @param string $search |
|
78 | - * @return string |
|
79 | - * @filter posts_search |
|
80 | - */ |
|
81 | - public function filterSearchByTitle($search, WP_Query $query) |
|
82 | - { |
|
83 | - if (empty($search) || empty($query->get('search_terms'))) { |
|
84 | - return $search; |
|
85 | - } |
|
86 | - global $wpdb; |
|
87 | - $n = empty($query->get('exact')) |
|
88 | - ? '%' |
|
89 | - : ''; |
|
90 | - $search = []; |
|
91 | - foreach ((array) $query->get('search_terms') as $term) { |
|
92 | - $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
93 | - } |
|
94 | - if (!is_user_logged_in()) { |
|
95 | - $search[] = "{$wpdb->posts}.post_password = ''"; |
|
96 | - } |
|
97 | - return ' AND '.implode(' AND ', $search); |
|
98 | - } |
|
74 | + /** |
|
75 | + * Search SQL filter for matching against post title only. |
|
76 | + * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
77 | + * @param string $search |
|
78 | + * @return string |
|
79 | + * @filter posts_search |
|
80 | + */ |
|
81 | + public function filterSearchByTitle($search, WP_Query $query) |
|
82 | + { |
|
83 | + if (empty($search) || empty($query->get('search_terms'))) { |
|
84 | + return $search; |
|
85 | + } |
|
86 | + global $wpdb; |
|
87 | + $n = empty($query->get('exact')) |
|
88 | + ? '%' |
|
89 | + : ''; |
|
90 | + $search = []; |
|
91 | + foreach ((array) $query->get('search_terms') as $term) { |
|
92 | + $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
93 | + } |
|
94 | + if (!is_user_logged_in()) { |
|
95 | + $search[] = "{$wpdb->posts}.post_password = ''"; |
|
96 | + } |
|
97 | + return ' AND '.implode(' AND ', $search); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Get the current page number from the global query. |
|
102 | - * @param bool $isEnabled |
|
103 | - * @return int |
|
104 | - */ |
|
105 | - public function getPaged($isEnabled = true) |
|
106 | - { |
|
107 | - $pagedQuery = !is_front_page() |
|
108 | - ? glsr()->constant('PAGED_QUERY_VAR') |
|
109 | - : 'page'; |
|
110 | - return $isEnabled |
|
111 | - ? max(1, intval(get_query_var($pagedQuery))) |
|
112 | - : 1; |
|
113 | - } |
|
100 | + /** |
|
101 | + * Get the current page number from the global query. |
|
102 | + * @param bool $isEnabled |
|
103 | + * @return int |
|
104 | + */ |
|
105 | + public function getPaged($isEnabled = true) |
|
106 | + { |
|
107 | + $pagedQuery = !is_front_page() |
|
108 | + ? glsr()->constant('PAGED_QUERY_VAR') |
|
109 | + : 'page'; |
|
110 | + return $isEnabled |
|
111 | + ? max(1, intval(get_query_var($pagedQuery))) |
|
112 | + : 1; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @param string $value |
|
117 | - * @return void|array |
|
118 | - */ |
|
119 | - protected function buildQueryAssignedTo($value) |
|
120 | - { |
|
121 | - if (!empty($value)) { |
|
122 | - $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
123 | - return [ |
|
124 | - 'compare' => 'IN', |
|
125 | - 'key' => '_assigned_to', |
|
126 | - 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
127 | - ]; |
|
128 | - } |
|
129 | - } |
|
115 | + /** |
|
116 | + * @param string $value |
|
117 | + * @return void|array |
|
118 | + */ |
|
119 | + protected function buildQueryAssignedTo($value) |
|
120 | + { |
|
121 | + if (!empty($value)) { |
|
122 | + $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
123 | + return [ |
|
124 | + 'compare' => 'IN', |
|
125 | + 'key' => '_assigned_to', |
|
126 | + 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
127 | + ]; |
|
128 | + } |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @param array $value |
|
133 | - * @return void|array |
|
134 | - */ |
|
135 | - protected function buildQueryCategory($value) |
|
136 | - { |
|
137 | - if (!empty($value)) { |
|
138 | - return [ |
|
139 | - 'field' => 'term_id', |
|
140 | - 'taxonomy' => Application::TAXONOMY, |
|
141 | - 'terms' => $value, |
|
142 | - ]; |
|
143 | - } |
|
144 | - } |
|
131 | + /** |
|
132 | + * @param array $value |
|
133 | + * @return void|array |
|
134 | + */ |
|
135 | + protected function buildQueryCategory($value) |
|
136 | + { |
|
137 | + if (!empty($value)) { |
|
138 | + return [ |
|
139 | + 'field' => 'term_id', |
|
140 | + 'taxonomy' => Application::TAXONOMY, |
|
141 | + 'terms' => $value, |
|
142 | + ]; |
|
143 | + } |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * @param string $value |
|
148 | - * @return void|array |
|
149 | - */ |
|
150 | - protected function buildQueryRating($value) |
|
151 | - { |
|
152 | - if (is_numeric($value) |
|
153 | - && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
154 | - return [ |
|
155 | - 'compare' => '>=', |
|
156 | - 'key' => '_rating', |
|
157 | - 'value' => $value, |
|
158 | - ]; |
|
159 | - } |
|
160 | - } |
|
146 | + /** |
|
147 | + * @param string $value |
|
148 | + * @return void|array |
|
149 | + */ |
|
150 | + protected function buildQueryRating($value) |
|
151 | + { |
|
152 | + if (is_numeric($value) |
|
153 | + && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
154 | + return [ |
|
155 | + 'compare' => '>=', |
|
156 | + 'key' => '_rating', |
|
157 | + 'value' => $value, |
|
158 | + ]; |
|
159 | + } |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * @param string $value |
|
164 | - * @return void|array |
|
165 | - */ |
|
166 | - protected function buildQueryType($value) |
|
167 | - { |
|
168 | - if (!in_array($value, ['', 'all'])) { |
|
169 | - return [ |
|
170 | - 'key' => '_review_type', |
|
171 | - 'value' => $value, |
|
172 | - ]; |
|
173 | - } |
|
174 | - } |
|
162 | + /** |
|
163 | + * @param string $value |
|
164 | + * @return void|array |
|
165 | + */ |
|
166 | + protected function buildQueryType($value) |
|
167 | + { |
|
168 | + if (!in_array($value, ['', 'all'])) { |
|
169 | + return [ |
|
170 | + 'key' => '_review_type', |
|
171 | + 'value' => $value, |
|
172 | + ]; |
|
173 | + } |
|
174 | + } |
|
175 | 175 | } |
@@ -15,19 +15,19 @@ discard block |
||
15 | 15 | * Build a WP_Query meta_query/tax_query. |
16 | 16 | * @return array |
17 | 17 | */ |
18 | - public function buildQuery(array $keys = [], array $values = []) |
|
18 | + public function buildQuery( array $keys = [], array $values = [] ) |
|
19 | 19 | { |
20 | 20 | $queries = []; |
21 | - foreach ($keys as $key) { |
|
22 | - if (!array_key_exists($key, $values)) { |
|
21 | + foreach( $keys as $key ) { |
|
22 | + if( !array_key_exists( $key, $values ) ) { |
|
23 | 23 | continue; |
24 | 24 | } |
25 | - $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
26 | - if (!method_exists($this, $methodName)) { |
|
25 | + $methodName = Helper::buildMethodName( $key, __FUNCTION__ ); |
|
26 | + if( !method_exists( $this, $methodName ) ) { |
|
27 | 27 | continue; |
28 | 28 | } |
29 | - $query = call_user_func([$this, $methodName], $values[$key]); |
|
30 | - if (is_array($query)) { |
|
29 | + $query = call_user_func( [$this, $methodName], $values[$key] ); |
|
30 | + if( is_array( $query ) ) { |
|
31 | 31 | $queries[] = $query; |
32 | 32 | } |
33 | 33 | } |
@@ -37,17 +37,17 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * @return string |
39 | 39 | */ |
40 | - public function buildSqlLines(array $values, array $conditions) |
|
40 | + public function buildSqlLines( array $values, array $conditions ) |
|
41 | 41 | { |
42 | 42 | $string = ''; |
43 | - $values = array_filter($values); |
|
44 | - foreach ($conditions as $key => $value) { |
|
45 | - if (!isset($values[$key])) { |
|
43 | + $values = array_filter( $values ); |
|
44 | + foreach( $conditions as $key => $value ) { |
|
45 | + if( !isset($values[$key]) ) { |
|
46 | 46 | continue; |
47 | 47 | } |
48 | - $values[$key] = implode(',', (array) $values[$key]); |
|
49 | - $string.= false !== strpos($value, '%s') |
|
50 | - ? sprintf($value, strval($values[$key])) |
|
48 | + $values[$key] = implode( ',', (array)$values[$key] ); |
|
49 | + $string .= false !== strpos( $value, '%s' ) |
|
50 | + ? sprintf( $value, strval( $values[$key] ) ) |
|
51 | 51 | : $value; |
52 | 52 | } |
53 | 53 | return $string; |
@@ -59,16 +59,16 @@ discard block |
||
59 | 59 | * @param string $sprintfFormat |
60 | 60 | * @return string |
61 | 61 | */ |
62 | - public function buildSqlOr($values, $sprintfFormat) |
|
62 | + public function buildSqlOr( $values, $sprintfFormat ) |
|
63 | 63 | { |
64 | - if (!is_array($values)) { |
|
65 | - $values = explode(',', $values); |
|
64 | + if( !is_array( $values ) ) { |
|
65 | + $values = explode( ',', $values ); |
|
66 | 66 | } |
67 | - $values = array_filter(array_map('trim', (array) $values)); |
|
68 | - $values = array_map(function ($value) use ($sprintfFormat) { |
|
69 | - return sprintf($sprintfFormat, $value); |
|
70 | - }, $values); |
|
71 | - return implode(' OR ', $values); |
|
67 | + $values = array_filter( array_map( 'trim', (array)$values ) ); |
|
68 | + $values = array_map( function( $value ) use ($sprintfFormat) { |
|
69 | + return sprintf( $sprintfFormat, $value ); |
|
70 | + }, $values ); |
|
71 | + return implode( ' OR ', $values ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -78,23 +78,23 @@ discard block |
||
78 | 78 | * @return string |
79 | 79 | * @filter posts_search |
80 | 80 | */ |
81 | - public function filterSearchByTitle($search, WP_Query $query) |
|
81 | + public function filterSearchByTitle( $search, WP_Query $query ) |
|
82 | 82 | { |
83 | - if (empty($search) || empty($query->get('search_terms'))) { |
|
83 | + if( empty($search) || empty($query->get( 'search_terms' )) ) { |
|
84 | 84 | return $search; |
85 | 85 | } |
86 | 86 | global $wpdb; |
87 | - $n = empty($query->get('exact')) |
|
87 | + $n = empty($query->get( 'exact' )) |
|
88 | 88 | ? '%' |
89 | 89 | : ''; |
90 | 90 | $search = []; |
91 | - foreach ((array) $query->get('search_terms') as $term) { |
|
92 | - $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
91 | + foreach( (array)$query->get( 'search_terms' ) as $term ) { |
|
92 | + $search[] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like( $term ).$n ); |
|
93 | 93 | } |
94 | - if (!is_user_logged_in()) { |
|
94 | + if( !is_user_logged_in() ) { |
|
95 | 95 | $search[] = "{$wpdb->posts}.post_password = ''"; |
96 | 96 | } |
97 | - return ' AND '.implode(' AND ', $search); |
|
97 | + return ' AND '.implode( ' AND ', $search ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | * @param bool $isEnabled |
103 | 103 | * @return int |
104 | 104 | */ |
105 | - public function getPaged($isEnabled = true) |
|
105 | + public function getPaged( $isEnabled = true ) |
|
106 | 106 | { |
107 | 107 | $pagedQuery = !is_front_page() |
108 | - ? glsr()->constant('PAGED_QUERY_VAR') |
|
108 | + ? glsr()->constant( 'PAGED_QUERY_VAR' ) |
|
109 | 109 | : 'page'; |
110 | 110 | return $isEnabled |
111 | - ? max(1, intval(get_query_var($pagedQuery))) |
|
111 | + ? max( 1, intval( get_query_var( $pagedQuery ) ) ) |
|
112 | 112 | : 1; |
113 | 113 | } |
114 | 114 | |
@@ -116,14 +116,14 @@ discard block |
||
116 | 116 | * @param string $value |
117 | 117 | * @return void|array |
118 | 118 | */ |
119 | - protected function buildQueryAssignedTo($value) |
|
119 | + protected function buildQueryAssignedTo( $value ) |
|
120 | 120 | { |
121 | - if (!empty($value)) { |
|
122 | - $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
121 | + if( !empty($value) ) { |
|
122 | + $postIds = Arr::convertStringToArray( $value, 'is_numeric' ); |
|
123 | 123 | return [ |
124 | 124 | 'compare' => 'IN', |
125 | 125 | 'key' => '_assigned_to', |
126 | - 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
126 | + 'value' => glsr( Polylang::class )->getPostIds( $postIds ), |
|
127 | 127 | ]; |
128 | 128 | } |
129 | 129 | } |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * @param array $value |
133 | 133 | * @return void|array |
134 | 134 | */ |
135 | - protected function buildQueryCategory($value) |
|
135 | + protected function buildQueryCategory( $value ) |
|
136 | 136 | { |
137 | - if (!empty($value)) { |
|
137 | + if( !empty($value) ) { |
|
138 | 138 | return [ |
139 | 139 | 'field' => 'term_id', |
140 | 140 | 'taxonomy' => Application::TAXONOMY, |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | * @param string $value |
148 | 148 | * @return void|array |
149 | 149 | */ |
150 | - protected function buildQueryRating($value) |
|
150 | + protected function buildQueryRating( $value ) |
|
151 | 151 | { |
152 | - if (is_numeric($value) |
|
153 | - && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
152 | + if( is_numeric( $value ) |
|
153 | + && in_array( intval( $value ), range( 1, glsr()->constant( 'MAX_RATING', Rating::class ) ) ) ) { |
|
154 | 154 | return [ |
155 | 155 | 'compare' => '>=', |
156 | 156 | 'key' => '_rating', |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * @param string $value |
164 | 164 | * @return void|array |
165 | 165 | */ |
166 | - protected function buildQueryType($value) |
|
166 | + protected function buildQueryType( $value ) |
|
167 | 167 | { |
168 | - if (!in_array($value, ['', 'all'])) { |
|
168 | + if( !in_array( $value, ['', 'all'] ) ) { |
|
169 | 169 | return [ |
170 | 170 | 'key' => '_review_type', |
171 | 171 | 'value' => $value, |
@@ -9,153 +9,153 @@ |
||
9 | 9 | |
10 | 10 | class OptionManager |
11 | 11 | { |
12 | - /** |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - protected $options; |
|
12 | + /** |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + protected $options; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public static function databaseKey($version = null) |
|
21 | - { |
|
22 | - if (null === $version) { |
|
23 | - $version = explode('.', glsr()->version); |
|
24 | - $version = array_shift($version); |
|
25 | - } |
|
26 | - return Str::snakeCase( |
|
27 | - Application::ID.'-v'.intval($version) |
|
28 | - ); |
|
29 | - } |
|
17 | + /** |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public static function databaseKey($version = null) |
|
21 | + { |
|
22 | + if (null === $version) { |
|
23 | + $version = explode('.', glsr()->version); |
|
24 | + $version = array_shift($version); |
|
25 | + } |
|
26 | + return Str::snakeCase( |
|
27 | + Application::ID.'-v'.intval($version) |
|
28 | + ); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - public function all() |
|
35 | - { |
|
36 | - if (empty($this->options)) { |
|
37 | - $this->reset(); |
|
38 | - } |
|
39 | - return $this->options; |
|
40 | - } |
|
31 | + /** |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + public function all() |
|
35 | + { |
|
36 | + if (empty($this->options)) { |
|
37 | + $this->reset(); |
|
38 | + } |
|
39 | + return $this->options; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param string $path |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - public function delete($path) |
|
47 | - { |
|
48 | - $keys = explode('.', $path); |
|
49 | - $last = array_pop($keys); |
|
50 | - $options = $this->all(); |
|
51 | - $pointer = &$options; |
|
52 | - foreach ($keys as $key) { |
|
53 | - if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
54 | - continue; |
|
55 | - } |
|
56 | - $pointer = &$pointer[$key]; |
|
57 | - } |
|
58 | - unset($pointer[$last]); |
|
59 | - return $this->set($options); |
|
60 | - } |
|
42 | + /** |
|
43 | + * @param string $path |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + public function delete($path) |
|
47 | + { |
|
48 | + $keys = explode('.', $path); |
|
49 | + $last = array_pop($keys); |
|
50 | + $options = $this->all(); |
|
51 | + $pointer = &$options; |
|
52 | + foreach ($keys as $key) { |
|
53 | + if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
54 | + continue; |
|
55 | + } |
|
56 | + $pointer = &$pointer[$key]; |
|
57 | + } |
|
58 | + unset($pointer[$last]); |
|
59 | + return $this->set($options); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param string $path |
|
64 | - * @param mixed $fallback |
|
65 | - * @param string $cast |
|
66 | - * @return mixed |
|
67 | - */ |
|
68 | - public function get($path = '', $fallback = '', $cast = '') |
|
69 | - { |
|
70 | - $result = Arr::get($this->all(), $path, $fallback); |
|
71 | - return Helper::castTo($cast, $result); |
|
72 | - } |
|
62 | + /** |
|
63 | + * @param string $path |
|
64 | + * @param mixed $fallback |
|
65 | + * @param string $cast |
|
66 | + * @return mixed |
|
67 | + */ |
|
68 | + public function get($path = '', $fallback = '', $cast = '') |
|
69 | + { |
|
70 | + $result = Arr::get($this->all(), $path, $fallback); |
|
71 | + return Helper::castTo($cast, $result); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $path |
|
76 | - * @return bool |
|
77 | - */ |
|
78 | - public function getBool($path) |
|
79 | - { |
|
80 | - return Helper::castTo('bool', $this->get($path)); |
|
81 | - } |
|
74 | + /** |
|
75 | + * @param string $path |
|
76 | + * @return bool |
|
77 | + */ |
|
78 | + public function getBool($path) |
|
79 | + { |
|
80 | + return Helper::castTo('bool', $this->get($path)); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param string $path |
|
85 | - * @param mixed $fallback |
|
86 | - * @param string $cast |
|
87 | - * @return mixed |
|
88 | - */ |
|
89 | - public function getWP($path, $fallback = '', $cast = '') |
|
90 | - { |
|
91 | - $option = get_option($path, $fallback); |
|
92 | - if (empty($option)) { |
|
93 | - $option = $fallback; |
|
94 | - } |
|
95 | - return Helper::castTo($cast, $option); |
|
96 | - } |
|
83 | + /** |
|
84 | + * @param string $path |
|
85 | + * @param mixed $fallback |
|
86 | + * @param string $cast |
|
87 | + * @return mixed |
|
88 | + */ |
|
89 | + public function getWP($path, $fallback = '', $cast = '') |
|
90 | + { |
|
91 | + $option = get_option($path, $fallback); |
|
92 | + if (empty($option)) { |
|
93 | + $option = $fallback; |
|
94 | + } |
|
95 | + return Helper::castTo($cast, $option); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * @return string |
|
100 | - */ |
|
101 | - public function json() |
|
102 | - { |
|
103 | - return json_encode($this->all()); |
|
104 | - } |
|
98 | + /** |
|
99 | + * @return string |
|
100 | + */ |
|
101 | + public function json() |
|
102 | + { |
|
103 | + return json_encode($this->all()); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @return array |
|
108 | - */ |
|
109 | - public function normalize(array $options = []) |
|
110 | - { |
|
111 | - $options = wp_parse_args( |
|
112 | - Arr::flattenArray($options), |
|
113 | - glsr(DefaultsManager::class)->defaults() |
|
114 | - ); |
|
115 | - array_walk($options, function (&$value) { |
|
116 | - if (!is_string($value)) { |
|
117 | - return; |
|
118 | - } |
|
119 | - $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
120 | - }); |
|
121 | - return Arr::convertDotNotationArray($options); |
|
122 | - } |
|
106 | + /** |
|
107 | + * @return array |
|
108 | + */ |
|
109 | + public function normalize(array $options = []) |
|
110 | + { |
|
111 | + $options = wp_parse_args( |
|
112 | + Arr::flattenArray($options), |
|
113 | + glsr(DefaultsManager::class)->defaults() |
|
114 | + ); |
|
115 | + array_walk($options, function (&$value) { |
|
116 | + if (!is_string($value)) { |
|
117 | + return; |
|
118 | + } |
|
119 | + $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
120 | + }); |
|
121 | + return Arr::convertDotNotationArray($options); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * @return bool |
|
126 | - */ |
|
127 | - public function isRecaptchaEnabled() |
|
128 | - { |
|
129 | - $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
130 | - return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
|
131 | - } |
|
124 | + /** |
|
125 | + * @return bool |
|
126 | + */ |
|
127 | + public function isRecaptchaEnabled() |
|
128 | + { |
|
129 | + $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
130 | + return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - public function reset() |
|
137 | - { |
|
138 | - $options = $this->getWP(static::databaseKey(), []); |
|
139 | - if (!is_array($options) || empty($options)) { |
|
140 | - delete_option(static::databaseKey()); |
|
141 | - $options = glsr()->defaults ?: []; |
|
142 | - } |
|
143 | - $this->options = $options; |
|
144 | - } |
|
133 | + /** |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + public function reset() |
|
137 | + { |
|
138 | + $options = $this->getWP(static::databaseKey(), []); |
|
139 | + if (!is_array($options) || empty($options)) { |
|
140 | + delete_option(static::databaseKey()); |
|
141 | + $options = glsr()->defaults ?: []; |
|
142 | + } |
|
143 | + $this->options = $options; |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * @param string|array $pathOrOptions |
|
148 | - * @param mixed $value |
|
149 | - * @return bool |
|
150 | - */ |
|
151 | - public function set($pathOrOptions, $value = '') |
|
152 | - { |
|
153 | - if (is_string($pathOrOptions)) { |
|
154 | - $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value); |
|
155 | - } |
|
156 | - if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
157 | - $this->reset(); |
|
158 | - } |
|
159 | - return $result; |
|
160 | - } |
|
146 | + /** |
|
147 | + * @param string|array $pathOrOptions |
|
148 | + * @param mixed $value |
|
149 | + * @return bool |
|
150 | + */ |
|
151 | + public function set($pathOrOptions, $value = '') |
|
152 | + { |
|
153 | + if (is_string($pathOrOptions)) { |
|
154 | + $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value); |
|
155 | + } |
|
156 | + if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
157 | + $this->reset(); |
|
158 | + } |
|
159 | + return $result; |
|
160 | + } |
|
161 | 161 | } |
@@ -17,14 +17,14 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @return string |
19 | 19 | */ |
20 | - public static function databaseKey($version = null) |
|
20 | + public static function databaseKey( $version = null ) |
|
21 | 21 | { |
22 | - if (null === $version) { |
|
23 | - $version = explode('.', glsr()->version); |
|
24 | - $version = array_shift($version); |
|
22 | + if( null === $version ) { |
|
23 | + $version = explode( '.', glsr()->version ); |
|
24 | + $version = array_shift( $version ); |
|
25 | 25 | } |
26 | 26 | return Str::snakeCase( |
27 | - Application::ID.'-v'.intval($version) |
|
27 | + Application::ID.'-v'.intval( $version ) |
|
28 | 28 | ); |
29 | 29 | } |
30 | 30 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public function all() |
35 | 35 | { |
36 | - if (empty($this->options)) { |
|
36 | + if( empty($this->options) ) { |
|
37 | 37 | $this->reset(); |
38 | 38 | } |
39 | 39 | return $this->options; |
@@ -43,20 +43,20 @@ discard block |
||
43 | 43 | * @param string $path |
44 | 44 | * @return bool |
45 | 45 | */ |
46 | - public function delete($path) |
|
46 | + public function delete( $path ) |
|
47 | 47 | { |
48 | - $keys = explode('.', $path); |
|
49 | - $last = array_pop($keys); |
|
48 | + $keys = explode( '.', $path ); |
|
49 | + $last = array_pop( $keys ); |
|
50 | 50 | $options = $this->all(); |
51 | 51 | $pointer = &$options; |
52 | - foreach ($keys as $key) { |
|
53 | - if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
52 | + foreach( $keys as $key ) { |
|
53 | + if( !isset($pointer[$key]) || !is_array( $pointer[$key] ) ) { |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | $pointer = &$pointer[$key]; |
57 | 57 | } |
58 | 58 | unset($pointer[$last]); |
59 | - return $this->set($options); |
|
59 | + return $this->set( $options ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -65,19 +65,19 @@ discard block |
||
65 | 65 | * @param string $cast |
66 | 66 | * @return mixed |
67 | 67 | */ |
68 | - public function get($path = '', $fallback = '', $cast = '') |
|
68 | + public function get( $path = '', $fallback = '', $cast = '' ) |
|
69 | 69 | { |
70 | - $result = Arr::get($this->all(), $path, $fallback); |
|
71 | - return Helper::castTo($cast, $result); |
|
70 | + $result = Arr::get( $this->all(), $path, $fallback ); |
|
71 | + return Helper::castTo( $cast, $result ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @param string $path |
76 | 76 | * @return bool |
77 | 77 | */ |
78 | - public function getBool($path) |
|
78 | + public function getBool( $path ) |
|
79 | 79 | { |
80 | - return Helper::castTo('bool', $this->get($path)); |
|
80 | + return Helper::castTo( 'bool', $this->get( $path ) ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | * @param string $cast |
87 | 87 | * @return mixed |
88 | 88 | */ |
89 | - public function getWP($path, $fallback = '', $cast = '') |
|
89 | + public function getWP( $path, $fallback = '', $cast = '' ) |
|
90 | 90 | { |
91 | - $option = get_option($path, $fallback); |
|
92 | - if (empty($option)) { |
|
91 | + $option = get_option( $path, $fallback ); |
|
92 | + if( empty($option) ) { |
|
93 | 93 | $option = $fallback; |
94 | 94 | } |
95 | - return Helper::castTo($cast, $option); |
|
95 | + return Helper::castTo( $cast, $option ); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -100,25 +100,25 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function json() |
102 | 102 | { |
103 | - return json_encode($this->all()); |
|
103 | + return json_encode( $this->all() ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @return array |
108 | 108 | */ |
109 | - public function normalize(array $options = []) |
|
109 | + public function normalize( array $options = [] ) |
|
110 | 110 | { |
111 | 111 | $options = wp_parse_args( |
112 | - Arr::flattenArray($options), |
|
113 | - glsr(DefaultsManager::class)->defaults() |
|
112 | + Arr::flattenArray( $options ), |
|
113 | + glsr( DefaultsManager::class )->defaults() |
|
114 | 114 | ); |
115 | - array_walk($options, function (&$value) { |
|
116 | - if (!is_string($value)) { |
|
115 | + array_walk( $options, function( &$value ) { |
|
116 | + if( !is_string( $value ) ) { |
|
117 | 117 | return; |
118 | 118 | } |
119 | - $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
119 | + $value = wp_kses( $value, wp_kses_allowed_html( 'post' ) ); |
|
120 | 120 | }); |
121 | - return Arr::convertDotNotationArray($options); |
|
121 | + return Arr::convertDotNotationArray( $options ); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function isRecaptchaEnabled() |
128 | 128 | { |
129 | - $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
129 | + $integration = $this->get( 'settings.submissions.recaptcha.integration' ); |
|
130 | 130 | return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
131 | 131 | } |
132 | 132 | |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function reset() |
137 | 137 | { |
138 | - $options = $this->getWP(static::databaseKey(), []); |
|
139 | - if (!is_array($options) || empty($options)) { |
|
140 | - delete_option(static::databaseKey()); |
|
138 | + $options = $this->getWP( static::databaseKey(), [] ); |
|
139 | + if( !is_array( $options ) || empty($options) ) { |
|
140 | + delete_option( static::databaseKey() ); |
|
141 | 141 | $options = glsr()->defaults ?: []; |
142 | 142 | } |
143 | 143 | $this->options = $options; |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | * @param mixed $value |
149 | 149 | * @return bool |
150 | 150 | */ |
151 | - public function set($pathOrOptions, $value = '') |
|
151 | + public function set( $pathOrOptions, $value = '' ) |
|
152 | 152 | { |
153 | - if (is_string($pathOrOptions)) { |
|
154 | - $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value); |
|
153 | + if( is_string( $pathOrOptions ) ) { |
|
154 | + $pathOrOptions = Arr::set( $this->all(), $pathOrOptions, $value ); |
|
155 | 155 | } |
156 | - if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
156 | + if( $result = update_option( static::databaseKey(), (array)$pathOrOptions ) ) { |
|
157 | 157 | $this->reset(); |
158 | 158 | } |
159 | 159 | return $result; |
@@ -9,77 +9,77 @@ |
||
9 | 9 | |
10 | 10 | class RegisterPostType |
11 | 11 | { |
12 | - public $args; |
|
13 | - public $columns; |
|
14 | - public $plural; |
|
15 | - public $postType; |
|
16 | - public $single; |
|
12 | + public $args; |
|
13 | + public $columns; |
|
14 | + public $plural; |
|
15 | + public $postType; |
|
16 | + public $single; |
|
17 | 17 | |
18 | - public function __construct($input) |
|
19 | - { |
|
20 | - $args = glsr(PostTypeDefaults::class)->merge($input); |
|
21 | - $this->normalize($args); |
|
22 | - $this->normalizeColumns(); |
|
23 | - $this->normalizeLabels(); |
|
24 | - } |
|
18 | + public function __construct($input) |
|
19 | + { |
|
20 | + $args = glsr(PostTypeDefaults::class)->merge($input); |
|
21 | + $this->normalize($args); |
|
22 | + $this->normalizeColumns(); |
|
23 | + $this->normalizeLabels(); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - protected function normalize(array $args) |
|
30 | - { |
|
31 | - foreach ($args as $key => $value) { |
|
32 | - $property = Helper::buildPropertyName($key); |
|
33 | - if (!property_exists($this, $property)) { |
|
34 | - continue; |
|
35 | - } |
|
36 | - $this->$property = $value; |
|
37 | - unset($args[$key]); |
|
38 | - } |
|
39 | - $this->args = wp_parse_args($args, [ |
|
40 | - 'menu_name' => $this->plural, |
|
41 | - ]); |
|
42 | - } |
|
26 | + /** |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + protected function normalize(array $args) |
|
30 | + { |
|
31 | + foreach ($args as $key => $value) { |
|
32 | + $property = Helper::buildPropertyName($key); |
|
33 | + if (!property_exists($this, $property)) { |
|
34 | + continue; |
|
35 | + } |
|
36 | + $this->$property = $value; |
|
37 | + unset($args[$key]); |
|
38 | + } |
|
39 | + $this->args = wp_parse_args($args, [ |
|
40 | + 'menu_name' => $this->plural, |
|
41 | + ]); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - protected function normalizeLabels() |
|
48 | - { |
|
49 | - $this->args['labels'] = wp_parse_args($this->args['labels'], [ |
|
50 | - 'add_new_item' => sprintf(_x('Add New %s', 'Add New Post', 'site-reviews'), $this->plural), |
|
51 | - 'all_items' => sprintf(_x('All %s', 'All Posts', 'site-reviews'), $this->plural), |
|
52 | - 'archives' => sprintf(_x('%s Archives', 'Post Archives', 'site-reviews'), $this->single), |
|
53 | - 'edit_item' => sprintf(_x('Edit %s', 'Edit Post', 'site-reviews'), $this->single), |
|
54 | - 'insert_into_item' => sprintf(_x('Insert into %s', 'Insert into Post', 'site-reviews'), $this->single), |
|
55 | - 'menu_name' => $this->args['menu_name'], |
|
56 | - 'name' => $this->plural, |
|
57 | - 'new_item' => sprintf(_x('New %s', 'New Post', 'site-reviews'), $this->single), |
|
58 | - 'not_found' => sprintf(_x('No %s found', 'No Posts found', 'site-reviews'), $this->plural), |
|
59 | - 'not_found_in_trash' => sprintf(_x('No %s found in Trash', 'No Posts found in Trash', 'site-reviews'), $this->plural), |
|
60 | - 'search_items' => sprintf(_x('Search %s', 'Search Posts', 'site-reviews'), $this->plural), |
|
61 | - 'singular_name' => $this->single, |
|
62 | - 'uploaded_to_this_item' => sprintf(_x('Uploaded to this %s', 'Uploaded to this Post', 'site-reviews'), $this->single), |
|
63 | - 'view_item' => sprintf(_x('View %s', 'View Post', 'site-reviews'), $this->single), |
|
64 | - ]); |
|
65 | - unset($this->args['menu_name']); |
|
66 | - } |
|
44 | + /** |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + protected function normalizeLabels() |
|
48 | + { |
|
49 | + $this->args['labels'] = wp_parse_args($this->args['labels'], [ |
|
50 | + 'add_new_item' => sprintf(_x('Add New %s', 'Add New Post', 'site-reviews'), $this->plural), |
|
51 | + 'all_items' => sprintf(_x('All %s', 'All Posts', 'site-reviews'), $this->plural), |
|
52 | + 'archives' => sprintf(_x('%s Archives', 'Post Archives', 'site-reviews'), $this->single), |
|
53 | + 'edit_item' => sprintf(_x('Edit %s', 'Edit Post', 'site-reviews'), $this->single), |
|
54 | + 'insert_into_item' => sprintf(_x('Insert into %s', 'Insert into Post', 'site-reviews'), $this->single), |
|
55 | + 'menu_name' => $this->args['menu_name'], |
|
56 | + 'name' => $this->plural, |
|
57 | + 'new_item' => sprintf(_x('New %s', 'New Post', 'site-reviews'), $this->single), |
|
58 | + 'not_found' => sprintf(_x('No %s found', 'No Posts found', 'site-reviews'), $this->plural), |
|
59 | + 'not_found_in_trash' => sprintf(_x('No %s found in Trash', 'No Posts found in Trash', 'site-reviews'), $this->plural), |
|
60 | + 'search_items' => sprintf(_x('Search %s', 'Search Posts', 'site-reviews'), $this->plural), |
|
61 | + 'singular_name' => $this->single, |
|
62 | + 'uploaded_to_this_item' => sprintf(_x('Uploaded to this %s', 'Uploaded to this Post', 'site-reviews'), $this->single), |
|
63 | + 'view_item' => sprintf(_x('View %s', 'View Post', 'site-reviews'), $this->single), |
|
64 | + ]); |
|
65 | + unset($this->args['menu_name']); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - protected function normalizeColumns() |
|
72 | - { |
|
73 | - $this->columns = ['cb' => ''] + $this->columns; |
|
74 | - if (array_key_exists('category', $this->columns)) { |
|
75 | - $keys = array_keys($this->columns); |
|
76 | - $keys[array_search('category', $keys)] = 'taxonomy-'.Application::TAXONOMY; |
|
77 | - $this->columns = array_combine($keys, $this->columns); |
|
78 | - } |
|
79 | - if (array_key_exists('pinned', $this->columns)) { |
|
80 | - $this->columns['pinned'] = glsr(Builder::class)->span('<span>'.$this->columns['pinned'].'</span>', |
|
81 | - ['class' => 'pinned-icon'] |
|
82 | - ); |
|
83 | - } |
|
84 | - } |
|
68 | + /** |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + protected function normalizeColumns() |
|
72 | + { |
|
73 | + $this->columns = ['cb' => ''] + $this->columns; |
|
74 | + if (array_key_exists('category', $this->columns)) { |
|
75 | + $keys = array_keys($this->columns); |
|
76 | + $keys[array_search('category', $keys)] = 'taxonomy-'.Application::TAXONOMY; |
|
77 | + $this->columns = array_combine($keys, $this->columns); |
|
78 | + } |
|
79 | + if (array_key_exists('pinned', $this->columns)) { |
|
80 | + $this->columns['pinned'] = glsr(Builder::class)->span('<span>'.$this->columns['pinned'].'</span>', |
|
81 | + ['class' => 'pinned-icon'] |
|
82 | + ); |
|
83 | + } |
|
84 | + } |
|
85 | 85 | } |
@@ -15,10 +15,10 @@ discard block |
||
15 | 15 | public $postType; |
16 | 16 | public $single; |
17 | 17 | |
18 | - public function __construct($input) |
|
18 | + public function __construct( $input ) |
|
19 | 19 | { |
20 | - $args = glsr(PostTypeDefaults::class)->merge($input); |
|
21 | - $this->normalize($args); |
|
20 | + $args = glsr( PostTypeDefaults::class )->merge( $input ); |
|
21 | + $this->normalize( $args ); |
|
22 | 22 | $this->normalizeColumns(); |
23 | 23 | $this->normalizeLabels(); |
24 | 24 | } |
@@ -26,19 +26,19 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @return void |
28 | 28 | */ |
29 | - protected function normalize(array $args) |
|
29 | + protected function normalize( array $args ) |
|
30 | 30 | { |
31 | - foreach ($args as $key => $value) { |
|
32 | - $property = Helper::buildPropertyName($key); |
|
33 | - if (!property_exists($this, $property)) { |
|
31 | + foreach( $args as $key => $value ) { |
|
32 | + $property = Helper::buildPropertyName( $key ); |
|
33 | + if( !property_exists( $this, $property ) ) { |
|
34 | 34 | continue; |
35 | 35 | } |
36 | 36 | $this->$property = $value; |
37 | 37 | unset($args[$key]); |
38 | 38 | } |
39 | - $this->args = wp_parse_args($args, [ |
|
39 | + $this->args = wp_parse_args( $args, [ |
|
40 | 40 | 'menu_name' => $this->plural, |
41 | - ]); |
|
41 | + ] ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -46,22 +46,22 @@ discard block |
||
46 | 46 | */ |
47 | 47 | protected function normalizeLabels() |
48 | 48 | { |
49 | - $this->args['labels'] = wp_parse_args($this->args['labels'], [ |
|
50 | - 'add_new_item' => sprintf(_x('Add New %s', 'Add New Post', 'site-reviews'), $this->plural), |
|
51 | - 'all_items' => sprintf(_x('All %s', 'All Posts', 'site-reviews'), $this->plural), |
|
52 | - 'archives' => sprintf(_x('%s Archives', 'Post Archives', 'site-reviews'), $this->single), |
|
53 | - 'edit_item' => sprintf(_x('Edit %s', 'Edit Post', 'site-reviews'), $this->single), |
|
54 | - 'insert_into_item' => sprintf(_x('Insert into %s', 'Insert into Post', 'site-reviews'), $this->single), |
|
49 | + $this->args['labels'] = wp_parse_args( $this->args['labels'], [ |
|
50 | + 'add_new_item' => sprintf( _x( 'Add New %s', 'Add New Post', 'site-reviews' ), $this->plural ), |
|
51 | + 'all_items' => sprintf( _x( 'All %s', 'All Posts', 'site-reviews' ), $this->plural ), |
|
52 | + 'archives' => sprintf( _x( '%s Archives', 'Post Archives', 'site-reviews' ), $this->single ), |
|
53 | + 'edit_item' => sprintf( _x( 'Edit %s', 'Edit Post', 'site-reviews' ), $this->single ), |
|
54 | + 'insert_into_item' => sprintf( _x( 'Insert into %s', 'Insert into Post', 'site-reviews' ), $this->single ), |
|
55 | 55 | 'menu_name' => $this->args['menu_name'], |
56 | 56 | 'name' => $this->plural, |
57 | - 'new_item' => sprintf(_x('New %s', 'New Post', 'site-reviews'), $this->single), |
|
58 | - 'not_found' => sprintf(_x('No %s found', 'No Posts found', 'site-reviews'), $this->plural), |
|
59 | - 'not_found_in_trash' => sprintf(_x('No %s found in Trash', 'No Posts found in Trash', 'site-reviews'), $this->plural), |
|
60 | - 'search_items' => sprintf(_x('Search %s', 'Search Posts', 'site-reviews'), $this->plural), |
|
57 | + 'new_item' => sprintf( _x( 'New %s', 'New Post', 'site-reviews' ), $this->single ), |
|
58 | + 'not_found' => sprintf( _x( 'No %s found', 'No Posts found', 'site-reviews' ), $this->plural ), |
|
59 | + 'not_found_in_trash' => sprintf( _x( 'No %s found in Trash', 'No Posts found in Trash', 'site-reviews' ), $this->plural ), |
|
60 | + 'search_items' => sprintf( _x( 'Search %s', 'Search Posts', 'site-reviews' ), $this->plural ), |
|
61 | 61 | 'singular_name' => $this->single, |
62 | - 'uploaded_to_this_item' => sprintf(_x('Uploaded to this %s', 'Uploaded to this Post', 'site-reviews'), $this->single), |
|
63 | - 'view_item' => sprintf(_x('View %s', 'View Post', 'site-reviews'), $this->single), |
|
64 | - ]); |
|
62 | + 'uploaded_to_this_item' => sprintf( _x( 'Uploaded to this %s', 'Uploaded to this Post', 'site-reviews' ), $this->single ), |
|
63 | + 'view_item' => sprintf( _x( 'View %s', 'View Post', 'site-reviews' ), $this->single ), |
|
64 | + ] ); |
|
65 | 65 | unset($this->args['menu_name']); |
66 | 66 | } |
67 | 67 | |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | protected function normalizeColumns() |
72 | 72 | { |
73 | 73 | $this->columns = ['cb' => ''] + $this->columns; |
74 | - if (array_key_exists('category', $this->columns)) { |
|
75 | - $keys = array_keys($this->columns); |
|
76 | - $keys[array_search('category', $keys)] = 'taxonomy-'.Application::TAXONOMY; |
|
77 | - $this->columns = array_combine($keys, $this->columns); |
|
74 | + if( array_key_exists( 'category', $this->columns ) ) { |
|
75 | + $keys = array_keys( $this->columns ); |
|
76 | + $keys[array_search( 'category', $keys )] = 'taxonomy-'.Application::TAXONOMY; |
|
77 | + $this->columns = array_combine( $keys, $this->columns ); |
|
78 | 78 | } |
79 | - if (array_key_exists('pinned', $this->columns)) { |
|
80 | - $this->columns['pinned'] = glsr(Builder::class)->span('<span>'.$this->columns['pinned'].'</span>', |
|
79 | + if( array_key_exists( 'pinned', $this->columns ) ) { |
|
80 | + $this->columns['pinned'] = glsr( Builder::class )->span( '<span>'.$this->columns['pinned'].'</span>', |
|
81 | 81 | ['class' => 'pinned-icon'] |
82 | 82 | ); |
83 | 83 | } |
@@ -6,140 +6,140 @@ |
||
6 | 6 | |
7 | 7 | class CreateReview |
8 | 8 | { |
9 | - public $ajax_request; |
|
10 | - public $assigned_to; |
|
11 | - public $author; |
|
12 | - public $avatar; |
|
13 | - public $blacklisted; |
|
14 | - public $category; |
|
15 | - public $content; |
|
16 | - public $custom; |
|
17 | - public $date; |
|
18 | - public $email; |
|
19 | - public $form_id; |
|
20 | - public $ip_address; |
|
21 | - public $post_id; |
|
22 | - public $rating; |
|
23 | - public $referer; |
|
24 | - public $request; |
|
25 | - public $response; |
|
26 | - public $terms; |
|
27 | - public $title; |
|
28 | - public $url; |
|
9 | + public $ajax_request; |
|
10 | + public $assigned_to; |
|
11 | + public $author; |
|
12 | + public $avatar; |
|
13 | + public $blacklisted; |
|
14 | + public $category; |
|
15 | + public $content; |
|
16 | + public $custom; |
|
17 | + public $date; |
|
18 | + public $email; |
|
19 | + public $form_id; |
|
20 | + public $ip_address; |
|
21 | + public $post_id; |
|
22 | + public $rating; |
|
23 | + public $referer; |
|
24 | + public $request; |
|
25 | + public $response; |
|
26 | + public $terms; |
|
27 | + public $title; |
|
28 | + public $url; |
|
29 | 29 | |
30 | - public function __construct($input) |
|
31 | - { |
|
32 | - $this->request = $input; |
|
33 | - $this->ajax_request = isset($input['_ajax_request']); |
|
34 | - $this->assigned_to = $this->getNumeric('assign_to'); |
|
35 | - $this->author = sanitize_text_field($this->getUser('name')); |
|
36 | - $this->avatar = $this->getAvatar(); |
|
37 | - $this->blacklisted = isset($input['blacklisted']); |
|
38 | - $this->category = $this->getCategory(); |
|
39 | - $this->content = sanitize_textarea_field($this->get('content')); |
|
40 | - $this->custom = $this->getCustom(); |
|
41 | - $this->date = $this->getDate('date'); |
|
42 | - $this->email = sanitize_email($this->getUser('email')); |
|
43 | - $this->form_id = sanitize_key($this->get('form_id')); |
|
44 | - $this->ip_address = $this->get('ip_address'); |
|
45 | - $this->post_id = intval($this->get('_post_id')); |
|
46 | - $this->rating = intval($this->get('rating')); |
|
47 | - $this->referer = $this->get('_referer'); |
|
48 | - $this->response = sanitize_textarea_field($this->get('response')); |
|
49 | - $this->terms = !empty($input['terms']); |
|
50 | - $this->title = sanitize_text_field($this->get('title')); |
|
51 | - $this->url = esc_url_raw($this->get('url')); |
|
52 | - } |
|
30 | + public function __construct($input) |
|
31 | + { |
|
32 | + $this->request = $input; |
|
33 | + $this->ajax_request = isset($input['_ajax_request']); |
|
34 | + $this->assigned_to = $this->getNumeric('assign_to'); |
|
35 | + $this->author = sanitize_text_field($this->getUser('name')); |
|
36 | + $this->avatar = $this->getAvatar(); |
|
37 | + $this->blacklisted = isset($input['blacklisted']); |
|
38 | + $this->category = $this->getCategory(); |
|
39 | + $this->content = sanitize_textarea_field($this->get('content')); |
|
40 | + $this->custom = $this->getCustom(); |
|
41 | + $this->date = $this->getDate('date'); |
|
42 | + $this->email = sanitize_email($this->getUser('email')); |
|
43 | + $this->form_id = sanitize_key($this->get('form_id')); |
|
44 | + $this->ip_address = $this->get('ip_address'); |
|
45 | + $this->post_id = intval($this->get('_post_id')); |
|
46 | + $this->rating = intval($this->get('rating')); |
|
47 | + $this->referer = $this->get('_referer'); |
|
48 | + $this->response = sanitize_textarea_field($this->get('response')); |
|
49 | + $this->terms = !empty($input['terms']); |
|
50 | + $this->title = sanitize_text_field($this->get('title')); |
|
51 | + $this->url = esc_url_raw($this->get('url')); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $key |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - protected function get($key) |
|
59 | - { |
|
60 | - return (string) Arr::get($this->request, $key); |
|
61 | - } |
|
54 | + /** |
|
55 | + * @param string $key |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + protected function get($key) |
|
59 | + { |
|
60 | + return (string) Arr::get($this->request, $key); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - protected function getAvatar() |
|
67 | - { |
|
68 | - $avatar = $this->get('avatar'); |
|
69 | - return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
70 | - ? (string) get_avatar_url($this->get('email')) |
|
71 | - : $avatar; |
|
72 | - } |
|
63 | + /** |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + protected function getAvatar() |
|
67 | + { |
|
68 | + $avatar = $this->get('avatar'); |
|
69 | + return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
70 | + ? (string) get_avatar_url($this->get('email')) |
|
71 | + : $avatar; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - protected function getCategory() |
|
78 | - { |
|
79 | - $categories = Arr::convertStringToArray($this->get('category')); |
|
80 | - return sanitize_key(Arr::get($categories, 0)); |
|
81 | - } |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + protected function getCategory() |
|
78 | + { |
|
79 | + $categories = Arr::convertStringToArray($this->get('category')); |
|
80 | + return sanitize_key(Arr::get($categories, 0)); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function getCustom() |
|
87 | - { |
|
88 | - $unset = [ |
|
89 | - '_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token', |
|
90 | - '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
|
91 | - 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
|
92 | - ]; |
|
93 | - $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
94 | - $custom = $this->request; |
|
95 | - foreach ($unset as $value) { |
|
96 | - unset($custom[$value]); |
|
97 | - } |
|
98 | - return $custom; |
|
99 | - } |
|
83 | + /** |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function getCustom() |
|
87 | + { |
|
88 | + $unset = [ |
|
89 | + '_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token', |
|
90 | + '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
|
91 | + 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
|
92 | + ]; |
|
93 | + $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
94 | + $custom = $this->request; |
|
95 | + foreach ($unset as $value) { |
|
96 | + unset($custom[$value]); |
|
97 | + } |
|
98 | + return $custom; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @param string $key |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - protected function getDate($key) |
|
106 | - { |
|
107 | - $date = strtotime($this->get($key)); |
|
108 | - if (false === $date) { |
|
109 | - $date = time(); |
|
110 | - } |
|
111 | - return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
112 | - } |
|
101 | + /** |
|
102 | + * @param string $key |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + protected function getDate($key) |
|
106 | + { |
|
107 | + $date = strtotime($this->get($key)); |
|
108 | + if (false === $date) { |
|
109 | + $date = time(); |
|
110 | + } |
|
111 | + return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @param string $key |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - protected function getUser($key) |
|
119 | - { |
|
120 | - $value = $this->get($key); |
|
121 | - if (empty($value)) { |
|
122 | - $user = wp_get_current_user(); |
|
123 | - $userValues = [ |
|
124 | - 'email' => 'user_email', |
|
125 | - 'name' => 'display_name', |
|
126 | - ]; |
|
127 | - if ($user->exists() && array_key_exists($key, $userValues)) { |
|
128 | - return $user->{$userValues[$key]}; |
|
129 | - } |
|
130 | - } |
|
131 | - return $value; |
|
132 | - } |
|
114 | + /** |
|
115 | + * @param string $key |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + protected function getUser($key) |
|
119 | + { |
|
120 | + $value = $this->get($key); |
|
121 | + if (empty($value)) { |
|
122 | + $user = wp_get_current_user(); |
|
123 | + $userValues = [ |
|
124 | + 'email' => 'user_email', |
|
125 | + 'name' => 'display_name', |
|
126 | + ]; |
|
127 | + if ($user->exists() && array_key_exists($key, $userValues)) { |
|
128 | + return $user->{$userValues[$key]}; |
|
129 | + } |
|
130 | + } |
|
131 | + return $value; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @param string $key |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - protected function getNumeric($key) |
|
139 | - { |
|
140 | - $value = $this->get($key); |
|
141 | - return is_numeric($value) |
|
142 | - ? $value |
|
143 | - : ''; |
|
144 | - } |
|
134 | + /** |
|
135 | + * @param string $key |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + protected function getNumeric($key) |
|
139 | + { |
|
140 | + $value = $this->get($key); |
|
141 | + return is_numeric($value) |
|
142 | + ? $value |
|
143 | + : ''; |
|
144 | + } |
|
145 | 145 | } |
@@ -27,37 +27,37 @@ discard block |
||
27 | 27 | public $title; |
28 | 28 | public $url; |
29 | 29 | |
30 | - public function __construct($input) |
|
30 | + public function __construct( $input ) |
|
31 | 31 | { |
32 | 32 | $this->request = $input; |
33 | 33 | $this->ajax_request = isset($input['_ajax_request']); |
34 | - $this->assigned_to = $this->getNumeric('assign_to'); |
|
35 | - $this->author = sanitize_text_field($this->getUser('name')); |
|
34 | + $this->assigned_to = $this->getNumeric( 'assign_to' ); |
|
35 | + $this->author = sanitize_text_field( $this->getUser( 'name' ) ); |
|
36 | 36 | $this->avatar = $this->getAvatar(); |
37 | 37 | $this->blacklisted = isset($input['blacklisted']); |
38 | 38 | $this->category = $this->getCategory(); |
39 | - $this->content = sanitize_textarea_field($this->get('content')); |
|
39 | + $this->content = sanitize_textarea_field( $this->get( 'content' ) ); |
|
40 | 40 | $this->custom = $this->getCustom(); |
41 | - $this->date = $this->getDate('date'); |
|
42 | - $this->email = sanitize_email($this->getUser('email')); |
|
43 | - $this->form_id = sanitize_key($this->get('form_id')); |
|
44 | - $this->ip_address = $this->get('ip_address'); |
|
45 | - $this->post_id = intval($this->get('_post_id')); |
|
46 | - $this->rating = intval($this->get('rating')); |
|
47 | - $this->referer = $this->get('_referer'); |
|
48 | - $this->response = sanitize_textarea_field($this->get('response')); |
|
41 | + $this->date = $this->getDate( 'date' ); |
|
42 | + $this->email = sanitize_email( $this->getUser( 'email' ) ); |
|
43 | + $this->form_id = sanitize_key( $this->get( 'form_id' ) ); |
|
44 | + $this->ip_address = $this->get( 'ip_address' ); |
|
45 | + $this->post_id = intval( $this->get( '_post_id' ) ); |
|
46 | + $this->rating = intval( $this->get( 'rating' ) ); |
|
47 | + $this->referer = $this->get( '_referer' ); |
|
48 | + $this->response = sanitize_textarea_field( $this->get( 'response' ) ); |
|
49 | 49 | $this->terms = !empty($input['terms']); |
50 | - $this->title = sanitize_text_field($this->get('title')); |
|
51 | - $this->url = esc_url_raw($this->get('url')); |
|
50 | + $this->title = sanitize_text_field( $this->get( 'title' ) ); |
|
51 | + $this->url = esc_url_raw( $this->get( 'url' ) ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @param string $key |
56 | 56 | * @return string |
57 | 57 | */ |
58 | - protected function get($key) |
|
58 | + protected function get( $key ) |
|
59 | 59 | { |
60 | - return (string) Arr::get($this->request, $key); |
|
60 | + return (string)Arr::get( $this->request, $key ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | */ |
66 | 66 | protected function getAvatar() |
67 | 67 | { |
68 | - $avatar = $this->get('avatar'); |
|
69 | - return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
70 | - ? (string) get_avatar_url($this->get('email')) |
|
68 | + $avatar = $this->get( 'avatar' ); |
|
69 | + return !filter_var( $avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED ) |
|
70 | + ? (string)get_avatar_url( $this->get( 'email' ) ) |
|
71 | 71 | : $avatar; |
72 | 72 | } |
73 | 73 | |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | */ |
77 | 77 | protected function getCategory() |
78 | 78 | { |
79 | - $categories = Arr::convertStringToArray($this->get('category')); |
|
80 | - return sanitize_key(Arr::get($categories, 0)); |
|
79 | + $categories = Arr::convertStringToArray( $this->get( 'category' ) ); |
|
80 | + return sanitize_key( Arr::get( $categories, 0 ) ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
91 | 91 | 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
92 | 92 | ]; |
93 | - $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
93 | + $unset = apply_filters( 'site-reviews/create/unset-keys-from-custom', $unset ); |
|
94 | 94 | $custom = $this->request; |
95 | - foreach ($unset as $value) { |
|
95 | + foreach( $unset as $value ) { |
|
96 | 96 | unset($custom[$value]); |
97 | 97 | } |
98 | 98 | return $custom; |
@@ -102,29 +102,29 @@ discard block |
||
102 | 102 | * @param string $key |
103 | 103 | * @return string |
104 | 104 | */ |
105 | - protected function getDate($key) |
|
105 | + protected function getDate( $key ) |
|
106 | 106 | { |
107 | - $date = strtotime($this->get($key)); |
|
108 | - if (false === $date) { |
|
107 | + $date = strtotime( $this->get( $key ) ); |
|
108 | + if( false === $date ) { |
|
109 | 109 | $date = time(); |
110 | 110 | } |
111 | - return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
111 | + return get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $date ) ); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | 115 | * @param string $key |
116 | 116 | * @return string |
117 | 117 | */ |
118 | - protected function getUser($key) |
|
118 | + protected function getUser( $key ) |
|
119 | 119 | { |
120 | - $value = $this->get($key); |
|
121 | - if (empty($value)) { |
|
120 | + $value = $this->get( $key ); |
|
121 | + if( empty($value) ) { |
|
122 | 122 | $user = wp_get_current_user(); |
123 | 123 | $userValues = [ |
124 | 124 | 'email' => 'user_email', |
125 | 125 | 'name' => 'display_name', |
126 | 126 | ]; |
127 | - if ($user->exists() && array_key_exists($key, $userValues)) { |
|
127 | + if( $user->exists() && array_key_exists( $key, $userValues ) ) { |
|
128 | 128 | return $user->{$userValues[$key]}; |
129 | 129 | } |
130 | 130 | } |
@@ -135,10 +135,10 @@ discard block |
||
135 | 135 | * @param string $key |
136 | 136 | * @return string |
137 | 137 | */ |
138 | - protected function getNumeric($key) |
|
138 | + protected function getNumeric( $key ) |
|
139 | 139 | { |
140 | - $value = $this->get($key); |
|
141 | - return is_numeric($value) |
|
140 | + $value = $this->get( $key ); |
|
141 | + return is_numeric( $value ) |
|
142 | 142 | ? $value |
143 | 143 | : ''; |
144 | 144 | } |
@@ -7,162 +7,162 @@ |
||
7 | 7 | |
8 | 8 | class Router |
9 | 9 | { |
10 | - /** |
|
11 | - * @var array |
|
12 | - */ |
|
13 | - protected $unguardedActions = []; |
|
10 | + /** |
|
11 | + * @var array |
|
12 | + */ |
|
13 | + protected $unguardedActions = []; |
|
14 | 14 | |
15 | - public function __construct() |
|
16 | - { |
|
17 | - $this->unguardedActions = apply_filters('site-reviews/router/unguarded-actions', [ |
|
18 | - 'dismiss-notice', |
|
19 | - 'fetch-paged-reviews', |
|
20 | - ]); |
|
21 | - } |
|
15 | + public function __construct() |
|
16 | + { |
|
17 | + $this->unguardedActions = apply_filters('site-reviews/router/unguarded-actions', [ |
|
18 | + 'dismiss-notice', |
|
19 | + 'fetch-paged-reviews', |
|
20 | + ]); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function routeAdminPostRequest() |
|
27 | - { |
|
28 | - $request = $this->getRequest(); |
|
29 | - if (!$this->isValidPostRequest($request)) { |
|
30 | - return; |
|
31 | - } |
|
32 | - check_admin_referer($request['_action']); |
|
33 | - $this->routeRequest('admin', $request['_action'], $request); |
|
34 | - } |
|
23 | + /** |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function routeAdminPostRequest() |
|
27 | + { |
|
28 | + $request = $this->getRequest(); |
|
29 | + if (!$this->isValidPostRequest($request)) { |
|
30 | + return; |
|
31 | + } |
|
32 | + check_admin_referer($request['_action']); |
|
33 | + $this->routeRequest('admin', $request['_action'], $request); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function routeAjaxRequest() |
|
40 | - { |
|
41 | - $request = $this->getRequest(); |
|
42 | - $this->checkAjaxRequest($request); |
|
43 | - $this->checkAjaxNonce($request); |
|
44 | - $this->routeRequest('ajax', $request['_action'], $request); |
|
45 | - wp_die(); |
|
46 | - } |
|
36 | + /** |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function routeAjaxRequest() |
|
40 | + { |
|
41 | + $request = $this->getRequest(); |
|
42 | + $this->checkAjaxRequest($request); |
|
43 | + $this->checkAjaxNonce($request); |
|
44 | + $this->routeRequest('ajax', $request['_action'], $request); |
|
45 | + wp_die(); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function routePublicPostRequest() |
|
52 | - { |
|
53 | - if (is_admin()) { |
|
54 | - return; |
|
55 | - } |
|
56 | - $request = $this->getRequest(); |
|
57 | - if (!$this->isValidPostRequest($request)) { |
|
58 | - return; |
|
59 | - } |
|
60 | - if (!$this->isValidPublicNonce($request)) { |
|
61 | - return; |
|
62 | - } |
|
63 | - $this->routeRequest('public', $request['_action'], $request); |
|
64 | - } |
|
48 | + /** |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function routePublicPostRequest() |
|
52 | + { |
|
53 | + if (is_admin()) { |
|
54 | + return; |
|
55 | + } |
|
56 | + $request = $this->getRequest(); |
|
57 | + if (!$this->isValidPostRequest($request)) { |
|
58 | + return; |
|
59 | + } |
|
60 | + if (!$this->isValidPublicNonce($request)) { |
|
61 | + return; |
|
62 | + } |
|
63 | + $this->routeRequest('public', $request['_action'], $request); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - protected function checkAjaxNonce(array $request) |
|
70 | - { |
|
71 | - if (!is_user_logged_in() || in_array(Arr::get($request, '_action'), $this->unguardedActions)) { |
|
72 | - return; |
|
73 | - } |
|
74 | - if (!isset($request['_nonce'])) { |
|
75 | - $this->sendAjaxError('request is missing a nonce', $request); |
|
76 | - } |
|
77 | - if (!wp_verify_nonce($request['_nonce'], $request['_action'])) { |
|
78 | - $this->sendAjaxError('request failed the nonce check', $request, 403); |
|
79 | - } |
|
80 | - } |
|
66 | + /** |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + protected function checkAjaxNonce(array $request) |
|
70 | + { |
|
71 | + if (!is_user_logged_in() || in_array(Arr::get($request, '_action'), $this->unguardedActions)) { |
|
72 | + return; |
|
73 | + } |
|
74 | + if (!isset($request['_nonce'])) { |
|
75 | + $this->sendAjaxError('request is missing a nonce', $request); |
|
76 | + } |
|
77 | + if (!wp_verify_nonce($request['_nonce'], $request['_action'])) { |
|
78 | + $this->sendAjaxError('request failed the nonce check', $request, 403); |
|
79 | + } |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return void |
|
84 | - */ |
|
85 | - protected function checkAjaxRequest(array $request) |
|
86 | - { |
|
87 | - if (!isset($request['_action'])) { |
|
88 | - $this->sendAjaxError('request must include an action', $request); |
|
89 | - } |
|
90 | - if (empty($request['_ajax_request'])) { |
|
91 | - $this->sendAjaxError('request is invalid', $request); |
|
92 | - } |
|
93 | - } |
|
82 | + /** |
|
83 | + * @return void |
|
84 | + */ |
|
85 | + protected function checkAjaxRequest(array $request) |
|
86 | + { |
|
87 | + if (!isset($request['_action'])) { |
|
88 | + $this->sendAjaxError('request must include an action', $request); |
|
89 | + } |
|
90 | + if (empty($request['_ajax_request'])) { |
|
91 | + $this->sendAjaxError('request is invalid', $request); |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * All ajax requests in the plugin are triggered by a single action hook: glsr_action, |
|
97 | - * while each ajax route is determined by $_POST[request][_action]. |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - protected function getRequest() |
|
101 | - { |
|
102 | - $request = Helper::filterInputArray(Application::ID); |
|
103 | - if (Helper::filterInput('action') == Application::PREFIX.'action') { |
|
104 | - $request['_ajax_request'] = true; |
|
105 | - } |
|
106 | - if ('submit-review' == Helper::filterInput('_action', $request)) { |
|
107 | - $request['_recaptcha-token'] = Helper::filterInput('g-recaptcha-response'); |
|
108 | - } |
|
109 | - return $request; |
|
110 | - } |
|
95 | + /** |
|
96 | + * All ajax requests in the plugin are triggered by a single action hook: glsr_action, |
|
97 | + * while each ajax route is determined by $_POST[request][_action]. |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + protected function getRequest() |
|
101 | + { |
|
102 | + $request = Helper::filterInputArray(Application::ID); |
|
103 | + if (Helper::filterInput('action') == Application::PREFIX.'action') { |
|
104 | + $request['_ajax_request'] = true; |
|
105 | + } |
|
106 | + if ('submit-review' == Helper::filterInput('_action', $request)) { |
|
107 | + $request['_recaptcha-token'] = Helper::filterInput('g-recaptcha-response'); |
|
108 | + } |
|
109 | + return $request; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * @return bool |
|
114 | - */ |
|
115 | - protected function isValidPostRequest(array $request = []) |
|
116 | - { |
|
117 | - return !empty($request['_action']) && empty($request['_ajax_request']); |
|
118 | - } |
|
112 | + /** |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | + protected function isValidPostRequest(array $request = []) |
|
116 | + { |
|
117 | + return !empty($request['_action']) && empty($request['_ajax_request']); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - protected function isValidPublicNonce(array $request) |
|
124 | - { |
|
125 | - if (is_user_logged_in() && !wp_verify_nonce($request['_nonce'], $request['_action'])) { |
|
126 | - glsr_log()->error('nonce check failed for public request')->debug($request); |
|
127 | - return false; |
|
128 | - } |
|
129 | - return true; |
|
130 | - } |
|
120 | + /** |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + protected function isValidPublicNonce(array $request) |
|
124 | + { |
|
125 | + if (is_user_logged_in() && !wp_verify_nonce($request['_nonce'], $request['_action'])) { |
|
126 | + glsr_log()->error('nonce check failed for public request')->debug($request); |
|
127 | + return false; |
|
128 | + } |
|
129 | + return true; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @param string $type |
|
134 | - * @param string $action |
|
135 | - * @return void |
|
136 | - */ |
|
137 | - protected function routeRequest($type, $action, array $request = []) |
|
138 | - { |
|
139 | - $actionHook = 'site-reviews/route/'.$type.'/request'; |
|
140 | - $controller = glsr(Helper::buildClassName($type.'-controller', 'Controllers')); |
|
141 | - $method = Helper::buildMethodName($action, 'router'); |
|
142 | - $request = apply_filters('site-reviews/route/request', $request, $action, $type); |
|
143 | - do_action($actionHook, $action, $request); |
|
144 | - if (is_callable([$controller, $method])) { |
|
145 | - call_user_func([$controller, $method], $request); |
|
146 | - return; |
|
147 | - } |
|
148 | - if (0 === did_action($actionHook)) { |
|
149 | - glsr_log('Unknown '.$type.' router request: '.$action); |
|
150 | - } |
|
151 | - } |
|
132 | + /** |
|
133 | + * @param string $type |
|
134 | + * @param string $action |
|
135 | + * @return void |
|
136 | + */ |
|
137 | + protected function routeRequest($type, $action, array $request = []) |
|
138 | + { |
|
139 | + $actionHook = 'site-reviews/route/'.$type.'/request'; |
|
140 | + $controller = glsr(Helper::buildClassName($type.'-controller', 'Controllers')); |
|
141 | + $method = Helper::buildMethodName($action, 'router'); |
|
142 | + $request = apply_filters('site-reviews/route/request', $request, $action, $type); |
|
143 | + do_action($actionHook, $action, $request); |
|
144 | + if (is_callable([$controller, $method])) { |
|
145 | + call_user_func([$controller, $method], $request); |
|
146 | + return; |
|
147 | + } |
|
148 | + if (0 === did_action($actionHook)) { |
|
149 | + glsr_log('Unknown '.$type.' router request: '.$action); |
|
150 | + } |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @param string $error |
|
155 | - * @param int $statusCode |
|
156 | - * @return void |
|
157 | - */ |
|
158 | - protected function sendAjaxError($error, array $request, $statusCode = 400) |
|
159 | - { |
|
160 | - glsr_log()->error($error)->debug($request); |
|
161 | - glsr(Notice::class)->addError(__('There was an error (try reloading the page).', 'site-reviews').' <code>'.$error.'</code>'); |
|
162 | - wp_send_json_error([ |
|
163 | - 'message' => __('The form could not be submitted. Please notify the site administrator.', 'site-reviews'), |
|
164 | - 'notices' => glsr(Notice::class)->get(), |
|
165 | - 'error' => $error, |
|
166 | - ]); |
|
167 | - } |
|
153 | + /** |
|
154 | + * @param string $error |
|
155 | + * @param int $statusCode |
|
156 | + * @return void |
|
157 | + */ |
|
158 | + protected function sendAjaxError($error, array $request, $statusCode = 400) |
|
159 | + { |
|
160 | + glsr_log()->error($error)->debug($request); |
|
161 | + glsr(Notice::class)->addError(__('There was an error (try reloading the page).', 'site-reviews').' <code>'.$error.'</code>'); |
|
162 | + wp_send_json_error([ |
|
163 | + 'message' => __('The form could not be submitted. Please notify the site administrator.', 'site-reviews'), |
|
164 | + 'notices' => glsr(Notice::class)->get(), |
|
165 | + 'error' => $error, |
|
166 | + ]); |
|
167 | + } |
|
168 | 168 | } |
@@ -14,10 +14,10 @@ discard block |
||
14 | 14 | |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - $this->unguardedActions = apply_filters('site-reviews/router/unguarded-actions', [ |
|
17 | + $this->unguardedActions = apply_filters( 'site-reviews/router/unguarded-actions', [ |
|
18 | 18 | 'dismiss-notice', |
19 | 19 | 'fetch-paged-reviews', |
20 | - ]); |
|
20 | + ] ); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -26,11 +26,11 @@ discard block |
||
26 | 26 | public function routeAdminPostRequest() |
27 | 27 | { |
28 | 28 | $request = $this->getRequest(); |
29 | - if (!$this->isValidPostRequest($request)) { |
|
29 | + if( !$this->isValidPostRequest( $request ) ) { |
|
30 | 30 | return; |
31 | 31 | } |
32 | - check_admin_referer($request['_action']); |
|
33 | - $this->routeRequest('admin', $request['_action'], $request); |
|
32 | + check_admin_referer( $request['_action'] ); |
|
33 | + $this->routeRequest( 'admin', $request['_action'], $request ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | public function routeAjaxRequest() |
40 | 40 | { |
41 | 41 | $request = $this->getRequest(); |
42 | - $this->checkAjaxRequest($request); |
|
43 | - $this->checkAjaxNonce($request); |
|
44 | - $this->routeRequest('ajax', $request['_action'], $request); |
|
42 | + $this->checkAjaxRequest( $request ); |
|
43 | + $this->checkAjaxNonce( $request ); |
|
44 | + $this->routeRequest( 'ajax', $request['_action'], $request ); |
|
45 | 45 | wp_die(); |
46 | 46 | } |
47 | 47 | |
@@ -50,45 +50,45 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function routePublicPostRequest() |
52 | 52 | { |
53 | - if (is_admin()) { |
|
53 | + if( is_admin() ) { |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | $request = $this->getRequest(); |
57 | - if (!$this->isValidPostRequest($request)) { |
|
57 | + if( !$this->isValidPostRequest( $request ) ) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | - if (!$this->isValidPublicNonce($request)) { |
|
60 | + if( !$this->isValidPublicNonce( $request ) ) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | - $this->routeRequest('public', $request['_action'], $request); |
|
63 | + $this->routeRequest( 'public', $request['_action'], $request ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @return void |
68 | 68 | */ |
69 | - protected function checkAjaxNonce(array $request) |
|
69 | + protected function checkAjaxNonce( array $request ) |
|
70 | 70 | { |
71 | - if (!is_user_logged_in() || in_array(Arr::get($request, '_action'), $this->unguardedActions)) { |
|
71 | + if( !is_user_logged_in() || in_array( Arr::get( $request, '_action' ), $this->unguardedActions ) ) { |
|
72 | 72 | return; |
73 | 73 | } |
74 | - if (!isset($request['_nonce'])) { |
|
75 | - $this->sendAjaxError('request is missing a nonce', $request); |
|
74 | + if( !isset($request['_nonce']) ) { |
|
75 | + $this->sendAjaxError( 'request is missing a nonce', $request ); |
|
76 | 76 | } |
77 | - if (!wp_verify_nonce($request['_nonce'], $request['_action'])) { |
|
78 | - $this->sendAjaxError('request failed the nonce check', $request, 403); |
|
77 | + if( !wp_verify_nonce( $request['_nonce'], $request['_action'] ) ) { |
|
78 | + $this->sendAjaxError( 'request failed the nonce check', $request, 403 ); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * @return void |
84 | 84 | */ |
85 | - protected function checkAjaxRequest(array $request) |
|
85 | + protected function checkAjaxRequest( array $request ) |
|
86 | 86 | { |
87 | - if (!isset($request['_action'])) { |
|
88 | - $this->sendAjaxError('request must include an action', $request); |
|
87 | + if( !isset($request['_action']) ) { |
|
88 | + $this->sendAjaxError( 'request must include an action', $request ); |
|
89 | 89 | } |
90 | - if (empty($request['_ajax_request'])) { |
|
91 | - $this->sendAjaxError('request is invalid', $request); |
|
90 | + if( empty($request['_ajax_request']) ) { |
|
91 | + $this->sendAjaxError( 'request is invalid', $request ); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | */ |
100 | 100 | protected function getRequest() |
101 | 101 | { |
102 | - $request = Helper::filterInputArray(Application::ID); |
|
103 | - if (Helper::filterInput('action') == Application::PREFIX.'action') { |
|
102 | + $request = Helper::filterInputArray( Application::ID ); |
|
103 | + if( Helper::filterInput( 'action' ) == Application::PREFIX.'action' ) { |
|
104 | 104 | $request['_ajax_request'] = true; |
105 | 105 | } |
106 | - if ('submit-review' == Helper::filterInput('_action', $request)) { |
|
107 | - $request['_recaptcha-token'] = Helper::filterInput('g-recaptcha-response'); |
|
106 | + if( 'submit-review' == Helper::filterInput( '_action', $request ) ) { |
|
107 | + $request['_recaptcha-token'] = Helper::filterInput( 'g-recaptcha-response' ); |
|
108 | 108 | } |
109 | 109 | return $request; |
110 | 110 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | /** |
113 | 113 | * @return bool |
114 | 114 | */ |
115 | - protected function isValidPostRequest(array $request = []) |
|
115 | + protected function isValidPostRequest( array $request = [] ) |
|
116 | 116 | { |
117 | 117 | return !empty($request['_action']) && empty($request['_ajax_request']); |
118 | 118 | } |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | /** |
121 | 121 | * @return bool |
122 | 122 | */ |
123 | - protected function isValidPublicNonce(array $request) |
|
123 | + protected function isValidPublicNonce( array $request ) |
|
124 | 124 | { |
125 | - if (is_user_logged_in() && !wp_verify_nonce($request['_nonce'], $request['_action'])) { |
|
126 | - glsr_log()->error('nonce check failed for public request')->debug($request); |
|
125 | + if( is_user_logged_in() && !wp_verify_nonce( $request['_nonce'], $request['_action'] ) ) { |
|
126 | + glsr_log()->error( 'nonce check failed for public request' )->debug( $request ); |
|
127 | 127 | return false; |
128 | 128 | } |
129 | 129 | return true; |
@@ -134,19 +134,19 @@ discard block |
||
134 | 134 | * @param string $action |
135 | 135 | * @return void |
136 | 136 | */ |
137 | - protected function routeRequest($type, $action, array $request = []) |
|
137 | + protected function routeRequest( $type, $action, array $request = [] ) |
|
138 | 138 | { |
139 | 139 | $actionHook = 'site-reviews/route/'.$type.'/request'; |
140 | - $controller = glsr(Helper::buildClassName($type.'-controller', 'Controllers')); |
|
141 | - $method = Helper::buildMethodName($action, 'router'); |
|
142 | - $request = apply_filters('site-reviews/route/request', $request, $action, $type); |
|
143 | - do_action($actionHook, $action, $request); |
|
144 | - if (is_callable([$controller, $method])) { |
|
145 | - call_user_func([$controller, $method], $request); |
|
140 | + $controller = glsr( Helper::buildClassName( $type.'-controller', 'Controllers' ) ); |
|
141 | + $method = Helper::buildMethodName( $action, 'router' ); |
|
142 | + $request = apply_filters( 'site-reviews/route/request', $request, $action, $type ); |
|
143 | + do_action( $actionHook, $action, $request ); |
|
144 | + if( is_callable( [$controller, $method] ) ) { |
|
145 | + call_user_func( [$controller, $method], $request ); |
|
146 | 146 | return; |
147 | 147 | } |
148 | - if (0 === did_action($actionHook)) { |
|
149 | - glsr_log('Unknown '.$type.' router request: '.$action); |
|
148 | + if( 0 === did_action( $actionHook ) ) { |
|
149 | + glsr_log( 'Unknown '.$type.' router request: '.$action ); |
|
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
@@ -155,14 +155,14 @@ discard block |
||
155 | 155 | * @param int $statusCode |
156 | 156 | * @return void |
157 | 157 | */ |
158 | - protected function sendAjaxError($error, array $request, $statusCode = 400) |
|
158 | + protected function sendAjaxError( $error, array $request, $statusCode = 400 ) |
|
159 | 159 | { |
160 | - glsr_log()->error($error)->debug($request); |
|
161 | - glsr(Notice::class)->addError(__('There was an error (try reloading the page).', 'site-reviews').' <code>'.$error.'</code>'); |
|
162 | - wp_send_json_error([ |
|
163 | - 'message' => __('The form could not be submitted. Please notify the site administrator.', 'site-reviews'), |
|
164 | - 'notices' => glsr(Notice::class)->get(), |
|
160 | + glsr_log()->error( $error )->debug( $request ); |
|
161 | + glsr( Notice::class )->addError( __( 'There was an error (try reloading the page).', 'site-reviews' ).' <code>'.$error.'</code>' ); |
|
162 | + wp_send_json_error( [ |
|
163 | + 'message' => __( 'The form could not be submitted. Please notify the site administrator.', 'site-reviews' ), |
|
164 | + 'notices' => glsr( Notice::class )->get(), |
|
165 | 165 | 'error' => $error, |
166 | - ]); |
|
166 | + ] ); |
|
167 | 167 | } |
168 | 168 | } |
@@ -8,23 +8,23 @@ discard block |
||
8 | 8 | |
9 | 9 | class SqlQueries |
10 | 10 | { |
11 | - protected $db; |
|
12 | - protected $postType; |
|
11 | + protected $db; |
|
12 | + protected $postType; |
|
13 | 13 | |
14 | - public function __construct() |
|
15 | - { |
|
16 | - global $wpdb; |
|
17 | - $this->db = $wpdb; |
|
18 | - $this->postType = Application::POST_TYPE; |
|
19 | - } |
|
14 | + public function __construct() |
|
15 | + { |
|
16 | + global $wpdb; |
|
17 | + $this->db = $wpdb; |
|
18 | + $this->postType = Application::POST_TYPE; |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param string $metaReviewId |
|
23 | - * @return int |
|
24 | - */ |
|
25 | - public function getPostIdFromReviewId($metaReviewId) |
|
26 | - { |
|
27 | - $postId = $this->db->get_var(" |
|
21 | + /** |
|
22 | + * @param string $metaReviewId |
|
23 | + * @return int |
|
24 | + */ |
|
25 | + public function getPostIdFromReviewId($metaReviewId) |
|
26 | + { |
|
27 | + $postId = $this->db->get_var(" |
|
28 | 28 | SELECT p.ID |
29 | 29 | FROM {$this->db->posts} AS p |
30 | 30 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | AND m.meta_key = '_review_id' |
33 | 33 | AND m.meta_value = '{$metaReviewId}' |
34 | 34 | "); |
35 | - return intval($postId); |
|
36 | - } |
|
35 | + return intval($postId); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param int $lastPostId |
|
40 | - * @param int $limit |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
44 | - { |
|
45 | - return (array) $this->db->get_results(" |
|
38 | + /** |
|
39 | + * @param int $lastPostId |
|
40 | + * @param int $limit |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
44 | + { |
|
45 | + return (array) $this->db->get_results(" |
|
46 | 46 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
47 | 47 | FROM {$this->db->posts} AS p |
48 | 48 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -57,17 +57,17 @@ discard block |
||
57 | 57 | ORDER By p.ID ASC |
58 | 58 | LIMIT {$limit} |
59 | 59 | "); |
60 | - } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @todo remove this? |
|
64 | - * @param string $metaKey |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - public function getReviewCountsFor($metaKey) |
|
68 | - { |
|
69 | - $metaKey = Str::prefix('_', $metaKey); |
|
70 | - return (array) $this->db->get_results(" |
|
62 | + /** |
|
63 | + * @todo remove this? |
|
64 | + * @param string $metaKey |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + public function getReviewCountsFor($metaKey) |
|
68 | + { |
|
69 | + $metaKey = Str::prefix('_', $metaKey); |
|
70 | + return (array) $this->db->get_results(" |
|
71 | 71 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
72 | 72 | FROM {$this->db->posts} AS p |
73 | 73 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -75,16 +75,16 @@ discard block |
||
75 | 75 | AND m.meta_key = '{$metaKey}' |
76 | 76 | GROUP BY name |
77 | 77 | "); |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @todo remove this? |
|
82 | - * @param string $reviewType |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - public function getReviewIdsByType($reviewType) |
|
86 | - { |
|
87 | - $results = $this->db->get_col(" |
|
80 | + /** |
|
81 | + * @todo remove this? |
|
82 | + * @param string $reviewType |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + public function getReviewIdsByType($reviewType) |
|
86 | + { |
|
87 | + $results = $this->db->get_col(" |
|
88 | 88 | SELECT DISTINCT m1.meta_value AS review_id |
89 | 89 | FROM {$this->db->posts} AS p |
90 | 90 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -94,20 +94,20 @@ discard block |
||
94 | 94 | AND m2.meta_key = '_review_type' |
95 | 95 | AND m2.meta_value = '{$reviewType}' |
96 | 96 | "); |
97 | - return array_keys(array_flip($results)); |
|
98 | - } |
|
97 | + return array_keys(array_flip($results)); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @param int $greaterThanId |
|
102 | - * @param int $limit |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
106 | - { |
|
107 | - sort($postIds); |
|
108 | - $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
109 | - $postIds = implode(',', $postIds); |
|
110 | - return (array) $this->db->get_results(" |
|
100 | + /** |
|
101 | + * @param int $greaterThanId |
|
102 | + * @param int $limit |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
106 | + { |
|
107 | + sort($postIds); |
|
108 | + $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
109 | + $postIds = implode(',', $postIds); |
|
110 | + return (array) $this->db->get_results(" |
|
111 | 111 | SELECT p.ID, m.meta_value AS rating |
112 | 112 | FROM {$this->db->posts} AS p |
113 | 113 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -120,17 +120,17 @@ discard block |
||
120 | 120 | ORDER By p.ID ASC |
121 | 121 | LIMIT {$limit} |
122 | 122 | "); |
123 | - } |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * @param string $key |
|
127 | - * @param string $status |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function getReviewsMeta($key, $status = 'publish') |
|
131 | - { |
|
132 | - $key = Str::prefix('_', $key); |
|
133 | - $values = $this->db->get_col(" |
|
125 | + /** |
|
126 | + * @param string $key |
|
127 | + * @param string $status |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function getReviewsMeta($key, $status = 'publish') |
|
131 | + { |
|
132 | + $key = Str::prefix('_', $key); |
|
133 | + $values = $this->db->get_col(" |
|
134 | 134 | SELECT DISTINCT m.meta_value |
135 | 135 | FROM {$this->db->postmeta} m |
136 | 136 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -141,42 +141,42 @@ discard block |
||
141 | 141 | GROUP BY p.ID -- remove duplicate meta_value entries |
142 | 142 | ORDER BY m.meta_id ASC -- sort by oldest meta_value |
143 | 143 | "); |
144 | - sort($values); |
|
145 | - return $values; |
|
146 | - } |
|
144 | + sort($values); |
|
145 | + return $values; |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * @param string $and |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - protected function getAndForCounts(array $args, $and = '') |
|
153 | - { |
|
154 | - $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', []))); |
|
155 | - $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', []))); |
|
156 | - if (!empty($args['type'])) { |
|
157 | - $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
158 | - } |
|
159 | - if ($postIds) { |
|
160 | - $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
161 | - } |
|
162 | - if ($termIds) { |
|
163 | - $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
164 | - } |
|
165 | - return apply_filters('site-reviews/query/and-for-counts', $and); |
|
166 | - } |
|
148 | + /** |
|
149 | + * @param string $and |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + protected function getAndForCounts(array $args, $and = '') |
|
153 | + { |
|
154 | + $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', []))); |
|
155 | + $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', []))); |
|
156 | + if (!empty($args['type'])) { |
|
157 | + $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
158 | + } |
|
159 | + if ($postIds) { |
|
160 | + $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
161 | + } |
|
162 | + if ($termIds) { |
|
163 | + $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
164 | + } |
|
165 | + return apply_filters('site-reviews/query/and-for-counts', $and); |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * @param string $innerJoin |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
173 | - { |
|
174 | - if (!empty(Arr::get($args, 'post_ids'))) { |
|
175 | - $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
176 | - } |
|
177 | - if (!empty(Arr::get($args, 'term_ids'))) { |
|
178 | - $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
179 | - } |
|
180 | - return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
181 | - } |
|
168 | + /** |
|
169 | + * @param string $innerJoin |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
173 | + { |
|
174 | + if (!empty(Arr::get($args, 'post_ids'))) { |
|
175 | + $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
176 | + } |
|
177 | + if (!empty(Arr::get($args, 'term_ids'))) { |
|
178 | + $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
179 | + } |
|
180 | + return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
181 | + } |
|
182 | 182 | } |
@@ -22,17 +22,17 @@ discard block |
||
22 | 22 | * @param string $metaReviewId |
23 | 23 | * @return int |
24 | 24 | */ |
25 | - public function getPostIdFromReviewId($metaReviewId) |
|
25 | + public function getPostIdFromReviewId( $metaReviewId ) |
|
26 | 26 | { |
27 | - $postId = $this->db->get_var(" |
|
27 | + $postId = $this->db->get_var( " |
|
28 | 28 | SELECT p.ID |
29 | 29 | FROM {$this->db->posts} AS p |
30 | 30 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
31 | 31 | WHERE p.post_type = '{$this->postType}' |
32 | 32 | AND m.meta_key = '_review_id' |
33 | 33 | AND m.meta_value = '{$metaReviewId}' |
34 | - "); |
|
35 | - return intval($postId); |
|
34 | + " ); |
|
35 | + return intval( $postId ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -40,23 +40,23 @@ discard block |
||
40 | 40 | * @param int $limit |
41 | 41 | * @return array |
42 | 42 | */ |
43 | - public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
43 | + public function getReviewCounts( array $args, $lastPostId = 0, $limit = 500 ) |
|
44 | 44 | { |
45 | - return (array) $this->db->get_results(" |
|
45 | + return (array)$this->db->get_results( " |
|
46 | 46 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
47 | 47 | FROM {$this->db->posts} AS p |
48 | 48 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
49 | 49 | INNER JOIN {$this->db->postmeta} AS m2 ON p.ID = m2.post_id |
50 | - {$this->getInnerJoinForCounts($args)} |
|
50 | + {$this->getInnerJoinForCounts( $args )} |
|
51 | 51 | WHERE p.ID > {$lastPostId} |
52 | 52 | AND p.post_status = 'publish' |
53 | 53 | AND p.post_type = '{$this->postType}' |
54 | 54 | AND m1.meta_key = '_rating' |
55 | 55 | AND m2.meta_key = '_review_type' |
56 | - {$this->getAndForCounts($args)} |
|
56 | + {$this->getAndForCounts( $args )} |
|
57 | 57 | ORDER By p.ID ASC |
58 | 58 | LIMIT {$limit} |
59 | - "); |
|
59 | + " ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -64,17 +64,17 @@ discard block |
||
64 | 64 | * @param string $metaKey |
65 | 65 | * @return array |
66 | 66 | */ |
67 | - public function getReviewCountsFor($metaKey) |
|
67 | + public function getReviewCountsFor( $metaKey ) |
|
68 | 68 | { |
69 | - $metaKey = Str::prefix('_', $metaKey); |
|
70 | - return (array) $this->db->get_results(" |
|
69 | + $metaKey = Str::prefix( '_', $metaKey ); |
|
70 | + return (array)$this->db->get_results( " |
|
71 | 71 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
72 | 72 | FROM {$this->db->posts} AS p |
73 | 73 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
74 | 74 | WHERE p.post_type = '{$this->postType}' |
75 | 75 | AND m.meta_key = '{$metaKey}' |
76 | 76 | GROUP BY name |
77 | - "); |
|
77 | + " ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * @param string $reviewType |
83 | 83 | * @return array |
84 | 84 | */ |
85 | - public function getReviewIdsByType($reviewType) |
|
85 | + public function getReviewIdsByType( $reviewType ) |
|
86 | 86 | { |
87 | - $results = $this->db->get_col(" |
|
87 | + $results = $this->db->get_col( " |
|
88 | 88 | SELECT DISTINCT m1.meta_value AS review_id |
89 | 89 | FROM {$this->db->posts} AS p |
90 | 90 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | AND m1.meta_key = '_review_id' |
94 | 94 | AND m2.meta_key = '_review_type' |
95 | 95 | AND m2.meta_value = '{$reviewType}' |
96 | - "); |
|
97 | - return array_keys(array_flip($results)); |
|
96 | + " ); |
|
97 | + return array_keys( array_flip( $results ) ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | * @param int $limit |
103 | 103 | * @return array |
104 | 104 | */ |
105 | - public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
105 | + public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 ) |
|
106 | 106 | { |
107 | - sort($postIds); |
|
108 | - $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
109 | - $postIds = implode(',', $postIds); |
|
110 | - return (array) $this->db->get_results(" |
|
107 | + sort( $postIds ); |
|
108 | + $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit ); |
|
109 | + $postIds = implode( ',', $postIds ); |
|
110 | + return (array)$this->db->get_results( " |
|
111 | 111 | SELECT p.ID, m.meta_value AS rating |
112 | 112 | FROM {$this->db->posts} AS p |
113 | 113 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | GROUP BY p.ID |
120 | 120 | ORDER By p.ID ASC |
121 | 121 | LIMIT {$limit} |
122 | - "); |
|
122 | + " ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | * @param string $status |
128 | 128 | * @return array |
129 | 129 | */ |
130 | - public function getReviewsMeta($key, $status = 'publish') |
|
130 | + public function getReviewsMeta( $key, $status = 'publish' ) |
|
131 | 131 | { |
132 | - $key = Str::prefix('_', $key); |
|
133 | - $values = $this->db->get_col(" |
|
132 | + $key = Str::prefix( '_', $key ); |
|
133 | + $values = $this->db->get_col( " |
|
134 | 134 | SELECT DISTINCT m.meta_value |
135 | 135 | FROM {$this->db->postmeta} m |
136 | 136 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | AND p.post_status = '{$status}' |
141 | 141 | GROUP BY p.ID -- remove duplicate meta_value entries |
142 | 142 | ORDER BY m.meta_id ASC -- sort by oldest meta_value |
143 | - "); |
|
144 | - sort($values); |
|
143 | + " ); |
|
144 | + sort( $values ); |
|
145 | 145 | return $values; |
146 | 146 | } |
147 | 147 | |
@@ -149,34 +149,34 @@ discard block |
||
149 | 149 | * @param string $and |
150 | 150 | * @return string |
151 | 151 | */ |
152 | - protected function getAndForCounts(array $args, $and = '') |
|
152 | + protected function getAndForCounts( array $args, $and = '' ) |
|
153 | 153 | { |
154 | - $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', []))); |
|
155 | - $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', []))); |
|
156 | - if (!empty($args['type'])) { |
|
157 | - $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
154 | + $postIds = implode( ',', array_filter( Arr::get( $args, 'post_ids', [] ) ) ); |
|
155 | + $termIds = implode( ',', array_filter( Arr::get( $args, 'term_ids', [] ) ) ); |
|
156 | + if( !empty($args['type']) ) { |
|
157 | + $and .= "AND m2.meta_value = '{$args['type']}' "; |
|
158 | 158 | } |
159 | - if ($postIds) { |
|
160 | - $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
159 | + if( $postIds ) { |
|
160 | + $and .= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
161 | 161 | } |
162 | - if ($termIds) { |
|
163 | - $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
162 | + if( $termIds ) { |
|
163 | + $and .= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
164 | 164 | } |
165 | - return apply_filters('site-reviews/query/and-for-counts', $and); |
|
165 | + return apply_filters( 'site-reviews/query/and-for-counts', $and ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | 169 | * @param string $innerJoin |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
172 | + protected function getInnerJoinForCounts( array $args, $innerJoin = '' ) |
|
173 | 173 | { |
174 | - if (!empty(Arr::get($args, 'post_ids'))) { |
|
175 | - $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
174 | + if( !empty(Arr::get( $args, 'post_ids' )) ) { |
|
175 | + $innerJoin .= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
176 | 176 | } |
177 | - if (!empty(Arr::get($args, 'term_ids'))) { |
|
178 | - $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
177 | + if( !empty(Arr::get( $args, 'term_ids' )) ) { |
|
178 | + $innerJoin .= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
179 | 179 | } |
180 | - return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
180 | + return apply_filters( 'site-reviews/query/inner-join-for-counts', $innerJoin ); |
|
181 | 181 | } |
182 | 182 | } |
@@ -16,204 +16,204 @@ |
||
16 | 16 | |
17 | 17 | class ReviewManager |
18 | 18 | { |
19 | - /** |
|
20 | - * @return false|Review |
|
21 | - */ |
|
22 | - public function create(CreateReview $command) |
|
23 | - { |
|
24 | - $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command); |
|
25 | - $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command); |
|
26 | - $reviewValues = Arr::prefixArrayKeys($reviewValues); |
|
27 | - unset($reviewValues['json']); // @todo remove the need for this |
|
28 | - $postValues = [ |
|
29 | - 'comment_status' => 'closed', |
|
30 | - 'meta_input' => $reviewValues, |
|
31 | - 'ping_status' => 'closed', |
|
32 | - 'post_content' => $reviewValues['_content'], |
|
33 | - 'post_date' => $reviewValues['_date'], |
|
34 | - 'post_date_gmt' => get_gmt_from_date($reviewValues['_date']), |
|
35 | - 'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'], |
|
36 | - 'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted), |
|
37 | - 'post_title' => $reviewValues['_title'], |
|
38 | - 'post_type' => Application::POST_TYPE, |
|
39 | - ]; |
|
40 | - $postId = wp_insert_post($postValues, true); |
|
41 | - if (is_wp_error($postId)) { |
|
42 | - glsr_log()->error($postId->get_error_message())->debug($postValues); |
|
43 | - return false; |
|
44 | - } |
|
45 | - $this->setTerms($postId, $command->category); |
|
46 | - $review = $this->single(get_post($postId)); |
|
47 | - do_action('site-reviews/review/created', $review, $command); |
|
48 | - return $review; |
|
49 | - } |
|
19 | + /** |
|
20 | + * @return false|Review |
|
21 | + */ |
|
22 | + public function create(CreateReview $command) |
|
23 | + { |
|
24 | + $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command); |
|
25 | + $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command); |
|
26 | + $reviewValues = Arr::prefixArrayKeys($reviewValues); |
|
27 | + unset($reviewValues['json']); // @todo remove the need for this |
|
28 | + $postValues = [ |
|
29 | + 'comment_status' => 'closed', |
|
30 | + 'meta_input' => $reviewValues, |
|
31 | + 'ping_status' => 'closed', |
|
32 | + 'post_content' => $reviewValues['_content'], |
|
33 | + 'post_date' => $reviewValues['_date'], |
|
34 | + 'post_date_gmt' => get_gmt_from_date($reviewValues['_date']), |
|
35 | + 'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'], |
|
36 | + 'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted), |
|
37 | + 'post_title' => $reviewValues['_title'], |
|
38 | + 'post_type' => Application::POST_TYPE, |
|
39 | + ]; |
|
40 | + $postId = wp_insert_post($postValues, true); |
|
41 | + if (is_wp_error($postId)) { |
|
42 | + glsr_log()->error($postId->get_error_message())->debug($postValues); |
|
43 | + return false; |
|
44 | + } |
|
45 | + $this->setTerms($postId, $command->category); |
|
46 | + $review = $this->single(get_post($postId)); |
|
47 | + do_action('site-reviews/review/created', $review, $command); |
|
48 | + return $review; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param string $metaReviewId |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function delete($metaReviewId) |
|
56 | - { |
|
57 | - if ($postId = $this->getPostId($metaReviewId)) { |
|
58 | - wp_delete_post($postId, true); |
|
59 | - } |
|
60 | - } |
|
51 | + /** |
|
52 | + * @param string $metaReviewId |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function delete($metaReviewId) |
|
56 | + { |
|
57 | + if ($postId = $this->getPostId($metaReviewId)) { |
|
58 | + wp_delete_post($postId, true); |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return object |
|
64 | - */ |
|
65 | - public function get(array $args = []) |
|
66 | - { |
|
67 | - $args = glsr(ReviewsDefaults::class)->merge($args); |
|
68 | - $metaQuery = glsr(QueryBuilder::class)->buildQuery( |
|
69 | - ['assigned_to', 'email', 'ip_address', 'type', 'rating'], |
|
70 | - $args |
|
71 | - ); |
|
72 | - $taxQuery = glsr(QueryBuilder::class)->buildQuery( |
|
73 | - ['category'], |
|
74 | - ['category' => $this->normalizeTermIds($args['category'])] |
|
75 | - ); |
|
76 | - $paged = glsr(QueryBuilder::class)->getPaged( |
|
77 | - wp_validate_boolean($args['pagination']) |
|
78 | - ); |
|
79 | - $parameters = [ |
|
80 | - 'meta_key' => '_pinned', |
|
81 | - 'meta_query' => $metaQuery, |
|
82 | - 'offset' => $args['offset'], |
|
83 | - 'order' => $args['order'], |
|
84 | - 'orderby' => 'meta_value '.$args['orderby'], |
|
85 | - 'paged' => Arr::get($args, 'paged', $paged), |
|
86 | - 'post__in' => $args['post__in'], |
|
87 | - 'post__not_in' => $args['post__not_in'], |
|
88 | - 'post_status' => 'publish', |
|
89 | - 'post_type' => Application::POST_TYPE, |
|
90 | - 'posts_per_page' => $args['count'], |
|
91 | - 'tax_query' => $taxQuery, |
|
92 | - ]; |
|
93 | - $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args); |
|
94 | - $query = new WP_Query($parameters); |
|
95 | - $results = array_map([$this, 'single'], $query->posts); |
|
96 | - $reviews = new Reviews($results, $query->max_num_pages, $args); |
|
97 | - return apply_filters('site-reviews/get/reviews', $reviews, $query); |
|
98 | - } |
|
62 | + /** |
|
63 | + * @return object |
|
64 | + */ |
|
65 | + public function get(array $args = []) |
|
66 | + { |
|
67 | + $args = glsr(ReviewsDefaults::class)->merge($args); |
|
68 | + $metaQuery = glsr(QueryBuilder::class)->buildQuery( |
|
69 | + ['assigned_to', 'email', 'ip_address', 'type', 'rating'], |
|
70 | + $args |
|
71 | + ); |
|
72 | + $taxQuery = glsr(QueryBuilder::class)->buildQuery( |
|
73 | + ['category'], |
|
74 | + ['category' => $this->normalizeTermIds($args['category'])] |
|
75 | + ); |
|
76 | + $paged = glsr(QueryBuilder::class)->getPaged( |
|
77 | + wp_validate_boolean($args['pagination']) |
|
78 | + ); |
|
79 | + $parameters = [ |
|
80 | + 'meta_key' => '_pinned', |
|
81 | + 'meta_query' => $metaQuery, |
|
82 | + 'offset' => $args['offset'], |
|
83 | + 'order' => $args['order'], |
|
84 | + 'orderby' => 'meta_value '.$args['orderby'], |
|
85 | + 'paged' => Arr::get($args, 'paged', $paged), |
|
86 | + 'post__in' => $args['post__in'], |
|
87 | + 'post__not_in' => $args['post__not_in'], |
|
88 | + 'post_status' => 'publish', |
|
89 | + 'post_type' => Application::POST_TYPE, |
|
90 | + 'posts_per_page' => $args['count'], |
|
91 | + 'tax_query' => $taxQuery, |
|
92 | + ]; |
|
93 | + $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args); |
|
94 | + $query = new WP_Query($parameters); |
|
95 | + $results = array_map([$this, 'single'], $query->posts); |
|
96 | + $reviews = new Reviews($results, $query->max_num_pages, $args); |
|
97 | + return apply_filters('site-reviews/get/reviews', $reviews, $query); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @param string $metaReviewId |
|
102 | - * @return int |
|
103 | - */ |
|
104 | - public function getPostId($metaReviewId) |
|
105 | - { |
|
106 | - return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId); |
|
107 | - } |
|
100 | + /** |
|
101 | + * @param string $metaReviewId |
|
102 | + * @return int |
|
103 | + */ |
|
104 | + public function getPostId($metaReviewId) |
|
105 | + { |
|
106 | + return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public function getRatingCounts(array $args = []) |
|
113 | - { |
|
114 | - $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args); |
|
115 | - $counts = glsr(CountsManager::class)->get([ |
|
116 | - 'post_ids' => Arr::convertStringToArray($args['assigned_to']), |
|
117 | - 'term_ids' => $this->normalizeTermIds($args['category']), |
|
118 | - 'type' => $args['type'], |
|
119 | - ]); |
|
120 | - return glsr(CountsManager::class)->flatten($counts, [ |
|
121 | - 'min' => $args['rating'], |
|
122 | - ]); |
|
123 | - } |
|
109 | + /** |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public function getRatingCounts(array $args = []) |
|
113 | + { |
|
114 | + $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args); |
|
115 | + $counts = glsr(CountsManager::class)->get([ |
|
116 | + 'post_ids' => Arr::convertStringToArray($args['assigned_to']), |
|
117 | + 'term_ids' => $this->normalizeTermIds($args['category']), |
|
118 | + 'type' => $args['type'], |
|
119 | + ]); |
|
120 | + return glsr(CountsManager::class)->flatten($counts, [ |
|
121 | + 'min' => $args['rating'], |
|
122 | + ]); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * @param string $commaSeparatedTermIds |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - public function normalizeTermIds($commaSeparatedTermIds) |
|
130 | - { |
|
131 | - $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id'); |
|
132 | - return array_unique(array_map('intval', $termIds)); |
|
133 | - } |
|
125 | + /** |
|
126 | + * @param string $commaSeparatedTermIds |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + public function normalizeTermIds($commaSeparatedTermIds) |
|
130 | + { |
|
131 | + $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id'); |
|
132 | + return array_unique(array_map('intval', $termIds)); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @param string $commaSeparatedTermIds |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public function normalizeTerms($commaSeparatedTermIds) |
|
140 | - { |
|
141 | - $terms = []; |
|
142 | - $termIds = Arr::convertStringToArray($commaSeparatedTermIds); |
|
143 | - foreach ($termIds as $termId) { |
|
144 | - if (is_numeric($termId)) { |
|
145 | - $termId = intval($termId); |
|
146 | - } |
|
147 | - $term = term_exists($termId, Application::TAXONOMY); |
|
148 | - if (!isset($term['term_id'])) { |
|
149 | - continue; |
|
150 | - } |
|
151 | - $terms[] = $term; |
|
152 | - } |
|
153 | - return $terms; |
|
154 | - } |
|
135 | + /** |
|
136 | + * @param string $commaSeparatedTermIds |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public function normalizeTerms($commaSeparatedTermIds) |
|
140 | + { |
|
141 | + $terms = []; |
|
142 | + $termIds = Arr::convertStringToArray($commaSeparatedTermIds); |
|
143 | + foreach ($termIds as $termId) { |
|
144 | + if (is_numeric($termId)) { |
|
145 | + $termId = intval($termId); |
|
146 | + } |
|
147 | + $term = term_exists($termId, Application::TAXONOMY); |
|
148 | + if (!isset($term['term_id'])) { |
|
149 | + continue; |
|
150 | + } |
|
151 | + $terms[] = $term; |
|
152 | + } |
|
153 | + return $terms; |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * @param int $postId |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - public function revert($postId) |
|
161 | - { |
|
162 | - if (Application::POST_TYPE != get_post_field('post_type', $postId)) { |
|
163 | - return; |
|
164 | - } |
|
165 | - delete_post_meta($postId, '_edit_last'); |
|
166 | - $result = wp_update_post([ |
|
167 | - 'ID' => $postId, |
|
168 | - 'post_content' => glsr(Database::class)->get($postId, 'content'), |
|
169 | - 'post_date' => glsr(Database::class)->get($postId, 'date'), |
|
170 | - 'post_title' => glsr(Database::class)->get($postId, 'title'), |
|
171 | - ]); |
|
172 | - if (is_wp_error($result)) { |
|
173 | - glsr_log()->error($result->get_error_message()); |
|
174 | - return; |
|
175 | - } |
|
176 | - do_action('site-reviews/review/reverted', glsr_get_review($postId)); |
|
177 | - } |
|
156 | + /** |
|
157 | + * @param int $postId |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + public function revert($postId) |
|
161 | + { |
|
162 | + if (Application::POST_TYPE != get_post_field('post_type', $postId)) { |
|
163 | + return; |
|
164 | + } |
|
165 | + delete_post_meta($postId, '_edit_last'); |
|
166 | + $result = wp_update_post([ |
|
167 | + 'ID' => $postId, |
|
168 | + 'post_content' => glsr(Database::class)->get($postId, 'content'), |
|
169 | + 'post_date' => glsr(Database::class)->get($postId, 'date'), |
|
170 | + 'post_title' => glsr(Database::class)->get($postId, 'title'), |
|
171 | + ]); |
|
172 | + if (is_wp_error($result)) { |
|
173 | + glsr_log()->error($result->get_error_message()); |
|
174 | + return; |
|
175 | + } |
|
176 | + do_action('site-reviews/review/reverted', glsr_get_review($postId)); |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * @return Review |
|
181 | - */ |
|
182 | - public function single(WP_Post $post) |
|
183 | - { |
|
184 | - if (Application::POST_TYPE != $post->post_type) { |
|
185 | - $post = new WP_Post((object) []); |
|
186 | - } |
|
187 | - $review = new Review($post); |
|
188 | - return apply_filters('site-reviews/get/review', $review, $post); |
|
189 | - } |
|
179 | + /** |
|
180 | + * @return Review |
|
181 | + */ |
|
182 | + public function single(WP_Post $post) |
|
183 | + { |
|
184 | + if (Application::POST_TYPE != $post->post_type) { |
|
185 | + $post = new WP_Post((object) []); |
|
186 | + } |
|
187 | + $review = new Review($post); |
|
188 | + return apply_filters('site-reviews/get/review', $review, $post); |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * @param bool $isBlacklisted |
|
193 | - * @return string |
|
194 | - */ |
|
195 | - protected function getNewPostStatus(array $reviewValues, $isBlacklisted) |
|
196 | - { |
|
197 | - $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval'); |
|
198 | - return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted) |
|
199 | - ? 'pending' |
|
200 | - : 'publish'; |
|
201 | - } |
|
191 | + /** |
|
192 | + * @param bool $isBlacklisted |
|
193 | + * @return string |
|
194 | + */ |
|
195 | + protected function getNewPostStatus(array $reviewValues, $isBlacklisted) |
|
196 | + { |
|
197 | + $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval'); |
|
198 | + return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted) |
|
199 | + ? 'pending' |
|
200 | + : 'publish'; |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * @param int $postId |
|
205 | - * @param string $termIds |
|
206 | - * @return void |
|
207 | - */ |
|
208 | - protected function setTerms($postId, $termIds) |
|
209 | - { |
|
210 | - $termIds = $this->normalizeTermIds($termIds); |
|
211 | - if (empty($termIds)) { |
|
212 | - return; |
|
213 | - } |
|
214 | - $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY); |
|
215 | - if (is_wp_error($termTaxonomyIds)) { |
|
216 | - glsr_log()->error($termTaxonomyIds->get_error_message()); |
|
217 | - } |
|
218 | - } |
|
203 | + /** |
|
204 | + * @param int $postId |
|
205 | + * @param string $termIds |
|
206 | + * @return void |
|
207 | + */ |
|
208 | + protected function setTerms($postId, $termIds) |
|
209 | + { |
|
210 | + $termIds = $this->normalizeTermIds($termIds); |
|
211 | + if (empty($termIds)) { |
|
212 | + return; |
|
213 | + } |
|
214 | + $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY); |
|
215 | + if (is_wp_error($termTaxonomyIds)) { |
|
216 | + glsr_log()->error($termTaxonomyIds->get_error_message()); |
|
217 | + } |
|
218 | + } |
|
219 | 219 | } |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @return false|Review |
21 | 21 | */ |
22 | - public function create(CreateReview $command) |
|
22 | + public function create( CreateReview $command ) |
|
23 | 23 | { |
24 | - $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command); |
|
25 | - $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command); |
|
26 | - $reviewValues = Arr::prefixArrayKeys($reviewValues); |
|
24 | + $reviewValues = glsr( CreateReviewDefaults::class )->restrict( (array)$command ); |
|
25 | + $reviewValues = apply_filters( 'site-reviews/create/review-values', $reviewValues, $command ); |
|
26 | + $reviewValues = Arr::prefixArrayKeys( $reviewValues ); |
|
27 | 27 | unset($reviewValues['json']); // @todo remove the need for this |
28 | 28 | $postValues = [ |
29 | 29 | 'comment_status' => 'closed', |
@@ -31,20 +31,20 @@ discard block |
||
31 | 31 | 'ping_status' => 'closed', |
32 | 32 | 'post_content' => $reviewValues['_content'], |
33 | 33 | 'post_date' => $reviewValues['_date'], |
34 | - 'post_date_gmt' => get_gmt_from_date($reviewValues['_date']), |
|
34 | + 'post_date_gmt' => get_gmt_from_date( $reviewValues['_date'] ), |
|
35 | 35 | 'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'], |
36 | - 'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted), |
|
36 | + 'post_status' => $this->getNewPostStatus( $reviewValues, $command->blacklisted ), |
|
37 | 37 | 'post_title' => $reviewValues['_title'], |
38 | 38 | 'post_type' => Application::POST_TYPE, |
39 | 39 | ]; |
40 | - $postId = wp_insert_post($postValues, true); |
|
41 | - if (is_wp_error($postId)) { |
|
42 | - glsr_log()->error($postId->get_error_message())->debug($postValues); |
|
40 | + $postId = wp_insert_post( $postValues, true ); |
|
41 | + if( is_wp_error( $postId ) ) { |
|
42 | + glsr_log()->error( $postId->get_error_message() )->debug( $postValues ); |
|
43 | 43 | return false; |
44 | 44 | } |
45 | - $this->setTerms($postId, $command->category); |
|
46 | - $review = $this->single(get_post($postId)); |
|
47 | - do_action('site-reviews/review/created', $review, $command); |
|
45 | + $this->setTerms( $postId, $command->category ); |
|
46 | + $review = $this->single( get_post( $postId ) ); |
|
47 | + do_action( 'site-reviews/review/created', $review, $command ); |
|
48 | 48 | return $review; |
49 | 49 | } |
50 | 50 | |
@@ -52,29 +52,29 @@ discard block |
||
52 | 52 | * @param string $metaReviewId |
53 | 53 | * @return void |
54 | 54 | */ |
55 | - public function delete($metaReviewId) |
|
55 | + public function delete( $metaReviewId ) |
|
56 | 56 | { |
57 | - if ($postId = $this->getPostId($metaReviewId)) { |
|
58 | - wp_delete_post($postId, true); |
|
57 | + if( $postId = $this->getPostId( $metaReviewId ) ) { |
|
58 | + wp_delete_post( $postId, true ); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @return object |
64 | 64 | */ |
65 | - public function get(array $args = []) |
|
65 | + public function get( array $args = [] ) |
|
66 | 66 | { |
67 | - $args = glsr(ReviewsDefaults::class)->merge($args); |
|
68 | - $metaQuery = glsr(QueryBuilder::class)->buildQuery( |
|
67 | + $args = glsr( ReviewsDefaults::class )->merge( $args ); |
|
68 | + $metaQuery = glsr( QueryBuilder::class )->buildQuery( |
|
69 | 69 | ['assigned_to', 'email', 'ip_address', 'type', 'rating'], |
70 | 70 | $args |
71 | 71 | ); |
72 | - $taxQuery = glsr(QueryBuilder::class)->buildQuery( |
|
72 | + $taxQuery = glsr( QueryBuilder::class )->buildQuery( |
|
73 | 73 | ['category'], |
74 | - ['category' => $this->normalizeTermIds($args['category'])] |
|
74 | + ['category' => $this->normalizeTermIds( $args['category'] )] |
|
75 | 75 | ); |
76 | - $paged = glsr(QueryBuilder::class)->getPaged( |
|
77 | - wp_validate_boolean($args['pagination']) |
|
76 | + $paged = glsr( QueryBuilder::class )->getPaged( |
|
77 | + wp_validate_boolean( $args['pagination'] ) |
|
78 | 78 | ); |
79 | 79 | $parameters = [ |
80 | 80 | 'meta_key' => '_pinned', |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | 'offset' => $args['offset'], |
83 | 83 | 'order' => $args['order'], |
84 | 84 | 'orderby' => 'meta_value '.$args['orderby'], |
85 | - 'paged' => Arr::get($args, 'paged', $paged), |
|
85 | + 'paged' => Arr::get( $args, 'paged', $paged ), |
|
86 | 86 | 'post__in' => $args['post__in'], |
87 | 87 | 'post__not_in' => $args['post__not_in'], |
88 | 88 | 'post_status' => 'publish', |
@@ -90,62 +90,62 @@ discard block |
||
90 | 90 | 'posts_per_page' => $args['count'], |
91 | 91 | 'tax_query' => $taxQuery, |
92 | 92 | ]; |
93 | - $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args); |
|
94 | - $query = new WP_Query($parameters); |
|
95 | - $results = array_map([$this, 'single'], $query->posts); |
|
96 | - $reviews = new Reviews($results, $query->max_num_pages, $args); |
|
97 | - return apply_filters('site-reviews/get/reviews', $reviews, $query); |
|
93 | + $parameters = apply_filters( 'site-reviews/get/reviews/query', $parameters, $args ); |
|
94 | + $query = new WP_Query( $parameters ); |
|
95 | + $results = array_map( [$this, 'single'], $query->posts ); |
|
96 | + $reviews = new Reviews( $results, $query->max_num_pages, $args ); |
|
97 | + return apply_filters( 'site-reviews/get/reviews', $reviews, $query ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @param string $metaReviewId |
102 | 102 | * @return int |
103 | 103 | */ |
104 | - public function getPostId($metaReviewId) |
|
104 | + public function getPostId( $metaReviewId ) |
|
105 | 105 | { |
106 | - return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId); |
|
106 | + return glsr( SqlQueries::class )->getPostIdFromReviewId( $metaReviewId ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * @return array |
111 | 111 | */ |
112 | - public function getRatingCounts(array $args = []) |
|
112 | + public function getRatingCounts( array $args = [] ) |
|
113 | 113 | { |
114 | - $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args); |
|
115 | - $counts = glsr(CountsManager::class)->get([ |
|
116 | - 'post_ids' => Arr::convertStringToArray($args['assigned_to']), |
|
117 | - 'term_ids' => $this->normalizeTermIds($args['category']), |
|
114 | + $args = glsr( SiteReviewsSummaryDefaults::class )->filter( $args ); |
|
115 | + $counts = glsr( CountsManager::class )->get( [ |
|
116 | + 'post_ids' => Arr::convertStringToArray( $args['assigned_to'] ), |
|
117 | + 'term_ids' => $this->normalizeTermIds( $args['category'] ), |
|
118 | 118 | 'type' => $args['type'], |
119 | - ]); |
|
120 | - return glsr(CountsManager::class)->flatten($counts, [ |
|
119 | + ] ); |
|
120 | + return glsr( CountsManager::class )->flatten( $counts, [ |
|
121 | 121 | 'min' => $args['rating'], |
122 | - ]); |
|
122 | + ] ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | 126 | * @param string $commaSeparatedTermIds |
127 | 127 | * @return array |
128 | 128 | */ |
129 | - public function normalizeTermIds($commaSeparatedTermIds) |
|
129 | + public function normalizeTermIds( $commaSeparatedTermIds ) |
|
130 | 130 | { |
131 | - $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id'); |
|
132 | - return array_unique(array_map('intval', $termIds)); |
|
131 | + $termIds = glsr_array_column( $this->normalizeTerms( $commaSeparatedTermIds ), 'term_id' ); |
|
132 | + return array_unique( array_map( 'intval', $termIds ) ); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | 136 | * @param string $commaSeparatedTermIds |
137 | 137 | * @return array |
138 | 138 | */ |
139 | - public function normalizeTerms($commaSeparatedTermIds) |
|
139 | + public function normalizeTerms( $commaSeparatedTermIds ) |
|
140 | 140 | { |
141 | 141 | $terms = []; |
142 | - $termIds = Arr::convertStringToArray($commaSeparatedTermIds); |
|
143 | - foreach ($termIds as $termId) { |
|
144 | - if (is_numeric($termId)) { |
|
145 | - $termId = intval($termId); |
|
142 | + $termIds = Arr::convertStringToArray( $commaSeparatedTermIds ); |
|
143 | + foreach( $termIds as $termId ) { |
|
144 | + if( is_numeric( $termId ) ) { |
|
145 | + $termId = intval( $termId ); |
|
146 | 146 | } |
147 | - $term = term_exists($termId, Application::TAXONOMY); |
|
148 | - if (!isset($term['term_id'])) { |
|
147 | + $term = term_exists( $termId, Application::TAXONOMY ); |
|
148 | + if( !isset($term['term_id']) ) { |
|
149 | 149 | continue; |
150 | 150 | } |
151 | 151 | $terms[] = $term; |
@@ -157,44 +157,44 @@ discard block |
||
157 | 157 | * @param int $postId |
158 | 158 | * @return void |
159 | 159 | */ |
160 | - public function revert($postId) |
|
160 | + public function revert( $postId ) |
|
161 | 161 | { |
162 | - if (Application::POST_TYPE != get_post_field('post_type', $postId)) { |
|
162 | + if( Application::POST_TYPE != get_post_field( 'post_type', $postId ) ) { |
|
163 | 163 | return; |
164 | 164 | } |
165 | - delete_post_meta($postId, '_edit_last'); |
|
166 | - $result = wp_update_post([ |
|
165 | + delete_post_meta( $postId, '_edit_last' ); |
|
166 | + $result = wp_update_post( [ |
|
167 | 167 | 'ID' => $postId, |
168 | - 'post_content' => glsr(Database::class)->get($postId, 'content'), |
|
169 | - 'post_date' => glsr(Database::class)->get($postId, 'date'), |
|
170 | - 'post_title' => glsr(Database::class)->get($postId, 'title'), |
|
171 | - ]); |
|
172 | - if (is_wp_error($result)) { |
|
173 | - glsr_log()->error($result->get_error_message()); |
|
168 | + 'post_content' => glsr( Database::class )->get( $postId, 'content' ), |
|
169 | + 'post_date' => glsr( Database::class )->get( $postId, 'date' ), |
|
170 | + 'post_title' => glsr( Database::class )->get( $postId, 'title' ), |
|
171 | + ] ); |
|
172 | + if( is_wp_error( $result ) ) { |
|
173 | + glsr_log()->error( $result->get_error_message() ); |
|
174 | 174 | return; |
175 | 175 | } |
176 | - do_action('site-reviews/review/reverted', glsr_get_review($postId)); |
|
176 | + do_action( 'site-reviews/review/reverted', glsr_get_review( $postId ) ); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * @return Review |
181 | 181 | */ |
182 | - public function single(WP_Post $post) |
|
182 | + public function single( WP_Post $post ) |
|
183 | 183 | { |
184 | - if (Application::POST_TYPE != $post->post_type) { |
|
185 | - $post = new WP_Post((object) []); |
|
184 | + if( Application::POST_TYPE != $post->post_type ) { |
|
185 | + $post = new WP_Post( (object)[] ); |
|
186 | 186 | } |
187 | - $review = new Review($post); |
|
188 | - return apply_filters('site-reviews/get/review', $review, $post); |
|
187 | + $review = new Review( $post ); |
|
188 | + return apply_filters( 'site-reviews/get/review', $review, $post ); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | 192 | * @param bool $isBlacklisted |
193 | 193 | * @return string |
194 | 194 | */ |
195 | - protected function getNewPostStatus(array $reviewValues, $isBlacklisted) |
|
195 | + protected function getNewPostStatus( array $reviewValues, $isBlacklisted ) |
|
196 | 196 | { |
197 | - $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval'); |
|
197 | + $requireApproval = glsr( OptionManager::class )->getBool( 'settings.general.require.approval' ); |
|
198 | 198 | return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted) |
199 | 199 | ? 'pending' |
200 | 200 | : 'publish'; |
@@ -205,15 +205,15 @@ discard block |
||
205 | 205 | * @param string $termIds |
206 | 206 | * @return void |
207 | 207 | */ |
208 | - protected function setTerms($postId, $termIds) |
|
208 | + protected function setTerms( $postId, $termIds ) |
|
209 | 209 | { |
210 | - $termIds = $this->normalizeTermIds($termIds); |
|
211 | - if (empty($termIds)) { |
|
210 | + $termIds = $this->normalizeTermIds( $termIds ); |
|
211 | + if( empty($termIds) ) { |
|
212 | 212 | return; |
213 | 213 | } |
214 | - $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY); |
|
215 | - if (is_wp_error($termTaxonomyIds)) { |
|
216 | - glsr_log()->error($termTaxonomyIds->get_error_message()); |
|
214 | + $termTaxonomyIds = wp_set_object_terms( $postId, $termIds, Application::TAXONOMY ); |
|
215 | + if( is_wp_error( $termTaxonomyIds ) ) { |
|
216 | + glsr_log()->error( $termTaxonomyIds->get_error_message() ); |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | } |
@@ -12,231 +12,231 @@ |
||
12 | 12 | |
13 | 13 | class RebusifyController extends Controller |
14 | 14 | { |
15 | - protected $apiKey = 'settings.general.rebusify_serial'; |
|
16 | - protected $emailKey = 'settings.general.rebusify_email'; |
|
17 | - protected $enabledKey = 'settings.general.rebusify'; |
|
18 | - protected $rebusifyKey = '_glsr_rebusify'; |
|
19 | - |
|
20 | - /** |
|
21 | - * @return array |
|
22 | - * @filter site-reviews/settings/callback |
|
23 | - */ |
|
24 | - public function filterSettingsCallback(array $settings) |
|
25 | - { |
|
26 | - if ('yes' !== Arr::get($settings, $this->enabledKey)) { |
|
27 | - return $settings; |
|
28 | - } |
|
29 | - $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings); |
|
30 | - $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings); |
|
31 | - $isAccountVerified = glsr(OptionManager::class)->getWP($this->rebusifyKey, false); |
|
32 | - if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
33 | - $settings = $this->sanitizeRebusifySettings($settings); |
|
34 | - } |
|
35 | - return $settings; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @param string $template |
|
40 | - * @return array |
|
41 | - * @filter site-reviews/interpolate/partials/form/table-row-multiple |
|
42 | - */ |
|
43 | - public function filterSettingsTableRow(array $context, $template, array $data) |
|
44 | - { |
|
45 | - if ($this->enabledKey !== Arr::get($data, 'field.path')) { |
|
46 | - return $context; |
|
47 | - } |
|
48 | - $rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey); |
|
49 | - if ('P' === $rebusifyProductType) { |
|
50 | - return $context; |
|
51 | - } |
|
52 | - if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) { |
|
53 | - $button = $this->buildUpgradeButton(); |
|
54 | - } else { |
|
55 | - $button = $this->buildCreateButton(); |
|
56 | - } |
|
57 | - $context['field'].= $button; |
|
58 | - return $context; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Triggered when a review is created. |
|
63 | - * @return void |
|
64 | - * @action site-reviews/review/created |
|
65 | - */ |
|
66 | - public function onCreated(Review $review) |
|
67 | - { |
|
68 | - if (!$this->canPostReview($review)) { |
|
69 | - return; |
|
70 | - } |
|
71 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
72 | - if ($rebusify->success) { |
|
73 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Triggered when a review is reverted to its original title/content/date_timestamp. |
|
79 | - * @return void |
|
80 | - * @action site-reviews/review/reverted |
|
81 | - */ |
|
82 | - public function onReverted(Review $review) |
|
83 | - { |
|
84 | - if (!$this->canPostReview($review)) { |
|
85 | - return; |
|
86 | - } |
|
87 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
88 | - if ($rebusify->success) { |
|
89 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Triggered when an existing review is updated. |
|
95 | - * @return void |
|
96 | - * @action site-reviews/review/saved |
|
97 | - */ |
|
98 | - public function onSaved(Review $review) |
|
99 | - { |
|
100 | - if (!$this->canPostReview($review)) { |
|
101 | - return; |
|
102 | - } |
|
103 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
104 | - if ($rebusify->success) { |
|
105 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Triggered when a review's response is added or updated. |
|
111 | - * @param int $metaId |
|
112 | - * @param int $postId |
|
113 | - * @param string $metaKey |
|
114 | - * @return void |
|
115 | - * @action updated_postmeta |
|
116 | - */ |
|
117 | - public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
118 | - { |
|
119 | - $review = glsr_get_review($postId); |
|
120 | - if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
121 | - return; |
|
122 | - } |
|
123 | - $rebusify = glsr(Rebusify::class)->sendReviewResponse($review); |
|
124 | - if ($rebusify->success) { |
|
125 | - glsr(Database::class)->set($review->ID, 'rebusify_response', true); |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - protected function buildCreateButton() |
|
133 | - { |
|
134 | - return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [ |
|
135 | - 'class' => 'button', |
|
136 | - 'href' => Rebusify::WEB_URL, |
|
137 | - 'target' => '_blank', |
|
138 | - ]); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - protected function buildUpgradeButton() |
|
145 | - { |
|
146 | - $build = glsr(Builder::class); |
|
147 | - $notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews')); |
|
148 | - $button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [ |
|
149 | - 'class' => 'button', |
|
150 | - 'href' => Rebusify::WEB_URL, |
|
151 | - 'target' => '_blank', |
|
152 | - ]); |
|
153 | - return $build->div($notice.$button, [ |
|
154 | - 'class' => 'glsr-notice-inline', |
|
155 | - ]); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @return bool |
|
160 | - */ |
|
161 | - protected function canPostResponse(Review $review) |
|
162 | - { |
|
163 | - $requiredValues = [ |
|
164 | - glsr(Database::class)->get($review->ID, 'rebusify'), |
|
165 | - $review->response, |
|
166 | - $review->review_id, |
|
167 | - ]; |
|
168 | - return $this->canProceed($review, 'rebusify_response') |
|
169 | - && 'publish' === $review->status |
|
170 | - && 3 === count(array_filter($requiredValues)); |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - protected function canPostReview(Review $review) |
|
177 | - { |
|
178 | - $requiredValues = [ |
|
179 | - $review->author, |
|
180 | - $review->content, |
|
181 | - $review->rating, |
|
182 | - $review->review_id, |
|
183 | - $review->title, |
|
184 | - ]; |
|
185 | - return $this->canProceed($review) |
|
186 | - && 'publish' === $review->status |
|
187 | - && 5 === count(array_filter($requiredValues)); |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * @param string $metaKey |
|
192 | - * @return bool |
|
193 | - */ |
|
194 | - protected function canProceed(Review $review, $metaKey = 'rebusify') |
|
195 | - { |
|
196 | - return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
197 | - && $this->isReviewPostId($review->ID) |
|
198 | - && !$this->hasMetaKey($review, $metaKey); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @param string $metaKey |
|
203 | - * @return bool |
|
204 | - */ |
|
205 | - protected function hasMetaKey(Review $review, $metaKey = 'rebusify') |
|
206 | - { |
|
207 | - return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @param string $key |
|
212 | - * @return bool |
|
213 | - */ |
|
214 | - protected function isEmptyOrModified($key, array $settings) |
|
215 | - { |
|
216 | - $oldValue = glsr_get_option($key); |
|
217 | - $newValue = Arr::get($settings, $key); |
|
218 | - return empty($newValue) || $newValue !== $oldValue; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * @return array |
|
223 | - */ |
|
224 | - protected function sanitizeRebusifySettings(array $settings) |
|
225 | - { |
|
226 | - $rebusify = glsr(Rebusify::class)->activateKey( |
|
227 | - Arr::get($settings, $this->apiKey), |
|
228 | - Arr::get($settings, $this->emailKey) |
|
229 | - ); |
|
230 | - if ($rebusify->success) { |
|
231 | - update_option($this->rebusifyKey, Arr::get($rebusify->response, 'producttype')); |
|
232 | - } else { |
|
233 | - delete_option($this->rebusifyKey); |
|
234 | - $settings = Arr::set($settings, $this->enabledKey, 'no'); |
|
235 | - glsr(Notice::class)->addError(sprintf( |
|
236 | - __('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'), |
|
237 | - '('.$rebusify->message.')' |
|
238 | - )); |
|
239 | - } |
|
240 | - return $settings; |
|
241 | - } |
|
15 | + protected $apiKey = 'settings.general.rebusify_serial'; |
|
16 | + protected $emailKey = 'settings.general.rebusify_email'; |
|
17 | + protected $enabledKey = 'settings.general.rebusify'; |
|
18 | + protected $rebusifyKey = '_glsr_rebusify'; |
|
19 | + |
|
20 | + /** |
|
21 | + * @return array |
|
22 | + * @filter site-reviews/settings/callback |
|
23 | + */ |
|
24 | + public function filterSettingsCallback(array $settings) |
|
25 | + { |
|
26 | + if ('yes' !== Arr::get($settings, $this->enabledKey)) { |
|
27 | + return $settings; |
|
28 | + } |
|
29 | + $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings); |
|
30 | + $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings); |
|
31 | + $isAccountVerified = glsr(OptionManager::class)->getWP($this->rebusifyKey, false); |
|
32 | + if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
33 | + $settings = $this->sanitizeRebusifySettings($settings); |
|
34 | + } |
|
35 | + return $settings; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @param string $template |
|
40 | + * @return array |
|
41 | + * @filter site-reviews/interpolate/partials/form/table-row-multiple |
|
42 | + */ |
|
43 | + public function filterSettingsTableRow(array $context, $template, array $data) |
|
44 | + { |
|
45 | + if ($this->enabledKey !== Arr::get($data, 'field.path')) { |
|
46 | + return $context; |
|
47 | + } |
|
48 | + $rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey); |
|
49 | + if ('P' === $rebusifyProductType) { |
|
50 | + return $context; |
|
51 | + } |
|
52 | + if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) { |
|
53 | + $button = $this->buildUpgradeButton(); |
|
54 | + } else { |
|
55 | + $button = $this->buildCreateButton(); |
|
56 | + } |
|
57 | + $context['field'].= $button; |
|
58 | + return $context; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Triggered when a review is created. |
|
63 | + * @return void |
|
64 | + * @action site-reviews/review/created |
|
65 | + */ |
|
66 | + public function onCreated(Review $review) |
|
67 | + { |
|
68 | + if (!$this->canPostReview($review)) { |
|
69 | + return; |
|
70 | + } |
|
71 | + $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
72 | + if ($rebusify->success) { |
|
73 | + glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Triggered when a review is reverted to its original title/content/date_timestamp. |
|
79 | + * @return void |
|
80 | + * @action site-reviews/review/reverted |
|
81 | + */ |
|
82 | + public function onReverted(Review $review) |
|
83 | + { |
|
84 | + if (!$this->canPostReview($review)) { |
|
85 | + return; |
|
86 | + } |
|
87 | + $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
88 | + if ($rebusify->success) { |
|
89 | + glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Triggered when an existing review is updated. |
|
95 | + * @return void |
|
96 | + * @action site-reviews/review/saved |
|
97 | + */ |
|
98 | + public function onSaved(Review $review) |
|
99 | + { |
|
100 | + if (!$this->canPostReview($review)) { |
|
101 | + return; |
|
102 | + } |
|
103 | + $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
104 | + if ($rebusify->success) { |
|
105 | + glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Triggered when a review's response is added or updated. |
|
111 | + * @param int $metaId |
|
112 | + * @param int $postId |
|
113 | + * @param string $metaKey |
|
114 | + * @return void |
|
115 | + * @action updated_postmeta |
|
116 | + */ |
|
117 | + public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
118 | + { |
|
119 | + $review = glsr_get_review($postId); |
|
120 | + if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
121 | + return; |
|
122 | + } |
|
123 | + $rebusify = glsr(Rebusify::class)->sendReviewResponse($review); |
|
124 | + if ($rebusify->success) { |
|
125 | + glsr(Database::class)->set($review->ID, 'rebusify_response', true); |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + protected function buildCreateButton() |
|
133 | + { |
|
134 | + return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [ |
|
135 | + 'class' => 'button', |
|
136 | + 'href' => Rebusify::WEB_URL, |
|
137 | + 'target' => '_blank', |
|
138 | + ]); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + protected function buildUpgradeButton() |
|
145 | + { |
|
146 | + $build = glsr(Builder::class); |
|
147 | + $notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews')); |
|
148 | + $button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [ |
|
149 | + 'class' => 'button', |
|
150 | + 'href' => Rebusify::WEB_URL, |
|
151 | + 'target' => '_blank', |
|
152 | + ]); |
|
153 | + return $build->div($notice.$button, [ |
|
154 | + 'class' => 'glsr-notice-inline', |
|
155 | + ]); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @return bool |
|
160 | + */ |
|
161 | + protected function canPostResponse(Review $review) |
|
162 | + { |
|
163 | + $requiredValues = [ |
|
164 | + glsr(Database::class)->get($review->ID, 'rebusify'), |
|
165 | + $review->response, |
|
166 | + $review->review_id, |
|
167 | + ]; |
|
168 | + return $this->canProceed($review, 'rebusify_response') |
|
169 | + && 'publish' === $review->status |
|
170 | + && 3 === count(array_filter($requiredValues)); |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + protected function canPostReview(Review $review) |
|
177 | + { |
|
178 | + $requiredValues = [ |
|
179 | + $review->author, |
|
180 | + $review->content, |
|
181 | + $review->rating, |
|
182 | + $review->review_id, |
|
183 | + $review->title, |
|
184 | + ]; |
|
185 | + return $this->canProceed($review) |
|
186 | + && 'publish' === $review->status |
|
187 | + && 5 === count(array_filter($requiredValues)); |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * @param string $metaKey |
|
192 | + * @return bool |
|
193 | + */ |
|
194 | + protected function canProceed(Review $review, $metaKey = 'rebusify') |
|
195 | + { |
|
196 | + return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
197 | + && $this->isReviewPostId($review->ID) |
|
198 | + && !$this->hasMetaKey($review, $metaKey); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @param string $metaKey |
|
203 | + * @return bool |
|
204 | + */ |
|
205 | + protected function hasMetaKey(Review $review, $metaKey = 'rebusify') |
|
206 | + { |
|
207 | + return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @param string $key |
|
212 | + * @return bool |
|
213 | + */ |
|
214 | + protected function isEmptyOrModified($key, array $settings) |
|
215 | + { |
|
216 | + $oldValue = glsr_get_option($key); |
|
217 | + $newValue = Arr::get($settings, $key); |
|
218 | + return empty($newValue) || $newValue !== $oldValue; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * @return array |
|
223 | + */ |
|
224 | + protected function sanitizeRebusifySettings(array $settings) |
|
225 | + { |
|
226 | + $rebusify = glsr(Rebusify::class)->activateKey( |
|
227 | + Arr::get($settings, $this->apiKey), |
|
228 | + Arr::get($settings, $this->emailKey) |
|
229 | + ); |
|
230 | + if ($rebusify->success) { |
|
231 | + update_option($this->rebusifyKey, Arr::get($rebusify->response, 'producttype')); |
|
232 | + } else { |
|
233 | + delete_option($this->rebusifyKey); |
|
234 | + $settings = Arr::set($settings, $this->enabledKey, 'no'); |
|
235 | + glsr(Notice::class)->addError(sprintf( |
|
236 | + __('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'), |
|
237 | + '('.$rebusify->message.')' |
|
238 | + )); |
|
239 | + } |
|
240 | + return $settings; |
|
241 | + } |
|
242 | 242 | } |
@@ -21,16 +21,16 @@ discard block |
||
21 | 21 | * @return array |
22 | 22 | * @filter site-reviews/settings/callback |
23 | 23 | */ |
24 | - public function filterSettingsCallback(array $settings) |
|
24 | + public function filterSettingsCallback( array $settings ) |
|
25 | 25 | { |
26 | - if ('yes' !== Arr::get($settings, $this->enabledKey)) { |
|
26 | + if( 'yes' !== Arr::get( $settings, $this->enabledKey ) ) { |
|
27 | 27 | return $settings; |
28 | 28 | } |
29 | - $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings); |
|
30 | - $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings); |
|
31 | - $isAccountVerified = glsr(OptionManager::class)->getWP($this->rebusifyKey, false); |
|
32 | - if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
33 | - $settings = $this->sanitizeRebusifySettings($settings); |
|
29 | + $isApiKeyModified = $this->isEmptyOrModified( $this->apiKey, $settings ); |
|
30 | + $isEmailModified = $this->isEmptyOrModified( $this->emailKey, $settings ); |
|
31 | + $isAccountVerified = glsr( OptionManager::class )->getWP( $this->rebusifyKey, false ); |
|
32 | + if( !$isAccountVerified || $isApiKeyModified || $isEmailModified ) { |
|
33 | + $settings = $this->sanitizeRebusifySettings( $settings ); |
|
34 | 34 | } |
35 | 35 | return $settings; |
36 | 36 | } |
@@ -40,21 +40,21 @@ discard block |
||
40 | 40 | * @return array |
41 | 41 | * @filter site-reviews/interpolate/partials/form/table-row-multiple |
42 | 42 | */ |
43 | - public function filterSettingsTableRow(array $context, $template, array $data) |
|
43 | + public function filterSettingsTableRow( array $context, $template, array $data ) |
|
44 | 44 | { |
45 | - if ($this->enabledKey !== Arr::get($data, 'field.path')) { |
|
45 | + if( $this->enabledKey !== Arr::get( $data, 'field.path' ) ) { |
|
46 | 46 | return $context; |
47 | 47 | } |
48 | - $rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey); |
|
49 | - if ('P' === $rebusifyProductType) { |
|
48 | + $rebusifyProductType = glsr( OptionManager::class )->getWP( $this->rebusifyKey ); |
|
49 | + if( 'P' === $rebusifyProductType ) { |
|
50 | 50 | return $context; |
51 | 51 | } |
52 | - if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) { |
|
52 | + if( 'F' === $rebusifyProductType && 'yes' === glsr_get_option( 'general.rebusify' ) ) { |
|
53 | 53 | $button = $this->buildUpgradeButton(); |
54 | 54 | } else { |
55 | 55 | $button = $this->buildCreateButton(); |
56 | 56 | } |
57 | - $context['field'].= $button; |
|
57 | + $context['field'] .= $button; |
|
58 | 58 | return $context; |
59 | 59 | } |
60 | 60 | |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | * @return void |
64 | 64 | * @action site-reviews/review/created |
65 | 65 | */ |
66 | - public function onCreated(Review $review) |
|
66 | + public function onCreated( Review $review ) |
|
67 | 67 | { |
68 | - if (!$this->canPostReview($review)) { |
|
68 | + if( !$this->canPostReview( $review ) ) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
72 | - if ($rebusify->success) { |
|
73 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
71 | + $rebusify = glsr( Rebusify::class )->sendReview( $review ); |
|
72 | + if( $rebusify->success ) { |
|
73 | + glsr( Database::class )->set( $review->ID, 'rebusify', $rebusify->review_id ); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | * @return void |
80 | 80 | * @action site-reviews/review/reverted |
81 | 81 | */ |
82 | - public function onReverted(Review $review) |
|
82 | + public function onReverted( Review $review ) |
|
83 | 83 | { |
84 | - if (!$this->canPostReview($review)) { |
|
84 | + if( !$this->canPostReview( $review ) ) { |
|
85 | 85 | return; |
86 | 86 | } |
87 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
88 | - if ($rebusify->success) { |
|
89 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
87 | + $rebusify = glsr( Rebusify::class )->sendReview( $review ); |
|
88 | + if( $rebusify->success ) { |
|
89 | + glsr( Database::class )->set( $review->ID, 'rebusify', $rebusify->review_id ); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | * @return void |
96 | 96 | * @action site-reviews/review/saved |
97 | 97 | */ |
98 | - public function onSaved(Review $review) |
|
98 | + public function onSaved( Review $review ) |
|
99 | 99 | { |
100 | - if (!$this->canPostReview($review)) { |
|
100 | + if( !$this->canPostReview( $review ) ) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
104 | - if ($rebusify->success) { |
|
105 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
103 | + $rebusify = glsr( Rebusify::class )->sendReview( $review ); |
|
104 | + if( $rebusify->success ) { |
|
105 | + glsr( Database::class )->set( $review->ID, 'rebusify', $rebusify->review_id ); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -114,15 +114,15 @@ discard block |
||
114 | 114 | * @return void |
115 | 115 | * @action updated_postmeta |
116 | 116 | */ |
117 | - public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
117 | + public function onUpdatedMeta( $metaId, $postId, $metaKey ) |
|
118 | 118 | { |
119 | - $review = glsr_get_review($postId); |
|
120 | - if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
119 | + $review = glsr_get_review( $postId ); |
|
120 | + if( !$this->canPostResponse( $review ) || '_response' !== $metaKey ) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | - $rebusify = glsr(Rebusify::class)->sendReviewResponse($review); |
|
124 | - if ($rebusify->success) { |
|
125 | - glsr(Database::class)->set($review->ID, 'rebusify_response', true); |
|
123 | + $rebusify = glsr( Rebusify::class )->sendReviewResponse( $review ); |
|
124 | + if( $rebusify->success ) { |
|
125 | + glsr( Database::class )->set( $review->ID, 'rebusify_response', true ); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | */ |
132 | 132 | protected function buildCreateButton() |
133 | 133 | { |
134 | - return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [ |
|
134 | + return glsr( Builder::class )->a( __( 'Create Your Rebusify Account', 'site-reviews' ), [ |
|
135 | 135 | 'class' => 'button', |
136 | 136 | 'href' => Rebusify::WEB_URL, |
137 | 137 | 'target' => '_blank', |
138 | - ]); |
|
138 | + ] ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -143,37 +143,37 @@ discard block |
||
143 | 143 | */ |
144 | 144 | protected function buildUpgradeButton() |
145 | 145 | { |
146 | - $build = glsr(Builder::class); |
|
147 | - $notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews')); |
|
148 | - $button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [ |
|
146 | + $build = glsr( Builder::class ); |
|
147 | + $notice = $build->p( __( 'Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews' ) ); |
|
148 | + $button = $build->a( __( 'Upgrade Your Rebusify Plan', 'site-reviews' ), [ |
|
149 | 149 | 'class' => 'button', |
150 | 150 | 'href' => Rebusify::WEB_URL, |
151 | 151 | 'target' => '_blank', |
152 | - ]); |
|
153 | - return $build->div($notice.$button, [ |
|
152 | + ] ); |
|
153 | + return $build->div( $notice.$button, [ |
|
154 | 154 | 'class' => 'glsr-notice-inline', |
155 | - ]); |
|
155 | + ] ); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
159 | 159 | * @return bool |
160 | 160 | */ |
161 | - protected function canPostResponse(Review $review) |
|
161 | + protected function canPostResponse( Review $review ) |
|
162 | 162 | { |
163 | 163 | $requiredValues = [ |
164 | - glsr(Database::class)->get($review->ID, 'rebusify'), |
|
164 | + glsr( Database::class )->get( $review->ID, 'rebusify' ), |
|
165 | 165 | $review->response, |
166 | 166 | $review->review_id, |
167 | 167 | ]; |
168 | - return $this->canProceed($review, 'rebusify_response') |
|
168 | + return $this->canProceed( $review, 'rebusify_response' ) |
|
169 | 169 | && 'publish' === $review->status |
170 | - && 3 === count(array_filter($requiredValues)); |
|
170 | + && 3 === count( array_filter( $requiredValues ) ); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
174 | 174 | * @return bool |
175 | 175 | */ |
176 | - protected function canPostReview(Review $review) |
|
176 | + protected function canPostReview( Review $review ) |
|
177 | 177 | { |
178 | 178 | $requiredValues = [ |
179 | 179 | $review->author, |
@@ -182,60 +182,60 @@ discard block |
||
182 | 182 | $review->review_id, |
183 | 183 | $review->title, |
184 | 184 | ]; |
185 | - return $this->canProceed($review) |
|
185 | + return $this->canProceed( $review ) |
|
186 | 186 | && 'publish' === $review->status |
187 | - && 5 === count(array_filter($requiredValues)); |
|
187 | + && 5 === count( array_filter( $requiredValues ) ); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | 191 | * @param string $metaKey |
192 | 192 | * @return bool |
193 | 193 | */ |
194 | - protected function canProceed(Review $review, $metaKey = 'rebusify') |
|
194 | + protected function canProceed( Review $review, $metaKey = 'rebusify' ) |
|
195 | 195 | { |
196 | - return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
197 | - && $this->isReviewPostId($review->ID) |
|
198 | - && !$this->hasMetaKey($review, $metaKey); |
|
196 | + return glsr( OptionManager::class )->getBool( $this->enabledKey ) |
|
197 | + && $this->isReviewPostId( $review->ID ) |
|
198 | + && !$this->hasMetaKey( $review, $metaKey ); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
202 | 202 | * @param string $metaKey |
203 | 203 | * @return bool |
204 | 204 | */ |
205 | - protected function hasMetaKey(Review $review, $metaKey = 'rebusify') |
|
205 | + protected function hasMetaKey( Review $review, $metaKey = 'rebusify' ) |
|
206 | 206 | { |
207 | - return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
207 | + return '' !== glsr( Database::class )->get( $review->ID, $metaKey ); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
211 | 211 | * @param string $key |
212 | 212 | * @return bool |
213 | 213 | */ |
214 | - protected function isEmptyOrModified($key, array $settings) |
|
214 | + protected function isEmptyOrModified( $key, array $settings ) |
|
215 | 215 | { |
216 | - $oldValue = glsr_get_option($key); |
|
217 | - $newValue = Arr::get($settings, $key); |
|
216 | + $oldValue = glsr_get_option( $key ); |
|
217 | + $newValue = Arr::get( $settings, $key ); |
|
218 | 218 | return empty($newValue) || $newValue !== $oldValue; |
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
222 | 222 | * @return array |
223 | 223 | */ |
224 | - protected function sanitizeRebusifySettings(array $settings) |
|
224 | + protected function sanitizeRebusifySettings( array $settings ) |
|
225 | 225 | { |
226 | - $rebusify = glsr(Rebusify::class)->activateKey( |
|
227 | - Arr::get($settings, $this->apiKey), |
|
228 | - Arr::get($settings, $this->emailKey) |
|
226 | + $rebusify = glsr( Rebusify::class )->activateKey( |
|
227 | + Arr::get( $settings, $this->apiKey ), |
|
228 | + Arr::get( $settings, $this->emailKey ) |
|
229 | 229 | ); |
230 | - if ($rebusify->success) { |
|
231 | - update_option($this->rebusifyKey, Arr::get($rebusify->response, 'producttype')); |
|
230 | + if( $rebusify->success ) { |
|
231 | + update_option( $this->rebusifyKey, Arr::get( $rebusify->response, 'producttype' ) ); |
|
232 | 232 | } else { |
233 | - delete_option($this->rebusifyKey); |
|
234 | - $settings = Arr::set($settings, $this->enabledKey, 'no'); |
|
235 | - glsr(Notice::class)->addError(sprintf( |
|
236 | - __('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'), |
|
233 | + delete_option( $this->rebusifyKey ); |
|
234 | + $settings = Arr::set( $settings, $this->enabledKey, 'no' ); |
|
235 | + glsr( Notice::class )->addError( sprintf( |
|
236 | + __( 'Your Rebusify account details could not be verified, please try again. %s', 'site-reviews' ), |
|
237 | 237 | '('.$rebusify->message.')' |
238 | - )); |
|
238 | + ) ); |
|
239 | 239 | } |
240 | 240 | return $settings; |
241 | 241 | } |
@@ -51,7 +51,8 @@ discard block |
||
51 | 51 | } |
52 | 52 | if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) { |
53 | 53 | $button = $this->buildUpgradeButton(); |
54 | - } else { |
|
54 | + } |
|
55 | + else { |
|
55 | 56 | $button = $this->buildCreateButton(); |
56 | 57 | } |
57 | 58 | $context['field'].= $button; |
@@ -229,7 +230,8 @@ discard block |
||
229 | 230 | ); |
230 | 231 | if ($rebusify->success) { |
231 | 232 | update_option($this->rebusifyKey, Arr::get($rebusify->response, 'producttype')); |
232 | - } else { |
|
233 | + } |
|
234 | + else { |
|
233 | 235 | delete_option($this->rebusifyKey); |
234 | 236 | $settings = Arr::set($settings, $this->enabledKey, 'no'); |
235 | 237 | glsr(Notice::class)->addError(sprintf( |
@@ -13,163 +13,163 @@ |
||
13 | 13 | |
14 | 14 | class AjaxController extends Controller |
15 | 15 | { |
16 | - /** |
|
17 | - * @return void |
|
18 | - */ |
|
19 | - public function routerChangeStatus(array $request) |
|
20 | - { |
|
21 | - wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
22 | - } |
|
16 | + /** |
|
17 | + * @return void |
|
18 | + */ |
|
19 | + public function routerChangeStatus(array $request) |
|
20 | + { |
|
21 | + wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * @return void |
|
26 | - */ |
|
27 | - public function routerClearConsole() |
|
28 | - { |
|
29 | - glsr(AdminController::class)->routerClearConsole(); |
|
30 | - wp_send_json_success([ |
|
31 | - 'console' => glsr(Console::class)->get(), |
|
32 | - 'notices' => glsr(Notice::class)->get(), |
|
33 | - ]); |
|
34 | - } |
|
24 | + /** |
|
25 | + * @return void |
|
26 | + */ |
|
27 | + public function routerClearConsole() |
|
28 | + { |
|
29 | + glsr(AdminController::class)->routerClearConsole(); |
|
30 | + wp_send_json_success([ |
|
31 | + 'console' => glsr(Console::class)->get(), |
|
32 | + 'notices' => glsr(Notice::class)->get(), |
|
33 | + ]); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function routerCountReviews() |
|
40 | - { |
|
41 | - glsr(AdminController::class)->routerCountReviews(); |
|
42 | - wp_send_json_success([ |
|
43 | - 'notices' => glsr(Notice::class)->get(), |
|
44 | - ]); |
|
45 | - } |
|
36 | + /** |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function routerCountReviews() |
|
40 | + { |
|
41 | + glsr(AdminController::class)->routerCountReviews(); |
|
42 | + wp_send_json_success([ |
|
43 | + 'notices' => glsr(Notice::class)->get(), |
|
44 | + ]); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @return void |
|
49 | - */ |
|
50 | - public function routerDismissNotice(array $request) |
|
51 | - { |
|
52 | - glsr(NoticeController::class)->routerDismissNotice($request); |
|
53 | - wp_send_json_success(); |
|
54 | - } |
|
47 | + /** |
|
48 | + * @return void |
|
49 | + */ |
|
50 | + public function routerDismissNotice(array $request) |
|
51 | + { |
|
52 | + glsr(NoticeController::class)->routerDismissNotice($request); |
|
53 | + wp_send_json_success(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - public function routerMceShortcode(array $request) |
|
60 | - { |
|
61 | - $shortcode = $request['shortcode']; |
|
62 | - $response = false; |
|
63 | - if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
64 | - $data = glsr()->mceShortcodes[$shortcode]; |
|
65 | - if (!empty($data['errors'])) { |
|
66 | - $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
67 | - } |
|
68 | - $response = [ |
|
69 | - 'body' => $data['fields'], |
|
70 | - 'close' => $data['btn_close'], |
|
71 | - 'ok' => $data['btn_okay'], |
|
72 | - 'shortcode' => $shortcode, |
|
73 | - 'title' => $data['title'], |
|
74 | - ]; |
|
75 | - } |
|
76 | - wp_send_json_success($response); |
|
77 | - } |
|
56 | + /** |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + public function routerMceShortcode(array $request) |
|
60 | + { |
|
61 | + $shortcode = $request['shortcode']; |
|
62 | + $response = false; |
|
63 | + if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
64 | + $data = glsr()->mceShortcodes[$shortcode]; |
|
65 | + if (!empty($data['errors'])) { |
|
66 | + $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
67 | + } |
|
68 | + $response = [ |
|
69 | + 'body' => $data['fields'], |
|
70 | + 'close' => $data['btn_close'], |
|
71 | + 'ok' => $data['btn_okay'], |
|
72 | + 'shortcode' => $shortcode, |
|
73 | + 'title' => $data['title'], |
|
74 | + ]; |
|
75 | + } |
|
76 | + wp_send_json_success($response); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public function routerFetchConsole() |
|
83 | - { |
|
84 | - glsr(AdminController::class)->routerFetchConsole(); |
|
85 | - wp_send_json_success([ |
|
86 | - 'console' => glsr(Console::class)->get(), |
|
87 | - 'notices' => glsr(Notice::class)->get(), |
|
88 | - ]); |
|
89 | - } |
|
79 | + /** |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public function routerFetchConsole() |
|
83 | + { |
|
84 | + glsr(AdminController::class)->routerFetchConsole(); |
|
85 | + wp_send_json_success([ |
|
86 | + 'console' => glsr(Console::class)->get(), |
|
87 | + 'notices' => glsr(Notice::class)->get(), |
|
88 | + ]); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public function routerSearchPosts(array $request) |
|
95 | - { |
|
96 | - $results = glsr(Database::class)->searchPosts($request['search']); |
|
97 | - wp_send_json_success([ |
|
98 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
99 | - 'items' => $results, |
|
100 | - ]); |
|
101 | - } |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public function routerSearchPosts(array $request) |
|
95 | + { |
|
96 | + $results = glsr(Database::class)->searchPosts($request['search']); |
|
97 | + wp_send_json_success([ |
|
98 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
99 | + 'items' => $results, |
|
100 | + ]); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public function routerSearchTranslations(array $request) |
|
107 | - { |
|
108 | - if (empty($request['exclude'])) { |
|
109 | - $request['exclude'] = []; |
|
110 | - } |
|
111 | - $results = glsr(Translation::class) |
|
112 | - ->search($request['search']) |
|
113 | - ->exclude() |
|
114 | - ->exclude($request['exclude']) |
|
115 | - ->renderResults(); |
|
116 | - wp_send_json_success([ |
|
117 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
118 | - 'items' => $results, |
|
119 | - ]); |
|
120 | - } |
|
103 | + /** |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public function routerSearchTranslations(array $request) |
|
107 | + { |
|
108 | + if (empty($request['exclude'])) { |
|
109 | + $request['exclude'] = []; |
|
110 | + } |
|
111 | + $results = glsr(Translation::class) |
|
112 | + ->search($request['search']) |
|
113 | + ->exclude() |
|
114 | + ->exclude($request['exclude']) |
|
115 | + ->renderResults(); |
|
116 | + wp_send_json_success([ |
|
117 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
118 | + 'items' => $results, |
|
119 | + ]); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public function routerSubmitReview(array $request) |
|
126 | - { |
|
127 | - $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
128 | - $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
129 | - $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
130 | - $data = [ |
|
131 | - 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
132 | - 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
133 | - 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
134 | - 'redirect' => $redirect, |
|
135 | - ]; |
|
136 | - if (false === $data['errors']) { |
|
137 | - glsr()->sessionClear(); |
|
138 | - wp_send_json_success($data); |
|
139 | - } |
|
140 | - wp_send_json_error($data); |
|
141 | - } |
|
122 | + /** |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public function routerSubmitReview(array $request) |
|
126 | + { |
|
127 | + $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
128 | + $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
129 | + $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
130 | + $data = [ |
|
131 | + 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
132 | + 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
133 | + 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
134 | + 'redirect' => $redirect, |
|
135 | + ]; |
|
136 | + if (false === $data['errors']) { |
|
137 | + glsr()->sessionClear(); |
|
138 | + wp_send_json_success($data); |
|
139 | + } |
|
140 | + wp_send_json_error($data); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public function routerFetchPagedReviews(array $request) |
|
147 | - { |
|
148 | - $urlQuery = []; |
|
149 | - parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
150 | - $args = [ |
|
151 | - 'paged' => Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
152 | - 'pagedUrl' => home_url(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)), |
|
153 | - 'pagination' => 'ajax', |
|
154 | - 'schema' => false, |
|
155 | - ]; |
|
156 | - $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
157 | - $html = glsr(SiteReviews::class)->build(wp_parse_args($args, $atts)); |
|
158 | - return wp_send_json_success([ |
|
159 | - 'pagination' => $html->getPagination(), |
|
160 | - 'reviews' => $html->getReviews(), |
|
161 | - ]); |
|
162 | - } |
|
143 | + /** |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public function routerFetchPagedReviews(array $request) |
|
147 | + { |
|
148 | + $urlQuery = []; |
|
149 | + parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
150 | + $args = [ |
|
151 | + 'paged' => Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
152 | + 'pagedUrl' => home_url(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)), |
|
153 | + 'pagination' => 'ajax', |
|
154 | + 'schema' => false, |
|
155 | + ]; |
|
156 | + $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
157 | + $html = glsr(SiteReviews::class)->build(wp_parse_args($args, $atts)); |
|
158 | + return wp_send_json_success([ |
|
159 | + 'pagination' => $html->getPagination(), |
|
160 | + 'reviews' => $html->getReviews(), |
|
161 | + ]); |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - public function routerTogglePinned(array $request) |
|
168 | - { |
|
169 | - $isPinned = $this->execute(new TogglePinned($request)); |
|
170 | - wp_send_json_success([ |
|
171 | - 'notices' => glsr(Notice::class)->get(), |
|
172 | - 'pinned' => $isPinned, |
|
173 | - ]); |
|
174 | - } |
|
164 | + /** |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + public function routerTogglePinned(array $request) |
|
168 | + { |
|
169 | + $isPinned = $this->execute(new TogglePinned($request)); |
|
170 | + wp_send_json_success([ |
|
171 | + 'notices' => glsr(Notice::class)->get(), |
|
172 | + 'pinned' => $isPinned, |
|
173 | + ]); |
|
174 | + } |
|
175 | 175 | } |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * @return void |
18 | 18 | */ |
19 | - public function routerChangeStatus(array $request) |
|
19 | + public function routerChangeStatus( array $request ) |
|
20 | 20 | { |
21 | - wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
21 | + wp_send_json_success( $this->execute( new ChangeStatus( $request ) ) ); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -26,11 +26,11 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function routerClearConsole() |
28 | 28 | { |
29 | - glsr(AdminController::class)->routerClearConsole(); |
|
30 | - wp_send_json_success([ |
|
31 | - 'console' => glsr(Console::class)->get(), |
|
32 | - 'notices' => glsr(Notice::class)->get(), |
|
33 | - ]); |
|
29 | + glsr( AdminController::class )->routerClearConsole(); |
|
30 | + wp_send_json_success( [ |
|
31 | + 'console' => glsr( Console::class )->get(), |
|
32 | + 'notices' => glsr( Notice::class )->get(), |
|
33 | + ] ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,32 +38,32 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function routerCountReviews() |
40 | 40 | { |
41 | - glsr(AdminController::class)->routerCountReviews(); |
|
42 | - wp_send_json_success([ |
|
43 | - 'notices' => glsr(Notice::class)->get(), |
|
44 | - ]); |
|
41 | + glsr( AdminController::class )->routerCountReviews(); |
|
42 | + wp_send_json_success( [ |
|
43 | + 'notices' => glsr( Notice::class )->get(), |
|
44 | + ] ); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @return void |
49 | 49 | */ |
50 | - public function routerDismissNotice(array $request) |
|
50 | + public function routerDismissNotice( array $request ) |
|
51 | 51 | { |
52 | - glsr(NoticeController::class)->routerDismissNotice($request); |
|
52 | + glsr( NoticeController::class )->routerDismissNotice( $request ); |
|
53 | 53 | wp_send_json_success(); |
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * @return void |
58 | 58 | */ |
59 | - public function routerMceShortcode(array $request) |
|
59 | + public function routerMceShortcode( array $request ) |
|
60 | 60 | { |
61 | 61 | $shortcode = $request['shortcode']; |
62 | 62 | $response = false; |
63 | - if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
63 | + if( array_key_exists( $shortcode, glsr()->mceShortcodes ) ) { |
|
64 | 64 | $data = glsr()->mceShortcodes[$shortcode]; |
65 | - if (!empty($data['errors'])) { |
|
66 | - $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
65 | + if( !empty($data['errors']) ) { |
|
66 | + $data['btn_okay'] = [esc_html__( 'Okay', 'site-reviews' )]; |
|
67 | 67 | } |
68 | 68 | $response = [ |
69 | 69 | 'body' => $data['fields'], |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | 'title' => $data['title'], |
74 | 74 | ]; |
75 | 75 | } |
76 | - wp_send_json_success($response); |
|
76 | + wp_send_json_success( $response ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -81,95 +81,95 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function routerFetchConsole() |
83 | 83 | { |
84 | - glsr(AdminController::class)->routerFetchConsole(); |
|
85 | - wp_send_json_success([ |
|
86 | - 'console' => glsr(Console::class)->get(), |
|
87 | - 'notices' => glsr(Notice::class)->get(), |
|
88 | - ]); |
|
84 | + glsr( AdminController::class )->routerFetchConsole(); |
|
85 | + wp_send_json_success( [ |
|
86 | + 'console' => glsr( Console::class )->get(), |
|
87 | + 'notices' => glsr( Notice::class )->get(), |
|
88 | + ] ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | 92 | * @return void |
93 | 93 | */ |
94 | - public function routerSearchPosts(array $request) |
|
94 | + public function routerSearchPosts( array $request ) |
|
95 | 95 | { |
96 | - $results = glsr(Database::class)->searchPosts($request['search']); |
|
97 | - wp_send_json_success([ |
|
98 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
96 | + $results = glsr( Database::class )->searchPosts( $request['search'] ); |
|
97 | + wp_send_json_success( [ |
|
98 | + 'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>', |
|
99 | 99 | 'items' => $results, |
100 | - ]); |
|
100 | + ] ); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | 104 | * @return void |
105 | 105 | */ |
106 | - public function routerSearchTranslations(array $request) |
|
106 | + public function routerSearchTranslations( array $request ) |
|
107 | 107 | { |
108 | - if (empty($request['exclude'])) { |
|
108 | + if( empty($request['exclude']) ) { |
|
109 | 109 | $request['exclude'] = []; |
110 | 110 | } |
111 | - $results = glsr(Translation::class) |
|
112 | - ->search($request['search']) |
|
111 | + $results = glsr( Translation::class ) |
|
112 | + ->search( $request['search'] ) |
|
113 | 113 | ->exclude() |
114 | - ->exclude($request['exclude']) |
|
114 | + ->exclude( $request['exclude'] ) |
|
115 | 115 | ->renderResults(); |
116 | - wp_send_json_success([ |
|
117 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
116 | + wp_send_json_success( [ |
|
117 | + 'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>', |
|
118 | 118 | 'items' => $results, |
119 | - ]); |
|
119 | + ] ); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @return void |
124 | 124 | */ |
125 | - public function routerSubmitReview(array $request) |
|
125 | + public function routerSubmitReview( array $request ) |
|
126 | 126 | { |
127 | - $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
128 | - $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
129 | - $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
127 | + $command = glsr( PublicController::class )->routerSubmitReview( $request ); |
|
128 | + $redirect = trim( strval( get_post_meta( $command->post_id, 'redirect_to', true ) ) ); |
|
129 | + $redirect = apply_filters( 'site-reviews/review/redirect', $redirect, $command ); |
|
130 | 130 | $data = [ |
131 | - 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
132 | - 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
133 | - 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
131 | + 'errors' => glsr()->sessionGet( $command->form_id.'errors', false ), |
|
132 | + 'message' => glsr()->sessionGet( $command->form_id.'message', '' ), |
|
133 | + 'recaptcha' => glsr()->sessionGet( $command->form_id.'recaptcha', false ), |
|
134 | 134 | 'redirect' => $redirect, |
135 | 135 | ]; |
136 | - if (false === $data['errors']) { |
|
136 | + if( false === $data['errors'] ) { |
|
137 | 137 | glsr()->sessionClear(); |
138 | - wp_send_json_success($data); |
|
138 | + wp_send_json_success( $data ); |
|
139 | 139 | } |
140 | - wp_send_json_error($data); |
|
140 | + wp_send_json_error( $data ); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
144 | 144 | * @return void |
145 | 145 | */ |
146 | - public function routerFetchPagedReviews(array $request) |
|
146 | + public function routerFetchPagedReviews( array $request ) |
|
147 | 147 | { |
148 | 148 | $urlQuery = []; |
149 | - parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
149 | + parse_str( parse_url( Arr::get( $request, 'url' ), PHP_URL_QUERY ), $urlQuery ); |
|
150 | 150 | $args = [ |
151 | - 'paged' => Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
152 | - 'pagedUrl' => home_url(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)), |
|
151 | + 'paged' => Arr::get( $urlQuery, glsr()->constant( 'PAGED_QUERY_VAR' ), 1 ), |
|
152 | + 'pagedUrl' => home_url( parse_url( Arr::get( $request, 'url' ), PHP_URL_PATH ) ), |
|
153 | 153 | 'pagination' => 'ajax', |
154 | 154 | 'schema' => false, |
155 | 155 | ]; |
156 | - $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
157 | - $html = glsr(SiteReviews::class)->build(wp_parse_args($args, $atts)); |
|
158 | - return wp_send_json_success([ |
|
156 | + $atts = (array)json_decode( Arr::get( $request, 'atts' ) ); |
|
157 | + $html = glsr( SiteReviews::class )->build( wp_parse_args( $args, $atts ) ); |
|
158 | + return wp_send_json_success( [ |
|
159 | 159 | 'pagination' => $html->getPagination(), |
160 | 160 | 'reviews' => $html->getReviews(), |
161 | - ]); |
|
161 | + ] ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * @return void |
166 | 166 | */ |
167 | - public function routerTogglePinned(array $request) |
|
167 | + public function routerTogglePinned( array $request ) |
|
168 | 168 | { |
169 | - $isPinned = $this->execute(new TogglePinned($request)); |
|
170 | - wp_send_json_success([ |
|
171 | - 'notices' => glsr(Notice::class)->get(), |
|
169 | + $isPinned = $this->execute( new TogglePinned( $request ) ); |
|
170 | + wp_send_json_success( [ |
|
171 | + 'notices' => glsr( Notice::class )->get(), |
|
172 | 172 | 'pinned' => $isPinned, |
173 | - ]); |
|
173 | + ] ); |
|
174 | 174 | } |
175 | 175 | } |