@@ -7,83 +7,83 @@ |
||
7 | 7 | |
8 | 8 | class Wpml implements Contract |
9 | 9 | { |
10 | - const PLUGIN_NAME = 'WPML'; |
|
11 | - const SUPPORTED_VERSION = '3.3.5'; |
|
10 | + const PLUGIN_NAME = 'WPML'; |
|
11 | + const SUPPORTED_VERSION = '3.3.5'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * {@inheritdoc} |
|
15 | - */ |
|
16 | - public function getPost($postId) |
|
17 | - { |
|
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
20 | - return; |
|
21 | - } |
|
22 | - if ($this->isEnabled()) { |
|
23 | - $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
24 | - } |
|
25 | - return get_post(intval($postId)); |
|
26 | - } |
|
13 | + /** |
|
14 | + * {@inheritdoc} |
|
15 | + */ |
|
16 | + public function getPost($postId) |
|
17 | + { |
|
18 | + $postId = trim($postId); |
|
19 | + if (!is_numeric($postId)) { |
|
20 | + return; |
|
21 | + } |
|
22 | + if ($this->isEnabled()) { |
|
23 | + $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
24 | + } |
|
25 | + return get_post(intval($postId)); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - public function getPostIds(array $postIds) |
|
32 | - { |
|
33 | - if (!$this->isEnabled()) { |
|
34 | - return $postIds; |
|
35 | - } |
|
36 | - $newPostIds = []; |
|
37 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
38 | - $postType = get_post_type($postId); |
|
39 | - if (!$postType) { |
|
40 | - continue; |
|
41 | - } |
|
42 | - $elementType = 'post_'.$postType; |
|
43 | - $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
44 | - $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
45 | - if (!is_array($translations)) { |
|
46 | - $translations = []; |
|
47 | - } |
|
48 | - $newPostIds = array_merge( |
|
49 | - $newPostIds, |
|
50 | - array_column($translations, 'element_id') |
|
51 | - ); |
|
52 | - } |
|
53 | - return $this->cleanIds($newPostIds); |
|
54 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + public function getPostIds(array $postIds) |
|
32 | + { |
|
33 | + if (!$this->isEnabled()) { |
|
34 | + return $postIds; |
|
35 | + } |
|
36 | + $newPostIds = []; |
|
37 | + foreach ($this->cleanIds($postIds) as $postId) { |
|
38 | + $postType = get_post_type($postId); |
|
39 | + if (!$postType) { |
|
40 | + continue; |
|
41 | + } |
|
42 | + $elementType = 'post_'.$postType; |
|
43 | + $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
44 | + $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
45 | + if (!is_array($translations)) { |
|
46 | + $translations = []; |
|
47 | + } |
|
48 | + $newPostIds = array_merge( |
|
49 | + $newPostIds, |
|
50 | + array_column($translations, 'element_id') |
|
51 | + ); |
|
52 | + } |
|
53 | + return $this->cleanIds($newPostIds); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - public function isActive() |
|
60 | - { |
|
61 | - return defined('ICL_SITEPRESS_VERSION'); |
|
62 | - } |
|
56 | + /** |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + public function isActive() |
|
60 | + { |
|
61 | + return defined('ICL_SITEPRESS_VERSION'); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * {@inheritdoc} |
|
66 | - */ |
|
67 | - public function isEnabled() |
|
68 | - { |
|
69 | - return $this->isActive() |
|
70 | - && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
71 | - } |
|
64 | + /** |
|
65 | + * {@inheritdoc} |
|
66 | + */ |
|
67 | + public function isEnabled() |
|
68 | + { |
|
69 | + return $this->isActive() |
|
70 | + && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * {@inheritdoc} |
|
75 | - */ |
|
76 | - public function isSupported() |
|
77 | - { |
|
78 | - return $this->isActive() |
|
79 | - && version_compare(ICL_SITEPRESS_VERSION, static::SUPPORTED_VERSION, '>='); |
|
80 | - } |
|
73 | + /** |
|
74 | + * {@inheritdoc} |
|
75 | + */ |
|
76 | + public function isSupported() |
|
77 | + { |
|
78 | + return $this->isActive() |
|
79 | + && version_compare(ICL_SITEPRESS_VERSION, static::SUPPORTED_VERSION, '>='); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - protected function cleanIds(array $postIds) |
|
86 | - { |
|
87 | - return array_filter(array_unique($postIds)); |
|
88 | - } |
|
82 | + /** |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + protected function cleanIds(array $postIds) |
|
86 | + { |
|
87 | + return array_filter(array_unique($postIds)); |
|
88 | + } |
|
89 | 89 | } |
@@ -13,44 +13,44 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * {@inheritdoc} |
15 | 15 | */ |
16 | - public function getPost($postId) |
|
16 | + public function getPost( $postId ) |
|
17 | 17 | { |
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
18 | + $postId = trim( $postId ); |
|
19 | + if( !is_numeric( $postId ) ) { |
|
20 | 20 | return; |
21 | 21 | } |
22 | - if ($this->isEnabled()) { |
|
23 | - $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
22 | + if( $this->isEnabled() ) { |
|
23 | + $postId = apply_filters( 'wpml_object_id', $postId, 'any', true ); |
|
24 | 24 | } |
25 | - return get_post(intval($postId)); |
|
25 | + return get_post( intval( $postId ) ); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * {@inheritdoc} |
30 | 30 | */ |
31 | - public function getPostIds(array $postIds) |
|
31 | + public function getPostIds( array $postIds ) |
|
32 | 32 | { |
33 | - if (!$this->isEnabled()) { |
|
33 | + if( !$this->isEnabled() ) { |
|
34 | 34 | return $postIds; |
35 | 35 | } |
36 | 36 | $newPostIds = []; |
37 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
38 | - $postType = get_post_type($postId); |
|
39 | - if (!$postType) { |
|
37 | + foreach( $this->cleanIds( $postIds ) as $postId ) { |
|
38 | + $postType = get_post_type( $postId ); |
|
39 | + if( !$postType ) { |
|
40 | 40 | continue; |
41 | 41 | } |
42 | 42 | $elementType = 'post_'.$postType; |
43 | - $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
44 | - $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
45 | - if (!is_array($translations)) { |
|
43 | + $trid = apply_filters( 'wpml_element_trid', null, $postId, $elementType ); |
|
44 | + $translations = apply_filters( 'wpml_get_element_translations', null, $trid, $elementType ); |
|
45 | + if( !is_array( $translations ) ) { |
|
46 | 46 | $translations = []; |
47 | 47 | } |
48 | 48 | $newPostIds = array_merge( |
49 | 49 | $newPostIds, |
50 | - array_column($translations, 'element_id') |
|
50 | + array_column( $translations, 'element_id' ) |
|
51 | 51 | ); |
52 | 52 | } |
53 | - return $this->cleanIds($newPostIds); |
|
53 | + return $this->cleanIds( $newPostIds ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function isActive() |
60 | 60 | { |
61 | - return defined('ICL_SITEPRESS_VERSION'); |
|
61 | + return defined( 'ICL_SITEPRESS_VERSION' ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | public function isEnabled() |
68 | 68 | { |
69 | 69 | return $this->isActive() |
70 | - && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
70 | + && 'wpml' == glsr( OptionManager::class )->get( 'settings.general.multilingual' ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | public function isSupported() |
77 | 77 | { |
78 | 78 | return $this->isActive() |
79 | - && version_compare(ICL_SITEPRESS_VERSION, static::SUPPORTED_VERSION, '>='); |
|
79 | + && version_compare( ICL_SITEPRESS_VERSION, static::SUPPORTED_VERSION, '>=' ); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | 83 | * @return array |
84 | 84 | */ |
85 | - protected function cleanIds(array $postIds) |
|
85 | + protected function cleanIds( array $postIds ) |
|
86 | 86 | { |
87 | - return array_filter(array_unique($postIds)); |
|
87 | + return array_filter( array_unique( $postIds ) ); |
|
88 | 88 | } |
89 | 89 | } |
@@ -7,79 +7,79 @@ |
||
7 | 7 | |
8 | 8 | class Polylang implements Contract |
9 | 9 | { |
10 | - const PLUGIN_NAME = 'Polylang'; |
|
11 | - const SUPPORTED_VERSION = '2.3'; |
|
10 | + const PLUGIN_NAME = 'Polylang'; |
|
11 | + const SUPPORTED_VERSION = '2.3'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * {@inheritdoc} |
|
15 | - */ |
|
16 | - public function getPost($postId) |
|
17 | - { |
|
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
20 | - return; |
|
21 | - } |
|
22 | - if ($this->isEnabled()) { |
|
23 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
24 | - } |
|
25 | - if (!empty($polylangPostId)) { |
|
26 | - $postId = $polylangPostId; |
|
27 | - } |
|
28 | - return get_post(intval($postId)); |
|
29 | - } |
|
13 | + /** |
|
14 | + * {@inheritdoc} |
|
15 | + */ |
|
16 | + public function getPost($postId) |
|
17 | + { |
|
18 | + $postId = trim($postId); |
|
19 | + if (!is_numeric($postId)) { |
|
20 | + return; |
|
21 | + } |
|
22 | + if ($this->isEnabled()) { |
|
23 | + $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
24 | + } |
|
25 | + if (!empty($polylangPostId)) { |
|
26 | + $postId = $polylangPostId; |
|
27 | + } |
|
28 | + return get_post(intval($postId)); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * {@inheritdoc} |
|
33 | - */ |
|
34 | - public function getPostIds(array $postIds) |
|
35 | - { |
|
36 | - if (!$this->isEnabled()) { |
|
37 | - return $postIds; |
|
38 | - } |
|
39 | - $newPostIds = []; |
|
40 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
41 | - $newPostIds = array_merge( |
|
42 | - $newPostIds, |
|
43 | - array_values(pll_get_post_translations($postId)) |
|
44 | - ); |
|
45 | - } |
|
46 | - return $this->cleanIds($newPostIds); |
|
47 | - } |
|
31 | + /** |
|
32 | + * {@inheritdoc} |
|
33 | + */ |
|
34 | + public function getPostIds(array $postIds) |
|
35 | + { |
|
36 | + if (!$this->isEnabled()) { |
|
37 | + return $postIds; |
|
38 | + } |
|
39 | + $newPostIds = []; |
|
40 | + foreach ($this->cleanIds($postIds) as $postId) { |
|
41 | + $newPostIds = array_merge( |
|
42 | + $newPostIds, |
|
43 | + array_values(pll_get_post_translations($postId)) |
|
44 | + ); |
|
45 | + } |
|
46 | + return $this->cleanIds($newPostIds); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - public function isActive() |
|
53 | - { |
|
54 | - return function_exists('PLL') |
|
55 | - && function_exists('pll_get_post') |
|
56 | - && function_exists('pll_get_post_language') |
|
57 | - && function_exists('pll_get_post_translations'); |
|
58 | - } |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + public function isActive() |
|
53 | + { |
|
54 | + return function_exists('PLL') |
|
55 | + && function_exists('pll_get_post') |
|
56 | + && function_exists('pll_get_post_language') |
|
57 | + && function_exists('pll_get_post_translations'); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * {@inheritdoc} |
|
62 | - */ |
|
63 | - public function isEnabled() |
|
64 | - { |
|
65 | - return $this->isActive() |
|
66 | - && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
67 | - } |
|
60 | + /** |
|
61 | + * {@inheritdoc} |
|
62 | + */ |
|
63 | + public function isEnabled() |
|
64 | + { |
|
65 | + return $this->isActive() |
|
66 | + && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * {@inheritdoc} |
|
71 | - */ |
|
72 | - public function isSupported() |
|
73 | - { |
|
74 | - return defined('POLYLANG_VERSION') |
|
75 | - && version_compare(POLYLANG_VERSION, static::SUPPORTED_VERSION, '>='); |
|
76 | - } |
|
69 | + /** |
|
70 | + * {@inheritdoc} |
|
71 | + */ |
|
72 | + public function isSupported() |
|
73 | + { |
|
74 | + return defined('POLYLANG_VERSION') |
|
75 | + && version_compare(POLYLANG_VERSION, static::SUPPORTED_VERSION, '>='); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - protected function cleanIds(array $postIds) |
|
82 | - { |
|
83 | - return array_filter(array_unique($postIds)); |
|
84 | - } |
|
78 | + /** |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + protected function cleanIds(array $postIds) |
|
82 | + { |
|
83 | + return array_filter(array_unique($postIds)); |
|
84 | + } |
|
85 | 85 | } |
@@ -13,37 +13,37 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * {@inheritdoc} |
15 | 15 | */ |
16 | - public function getPost($postId) |
|
16 | + public function getPost( $postId ) |
|
17 | 17 | { |
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
18 | + $postId = trim( $postId ); |
|
19 | + if( !is_numeric( $postId ) ) { |
|
20 | 20 | return; |
21 | 21 | } |
22 | - if ($this->isEnabled()) { |
|
23 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
22 | + if( $this->isEnabled() ) { |
|
23 | + $polylangPostId = pll_get_post( $postId, pll_get_post_language( get_the_ID() ) ); |
|
24 | 24 | } |
25 | - if (!empty($polylangPostId)) { |
|
25 | + if( !empty($polylangPostId) ) { |
|
26 | 26 | $postId = $polylangPostId; |
27 | 27 | } |
28 | - return get_post(intval($postId)); |
|
28 | + return get_post( intval( $postId ) ); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * {@inheritdoc} |
33 | 33 | */ |
34 | - public function getPostIds(array $postIds) |
|
34 | + public function getPostIds( array $postIds ) |
|
35 | 35 | { |
36 | - if (!$this->isEnabled()) { |
|
36 | + if( !$this->isEnabled() ) { |
|
37 | 37 | return $postIds; |
38 | 38 | } |
39 | 39 | $newPostIds = []; |
40 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
40 | + foreach( $this->cleanIds( $postIds ) as $postId ) { |
|
41 | 41 | $newPostIds = array_merge( |
42 | 42 | $newPostIds, |
43 | - array_values(pll_get_post_translations($postId)) |
|
43 | + array_values( pll_get_post_translations( $postId ) ) |
|
44 | 44 | ); |
45 | 45 | } |
46 | - return $this->cleanIds($newPostIds); |
|
46 | + return $this->cleanIds( $newPostIds ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function isActive() |
53 | 53 | { |
54 | - return function_exists('PLL') |
|
55 | - && function_exists('pll_get_post') |
|
56 | - && function_exists('pll_get_post_language') |
|
57 | - && function_exists('pll_get_post_translations'); |
|
54 | + return function_exists( 'PLL' ) |
|
55 | + && function_exists( 'pll_get_post' ) |
|
56 | + && function_exists( 'pll_get_post_language' ) |
|
57 | + && function_exists( 'pll_get_post_translations' ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | public function isEnabled() |
64 | 64 | { |
65 | 65 | return $this->isActive() |
66 | - && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
66 | + && 'polylang' == glsr( OptionManager::class )->get( 'settings.general.multilingual' ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,15 +71,15 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function isSupported() |
73 | 73 | { |
74 | - return defined('POLYLANG_VERSION') |
|
75 | - && version_compare(POLYLANG_VERSION, static::SUPPORTED_VERSION, '>='); |
|
74 | + return defined( 'POLYLANG_VERSION' ) |
|
75 | + && version_compare( POLYLANG_VERSION, static::SUPPORTED_VERSION, '>=' ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @return array |
80 | 80 | */ |
81 | - protected function cleanIds(array $postIds) |
|
81 | + protected function cleanIds( array $postIds ) |
|
82 | 82 | { |
83 | - return array_filter(array_unique($postIds)); |
|
83 | + return array_filter( array_unique( $postIds ) ); |
|
84 | 84 | } |
85 | 85 | } |
@@ -4,206 +4,206 @@ |
||
4 | 4 | |
5 | 5 | class Rating |
6 | 6 | { |
7 | - /** |
|
8 | - * The more sure we are of the confidence interval (the higher the confidence level), the less |
|
9 | - * precise the estimation will be as the margin for error will be higher. |
|
10 | - * @see http://homepages.math.uic.edu/~bpower6/stat101/Confidence%20Intervals.pdf |
|
11 | - * @see https://www.thecalculator.co/math/Confidence-Interval-Calculator-210.html |
|
12 | - * @see https://www.youtube.com/watch?v=grodoLzThy4 |
|
13 | - * @see https://en.wikipedia.org/wiki/Standard_score |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - const CONFIDENCE_LEVEL_Z_SCORES = [ |
|
17 | - 50 => 0.67449, |
|
18 | - 70 => 1.04, |
|
19 | - 75 => 1.15035, |
|
20 | - 80 => 1.282, |
|
21 | - 85 => 1.44, |
|
22 | - 90 => 1.64485, |
|
23 | - 92 => 1.75, |
|
24 | - 95 => 1.95996, |
|
25 | - 96 => 2.05, |
|
26 | - 97 => 2.17009, |
|
27 | - 98 => 2.326, |
|
28 | - 99 => 2.57583, |
|
29 | - '99.5' => 2.81, |
|
30 | - '99.8' => 3.08, |
|
31 | - '99.9' => 3.29053, |
|
32 | - ]; |
|
7 | + /** |
|
8 | + * The more sure we are of the confidence interval (the higher the confidence level), the less |
|
9 | + * precise the estimation will be as the margin for error will be higher. |
|
10 | + * @see http://homepages.math.uic.edu/~bpower6/stat101/Confidence%20Intervals.pdf |
|
11 | + * @see https://www.thecalculator.co/math/Confidence-Interval-Calculator-210.html |
|
12 | + * @see https://www.youtube.com/watch?v=grodoLzThy4 |
|
13 | + * @see https://en.wikipedia.org/wiki/Standard_score |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + const CONFIDENCE_LEVEL_Z_SCORES = [ |
|
17 | + 50 => 0.67449, |
|
18 | + 70 => 1.04, |
|
19 | + 75 => 1.15035, |
|
20 | + 80 => 1.282, |
|
21 | + 85 => 1.44, |
|
22 | + 90 => 1.64485, |
|
23 | + 92 => 1.75, |
|
24 | + 95 => 1.95996, |
|
25 | + 96 => 2.05, |
|
26 | + 97 => 2.17009, |
|
27 | + 98 => 2.326, |
|
28 | + 99 => 2.57583, |
|
29 | + '99.5' => 2.81, |
|
30 | + '99.8' => 3.08, |
|
31 | + '99.9' => 3.29053, |
|
32 | + ]; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var int |
|
36 | - */ |
|
37 | - const MAX_RATING = 5; |
|
34 | + /** |
|
35 | + * @var int |
|
36 | + */ |
|
37 | + const MAX_RATING = 5; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - const MIN_RATING = 1; |
|
39 | + /** |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + const MIN_RATING = 1; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param int $roundBy |
|
46 | - * @return float |
|
47 | - */ |
|
48 | - public function getAverage(array $ratingCounts, $roundBy = 1) |
|
49 | - { |
|
50 | - $average = array_sum($ratingCounts); |
|
51 | - if ($average > 0) { |
|
52 | - $average = round($this->getTotalSum($ratingCounts) / $average, intval($roundBy)); |
|
53 | - } |
|
54 | - return floatval(apply_filters('site-reviews/rating/average', $average, $ratingCounts)); |
|
55 | - } |
|
44 | + /** |
|
45 | + * @param int $roundBy |
|
46 | + * @return float |
|
47 | + */ |
|
48 | + public function getAverage(array $ratingCounts, $roundBy = 1) |
|
49 | + { |
|
50 | + $average = array_sum($ratingCounts); |
|
51 | + if ($average > 0) { |
|
52 | + $average = round($this->getTotalSum($ratingCounts) / $average, intval($roundBy)); |
|
53 | + } |
|
54 | + return floatval(apply_filters('site-reviews/rating/average', $average, $ratingCounts)); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Get the lower bound for up/down ratings |
|
59 | - * Method receives an up/down ratings array: [1, -1, -1, 1, 1, -1]. |
|
60 | - * @see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html |
|
61 | - * @see https://news.ycombinator.com/item?id=10481507 |
|
62 | - * @see https://dataorigami.net/blogs/napkin-folding/79030467-an-algorithm-to-sort-top-comments |
|
63 | - * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html |
|
64 | - * @param int $confidencePercentage |
|
65 | - * @return int|float |
|
66 | - */ |
|
67 | - public function getLowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95) |
|
68 | - { |
|
69 | - $numRatings = array_sum($upDownCounts); |
|
70 | - if ($numRatings < 1) { |
|
71 | - return 0; |
|
72 | - } |
|
73 | - $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
|
74 | - $phat = 1 * $upDownCounts[1] / $numRatings; |
|
75 | - return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings); |
|
76 | - } |
|
57 | + /** |
|
58 | + * Get the lower bound for up/down ratings |
|
59 | + * Method receives an up/down ratings array: [1, -1, -1, 1, 1, -1]. |
|
60 | + * @see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html |
|
61 | + * @see https://news.ycombinator.com/item?id=10481507 |
|
62 | + * @see https://dataorigami.net/blogs/napkin-folding/79030467-an-algorithm-to-sort-top-comments |
|
63 | + * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html |
|
64 | + * @param int $confidencePercentage |
|
65 | + * @return int|float |
|
66 | + */ |
|
67 | + public function getLowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95) |
|
68 | + { |
|
69 | + $numRatings = array_sum($upDownCounts); |
|
70 | + if ($numRatings < 1) { |
|
71 | + return 0; |
|
72 | + } |
|
73 | + $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
|
74 | + $phat = 1 * $upDownCounts[1] / $numRatings; |
|
75 | + return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return int|float |
|
80 | - */ |
|
81 | - public function getOverallPercentage(array $ratingCounts) |
|
82 | - { |
|
83 | - return round($this->getAverage($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2); |
|
84 | - } |
|
78 | + /** |
|
79 | + * @return int|float |
|
80 | + */ |
|
81 | + public function getOverallPercentage(array $ratingCounts) |
|
82 | + { |
|
83 | + return round($this->getAverage($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - public function getPercentages(array $ratingCounts) |
|
90 | - { |
|
91 | - $total = array_sum($ratingCounts); |
|
92 | - foreach ($ratingCounts as $index => $count) { |
|
93 | - if (empty($count)) { |
|
94 | - continue; |
|
95 | - } |
|
96 | - $ratingCounts[$index] = $count / $total * 100; |
|
97 | - } |
|
98 | - return $this->getRoundedPercentages($ratingCounts); |
|
99 | - } |
|
86 | + /** |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + public function getPercentages(array $ratingCounts) |
|
90 | + { |
|
91 | + $total = array_sum($ratingCounts); |
|
92 | + foreach ($ratingCounts as $index => $count) { |
|
93 | + if (empty($count)) { |
|
94 | + continue; |
|
95 | + } |
|
96 | + $ratingCounts[$index] = $count / $total * 100; |
|
97 | + } |
|
98 | + return $this->getRoundedPercentages($ratingCounts); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @return float |
|
103 | - */ |
|
104 | - public function getRanking(array $ratingCounts) |
|
105 | - { |
|
106 | - return floatval(apply_filters('site-reviews/rating/ranking', |
|
107 | - $this->getRankingUsingImdb($ratingCounts), |
|
108 | - $ratingCounts, |
|
109 | - $this |
|
110 | - )); |
|
111 | - } |
|
101 | + /** |
|
102 | + * @return float |
|
103 | + */ |
|
104 | + public function getRanking(array $ratingCounts) |
|
105 | + { |
|
106 | + return floatval(apply_filters('site-reviews/rating/ranking', |
|
107 | + $this->getRankingUsingImdb($ratingCounts), |
|
108 | + $ratingCounts, |
|
109 | + $this |
|
110 | + )); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Get the bayesian ranking for an array of reviews |
|
115 | - * This formula is the same one used by IMDB to rank their top 250 films. |
|
116 | - * @see https://www.xkcd.com/937/ |
|
117 | - * @see https://districtdatalabs.silvrback.com/computing-a-bayesian-estimate-of-star-rating-means |
|
118 | - * @see http://fulmicoton.com/posts/bayesian_rating/ |
|
119 | - * @see https://stats.stackexchange.com/questions/93974/is-there-an-equivalent-to-lower-bound-of-wilson-score-confidence-interval-for-va |
|
120 | - * @param int $confidencePercentage |
|
121 | - * @return int|float |
|
122 | - */ |
|
123 | - public function getRankingUsingImdb(array $ratingCounts, $confidencePercentage = 70) |
|
124 | - { |
|
125 | - $avgRating = $this->getAverage($ratingCounts); |
|
126 | - // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error. |
|
127 | - // This could also be the average score of all items instead of a fixed value. |
|
128 | - $bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5 |
|
129 | - // Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior. |
|
130 | - $bayesMinimal = 10; // confidence |
|
131 | - $numOfReviews = array_sum($ratingCounts); |
|
132 | - return $avgRating > 0 |
|
133 | - ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews) |
|
134 | - : 0; |
|
135 | - } |
|
113 | + /** |
|
114 | + * Get the bayesian ranking for an array of reviews |
|
115 | + * This formula is the same one used by IMDB to rank their top 250 films. |
|
116 | + * @see https://www.xkcd.com/937/ |
|
117 | + * @see https://districtdatalabs.silvrback.com/computing-a-bayesian-estimate-of-star-rating-means |
|
118 | + * @see http://fulmicoton.com/posts/bayesian_rating/ |
|
119 | + * @see https://stats.stackexchange.com/questions/93974/is-there-an-equivalent-to-lower-bound-of-wilson-score-confidence-interval-for-va |
|
120 | + * @param int $confidencePercentage |
|
121 | + * @return int|float |
|
122 | + */ |
|
123 | + public function getRankingUsingImdb(array $ratingCounts, $confidencePercentage = 70) |
|
124 | + { |
|
125 | + $avgRating = $this->getAverage($ratingCounts); |
|
126 | + // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error. |
|
127 | + // This could also be the average score of all items instead of a fixed value. |
|
128 | + $bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5 |
|
129 | + // Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior. |
|
130 | + $bayesMinimal = 10; // confidence |
|
131 | + $numOfReviews = array_sum($ratingCounts); |
|
132 | + return $avgRating > 0 |
|
133 | + ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews) |
|
134 | + : 0; |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * The quality of a 5 star rating depends not only on the average number of stars but also on |
|
139 | - * the number of reviews. This method calculates the bayesian ranking of a page by its number |
|
140 | - * of reviews and their rating. |
|
141 | - * @see http://www.evanmiller.org/ranking-items-with-star-ratings.html |
|
142 | - * @see https://stackoverflow.com/questions/1411199/what-is-a-better-way-to-sort-by-a-5-star-rating/1411268 |
|
143 | - * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html |
|
144 | - * @param int $confidencePercentage |
|
145 | - * @return float |
|
146 | - */ |
|
147 | - public function getRankingUsingZScores(array $ratingCounts, $confidencePercentage = 90) |
|
148 | - { |
|
149 | - $ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__); |
|
150 | - $weight = $this->getWeight($ratingCounts, $ratingCountsSum); |
|
151 | - $weightPow2 = $this->getWeight($ratingCounts, $ratingCountsSum, true); |
|
152 | - $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
|
153 | - return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1)); |
|
154 | - } |
|
137 | + /** |
|
138 | + * The quality of a 5 star rating depends not only on the average number of stars but also on |
|
139 | + * the number of reviews. This method calculates the bayesian ranking of a page by its number |
|
140 | + * of reviews and their rating. |
|
141 | + * @see http://www.evanmiller.org/ranking-items-with-star-ratings.html |
|
142 | + * @see https://stackoverflow.com/questions/1411199/what-is-a-better-way-to-sort-by-a-5-star-rating/1411268 |
|
143 | + * @see http://julesjacobs.github.io/2015/08/17/bayesian-scoring-of-ratings.html |
|
144 | + * @param int $confidencePercentage |
|
145 | + * @return float |
|
146 | + */ |
|
147 | + public function getRankingUsingZScores(array $ratingCounts, $confidencePercentage = 90) |
|
148 | + { |
|
149 | + $ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__); |
|
150 | + $weight = $this->getWeight($ratingCounts, $ratingCountsSum); |
|
151 | + $weightPow2 = $this->getWeight($ratingCounts, $ratingCountsSum, true); |
|
152 | + $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
|
153 | + return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1)); |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * @param int $target |
|
158 | - * @return array |
|
159 | - */ |
|
160 | - protected function getRoundedPercentages(array $percentages, $totalPercent = 100) |
|
161 | - { |
|
162 | - array_walk($percentages, function (&$percent, $index) { |
|
163 | - $percent = [ |
|
164 | - 'index' => $index, |
|
165 | - 'percent' => floor($percent), |
|
166 | - 'remainder' => fmod($percent, 1), |
|
167 | - ]; |
|
168 | - }); |
|
169 | - $indexes = glsr_array_column($percentages, 'index'); |
|
170 | - $remainders = glsr_array_column($percentages, 'remainder'); |
|
171 | - array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages); |
|
172 | - $i = 0; |
|
173 | - if (array_sum(glsr_array_column($percentages, 'percent')) > 0) { |
|
174 | - while (array_sum(glsr_array_column($percentages, 'percent')) < $totalPercent) { |
|
175 | - ++$percentages[$i]['percent']; |
|
176 | - ++$i; |
|
177 | - } |
|
178 | - } |
|
179 | - array_multisort($indexes, SORT_DESC, $percentages); |
|
180 | - return array_combine($indexes, glsr_array_column($percentages, 'percent')); |
|
181 | - } |
|
156 | + /** |
|
157 | + * @param int $target |
|
158 | + * @return array |
|
159 | + */ |
|
160 | + protected function getRoundedPercentages(array $percentages, $totalPercent = 100) |
|
161 | + { |
|
162 | + array_walk($percentages, function (&$percent, $index) { |
|
163 | + $percent = [ |
|
164 | + 'index' => $index, |
|
165 | + 'percent' => floor($percent), |
|
166 | + 'remainder' => fmod($percent, 1), |
|
167 | + ]; |
|
168 | + }); |
|
169 | + $indexes = glsr_array_column($percentages, 'index'); |
|
170 | + $remainders = glsr_array_column($percentages, 'remainder'); |
|
171 | + array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages); |
|
172 | + $i = 0; |
|
173 | + if (array_sum(glsr_array_column($percentages, 'percent')) > 0) { |
|
174 | + while (array_sum(glsr_array_column($percentages, 'percent')) < $totalPercent) { |
|
175 | + ++$percentages[$i]['percent']; |
|
176 | + ++$i; |
|
177 | + } |
|
178 | + } |
|
179 | + array_multisort($indexes, SORT_DESC, $percentages); |
|
180 | + return array_combine($indexes, glsr_array_column($percentages, 'percent')); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * @return int |
|
185 | - */ |
|
186 | - protected function getTotalSum(array $ratingCounts) |
|
187 | - { |
|
188 | - return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) { |
|
189 | - return $carry + ($index * $ratingCounts[$index]); |
|
190 | - }); |
|
191 | - } |
|
183 | + /** |
|
184 | + * @return int |
|
185 | + */ |
|
186 | + protected function getTotalSum(array $ratingCounts) |
|
187 | + { |
|
188 | + return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) { |
|
189 | + return $carry + ($index * $ratingCounts[$index]); |
|
190 | + }); |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * @param int|float $ratingCountsSum |
|
195 | - * @param bool $powerOf2 |
|
196 | - * @return float |
|
197 | - */ |
|
198 | - protected function getWeight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false) |
|
199 | - { |
|
200 | - return array_reduce(array_keys($ratingCounts), |
|
201 | - function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) { |
|
202 | - $ratingLevel = $powerOf2 |
|
203 | - ? pow($rating, 2) |
|
204 | - : $rating; |
|
205 | - return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum; |
|
206 | - } |
|
207 | - ); |
|
208 | - } |
|
193 | + /** |
|
194 | + * @param int|float $ratingCountsSum |
|
195 | + * @param bool $powerOf2 |
|
196 | + * @return float |
|
197 | + */ |
|
198 | + protected function getWeight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false) |
|
199 | + { |
|
200 | + return array_reduce(array_keys($ratingCounts), |
|
201 | + function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) { |
|
202 | + $ratingLevel = $powerOf2 |
|
203 | + ? pow($rating, 2) |
|
204 | + : $rating; |
|
205 | + return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum; |
|
206 | + } |
|
207 | + ); |
|
208 | + } |
|
209 | 209 | } |
@@ -45,13 +45,13 @@ discard block |
||
45 | 45 | * @param int $roundBy |
46 | 46 | * @return float |
47 | 47 | */ |
48 | - public function getAverage(array $ratingCounts, $roundBy = 1) |
|
48 | + public function getAverage( array $ratingCounts, $roundBy = 1 ) |
|
49 | 49 | { |
50 | - $average = array_sum($ratingCounts); |
|
51 | - if ($average > 0) { |
|
52 | - $average = round($this->getTotalSum($ratingCounts) / $average, intval($roundBy)); |
|
50 | + $average = array_sum( $ratingCounts ); |
|
51 | + if( $average > 0 ) { |
|
52 | + $average = round( $this->getTotalSum( $ratingCounts ) / $average, intval( $roundBy ) ); |
|
53 | 53 | } |
54 | - return floatval(apply_filters('site-reviews/rating/average', $average, $ratingCounts)); |
|
54 | + return floatval( apply_filters( 'site-reviews/rating/average', $average, $ratingCounts ) ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -64,50 +64,50 @@ discard block |
||
64 | 64 | * @param int $confidencePercentage |
65 | 65 | * @return int|float |
66 | 66 | */ |
67 | - public function getLowerBound(array $upDownCounts = [0, 0], $confidencePercentage = 95) |
|
67 | + public function getLowerBound( array $upDownCounts = [0, 0], $confidencePercentage = 95 ) |
|
68 | 68 | { |
69 | - $numRatings = array_sum($upDownCounts); |
|
70 | - if ($numRatings < 1) { |
|
69 | + $numRatings = array_sum( $upDownCounts ); |
|
70 | + if( $numRatings < 1 ) { |
|
71 | 71 | return 0; |
72 | 72 | } |
73 | 73 | $z = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
74 | 74 | $phat = 1 * $upDownCounts[1] / $numRatings; |
75 | - return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings)) / (1 + $z * $z / $numRatings); |
|
75 | + return ($phat + $z * $z / (2 * $numRatings) - $z * sqrt( ($phat * (1 - $phat) + $z * $z / (4 * $numRatings)) / $numRatings )) / (1 + $z * $z / $numRatings); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @return int|float |
80 | 80 | */ |
81 | - public function getOverallPercentage(array $ratingCounts) |
|
81 | + public function getOverallPercentage( array $ratingCounts ) |
|
82 | 82 | { |
83 | - return round($this->getAverage($ratingCounts) * 100 / glsr()->constant('MAX_RATING', __CLASS__), 2); |
|
83 | + return round( $this->getAverage( $ratingCounts ) * 100 / glsr()->constant( 'MAX_RATING', __CLASS__ ), 2 ); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
87 | 87 | * @return array |
88 | 88 | */ |
89 | - public function getPercentages(array $ratingCounts) |
|
89 | + public function getPercentages( array $ratingCounts ) |
|
90 | 90 | { |
91 | - $total = array_sum($ratingCounts); |
|
92 | - foreach ($ratingCounts as $index => $count) { |
|
93 | - if (empty($count)) { |
|
91 | + $total = array_sum( $ratingCounts ); |
|
92 | + foreach( $ratingCounts as $index => $count ) { |
|
93 | + if( empty($count) ) { |
|
94 | 94 | continue; |
95 | 95 | } |
96 | 96 | $ratingCounts[$index] = $count / $total * 100; |
97 | 97 | } |
98 | - return $this->getRoundedPercentages($ratingCounts); |
|
98 | + return $this->getRoundedPercentages( $ratingCounts ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
102 | 102 | * @return float |
103 | 103 | */ |
104 | - public function getRanking(array $ratingCounts) |
|
104 | + public function getRanking( array $ratingCounts ) |
|
105 | 105 | { |
106 | - return floatval(apply_filters('site-reviews/rating/ranking', |
|
107 | - $this->getRankingUsingImdb($ratingCounts), |
|
106 | + return floatval( apply_filters( 'site-reviews/rating/ranking', |
|
107 | + $this->getRankingUsingImdb( $ratingCounts ), |
|
108 | 108 | $ratingCounts, |
109 | 109 | $this |
110 | - )); |
|
110 | + ) ); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -120,15 +120,15 @@ discard block |
||
120 | 120 | * @param int $confidencePercentage |
121 | 121 | * @return int|float |
122 | 122 | */ |
123 | - public function getRankingUsingImdb(array $ratingCounts, $confidencePercentage = 70) |
|
123 | + public function getRankingUsingImdb( array $ratingCounts, $confidencePercentage = 70 ) |
|
124 | 124 | { |
125 | - $avgRating = $this->getAverage($ratingCounts); |
|
125 | + $avgRating = $this->getAverage( $ratingCounts ); |
|
126 | 126 | // Represents a prior (your prior opinion without data) for the average star rating. A higher prior also means a higher margin for error. |
127 | 127 | // This could also be the average score of all items instead of a fixed value. |
128 | - $bayesMean = ($confidencePercentage / 100) * glsr()->constant('MAX_RATING', __CLASS__); // prior, 70% = 3.5 |
|
128 | + $bayesMean = ($confidencePercentage / 100) * glsr()->constant( 'MAX_RATING', __CLASS__ ); // prior, 70% = 3.5 |
|
129 | 129 | // Represents the number of ratings expected to begin observing a pattern that would put confidence in the prior. |
130 | 130 | $bayesMinimal = 10; // confidence |
131 | - $numOfReviews = array_sum($ratingCounts); |
|
131 | + $numOfReviews = array_sum( $ratingCounts ); |
|
132 | 132 | return $avgRating > 0 |
133 | 133 | ? (($bayesMinimal * $bayesMean) + ($avgRating * $numOfReviews)) / ($bayesMinimal + $numOfReviews) |
134 | 134 | : 0; |
@@ -144,48 +144,48 @@ discard block |
||
144 | 144 | * @param int $confidencePercentage |
145 | 145 | * @return float |
146 | 146 | */ |
147 | - public function getRankingUsingZScores(array $ratingCounts, $confidencePercentage = 90) |
|
147 | + public function getRankingUsingZScores( array $ratingCounts, $confidencePercentage = 90 ) |
|
148 | 148 | { |
149 | - $ratingCountsSum = array_sum($ratingCounts) + glsr()->constant('MAX_RATING', __CLASS__); |
|
150 | - $weight = $this->getWeight($ratingCounts, $ratingCountsSum); |
|
151 | - $weightPow2 = $this->getWeight($ratingCounts, $ratingCountsSum, true); |
|
149 | + $ratingCountsSum = array_sum( $ratingCounts ) + glsr()->constant( 'MAX_RATING', __CLASS__ ); |
|
150 | + $weight = $this->getWeight( $ratingCounts, $ratingCountsSum ); |
|
151 | + $weightPow2 = $this->getWeight( $ratingCounts, $ratingCountsSum, true ); |
|
152 | 152 | $zScore = static::CONFIDENCE_LEVEL_Z_SCORES[$confidencePercentage]; |
153 | - return $weight - $zScore * sqrt(($weightPow2 - pow($weight, 2)) / ($ratingCountsSum + 1)); |
|
153 | + return $weight - $zScore * sqrt( ($weightPow2 - pow( $weight, 2 )) / ($ratingCountsSum + 1) ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
157 | 157 | * @param int $target |
158 | 158 | * @return array |
159 | 159 | */ |
160 | - protected function getRoundedPercentages(array $percentages, $totalPercent = 100) |
|
160 | + protected function getRoundedPercentages( array $percentages, $totalPercent = 100 ) |
|
161 | 161 | { |
162 | - array_walk($percentages, function (&$percent, $index) { |
|
162 | + array_walk( $percentages, function( &$percent, $index ) { |
|
163 | 163 | $percent = [ |
164 | 164 | 'index' => $index, |
165 | - 'percent' => floor($percent), |
|
166 | - 'remainder' => fmod($percent, 1), |
|
165 | + 'percent' => floor( $percent ), |
|
166 | + 'remainder' => fmod( $percent, 1 ), |
|
167 | 167 | ]; |
168 | 168 | }); |
169 | - $indexes = glsr_array_column($percentages, 'index'); |
|
170 | - $remainders = glsr_array_column($percentages, 'remainder'); |
|
171 | - array_multisort($remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages); |
|
169 | + $indexes = glsr_array_column( $percentages, 'index' ); |
|
170 | + $remainders = glsr_array_column( $percentages, 'remainder' ); |
|
171 | + array_multisort( $remainders, SORT_DESC, SORT_STRING, $indexes, SORT_DESC, $percentages ); |
|
172 | 172 | $i = 0; |
173 | - if (array_sum(glsr_array_column($percentages, 'percent')) > 0) { |
|
174 | - while (array_sum(glsr_array_column($percentages, 'percent')) < $totalPercent) { |
|
173 | + if( array_sum( glsr_array_column( $percentages, 'percent' ) ) > 0 ) { |
|
174 | + while( array_sum( glsr_array_column( $percentages, 'percent' ) ) < $totalPercent ) { |
|
175 | 175 | ++$percentages[$i]['percent']; |
176 | 176 | ++$i; |
177 | 177 | } |
178 | 178 | } |
179 | - array_multisort($indexes, SORT_DESC, $percentages); |
|
180 | - return array_combine($indexes, glsr_array_column($percentages, 'percent')); |
|
179 | + array_multisort( $indexes, SORT_DESC, $percentages ); |
|
180 | + return array_combine( $indexes, glsr_array_column( $percentages, 'percent' ) ); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
184 | 184 | * @return int |
185 | 185 | */ |
186 | - protected function getTotalSum(array $ratingCounts) |
|
186 | + protected function getTotalSum( array $ratingCounts ) |
|
187 | 187 | { |
188 | - return array_reduce(array_keys($ratingCounts), function ($carry, $index) use ($ratingCounts) { |
|
188 | + return array_reduce( array_keys( $ratingCounts ), function( $carry, $index ) use ($ratingCounts) { |
|
189 | 189 | return $carry + ($index * $ratingCounts[$index]); |
190 | 190 | }); |
191 | 191 | } |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | * @param bool $powerOf2 |
196 | 196 | * @return float |
197 | 197 | */ |
198 | - protected function getWeight(array $ratingCounts, $ratingCountsSum, $powerOf2 = false) |
|
198 | + protected function getWeight( array $ratingCounts, $ratingCountsSum, $powerOf2 = false ) |
|
199 | 199 | { |
200 | - return array_reduce(array_keys($ratingCounts), |
|
201 | - function ($count, $rating) use ($ratingCounts, $ratingCountsSum, $powerOf2) { |
|
200 | + return array_reduce( array_keys( $ratingCounts ), |
|
201 | + function( $count, $rating ) use ($ratingCounts, $ratingCountsSum, $powerOf2) { |
|
202 | 202 | $ratingLevel = $powerOf2 |
203 | - ? pow($rating, 2) |
|
203 | + ? pow( $rating, 2 ) |
|
204 | 204 | : $rating; |
205 | 205 | return $count + ($ratingLevel * ($ratingCounts[$rating] + 1)) / $ratingCountsSum; |
206 | 206 | } |
@@ -7,40 +7,40 @@ |
||
7 | 7 | |
8 | 8 | class EmailDefaults extends Defaults |
9 | 9 | { |
10 | - /** |
|
11 | - * @return array |
|
12 | - */ |
|
13 | - protected function defaults() |
|
14 | - { |
|
15 | - return [ |
|
16 | - 'after' => '', |
|
17 | - 'attachments' => [], |
|
18 | - 'bcc' => '', |
|
19 | - 'before' => '', |
|
20 | - 'cc' => '', |
|
21 | - 'from' => $this->getFromName().' <'.$this->getFromEmail().'>', |
|
22 | - 'message' => '', |
|
23 | - 'reply-to' => '', |
|
24 | - 'subject' => '', |
|
25 | - 'template' => '', |
|
26 | - 'template-tags' => [], |
|
27 | - 'to' => '', |
|
28 | - ]; |
|
29 | - } |
|
10 | + /** |
|
11 | + * @return array |
|
12 | + */ |
|
13 | + protected function defaults() |
|
14 | + { |
|
15 | + return [ |
|
16 | + 'after' => '', |
|
17 | + 'attachments' => [], |
|
18 | + 'bcc' => '', |
|
19 | + 'before' => '', |
|
20 | + 'cc' => '', |
|
21 | + 'from' => $this->getFromName().' <'.$this->getFromEmail().'>', |
|
22 | + 'message' => '', |
|
23 | + 'reply-to' => '', |
|
24 | + 'subject' => '', |
|
25 | + 'template' => '', |
|
26 | + 'template-tags' => [], |
|
27 | + 'to' => '', |
|
28 | + ]; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - protected function getFromEmail() |
|
35 | - { |
|
36 | - return glsr(OptionManager::class)->getWP('admin_email'); |
|
37 | - } |
|
31 | + /** |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + protected function getFromEmail() |
|
35 | + { |
|
36 | + return glsr(OptionManager::class)->getWP('admin_email'); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - protected function getFromName() |
|
43 | - { |
|
44 | - return wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES); |
|
45 | - } |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + protected function getFromName() |
|
43 | + { |
|
44 | + return wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES); |
|
45 | + } |
|
46 | 46 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | protected function getFromEmail() |
35 | 35 | { |
36 | - return glsr(OptionManager::class)->getWP('admin_email'); |
|
36 | + return glsr( OptionManager::class )->getWP( 'admin_email' ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -41,6 +41,6 @@ discard block |
||
41 | 41 | */ |
42 | 42 | protected function getFromName() |
43 | 43 | { |
44 | - return wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES); |
|
44 | + return wp_specialchars_decode( glsr( OptionManager::class )->getWP( 'blogname' ), ENT_QUOTES ); |
|
45 | 45 | } |
46 | 46 | } |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <p class="about-description">We think you'll love the changes in this new release!</p> |
4 | 4 | <div class="is-fullwidth"> |
@@ -1,23 +1,23 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <div class="glsr-welcome wrap about-wrap about-wrap-content"> |
4 | 4 | <h1>Welcome to <?= glsr()->name; ?></h1> |
5 | 5 | <div class="about-text">Site Reviews is a free WordPress review plugin with advanced features that makes it easy to manage reviews on your website. Follow the instructions below to get started!</div> |
6 | 6 | <div class="wp-badge">Version <?= glsr()->version; ?></div> |
7 | 7 | <p class="about-buttons"> |
8 | - <a class="button" href="<?= admin_url('edit.php?post_type=site-review&page=documentation'); ?>">Documentation</a> |
|
8 | + <a class="button" href="<?= admin_url( 'edit.php?post_type=site-review&page=documentation' ); ?>">Documentation</a> |
|
9 | 9 | <a class="button" href="https://wordpress.org/support/plugin/site-reviews/">Support</a> |
10 | 10 | <a target="_blank" class="button" href="https://www.facebook.com/sharer/sharer.php?u=https%3A//geminilabs.io/site-reviews"><span class="dashicons dashicons-facebook-alt"></span> Share</a> |
11 | 11 | <a target="_blank" class="button" href="https://twitter.com/intent/tweet?text=Site Reviews is a fantastic WordPress review plugin with advanced features that makes it easy to manage reviews on your website.&url=https://geminilabs.io/site-reviews&hashtags=WordPress,reviewplugins,"><span class="dashicons dashicons-twitter"></span> Tweet</a> |
12 | 12 | </p> |
13 | 13 | <nav class="glsr-nav-tab-wrapper nav-tab-wrapper"> |
14 | - <?php foreach ($tabs as $id => $title) : ?> |
|
14 | + <?php foreach( $tabs as $id => $title ) : ?> |
|
15 | 15 | <a class="glsr-nav-tab nav-tab" href="#<?= $id; ?>"><?= $title; ?></a> |
16 | 16 | <?php endforeach; ?> |
17 | 17 | </nav> |
18 | - <?php foreach ($tabs as $id => $title) : ?> |
|
18 | + <?php foreach( $tabs as $id => $title ) : ?> |
|
19 | 19 | <div class="glsr-nav-view ui-tabs-hide" id="<?= $id; ?>"> |
20 | - <?php $template->render('pages/welcome/'.$id, $data); ?> |
|
20 | + <?php $template->render( 'pages/welcome/'.$id, $data ); ?> |
|
21 | 21 | </div> |
22 | 22 | <?php endforeach; ?> |
23 | 23 | <input type="hidden" name="_active_tab"> |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <p>Hooks (also known as <a href="https://developer.wordpress.org/plugins/hooks/index.html">Actions and Filters</a>) are used in your theme's <code>functions.php</code> file to make changes to the plugin.</p> |
4 | 4 | |
@@ -6,13 +6,13 @@ discard block |
||
6 | 6 | <div class="glsr-card-header"> |
7 | 7 | <h3>Customise the order of the fields in the review submission form</h3> |
8 | 8 | <button type="button" class="handlediv" aria-expanded="true"> |
9 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
9 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
10 | 10 | <span class="toggle-indicator" aria-hidden="true"></span> |
11 | 11 | </button> |
12 | 12 | </div> |
13 | 13 | <div class="inside"> |
14 | 14 | <p>Use this hook to customise the order of the fields in the review submission form used by Site Reviews.</p> |
15 | - <p>See the <code><a data-expand="#faq-07" href="<?= admin_url('edit.php?post_type=site-review&page=documentation#!faq'); ?>">FAQ</a></code> for a detailed example of how to use this hook.</p> |
|
15 | + <p>See the <code><a data-expand="#faq-07" href="<?= admin_url( 'edit.php?post_type=site-review&page=documentation#!faq' ); ?>">FAQ</a></code> for a detailed example of how to use this hook.</p> |
|
16 | 16 | <pre><code class="php">/** |
17 | 17 | * Customises the order of the fields used in the Site Reviews submission form. |
18 | 18 | * Paste this in your active theme's functions.php file. |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | <div class="glsr-card-header"> |
31 | 31 | <h3>Customise the star images</h3> |
32 | 32 | <button type="button" class="handlediv" aria-expanded="true"> |
33 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
33 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
34 | 34 | <span class="toggle-indicator" aria-hidden="true"></span> |
35 | 35 | </button> |
36 | 36 | </div> |
37 | 37 | <div class="inside"> |
38 | 38 | <p>Use this hook to customise the star images used by Site Reviews.</p> |
39 | - <p>See the <code><a data-expand="#faq-11" href="<?= admin_url('edit.php?post_type=site-review&page=documentation#!faq'); ?>">FAQ</a></code> for a detailed example of how to use this hook.</p> |
|
39 | + <p>See the <code><a data-expand="#faq-11" href="<?= admin_url( 'edit.php?post_type=site-review&page=documentation#!faq' ); ?>">FAQ</a></code> for a detailed example of how to use this hook.</p> |
|
40 | 40 | <pre><code class="php">/** |
41 | 41 | * Customises the stars used by Site Reviews. |
42 | 42 | * Paste this in your active theme's functions.php file. |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | <div class="glsr-card-header"> |
55 | 55 | <h3>Disable the plugin javascript</h3> |
56 | 56 | <button type="button" class="handlediv" aria-expanded="true"> |
57 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
57 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
58 | 58 | <span class="toggle-indicator" aria-hidden="true"></span> |
59 | 59 | </button> |
60 | 60 | </div> |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | <div class="glsr-card-header"> |
74 | 74 | <h3>Disable the plugin stylesheet</h3> |
75 | 75 | <button type="button" class="handlediv" aria-expanded="true"> |
76 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
76 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
77 | 77 | <span class="toggle-indicator" aria-hidden="true"></span> |
78 | 78 | </button> |
79 | 79 | </div> |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | <div class="glsr-card-header"> |
93 | 93 | <h3>Disable the polyfill.io script</h3> |
94 | 94 | <button type="button" class="handlediv" aria-expanded="true"> |
95 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
95 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
96 | 96 | <span class="toggle-indicator" aria-hidden="true"></span> |
97 | 97 | </button> |
98 | 98 | </div> |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | <div class="glsr-card-header"> |
113 | 113 | <h3>Do something immediately after a review has been submitted</h3> |
114 | 114 | <button type="button" class="handlediv" aria-expanded="true"> |
115 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
115 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
116 | 116 | <span class="toggle-indicator" aria-hidden="true"></span> |
117 | 117 | </button> |
118 | 118 | </div> |
@@ -136,14 +136,14 @@ discard block |
||
136 | 136 | <div class="glsr-card-header"> |
137 | 137 | <h3>Modify the schema</h3> |
138 | 138 | <button type="button" class="handlediv" aria-expanded="true"> |
139 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
139 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
140 | 140 | <span class="toggle-indicator" aria-hidden="true"></span> |
141 | 141 | </button> |
142 | 142 | </div> |
143 | 143 | <div class="inside"> |
144 | 144 | <p>Use this hook if you would like to modify the schema type properties.</p> |
145 | 145 | <p>This hook is specific to the schema type. For example, to modify the schema properties for the LocalBusiness schema type you would use the <code>site-reviews/schema/LocalBusiness</code> hook, but to modify the schema properties for the Product schema type you would use the <code>site-reviews/schema/Product</code> hook.</p> |
146 | - <p>See the <code><a data-expand="#faq-01" href="<?= admin_url('edit.php?post_type=site-review&page=documentation#!faq'); ?>">FAQ</a></code> for a detailed example of how to use this hook.</p> |
|
146 | + <p>See the <code><a data-expand="#faq-01" href="<?= admin_url( 'edit.php?post_type=site-review&page=documentation#!faq' ); ?>">FAQ</a></code> for a detailed example of how to use this hook.</p> |
|
147 | 147 | <p>Make sure to use Google's <a href="https://search.google.com/structured-data/testing-tool">Structured Data Testing Tool</a> to test the schema after any custom modifications have been made.</p> |
148 | 148 | <pre><code class="php">/** |
149 | 149 | * Modifies the properties of the schema created by Site Reviews. |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | <div class="glsr-card-header"> |
164 | 164 | <h3>Modify the submitted review before it is saved</h3> |
165 | 165 | <button type="button" class="handlediv" aria-expanded="true"> |
166 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
166 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
167 | 167 | <span class="toggle-indicator" aria-hidden="true"></span> |
168 | 168 | </button> |
169 | 169 | </div> |
@@ -1,7 +1,7 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | -<p><?= __('The JSON-LD schema is disabled by default. To use it, please enable the option in your blocks or shortcodes. The schema appears in Google\'s search results and shows the star rating and other information about your reviews. If the schema has been enabled, you can use Google\'s <a href="https://search.google.com/structured-data/testing-tool">Structured Data Testing Tool</a> to test your pages for valid schema data.', 'site-reviews'); ?></p> |
|
4 | -<p><?= __('You may override any of these options on a per-post/page basis by using its Custom Field name and adding a custom value using the <a href="https://codex.wordpress.org/Using_Custom_Fields#Usage">Custom Fields</a> metabox.', 'site-reviews'); ?></p> |
|
3 | +<p><?= __( 'The JSON-LD schema is disabled by default. To use it, please enable the option in your blocks or shortcodes. The schema appears in Google\'s search results and shows the star rating and other information about your reviews. If the schema has been enabled, you can use Google\'s <a href="https://search.google.com/structured-data/testing-tool">Structured Data Testing Tool</a> to test your pages for valid schema data.', 'site-reviews' ); ?></p> |
|
4 | +<p><?= __( 'You may override any of these options on a per-post/page basis by using its Custom Field name and adding a custom value using the <a href="https://codex.wordpress.org/Using_Custom_Fields#Usage">Custom Fields</a> metabox.', 'site-reviews' ); ?></p> |
|
5 | 5 | <table class="form-table"> |
6 | 6 | <tbody> |
7 | 7 | {{ rows }} |
@@ -10,94 +10,94 @@ |
||
10 | 10 | |
11 | 11 | class MainController extends Controller |
12 | 12 | { |
13 | - /** |
|
14 | - * @return void |
|
15 | - * @action init |
|
16 | - */ |
|
17 | - public function registerPostType() |
|
18 | - { |
|
19 | - if (!glsr()->hasPermission()) { |
|
20 | - return; |
|
21 | - } |
|
22 | - $command = new RegisterPostType([ |
|
23 | - 'capabilities' => ['create_posts' => 'create_'.Application::POST_TYPE], |
|
24 | - 'columns' => [ |
|
25 | - 'title' => '', |
|
26 | - 'category' => '', |
|
27 | - 'assigned_to' => __('Assigned To', 'site-reviews'), |
|
28 | - 'reviewer' => __('Author', 'site-reviews'), |
|
29 | - 'review_type' => __('Type', 'site-reviews'), |
|
30 | - 'rating' => __('Rating', 'site-reviews'), |
|
31 | - 'pinned' => __('Pinned', 'site-reviews'), |
|
32 | - 'date' => '', |
|
33 | - ], |
|
34 | - 'menu_icon' => 'dashicons-star-half', |
|
35 | - 'menu_name' => glsr()->name, |
|
36 | - 'map_meta_cap' => true, |
|
37 | - 'plural' => __('Reviews', 'site-reviews'), |
|
38 | - 'post_type' => Application::POST_TYPE, |
|
39 | - 'rest_controller_class' => RestReviewController::class, |
|
40 | - 'show_in_rest' => true, |
|
41 | - 'single' => __('Review', 'site-reviews'), |
|
42 | - ]); |
|
43 | - $this->execute($command); |
|
44 | - } |
|
13 | + /** |
|
14 | + * @return void |
|
15 | + * @action init |
|
16 | + */ |
|
17 | + public function registerPostType() |
|
18 | + { |
|
19 | + if (!glsr()->hasPermission()) { |
|
20 | + return; |
|
21 | + } |
|
22 | + $command = new RegisterPostType([ |
|
23 | + 'capabilities' => ['create_posts' => 'create_'.Application::POST_TYPE], |
|
24 | + 'columns' => [ |
|
25 | + 'title' => '', |
|
26 | + 'category' => '', |
|
27 | + 'assigned_to' => __('Assigned To', 'site-reviews'), |
|
28 | + 'reviewer' => __('Author', 'site-reviews'), |
|
29 | + 'review_type' => __('Type', 'site-reviews'), |
|
30 | + 'rating' => __('Rating', 'site-reviews'), |
|
31 | + 'pinned' => __('Pinned', 'site-reviews'), |
|
32 | + 'date' => '', |
|
33 | + ], |
|
34 | + 'menu_icon' => 'dashicons-star-half', |
|
35 | + 'menu_name' => glsr()->name, |
|
36 | + 'map_meta_cap' => true, |
|
37 | + 'plural' => __('Reviews', 'site-reviews'), |
|
38 | + 'post_type' => Application::POST_TYPE, |
|
39 | + 'rest_controller_class' => RestReviewController::class, |
|
40 | + 'show_in_rest' => true, |
|
41 | + 'single' => __('Review', 'site-reviews'), |
|
42 | + ]); |
|
43 | + $this->execute($command); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return void |
|
48 | - * @action init |
|
49 | - */ |
|
50 | - public function registerShortcodes() |
|
51 | - { |
|
52 | - $command = new RegisterShortcodes([ |
|
53 | - 'site_reviews', |
|
54 | - 'site_reviews_form', |
|
55 | - 'site_reviews_summary', |
|
56 | - ]); |
|
57 | - $this->execute($command); |
|
58 | - } |
|
46 | + /** |
|
47 | + * @return void |
|
48 | + * @action init |
|
49 | + */ |
|
50 | + public function registerShortcodes() |
|
51 | + { |
|
52 | + $command = new RegisterShortcodes([ |
|
53 | + 'site_reviews', |
|
54 | + 'site_reviews_form', |
|
55 | + 'site_reviews_summary', |
|
56 | + ]); |
|
57 | + $this->execute($command); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return void |
|
62 | - * @action init |
|
63 | - */ |
|
64 | - public function registerTaxonomy() |
|
65 | - { |
|
66 | - $command = new RegisterTaxonomy([ |
|
67 | - 'hierarchical' => true, |
|
68 | - 'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'], |
|
69 | - 'public' => false, |
|
70 | - 'rest_controller_class' => RestCategoryController::class, |
|
71 | - 'show_admin_column' => true, |
|
72 | - 'show_in_rest' => true, |
|
73 | - 'show_ui' => true, |
|
74 | - ]); |
|
75 | - $this->execute($command); |
|
76 | - } |
|
60 | + /** |
|
61 | + * @return void |
|
62 | + * @action init |
|
63 | + */ |
|
64 | + public function registerTaxonomy() |
|
65 | + { |
|
66 | + $command = new RegisterTaxonomy([ |
|
67 | + 'hierarchical' => true, |
|
68 | + 'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'], |
|
69 | + 'public' => false, |
|
70 | + 'rest_controller_class' => RestCategoryController::class, |
|
71 | + 'show_admin_column' => true, |
|
72 | + 'show_in_rest' => true, |
|
73 | + 'show_ui' => true, |
|
74 | + ]); |
|
75 | + $this->execute($command); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return void |
|
80 | - * @action widgets_init |
|
81 | - */ |
|
82 | - public function registerWidgets() |
|
83 | - { |
|
84 | - $command = new RegisterWidgets([ |
|
85 | - 'site-reviews' => [ |
|
86 | - 'class' => 'glsr-widget glsr-widget-site-reviews', |
|
87 | - 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
88 | - 'title' => __('Recent Reviews', 'site-reviews'), |
|
89 | - ], |
|
90 | - 'site-reviews-form' => [ |
|
91 | - 'class' => 'glsr-widget glsr-widget-site-reviews-form', |
|
92 | - 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
93 | - 'title' => __('Submit a Review', 'site-reviews'), |
|
94 | - ], |
|
95 | - 'site-reviews-summary' => [ |
|
96 | - 'class' => 'glsr-widget glsr-widget-site-reviews-summary', |
|
97 | - 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
98 | - 'title' => __('Summary of Reviews', 'site-reviews'), |
|
99 | - ], |
|
100 | - ]); |
|
101 | - $this->execute($command); |
|
102 | - } |
|
78 | + /** |
|
79 | + * @return void |
|
80 | + * @action widgets_init |
|
81 | + */ |
|
82 | + public function registerWidgets() |
|
83 | + { |
|
84 | + $command = new RegisterWidgets([ |
|
85 | + 'site-reviews' => [ |
|
86 | + 'class' => 'glsr-widget glsr-widget-site-reviews', |
|
87 | + 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
88 | + 'title' => __('Recent Reviews', 'site-reviews'), |
|
89 | + ], |
|
90 | + 'site-reviews-form' => [ |
|
91 | + 'class' => 'glsr-widget glsr-widget-site-reviews-form', |
|
92 | + 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
93 | + 'title' => __('Submit a Review', 'site-reviews'), |
|
94 | + ], |
|
95 | + 'site-reviews-summary' => [ |
|
96 | + 'class' => 'glsr-widget glsr-widget-site-reviews-summary', |
|
97 | + 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
98 | + 'title' => __('Summary of Reviews', 'site-reviews'), |
|
99 | + ], |
|
100 | + ]); |
|
101 | + $this->execute($command); |
|
102 | + } |
|
103 | 103 | } |
@@ -16,31 +16,31 @@ discard block |
||
16 | 16 | */ |
17 | 17 | public function registerPostType() |
18 | 18 | { |
19 | - if (!glsr()->hasPermission()) { |
|
19 | + if( !glsr()->hasPermission() ) { |
|
20 | 20 | return; |
21 | 21 | } |
22 | - $command = new RegisterPostType([ |
|
22 | + $command = new RegisterPostType( [ |
|
23 | 23 | 'capabilities' => ['create_posts' => 'create_'.Application::POST_TYPE], |
24 | 24 | 'columns' => [ |
25 | 25 | 'title' => '', |
26 | 26 | 'category' => '', |
27 | - 'assigned_to' => __('Assigned To', 'site-reviews'), |
|
28 | - 'reviewer' => __('Author', 'site-reviews'), |
|
29 | - 'review_type' => __('Type', 'site-reviews'), |
|
30 | - 'rating' => __('Rating', 'site-reviews'), |
|
31 | - 'pinned' => __('Pinned', 'site-reviews'), |
|
27 | + 'assigned_to' => __( 'Assigned To', 'site-reviews' ), |
|
28 | + 'reviewer' => __( 'Author', 'site-reviews' ), |
|
29 | + 'review_type' => __( 'Type', 'site-reviews' ), |
|
30 | + 'rating' => __( 'Rating', 'site-reviews' ), |
|
31 | + 'pinned' => __( 'Pinned', 'site-reviews' ), |
|
32 | 32 | 'date' => '', |
33 | 33 | ], |
34 | 34 | 'menu_icon' => 'dashicons-star-half', |
35 | 35 | 'menu_name' => glsr()->name, |
36 | 36 | 'map_meta_cap' => true, |
37 | - 'plural' => __('Reviews', 'site-reviews'), |
|
37 | + 'plural' => __( 'Reviews', 'site-reviews' ), |
|
38 | 38 | 'post_type' => Application::POST_TYPE, |
39 | 39 | 'rest_controller_class' => RestReviewController::class, |
40 | 40 | 'show_in_rest' => true, |
41 | - 'single' => __('Review', 'site-reviews'), |
|
42 | - ]); |
|
43 | - $this->execute($command); |
|
41 | + 'single' => __( 'Review', 'site-reviews' ), |
|
42 | + ] ); |
|
43 | + $this->execute( $command ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -49,12 +49,12 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function registerShortcodes() |
51 | 51 | { |
52 | - $command = new RegisterShortcodes([ |
|
52 | + $command = new RegisterShortcodes( [ |
|
53 | 53 | 'site_reviews', |
54 | 54 | 'site_reviews_form', |
55 | 55 | 'site_reviews_summary', |
56 | - ]); |
|
57 | - $this->execute($command); |
|
56 | + ] ); |
|
57 | + $this->execute( $command ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,16 +63,16 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function registerTaxonomy() |
65 | 65 | { |
66 | - $command = new RegisterTaxonomy([ |
|
66 | + $command = new RegisterTaxonomy( [ |
|
67 | 67 | 'hierarchical' => true, |
68 | - 'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'], |
|
68 | + 'meta_box_cb' => [glsr( EditorController::class ), 'renderTaxonomyMetabox'], |
|
69 | 69 | 'public' => false, |
70 | 70 | 'rest_controller_class' => RestCategoryController::class, |
71 | 71 | 'show_admin_column' => true, |
72 | 72 | 'show_in_rest' => true, |
73 | 73 | 'show_ui' => true, |
74 | - ]); |
|
75 | - $this->execute($command); |
|
74 | + ] ); |
|
75 | + $this->execute( $command ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function registerWidgets() |
83 | 83 | { |
84 | - $command = new RegisterWidgets([ |
|
84 | + $command = new RegisterWidgets( [ |
|
85 | 85 | 'site-reviews' => [ |
86 | 86 | 'class' => 'glsr-widget glsr-widget-site-reviews', |
87 | - 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
88 | - 'title' => __('Recent Reviews', 'site-reviews'), |
|
87 | + 'description' => __( 'Site Reviews: Display your recent reviews.', 'site-reviews' ), |
|
88 | + 'title' => __( 'Recent Reviews', 'site-reviews' ), |
|
89 | 89 | ], |
90 | 90 | 'site-reviews-form' => [ |
91 | 91 | 'class' => 'glsr-widget glsr-widget-site-reviews-form', |
92 | - 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
93 | - 'title' => __('Submit a Review', 'site-reviews'), |
|
92 | + 'description' => __( 'Site Reviews: Display a form to submit reviews.', 'site-reviews' ), |
|
93 | + 'title' => __( 'Submit a Review', 'site-reviews' ), |
|
94 | 94 | ], |
95 | 95 | 'site-reviews-summary' => [ |
96 | 96 | 'class' => 'glsr-widget glsr-widget-site-reviews-summary', |
97 | - 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
98 | - 'title' => __('Summary of Reviews', 'site-reviews'), |
|
97 | + 'description' => __( 'Site Reviews: Display a summary of your reviews.', 'site-reviews' ), |
|
98 | + 'title' => __( 'Summary of Reviews', 'site-reviews' ), |
|
99 | 99 | ], |
100 | - ]); |
|
101 | - $this->execute($command); |
|
100 | + ] ); |
|
101 | + $this->execute( $command ); |
|
102 | 102 | } |
103 | 103 | } |