@@ -7,87 +7,87 @@ |
||
7 | 7 | |
8 | 8 | class Date |
9 | 9 | { |
10 | - /** |
|
11 | - * [60, 1], |
|
12 | - * [60 * 100, 60], |
|
13 | - * [3600 * 70, 3600], |
|
14 | - * [3600 * 24 * 10, 3600 * 24], |
|
15 | - * [3600 * 24 * 30, 3600 * 24 * 7], |
|
16 | - * [3600 * 24 * 30 * 30, 3600 * 24 * 30], |
|
17 | - * [INF, 3600 * 24 * 265],. |
|
18 | - */ |
|
19 | - protected static $TIME_PERIODS = [ |
|
20 | - [60, 1], |
|
21 | - [6000, 60], |
|
22 | - [252000, 3600], |
|
23 | - [864000, 86400], |
|
24 | - [2592000, 604800], |
|
25 | - [77760000, 2592000], |
|
26 | - [INF, 22896000], |
|
27 | - ]; |
|
10 | + /** |
|
11 | + * [60, 1], |
|
12 | + * [60 * 100, 60], |
|
13 | + * [3600 * 70, 3600], |
|
14 | + * [3600 * 24 * 10, 3600 * 24], |
|
15 | + * [3600 * 24 * 30, 3600 * 24 * 7], |
|
16 | + * [3600 * 24 * 30 * 30, 3600 * 24 * 30], |
|
17 | + * [INF, 3600 * 24 * 265],. |
|
18 | + */ |
|
19 | + protected static $TIME_PERIODS = [ |
|
20 | + [60, 1], |
|
21 | + [6000, 60], |
|
22 | + [252000, 3600], |
|
23 | + [864000, 86400], |
|
24 | + [2592000, 604800], |
|
25 | + [77760000, 2592000], |
|
26 | + [INF, 22896000], |
|
27 | + ]; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param mixed $date |
|
31 | - * @param string $format |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public function isDate($date, $format = 'Y-m-d H:i:s') |
|
35 | - { |
|
36 | - $datetime = DateTime::createFromFormat($format, $date); |
|
37 | - return $datetime && $date == $datetime->format($format); |
|
38 | - } |
|
29 | + /** |
|
30 | + * @param mixed $date |
|
31 | + * @param string $format |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public function isDate($date, $format = 'Y-m-d H:i:s') |
|
35 | + { |
|
36 | + $datetime = DateTime::createFromFormat($format, $date); |
|
37 | + return $datetime && $date == $datetime->format($format); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param mixed $date |
|
42 | - * @return bool |
|
43 | - */ |
|
44 | - public function isTimestamp($date) |
|
45 | - { |
|
46 | - return ctype_digit($date) |
|
47 | - ? true |
|
48 | - : false; |
|
49 | - } |
|
40 | + /** |
|
41 | + * @param mixed $date |
|
42 | + * @return bool |
|
43 | + */ |
|
44 | + public function isTimestamp($date) |
|
45 | + { |
|
46 | + return ctype_digit($date) |
|
47 | + ? true |
|
48 | + : false; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param mixed $date |
|
53 | - * @param string $fallback |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public function localized($date, $fallback = '') |
|
57 | - { |
|
58 | - return $this->isDate($date) || $this->isTimestamp($date) |
|
59 | - ? date_i18n('Y-m-d H:i', $date) |
|
60 | - : $fallback; |
|
61 | - } |
|
51 | + /** |
|
52 | + * @param mixed $date |
|
53 | + * @param string $fallback |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public function localized($date, $fallback = '') |
|
57 | + { |
|
58 | + return $this->isDate($date) || $this->isTimestamp($date) |
|
59 | + ? date_i18n('Y-m-d H:i', $date) |
|
60 | + : $fallback; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param mixed $date |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function relative($date) |
|
68 | - { |
|
69 | - if (!$this->isDate($date)) { |
|
70 | - return ''; |
|
71 | - } |
|
72 | - $diff = time() - strtotime($date); |
|
73 | - foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
74 | - if ($diff > $timePeriod[0]) { |
|
75 | - continue; |
|
76 | - } |
|
77 | - $unit = intval(floor($diff / $timePeriod[1])); |
|
78 | - $relativeDates = [ |
|
79 | - _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
80 | - _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
81 | - _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
82 | - _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
83 | - _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
84 | - _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
85 | - _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
86 | - ]; |
|
87 | - $relativeDate = $relativeDates[$i]; |
|
88 | - return Str::contains($relativeDate, '%s') |
|
89 | - ? sprintf($relativeDate, $unit) |
|
90 | - : $relativeDate; |
|
91 | - } |
|
92 | - } |
|
63 | + /** |
|
64 | + * @param mixed $date |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function relative($date) |
|
68 | + { |
|
69 | + if (!$this->isDate($date)) { |
|
70 | + return ''; |
|
71 | + } |
|
72 | + $diff = time() - strtotime($date); |
|
73 | + foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
74 | + if ($diff > $timePeriod[0]) { |
|
75 | + continue; |
|
76 | + } |
|
77 | + $unit = intval(floor($diff / $timePeriod[1])); |
|
78 | + $relativeDates = [ |
|
79 | + _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
80 | + _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
81 | + _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
82 | + _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
83 | + _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
84 | + _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
85 | + _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
86 | + ]; |
|
87 | + $relativeDate = $relativeDates[$i]; |
|
88 | + return Str::contains($relativeDate, '%s') |
|
89 | + ? sprintf($relativeDate, $unit) |
|
90 | + : $relativeDate; |
|
91 | + } |
|
92 | + } |
|
93 | 93 | } |
@@ -31,19 +31,19 @@ discard block |
||
31 | 31 | * @param string $format |
32 | 32 | * @return bool |
33 | 33 | */ |
34 | - public function isDate($date, $format = 'Y-m-d H:i:s') |
|
34 | + public function isDate( $date, $format = 'Y-m-d H:i:s' ) |
|
35 | 35 | { |
36 | - $datetime = DateTime::createFromFormat($format, $date); |
|
37 | - return $datetime && $date == $datetime->format($format); |
|
36 | + $datetime = DateTime::createFromFormat( $format, $date ); |
|
37 | + return $datetime && $date == $datetime->format( $format ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @param mixed $date |
42 | 42 | * @return bool |
43 | 43 | */ |
44 | - public function isTimestamp($date) |
|
44 | + public function isTimestamp( $date ) |
|
45 | 45 | { |
46 | - return ctype_digit($date) |
|
46 | + return ctype_digit( $date ) |
|
47 | 47 | ? true |
48 | 48 | : false; |
49 | 49 | } |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | * @param string $fallback |
54 | 54 | * @return string |
55 | 55 | */ |
56 | - public function localized($date, $fallback = '') |
|
56 | + public function localized( $date, $fallback = '' ) |
|
57 | 57 | { |
58 | - return $this->isDate($date) || $this->isTimestamp($date) |
|
59 | - ? date_i18n('Y-m-d H:i', $date) |
|
58 | + return $this->isDate( $date ) || $this->isTimestamp( $date ) |
|
59 | + ? date_i18n( 'Y-m-d H:i', $date ) |
|
60 | 60 | : $fallback; |
61 | 61 | } |
62 | 62 | |
@@ -64,29 +64,29 @@ discard block |
||
64 | 64 | * @param mixed $date |
65 | 65 | * @return string |
66 | 66 | */ |
67 | - public function relative($date) |
|
67 | + public function relative( $date ) |
|
68 | 68 | { |
69 | - if (!$this->isDate($date)) { |
|
69 | + if( !$this->isDate( $date ) ) { |
|
70 | 70 | return ''; |
71 | 71 | } |
72 | - $diff = time() - strtotime($date); |
|
73 | - foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
74 | - if ($diff > $timePeriod[0]) { |
|
72 | + $diff = time() - strtotime( $date ); |
|
73 | + foreach( static::$TIME_PERIODS as $i => $timePeriod ) { |
|
74 | + if( $diff > $timePeriod[0] ) { |
|
75 | 75 | continue; |
76 | 76 | } |
77 | - $unit = intval(floor($diff / $timePeriod[1])); |
|
77 | + $unit = intval( floor( $diff / $timePeriod[1] ) ); |
|
78 | 78 | $relativeDates = [ |
79 | - _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
80 | - _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
81 | - _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
82 | - _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
83 | - _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
84 | - _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
85 | - _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
79 | + _n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ), |
|
80 | + _n( '%s minute ago', '%s minutes ago', $unit, 'site-reviews' ), |
|
81 | + _n( 'an hour ago', '%s hours ago', $unit, 'site-reviews' ), |
|
82 | + _n( 'yesterday', '%s days ago', $unit, 'site-reviews' ), |
|
83 | + _n( 'a week ago', '%s weeks ago', $unit, 'site-reviews' ), |
|
84 | + _n( '%s month ago', '%s months ago', $unit, 'site-reviews' ), |
|
85 | + _n( '%s year ago', '%s years ago', $unit, 'site-reviews' ), |
|
86 | 86 | ]; |
87 | 87 | $relativeDate = $relativeDates[$i]; |
88 | - return Str::contains($relativeDate, '%s') |
|
89 | - ? sprintf($relativeDate, $unit) |
|
88 | + return Str::contains( $relativeDate, '%s' ) |
|
89 | + ? sprintf( $relativeDate, $unit ) |
|
90 | 90 | : $relativeDate; |
91 | 91 | } |
92 | 92 | } |
@@ -9,70 +9,70 @@ |
||
9 | 9 | |
10 | 10 | class Migrate_4_0_2 |
11 | 11 | { |
12 | - /** |
|
13 | - * @return void |
|
14 | - */ |
|
15 | - public function deleteSessions() |
|
16 | - { |
|
17 | - global $wpdb; |
|
18 | - $wpdb->query(" |
|
12 | + /** |
|
13 | + * @return void |
|
14 | + */ |
|
15 | + public function deleteSessions() |
|
16 | + { |
|
17 | + global $wpdb; |
|
18 | + $wpdb->query(" |
|
19 | 19 | DELETE |
20 | 20 | FROM {$wpdb->options} |
21 | 21 | WHERE option_name LIKE '_glsr_session%' |
22 | 22 | "); |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function migrateSettings() |
|
29 | - { |
|
30 | - if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
31 | - $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang') |
|
32 | - ? 'polylang' |
|
33 | - : ''; |
|
34 | - $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual); |
|
35 | - $settings = Arr::set($settings, 'settings.general.rebusify', 'no'); |
|
36 | - $settings = Arr::set($settings, 'settings.general.rebusify_email', ''); |
|
37 | - $settings = Arr::set($settings, 'settings.general.rebusify_serial', ''); |
|
38 | - $settings = Arr::set($settings, 'settings.reviews.name.format', ''); |
|
39 | - $settings = Arr::set($settings, 'settings.reviews.name.initial', ''); |
|
40 | - $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', ''); |
|
41 | - $settings = Arr::set($settings, 'settings.submissions.limit', ''); |
|
42 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
43 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
44 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
45 | - unset($settings['settings']['general']['support']); |
|
46 | - update_option(OptionManager::databaseKey(4), $settings); |
|
47 | - } |
|
48 | - } |
|
25 | + /** |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function migrateSettings() |
|
29 | + { |
|
30 | + if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
31 | + $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang') |
|
32 | + ? 'polylang' |
|
33 | + : ''; |
|
34 | + $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual); |
|
35 | + $settings = Arr::set($settings, 'settings.general.rebusify', 'no'); |
|
36 | + $settings = Arr::set($settings, 'settings.general.rebusify_email', ''); |
|
37 | + $settings = Arr::set($settings, 'settings.general.rebusify_serial', ''); |
|
38 | + $settings = Arr::set($settings, 'settings.reviews.name.format', ''); |
|
39 | + $settings = Arr::set($settings, 'settings.reviews.name.initial', ''); |
|
40 | + $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', ''); |
|
41 | + $settings = Arr::set($settings, 'settings.submissions.limit', ''); |
|
42 | + $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
43 | + $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
44 | + $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
45 | + unset($settings['settings']['general']['support']); |
|
46 | + update_option(OptionManager::databaseKey(4), $settings); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public function protectMetaKeys() |
|
54 | - { |
|
55 | - global $wpdb; |
|
56 | - $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
57 | - $keys = implode("','", $keys); |
|
58 | - $postType = Application::POST_TYPE; |
|
59 | - $wpdb->query(" |
|
50 | + /** |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public function protectMetaKeys() |
|
54 | + { |
|
55 | + global $wpdb; |
|
56 | + $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
57 | + $keys = implode("','", $keys); |
|
58 | + $postType = Application::POST_TYPE; |
|
59 | + $wpdb->query(" |
|
60 | 60 | UPDATE {$wpdb->postmeta} pm |
61 | 61 | INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id |
62 | 62 | SET pm.meta_key = CONCAT('_', pm.meta_key) |
63 | 63 | WHERE pm.meta_key IN ('{$keys}') |
64 | 64 | AND p.post_type = '{$postType}' |
65 | 65 | "); |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public function run() |
|
72 | - { |
|
73 | - $this->migrateSettings(); |
|
74 | - $this->protectMetaKeys(); |
|
75 | - $this->deleteSessions(); |
|
76 | - delete_transient(Application::ID.'_cloudflare_ips'); |
|
77 | - } |
|
68 | + /** |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public function run() |
|
72 | + { |
|
73 | + $this->migrateSettings(); |
|
74 | + $this->protectMetaKeys(); |
|
75 | + $this->deleteSessions(); |
|
76 | + delete_transient(Application::ID.'_cloudflare_ips'); |
|
77 | + } |
|
78 | 78 | } |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | public function deleteSessions() |
16 | 16 | { |
17 | 17 | global $wpdb; |
18 | - $wpdb->query(" |
|
18 | + $wpdb->query( " |
|
19 | 19 | DELETE |
20 | 20 | FROM {$wpdb->options} |
21 | 21 | WHERE option_name LIKE '_glsr_session%' |
22 | - "); |
|
22 | + " ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -27,23 +27,23 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function migrateSettings() |
29 | 29 | { |
30 | - if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
31 | - $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang') |
|
30 | + if( $settings = get_option( OptionManager::databaseKey( 3 ) ) ) { |
|
31 | + $multilingual = 'yes' == Arr::get( $settings, 'settings.general.support.polylang' ) |
|
32 | 32 | ? 'polylang' |
33 | 33 | : ''; |
34 | - $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual); |
|
35 | - $settings = Arr::set($settings, 'settings.general.rebusify', 'no'); |
|
36 | - $settings = Arr::set($settings, 'settings.general.rebusify_email', ''); |
|
37 | - $settings = Arr::set($settings, 'settings.general.rebusify_serial', ''); |
|
38 | - $settings = Arr::set($settings, 'settings.reviews.name.format', ''); |
|
39 | - $settings = Arr::set($settings, 'settings.reviews.name.initial', ''); |
|
40 | - $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', ''); |
|
41 | - $settings = Arr::set($settings, 'settings.submissions.limit', ''); |
|
42 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
43 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
44 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
34 | + $settings = Arr::set( $settings, 'settings.general.multilingual', $multilingual ); |
|
35 | + $settings = Arr::set( $settings, 'settings.general.rebusify', 'no' ); |
|
36 | + $settings = Arr::set( $settings, 'settings.general.rebusify_email', '' ); |
|
37 | + $settings = Arr::set( $settings, 'settings.general.rebusify_serial', '' ); |
|
38 | + $settings = Arr::set( $settings, 'settings.reviews.name.format', '' ); |
|
39 | + $settings = Arr::set( $settings, 'settings.reviews.name.initial', '' ); |
|
40 | + $settings = Arr::set( $settings, 'settings.submissions.blacklist.integration', '' ); |
|
41 | + $settings = Arr::set( $settings, 'settings.submissions.limit', '' ); |
|
42 | + $settings = Arr::set( $settings, 'settings.submissions.limit_whitelist.email', '' ); |
|
43 | + $settings = Arr::set( $settings, 'settings.submissions.limit_whitelist.ip_address', '' ); |
|
44 | + $settings = Arr::set( $settings, 'settings.submissions.limit_whitelist.username', '' ); |
|
45 | 45 | unset($settings['settings']['general']['support']); |
46 | - update_option(OptionManager::databaseKey(4), $settings); |
|
46 | + update_option( OptionManager::databaseKey( 4 ), $settings ); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
@@ -53,16 +53,16 @@ discard block |
||
53 | 53 | public function protectMetaKeys() |
54 | 54 | { |
55 | 55 | global $wpdb; |
56 | - $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
57 | - $keys = implode("','", $keys); |
|
56 | + $keys = array_keys( glsr( CreateReviewDefaults::class )->defaults() ); |
|
57 | + $keys = implode( "','", $keys ); |
|
58 | 58 | $postType = Application::POST_TYPE; |
59 | - $wpdb->query(" |
|
59 | + $wpdb->query( " |
|
60 | 60 | UPDATE {$wpdb->postmeta} pm |
61 | 61 | INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id |
62 | 62 | SET pm.meta_key = CONCAT('_', pm.meta_key) |
63 | 63 | WHERE pm.meta_key IN ('{$keys}') |
64 | 64 | AND p.post_type = '{$postType}' |
65 | - "); |
|
65 | + " ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -73,6 +73,6 @@ discard block |
||
73 | 73 | $this->migrateSettings(); |
74 | 74 | $this->protectMetaKeys(); |
75 | 75 | $this->deleteSessions(); |
76 | - delete_transient(Application::ID.'_cloudflare_ips'); |
|
76 | + delete_transient( Application::ID.'_cloudflare_ips' ); |
|
77 | 77 | } |
78 | 78 | } |
@@ -9,75 +9,75 @@ |
||
9 | 9 | |
10 | 10 | class Wpml implements Contract |
11 | 11 | { |
12 | - public $pluginName = 'WPML'; |
|
13 | - public $supportedVersion = '3.3.5'; |
|
12 | + public $pluginName = 'WPML'; |
|
13 | + public $supportedVersion = '3.3.5'; |
|
14 | 14 | |
15 | - /** |
|
16 | - * {@inheritdoc} |
|
17 | - */ |
|
18 | - public function getPostId($postId) |
|
19 | - { |
|
20 | - $postId = trim($postId); |
|
21 | - if (!is_numeric($postId)) { |
|
22 | - return 0; |
|
23 | - } |
|
24 | - if ($this->isEnabled()) { |
|
25 | - $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
26 | - } |
|
27 | - return intval($postId); |
|
28 | - } |
|
15 | + /** |
|
16 | + * {@inheritdoc} |
|
17 | + */ |
|
18 | + public function getPostId($postId) |
|
19 | + { |
|
20 | + $postId = trim($postId); |
|
21 | + if (!is_numeric($postId)) { |
|
22 | + return 0; |
|
23 | + } |
|
24 | + if ($this->isEnabled()) { |
|
25 | + $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
26 | + } |
|
27 | + return intval($postId); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - public function getPostIds(array $postIds) |
|
34 | - { |
|
35 | - if (!$this->isEnabled()) { |
|
36 | - return $postIds; |
|
37 | - } |
|
38 | - $newPostIds = []; |
|
39 | - foreach (Arr::unique($postIds) as $postId) { |
|
40 | - $postType = get_post_type($postId); |
|
41 | - if (!$postType) { |
|
42 | - continue; |
|
43 | - } |
|
44 | - $elementType = 'post_'.$postType; |
|
45 | - $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
46 | - $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
47 | - if (!is_array($translations)) { |
|
48 | - $translations = []; |
|
49 | - } |
|
50 | - $newPostIds = array_merge( |
|
51 | - $newPostIds, |
|
52 | - array_column($translations, 'element_id') |
|
53 | - ); |
|
54 | - } |
|
55 | - return Arr::unique($newPostIds); |
|
56 | - } |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + public function getPostIds(array $postIds) |
|
34 | + { |
|
35 | + if (!$this->isEnabled()) { |
|
36 | + return $postIds; |
|
37 | + } |
|
38 | + $newPostIds = []; |
|
39 | + foreach (Arr::unique($postIds) as $postId) { |
|
40 | + $postType = get_post_type($postId); |
|
41 | + if (!$postType) { |
|
42 | + continue; |
|
43 | + } |
|
44 | + $elementType = 'post_'.$postType; |
|
45 | + $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
46 | + $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
47 | + if (!is_array($translations)) { |
|
48 | + $translations = []; |
|
49 | + } |
|
50 | + $newPostIds = array_merge( |
|
51 | + $newPostIds, |
|
52 | + array_column($translations, 'element_id') |
|
53 | + ); |
|
54 | + } |
|
55 | + return Arr::unique($newPostIds); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * {@inheritdoc} |
|
60 | - */ |
|
61 | - public function isActive() |
|
62 | - { |
|
63 | - return defined('ICL_SITEPRESS_VERSION'); |
|
64 | - } |
|
58 | + /** |
|
59 | + * {@inheritdoc} |
|
60 | + */ |
|
61 | + public function isActive() |
|
62 | + { |
|
63 | + return defined('ICL_SITEPRESS_VERSION'); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * {@inheritdoc} |
|
68 | - */ |
|
69 | - public function isEnabled() |
|
70 | - { |
|
71 | - return $this->isActive() |
|
72 | - && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
73 | - } |
|
66 | + /** |
|
67 | + * {@inheritdoc} |
|
68 | + */ |
|
69 | + public function isEnabled() |
|
70 | + { |
|
71 | + return $this->isActive() |
|
72 | + && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * {@inheritdoc} |
|
77 | - */ |
|
78 | - public function isSupported() |
|
79 | - { |
|
80 | - return $this->isActive() |
|
81 | - && Helper::isGreaterThanOrEqual(ICL_SITEPRESS_VERSION, $this->supportedVersion); |
|
82 | - } |
|
75 | + /** |
|
76 | + * {@inheritdoc} |
|
77 | + */ |
|
78 | + public function isSupported() |
|
79 | + { |
|
80 | + return $this->isActive() |
|
81 | + && Helper::isGreaterThanOrEqual(ICL_SITEPRESS_VERSION, $this->supportedVersion); |
|
82 | + } |
|
83 | 83 | } |
@@ -15,44 +15,44 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * {@inheritdoc} |
17 | 17 | */ |
18 | - public function getPostId($postId) |
|
18 | + public function getPostId( $postId ) |
|
19 | 19 | { |
20 | - $postId = trim($postId); |
|
21 | - if (!is_numeric($postId)) { |
|
20 | + $postId = trim( $postId ); |
|
21 | + if( !is_numeric( $postId ) ) { |
|
22 | 22 | return 0; |
23 | 23 | } |
24 | - if ($this->isEnabled()) { |
|
25 | - $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
24 | + if( $this->isEnabled() ) { |
|
25 | + $postId = apply_filters( 'wpml_object_id', $postId, 'any', true ); |
|
26 | 26 | } |
27 | - return intval($postId); |
|
27 | + return intval( $postId ); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * {@inheritdoc} |
32 | 32 | */ |
33 | - public function getPostIds(array $postIds) |
|
33 | + public function getPostIds( array $postIds ) |
|
34 | 34 | { |
35 | - if (!$this->isEnabled()) { |
|
35 | + if( !$this->isEnabled() ) { |
|
36 | 36 | return $postIds; |
37 | 37 | } |
38 | 38 | $newPostIds = []; |
39 | - foreach (Arr::unique($postIds) as $postId) { |
|
40 | - $postType = get_post_type($postId); |
|
41 | - if (!$postType) { |
|
39 | + foreach( Arr::unique( $postIds ) as $postId ) { |
|
40 | + $postType = get_post_type( $postId ); |
|
41 | + if( !$postType ) { |
|
42 | 42 | continue; |
43 | 43 | } |
44 | 44 | $elementType = 'post_'.$postType; |
45 | - $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
46 | - $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
47 | - if (!is_array($translations)) { |
|
45 | + $trid = apply_filters( 'wpml_element_trid', null, $postId, $elementType ); |
|
46 | + $translations = apply_filters( 'wpml_get_element_translations', null, $trid, $elementType ); |
|
47 | + if( !is_array( $translations ) ) { |
|
48 | 48 | $translations = []; |
49 | 49 | } |
50 | 50 | $newPostIds = array_merge( |
51 | 51 | $newPostIds, |
52 | - array_column($translations, 'element_id') |
|
52 | + array_column( $translations, 'element_id' ) |
|
53 | 53 | ); |
54 | 54 | } |
55 | - return Arr::unique($newPostIds); |
|
55 | + return Arr::unique( $newPostIds ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function isActive() |
62 | 62 | { |
63 | - return defined('ICL_SITEPRESS_VERSION'); |
|
63 | + return defined( 'ICL_SITEPRESS_VERSION' ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function isEnabled() |
70 | 70 | { |
71 | 71 | return $this->isActive() |
72 | - && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
72 | + && 'wpml' == glsr( OptionManager::class )->get( 'settings.general.multilingual' ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -78,6 +78,6 @@ discard block |
||
78 | 78 | public function isSupported() |
79 | 79 | { |
80 | 80 | return $this->isActive() |
81 | - && Helper::isGreaterThanOrEqual(ICL_SITEPRESS_VERSION, $this->supportedVersion); |
|
81 | + && Helper::isGreaterThanOrEqual( ICL_SITEPRESS_VERSION, $this->supportedVersion ); |
|
82 | 82 | } |
83 | 83 | } |
@@ -9,71 +9,71 @@ |
||
9 | 9 | |
10 | 10 | class Polylang implements Contract |
11 | 11 | { |
12 | - public $pluginName = 'Polylang'; |
|
13 | - public $supportedVersion = '2.3'; |
|
12 | + public $pluginName = 'Polylang'; |
|
13 | + public $supportedVersion = '2.3'; |
|
14 | 14 | |
15 | - /** |
|
16 | - * {@inheritdoc} |
|
17 | - */ |
|
18 | - public function getPostId($postId) |
|
19 | - { |
|
20 | - $postId = trim($postId); |
|
21 | - if (!is_numeric($postId)) { |
|
22 | - return 0; |
|
23 | - } |
|
24 | - if ($this->isEnabled()) { |
|
25 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
26 | - } |
|
27 | - if (!empty($polylangPostId)) { |
|
28 | - $postId = $polylangPostId; |
|
29 | - } |
|
30 | - return intval($postId); |
|
31 | - } |
|
15 | + /** |
|
16 | + * {@inheritdoc} |
|
17 | + */ |
|
18 | + public function getPostId($postId) |
|
19 | + { |
|
20 | + $postId = trim($postId); |
|
21 | + if (!is_numeric($postId)) { |
|
22 | + return 0; |
|
23 | + } |
|
24 | + if ($this->isEnabled()) { |
|
25 | + $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
26 | + } |
|
27 | + if (!empty($polylangPostId)) { |
|
28 | + $postId = $polylangPostId; |
|
29 | + } |
|
30 | + return intval($postId); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * {@inheritdoc} |
|
35 | - */ |
|
36 | - public function getPostIds(array $postIds) |
|
37 | - { |
|
38 | - if (!$this->isEnabled()) { |
|
39 | - return $postIds; |
|
40 | - } |
|
41 | - $newPostIds = []; |
|
42 | - foreach (Arr::unique($postIds) as $postId) { |
|
43 | - $newPostIds = array_merge( |
|
44 | - $newPostIds, |
|
45 | - array_values(pll_get_post_translations($postId)) |
|
46 | - ); |
|
47 | - } |
|
48 | - return Arr::unique($newPostIds); |
|
49 | - } |
|
33 | + /** |
|
34 | + * {@inheritdoc} |
|
35 | + */ |
|
36 | + public function getPostIds(array $postIds) |
|
37 | + { |
|
38 | + if (!$this->isEnabled()) { |
|
39 | + return $postIds; |
|
40 | + } |
|
41 | + $newPostIds = []; |
|
42 | + foreach (Arr::unique($postIds) as $postId) { |
|
43 | + $newPostIds = array_merge( |
|
44 | + $newPostIds, |
|
45 | + array_values(pll_get_post_translations($postId)) |
|
46 | + ); |
|
47 | + } |
|
48 | + return Arr::unique($newPostIds); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * {@inheritdoc} |
|
53 | - */ |
|
54 | - public function isActive() |
|
55 | - { |
|
56 | - return function_exists('PLL') |
|
57 | - && function_exists('pll_get_post') |
|
58 | - && function_exists('pll_get_post_language') |
|
59 | - && function_exists('pll_get_post_translations'); |
|
60 | - } |
|
51 | + /** |
|
52 | + * {@inheritdoc} |
|
53 | + */ |
|
54 | + public function isActive() |
|
55 | + { |
|
56 | + return function_exists('PLL') |
|
57 | + && function_exists('pll_get_post') |
|
58 | + && function_exists('pll_get_post_language') |
|
59 | + && function_exists('pll_get_post_translations'); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * {@inheritdoc} |
|
64 | - */ |
|
65 | - public function isEnabled() |
|
66 | - { |
|
67 | - return $this->isActive() |
|
68 | - && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
69 | - } |
|
62 | + /** |
|
63 | + * {@inheritdoc} |
|
64 | + */ |
|
65 | + public function isEnabled() |
|
66 | + { |
|
67 | + return $this->isActive() |
|
68 | + && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * {@inheritdoc} |
|
73 | - */ |
|
74 | - public function isSupported() |
|
75 | - { |
|
76 | - return defined('POLYLANG_VERSION') |
|
77 | - && Helper::isGreaterThanOrEqual(POLYLANG_VERSION, $this->supportedVersion); |
|
78 | - } |
|
71 | + /** |
|
72 | + * {@inheritdoc} |
|
73 | + */ |
|
74 | + public function isSupported() |
|
75 | + { |
|
76 | + return defined('POLYLANG_VERSION') |
|
77 | + && Helper::isGreaterThanOrEqual(POLYLANG_VERSION, $this->supportedVersion); |
|
78 | + } |
|
79 | 79 | } |
@@ -15,37 +15,37 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * {@inheritdoc} |
17 | 17 | */ |
18 | - public function getPostId($postId) |
|
18 | + public function getPostId( $postId ) |
|
19 | 19 | { |
20 | - $postId = trim($postId); |
|
21 | - if (!is_numeric($postId)) { |
|
20 | + $postId = trim( $postId ); |
|
21 | + if( !is_numeric( $postId ) ) { |
|
22 | 22 | return 0; |
23 | 23 | } |
24 | - if ($this->isEnabled()) { |
|
25 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
24 | + if( $this->isEnabled() ) { |
|
25 | + $polylangPostId = pll_get_post( $postId, pll_get_post_language( get_the_ID() ) ); |
|
26 | 26 | } |
27 | - if (!empty($polylangPostId)) { |
|
27 | + if( !empty($polylangPostId) ) { |
|
28 | 28 | $postId = $polylangPostId; |
29 | 29 | } |
30 | - return intval($postId); |
|
30 | + return intval( $postId ); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * {@inheritdoc} |
35 | 35 | */ |
36 | - public function getPostIds(array $postIds) |
|
36 | + public function getPostIds( array $postIds ) |
|
37 | 37 | { |
38 | - if (!$this->isEnabled()) { |
|
38 | + if( !$this->isEnabled() ) { |
|
39 | 39 | return $postIds; |
40 | 40 | } |
41 | 41 | $newPostIds = []; |
42 | - foreach (Arr::unique($postIds) as $postId) { |
|
42 | + foreach( Arr::unique( $postIds ) as $postId ) { |
|
43 | 43 | $newPostIds = array_merge( |
44 | 44 | $newPostIds, |
45 | - array_values(pll_get_post_translations($postId)) |
|
45 | + array_values( pll_get_post_translations( $postId ) ) |
|
46 | 46 | ); |
47 | 47 | } |
48 | - return Arr::unique($newPostIds); |
|
48 | + return Arr::unique( $newPostIds ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function isActive() |
55 | 55 | { |
56 | - return function_exists('PLL') |
|
57 | - && function_exists('pll_get_post') |
|
58 | - && function_exists('pll_get_post_language') |
|
59 | - && function_exists('pll_get_post_translations'); |
|
56 | + return function_exists( 'PLL' ) |
|
57 | + && function_exists( 'pll_get_post' ) |
|
58 | + && function_exists( 'pll_get_post_language' ) |
|
59 | + && function_exists( 'pll_get_post_translations' ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | public function isEnabled() |
66 | 66 | { |
67 | 67 | return $this->isActive() |
68 | - && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
68 | + && 'polylang' == glsr( OptionManager::class )->get( 'settings.general.multilingual' ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function isSupported() |
75 | 75 | { |
76 | - return defined('POLYLANG_VERSION') |
|
77 | - && Helper::isGreaterThanOrEqual(POLYLANG_VERSION, $this->supportedVersion); |
|
76 | + return defined( 'POLYLANG_VERSION' ) |
|
77 | + && Helper::isGreaterThanOrEqual( POLYLANG_VERSION, $this->supportedVersion ); |
|
78 | 78 | } |
79 | 79 | } |
@@ -14,248 +14,248 @@ |
||
14 | 14 | |
15 | 15 | class CountsManager |
16 | 16 | { |
17 | - const LIMIT = 500; |
|
18 | - const META_AVERAGE = '_glsr_average'; |
|
19 | - const META_COUNT = '_glsr_count'; |
|
20 | - const META_RANKING = '_glsr_ranking'; |
|
17 | + const LIMIT = 500; |
|
18 | + const META_AVERAGE = '_glsr_average'; |
|
19 | + const META_COUNT = '_glsr_count'; |
|
20 | + const META_RANKING = '_glsr_ranking'; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @return array |
|
24 | - */ |
|
25 | - public function buildCounts(array $args = []) |
|
26 | - { |
|
27 | - $counts = [ |
|
28 | - 'local' => $this->generateEmptyCountsArray(), |
|
29 | - ]; |
|
30 | - $query = $this->queryReviews($args); |
|
31 | - while ($query) { |
|
32 | - $counts = $this->populateCountsFromQuery($query, $counts); |
|
33 | - $query = $query->has_more |
|
34 | - ? $this->queryReviews($args, end($query->reviews)->ID) |
|
35 | - : false; |
|
36 | - } |
|
37 | - return $counts; |
|
38 | - } |
|
22 | + /** |
|
23 | + * @return array |
|
24 | + */ |
|
25 | + public function buildCounts(array $args = []) |
|
26 | + { |
|
27 | + $counts = [ |
|
28 | + 'local' => $this->generateEmptyCountsArray(), |
|
29 | + ]; |
|
30 | + $query = $this->queryReviews($args); |
|
31 | + while ($query) { |
|
32 | + $counts = $this->populateCountsFromQuery($query, $counts); |
|
33 | + $query = $query->has_more |
|
34 | + ? $this->queryReviews($args, end($query->reviews)->ID) |
|
35 | + : false; |
|
36 | + } |
|
37 | + return $counts; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public function decreaseAll(Review $review) |
|
44 | - { |
|
45 | - glsr(GlobalCountsManager::class)->decrease($review); |
|
46 | - glsr(PostCountsManager::class)->decrease($review); |
|
47 | - glsr(TermCountsManager::class)->decrease($review); |
|
48 | - } |
|
40 | + /** |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public function decreaseAll(Review $review) |
|
44 | + { |
|
45 | + glsr(GlobalCountsManager::class)->decrease($review); |
|
46 | + glsr(PostCountsManager::class)->decrease($review); |
|
47 | + glsr(TermCountsManager::class)->decrease($review); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $type |
|
52 | - * @param int $rating |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function decreaseRating(array $reviewCounts, $type, $rating) |
|
56 | - { |
|
57 | - if (isset($reviewCounts[$type][$rating])) { |
|
58 | - $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
59 | - } |
|
60 | - return $reviewCounts; |
|
61 | - } |
|
50 | + /** |
|
51 | + * @param string $type |
|
52 | + * @param int $rating |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function decreaseRating(array $reviewCounts, $type, $rating) |
|
56 | + { |
|
57 | + if (isset($reviewCounts[$type][$rating])) { |
|
58 | + $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
59 | + } |
|
60 | + return $reviewCounts; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function flatten(array $reviewCounts, array $args = []) |
|
67 | - { |
|
68 | - $counts = []; |
|
69 | - array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
70 | - $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
71 | - }); |
|
72 | - $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class)); |
|
73 | - $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class)); |
|
74 | - foreach ($counts as $index => &$num) { |
|
75 | - if (!Helper::inRange($index, $min, $max)) { |
|
76 | - $num = 0; |
|
77 | - } |
|
78 | - } |
|
79 | - return $counts; |
|
80 | - } |
|
63 | + /** |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function flatten(array $reviewCounts, array $args = []) |
|
67 | + { |
|
68 | + $counts = []; |
|
69 | + array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
70 | + $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
71 | + }); |
|
72 | + $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class)); |
|
73 | + $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class)); |
|
74 | + foreach ($counts as $index => &$num) { |
|
75 | + if (!Helper::inRange($index, $min, $max)) { |
|
76 | + $num = 0; |
|
77 | + } |
|
78 | + } |
|
79 | + return $counts; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - public function getCounts(array $args = []) |
|
86 | - { |
|
87 | - $args = $this->normalizeArgs($args); |
|
88 | - $counts = $this->hasMixedAssignment($args) |
|
89 | - ? $this->buildCounts($args) // force query the database |
|
90 | - : $this->get($args); |
|
91 | - return $this->normalize($counts); |
|
92 | - } |
|
82 | + /** |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + public function getCounts(array $args = []) |
|
86 | + { |
|
87 | + $args = $this->normalizeArgs($args); |
|
88 | + $counts = $this->hasMixedAssignment($args) |
|
89 | + ? $this->buildCounts($args) // force query the database |
|
90 | + : $this->get($args); |
|
91 | + return $this->normalize($counts); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - public function increaseAll(Review $review) |
|
98 | - { |
|
99 | - glsr(GlobalCountsManager::class)->increase($review); |
|
100 | - glsr(PostCountsManager::class)->increase($review); |
|
101 | - glsr(TermCountsManager::class)->increase($review); |
|
102 | - } |
|
94 | + /** |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + public function increaseAll(Review $review) |
|
98 | + { |
|
99 | + glsr(GlobalCountsManager::class)->increase($review); |
|
100 | + glsr(PostCountsManager::class)->increase($review); |
|
101 | + glsr(TermCountsManager::class)->increase($review); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @param string $type |
|
106 | - * @param int $rating |
|
107 | - * @return array |
|
108 | - */ |
|
109 | - public function increaseRating(array $reviewCounts, $type, $rating) |
|
110 | - { |
|
111 | - if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
112 | - return $reviewCounts; |
|
113 | - } |
|
114 | - if (!array_key_exists($type, $reviewCounts)) { |
|
115 | - $reviewCounts[$type] = []; |
|
116 | - } |
|
117 | - $reviewCounts = $this->normalize($reviewCounts); |
|
118 | - $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
119 | - return $reviewCounts; |
|
120 | - } |
|
104 | + /** |
|
105 | + * @param string $type |
|
106 | + * @param int $rating |
|
107 | + * @return array |
|
108 | + */ |
|
109 | + public function increaseRating(array $reviewCounts, $type, $rating) |
|
110 | + { |
|
111 | + if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
112 | + return $reviewCounts; |
|
113 | + } |
|
114 | + if (!array_key_exists($type, $reviewCounts)) { |
|
115 | + $reviewCounts[$type] = []; |
|
116 | + } |
|
117 | + $reviewCounts = $this->normalize($reviewCounts); |
|
118 | + $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
119 | + return $reviewCounts; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public function updateAll() |
|
126 | - { |
|
127 | - glsr(GlobalCountsManager::class)->updateAll(); |
|
128 | - glsr(PostCountsManager::class)->updateAll(); |
|
129 | - glsr(TermCountsManager::class)->updateAll(); |
|
130 | - glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
131 | - } |
|
122 | + /** |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public function updateAll() |
|
126 | + { |
|
127 | + glsr(GlobalCountsManager::class)->updateAll(); |
|
128 | + glsr(PostCountsManager::class)->updateAll(); |
|
129 | + glsr(TermCountsManager::class)->updateAll(); |
|
130 | + glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - protected function combine(array $results) |
|
137 | - { |
|
138 | - if (!wp_is_numeric_array($results)) { |
|
139 | - return $results; |
|
140 | - } |
|
141 | - $mergedKeys = array_keys(array_merge(...$results)); |
|
142 | - $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray()); |
|
143 | - foreach ($results as $typeRatings) { |
|
144 | - foreach ($typeRatings as $type => $ratings) { |
|
145 | - foreach ($ratings as $index => $rating) { |
|
146 | - $counts[$type][$index] = intval($rating) + $counts[$type][$index]; |
|
147 | - } |
|
148 | - } |
|
149 | - } |
|
150 | - return $counts; |
|
151 | - } |
|
133 | + /** |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + protected function combine(array $results) |
|
137 | + { |
|
138 | + if (!wp_is_numeric_array($results)) { |
|
139 | + return $results; |
|
140 | + } |
|
141 | + $mergedKeys = array_keys(array_merge(...$results)); |
|
142 | + $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray()); |
|
143 | + foreach ($results as $typeRatings) { |
|
144 | + foreach ($typeRatings as $type => $ratings) { |
|
145 | + foreach ($ratings as $index => $rating) { |
|
146 | + $counts[$type][$index] = intval($rating) + $counts[$type][$index]; |
|
147 | + } |
|
148 | + } |
|
149 | + } |
|
150 | + return $counts; |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - protected function generateEmptyCountsArray() |
|
157 | - { |
|
158 | - return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
159 | - } |
|
153 | + /** |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + protected function generateEmptyCountsArray() |
|
157 | + { |
|
158 | + return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - protected function get($args) |
|
165 | - { |
|
166 | - $results = []; |
|
167 | - foreach ($args['post_ids'] as $postId) { |
|
168 | - $results[] = glsr(PostCountsManager::class)->get($postId); |
|
169 | - } |
|
170 | - foreach ($args['term_ids'] as $termId) { |
|
171 | - $results[] = glsr(TermCountsManager::class)->get($termId); |
|
172 | - } |
|
173 | - if (empty($results)) { |
|
174 | - $results[] = glsr(GlobalCountsManager::class)->get(); |
|
175 | - } |
|
176 | - $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback |
|
177 | - return $this->combine($results); |
|
178 | - } |
|
161 | + /** |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + protected function get($args) |
|
165 | + { |
|
166 | + $results = []; |
|
167 | + foreach ($args['post_ids'] as $postId) { |
|
168 | + $results[] = glsr(PostCountsManager::class)->get($postId); |
|
169 | + } |
|
170 | + foreach ($args['term_ids'] as $termId) { |
|
171 | + $results[] = glsr(TermCountsManager::class)->get($termId); |
|
172 | + } |
|
173 | + if (empty($results)) { |
|
174 | + $results[] = glsr(GlobalCountsManager::class)->get(); |
|
175 | + } |
|
176 | + $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback |
|
177 | + return $this->combine($results); |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * @return bool |
|
182 | - */ |
|
183 | - protected function hasMixedAssignment(array $args) |
|
184 | - { |
|
185 | - return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
186 | - } |
|
180 | + /** |
|
181 | + * @return bool |
|
182 | + */ |
|
183 | + protected function hasMixedAssignment(array $args) |
|
184 | + { |
|
185 | + return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * @return array |
|
190 | - */ |
|
191 | - protected function normalize(array $reviewCounts) |
|
192 | - { |
|
193 | - foreach ($reviewCounts as &$counts) { |
|
194 | - foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
195 | - if (!isset($counts[$index])) { |
|
196 | - $counts[$index] = 0; |
|
197 | - } |
|
198 | - } |
|
199 | - ksort($counts); |
|
200 | - } |
|
201 | - return $reviewCounts; |
|
202 | - } |
|
188 | + /** |
|
189 | + * @return array |
|
190 | + */ |
|
191 | + protected function normalize(array $reviewCounts) |
|
192 | + { |
|
193 | + foreach ($reviewCounts as &$counts) { |
|
194 | + foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
195 | + if (!isset($counts[$index])) { |
|
196 | + $counts[$index] = 0; |
|
197 | + } |
|
198 | + } |
|
199 | + ksort($counts); |
|
200 | + } |
|
201 | + return $reviewCounts; |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * @return array |
|
206 | - */ |
|
207 | - protected function normalizeArgs(array $args) |
|
208 | - { |
|
209 | - $args = wp_parse_args(array_filter($args), [ |
|
210 | - 'post_ids' => [], |
|
211 | - 'term_ids' => [], |
|
212 | - 'type' => 'local', |
|
213 | - ]); |
|
214 | - $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
215 | - $args['type'] = $this->normalizeType($args['type']); |
|
216 | - return $args; |
|
217 | - } |
|
204 | + /** |
|
205 | + * @return array |
|
206 | + */ |
|
207 | + protected function normalizeArgs(array $args) |
|
208 | + { |
|
209 | + $args = wp_parse_args(array_filter($args), [ |
|
210 | + 'post_ids' => [], |
|
211 | + 'term_ids' => [], |
|
212 | + 'type' => 'local', |
|
213 | + ]); |
|
214 | + $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
215 | + $args['type'] = $this->normalizeType($args['type']); |
|
216 | + return $args; |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * @param string $type |
|
221 | - * @return string |
|
222 | - */ |
|
223 | - protected function normalizeType($type) |
|
224 | - { |
|
225 | - return empty($type) || !is_string($type) |
|
226 | - ? 'local' |
|
227 | - : $type; |
|
228 | - } |
|
219 | + /** |
|
220 | + * @param string $type |
|
221 | + * @return string |
|
222 | + */ |
|
223 | + protected function normalizeType($type) |
|
224 | + { |
|
225 | + return empty($type) || !is_string($type) |
|
226 | + ? 'local' |
|
227 | + : $type; |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * @param object $query |
|
232 | - * @return array |
|
233 | - */ |
|
234 | - protected function populateCountsFromQuery($query, array $counts) |
|
235 | - { |
|
236 | - foreach ($query->reviews as $review) { |
|
237 | - $type = $this->normalizeType($review->type); |
|
238 | - if (!array_key_exists($type, $counts)) { |
|
239 | - $counts[$type] = $this->generateEmptyCountsArray(); |
|
240 | - } |
|
241 | - ++$counts[$type][$review->rating]; |
|
242 | - } |
|
243 | - return $counts; |
|
244 | - } |
|
230 | + /** |
|
231 | + * @param object $query |
|
232 | + * @return array |
|
233 | + */ |
|
234 | + protected function populateCountsFromQuery($query, array $counts) |
|
235 | + { |
|
236 | + foreach ($query->reviews as $review) { |
|
237 | + $type = $this->normalizeType($review->type); |
|
238 | + if (!array_key_exists($type, $counts)) { |
|
239 | + $counts[$type] = $this->generateEmptyCountsArray(); |
|
240 | + } |
|
241 | + ++$counts[$type][$review->rating]; |
|
242 | + } |
|
243 | + return $counts; |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * @param int $lastPostId |
|
248 | - * @return object |
|
249 | - */ |
|
250 | - protected function queryReviews(array $args = [], $lastPostId = 0) |
|
251 | - { |
|
252 | - $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
253 | - $hasMore = is_array($reviews) |
|
254 | - ? count($reviews) == static::LIMIT |
|
255 | - : false; |
|
256 | - return (object) [ |
|
257 | - 'has_more' => $hasMore, |
|
258 | - 'reviews' => $reviews, |
|
259 | - ]; |
|
260 | - } |
|
246 | + /** |
|
247 | + * @param int $lastPostId |
|
248 | + * @return object |
|
249 | + */ |
|
250 | + protected function queryReviews(array $args = [], $lastPostId = 0) |
|
251 | + { |
|
252 | + $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
253 | + $hasMore = is_array($reviews) |
|
254 | + ? count($reviews) == static::LIMIT |
|
255 | + : false; |
|
256 | + return (object) [ |
|
257 | + 'has_more' => $hasMore, |
|
258 | + 'reviews' => $reviews, |
|
259 | + ]; |
|
260 | + } |
|
261 | 261 | } |
@@ -22,16 +22,16 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @return array |
24 | 24 | */ |
25 | - public function buildCounts(array $args = []) |
|
25 | + public function buildCounts( array $args = [] ) |
|
26 | 26 | { |
27 | 27 | $counts = [ |
28 | 28 | 'local' => $this->generateEmptyCountsArray(), |
29 | 29 | ]; |
30 | - $query = $this->queryReviews($args); |
|
31 | - while ($query) { |
|
32 | - $counts = $this->populateCountsFromQuery($query, $counts); |
|
30 | + $query = $this->queryReviews( $args ); |
|
31 | + while( $query ) { |
|
32 | + $counts = $this->populateCountsFromQuery( $query, $counts ); |
|
33 | 33 | $query = $query->has_more |
34 | - ? $this->queryReviews($args, end($query->reviews)->ID) |
|
34 | + ? $this->queryReviews( $args, end( $query->reviews )->ID ) |
|
35 | 35 | : false; |
36 | 36 | } |
37 | 37 | return $counts; |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * @return void |
42 | 42 | */ |
43 | - public function decreaseAll(Review $review) |
|
43 | + public function decreaseAll( Review $review ) |
|
44 | 44 | { |
45 | - glsr(GlobalCountsManager::class)->decrease($review); |
|
46 | - glsr(PostCountsManager::class)->decrease($review); |
|
47 | - glsr(TermCountsManager::class)->decrease($review); |
|
45 | + glsr( GlobalCountsManager::class )->decrease( $review ); |
|
46 | + glsr( PostCountsManager::class )->decrease( $review ); |
|
47 | + glsr( TermCountsManager::class )->decrease( $review ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | * @param int $rating |
53 | 53 | * @return array |
54 | 54 | */ |
55 | - public function decreaseRating(array $reviewCounts, $type, $rating) |
|
55 | + public function decreaseRating( array $reviewCounts, $type, $rating ) |
|
56 | 56 | { |
57 | - if (isset($reviewCounts[$type][$rating])) { |
|
58 | - $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
57 | + if( isset($reviewCounts[$type][$rating]) ) { |
|
58 | + $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 ); |
|
59 | 59 | } |
60 | 60 | return $reviewCounts; |
61 | 61 | } |
@@ -63,16 +63,16 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * @return array |
65 | 65 | */ |
66 | - public function flatten(array $reviewCounts, array $args = []) |
|
66 | + public function flatten( array $reviewCounts, array $args = [] ) |
|
67 | 67 | { |
68 | 68 | $counts = []; |
69 | - array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
70 | - $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
69 | + array_walk_recursive( $reviewCounts, function( $num, $index ) use (&$counts) { |
|
70 | + $counts[$index] = $num + intval( Arr::get( $counts, $index, 0 ) ); |
|
71 | 71 | }); |
72 | - $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class)); |
|
73 | - $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class)); |
|
74 | - foreach ($counts as $index => &$num) { |
|
75 | - if (!Helper::inRange($index, $min, $max)) { |
|
72 | + $min = Arr::get( $args, 'min', glsr()->constant( 'MIN_RATING', Rating::class ) ); |
|
73 | + $max = Arr::get( $args, 'max', glsr()->constant( 'MAX_RATING', Rating::class ) ); |
|
74 | + foreach( $counts as $index => &$num ) { |
|
75 | + if( !Helper::inRange( $index, $min, $max ) ) { |
|
76 | 76 | $num = 0; |
77 | 77 | } |
78 | 78 | } |
@@ -82,23 +82,23 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * @return array |
84 | 84 | */ |
85 | - public function getCounts(array $args = []) |
|
85 | + public function getCounts( array $args = [] ) |
|
86 | 86 | { |
87 | - $args = $this->normalizeArgs($args); |
|
88 | - $counts = $this->hasMixedAssignment($args) |
|
89 | - ? $this->buildCounts($args) // force query the database |
|
90 | - : $this->get($args); |
|
91 | - return $this->normalize($counts); |
|
87 | + $args = $this->normalizeArgs( $args ); |
|
88 | + $counts = $this->hasMixedAssignment( $args ) |
|
89 | + ? $this->buildCounts( $args ) // force query the database |
|
90 | + : $this->get( $args ); |
|
91 | + return $this->normalize( $counts ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
95 | 95 | * @return void |
96 | 96 | */ |
97 | - public function increaseAll(Review $review) |
|
97 | + public function increaseAll( Review $review ) |
|
98 | 98 | { |
99 | - glsr(GlobalCountsManager::class)->increase($review); |
|
100 | - glsr(PostCountsManager::class)->increase($review); |
|
101 | - glsr(TermCountsManager::class)->increase($review); |
|
99 | + glsr( GlobalCountsManager::class )->increase( $review ); |
|
100 | + glsr( PostCountsManager::class )->increase( $review ); |
|
101 | + glsr( TermCountsManager::class )->increase( $review ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,16 +106,16 @@ discard block |
||
106 | 106 | * @param int $rating |
107 | 107 | * @return array |
108 | 108 | */ |
109 | - public function increaseRating(array $reviewCounts, $type, $rating) |
|
109 | + public function increaseRating( array $reviewCounts, $type, $rating ) |
|
110 | 110 | { |
111 | - if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
111 | + if( !array_key_exists( $type, glsr()->reviewTypes ) ) { |
|
112 | 112 | return $reviewCounts; |
113 | 113 | } |
114 | - if (!array_key_exists($type, $reviewCounts)) { |
|
114 | + if( !array_key_exists( $type, $reviewCounts ) ) { |
|
115 | 115 | $reviewCounts[$type] = []; |
116 | 116 | } |
117 | - $reviewCounts = $this->normalize($reviewCounts); |
|
118 | - $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
117 | + $reviewCounts = $this->normalize( $reviewCounts ); |
|
118 | + $reviewCounts[$type][$rating] = intval( $reviewCounts[$type][$rating] ) + 1; |
|
119 | 119 | return $reviewCounts; |
120 | 120 | } |
121 | 121 | |
@@ -124,26 +124,26 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function updateAll() |
126 | 126 | { |
127 | - glsr(GlobalCountsManager::class)->updateAll(); |
|
128 | - glsr(PostCountsManager::class)->updateAll(); |
|
129 | - glsr(TermCountsManager::class)->updateAll(); |
|
130 | - glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
127 | + glsr( GlobalCountsManager::class )->updateAll(); |
|
128 | + glsr( PostCountsManager::class )->updateAll(); |
|
129 | + glsr( TermCountsManager::class )->updateAll(); |
|
130 | + glsr( OptionManager::class )->set( 'last_review_count', current_time( 'timestamp' ) ); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | 134 | * @return array |
135 | 135 | */ |
136 | - protected function combine(array $results) |
|
136 | + protected function combine( array $results ) |
|
137 | 137 | { |
138 | - if (!wp_is_numeric_array($results)) { |
|
138 | + if( !wp_is_numeric_array( $results ) ) { |
|
139 | 139 | return $results; |
140 | 140 | } |
141 | - $mergedKeys = array_keys(array_merge(...$results)); |
|
142 | - $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray()); |
|
143 | - foreach ($results as $typeRatings) { |
|
144 | - foreach ($typeRatings as $type => $ratings) { |
|
145 | - foreach ($ratings as $index => $rating) { |
|
146 | - $counts[$type][$index] = intval($rating) + $counts[$type][$index]; |
|
141 | + $mergedKeys = array_keys( array_merge( ...$results ) ); |
|
142 | + $counts = array_fill_keys( $mergedKeys, $this->generateEmptyCountsArray() ); |
|
143 | + foreach( $results as $typeRatings ) { |
|
144 | + foreach( $typeRatings as $type => $ratings ) { |
|
145 | + foreach( $ratings as $index => $rating ) { |
|
146 | + $counts[$type][$index] = intval( $rating ) + $counts[$type][$index]; |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | } |
@@ -155,32 +155,32 @@ discard block |
||
155 | 155 | */ |
156 | 156 | protected function generateEmptyCountsArray() |
157 | 157 | { |
158 | - return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
158 | + return array_fill_keys( range( 0, glsr()->constant( 'MAX_RATING', Rating::class ) ), 0 ); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | 162 | * @return array |
163 | 163 | */ |
164 | - protected function get($args) |
|
164 | + protected function get( $args ) |
|
165 | 165 | { |
166 | 166 | $results = []; |
167 | - foreach ($args['post_ids'] as $postId) { |
|
168 | - $results[] = glsr(PostCountsManager::class)->get($postId); |
|
167 | + foreach( $args['post_ids'] as $postId ) { |
|
168 | + $results[] = glsr( PostCountsManager::class )->get( $postId ); |
|
169 | 169 | } |
170 | - foreach ($args['term_ids'] as $termId) { |
|
171 | - $results[] = glsr(TermCountsManager::class)->get($termId); |
|
170 | + foreach( $args['term_ids'] as $termId ) { |
|
171 | + $results[] = glsr( TermCountsManager::class )->get( $termId ); |
|
172 | 172 | } |
173 | - if (empty($results)) { |
|
174 | - $results[] = glsr(GlobalCountsManager::class)->get(); |
|
173 | + if( empty($results) ) { |
|
174 | + $results[] = glsr( GlobalCountsManager::class )->get(); |
|
175 | 175 | } |
176 | 176 | $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback |
177 | - return $this->combine($results); |
|
177 | + return $this->combine( $results ); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
181 | 181 | * @return bool |
182 | 182 | */ |
183 | - protected function hasMixedAssignment(array $args) |
|
183 | + protected function hasMixedAssignment( array $args ) |
|
184 | 184 | { |
185 | 185 | return !empty($args['post_ids']) && !empty($args['term_ids']); |
186 | 186 | } |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | /** |
189 | 189 | * @return array |
190 | 190 | */ |
191 | - protected function normalize(array $reviewCounts) |
|
191 | + protected function normalize( array $reviewCounts ) |
|
192 | 192 | { |
193 | - foreach ($reviewCounts as &$counts) { |
|
194 | - foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
195 | - if (!isset($counts[$index])) { |
|
193 | + foreach( $reviewCounts as &$counts ) { |
|
194 | + foreach( array_keys( $this->generateEmptyCountsArray() ) as $index ) { |
|
195 | + if( !isset($counts[$index]) ) { |
|
196 | 196 | $counts[$index] = 0; |
197 | 197 | } |
198 | 198 | } |
199 | - ksort($counts); |
|
199 | + ksort( $counts ); |
|
200 | 200 | } |
201 | 201 | return $reviewCounts; |
202 | 202 | } |
@@ -204,15 +204,15 @@ discard block |
||
204 | 204 | /** |
205 | 205 | * @return array |
206 | 206 | */ |
207 | - protected function normalizeArgs(array $args) |
|
207 | + protected function normalizeArgs( array $args ) |
|
208 | 208 | { |
209 | - $args = wp_parse_args(array_filter($args), [ |
|
209 | + $args = wp_parse_args( array_filter( $args ), [ |
|
210 | 210 | 'post_ids' => [], |
211 | 211 | 'term_ids' => [], |
212 | 212 | 'type' => 'local', |
213 | - ]); |
|
214 | - $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
215 | - $args['type'] = $this->normalizeType($args['type']); |
|
213 | + ] ); |
|
214 | + $args['post_ids'] = glsr( Multilingual::class )->getPostIds( $args['post_ids'] ); |
|
215 | + $args['type'] = $this->normalizeType( $args['type'] ); |
|
216 | 216 | return $args; |
217 | 217 | } |
218 | 218 | |
@@ -220,9 +220,9 @@ discard block |
||
220 | 220 | * @param string $type |
221 | 221 | * @return string |
222 | 222 | */ |
223 | - protected function normalizeType($type) |
|
223 | + protected function normalizeType( $type ) |
|
224 | 224 | { |
225 | - return empty($type) || !is_string($type) |
|
225 | + return empty($type) || !is_string( $type ) |
|
226 | 226 | ? 'local' |
227 | 227 | : $type; |
228 | 228 | } |
@@ -231,11 +231,11 @@ discard block |
||
231 | 231 | * @param object $query |
232 | 232 | * @return array |
233 | 233 | */ |
234 | - protected function populateCountsFromQuery($query, array $counts) |
|
234 | + protected function populateCountsFromQuery( $query, array $counts ) |
|
235 | 235 | { |
236 | - foreach ($query->reviews as $review) { |
|
237 | - $type = $this->normalizeType($review->type); |
|
238 | - if (!array_key_exists($type, $counts)) { |
|
236 | + foreach( $query->reviews as $review ) { |
|
237 | + $type = $this->normalizeType( $review->type ); |
|
238 | + if( !array_key_exists( $type, $counts ) ) { |
|
239 | 239 | $counts[$type] = $this->generateEmptyCountsArray(); |
240 | 240 | } |
241 | 241 | ++$counts[$type][$review->rating]; |
@@ -247,13 +247,13 @@ discard block |
||
247 | 247 | * @param int $lastPostId |
248 | 248 | * @return object |
249 | 249 | */ |
250 | - protected function queryReviews(array $args = [], $lastPostId = 0) |
|
250 | + protected function queryReviews( array $args = [], $lastPostId = 0 ) |
|
251 | 251 | { |
252 | - $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
253 | - $hasMore = is_array($reviews) |
|
254 | - ? count($reviews) == static::LIMIT |
|
252 | + $reviews = glsr( SqlQueries::class )->getReviewCounts( $args, $lastPostId, static::LIMIT ); |
|
253 | + $hasMore = is_array( $reviews ) |
|
254 | + ? count( $reviews ) == static::LIMIT |
|
255 | 255 | : false; |
256 | - return (object) [ |
|
256 | + return (object)[ |
|
257 | 257 | 'has_more' => $hasMore, |
258 | 258 | 'reviews' => $reviews, |
259 | 259 | ]; |
@@ -6,133 +6,133 @@ |
||
6 | 6 | |
7 | 7 | class Role |
8 | 8 | { |
9 | - /** |
|
10 | - * @param string $role |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function addCapabilities($role) |
|
14 | - { |
|
15 | - $roleCapabilities = $this->roleCapabilities(); |
|
16 | - $wpRole = get_role($role); |
|
17 | - if (empty($wpRole) || !array_key_exists($role, $roleCapabilities)) { |
|
18 | - return; |
|
19 | - } |
|
20 | - foreach ($roleCapabilities[$role] as $capability) { |
|
21 | - $wpRole->add_cap($this->normalizeCapability($capability)); |
|
22 | - } |
|
23 | - } |
|
9 | + /** |
|
10 | + * @param string $role |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function addCapabilities($role) |
|
14 | + { |
|
15 | + $roleCapabilities = $this->roleCapabilities(); |
|
16 | + $wpRole = get_role($role); |
|
17 | + if (empty($wpRole) || !array_key_exists($role, $roleCapabilities)) { |
|
18 | + return; |
|
19 | + } |
|
20 | + foreach ($roleCapabilities[$role] as $capability) { |
|
21 | + $wpRole->add_cap($this->normalizeCapability($capability)); |
|
22 | + } |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param string $capability |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public function can($capability) |
|
30 | - { |
|
31 | - return in_array($capability, $this->capabilities()) |
|
32 | - ? current_user_can($this->normalizeCapability($capability)) |
|
33 | - : current_user_can($capability); |
|
34 | - } |
|
25 | + /** |
|
26 | + * @param string $capability |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public function can($capability) |
|
30 | + { |
|
31 | + return in_array($capability, $this->capabilities()) |
|
32 | + ? current_user_can($this->normalizeCapability($capability)) |
|
33 | + : current_user_can($capability); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $role |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public function removeCapabilities($role) |
|
41 | - { |
|
42 | - $wpRole = get_role($role); |
|
43 | - if (empty($wpRole) || 'administrator' === $role) { // do not remove from administrator role |
|
44 | - return; |
|
45 | - } |
|
46 | - foreach ($this->capabilities() as $capability) { |
|
47 | - $wpRole->remove_cap($this->normalizeCapability($capability)); |
|
48 | - } |
|
49 | - } |
|
36 | + /** |
|
37 | + * @param string $role |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public function removeCapabilities($role) |
|
41 | + { |
|
42 | + $wpRole = get_role($role); |
|
43 | + if (empty($wpRole) || 'administrator' === $role) { // do not remove from administrator role |
|
44 | + return; |
|
45 | + } |
|
46 | + foreach ($this->capabilities() as $capability) { |
|
47 | + $wpRole->remove_cap($this->normalizeCapability($capability)); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function resetAll() |
|
55 | - { |
|
56 | - $roles = array_keys(wp_roles()->roles); |
|
57 | - array_walk($roles, [$this, 'removeCapabilities']); |
|
58 | - $roles = array_keys($this->roleCapabilities()); |
|
59 | - array_walk($roles, [$this, 'addCapabilities']); |
|
60 | - } |
|
51 | + /** |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function resetAll() |
|
55 | + { |
|
56 | + $roles = array_keys(wp_roles()->roles); |
|
57 | + array_walk($roles, [$this, 'removeCapabilities']); |
|
58 | + $roles = array_keys($this->roleCapabilities()); |
|
59 | + array_walk($roles, [$this, 'addCapabilities']); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - protected function capabilities() |
|
66 | - { |
|
67 | - $capabilities = [ |
|
68 | - 'delete_others_posts', |
|
69 | - 'delete_post', |
|
70 | - 'delete_posts', |
|
71 | - 'delete_private_posts', |
|
72 | - 'delete_published_posts', |
|
73 | - 'edit_others_posts', |
|
74 | - 'edit_post', |
|
75 | - 'edit_posts', |
|
76 | - 'edit_private_posts', |
|
77 | - 'edit_published_posts', |
|
78 | - 'publish_posts', |
|
79 | - 'read_post', |
|
80 | - 'read_private_posts', |
|
81 | - ]; |
|
82 | - return apply_filters('site-reviews/capabilities', $capabilities); |
|
83 | - } |
|
62 | + /** |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + protected function capabilities() |
|
66 | + { |
|
67 | + $capabilities = [ |
|
68 | + 'delete_others_posts', |
|
69 | + 'delete_post', |
|
70 | + 'delete_posts', |
|
71 | + 'delete_private_posts', |
|
72 | + 'delete_published_posts', |
|
73 | + 'edit_others_posts', |
|
74 | + 'edit_post', |
|
75 | + 'edit_posts', |
|
76 | + 'edit_private_posts', |
|
77 | + 'edit_published_posts', |
|
78 | + 'publish_posts', |
|
79 | + 'read_post', |
|
80 | + 'read_private_posts', |
|
81 | + ]; |
|
82 | + return apply_filters('site-reviews/capabilities', $capabilities); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param string $capability |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - protected function normalizeCapability($capability) |
|
90 | - { |
|
91 | - return str_replace('post', Application::POST_TYPE, $capability); |
|
92 | - } |
|
85 | + /** |
|
86 | + * @param string $capability |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + protected function normalizeCapability($capability) |
|
90 | + { |
|
91 | + return str_replace('post', Application::POST_TYPE, $capability); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - protected function roleCapabilities() |
|
98 | - { |
|
99 | - $capabilities = [ |
|
100 | - 'administrator' => [ |
|
101 | - 'delete_others_posts', |
|
102 | - 'delete_posts', |
|
103 | - 'delete_private_posts', |
|
104 | - 'delete_published_posts', |
|
105 | - 'edit_others_posts', |
|
106 | - 'edit_posts', |
|
107 | - 'edit_private_posts', |
|
108 | - 'edit_published_posts', |
|
109 | - 'publish_posts', |
|
110 | - 'read_private_posts', |
|
111 | - ], |
|
112 | - 'editor' => [ |
|
113 | - 'delete_others_posts', |
|
114 | - 'delete_posts', |
|
115 | - 'delete_private_posts', |
|
116 | - 'delete_published_posts', |
|
117 | - 'edit_others_posts', |
|
118 | - 'edit_posts', |
|
119 | - 'edit_private_posts', |
|
120 | - 'edit_published_posts', |
|
121 | - 'publish_posts', |
|
122 | - 'read_private_posts', |
|
123 | - ], |
|
124 | - 'author' => [ |
|
125 | - 'delete_posts', |
|
126 | - 'delete_published_posts', |
|
127 | - 'edit_posts', |
|
128 | - 'edit_published_posts', |
|
129 | - 'publish_posts', |
|
130 | - ], |
|
131 | - 'contributor' => [ |
|
132 | - 'delete_posts', |
|
133 | - 'edit_posts', |
|
134 | - ], |
|
135 | - ]; |
|
136 | - return apply_filters('site-reviews/capabilities/for-roles', $capabilities); |
|
137 | - } |
|
94 | + /** |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + protected function roleCapabilities() |
|
98 | + { |
|
99 | + $capabilities = [ |
|
100 | + 'administrator' => [ |
|
101 | + 'delete_others_posts', |
|
102 | + 'delete_posts', |
|
103 | + 'delete_private_posts', |
|
104 | + 'delete_published_posts', |
|
105 | + 'edit_others_posts', |
|
106 | + 'edit_posts', |
|
107 | + 'edit_private_posts', |
|
108 | + 'edit_published_posts', |
|
109 | + 'publish_posts', |
|
110 | + 'read_private_posts', |
|
111 | + ], |
|
112 | + 'editor' => [ |
|
113 | + 'delete_others_posts', |
|
114 | + 'delete_posts', |
|
115 | + 'delete_private_posts', |
|
116 | + 'delete_published_posts', |
|
117 | + 'edit_others_posts', |
|
118 | + 'edit_posts', |
|
119 | + 'edit_private_posts', |
|
120 | + 'edit_published_posts', |
|
121 | + 'publish_posts', |
|
122 | + 'read_private_posts', |
|
123 | + ], |
|
124 | + 'author' => [ |
|
125 | + 'delete_posts', |
|
126 | + 'delete_published_posts', |
|
127 | + 'edit_posts', |
|
128 | + 'edit_published_posts', |
|
129 | + 'publish_posts', |
|
130 | + ], |
|
131 | + 'contributor' => [ |
|
132 | + 'delete_posts', |
|
133 | + 'edit_posts', |
|
134 | + ], |
|
135 | + ]; |
|
136 | + return apply_filters('site-reviews/capabilities/for-roles', $capabilities); |
|
137 | + } |
|
138 | 138 | } |
@@ -10,15 +10,15 @@ discard block |
||
10 | 10 | * @param string $role |
11 | 11 | * @return void |
12 | 12 | */ |
13 | - public function addCapabilities($role) |
|
13 | + public function addCapabilities( $role ) |
|
14 | 14 | { |
15 | 15 | $roleCapabilities = $this->roleCapabilities(); |
16 | - $wpRole = get_role($role); |
|
17 | - if (empty($wpRole) || !array_key_exists($role, $roleCapabilities)) { |
|
16 | + $wpRole = get_role( $role ); |
|
17 | + if( empty($wpRole) || !array_key_exists( $role, $roleCapabilities ) ) { |
|
18 | 18 | return; |
19 | 19 | } |
20 | - foreach ($roleCapabilities[$role] as $capability) { |
|
21 | - $wpRole->add_cap($this->normalizeCapability($capability)); |
|
20 | + foreach( $roleCapabilities[$role] as $capability ) { |
|
21 | + $wpRole->add_cap( $this->normalizeCapability( $capability ) ); |
|
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
@@ -26,25 +26,25 @@ discard block |
||
26 | 26 | * @param string $capability |
27 | 27 | * @return bool |
28 | 28 | */ |
29 | - public function can($capability) |
|
29 | + public function can( $capability ) |
|
30 | 30 | { |
31 | - return in_array($capability, $this->capabilities()) |
|
32 | - ? current_user_can($this->normalizeCapability($capability)) |
|
33 | - : current_user_can($capability); |
|
31 | + return in_array( $capability, $this->capabilities() ) |
|
32 | + ? current_user_can( $this->normalizeCapability( $capability ) ) |
|
33 | + : current_user_can( $capability ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @param string $role |
38 | 38 | * @return void |
39 | 39 | */ |
40 | - public function removeCapabilities($role) |
|
40 | + public function removeCapabilities( $role ) |
|
41 | 41 | { |
42 | - $wpRole = get_role($role); |
|
43 | - if (empty($wpRole) || 'administrator' === $role) { // do not remove from administrator role |
|
42 | + $wpRole = get_role( $role ); |
|
43 | + if( empty($wpRole) || 'administrator' === $role ) { // do not remove from administrator role |
|
44 | 44 | return; |
45 | 45 | } |
46 | - foreach ($this->capabilities() as $capability) { |
|
47 | - $wpRole->remove_cap($this->normalizeCapability($capability)); |
|
46 | + foreach( $this->capabilities() as $capability ) { |
|
47 | + $wpRole->remove_cap( $this->normalizeCapability( $capability ) ); |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function resetAll() |
55 | 55 | { |
56 | - $roles = array_keys(wp_roles()->roles); |
|
57 | - array_walk($roles, [$this, 'removeCapabilities']); |
|
58 | - $roles = array_keys($this->roleCapabilities()); |
|
59 | - array_walk($roles, [$this, 'addCapabilities']); |
|
56 | + $roles = array_keys( wp_roles()->roles ); |
|
57 | + array_walk( $roles, [$this, 'removeCapabilities'] ); |
|
58 | + $roles = array_keys( $this->roleCapabilities() ); |
|
59 | + array_walk( $roles, [$this, 'addCapabilities'] ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -79,16 +79,16 @@ discard block |
||
79 | 79 | 'read_post', |
80 | 80 | 'read_private_posts', |
81 | 81 | ]; |
82 | - return apply_filters('site-reviews/capabilities', $capabilities); |
|
82 | + return apply_filters( 'site-reviews/capabilities', $capabilities ); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
86 | 86 | * @param string $capability |
87 | 87 | * @return string |
88 | 88 | */ |
89 | - protected function normalizeCapability($capability) |
|
89 | + protected function normalizeCapability( $capability ) |
|
90 | 90 | { |
91 | - return str_replace('post', Application::POST_TYPE, $capability); |
|
91 | + return str_replace( 'post', Application::POST_TYPE, $capability ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -133,6 +133,6 @@ discard block |
||
133 | 133 | 'edit_posts', |
134 | 134 | ], |
135 | 135 | ]; |
136 | - return apply_filters('site-reviews/capabilities/for-roles', $capabilities); |
|
136 | + return apply_filters( 'site-reviews/capabilities/for-roles', $capabilities ); |
|
137 | 137 | } |
138 | 138 | } |
@@ -15,197 +15,197 @@ |
||
15 | 15 | |
16 | 16 | class MenuController extends Controller |
17 | 17 | { |
18 | - /** |
|
19 | - * @return void |
|
20 | - * @action admin_menu |
|
21 | - */ |
|
22 | - public function registerMenuCount() |
|
23 | - { |
|
24 | - global $menu, $typenow; |
|
25 | - foreach ($menu as $key => $value) { |
|
26 | - if (!isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE) { |
|
27 | - continue; |
|
28 | - } |
|
29 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
30 | - $pendingCount = glsr(Builder::class)->span(number_format_i18n($postCount->pending), [ |
|
31 | - 'class' => 'unapproved-count', |
|
32 | - ]); |
|
33 | - $awaitingModeration = glsr(Builder::class)->span($pendingCount, [ |
|
34 | - 'class' => 'awaiting-mod count-'.$postCount->pending, |
|
35 | - ]); |
|
36 | - $menu[$key][0].= ' '.$awaitingModeration; |
|
37 | - if (Application::POST_TYPE === $typenow) { |
|
38 | - $menu[$key][4].= ' current'; |
|
39 | - } |
|
40 | - break; |
|
41 | - } |
|
42 | - } |
|
18 | + /** |
|
19 | + * @return void |
|
20 | + * @action admin_menu |
|
21 | + */ |
|
22 | + public function registerMenuCount() |
|
23 | + { |
|
24 | + global $menu, $typenow; |
|
25 | + foreach ($menu as $key => $value) { |
|
26 | + if (!isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE) { |
|
27 | + continue; |
|
28 | + } |
|
29 | + $postCount = wp_count_posts(Application::POST_TYPE); |
|
30 | + $pendingCount = glsr(Builder::class)->span(number_format_i18n($postCount->pending), [ |
|
31 | + 'class' => 'unapproved-count', |
|
32 | + ]); |
|
33 | + $awaitingModeration = glsr(Builder::class)->span($pendingCount, [ |
|
34 | + 'class' => 'awaiting-mod count-'.$postCount->pending, |
|
35 | + ]); |
|
36 | + $menu[$key][0].= ' '.$awaitingModeration; |
|
37 | + if (Application::POST_TYPE === $typenow) { |
|
38 | + $menu[$key][4].= ' current'; |
|
39 | + } |
|
40 | + break; |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return void |
|
46 | - * @action admin_menu |
|
47 | - */ |
|
48 | - public function registerSubMenus() |
|
49 | - { |
|
50 | - $pages = $this->parseWithFilter('submenu/pages', [ |
|
51 | - 'settings' => __('Settings', 'site-reviews'), |
|
52 | - 'tools' => __('Tools', 'site-reviews'), |
|
53 | - 'addons' => __('Add-ons', 'site-reviews'), |
|
54 | - 'documentation' => __('Help', 'site-reviews'), |
|
55 | - ]); |
|
56 | - foreach ($pages as $slug => $title) { |
|
57 | - $method = Helper::buildMethodName('render-'.$slug.'-menu'); |
|
58 | - $callback = apply_filters('site-reviews/addon/submenu/callback', [$this, $method], $slug); |
|
59 | - if (!is_callable($callback)) { |
|
60 | - continue; |
|
61 | - } |
|
62 | - add_submenu_page('edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission($slug), $slug, $callback); |
|
63 | - } |
|
64 | - } |
|
44 | + /** |
|
45 | + * @return void |
|
46 | + * @action admin_menu |
|
47 | + */ |
|
48 | + public function registerSubMenus() |
|
49 | + { |
|
50 | + $pages = $this->parseWithFilter('submenu/pages', [ |
|
51 | + 'settings' => __('Settings', 'site-reviews'), |
|
52 | + 'tools' => __('Tools', 'site-reviews'), |
|
53 | + 'addons' => __('Add-ons', 'site-reviews'), |
|
54 | + 'documentation' => __('Help', 'site-reviews'), |
|
55 | + ]); |
|
56 | + foreach ($pages as $slug => $title) { |
|
57 | + $method = Helper::buildMethodName('render-'.$slug.'-menu'); |
|
58 | + $callback = apply_filters('site-reviews/addon/submenu/callback', [$this, $method], $slug); |
|
59 | + if (!is_callable($callback)) { |
|
60 | + continue; |
|
61 | + } |
|
62 | + add_submenu_page('edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission($slug), $slug, $callback); |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return void |
|
68 | - * @see $this->registerSubMenus() |
|
69 | - * @callback add_submenu_page |
|
70 | - */ |
|
71 | - public function renderAddonsMenu() |
|
72 | - { |
|
73 | - $this->renderPage('addons', [ |
|
74 | - 'template' => glsr(Template::class), |
|
75 | - ]); |
|
76 | - } |
|
66 | + /** |
|
67 | + * @return void |
|
68 | + * @see $this->registerSubMenus() |
|
69 | + * @callback add_submenu_page |
|
70 | + */ |
|
71 | + public function renderAddonsMenu() |
|
72 | + { |
|
73 | + $this->renderPage('addons', [ |
|
74 | + 'template' => glsr(Template::class), |
|
75 | + ]); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return void |
|
80 | - * @see $this->registerSubMenus() |
|
81 | - * @callback add_submenu_page |
|
82 | - */ |
|
83 | - public function renderDocumentationMenu() |
|
84 | - { |
|
85 | - $tabs = $this->parseWithFilter('documentation/tabs', [ |
|
86 | - 'support' => __('Support', 'site-reviews'), |
|
87 | - 'faq' => __('FAQ', 'site-reviews'), |
|
88 | - 'shortcodes' => __('Shortcodes', 'site-reviews'), |
|
89 | - 'hooks' => __('Hooks', 'site-reviews'), |
|
90 | - 'functions' => __('Functions', 'site-reviews'), |
|
91 | - 'addons' => __('Addons', 'site-reviews'), |
|
92 | - ]); |
|
93 | - $addons = apply_filters('site-reviews/addon/documentation', []); |
|
94 | - ksort($addons); |
|
95 | - if (empty($addons)) { |
|
96 | - unset($tabs['addons']); |
|
97 | - } |
|
98 | - $this->renderPage('documentation', [ |
|
99 | - 'addons' => $addons, |
|
100 | - 'tabs' => $tabs, |
|
101 | - ]); |
|
102 | - } |
|
78 | + /** |
|
79 | + * @return void |
|
80 | + * @see $this->registerSubMenus() |
|
81 | + * @callback add_submenu_page |
|
82 | + */ |
|
83 | + public function renderDocumentationMenu() |
|
84 | + { |
|
85 | + $tabs = $this->parseWithFilter('documentation/tabs', [ |
|
86 | + 'support' => __('Support', 'site-reviews'), |
|
87 | + 'faq' => __('FAQ', 'site-reviews'), |
|
88 | + 'shortcodes' => __('Shortcodes', 'site-reviews'), |
|
89 | + 'hooks' => __('Hooks', 'site-reviews'), |
|
90 | + 'functions' => __('Functions', 'site-reviews'), |
|
91 | + 'addons' => __('Addons', 'site-reviews'), |
|
92 | + ]); |
|
93 | + $addons = apply_filters('site-reviews/addon/documentation', []); |
|
94 | + ksort($addons); |
|
95 | + if (empty($addons)) { |
|
96 | + unset($tabs['addons']); |
|
97 | + } |
|
98 | + $this->renderPage('documentation', [ |
|
99 | + 'addons' => $addons, |
|
100 | + 'tabs' => $tabs, |
|
101 | + ]); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return void |
|
106 | - * @see $this->registerSubMenus() |
|
107 | - * @callback add_submenu_page |
|
108 | - */ |
|
109 | - public function renderSettingsMenu() |
|
110 | - { |
|
111 | - $tabs = $this->parseWithFilter('settings/tabs', [ |
|
112 | - 'general' => __('General', 'site-reviews'), |
|
113 | - 'reviews' => __('Reviews', 'site-reviews'), |
|
114 | - 'submissions' => __('Submissions', 'site-reviews'), |
|
115 | - 'schema' => __('Schema', 'site-reviews'), |
|
116 | - 'translations' => __('Translations', 'site-reviews'), |
|
117 | - 'addons' => __('Addons', 'site-reviews'), |
|
118 | - 'licenses' => __('Licenses', 'site-reviews'), |
|
119 | - ]); |
|
120 | - if (empty(Arr::get(glsr()->defaults, 'settings.addons'))) { |
|
121 | - unset($tabs['addons']); |
|
122 | - } |
|
123 | - if (empty(Arr::get(glsr()->defaults, 'settings.licenses'))) { |
|
124 | - unset($tabs['licenses']); |
|
125 | - } |
|
126 | - $this->renderPage('settings', [ |
|
127 | - 'settings' => glsr(Settings::class), |
|
128 | - 'tabs' => $tabs, |
|
129 | - ]); |
|
130 | - } |
|
104 | + /** |
|
105 | + * @return void |
|
106 | + * @see $this->registerSubMenus() |
|
107 | + * @callback add_submenu_page |
|
108 | + */ |
|
109 | + public function renderSettingsMenu() |
|
110 | + { |
|
111 | + $tabs = $this->parseWithFilter('settings/tabs', [ |
|
112 | + 'general' => __('General', 'site-reviews'), |
|
113 | + 'reviews' => __('Reviews', 'site-reviews'), |
|
114 | + 'submissions' => __('Submissions', 'site-reviews'), |
|
115 | + 'schema' => __('Schema', 'site-reviews'), |
|
116 | + 'translations' => __('Translations', 'site-reviews'), |
|
117 | + 'addons' => __('Addons', 'site-reviews'), |
|
118 | + 'licenses' => __('Licenses', 'site-reviews'), |
|
119 | + ]); |
|
120 | + if (empty(Arr::get(glsr()->defaults, 'settings.addons'))) { |
|
121 | + unset($tabs['addons']); |
|
122 | + } |
|
123 | + if (empty(Arr::get(glsr()->defaults, 'settings.licenses'))) { |
|
124 | + unset($tabs['licenses']); |
|
125 | + } |
|
126 | + $this->renderPage('settings', [ |
|
127 | + 'settings' => glsr(Settings::class), |
|
128 | + 'tabs' => $tabs, |
|
129 | + ]); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @return void |
|
134 | - * @see $this->registerSubMenus() |
|
135 | - * @callback add_submenu_page |
|
136 | - */ |
|
137 | - public function renderToolsMenu() |
|
138 | - { |
|
139 | - $tabs = $this->parseWithFilter('tools/tabs', [ |
|
140 | - 'general' => __('General', 'site-reviews'), |
|
141 | - 'sync' => __('Sync Reviews', 'site-reviews'), |
|
142 | - 'console' => __('Console', 'site-reviews'), |
|
143 | - 'system-info' => __('System Info', 'site-reviews'), |
|
144 | - ]); |
|
145 | - if (!apply_filters('site-reviews/addon/sync/enable', false)) { |
|
146 | - unset($tabs['sync']); |
|
147 | - } |
|
148 | - $this->renderPage('tools', [ |
|
149 | - 'data' => [ |
|
150 | - 'context' => [ |
|
151 | - 'base_url' => admin_url('edit.php?post_type='.Application::POST_TYPE), |
|
152 | - 'console' => strval(glsr(Console::class)), |
|
153 | - 'id' => Application::ID, |
|
154 | - 'system' => strval(glsr(System::class)), |
|
155 | - ], |
|
156 | - 'services' => apply_filters('site-reviews/addon/sync/services', []), |
|
157 | - ], |
|
158 | - 'tabs' => $tabs, |
|
159 | - 'template' => glsr(Template::class), |
|
160 | - ]); |
|
161 | - } |
|
132 | + /** |
|
133 | + * @return void |
|
134 | + * @see $this->registerSubMenus() |
|
135 | + * @callback add_submenu_page |
|
136 | + */ |
|
137 | + public function renderToolsMenu() |
|
138 | + { |
|
139 | + $tabs = $this->parseWithFilter('tools/tabs', [ |
|
140 | + 'general' => __('General', 'site-reviews'), |
|
141 | + 'sync' => __('Sync Reviews', 'site-reviews'), |
|
142 | + 'console' => __('Console', 'site-reviews'), |
|
143 | + 'system-info' => __('System Info', 'site-reviews'), |
|
144 | + ]); |
|
145 | + if (!apply_filters('site-reviews/addon/sync/enable', false)) { |
|
146 | + unset($tabs['sync']); |
|
147 | + } |
|
148 | + $this->renderPage('tools', [ |
|
149 | + 'data' => [ |
|
150 | + 'context' => [ |
|
151 | + 'base_url' => admin_url('edit.php?post_type='.Application::POST_TYPE), |
|
152 | + 'console' => strval(glsr(Console::class)), |
|
153 | + 'id' => Application::ID, |
|
154 | + 'system' => strval(glsr(System::class)), |
|
155 | + ], |
|
156 | + 'services' => apply_filters('site-reviews/addon/sync/services', []), |
|
157 | + ], |
|
158 | + 'tabs' => $tabs, |
|
159 | + 'template' => glsr(Template::class), |
|
160 | + ]); |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * @return void |
|
165 | - * @action admin_init |
|
166 | - */ |
|
167 | - public function setCustomPermissions() |
|
168 | - { |
|
169 | - foreach (wp_roles()->roles as $role => $value) { |
|
170 | - wp_roles()->remove_cap($role, 'create_'.Application::POST_TYPE); |
|
171 | - } |
|
172 | - } |
|
163 | + /** |
|
164 | + * @return void |
|
165 | + * @action admin_init |
|
166 | + */ |
|
167 | + public function setCustomPermissions() |
|
168 | + { |
|
169 | + foreach (wp_roles()->roles as $role => $value) { |
|
170 | + wp_roles()->remove_cap($role, 'create_'.Application::POST_TYPE); |
|
171 | + } |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * @return string |
|
176 | - */ |
|
177 | - protected function getNotices() |
|
178 | - { |
|
179 | - return glsr(Builder::class)->div(glsr(Notice::class)->get(), [ |
|
180 | - 'id' => 'glsr-notices', |
|
181 | - ]); |
|
182 | - } |
|
174 | + /** |
|
175 | + * @return string |
|
176 | + */ |
|
177 | + protected function getNotices() |
|
178 | + { |
|
179 | + return glsr(Builder::class)->div(glsr(Notice::class)->get(), [ |
|
180 | + 'id' => 'glsr-notices', |
|
181 | + ]); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * @param string $hookSuffix |
|
186 | - * @return array |
|
187 | - */ |
|
188 | - protected function parseWithFilter($hookSuffix, array $args = []) |
|
189 | - { |
|
190 | - if (Str::endsWith('/tabs', $hookSuffix)) { |
|
191 | - $page = str_replace('/tabs', '', $hookSuffix); |
|
192 | - foreach ($args as $tab => $title) { |
|
193 | - if (!glsr()->hasPermission($page, $tab)) { |
|
194 | - unset($args[$tab]); |
|
195 | - } |
|
196 | - } |
|
197 | - } |
|
198 | - return apply_filters('site-reviews/addon/'.$hookSuffix, $args); |
|
199 | - } |
|
184 | + /** |
|
185 | + * @param string $hookSuffix |
|
186 | + * @return array |
|
187 | + */ |
|
188 | + protected function parseWithFilter($hookSuffix, array $args = []) |
|
189 | + { |
|
190 | + if (Str::endsWith('/tabs', $hookSuffix)) { |
|
191 | + $page = str_replace('/tabs', '', $hookSuffix); |
|
192 | + foreach ($args as $tab => $title) { |
|
193 | + if (!glsr()->hasPermission($page, $tab)) { |
|
194 | + unset($args[$tab]); |
|
195 | + } |
|
196 | + } |
|
197 | + } |
|
198 | + return apply_filters('site-reviews/addon/'.$hookSuffix, $args); |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * @param string $page |
|
203 | - * @return void |
|
204 | - */ |
|
205 | - protected function renderPage($page, array $data = []) |
|
206 | - { |
|
207 | - $data['http_referer'] = (string) wp_get_referer(); |
|
208 | - $data['notices'] = $this->getNotices(); |
|
209 | - glsr()->render('pages/'.$page.'/index', $data); |
|
210 | - } |
|
201 | + /** |
|
202 | + * @param string $page |
|
203 | + * @return void |
|
204 | + */ |
|
205 | + protected function renderPage($page, array $data = []) |
|
206 | + { |
|
207 | + $data['http_referer'] = (string) wp_get_referer(); |
|
208 | + $data['notices'] = $this->getNotices(); |
|
209 | + glsr()->render('pages/'.$page.'/index', $data); |
|
210 | + } |
|
211 | 211 | } |
@@ -22,20 +22,20 @@ discard block |
||
22 | 22 | public function registerMenuCount() |
23 | 23 | { |
24 | 24 | global $menu, $typenow; |
25 | - foreach ($menu as $key => $value) { |
|
26 | - if (!isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE) { |
|
25 | + foreach( $menu as $key => $value ) { |
|
26 | + if( !isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE ) { |
|
27 | 27 | continue; |
28 | 28 | } |
29 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
30 | - $pendingCount = glsr(Builder::class)->span(number_format_i18n($postCount->pending), [ |
|
29 | + $postCount = wp_count_posts( Application::POST_TYPE ); |
|
30 | + $pendingCount = glsr( Builder::class )->span( number_format_i18n( $postCount->pending ), [ |
|
31 | 31 | 'class' => 'unapproved-count', |
32 | - ]); |
|
33 | - $awaitingModeration = glsr(Builder::class)->span($pendingCount, [ |
|
32 | + ] ); |
|
33 | + $awaitingModeration = glsr( Builder::class )->span( $pendingCount, [ |
|
34 | 34 | 'class' => 'awaiting-mod count-'.$postCount->pending, |
35 | - ]); |
|
36 | - $menu[$key][0].= ' '.$awaitingModeration; |
|
37 | - if (Application::POST_TYPE === $typenow) { |
|
38 | - $menu[$key][4].= ' current'; |
|
35 | + ] ); |
|
36 | + $menu[$key][0] .= ' '.$awaitingModeration; |
|
37 | + if( Application::POST_TYPE === $typenow ) { |
|
38 | + $menu[$key][4] .= ' current'; |
|
39 | 39 | } |
40 | 40 | break; |
41 | 41 | } |
@@ -47,19 +47,19 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function registerSubMenus() |
49 | 49 | { |
50 | - $pages = $this->parseWithFilter('submenu/pages', [ |
|
51 | - 'settings' => __('Settings', 'site-reviews'), |
|
52 | - 'tools' => __('Tools', 'site-reviews'), |
|
53 | - 'addons' => __('Add-ons', 'site-reviews'), |
|
54 | - 'documentation' => __('Help', 'site-reviews'), |
|
55 | - ]); |
|
56 | - foreach ($pages as $slug => $title) { |
|
57 | - $method = Helper::buildMethodName('render-'.$slug.'-menu'); |
|
58 | - $callback = apply_filters('site-reviews/addon/submenu/callback', [$this, $method], $slug); |
|
59 | - if (!is_callable($callback)) { |
|
50 | + $pages = $this->parseWithFilter( 'submenu/pages', [ |
|
51 | + 'settings' => __( 'Settings', 'site-reviews' ), |
|
52 | + 'tools' => __( 'Tools', 'site-reviews' ), |
|
53 | + 'addons' => __( 'Add-ons', 'site-reviews' ), |
|
54 | + 'documentation' => __( 'Help', 'site-reviews' ), |
|
55 | + ] ); |
|
56 | + foreach( $pages as $slug => $title ) { |
|
57 | + $method = Helper::buildMethodName( 'render-'.$slug.'-menu' ); |
|
58 | + $callback = apply_filters( 'site-reviews/addon/submenu/callback', [$this, $method], $slug ); |
|
59 | + if( !is_callable( $callback ) ) { |
|
60 | 60 | continue; |
61 | 61 | } |
62 | - add_submenu_page('edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission($slug), $slug, $callback); |
|
62 | + add_submenu_page( 'edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission( $slug ), $slug, $callback ); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function renderAddonsMenu() |
72 | 72 | { |
73 | - $this->renderPage('addons', [ |
|
74 | - 'template' => glsr(Template::class), |
|
75 | - ]); |
|
73 | + $this->renderPage( 'addons', [ |
|
74 | + 'template' => glsr( Template::class ), |
|
75 | + ] ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -82,23 +82,23 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function renderDocumentationMenu() |
84 | 84 | { |
85 | - $tabs = $this->parseWithFilter('documentation/tabs', [ |
|
86 | - 'support' => __('Support', 'site-reviews'), |
|
87 | - 'faq' => __('FAQ', 'site-reviews'), |
|
88 | - 'shortcodes' => __('Shortcodes', 'site-reviews'), |
|
89 | - 'hooks' => __('Hooks', 'site-reviews'), |
|
90 | - 'functions' => __('Functions', 'site-reviews'), |
|
91 | - 'addons' => __('Addons', 'site-reviews'), |
|
92 | - ]); |
|
93 | - $addons = apply_filters('site-reviews/addon/documentation', []); |
|
94 | - ksort($addons); |
|
95 | - if (empty($addons)) { |
|
85 | + $tabs = $this->parseWithFilter( 'documentation/tabs', [ |
|
86 | + 'support' => __( 'Support', 'site-reviews' ), |
|
87 | + 'faq' => __( 'FAQ', 'site-reviews' ), |
|
88 | + 'shortcodes' => __( 'Shortcodes', 'site-reviews' ), |
|
89 | + 'hooks' => __( 'Hooks', 'site-reviews' ), |
|
90 | + 'functions' => __( 'Functions', 'site-reviews' ), |
|
91 | + 'addons' => __( 'Addons', 'site-reviews' ), |
|
92 | + ] ); |
|
93 | + $addons = apply_filters( 'site-reviews/addon/documentation', [] ); |
|
94 | + ksort( $addons ); |
|
95 | + if( empty($addons) ) { |
|
96 | 96 | unset($tabs['addons']); |
97 | 97 | } |
98 | - $this->renderPage('documentation', [ |
|
98 | + $this->renderPage( 'documentation', [ |
|
99 | 99 | 'addons' => $addons, |
100 | 100 | 'tabs' => $tabs, |
101 | - ]); |
|
101 | + ] ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -108,25 +108,25 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function renderSettingsMenu() |
110 | 110 | { |
111 | - $tabs = $this->parseWithFilter('settings/tabs', [ |
|
112 | - 'general' => __('General', 'site-reviews'), |
|
113 | - 'reviews' => __('Reviews', 'site-reviews'), |
|
114 | - 'submissions' => __('Submissions', 'site-reviews'), |
|
115 | - 'schema' => __('Schema', 'site-reviews'), |
|
116 | - 'translations' => __('Translations', 'site-reviews'), |
|
117 | - 'addons' => __('Addons', 'site-reviews'), |
|
118 | - 'licenses' => __('Licenses', 'site-reviews'), |
|
119 | - ]); |
|
120 | - if (empty(Arr::get(glsr()->defaults, 'settings.addons'))) { |
|
111 | + $tabs = $this->parseWithFilter( 'settings/tabs', [ |
|
112 | + 'general' => __( 'General', 'site-reviews' ), |
|
113 | + 'reviews' => __( 'Reviews', 'site-reviews' ), |
|
114 | + 'submissions' => __( 'Submissions', 'site-reviews' ), |
|
115 | + 'schema' => __( 'Schema', 'site-reviews' ), |
|
116 | + 'translations' => __( 'Translations', 'site-reviews' ), |
|
117 | + 'addons' => __( 'Addons', 'site-reviews' ), |
|
118 | + 'licenses' => __( 'Licenses', 'site-reviews' ), |
|
119 | + ] ); |
|
120 | + if( empty(Arr::get( glsr()->defaults, 'settings.addons' )) ) { |
|
121 | 121 | unset($tabs['addons']); |
122 | 122 | } |
123 | - if (empty(Arr::get(glsr()->defaults, 'settings.licenses'))) { |
|
123 | + if( empty(Arr::get( glsr()->defaults, 'settings.licenses' )) ) { |
|
124 | 124 | unset($tabs['licenses']); |
125 | 125 | } |
126 | - $this->renderPage('settings', [ |
|
127 | - 'settings' => glsr(Settings::class), |
|
126 | + $this->renderPage( 'settings', [ |
|
127 | + 'settings' => glsr( Settings::class ), |
|
128 | 128 | 'tabs' => $tabs, |
129 | - ]); |
|
129 | + ] ); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -136,28 +136,28 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function renderToolsMenu() |
138 | 138 | { |
139 | - $tabs = $this->parseWithFilter('tools/tabs', [ |
|
140 | - 'general' => __('General', 'site-reviews'), |
|
141 | - 'sync' => __('Sync Reviews', 'site-reviews'), |
|
142 | - 'console' => __('Console', 'site-reviews'), |
|
143 | - 'system-info' => __('System Info', 'site-reviews'), |
|
144 | - ]); |
|
145 | - if (!apply_filters('site-reviews/addon/sync/enable', false)) { |
|
139 | + $tabs = $this->parseWithFilter( 'tools/tabs', [ |
|
140 | + 'general' => __( 'General', 'site-reviews' ), |
|
141 | + 'sync' => __( 'Sync Reviews', 'site-reviews' ), |
|
142 | + 'console' => __( 'Console', 'site-reviews' ), |
|
143 | + 'system-info' => __( 'System Info', 'site-reviews' ), |
|
144 | + ] ); |
|
145 | + if( !apply_filters( 'site-reviews/addon/sync/enable', false ) ) { |
|
146 | 146 | unset($tabs['sync']); |
147 | 147 | } |
148 | - $this->renderPage('tools', [ |
|
148 | + $this->renderPage( 'tools', [ |
|
149 | 149 | 'data' => [ |
150 | 150 | 'context' => [ |
151 | - 'base_url' => admin_url('edit.php?post_type='.Application::POST_TYPE), |
|
152 | - 'console' => strval(glsr(Console::class)), |
|
151 | + 'base_url' => admin_url( 'edit.php?post_type='.Application::POST_TYPE ), |
|
152 | + 'console' => strval( glsr( Console::class ) ), |
|
153 | 153 | 'id' => Application::ID, |
154 | - 'system' => strval(glsr(System::class)), |
|
154 | + 'system' => strval( glsr( System::class ) ), |
|
155 | 155 | ], |
156 | - 'services' => apply_filters('site-reviews/addon/sync/services', []), |
|
156 | + 'services' => apply_filters( 'site-reviews/addon/sync/services', [] ), |
|
157 | 157 | ], |
158 | 158 | 'tabs' => $tabs, |
159 | - 'template' => glsr(Template::class), |
|
160 | - ]); |
|
159 | + 'template' => glsr( Template::class ), |
|
160 | + ] ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function setCustomPermissions() |
168 | 168 | { |
169 | - foreach (wp_roles()->roles as $role => $value) { |
|
170 | - wp_roles()->remove_cap($role, 'create_'.Application::POST_TYPE); |
|
169 | + foreach( wp_roles()->roles as $role => $value ) { |
|
170 | + wp_roles()->remove_cap( $role, 'create_'.Application::POST_TYPE ); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
@@ -176,36 +176,36 @@ discard block |
||
176 | 176 | */ |
177 | 177 | protected function getNotices() |
178 | 178 | { |
179 | - return glsr(Builder::class)->div(glsr(Notice::class)->get(), [ |
|
179 | + return glsr( Builder::class )->div( glsr( Notice::class )->get(), [ |
|
180 | 180 | 'id' => 'glsr-notices', |
181 | - ]); |
|
181 | + ] ); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | 185 | * @param string $hookSuffix |
186 | 186 | * @return array |
187 | 187 | */ |
188 | - protected function parseWithFilter($hookSuffix, array $args = []) |
|
188 | + protected function parseWithFilter( $hookSuffix, array $args = [] ) |
|
189 | 189 | { |
190 | - if (Str::endsWith('/tabs', $hookSuffix)) { |
|
191 | - $page = str_replace('/tabs', '', $hookSuffix); |
|
192 | - foreach ($args as $tab => $title) { |
|
193 | - if (!glsr()->hasPermission($page, $tab)) { |
|
190 | + if( Str::endsWith( '/tabs', $hookSuffix ) ) { |
|
191 | + $page = str_replace( '/tabs', '', $hookSuffix ); |
|
192 | + foreach( $args as $tab => $title ) { |
|
193 | + if( !glsr()->hasPermission( $page, $tab ) ) { |
|
194 | 194 | unset($args[$tab]); |
195 | 195 | } |
196 | 196 | } |
197 | 197 | } |
198 | - return apply_filters('site-reviews/addon/'.$hookSuffix, $args); |
|
198 | + return apply_filters( 'site-reviews/addon/'.$hookSuffix, $args ); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
202 | 202 | * @param string $page |
203 | 203 | * @return void |
204 | 204 | */ |
205 | - protected function renderPage($page, array $data = []) |
|
205 | + protected function renderPage( $page, array $data = [] ) |
|
206 | 206 | { |
207 | - $data['http_referer'] = (string) wp_get_referer(); |
|
207 | + $data['http_referer'] = (string)wp_get_referer(); |
|
208 | 208 | $data['notices'] = $this->getNotices(); |
209 | - glsr()->render('pages/'.$page.'/index', $data); |
|
209 | + glsr()->render( 'pages/'.$page.'/index', $data ); |
|
210 | 210 | } |
211 | 211 | } |
@@ -10,180 +10,180 @@ |
||
10 | 10 | |
11 | 11 | class Columns |
12 | 12 | { |
13 | - /** |
|
14 | - * @param int $postId |
|
15 | - * @return void|string |
|
16 | - */ |
|
17 | - public function buildColumnAssignedTo($postId) |
|
18 | - { |
|
19 | - $assignedPost = glsr(Database::class)->getAssignedToPost($postId); |
|
20 | - if ($assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status) { |
|
21 | - return glsr(Builder::class)->a(get_the_title($assignedPost->ID), [ |
|
22 | - 'href' => (string) get_the_permalink($assignedPost->ID), |
|
23 | - ]); |
|
24 | - } |
|
25 | - } |
|
13 | + /** |
|
14 | + * @param int $postId |
|
15 | + * @return void|string |
|
16 | + */ |
|
17 | + public function buildColumnAssignedTo($postId) |
|
18 | + { |
|
19 | + $assignedPost = glsr(Database::class)->getAssignedToPost($postId); |
|
20 | + if ($assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status) { |
|
21 | + return glsr(Builder::class)->a(get_the_title($assignedPost->ID), [ |
|
22 | + 'href' => (string) get_the_permalink($assignedPost->ID), |
|
23 | + ]); |
|
24 | + } |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param int $postId |
|
29 | - * @return void|string |
|
30 | - */ |
|
31 | - public function buildColumnEmail($postId) |
|
32 | - { |
|
33 | - if ($email = glsr(Database::class)->get($postId, 'email')) { |
|
34 | - return $email; |
|
35 | - } |
|
36 | - } |
|
27 | + /** |
|
28 | + * @param int $postId |
|
29 | + * @return void|string |
|
30 | + */ |
|
31 | + public function buildColumnEmail($postId) |
|
32 | + { |
|
33 | + if ($email = glsr(Database::class)->get($postId, 'email')) { |
|
34 | + return $email; |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param int $postId |
|
40 | - * @return void|string |
|
41 | - */ |
|
42 | - public function buildColumnIpAddress($postId) |
|
43 | - { |
|
44 | - if ($ipAddress = glsr(Database::class)->get($postId, 'ip_address')) { |
|
45 | - return $ipAddress; |
|
46 | - } |
|
47 | - } |
|
38 | + /** |
|
39 | + * @param int $postId |
|
40 | + * @return void|string |
|
41 | + */ |
|
42 | + public function buildColumnIpAddress($postId) |
|
43 | + { |
|
44 | + if ($ipAddress = glsr(Database::class)->get($postId, 'ip_address')) { |
|
45 | + return $ipAddress; |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param int $postId |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function buildColumnPinned($postId) |
|
54 | - { |
|
55 | - $pinned = glsr(Database::class)->get($postId, 'pinned') |
|
56 | - ? 'pinned ' |
|
57 | - : ''; |
|
58 | - if (glsr()->can('edit_others_posts')) { |
|
59 | - $pinned.= 'pin-review '; |
|
60 | - } |
|
61 | - return glsr(Builder::class)->i([ |
|
62 | - 'class' => $pinned.'dashicons dashicons-sticky', |
|
63 | - 'data-id' => $postId, |
|
64 | - ]); |
|
65 | - } |
|
49 | + /** |
|
50 | + * @param int $postId |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function buildColumnPinned($postId) |
|
54 | + { |
|
55 | + $pinned = glsr(Database::class)->get($postId, 'pinned') |
|
56 | + ? 'pinned ' |
|
57 | + : ''; |
|
58 | + if (glsr()->can('edit_others_posts')) { |
|
59 | + $pinned.= 'pin-review '; |
|
60 | + } |
|
61 | + return glsr(Builder::class)->i([ |
|
62 | + 'class' => $pinned.'dashicons dashicons-sticky', |
|
63 | + 'data-id' => $postId, |
|
64 | + ]); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param int $postId |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function buildColumnResponse($postId) |
|
72 | - { |
|
73 | - return glsr(Database::class)->get($postId, 'response') |
|
74 | - ? __('Yes', 'site-reviews') |
|
75 | - : __('No', 'site-reviews'); |
|
76 | - } |
|
67 | + /** |
|
68 | + * @param int $postId |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function buildColumnResponse($postId) |
|
72 | + { |
|
73 | + return glsr(Database::class)->get($postId, 'response') |
|
74 | + ? __('Yes', 'site-reviews') |
|
75 | + : __('No', 'site-reviews'); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param int $postId |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function buildColumnReviewer($postId) |
|
83 | - { |
|
84 | - return strval(glsr(Database::class)->get($postId, 'author')); |
|
85 | - } |
|
78 | + /** |
|
79 | + * @param int $postId |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function buildColumnReviewer($postId) |
|
83 | + { |
|
84 | + return strval(glsr(Database::class)->get($postId, 'author')); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @param int $postId |
|
89 | - * @param int|null $rating |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function buildColumnRating($postId) |
|
93 | - { |
|
94 | - return glsr_star_rating(intval(glsr(Database::class)->get($postId, 'rating'))); |
|
95 | - } |
|
87 | + /** |
|
88 | + * @param int $postId |
|
89 | + * @param int|null $rating |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function buildColumnRating($postId) |
|
93 | + { |
|
94 | + return glsr_star_rating(intval(glsr(Database::class)->get($postId, 'rating'))); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @param int $postId |
|
99 | - * @return string |
|
100 | - */ |
|
101 | - public function buildColumnReviewType($postId) |
|
102 | - { |
|
103 | - $type = glsr(Database::class)->get($postId, 'review_type'); |
|
104 | - return array_key_exists($type, glsr()->reviewTypes) |
|
105 | - ? glsr()->reviewTypes[$type] |
|
106 | - : __('Unsupported Type', 'site-reviews'); |
|
107 | - } |
|
97 | + /** |
|
98 | + * @param int $postId |
|
99 | + * @return string |
|
100 | + */ |
|
101 | + public function buildColumnReviewType($postId) |
|
102 | + { |
|
103 | + $type = glsr(Database::class)->get($postId, 'review_type'); |
|
104 | + return array_key_exists($type, glsr()->reviewTypes) |
|
105 | + ? glsr()->reviewTypes[$type] |
|
106 | + : __('Unsupported Type', 'site-reviews'); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @param string $postType |
|
111 | - * @return void |
|
112 | - */ |
|
113 | - public function renderFilters($postType) |
|
114 | - { |
|
115 | - if (Application::POST_TYPE !== $postType) { |
|
116 | - return; |
|
117 | - } |
|
118 | - if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
119 | - $status = 'publish'; |
|
120 | - } |
|
121 | - $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
122 | - $types = glsr(Database::class)->getReviewsMeta('review_type', $status); |
|
123 | - $this->renderFilterRatings($ratings); |
|
124 | - $this->renderFilterTypes($types); |
|
125 | - } |
|
109 | + /** |
|
110 | + * @param string $postType |
|
111 | + * @return void |
|
112 | + */ |
|
113 | + public function renderFilters($postType) |
|
114 | + { |
|
115 | + if (Application::POST_TYPE !== $postType) { |
|
116 | + return; |
|
117 | + } |
|
118 | + if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
119 | + $status = 'publish'; |
|
120 | + } |
|
121 | + $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
122 | + $types = glsr(Database::class)->getReviewsMeta('review_type', $status); |
|
123 | + $this->renderFilterRatings($ratings); |
|
124 | + $this->renderFilterTypes($types); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @param string $column |
|
129 | - * @param int $postId |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - public function renderValues($column, $postId) |
|
133 | - { |
|
134 | - $method = Helper::buildMethodName($column, 'buildColumn'); |
|
135 | - $value = method_exists($this, $method) |
|
136 | - ? call_user_func([$this, $method], $postId) |
|
137 | - : ''; |
|
138 | - $value = apply_filters('site-reviews/columns/'.$column, $value, $postId); |
|
139 | - if (0 !== $value && empty($value)) { |
|
140 | - $value = '—'; |
|
141 | - } |
|
142 | - echo $value; |
|
143 | - } |
|
127 | + /** |
|
128 | + * @param string $column |
|
129 | + * @param int $postId |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + public function renderValues($column, $postId) |
|
133 | + { |
|
134 | + $method = Helper::buildMethodName($column, 'buildColumn'); |
|
135 | + $value = method_exists($this, $method) |
|
136 | + ? call_user_func([$this, $method], $postId) |
|
137 | + : ''; |
|
138 | + $value = apply_filters('site-reviews/columns/'.$column, $value, $postId); |
|
139 | + if (0 !== $value && empty($value)) { |
|
140 | + $value = '—'; |
|
141 | + } |
|
142 | + echo $value; |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @param array $ratings |
|
147 | - * @return void |
|
148 | - */ |
|
149 | - protected function renderFilterRatings($ratings) |
|
150 | - { |
|
151 | - if (empty($ratings)) { |
|
152 | - return; |
|
153 | - } |
|
154 | - $ratings = array_flip(array_reverse($ratings)); |
|
155 | - array_walk($ratings, function (&$value, $key) { |
|
156 | - $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
157 | - $value = sprintf($label, $key); |
|
158 | - }); |
|
159 | - echo glsr(Builder::class)->label(__('Filter by rating', 'site-reviews'), [ |
|
160 | - 'class' => 'screen-reader-text', |
|
161 | - 'for' => 'rating', |
|
162 | - ]); |
|
163 | - echo glsr(Builder::class)->select([ |
|
164 | - 'name' => 'rating', |
|
165 | - 'options' => ['' => __('All ratings', 'site-reviews')] + $ratings, |
|
166 | - 'value' => filter_input(INPUT_GET, 'rating'), |
|
167 | - ]); |
|
168 | - } |
|
145 | + /** |
|
146 | + * @param array $ratings |
|
147 | + * @return void |
|
148 | + */ |
|
149 | + protected function renderFilterRatings($ratings) |
|
150 | + { |
|
151 | + if (empty($ratings)) { |
|
152 | + return; |
|
153 | + } |
|
154 | + $ratings = array_flip(array_reverse($ratings)); |
|
155 | + array_walk($ratings, function (&$value, $key) { |
|
156 | + $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
157 | + $value = sprintf($label, $key); |
|
158 | + }); |
|
159 | + echo glsr(Builder::class)->label(__('Filter by rating', 'site-reviews'), [ |
|
160 | + 'class' => 'screen-reader-text', |
|
161 | + 'for' => 'rating', |
|
162 | + ]); |
|
163 | + echo glsr(Builder::class)->select([ |
|
164 | + 'name' => 'rating', |
|
165 | + 'options' => ['' => __('All ratings', 'site-reviews')] + $ratings, |
|
166 | + 'value' => filter_input(INPUT_GET, 'rating'), |
|
167 | + ]); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * @param array $types |
|
172 | - * @return void |
|
173 | - */ |
|
174 | - protected function renderFilterTypes($types) |
|
175 | - { |
|
176 | - if (count(glsr()->reviewTypes) < 2) { |
|
177 | - return; |
|
178 | - } |
|
179 | - echo glsr(Builder::class)->label(__('Filter by type', 'site-reviews'), [ |
|
180 | - 'class' => 'screen-reader-text', |
|
181 | - 'for' => 'review_type', |
|
182 | - ]); |
|
183 | - echo glsr(Builder::class)->select([ |
|
184 | - 'name' => 'review_type', |
|
185 | - 'options' => ['' => __('All types', 'site-reviews')] + glsr()->reviewTypes, |
|
186 | - 'value' => filter_input(INPUT_GET, 'review_type'), |
|
187 | - ]); |
|
188 | - } |
|
170 | + /** |
|
171 | + * @param array $types |
|
172 | + * @return void |
|
173 | + */ |
|
174 | + protected function renderFilterTypes($types) |
|
175 | + { |
|
176 | + if (count(glsr()->reviewTypes) < 2) { |
|
177 | + return; |
|
178 | + } |
|
179 | + echo glsr(Builder::class)->label(__('Filter by type', 'site-reviews'), [ |
|
180 | + 'class' => 'screen-reader-text', |
|
181 | + 'for' => 'review_type', |
|
182 | + ]); |
|
183 | + echo glsr(Builder::class)->select([ |
|
184 | + 'name' => 'review_type', |
|
185 | + 'options' => ['' => __('All types', 'site-reviews')] + glsr()->reviewTypes, |
|
186 | + 'value' => filter_input(INPUT_GET, 'review_type'), |
|
187 | + ]); |
|
188 | + } |
|
189 | 189 | } |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | * @param int $postId |
15 | 15 | * @return void|string |
16 | 16 | */ |
17 | - public function buildColumnAssignedTo($postId) |
|
17 | + public function buildColumnAssignedTo( $postId ) |
|
18 | 18 | { |
19 | - $assignedPost = glsr(Database::class)->getAssignedToPost($postId); |
|
20 | - if ($assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status) { |
|
21 | - return glsr(Builder::class)->a(get_the_title($assignedPost->ID), [ |
|
22 | - 'href' => (string) get_the_permalink($assignedPost->ID), |
|
23 | - ]); |
|
19 | + $assignedPost = glsr( Database::class )->getAssignedToPost( $postId ); |
|
20 | + if( $assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status ) { |
|
21 | + return glsr( Builder::class )->a( get_the_title( $assignedPost->ID ), [ |
|
22 | + 'href' => (string)get_the_permalink( $assignedPost->ID ), |
|
23 | + ] ); |
|
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | * @param int $postId |
29 | 29 | * @return void|string |
30 | 30 | */ |
31 | - public function buildColumnEmail($postId) |
|
31 | + public function buildColumnEmail( $postId ) |
|
32 | 32 | { |
33 | - if ($email = glsr(Database::class)->get($postId, 'email')) { |
|
33 | + if( $email = glsr( Database::class )->get( $postId, 'email' ) ) { |
|
34 | 34 | return $email; |
35 | 35 | } |
36 | 36 | } |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | * @param int $postId |
40 | 40 | * @return void|string |
41 | 41 | */ |
42 | - public function buildColumnIpAddress($postId) |
|
42 | + public function buildColumnIpAddress( $postId ) |
|
43 | 43 | { |
44 | - if ($ipAddress = glsr(Database::class)->get($postId, 'ip_address')) { |
|
44 | + if( $ipAddress = glsr( Database::class )->get( $postId, 'ip_address' ) ) { |
|
45 | 45 | return $ipAddress; |
46 | 46 | } |
47 | 47 | } |
@@ -50,38 +50,38 @@ discard block |
||
50 | 50 | * @param int $postId |
51 | 51 | * @return string |
52 | 52 | */ |
53 | - public function buildColumnPinned($postId) |
|
53 | + public function buildColumnPinned( $postId ) |
|
54 | 54 | { |
55 | - $pinned = glsr(Database::class)->get($postId, 'pinned') |
|
55 | + $pinned = glsr( Database::class )->get( $postId, 'pinned' ) |
|
56 | 56 | ? 'pinned ' |
57 | 57 | : ''; |
58 | - if (glsr()->can('edit_others_posts')) { |
|
59 | - $pinned.= 'pin-review '; |
|
58 | + if( glsr()->can( 'edit_others_posts' ) ) { |
|
59 | + $pinned .= 'pin-review '; |
|
60 | 60 | } |
61 | - return glsr(Builder::class)->i([ |
|
61 | + return glsr( Builder::class )->i( [ |
|
62 | 62 | 'class' => $pinned.'dashicons dashicons-sticky', |
63 | 63 | 'data-id' => $postId, |
64 | - ]); |
|
64 | + ] ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * @param int $postId |
69 | 69 | * @return string |
70 | 70 | */ |
71 | - public function buildColumnResponse($postId) |
|
71 | + public function buildColumnResponse( $postId ) |
|
72 | 72 | { |
73 | - return glsr(Database::class)->get($postId, 'response') |
|
74 | - ? __('Yes', 'site-reviews') |
|
75 | - : __('No', 'site-reviews'); |
|
73 | + return glsr( Database::class )->get( $postId, 'response' ) |
|
74 | + ? __( 'Yes', 'site-reviews' ) |
|
75 | + : __( 'No', 'site-reviews' ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @param int $postId |
80 | 80 | * @return string |
81 | 81 | */ |
82 | - public function buildColumnReviewer($postId) |
|
82 | + public function buildColumnReviewer( $postId ) |
|
83 | 83 | { |
84 | - return strval(glsr(Database::class)->get($postId, 'author')); |
|
84 | + return strval( glsr( Database::class )->get( $postId, 'author' ) ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -89,39 +89,39 @@ discard block |
||
89 | 89 | * @param int|null $rating |
90 | 90 | * @return string |
91 | 91 | */ |
92 | - public function buildColumnRating($postId) |
|
92 | + public function buildColumnRating( $postId ) |
|
93 | 93 | { |
94 | - return glsr_star_rating(intval(glsr(Database::class)->get($postId, 'rating'))); |
|
94 | + return glsr_star_rating( intval( glsr( Database::class )->get( $postId, 'rating' ) ) ); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
98 | 98 | * @param int $postId |
99 | 99 | * @return string |
100 | 100 | */ |
101 | - public function buildColumnReviewType($postId) |
|
101 | + public function buildColumnReviewType( $postId ) |
|
102 | 102 | { |
103 | - $type = glsr(Database::class)->get($postId, 'review_type'); |
|
104 | - return array_key_exists($type, glsr()->reviewTypes) |
|
103 | + $type = glsr( Database::class )->get( $postId, 'review_type' ); |
|
104 | + return array_key_exists( $type, glsr()->reviewTypes ) |
|
105 | 105 | ? glsr()->reviewTypes[$type] |
106 | - : __('Unsupported Type', 'site-reviews'); |
|
106 | + : __( 'Unsupported Type', 'site-reviews' ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * @param string $postType |
111 | 111 | * @return void |
112 | 112 | */ |
113 | - public function renderFilters($postType) |
|
113 | + public function renderFilters( $postType ) |
|
114 | 114 | { |
115 | - if (Application::POST_TYPE !== $postType) { |
|
115 | + if( Application::POST_TYPE !== $postType ) { |
|
116 | 116 | return; |
117 | 117 | } |
118 | - if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
118 | + if( !($status = filter_input( INPUT_GET, 'post_status' )) ) { |
|
119 | 119 | $status = 'publish'; |
120 | 120 | } |
121 | - $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
122 | - $types = glsr(Database::class)->getReviewsMeta('review_type', $status); |
|
123 | - $this->renderFilterRatings($ratings); |
|
124 | - $this->renderFilterTypes($types); |
|
121 | + $ratings = glsr( Database::class )->getReviewsMeta( 'rating', $status ); |
|
122 | + $types = glsr( Database::class )->getReviewsMeta( 'review_type', $status ); |
|
123 | + $this->renderFilterRatings( $ratings ); |
|
124 | + $this->renderFilterTypes( $types ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | * @param int $postId |
130 | 130 | * @return void |
131 | 131 | */ |
132 | - public function renderValues($column, $postId) |
|
132 | + public function renderValues( $column, $postId ) |
|
133 | 133 | { |
134 | - $method = Helper::buildMethodName($column, 'buildColumn'); |
|
135 | - $value = method_exists($this, $method) |
|
136 | - ? call_user_func([$this, $method], $postId) |
|
134 | + $method = Helper::buildMethodName( $column, 'buildColumn' ); |
|
135 | + $value = method_exists( $this, $method ) |
|
136 | + ? call_user_func( [$this, $method], $postId ) |
|
137 | 137 | : ''; |
138 | - $value = apply_filters('site-reviews/columns/'.$column, $value, $postId); |
|
139 | - if (0 !== $value && empty($value)) { |
|
138 | + $value = apply_filters( 'site-reviews/columns/'.$column, $value, $postId ); |
|
139 | + if( 0 !== $value && empty($value) ) { |
|
140 | 140 | $value = '—'; |
141 | 141 | } |
142 | 142 | echo $value; |
@@ -146,44 +146,44 @@ discard block |
||
146 | 146 | * @param array $ratings |
147 | 147 | * @return void |
148 | 148 | */ |
149 | - protected function renderFilterRatings($ratings) |
|
149 | + protected function renderFilterRatings( $ratings ) |
|
150 | 150 | { |
151 | - if (empty($ratings)) { |
|
151 | + if( empty($ratings) ) { |
|
152 | 152 | return; |
153 | 153 | } |
154 | - $ratings = array_flip(array_reverse($ratings)); |
|
155 | - array_walk($ratings, function (&$value, $key) { |
|
156 | - $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
157 | - $value = sprintf($label, $key); |
|
154 | + $ratings = array_flip( array_reverse( $ratings ) ); |
|
155 | + array_walk( $ratings, function( &$value, $key ) { |
|
156 | + $label = _n( '%s star', '%s stars', $key, 'site-reviews' ); |
|
157 | + $value = sprintf( $label, $key ); |
|
158 | 158 | }); |
159 | - echo glsr(Builder::class)->label(__('Filter by rating', 'site-reviews'), [ |
|
159 | + echo glsr( Builder::class )->label( __( 'Filter by rating', 'site-reviews' ), [ |
|
160 | 160 | 'class' => 'screen-reader-text', |
161 | 161 | 'for' => 'rating', |
162 | - ]); |
|
163 | - echo glsr(Builder::class)->select([ |
|
162 | + ] ); |
|
163 | + echo glsr( Builder::class )->select( [ |
|
164 | 164 | 'name' => 'rating', |
165 | - 'options' => ['' => __('All ratings', 'site-reviews')] + $ratings, |
|
166 | - 'value' => filter_input(INPUT_GET, 'rating'), |
|
167 | - ]); |
|
165 | + 'options' => ['' => __( 'All ratings', 'site-reviews' )] + $ratings, |
|
166 | + 'value' => filter_input( INPUT_GET, 'rating' ), |
|
167 | + ] ); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
171 | 171 | * @param array $types |
172 | 172 | * @return void |
173 | 173 | */ |
174 | - protected function renderFilterTypes($types) |
|
174 | + protected function renderFilterTypes( $types ) |
|
175 | 175 | { |
176 | - if (count(glsr()->reviewTypes) < 2) { |
|
176 | + if( count( glsr()->reviewTypes ) < 2 ) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | - echo glsr(Builder::class)->label(__('Filter by type', 'site-reviews'), [ |
|
179 | + echo glsr( Builder::class )->label( __( 'Filter by type', 'site-reviews' ), [ |
|
180 | 180 | 'class' => 'screen-reader-text', |
181 | 181 | 'for' => 'review_type', |
182 | - ]); |
|
183 | - echo glsr(Builder::class)->select([ |
|
182 | + ] ); |
|
183 | + echo glsr( Builder::class )->select( [ |
|
184 | 184 | 'name' => 'review_type', |
185 | - 'options' => ['' => __('All types', 'site-reviews')] + glsr()->reviewTypes, |
|
186 | - 'value' => filter_input(INPUT_GET, 'review_type'), |
|
187 | - ]); |
|
185 | + 'options' => ['' => __( 'All types', 'site-reviews' )] + glsr()->reviewTypes, |
|
186 | + 'value' => filter_input( INPUT_GET, 'review_type' ), |
|
187 | + ] ); |
|
188 | 188 | } |
189 | 189 | } |
@@ -15,192 +15,192 @@ |
||
15 | 15 | |
16 | 16 | class AjaxController extends Controller |
17 | 17 | { |
18 | - /** |
|
19 | - * @return void |
|
20 | - */ |
|
21 | - public function routerChangeStatus(array $request) |
|
22 | - { |
|
23 | - wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
24 | - } |
|
18 | + /** |
|
19 | + * @return void |
|
20 | + */ |
|
21 | + public function routerChangeStatus(array $request) |
|
22 | + { |
|
23 | + wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public function routerClearConsole() |
|
30 | - { |
|
31 | - glsr(AdminController::class)->routerClearConsole(); |
|
32 | - wp_send_json_success([ |
|
33 | - 'console' => glsr(Console::class)->get(), |
|
34 | - 'notices' => glsr(Notice::class)->get(), |
|
35 | - ]); |
|
36 | - } |
|
26 | + /** |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public function routerClearConsole() |
|
30 | + { |
|
31 | + glsr(AdminController::class)->routerClearConsole(); |
|
32 | + wp_send_json_success([ |
|
33 | + 'console' => glsr(Console::class)->get(), |
|
34 | + 'notices' => glsr(Notice::class)->get(), |
|
35 | + ]); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return void |
|
40 | - */ |
|
41 | - public function routerCountReviews() |
|
42 | - { |
|
43 | - glsr(AdminController::class)->routerCountReviews(); |
|
44 | - wp_send_json_success([ |
|
45 | - 'notices' => glsr(Notice::class)->get(), |
|
46 | - ]); |
|
47 | - } |
|
38 | + /** |
|
39 | + * @return void |
|
40 | + */ |
|
41 | + public function routerCountReviews() |
|
42 | + { |
|
43 | + glsr(AdminController::class)->routerCountReviews(); |
|
44 | + wp_send_json_success([ |
|
45 | + 'notices' => glsr(Notice::class)->get(), |
|
46 | + ]); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - public function routerMigrateReviews() |
|
53 | - { |
|
54 | - glsr(AdminController::class)->routerMigrateReviews(); |
|
55 | - wp_send_json_success([ |
|
56 | - 'notices' => glsr(Notice::class)->get(), |
|
57 | - ]); |
|
58 | - } |
|
49 | + /** |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + public function routerMigrateReviews() |
|
53 | + { |
|
54 | + glsr(AdminController::class)->routerMigrateReviews(); |
|
55 | + wp_send_json_success([ |
|
56 | + 'notices' => glsr(Notice::class)->get(), |
|
57 | + ]); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function routerDismissNotice(array $request) |
|
64 | - { |
|
65 | - glsr(NoticeController::class)->routerDismissNotice($request); |
|
66 | - wp_send_json_success(); |
|
67 | - } |
|
60 | + /** |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function routerDismissNotice(array $request) |
|
64 | + { |
|
65 | + glsr(NoticeController::class)->routerDismissNotice($request); |
|
66 | + wp_send_json_success(); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function routerMceShortcode(array $request) |
|
73 | - { |
|
74 | - $shortcode = $request['shortcode']; |
|
75 | - $response = false; |
|
76 | - if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
77 | - $data = glsr()->mceShortcodes[$shortcode]; |
|
78 | - if (!empty($data['errors'])) { |
|
79 | - $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
80 | - } |
|
81 | - $response = [ |
|
82 | - 'body' => $data['fields'], |
|
83 | - 'close' => $data['btn_close'], |
|
84 | - 'ok' => $data['btn_okay'], |
|
85 | - 'shortcode' => $shortcode, |
|
86 | - 'title' => $data['title'], |
|
87 | - ]; |
|
88 | - } |
|
89 | - wp_send_json_success($response); |
|
90 | - } |
|
69 | + /** |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function routerMceShortcode(array $request) |
|
73 | + { |
|
74 | + $shortcode = $request['shortcode']; |
|
75 | + $response = false; |
|
76 | + if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
77 | + $data = glsr()->mceShortcodes[$shortcode]; |
|
78 | + if (!empty($data['errors'])) { |
|
79 | + $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
80 | + } |
|
81 | + $response = [ |
|
82 | + 'body' => $data['fields'], |
|
83 | + 'close' => $data['btn_close'], |
|
84 | + 'ok' => $data['btn_okay'], |
|
85 | + 'shortcode' => $shortcode, |
|
86 | + 'title' => $data['title'], |
|
87 | + ]; |
|
88 | + } |
|
89 | + wp_send_json_success($response); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - public function routerFetchConsole() |
|
96 | - { |
|
97 | - glsr(AdminController::class)->routerFetchConsole(); |
|
98 | - wp_send_json_success([ |
|
99 | - 'console' => glsr(Console::class)->get(), |
|
100 | - 'notices' => glsr(Notice::class)->get(), |
|
101 | - ]); |
|
102 | - } |
|
92 | + /** |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + public function routerFetchConsole() |
|
96 | + { |
|
97 | + glsr(AdminController::class)->routerFetchConsole(); |
|
98 | + wp_send_json_success([ |
|
99 | + 'console' => glsr(Console::class)->get(), |
|
100 | + 'notices' => glsr(Notice::class)->get(), |
|
101 | + ]); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - public function routerResetPermissions() |
|
108 | - { |
|
109 | - glsr(Role::class)->resetAll(); |
|
110 | - glsr(Notice::class)->clear()->addSuccess(__('The permissions have been reset, please reload the page for them to take effect.', 'site-reviews')); |
|
111 | - wp_send_json_success([ |
|
112 | - 'notices' => glsr(Notice::class)->get(), |
|
113 | - ]); |
|
114 | - } |
|
104 | + /** |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + public function routerResetPermissions() |
|
108 | + { |
|
109 | + glsr(Role::class)->resetAll(); |
|
110 | + glsr(Notice::class)->clear()->addSuccess(__('The permissions have been reset, please reload the page for them to take effect.', 'site-reviews')); |
|
111 | + wp_send_json_success([ |
|
112 | + 'notices' => glsr(Notice::class)->get(), |
|
113 | + ]); |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - public function routerSearchPosts(array $request) |
|
120 | - { |
|
121 | - $results = glsr(Database::class)->searchPosts($request['search']); |
|
122 | - wp_send_json_success([ |
|
123 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
124 | - 'items' => $results, |
|
125 | - ]); |
|
126 | - } |
|
116 | + /** |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + public function routerSearchPosts(array $request) |
|
120 | + { |
|
121 | + $results = glsr(Database::class)->searchPosts($request['search']); |
|
122 | + wp_send_json_success([ |
|
123 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
124 | + 'items' => $results, |
|
125 | + ]); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * @return void |
|
130 | - */ |
|
131 | - public function routerSearchTranslations(array $request) |
|
132 | - { |
|
133 | - if (empty($request['exclude'])) { |
|
134 | - $request['exclude'] = []; |
|
135 | - } |
|
136 | - $results = glsr(Translation::class) |
|
137 | - ->search($request['search']) |
|
138 | - ->exclude() |
|
139 | - ->exclude($request['exclude']) |
|
140 | - ->renderResults(); |
|
141 | - wp_send_json_success([ |
|
142 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
143 | - 'items' => $results, |
|
144 | - ]); |
|
145 | - } |
|
128 | + /** |
|
129 | + * @return void |
|
130 | + */ |
|
131 | + public function routerSearchTranslations(array $request) |
|
132 | + { |
|
133 | + if (empty($request['exclude'])) { |
|
134 | + $request['exclude'] = []; |
|
135 | + } |
|
136 | + $results = glsr(Translation::class) |
|
137 | + ->search($request['search']) |
|
138 | + ->exclude() |
|
139 | + ->exclude($request['exclude']) |
|
140 | + ->renderResults(); |
|
141 | + wp_send_json_success([ |
|
142 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
143 | + 'items' => $results, |
|
144 | + ]); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * @return void |
|
149 | - */ |
|
150 | - public function routerSubmitReview(array $request) |
|
151 | - { |
|
152 | - $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
153 | - $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
154 | - $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
155 | - $data = [ |
|
156 | - 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
157 | - 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
158 | - 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
159 | - 'redirect' => $redirect, |
|
160 | - ]; |
|
161 | - if (false === $data['errors']) { |
|
162 | - glsr()->sessionClear(); |
|
163 | - wp_send_json_success($data); |
|
164 | - } |
|
165 | - wp_send_json_error($data); |
|
166 | - } |
|
147 | + /** |
|
148 | + * @return void |
|
149 | + */ |
|
150 | + public function routerSubmitReview(array $request) |
|
151 | + { |
|
152 | + $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
153 | + $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
154 | + $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
155 | + $data = [ |
|
156 | + 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
157 | + 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
158 | + 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
159 | + 'redirect' => $redirect, |
|
160 | + ]; |
|
161 | + if (false === $data['errors']) { |
|
162 | + glsr()->sessionClear(); |
|
163 | + wp_send_json_success($data); |
|
164 | + } |
|
165 | + wp_send_json_error($data); |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - public function routerFetchPagedReviews(array $request) |
|
172 | - { |
|
173 | - $homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH)); |
|
174 | - $urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)); |
|
175 | - $urlQuery = []; |
|
176 | - parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
177 | - $pagedUrl = $homePath === $urlPath |
|
178 | - ? home_url() |
|
179 | - : home_url($urlPath); |
|
180 | - $args = [ |
|
181 | - 'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
182 | - 'pagedUrl' => trailingslashit($pagedUrl), |
|
183 | - 'pagination' => 'ajax', |
|
184 | - 'schema' => false, |
|
185 | - ]; |
|
186 | - $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
187 | - $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts); |
|
188 | - $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts)); |
|
189 | - return wp_send_json_success([ |
|
190 | - 'pagination' => $html->getPagination(), |
|
191 | - 'reviews' => $html->getReviews(), |
|
192 | - ]); |
|
193 | - } |
|
168 | + /** |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + public function routerFetchPagedReviews(array $request) |
|
172 | + { |
|
173 | + $homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH)); |
|
174 | + $urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)); |
|
175 | + $urlQuery = []; |
|
176 | + parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
177 | + $pagedUrl = $homePath === $urlPath |
|
178 | + ? home_url() |
|
179 | + : home_url($urlPath); |
|
180 | + $args = [ |
|
181 | + 'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
182 | + 'pagedUrl' => trailingslashit($pagedUrl), |
|
183 | + 'pagination' => 'ajax', |
|
184 | + 'schema' => false, |
|
185 | + ]; |
|
186 | + $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
187 | + $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts); |
|
188 | + $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts)); |
|
189 | + return wp_send_json_success([ |
|
190 | + 'pagination' => $html->getPagination(), |
|
191 | + 'reviews' => $html->getReviews(), |
|
192 | + ]); |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * @return void |
|
197 | - */ |
|
198 | - public function routerTogglePinned(array $request) |
|
199 | - { |
|
200 | - $isPinned = $this->execute(new TogglePinned($request)); |
|
201 | - wp_send_json_success([ |
|
202 | - 'notices' => glsr(Notice::class)->get(), |
|
203 | - 'pinned' => $isPinned, |
|
204 | - ]); |
|
205 | - } |
|
195 | + /** |
|
196 | + * @return void |
|
197 | + */ |
|
198 | + public function routerTogglePinned(array $request) |
|
199 | + { |
|
200 | + $isPinned = $this->execute(new TogglePinned($request)); |
|
201 | + wp_send_json_success([ |
|
202 | + 'notices' => glsr(Notice::class)->get(), |
|
203 | + 'pinned' => $isPinned, |
|
204 | + ]); |
|
205 | + } |
|
206 | 206 | } |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @return void |
20 | 20 | */ |
21 | - public function routerChangeStatus(array $request) |
|
21 | + public function routerChangeStatus( array $request ) |
|
22 | 22 | { |
23 | - wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
23 | + wp_send_json_success( $this->execute( new ChangeStatus( $request ) ) ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function routerClearConsole() |
30 | 30 | { |
31 | - glsr(AdminController::class)->routerClearConsole(); |
|
32 | - wp_send_json_success([ |
|
33 | - 'console' => glsr(Console::class)->get(), |
|
34 | - 'notices' => glsr(Notice::class)->get(), |
|
35 | - ]); |
|
31 | + glsr( AdminController::class )->routerClearConsole(); |
|
32 | + wp_send_json_success( [ |
|
33 | + 'console' => glsr( Console::class )->get(), |
|
34 | + 'notices' => glsr( Notice::class )->get(), |
|
35 | + ] ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -40,10 +40,10 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function routerCountReviews() |
42 | 42 | { |
43 | - glsr(AdminController::class)->routerCountReviews(); |
|
44 | - wp_send_json_success([ |
|
45 | - 'notices' => glsr(Notice::class)->get(), |
|
46 | - ]); |
|
43 | + glsr( AdminController::class )->routerCountReviews(); |
|
44 | + wp_send_json_success( [ |
|
45 | + 'notices' => glsr( Notice::class )->get(), |
|
46 | + ] ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -51,32 +51,32 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function routerMigrateReviews() |
53 | 53 | { |
54 | - glsr(AdminController::class)->routerMigrateReviews(); |
|
55 | - wp_send_json_success([ |
|
56 | - 'notices' => glsr(Notice::class)->get(), |
|
57 | - ]); |
|
54 | + glsr( AdminController::class )->routerMigrateReviews(); |
|
55 | + wp_send_json_success( [ |
|
56 | + 'notices' => glsr( Notice::class )->get(), |
|
57 | + ] ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * @return void |
62 | 62 | */ |
63 | - public function routerDismissNotice(array $request) |
|
63 | + public function routerDismissNotice( array $request ) |
|
64 | 64 | { |
65 | - glsr(NoticeController::class)->routerDismissNotice($request); |
|
65 | + glsr( NoticeController::class )->routerDismissNotice( $request ); |
|
66 | 66 | wp_send_json_success(); |
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
70 | 70 | * @return void |
71 | 71 | */ |
72 | - public function routerMceShortcode(array $request) |
|
72 | + public function routerMceShortcode( array $request ) |
|
73 | 73 | { |
74 | 74 | $shortcode = $request['shortcode']; |
75 | 75 | $response = false; |
76 | - if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
76 | + if( array_key_exists( $shortcode, glsr()->mceShortcodes ) ) { |
|
77 | 77 | $data = glsr()->mceShortcodes[$shortcode]; |
78 | - if (!empty($data['errors'])) { |
|
79 | - $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
78 | + if( !empty($data['errors']) ) { |
|
79 | + $data['btn_okay'] = [esc_html__( 'Okay', 'site-reviews' )]; |
|
80 | 80 | } |
81 | 81 | $response = [ |
82 | 82 | 'body' => $data['fields'], |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | 'title' => $data['title'], |
87 | 87 | ]; |
88 | 88 | } |
89 | - wp_send_json_success($response); |
|
89 | + wp_send_json_success( $response ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function routerFetchConsole() |
96 | 96 | { |
97 | - glsr(AdminController::class)->routerFetchConsole(); |
|
98 | - wp_send_json_success([ |
|
99 | - 'console' => glsr(Console::class)->get(), |
|
100 | - 'notices' => glsr(Notice::class)->get(), |
|
101 | - ]); |
|
97 | + glsr( AdminController::class )->routerFetchConsole(); |
|
98 | + wp_send_json_success( [ |
|
99 | + 'console' => glsr( Console::class )->get(), |
|
100 | + 'notices' => glsr( Notice::class )->get(), |
|
101 | + ] ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,101 +106,101 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function routerResetPermissions() |
108 | 108 | { |
109 | - glsr(Role::class)->resetAll(); |
|
110 | - glsr(Notice::class)->clear()->addSuccess(__('The permissions have been reset, please reload the page for them to take effect.', 'site-reviews')); |
|
111 | - wp_send_json_success([ |
|
112 | - 'notices' => glsr(Notice::class)->get(), |
|
113 | - ]); |
|
109 | + glsr( Role::class )->resetAll(); |
|
110 | + glsr( Notice::class )->clear()->addSuccess( __( 'The permissions have been reset, please reload the page for them to take effect.', 'site-reviews' ) ); |
|
111 | + wp_send_json_success( [ |
|
112 | + 'notices' => glsr( Notice::class )->get(), |
|
113 | + ] ); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
117 | 117 | * @return void |
118 | 118 | */ |
119 | - public function routerSearchPosts(array $request) |
|
119 | + public function routerSearchPosts( array $request ) |
|
120 | 120 | { |
121 | - $results = glsr(Database::class)->searchPosts($request['search']); |
|
122 | - wp_send_json_success([ |
|
123 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
121 | + $results = glsr( Database::class )->searchPosts( $request['search'] ); |
|
122 | + wp_send_json_success( [ |
|
123 | + 'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>', |
|
124 | 124 | 'items' => $results, |
125 | - ]); |
|
125 | + ] ); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
129 | 129 | * @return void |
130 | 130 | */ |
131 | - public function routerSearchTranslations(array $request) |
|
131 | + public function routerSearchTranslations( array $request ) |
|
132 | 132 | { |
133 | - if (empty($request['exclude'])) { |
|
133 | + if( empty($request['exclude']) ) { |
|
134 | 134 | $request['exclude'] = []; |
135 | 135 | } |
136 | - $results = glsr(Translation::class) |
|
137 | - ->search($request['search']) |
|
136 | + $results = glsr( Translation::class ) |
|
137 | + ->search( $request['search'] ) |
|
138 | 138 | ->exclude() |
139 | - ->exclude($request['exclude']) |
|
139 | + ->exclude( $request['exclude'] ) |
|
140 | 140 | ->renderResults(); |
141 | - wp_send_json_success([ |
|
142 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
141 | + wp_send_json_success( [ |
|
142 | + 'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>', |
|
143 | 143 | 'items' => $results, |
144 | - ]); |
|
144 | + ] ); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
148 | 148 | * @return void |
149 | 149 | */ |
150 | - public function routerSubmitReview(array $request) |
|
150 | + public function routerSubmitReview( array $request ) |
|
151 | 151 | { |
152 | - $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
153 | - $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
154 | - $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
152 | + $command = glsr( PublicController::class )->routerSubmitReview( $request ); |
|
153 | + $redirect = trim( strval( get_post_meta( $command->post_id, 'redirect_to', true ) ) ); |
|
154 | + $redirect = apply_filters( 'site-reviews/review/redirect', $redirect, $command ); |
|
155 | 155 | $data = [ |
156 | - 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
157 | - 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
158 | - 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
156 | + 'errors' => glsr()->sessionGet( $command->form_id.'errors', false ), |
|
157 | + 'message' => glsr()->sessionGet( $command->form_id.'message', '' ), |
|
158 | + 'recaptcha' => glsr()->sessionGet( $command->form_id.'recaptcha', false ), |
|
159 | 159 | 'redirect' => $redirect, |
160 | 160 | ]; |
161 | - if (false === $data['errors']) { |
|
161 | + if( false === $data['errors'] ) { |
|
162 | 162 | glsr()->sessionClear(); |
163 | - wp_send_json_success($data); |
|
163 | + wp_send_json_success( $data ); |
|
164 | 164 | } |
165 | - wp_send_json_error($data); |
|
165 | + wp_send_json_error( $data ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | 169 | * @return void |
170 | 170 | */ |
171 | - public function routerFetchPagedReviews(array $request) |
|
171 | + public function routerFetchPagedReviews( array $request ) |
|
172 | 172 | { |
173 | - $homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH)); |
|
174 | - $urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)); |
|
173 | + $homePath = untrailingslashit( parse_url( home_url(), PHP_URL_PATH ) ); |
|
174 | + $urlPath = untrailingslashit( parse_url( Arr::get( $request, 'url' ), PHP_URL_PATH ) ); |
|
175 | 175 | $urlQuery = []; |
176 | - parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
176 | + parse_str( parse_url( Arr::get( $request, 'url' ), PHP_URL_QUERY ), $urlQuery ); |
|
177 | 177 | $pagedUrl = $homePath === $urlPath |
178 | 178 | ? home_url() |
179 | - : home_url($urlPath); |
|
179 | + : home_url( $urlPath ); |
|
180 | 180 | $args = [ |
181 | - 'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
182 | - 'pagedUrl' => trailingslashit($pagedUrl), |
|
181 | + 'paged' => (int)Arr::get( $urlQuery, glsr()->constant( 'PAGED_QUERY_VAR' ), 1 ), |
|
182 | + 'pagedUrl' => trailingslashit( $pagedUrl ), |
|
183 | 183 | 'pagination' => 'ajax', |
184 | 184 | 'schema' => false, |
185 | 185 | ]; |
186 | - $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
187 | - $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts); |
|
188 | - $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts)); |
|
189 | - return wp_send_json_success([ |
|
186 | + $atts = (array)json_decode( Arr::get( $request, 'atts' ) ); |
|
187 | + $atts = glsr( SiteReviewsShortcode::class )->normalizeAtts( $atts ); |
|
188 | + $html = glsr( SiteReviewsPartial::class )->build( wp_parse_args( $args, $atts ) ); |
|
189 | + return wp_send_json_success( [ |
|
190 | 190 | 'pagination' => $html->getPagination(), |
191 | 191 | 'reviews' => $html->getReviews(), |
192 | - ]); |
|
192 | + ] ); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | 196 | * @return void |
197 | 197 | */ |
198 | - public function routerTogglePinned(array $request) |
|
198 | + public function routerTogglePinned( array $request ) |
|
199 | 199 | { |
200 | - $isPinned = $this->execute(new TogglePinned($request)); |
|
201 | - wp_send_json_success([ |
|
202 | - 'notices' => glsr(Notice::class)->get(), |
|
200 | + $isPinned = $this->execute( new TogglePinned( $request ) ); |
|
201 | + wp_send_json_success( [ |
|
202 | + 'notices' => glsr( Notice::class )->get(), |
|
203 | 203 | 'pinned' => $isPinned, |
204 | - ]); |
|
204 | + ] ); |
|
205 | 205 | } |
206 | 206 | } |