@@ -32,13 +32,13 @@ |
||
32 | 32 | 'avatar' => '', |
33 | 33 | 'content' => '', |
34 | 34 | 'custom' => '', |
35 | - 'date' => current_time('mysql'), |
|
35 | + 'date' => current_time( 'mysql' ), |
|
36 | 36 | 'email' => '', |
37 | 37 | 'ip_address' => Helper::getIpAddress(), |
38 | 38 | 'pinned' => false, |
39 | 39 | 'rating' => '', |
40 | 40 | 'response' => '', |
41 | - 'review_id' => md5(time().mt_rand()), |
|
41 | + 'review_id' => md5( time().mt_rand() ), |
|
42 | 42 | 'review_type' => 'local', |
43 | 43 | 'title' => '', |
44 | 44 | 'url' => '', |
@@ -12,11 +12,11 @@ discard block |
||
12 | 12 | public function defaults() |
13 | 13 | { |
14 | 14 | $settings = $this->settings(); |
15 | - $defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default')); |
|
16 | - return wp_parse_args($defaults, [ |
|
15 | + $defaults = (array)array_combine( array_keys( $settings ), glsr_array_column( $settings, 'default' ) ); |
|
16 | + return wp_parse_args( $defaults, [ |
|
17 | 17 | 'version' => '', |
18 | 18 | 'version_upgraded_from' => '', |
19 | - ]); |
|
19 | + ] ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function get() |
26 | 26 | { |
27 | - return Arr::convertDotNotationArray($this->defaults()); |
|
27 | + return Arr::convertDotNotationArray( $this->defaults() ); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function set() |
34 | 34 | { |
35 | - $settings = glsr(OptionManager::class)->all(); |
|
36 | - $currentSettings = Arr::removeEmptyArrayValues($settings); |
|
37 | - $defaultSettings = array_replace_recursive($this->get(), $currentSettings); |
|
38 | - $updatedSettings = array_replace_recursive($settings, $defaultSettings); |
|
39 | - update_option(OptionManager::databaseKey(), $updatedSettings); |
|
35 | + $settings = glsr( OptionManager::class )->all(); |
|
36 | + $currentSettings = Arr::removeEmptyArrayValues( $settings ); |
|
37 | + $defaultSettings = array_replace_recursive( $this->get(), $currentSettings ); |
|
38 | + $updatedSettings = array_replace_recursive( $settings, $defaultSettings ); |
|
39 | + update_option( OptionManager::databaseKey(), $updatedSettings ); |
|
40 | 40 | return $defaultSettings; |
41 | 41 | } |
42 | 42 | |
@@ -45,17 +45,17 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function settings() |
47 | 47 | { |
48 | - $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings')); |
|
49 | - return $this->normalize($settings); |
|
48 | + $settings = apply_filters( 'site-reviews/addon/settings', glsr()->config( 'settings' ) ); |
|
49 | + return $this->normalize( $settings ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @return array |
54 | 54 | */ |
55 | - protected function normalize(array $settings) |
|
55 | + protected function normalize( array $settings ) |
|
56 | 56 | { |
57 | - array_walk($settings, function (&$setting) { |
|
58 | - if (isset($setting['default'])) { |
|
57 | + array_walk( $settings, function( &$setting ) { |
|
58 | + if( isset($setting['default']) ) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | 61 | $setting['default'] = ''; |
@@ -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, |
@@ -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; |
@@ -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 | } |
@@ -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 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public static function load() |
47 | 47 | { |
48 | - if (empty(static::$instance)) { |
|
48 | + if( empty(static::$instance) ) { |
|
49 | 49 | static::$instance = new static(); |
50 | 50 | } |
51 | 51 | return static::$instance; |
@@ -55,16 +55,16 @@ discard block |
||
55 | 55 | * @param string $property |
56 | 56 | * @return mixed |
57 | 57 | */ |
58 | - public function __get($property) |
|
58 | + public function __get( $property ) |
|
59 | 59 | { |
60 | - if (property_exists($this, $property) && !in_array($property, static::PROTECTED_PROPERTIES)) { |
|
60 | + if( property_exists( $this, $property ) && !in_array( $property, static::PROTECTED_PROPERTIES ) ) { |
|
61 | 61 | return $this->$property; |
62 | 62 | } |
63 | - $constant = 'static::'.strtoupper(Str::snakeCase($property)); |
|
64 | - if (defined($constant)) { |
|
65 | - return constant($constant); |
|
63 | + $constant = 'static::'.strtoupper( Str::snakeCase( $property ) ); |
|
64 | + if( defined( $constant ) ) { |
|
65 | + return constant( $constant ); |
|
66 | 66 | } |
67 | - return Arr::get($this->storage, $property, null); |
|
67 | + return Arr::get( $this->storage, $property, null ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -72,14 +72,14 @@ discard block |
||
72 | 72 | * @param string $value |
73 | 73 | * @return void |
74 | 74 | */ |
75 | - public function __set($property, $value) |
|
75 | + public function __set( $property, $value ) |
|
76 | 76 | { |
77 | - if (!property_exists($this, $property) || in_array($property, static::PROTECTED_PROPERTIES)) { |
|
77 | + if( !property_exists( $this, $property ) || in_array( $property, static::PROTECTED_PROPERTIES ) ) { |
|
78 | 78 | $this->storage[$property] = $value; |
79 | - } elseif (!isset($this->$property)) { |
|
79 | + } elseif( !isset($this->$property) ) { |
|
80 | 80 | $this->$property = $value; |
81 | 81 | } else { |
82 | - throw new Exception(sprintf('The "%s" property cannot be changed once set.', $property)); |
|
82 | + throw new Exception( sprintf( 'The "%s" property cannot be changed once set.', $property ) ); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @param mixed $concrete |
90 | 90 | * @return mixed |
91 | 91 | */ |
92 | - public function bind($alias, $concrete) |
|
92 | + public function bind( $alias, $concrete ) |
|
93 | 93 | { |
94 | 94 | $this->services[$alias] = $concrete; |
95 | 95 | } |
@@ -99,21 +99,21 @@ discard block |
||
99 | 99 | * @param mixed $abstract |
100 | 100 | * @return mixed |
101 | 101 | */ |
102 | - public function make($abstract) |
|
102 | + public function make( $abstract ) |
|
103 | 103 | { |
104 | - if (!isset($this->services[$abstract])) { |
|
105 | - $abstract = $this->addNamespace($abstract); |
|
104 | + if( !isset($this->services[$abstract]) ) { |
|
105 | + $abstract = $this->addNamespace( $abstract ); |
|
106 | 106 | } |
107 | - if (isset($this->services[$abstract])) { |
|
107 | + if( isset($this->services[$abstract]) ) { |
|
108 | 108 | $abstract = $this->services[$abstract]; |
109 | 109 | } |
110 | - if (is_callable($abstract)) { |
|
111 | - return call_user_func_array($abstract, [$this]); |
|
110 | + if( is_callable( $abstract ) ) { |
|
111 | + return call_user_func_array( $abstract, [$this] ); |
|
112 | 112 | } |
113 | - if (is_object($abstract)) { |
|
113 | + if( is_object( $abstract ) ) { |
|
114 | 114 | return $abstract; |
115 | 115 | } |
116 | - return $this->resolve($abstract); |
|
116 | + return $this->resolve( $abstract ); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | /** |
128 | 128 | * @return mixed |
129 | 129 | */ |
130 | - public function sessionGet($key, $fallback = '') |
|
130 | + public function sessionGet( $key, $fallback = '' ) |
|
131 | 131 | { |
132 | - $value = Arr::get($this->session, $key, $fallback); |
|
132 | + $value = Arr::get( $this->session, $key, $fallback ); |
|
133 | 133 | unset($this->session[$key]); |
134 | 134 | return $value; |
135 | 135 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | /** |
138 | 138 | * @return void |
139 | 139 | */ |
140 | - public function sessionSet($key, $value) |
|
140 | + public function sessionSet( $key, $value ) |
|
141 | 141 | { |
142 | 142 | $this->session[$key] = $value; |
143 | 143 | } |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | * @param callable|string|null $binding |
149 | 149 | * @return void |
150 | 150 | */ |
151 | - public function singleton($alias, $binding) |
|
151 | + public function singleton( $alias, $binding ) |
|
152 | 152 | { |
153 | - $this->bind($alias, $this->make($binding)); |
|
153 | + $this->bind( $alias, $this->make( $binding ) ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | * @param string $abstract |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - protected function addNamespace($abstract) |
|
161 | + protected function addNamespace( $abstract ) |
|
162 | 162 | { |
163 | - if (false === strpos($abstract, __NAMESPACE__) && !class_exists($abstract)) { |
|
163 | + if( false === strpos( $abstract, __NAMESPACE__ ) && !class_exists( $abstract ) ) { |
|
164 | 164 | $abstract = __NAMESPACE__.'\\'.$abstract; |
165 | 165 | } |
166 | 166 | return $abstract; |
@@ -172,21 +172,21 @@ discard block |
||
172 | 172 | * @return mixed |
173 | 173 | * @throws Exception |
174 | 174 | */ |
175 | - protected function resolve($concrete) |
|
175 | + protected function resolve( $concrete ) |
|
176 | 176 | { |
177 | - if ($concrete instanceof Closure) { |
|
178 | - return $concrete($this); |
|
177 | + if( $concrete instanceof Closure ) { |
|
178 | + return $concrete( $this ); |
|
179 | 179 | } |
180 | - $reflector = new ReflectionClass($concrete); |
|
181 | - if (!$reflector->isInstantiable()) { |
|
182 | - throw new Exception('Target ['.$concrete.'] is not instantiable.'); |
|
180 | + $reflector = new ReflectionClass( $concrete ); |
|
181 | + if( !$reflector->isInstantiable() ) { |
|
182 | + throw new Exception( 'Target ['.$concrete.'] is not instantiable.' ); |
|
183 | 183 | } |
184 | 184 | $constructor = $reflector->getConstructor(); |
185 | - if (empty($constructor)) { |
|
185 | + if( empty($constructor) ) { |
|
186 | 186 | return new $concrete(); |
187 | 187 | } |
188 | 188 | return $reflector->newInstanceArgs( |
189 | - $this->resolveDependencies($constructor->getParameters()) |
|
189 | + $this->resolveDependencies( $constructor->getParameters() ) |
|
190 | 190 | ); |
191 | 191 | } |
192 | 192 | |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | * @return mixed |
196 | 196 | * @throws Exception |
197 | 197 | */ |
198 | - protected function resolveClass(ReflectionParameter $parameter) |
|
198 | + protected function resolveClass( ReflectionParameter $parameter ) |
|
199 | 199 | { |
200 | 200 | try { |
201 | - return $this->make($parameter->getClass()->name); |
|
202 | - } catch (Exception $error) { |
|
203 | - if ($parameter->isOptional()) { |
|
201 | + return $this->make( $parameter->getClass()->name ); |
|
202 | + } catch( Exception $error ) { |
|
203 | + if( $parameter->isOptional() ) { |
|
204 | 204 | return $parameter->getDefaultValue(); |
205 | 205 | } |
206 | 206 | throw $error; |
@@ -211,13 +211,13 @@ discard block |
||
211 | 211 | * Resolve all of the dependencies from the ReflectionParameters. |
212 | 212 | * @return array |
213 | 213 | */ |
214 | - protected function resolveDependencies(array $dependencies) |
|
214 | + protected function resolveDependencies( array $dependencies ) |
|
215 | 215 | { |
216 | 216 | $results = []; |
217 | - foreach ($dependencies as $dependency) { |
|
218 | - $results[] = !is_null($class = $dependency->getClass()) |
|
219 | - ? $this->resolveClass($dependency) |
|
220 | - : $this->resolveDependency($dependency); |
|
217 | + foreach( $dependencies as $dependency ) { |
|
218 | + $results[] = !is_null( $class = $dependency->getClass() ) |
|
219 | + ? $this->resolveClass( $dependency ) |
|
220 | + : $this->resolveDependency( $dependency ); |
|
221 | 221 | } |
222 | 222 | return $results; |
223 | 223 | } |
@@ -226,9 +226,9 @@ discard block |
||
226 | 226 | * Resolve a single ReflectionParameter dependency. |
227 | 227 | * @return array|null |
228 | 228 | */ |
229 | - protected function resolveDependency(ReflectionParameter $parameter) |
|
229 | + protected function resolveDependency( ReflectionParameter $parameter ) |
|
230 | 230 | { |
231 | - if ($parameter->isArray() && $parameter->isDefaultValueAvailable()) { |
|
231 | + if( $parameter->isArray() && $parameter->isDefaultValueAvailable() ) { |
|
232 | 232 | return $parameter->getDefaultValue(); |
233 | 233 | } |
234 | 234 | return null; |
@@ -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 | } |
@@ -21,26 +21,26 @@ discard block |
||
21 | 21 | * @return array |
22 | 22 | * @todo verify the additional type checks are needed |
23 | 23 | */ |
24 | - public function buildCounts(array $args = []) |
|
24 | + public function buildCounts( array $args = [] ) |
|
25 | 25 | { |
26 | 26 | $counts = []; |
27 | - $query = $this->queryReviews($args); |
|
28 | - while ($query) { |
|
29 | - $types = array_keys(array_flip(glsr_array_column($query->reviews, 'type'))); |
|
30 | - $types = array_unique(array_merge(['local'], $types)); |
|
31 | - foreach ($types as $type) { |
|
32 | - $type = $this->normalizeType($type); |
|
33 | - if (isset($counts[$type])) { |
|
27 | + $query = $this->queryReviews( $args ); |
|
28 | + while( $query ) { |
|
29 | + $types = array_keys( array_flip( glsr_array_column( $query->reviews, 'type' ) ) ); |
|
30 | + $types = array_unique( array_merge( ['local'], $types ) ); |
|
31 | + foreach( $types as $type ) { |
|
32 | + $type = $this->normalizeType( $type ); |
|
33 | + if( isset($counts[$type]) ) { |
|
34 | 34 | continue; |
35 | 35 | } |
36 | - $counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
36 | + $counts[$type] = array_fill_keys( range( 0, glsr()->constant( 'MAX_RATING', Rating::class ) ), 0 ); |
|
37 | 37 | } |
38 | - foreach ($query->reviews as $review) { |
|
39 | - $type = $this->normalizeType($review->type); |
|
38 | + foreach( $query->reviews as $review ) { |
|
39 | + $type = $this->normalizeType( $review->type ); |
|
40 | 40 | ++$counts[$type][$review->rating]; |
41 | 41 | } |
42 | 42 | $query = $query->has_more |
43 | - ? $this->queryReviews($args, end($query->reviews)->ID) |
|
43 | + ? $this->queryReviews( $args, end( $query->reviews )->ID ) |
|
44 | 44 | : false; |
45 | 45 | } |
46 | 46 | return $counts; |
@@ -50,18 +50,18 @@ discard block |
||
50 | 50 | * @param int $postId |
51 | 51 | * @return array |
52 | 52 | */ |
53 | - public function buildPostCounts($postId) |
|
53 | + public function buildPostCounts( $postId ) |
|
54 | 54 | { |
55 | - return $this->buildCounts(['post_ids' => [$postId]]); |
|
55 | + return $this->buildCounts( ['post_ids' => [$postId]] ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @param int $termTaxonomyId |
60 | 60 | * @return array |
61 | 61 | */ |
62 | - public function buildTermCounts($termTaxonomyId) |
|
62 | + public function buildTermCounts( $termTaxonomyId ) |
|
63 | 63 | { |
64 | - return $this->buildCounts(['term_ids' => [$termTaxonomyId]]); |
|
64 | + return $this->buildCounts( ['term_ids' => [$termTaxonomyId]] ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -69,80 +69,80 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function countAll() |
71 | 71 | { |
72 | - $terms = glsr(Database::class)->getTerms(['fields' => 'all']); |
|
73 | - foreach ($terms as $term) { |
|
74 | - $this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id)); |
|
72 | + $terms = glsr( Database::class )->getTerms( ['fields' => 'all'] ); |
|
73 | + foreach( $terms as $term ) { |
|
74 | + $this->setTermCounts( $term->term_id, $this->buildTermCounts( $term->term_taxonomy_id ) ); |
|
75 | 75 | } |
76 | - $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to'); |
|
77 | - foreach ($postIds as $postId) { |
|
78 | - $this->setPostCounts($postId, $this->buildPostCounts($postId)); |
|
76 | + $postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' ); |
|
77 | + foreach( $postIds as $postId ) { |
|
78 | + $this->setPostCounts( $postId, $this->buildPostCounts( $postId ) ); |
|
79 | 79 | } |
80 | - $this->setCounts($this->buildCounts()); |
|
80 | + $this->setCounts( $this->buildCounts() ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | 84 | * @return void |
85 | 85 | */ |
86 | - public function decrease(Review $review) |
|
86 | + public function decrease( Review $review ) |
|
87 | 87 | { |
88 | - $this->decreaseCounts($review); |
|
89 | - $this->decreasePostCounts($review); |
|
90 | - $this->decreaseTermCounts($review); |
|
88 | + $this->decreaseCounts( $review ); |
|
89 | + $this->decreasePostCounts( $review ); |
|
90 | + $this->decreaseTermCounts( $review ); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | 94 | * @return void |
95 | 95 | */ |
96 | - public function decreaseCounts(Review $review) |
|
96 | + public function decreaseCounts( Review $review ) |
|
97 | 97 | { |
98 | - $this->setCounts($this->decreaseRating( |
|
98 | + $this->setCounts( $this->decreaseRating( |
|
99 | 99 | $this->getCounts(), |
100 | 100 | $review->review_type, |
101 | 101 | $review->rating |
102 | - )); |
|
102 | + ) ); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
106 | 106 | * @return void |
107 | 107 | */ |
108 | - public function decreasePostCounts(Review $review) |
|
108 | + public function decreasePostCounts( Review $review ) |
|
109 | 109 | { |
110 | - if (empty($counts = $this->getPostCounts($review->assigned_to))) { |
|
110 | + if( empty($counts = $this->getPostCounts( $review->assigned_to )) ) { |
|
111 | 111 | return; |
112 | 112 | } |
113 | - $counts = $this->decreaseRating($counts, $review->review_type, $review->rating); |
|
114 | - $this->setPostCounts($review->assigned_to, $counts); |
|
113 | + $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
|
114 | + $this->setPostCounts( $review->assigned_to, $counts ); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
118 | 118 | * @return void |
119 | 119 | */ |
120 | - public function decreaseTermCounts(Review $review) |
|
120 | + public function decreaseTermCounts( Review $review ) |
|
121 | 121 | { |
122 | - foreach ($review->term_ids as $termId) { |
|
123 | - if (empty($counts = $this->getTermCounts($termId))) { |
|
122 | + foreach( $review->term_ids as $termId ) { |
|
123 | + if( empty($counts = $this->getTermCounts( $termId )) ) { |
|
124 | 124 | continue; |
125 | 125 | } |
126 | - $counts = $this->decreaseRating($counts, $review->review_type, $review->rating); |
|
127 | - $this->setTermCounts($termId, $counts); |
|
126 | + $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
|
127 | + $this->setTermCounts( $termId, $counts ); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | 132 | * @return array |
133 | 133 | */ |
134 | - public function flatten(array $reviewCounts, array $args = []) |
|
134 | + public function flatten( array $reviewCounts, array $args = [] ) |
|
135 | 135 | { |
136 | 136 | $counts = []; |
137 | - array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
138 | - $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
137 | + array_walk_recursive( $reviewCounts, function( $num, $index ) use (&$counts) { |
|
138 | + $counts[$index] = $num + intval( Arr::get( $counts, $index, 0 ) ); |
|
139 | 139 | }); |
140 | - $args = wp_parse_args($args, [ |
|
141 | - 'max' => glsr()->constant('MAX_RATING', Rating::class), |
|
142 | - 'min' => glsr()->constant('MIN_RATING', Rating::class), |
|
143 | - ]); |
|
144 | - foreach ($counts as $index => &$num) { |
|
145 | - if ($index >= intval($args['min']) && $index <= intval($args['max'])) { |
|
140 | + $args = wp_parse_args( $args, [ |
|
141 | + 'max' => glsr()->constant( 'MAX_RATING', Rating::class ), |
|
142 | + 'min' => glsr()->constant( 'MIN_RATING', Rating::class ), |
|
143 | + ] ); |
|
144 | + foreach( $counts as $index => &$num ) { |
|
145 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ) ) { |
|
146 | 146 | continue; |
147 | 147 | } |
148 | 148 | $num = 0; |
@@ -153,26 +153,26 @@ discard block |
||
153 | 153 | /** |
154 | 154 | * @return array |
155 | 155 | */ |
156 | - public function get(array $args = []) |
|
156 | + public function get( array $args = [] ) |
|
157 | 157 | { |
158 | - $args = $this->normalizeArgs($args); |
|
158 | + $args = $this->normalizeArgs( $args ); |
|
159 | 159 | $counts = []; |
160 | - if ($this->isMixedCount($args)) { |
|
161 | - $counts = [$this->buildCounts($args)]; // force query the database |
|
160 | + if( $this->isMixedCount( $args ) ) { |
|
161 | + $counts = [$this->buildCounts( $args )]; // force query the database |
|
162 | 162 | } else { |
163 | - foreach ($args['post_ids'] as $postId) { |
|
164 | - $counts[] = $this->getPostCounts($postId); |
|
163 | + foreach( $args['post_ids'] as $postId ) { |
|
164 | + $counts[] = $this->getPostCounts( $postId ); |
|
165 | 165 | } |
166 | - foreach ($args['term_ids'] as $termId) { |
|
167 | - $counts[] = $this->getTermCounts($termId); |
|
166 | + foreach( $args['term_ids'] as $termId ) { |
|
167 | + $counts[] = $this->getTermCounts( $termId ); |
|
168 | 168 | } |
169 | - if (empty($counts)) { |
|
169 | + if( empty($counts) ) { |
|
170 | 170 | $counts[] = $this->getCounts(); |
171 | 171 | } |
172 | 172 | } |
173 | - return in_array($args['type'], ['', 'all']) |
|
174 | - ? $this->normalize([$this->flatten($counts)]) |
|
175 | - : $this->normalize(glsr_array_column($counts, $args['type'])); |
|
173 | + return in_array( $args['type'], ['', 'all'] ) |
|
174 | + ? $this->normalize( [$this->flatten( $counts )] ) |
|
175 | + : $this->normalize( glsr_array_column( $counts, $args['type'] ) ); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -180,9 +180,9 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function getCounts() |
182 | 182 | { |
183 | - $counts = glsr(OptionManager::class)->get('counts', []); |
|
184 | - if (!is_array($counts)) { |
|
185 | - glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
183 | + $counts = glsr( OptionManager::class )->get( 'counts', [] ); |
|
184 | + if( !is_array( $counts ) ) { |
|
185 | + glsr_log()->error( 'Review counts is not an array; possibly due to incorrectly imported reviews.' )->debug( $counts ); |
|
186 | 186 | return []; |
187 | 187 | } |
188 | 188 | return $counts; |
@@ -192,105 +192,105 @@ discard block |
||
192 | 192 | * @param int $postId |
193 | 193 | * @return array |
194 | 194 | */ |
195 | - public function getPostCounts($postId) |
|
195 | + public function getPostCounts( $postId ) |
|
196 | 196 | { |
197 | - return array_filter((array) get_post_meta($postId, static::META_COUNT, true)); |
|
197 | + return array_filter( (array)get_post_meta( $postId, static::META_COUNT, true ) ); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
201 | 201 | * @param int $termId |
202 | 202 | * @return array |
203 | 203 | */ |
204 | - public function getTermCounts($termId) |
|
204 | + public function getTermCounts( $termId ) |
|
205 | 205 | { |
206 | - return array_filter((array) get_term_meta($termId, static::META_COUNT, true)); |
|
206 | + return array_filter( (array)get_term_meta( $termId, static::META_COUNT, true ) ); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
210 | 210 | * @return void |
211 | 211 | */ |
212 | - public function increase(Review $review) |
|
212 | + public function increase( Review $review ) |
|
213 | 213 | { |
214 | - $this->increaseCounts($review); |
|
215 | - $this->increasePostCounts($review); |
|
216 | - $this->increaseTermCounts($review); |
|
214 | + $this->increaseCounts( $review ); |
|
215 | + $this->increasePostCounts( $review ); |
|
216 | + $this->increaseTermCounts( $review ); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
220 | 220 | * @return void |
221 | 221 | */ |
222 | - public function increaseCounts(Review $review) |
|
222 | + public function increaseCounts( Review $review ) |
|
223 | 223 | { |
224 | - if (empty($counts = $this->getCounts())) { |
|
224 | + if( empty($counts = $this->getCounts()) ) { |
|
225 | 225 | $counts = $this->buildCounts(); |
226 | 226 | } |
227 | - $this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating)); |
|
227 | + $this->setCounts( $this->increaseRating( $counts, $review->review_type, $review->rating ) ); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
231 | 231 | * @return void |
232 | 232 | */ |
233 | - public function increasePostCounts(Review $review) |
|
233 | + public function increasePostCounts( Review $review ) |
|
234 | 234 | { |
235 | - if (!(get_post($review->assigned_to) instanceof WP_Post)) { |
|
235 | + if( !(get_post( $review->assigned_to ) instanceof WP_Post) ) { |
|
236 | 236 | return; |
237 | 237 | } |
238 | - $counts = $this->getPostCounts($review->assigned_to); |
|
238 | + $counts = $this->getPostCounts( $review->assigned_to ); |
|
239 | 239 | $counts = empty($counts) |
240 | - ? $this->buildPostCounts($review->assigned_to) |
|
241 | - : $this->increaseRating($counts, $review->review_type, $review->rating); |
|
242 | - $this->setPostCounts($review->assigned_to, $counts); |
|
240 | + ? $this->buildPostCounts( $review->assigned_to ) |
|
241 | + : $this->increaseRating( $counts, $review->review_type, $review->rating ); |
|
242 | + $this->setPostCounts( $review->assigned_to, $counts ); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | 246 | * @return void |
247 | 247 | */ |
248 | - public function increaseTermCounts(Review $review) |
|
248 | + public function increaseTermCounts( Review $review ) |
|
249 | 249 | { |
250 | - $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids)); |
|
251 | - foreach ($terms as $term) { |
|
252 | - $counts = $this->getTermCounts($term['term_id']); |
|
250 | + $terms = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids ) ); |
|
251 | + foreach( $terms as $term ) { |
|
252 | + $counts = $this->getTermCounts( $term['term_id'] ); |
|
253 | 253 | $counts = empty($counts) |
254 | - ? $this->buildTermCounts($term['term_taxonomy_id']) |
|
255 | - : $this->increaseRating($counts, $review->review_type, $review->rating); |
|
256 | - $this->setTermCounts($term['term_id'], $counts); |
|
254 | + ? $this->buildTermCounts( $term['term_taxonomy_id'] ) |
|
255 | + : $this->increaseRating( $counts, $review->review_type, $review->rating ); |
|
256 | + $this->setTermCounts( $term['term_id'], $counts ); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | 261 | * @return void |
262 | 262 | */ |
263 | - public function setCounts(array $reviewCounts) |
|
263 | + public function setCounts( array $reviewCounts ) |
|
264 | 264 | { |
265 | - glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
265 | + glsr( OptionManager::class )->set( 'counts', $reviewCounts ); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
269 | 269 | * @param int $postId |
270 | 270 | * @return void |
271 | 271 | */ |
272 | - public function setPostCounts($postId, array $reviewCounts) |
|
272 | + public function setPostCounts( $postId, array $reviewCounts ) |
|
273 | 273 | { |
274 | - $ratingCounts = $this->flatten($reviewCounts); |
|
275 | - update_post_meta($postId, static::META_COUNT, $reviewCounts); |
|
276 | - update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
277 | - update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
274 | + $ratingCounts = $this->flatten( $reviewCounts ); |
|
275 | + update_post_meta( $postId, static::META_COUNT, $reviewCounts ); |
|
276 | + update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
277 | + update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
281 | 281 | * @param int $termId |
282 | 282 | * @return void |
283 | 283 | */ |
284 | - public function setTermCounts($termId, array $reviewCounts) |
|
284 | + public function setTermCounts( $termId, array $reviewCounts ) |
|
285 | 285 | { |
286 | - $term = get_term($termId, Application::TAXONOMY); |
|
287 | - if (!isset($term->term_id)) { |
|
286 | + $term = get_term( $termId, Application::TAXONOMY ); |
|
287 | + if( !isset($term->term_id) ) { |
|
288 | 288 | return; |
289 | 289 | } |
290 | - $ratingCounts = $this->flatten($reviewCounts); |
|
291 | - update_term_meta($termId, static::META_COUNT, $reviewCounts); |
|
292 | - update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
293 | - update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
290 | + $ratingCounts = $this->flatten( $reviewCounts ); |
|
291 | + update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
|
292 | + update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
293 | + update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -298,10 +298,10 @@ discard block |
||
298 | 298 | * @param int $rating |
299 | 299 | * @return array |
300 | 300 | */ |
301 | - protected function decreaseRating(array $reviewCounts, $type, $rating) |
|
301 | + protected function decreaseRating( array $reviewCounts, $type, $rating ) |
|
302 | 302 | { |
303 | - if (isset($reviewCounts[$type][$rating])) { |
|
304 | - $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
303 | + if( isset($reviewCounts[$type][$rating]) ) { |
|
304 | + $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 ); |
|
305 | 305 | } |
306 | 306 | return $reviewCounts; |
307 | 307 | } |
@@ -311,23 +311,23 @@ discard block |
||
311 | 311 | * @param int $rating |
312 | 312 | * @return array |
313 | 313 | */ |
314 | - protected function increaseRating(array $reviewCounts, $type, $rating) |
|
314 | + protected function increaseRating( array $reviewCounts, $type, $rating ) |
|
315 | 315 | { |
316 | - if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
316 | + if( !array_key_exists( $type, glsr()->reviewTypes ) ) { |
|
317 | 317 | return $reviewCounts; |
318 | 318 | } |
319 | - if (!array_key_exists($type, $reviewCounts)) { |
|
319 | + if( !array_key_exists( $type, $reviewCounts ) ) { |
|
320 | 320 | $reviewCounts[$type] = []; |
321 | 321 | } |
322 | - $reviewCounts = $this->normalize($reviewCounts); |
|
323 | - $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
322 | + $reviewCounts = $this->normalize( $reviewCounts ); |
|
323 | + $reviewCounts[$type][$rating] = intval( $reviewCounts[$type][$rating] ) + 1; |
|
324 | 324 | return $reviewCounts; |
325 | 325 | } |
326 | 326 | |
327 | 327 | /** |
328 | 328 | * @return bool |
329 | 329 | */ |
330 | - protected function isMixedCount(array $args) |
|
330 | + protected function isMixedCount( array $args ) |
|
331 | 331 | { |
332 | 332 | return !empty($args['post_ids']) && !empty($args['term_ids']); |
333 | 333 | } |
@@ -335,19 +335,19 @@ discard block |
||
335 | 335 | /** |
336 | 336 | * @return array |
337 | 337 | */ |
338 | - protected function normalize(array $reviewCounts) |
|
338 | + protected function normalize( array $reviewCounts ) |
|
339 | 339 | { |
340 | - if (empty($reviewCounts)) { |
|
340 | + if( empty($reviewCounts) ) { |
|
341 | 341 | $reviewCounts = [[]]; |
342 | 342 | } |
343 | - foreach ($reviewCounts as &$counts) { |
|
344 | - foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) { |
|
345 | - if (isset($counts[$index])) { |
|
343 | + foreach( $reviewCounts as &$counts ) { |
|
344 | + foreach( range( 0, glsr()->constant( 'MAX_RATING', Rating::class ) ) as $index ) { |
|
345 | + if( isset($counts[$index]) ) { |
|
346 | 346 | continue; |
347 | 347 | } |
348 | 348 | $counts[$index] = 0; |
349 | 349 | } |
350 | - ksort($counts); |
|
350 | + ksort( $counts ); |
|
351 | 351 | } |
352 | 352 | return $reviewCounts; |
353 | 353 | } |
@@ -355,15 +355,15 @@ discard block |
||
355 | 355 | /** |
356 | 356 | * @return array |
357 | 357 | */ |
358 | - protected function normalizeArgs(array $args) |
|
358 | + protected function normalizeArgs( array $args ) |
|
359 | 359 | { |
360 | - $args = wp_parse_args(array_filter($args), [ |
|
360 | + $args = wp_parse_args( array_filter( $args ), [ |
|
361 | 361 | 'post_ids' => [], |
362 | 362 | 'term_ids' => [], |
363 | 363 | 'type' => 'local', |
364 | - ]); |
|
365 | - $args['post_ids'] = glsr(Polylang::class)->getPostIds($args['post_ids']); |
|
366 | - $args['type'] = $this->normalizeType($args['type']); |
|
364 | + ] ); |
|
365 | + $args['post_ids'] = glsr( Polylang::class )->getPostIds( $args['post_ids'] ); |
|
366 | + $args['type'] = $this->normalizeType( $args['type'] ); |
|
367 | 367 | return $args; |
368 | 368 | } |
369 | 369 | |
@@ -371,9 +371,9 @@ discard block |
||
371 | 371 | * @param string $type |
372 | 372 | * @return string |
373 | 373 | */ |
374 | - protected function normalizeType($type) |
|
374 | + protected function normalizeType( $type ) |
|
375 | 375 | { |
376 | - return empty($type) || !is_string($type) |
|
376 | + return empty($type) || !is_string( $type ) |
|
377 | 377 | ? 'local' |
378 | 378 | : $type; |
379 | 379 | } |
@@ -382,13 +382,13 @@ discard block |
||
382 | 382 | * @param int $lastPostId |
383 | 383 | * @return object |
384 | 384 | */ |
385 | - protected function queryReviews(array $args = [], $lastPostId = 0) |
|
385 | + protected function queryReviews( array $args = [], $lastPostId = 0 ) |
|
386 | 386 | { |
387 | - $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
388 | - $hasMore = is_array($reviews) |
|
389 | - ? count($reviews) == static::LIMIT |
|
387 | + $reviews = glsr( SqlQueries::class )->getReviewCounts( $args, $lastPostId, static::LIMIT ); |
|
388 | + $hasMore = is_array( $reviews ) |
|
389 | + ? count( $reviews ) == static::LIMIT |
|
390 | 390 | : false; |
391 | - return (object) [ |
|
391 | + return (object)[ |
|
392 | 392 | 'has_more' => $hasMore, |
393 | 393 | 'reviews' => $reviews, |
394 | 394 | ]; |