@@ -14,16 +14,16 @@ discard block |
||
| 14 | 14 | * @return array |
| 15 | 15 | * @callback register_setting |
| 16 | 16 | */ |
| 17 | - public function callbackRegisterSettings($input) |
|
| 17 | + public function callbackRegisterSettings( $input ) |
|
| 18 | 18 | { |
| 19 | - $settings = glsr(Helper::class)->consolidateArray($input); |
|
| 20 | - if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
| 21 | - $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
| 22 | - $options = $this->sanitizeGeneral($input, $options); |
|
| 23 | - $options = $this->sanitizeSubmissions($input, $options); |
|
| 24 | - $options = $this->sanitizeTranslations($input, $options); |
|
| 25 | - if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
| 26 | - glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
| 19 | + $settings = glsr( Helper::class )->consolidateArray( $input ); |
|
| 20 | + if( 1 === count( $settings ) && array_key_exists( 'settings', $settings ) ) { |
|
| 21 | + $options = array_replace_recursive( glsr( OptionManager::class )->all(), $input ); |
|
| 22 | + $options = $this->sanitizeGeneral( $input, $options ); |
|
| 23 | + $options = $this->sanitizeSubmissions( $input, $options ); |
|
| 24 | + $options = $this->sanitizeTranslations( $input, $options ); |
|
| 25 | + if( filter_input( INPUT_POST, 'option_page' ) == Application::ID.'-settings' ) { |
|
| 26 | + glsr( Notice::class )->addSuccess( __( 'Settings updated.', 'site-reviews' ) ); |
|
| 27 | 27 | } |
| 28 | 28 | return $options; |
| 29 | 29 | } |
@@ -36,31 +36,31 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function registerSettings() |
| 38 | 38 | { |
| 39 | - register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
| 39 | + register_setting( Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
| 40 | 40 | 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
| 41 | - ]); |
|
| 41 | + ] ); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * @return array |
| 46 | 46 | */ |
| 47 | - protected function sanitizeGeneral(array $input, array $options) |
|
| 47 | + protected function sanitizeGeneral( array $input, array $options ) |
|
| 48 | 48 | { |
| 49 | 49 | $inputForm = $input['settings']['general']; |
| 50 | - if (!$this->hasMultilingualIntegration($inputForm['support']['multilingual'])) { |
|
| 50 | + if( !$this->hasMultilingualIntegration( $inputForm['support']['multilingual'] ) ) { |
|
| 51 | 51 | $options['settings']['general']['support']['multilingual'] = ''; |
| 52 | 52 | } |
| 53 | - if ('' == trim($inputForm['notification_message'])) { |
|
| 53 | + if( '' == trim( $inputForm['notification_message'] ) ) { |
|
| 54 | 54 | $options['settings']['general']['notification_message'] = glsr()->defaults['settings']['general']['notification_message']; |
| 55 | 55 | } |
| 56 | - $options['settings']['general']['notifications'] = glsr_get($inputForm, 'notifications', []); |
|
| 56 | + $options['settings']['general']['notifications'] = glsr_get( $inputForm, 'notifications', [] ); |
|
| 57 | 57 | return $options; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * @return array |
| 62 | 62 | */ |
| 63 | - protected function sanitizeSubmissions(array $input, array $options) |
|
| 63 | + protected function sanitizeSubmissions( array $input, array $options ) |
|
| 64 | 64 | { |
| 65 | 65 | $inputForm = $input['settings']['submissions']; |
| 66 | 66 | $options['settings']['submissions']['required'] = isset($inputForm['required']) |
@@ -72,20 +72,20 @@ discard block |
||
| 72 | 72 | /** |
| 73 | 73 | * @return array |
| 74 | 74 | */ |
| 75 | - protected function sanitizeTranslations(array $input, array $options) |
|
| 75 | + protected function sanitizeTranslations( array $input, array $options ) |
|
| 76 | 76 | { |
| 77 | - if (isset($input['settings']['strings'])) { |
|
| 78 | - $options['settings']['strings'] = array_values(array_filter($input['settings']['strings'])); |
|
| 77 | + if( isset($input['settings']['strings']) ) { |
|
| 78 | + $options['settings']['strings'] = array_values( array_filter( $input['settings']['strings'] ) ); |
|
| 79 | 79 | $allowedTags = [ |
| 80 | 80 | 'a' => ['class' => [], 'href' => [], 'target' => []], |
| 81 | 81 | 'span' => ['class' => []], |
| 82 | 82 | ]; |
| 83 | - array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
| 84 | - if (isset($string['s2'])) { |
|
| 85 | - $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
| 83 | + array_walk( $options['settings']['strings'], function( &$string ) use ($allowedTags) { |
|
| 84 | + if( isset($string['s2']) ) { |
|
| 85 | + $string['s2'] = wp_kses( $string['s2'], $allowedTags ); |
|
| 86 | 86 | } |
| 87 | - if (isset($string['p2'])) { |
|
| 88 | - $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
| 87 | + if( isset($string['p2']) ) { |
|
| 88 | + $string['p2'] = wp_kses( $string['p2'], $allowedTags ); |
|
| 89 | 89 | } |
| 90 | 90 | }); |
| 91 | 91 | } |
@@ -95,24 +95,24 @@ discard block |
||
| 95 | 95 | /** |
| 96 | 96 | * @return bool |
| 97 | 97 | */ |
| 98 | - protected function hasMultilingualIntegration($integration) |
|
| 98 | + protected function hasMultilingualIntegration( $integration ) |
|
| 99 | 99 | { |
| 100 | - if (!in_array($integration, ['polylang', 'wpml'])) { |
|
| 100 | + if( !in_array( $integration, ['polylang', 'wpml'] ) ) { |
|
| 101 | 101 | return false; |
| 102 | 102 | } |
| 103 | - $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst($integration); |
|
| 104 | - if (!glsr($integrationClass)->isActive()) { |
|
| 105 | - glsr(Notice::class)->addError(sprintf( |
|
| 106 | - __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
| 107 | - constant($integrationClass.'::PLUGIN_NAME') |
|
| 108 | - )); |
|
| 103 | + $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst( $integration ); |
|
| 104 | + if( !glsr( $integrationClass )->isActive() ) { |
|
| 105 | + glsr( Notice::class )->addError( sprintf( |
|
| 106 | + __( 'Please install/activate the %s plugin to enable integration.', 'site-reviews' ), |
|
| 107 | + constant( $integrationClass.'::PLUGIN_NAME' ) |
|
| 108 | + ) ); |
|
| 109 | 109 | return false; |
| 110 | - } elseif (!glsr($integrationClass)->isSupported()) { |
|
| 111 | - glsr(Notice::class)->addError(sprintf( |
|
| 112 | - __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
| 113 | - constant($integrationClass.'::PLUGIN_NAME'), |
|
| 114 | - constant($integrationClass.'::SUPPORTED_VERSION') |
|
| 115 | - )); |
|
| 110 | + } elseif( !glsr( $integrationClass )->isSupported() ) { |
|
| 111 | + glsr( Notice::class )->addError( sprintf( |
|
| 112 | + __( 'Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews' ), |
|
| 113 | + constant( $integrationClass.'::PLUGIN_NAME' ), |
|
| 114 | + constant( $integrationClass.'::SUPPORTED_VERSION' ) |
|
| 115 | + ) ); |
|
| 116 | 116 | return false; |
| 117 | 117 | } |
| 118 | 118 | return true; |
@@ -15,14 +15,14 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * @return string |
| 17 | 17 | */ |
| 18 | - public static function databaseKey($version = null) |
|
| 18 | + public static function databaseKey( $version = null ) |
|
| 19 | 19 | { |
| 20 | - if (null === $version) { |
|
| 21 | - $version = explode('.', glsr()->version); |
|
| 22 | - $version = array_shift($version); |
|
| 20 | + if( null === $version ) { |
|
| 21 | + $version = explode( '.', glsr()->version ); |
|
| 22 | + $version = array_shift( $version ); |
|
| 23 | 23 | } |
| 24 | - return glsr(Helper::class)->snakeCase( |
|
| 25 | - Application::ID.'-v'.intval($version) |
|
| 24 | + return glsr( Helper::class )->snakeCase( |
|
| 25 | + Application::ID.'-v'.intval( $version ) |
|
| 26 | 26 | ); |
| 27 | 27 | } |
| 28 | 28 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function all() |
| 33 | 33 | { |
| 34 | - if (empty($this->options)) { |
|
| 34 | + if( empty($this->options) ) { |
|
| 35 | 35 | $this->reset(); |
| 36 | 36 | } |
| 37 | 37 | return $this->options; |
@@ -41,20 +41,20 @@ discard block |
||
| 41 | 41 | * @param string $path |
| 42 | 42 | * @return bool |
| 43 | 43 | */ |
| 44 | - public function delete($path) |
|
| 44 | + public function delete( $path ) |
|
| 45 | 45 | { |
| 46 | - $keys = explode('.', $path); |
|
| 47 | - $last = array_pop($keys); |
|
| 46 | + $keys = explode( '.', $path ); |
|
| 47 | + $last = array_pop( $keys ); |
|
| 48 | 48 | $options = $this->all(); |
| 49 | 49 | $pointer = &$options; |
| 50 | - foreach ($keys as $key) { |
|
| 51 | - if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
| 50 | + foreach( $keys as $key ) { |
|
| 51 | + if( !isset($pointer[$key]) || !is_array( $pointer[$key] ) ) { |
|
| 52 | 52 | continue; |
| 53 | 53 | } |
| 54 | 54 | $pointer = &$pointer[$key]; |
| 55 | 55 | } |
| 56 | 56 | unset($pointer[$last]); |
| 57 | - return $this->set($options); |
|
| 57 | + return $this->set( $options ); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -63,19 +63,19 @@ discard block |
||
| 63 | 63 | * @param string $cast |
| 64 | 64 | * @return mixed |
| 65 | 65 | */ |
| 66 | - public function get($path = '', $fallback = '', $cast = '') |
|
| 66 | + public function get( $path = '', $fallback = '', $cast = '' ) |
|
| 67 | 67 | { |
| 68 | - $result = glsr(Helper::class)->dataGet($this->all(), $path, $fallback); |
|
| 69 | - return glsr(Helper::class)->castTo($cast, $result); |
|
| 68 | + $result = glsr( Helper::class )->dataGet( $this->all(), $path, $fallback ); |
|
| 69 | + return glsr( Helper::class )->castTo( $cast, $result ); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | 73 | * @param string $path |
| 74 | 74 | * @return bool |
| 75 | 75 | */ |
| 76 | - public function getBool($path) |
|
| 76 | + public function getBool( $path ) |
|
| 77 | 77 | { |
| 78 | - return 'yes' == $this->get($path) |
|
| 78 | + return 'yes' == $this->get( $path ) |
|
| 79 | 79 | ? true |
| 80 | 80 | : false; |
| 81 | 81 | } |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | * @param string $cast |
| 87 | 87 | * @return mixed |
| 88 | 88 | */ |
| 89 | - public function getWP($path, $fallback = '', $cast = '') |
|
| 89 | + public function getWP( $path, $fallback = '', $cast = '' ) |
|
| 90 | 90 | { |
| 91 | - $option = get_option($path, $fallback); |
|
| 92 | - if (empty($option)) { |
|
| 91 | + $option = get_option( $path, $fallback ); |
|
| 92 | + if( empty($option) ) { |
|
| 93 | 93 | $option = $fallback; |
| 94 | 94 | } |
| 95 | - return glsr(Helper::class)->castTo($cast, $option); |
|
| 95 | + return glsr( Helper::class )->castTo( $cast, $option ); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -100,25 +100,25 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | public function json() |
| 102 | 102 | { |
| 103 | - return json_encode($this->all()); |
|
| 103 | + return json_encode( $this->all() ); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | 107 | * @return array |
| 108 | 108 | */ |
| 109 | - public function normalize(array $options = []) |
|
| 109 | + public function normalize( array $options = [] ) |
|
| 110 | 110 | { |
| 111 | 111 | $options = wp_parse_args( |
| 112 | - glsr(Helper::class)->flattenArray($options), |
|
| 113 | - glsr(DefaultsManager::class)->defaults() |
|
| 112 | + glsr( Helper::class )->flattenArray( $options ), |
|
| 113 | + glsr( DefaultsManager::class )->defaults() |
|
| 114 | 114 | ); |
| 115 | - array_walk($options, function (&$value) { |
|
| 116 | - if (!is_string($value)) { |
|
| 115 | + array_walk( $options, function( &$value ) { |
|
| 116 | + if( !is_string( $value ) ) { |
|
| 117 | 117 | return; |
| 118 | 118 | } |
| 119 | - $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
| 119 | + $value = wp_kses( $value, wp_kses_allowed_html( 'post' ) ); |
|
| 120 | 120 | }); |
| 121 | - return glsr(Helper::class)->convertDotNotationArray($options); |
|
| 121 | + return glsr( Helper::class )->convertDotNotationArray( $options ); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function isRecaptchaEnabled() |
| 128 | 128 | { |
| 129 | - $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
| 129 | + $integration = $this->get( 'settings.submissions.recaptcha.integration' ); |
|
| 130 | 130 | return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
| 131 | 131 | } |
| 132 | 132 | |
@@ -135,9 +135,9 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | public function reset() |
| 137 | 137 | { |
| 138 | - $options = $this->getWP(static::databaseKey(), []); |
|
| 139 | - if (!is_array($options) || empty($options)) { |
|
| 140 | - delete_option(static::databaseKey()); |
|
| 138 | + $options = $this->getWP( static::databaseKey(), [] ); |
|
| 139 | + if( !is_array( $options ) || empty($options) ) { |
|
| 140 | + delete_option( static::databaseKey() ); |
|
| 141 | 141 | $options = glsr()->defaults; |
| 142 | 142 | } |
| 143 | 143 | $this->options = $options; |
@@ -148,12 +148,12 @@ discard block |
||
| 148 | 148 | * @param mixed $value |
| 149 | 149 | * @return bool |
| 150 | 150 | */ |
| 151 | - public function set($pathOrOptions, $value = '') |
|
| 151 | + public function set( $pathOrOptions, $value = '' ) |
|
| 152 | 152 | { |
| 153 | - if (is_string($pathOrOptions)) { |
|
| 154 | - $pathOrOptions = glsr(Helper::class)->dataSet($this->all(), $pathOrOptions, $value); |
|
| 153 | + if( is_string( $pathOrOptions ) ) { |
|
| 154 | + $pathOrOptions = glsr( Helper::class )->dataSet( $this->all(), $pathOrOptions, $value ); |
|
| 155 | 155 | } |
| 156 | - if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
| 156 | + if( $result = update_option( static::databaseKey(), (array)$pathOrOptions ) ) { |
|
| 157 | 157 | $this->reset(); |
| 158 | 158 | } |
| 159 | 159 | return $result; |
@@ -21,17 +21,17 @@ discard block |
||
| 21 | 21 | * @param string $metaReviewId |
| 22 | 22 | * @return int |
| 23 | 23 | */ |
| 24 | - public function getPostIdFromReviewId($metaReviewId) |
|
| 24 | + public function getPostIdFromReviewId( $metaReviewId ) |
|
| 25 | 25 | { |
| 26 | - $postId = $this->db->get_var(" |
|
| 26 | + $postId = $this->db->get_var( " |
|
| 27 | 27 | SELECT p.ID |
| 28 | 28 | FROM {$this->db->posts} AS p |
| 29 | 29 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
| 30 | 30 | WHERE p.post_type = '{$this->postType}' |
| 31 | 31 | AND m.meta_key = '_review_id' |
| 32 | 32 | AND m.meta_value = '{$metaReviewId}' |
| 33 | - "); |
|
| 34 | - return intval($postId); |
|
| 33 | + " ); |
|
| 34 | + return intval( $postId ); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -39,23 +39,23 @@ discard block |
||
| 39 | 39 | * @param int $limit |
| 40 | 40 | * @return array |
| 41 | 41 | */ |
| 42 | - public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
| 42 | + public function getReviewCounts( array $args, $lastPostId = 0, $limit = 500 ) |
|
| 43 | 43 | { |
| 44 | - return (array) $this->db->get_results(" |
|
| 44 | + return (array)$this->db->get_results( " |
|
| 45 | 45 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
| 46 | 46 | FROM {$this->db->posts} AS p |
| 47 | 47 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
| 48 | 48 | INNER JOIN {$this->db->postmeta} AS m2 ON p.ID = m2.post_id |
| 49 | - {$this->getInnerJoinForCounts($args)} |
|
| 49 | + {$this->getInnerJoinForCounts( $args )} |
|
| 50 | 50 | WHERE p.ID > {$lastPostId} |
| 51 | 51 | AND p.post_status = 'publish' |
| 52 | 52 | AND p.post_type = '{$this->postType}' |
| 53 | 53 | AND m1.meta_key = '_rating' |
| 54 | 54 | AND m2.meta_key = '_review_type' |
| 55 | - {$this->getAndForCounts($args)} |
|
| 55 | + {$this->getAndForCounts( $args )} |
|
| 56 | 56 | ORDER By p.ID ASC |
| 57 | 57 | LIMIT {$limit} |
| 58 | - "); |
|
| 58 | + " ); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -63,17 +63,17 @@ discard block |
||
| 63 | 63 | * @param string $metaKey |
| 64 | 64 | * @return array |
| 65 | 65 | */ |
| 66 | - public function getReviewCountsFor($metaKey) |
|
| 66 | + public function getReviewCountsFor( $metaKey ) |
|
| 67 | 67 | { |
| 68 | - $metaKey = glsr(Helper::class)->prefix('_', $metaKey); |
|
| 69 | - return (array) $this->db->get_results(" |
|
| 68 | + $metaKey = glsr( Helper::class )->prefix( '_', $metaKey ); |
|
| 69 | + return (array)$this->db->get_results( " |
|
| 70 | 70 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
| 71 | 71 | FROM {$this->db->posts} AS p |
| 72 | 72 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
| 73 | 73 | WHERE p.post_type = '{$this->postType}' |
| 74 | 74 | AND m.meta_key = '{$metaKey}' |
| 75 | 75 | GROUP BY name |
| 76 | - "); |
|
| 76 | + " ); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | * @param string $reviewType |
| 82 | 82 | * @return array |
| 83 | 83 | */ |
| 84 | - public function getReviewIdsByType($reviewType) |
|
| 84 | + public function getReviewIdsByType( $reviewType ) |
|
| 85 | 85 | { |
| 86 | - $results = $this->db->get_col(" |
|
| 86 | + $results = $this->db->get_col( " |
|
| 87 | 87 | SELECT DISTINCT m1.meta_value AS review_id |
| 88 | 88 | FROM {$this->db->posts} AS p |
| 89 | 89 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | AND m1.meta_key = '_review_id' |
| 93 | 93 | AND m2.meta_key = '_review_type' |
| 94 | 94 | AND m2.meta_value = '{$reviewType}' |
| 95 | - "); |
|
| 96 | - return array_keys(array_flip($results)); |
|
| 95 | + " ); |
|
| 96 | + return array_keys( array_flip( $results ) ); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -101,12 +101,12 @@ discard block |
||
| 101 | 101 | * @param int $limit |
| 102 | 102 | * @return array |
| 103 | 103 | */ |
| 104 | - public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
| 104 | + public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 ) |
|
| 105 | 105 | { |
| 106 | - sort($postIds); |
|
| 107 | - $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
| 108 | - $postIds = implode(',', $postIds); |
|
| 109 | - return (array) $this->db->get_results(" |
|
| 106 | + sort( $postIds ); |
|
| 107 | + $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit ); |
|
| 108 | + $postIds = implode( ',', $postIds ); |
|
| 109 | + return (array)$this->db->get_results( " |
|
| 110 | 110 | SELECT p.ID, m.meta_value AS rating |
| 111 | 111 | FROM {$this->db->posts} AS p |
| 112 | 112 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | GROUP BY p.ID |
| 119 | 119 | ORDER By p.ID ASC |
| 120 | 120 | LIMIT {$limit} |
| 121 | - "); |
|
| 121 | + " ); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -126,10 +126,10 @@ discard block |
||
| 126 | 126 | * @param string $status |
| 127 | 127 | * @return array |
| 128 | 128 | */ |
| 129 | - public function getReviewsMeta($key, $status = 'publish') |
|
| 129 | + public function getReviewsMeta( $key, $status = 'publish' ) |
|
| 130 | 130 | { |
| 131 | - $key = glsr(Helper::class)->prefix('_', $key); |
|
| 132 | - $values = $this->db->get_col(" |
|
| 131 | + $key = glsr( Helper::class )->prefix( '_', $key ); |
|
| 132 | + $values = $this->db->get_col( " |
|
| 133 | 133 | SELECT DISTINCT m.meta_value |
| 134 | 134 | FROM {$this->db->postmeta} m |
| 135 | 135 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | AND p.post_status = '{$status}' |
| 140 | 140 | GROUP BY p.ID -- remove duplicate meta_value entries |
| 141 | 141 | ORDER BY m.meta_id ASC -- sort by oldest meta_value |
| 142 | - "); |
|
| 143 | - sort($values); |
|
| 142 | + " ); |
|
| 143 | + sort( $values ); |
|
| 144 | 144 | return $values; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -148,34 +148,34 @@ discard block |
||
| 148 | 148 | * @param string $and |
| 149 | 149 | * @return string |
| 150 | 150 | */ |
| 151 | - protected function getAndForCounts(array $args, $and = '') |
|
| 151 | + protected function getAndForCounts( array $args, $and = '' ) |
|
| 152 | 152 | { |
| 153 | - $postIds = implode(',', array_filter(glsr_get($args, 'post_ids', []))); |
|
| 154 | - $termIds = implode(',', array_filter(glsr_get($args, 'term_ids', []))); |
|
| 155 | - if (!empty($args['type'])) { |
|
| 156 | - $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
| 153 | + $postIds = implode( ',', array_filter( glsr_get( $args, 'post_ids', [] ) ) ); |
|
| 154 | + $termIds = implode( ',', array_filter( glsr_get( $args, 'term_ids', [] ) ) ); |
|
| 155 | + if( !empty($args['type']) ) { |
|
| 156 | + $and .= "AND m2.meta_value = '{$args['type']}' "; |
|
| 157 | 157 | } |
| 158 | - if ($postIds) { |
|
| 159 | - $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
| 158 | + if( $postIds ) { |
|
| 159 | + $and .= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
| 160 | 160 | } |
| 161 | - if ($termIds) { |
|
| 162 | - $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
| 161 | + if( $termIds ) { |
|
| 162 | + $and .= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
| 163 | 163 | } |
| 164 | - return apply_filters('site-reviews/query/and-for-counts', $and); |
|
| 164 | + return apply_filters( 'site-reviews/query/and-for-counts', $and ); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | 168 | * @param string $innerJoin |
| 169 | 169 | * @return string |
| 170 | 170 | */ |
| 171 | - protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
| 171 | + protected function getInnerJoinForCounts( array $args, $innerJoin = '' ) |
|
| 172 | 172 | { |
| 173 | - if (!empty(glsr_get($args, 'post_ids'))) { |
|
| 174 | - $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
| 173 | + if( !empty(glsr_get( $args, 'post_ids' )) ) { |
|
| 174 | + $innerJoin .= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
| 175 | 175 | } |
| 176 | - if (!empty(glsr_get($args, 'term_ids'))) { |
|
| 177 | - $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
| 176 | + if( !empty(glsr_get( $args, 'term_ids' )) ) { |
|
| 177 | + $innerJoin .= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
| 178 | 178 | } |
| 179 | - return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
| 179 | + return apply_filters( 'site-reviews/query/inner-join-for-counts', $innerJoin ); |
|
| 180 | 180 | } |
| 181 | 181 | } |
@@ -18,24 +18,24 @@ discard block |
||
| 18 | 18 | public function run() |
| 19 | 19 | { |
| 20 | 20 | $filenames = []; |
| 21 | - $iterator = new DirectoryIterator(dirname(__FILE__).'/Upgrader'); |
|
| 22 | - foreach ($iterator as $fileinfo) { |
|
| 23 | - if ($fileinfo->isFile()) { |
|
| 21 | + $iterator = new DirectoryIterator( dirname( __FILE__ ).'/Upgrader' ); |
|
| 22 | + foreach( $iterator as $fileinfo ) { |
|
| 23 | + if( $fileinfo->isFile() ) { |
|
| 24 | 24 | $filenames[] = $fileinfo->getFilename(); |
| 25 | 25 | } |
| 26 | 26 | } |
| 27 | - natsort($filenames); |
|
| 27 | + natsort( $filenames ); |
|
| 28 | 28 | $this->currentVersion = $this->currentVersion(); |
| 29 | - array_walk($filenames, function ($file) { |
|
| 30 | - $className = str_replace('.php', '', $file); |
|
| 31 | - $upgradeFromVersion = str_replace(['Upgrade_', '_'], ['', '.'], $className); |
|
| 32 | - $suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
| 33 | - if ('0.0.0' == $this->currentVersion |
|
| 34 | - || version_compare($this->currentVersion, $upgradeFromVersion.$suffix, '>=')) { |
|
| 29 | + array_walk( $filenames, function( $file ) { |
|
| 30 | + $className = str_replace( '.php', '', $file ); |
|
| 31 | + $upgradeFromVersion = str_replace( ['Upgrade_', '_'], ['', '.'], $className ); |
|
| 32 | + $suffix = preg_replace( '/[\d.]+(.+)?/', '${1}', glsr()->version ); // allow alpha/beta versions |
|
| 33 | + if( '0.0.0' == $this->currentVersion |
|
| 34 | + || version_compare( $this->currentVersion, $upgradeFromVersion.$suffix, '>=' ) ) { |
|
| 35 | 35 | return; |
| 36 | 36 | } |
| 37 | - glsr('Modules\\Upgrader\\'.$className); |
|
| 38 | - glsr_log()->notice('Completed Upgrade for v'.$upgradeFromVersion.$suffix); |
|
| 37 | + glsr( 'Modules\\Upgrader\\'.$className ); |
|
| 38 | + glsr_log()->notice( 'Completed Upgrade for v'.$upgradeFromVersion.$suffix ); |
|
| 39 | 39 | }); |
| 40 | 40 | $this->finish(); |
| 41 | 41 | } |
@@ -45,10 +45,10 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function finish() |
| 47 | 47 | { |
| 48 | - if ($this->currentVersion !== glsr()->version) { |
|
| 48 | + if( $this->currentVersion !== glsr()->version ) { |
|
| 49 | 49 | $this->setReviewCounts(); |
| 50 | - $this->updateVersionFrom($this->currentVersion); |
|
| 51 | - } elseif (!glsr(OptionManager::class)->get('last_review_count', false)) { |
|
| 50 | + $this->updateVersionFrom( $this->currentVersion ); |
|
| 51 | + } elseif( !glsr( OptionManager::class )->get( 'last_review_count', false ) ) { |
|
| 52 | 52 | $this->setReviewCounts(); |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | { |
| 61 | 61 | $fallback = '0.0.0'; |
| 62 | 62 | $majorVersions = [4, 3, 2]; |
| 63 | - foreach ($majorVersions as $majorVersion) { |
|
| 64 | - $settings = get_option(OptionManager::databaseKey($majorVersion)); |
|
| 65 | - $version = glsr_get($settings, 'version', $fallback); |
|
| 66 | - if (version_compare($version, $fallback, '>')) { |
|
| 63 | + foreach( $majorVersions as $majorVersion ) { |
|
| 64 | + $settings = get_option( OptionManager::databaseKey( $majorVersion ) ); |
|
| 65 | + $version = glsr_get( $settings, 'version', $fallback ); |
|
| 66 | + if( version_compare( $version, $fallback, '>' ) ) { |
|
| 67 | 67 | return $version; |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -75,16 +75,16 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | protected function setReviewCounts() |
| 77 | 77 | { |
| 78 | - add_action('admin_init', 'glsr_calculate_ratings'); |
|
| 78 | + add_action( 'admin_init', 'glsr_calculate_ratings' ); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * @param string $previousVersion |
| 83 | 83 | * @return void |
| 84 | 84 | */ |
| 85 | - protected function updateVersionFrom($previousVersion) |
|
| 85 | + protected function updateVersionFrom( $previousVersion ) |
|
| 86 | 86 | { |
| 87 | - glsr(OptionManager::class)->set('version', glsr()->version); |
|
| 88 | - glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
| 87 | + glsr( OptionManager::class )->set( 'version', glsr()->version ); |
|
| 88 | + glsr( OptionManager::class )->set( 'version_upgraded_from', $previousVersion ); |
|
| 89 | 89 | } |
| 90 | 90 | } |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | $this->migrateSettings(); |
| 15 | 15 | $this->protectMetaKeys(); |
| 16 | 16 | $this->deleteSessions(); |
| 17 | - delete_transient(Application::ID.'_cloudflare_ips'); |
|
| 17 | + delete_transient( Application::ID.'_cloudflare_ips' ); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -23,11 +23,11 @@ discard block |
||
| 23 | 23 | public function deleteSessions() |
| 24 | 24 | { |
| 25 | 25 | global $wpdb; |
| 26 | - $wpdb->query(" |
|
| 26 | + $wpdb->query( " |
|
| 27 | 27 | DELETE |
| 28 | 28 | FROM {$wpdb->options} |
| 29 | 29 | WHERE option_name LIKE '_glsr_session%' |
| 30 | - "); |
|
| 30 | + " ); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function migrateSettings() |
| 37 | 37 | { |
| 38 | - if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
| 39 | - $previousVersion = glsr(Helper::class)->dataGet($settings, 'version', '0.0.0'); |
|
| 40 | - $multilingual = 'yes' == glsr(Helper::class)->dataGet($settings, 'settings.general.support.polylang') |
|
| 38 | + if( $settings = get_option( OptionManager::databaseKey( 3 ) ) ) { |
|
| 39 | + $previousVersion = glsr( Helper::class )->dataGet( $settings, 'version', '0.0.0' ); |
|
| 40 | + $multilingual = 'yes' == glsr( Helper::class )->dataGet( $settings, 'settings.general.support.polylang' ) |
|
| 41 | 41 | ? 'polylang' |
| 42 | 42 | : ''; |
| 43 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.general.multilingual', $multilingual); |
|
| 44 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.blacklist.integration', ''); |
|
| 43 | + $settings = glsr( Helper::class )->dataSet( $settings, 'settings.general.multilingual', $multilingual ); |
|
| 44 | + $settings = glsr( Helper::class )->dataSet( $settings, 'settings.submissions.blacklist.integration', '' ); |
|
| 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,15 +53,15 @@ 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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -13,10 +13,10 @@ discard block |
||
| 13 | 13 | * @return void |
| 14 | 14 | * @action site-reviews/review/created |
| 15 | 15 | */ |
| 16 | - public function onCreated(Review $review) |
|
| 16 | + public function onCreated( Review $review ) |
|
| 17 | 17 | { |
| 18 | - if ($this->canProceed($review) && 'publish' === $review->status) { |
|
| 19 | - $result = glsr(Rebusify::class)->sendReview($review); |
|
| 18 | + if( $this->canProceed( $review ) && 'publish' === $review->status ) { |
|
| 19 | + $result = glsr( Rebusify::class )->sendReview( $review ); |
|
| 20 | 20 | // @todo |
| 21 | 21 | } |
| 22 | 22 | } |
@@ -26,10 +26,10 @@ discard block |
||
| 26 | 26 | * @return void |
| 27 | 27 | * @action site-reviews/review/reverted |
| 28 | 28 | */ |
| 29 | - public function onReverted(Review $review) |
|
| 29 | + public function onReverted( Review $review ) |
|
| 30 | 30 | { |
| 31 | - if ($this->canProceed($review) && 'publish' === $review->status) { |
|
| 32 | - $result = glsr(Rebusify::class)->sendReview($review); |
|
| 31 | + if( $this->canProceed( $review ) && 'publish' === $review->status ) { |
|
| 32 | + $result = glsr( Rebusify::class )->sendReview( $review ); |
|
| 33 | 33 | // @todo |
| 34 | 34 | } |
| 35 | 35 | } |
@@ -39,10 +39,10 @@ discard block |
||
| 39 | 39 | * @return void |
| 40 | 40 | * @action site-reviews/review/saved |
| 41 | 41 | */ |
| 42 | - public function onSaved(Review $review) |
|
| 42 | + public function onSaved( Review $review ) |
|
| 43 | 43 | { |
| 44 | - if ($this->canProceed($review) && 'publish' === $review->status) { |
|
| 45 | - $result = glsr(Rebusify::class)->sendReview($review); |
|
| 44 | + if( $this->canProceed( $review ) && 'publish' === $review->status ) { |
|
| 45 | + $result = glsr( Rebusify::class )->sendReview( $review ); |
|
| 46 | 46 | // @todo |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -56,23 +56,23 @@ discard block |
||
| 56 | 56 | * @return void |
| 57 | 57 | * @action updated_postmeta |
| 58 | 58 | */ |
| 59 | - public function onUpdatedMeta($metaId, $postId, $metaKey, $metaValue) |
|
| 59 | + public function onUpdatedMeta( $metaId, $postId, $metaKey, $metaValue ) |
|
| 60 | 60 | { |
| 61 | - if (!$this->isReviewPostId($postId) |
|
| 62 | - || !$this->canProceed($review) |
|
| 63 | - || '_response' !== $metaKey) { |
|
| 61 | + if( !$this->isReviewPostId( $postId ) |
|
| 62 | + || !$this->canProceed( $review ) |
|
| 63 | + || '_response' !== $metaKey ) { |
|
| 64 | 64 | return; |
| 65 | 65 | } |
| 66 | - $review = glsr_get_review($postId); |
|
| 67 | - $result = glsr(Rebusify::class)->sendReviewResponse($review); |
|
| 66 | + $review = glsr_get_review( $postId ); |
|
| 67 | + $result = glsr( Rebusify::class )->sendReviewResponse( $review ); |
|
| 68 | 68 | // @todo |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * @return bool |
| 73 | 73 | */ |
| 74 | - protected function canProceed(Review $review) |
|
| 74 | + protected function canProceed( Review $review ) |
|
| 75 | 75 | { |
| 76 | - return glsr(OptionManager::class)->getBool('settings.general.rebusify'); |
|
| 76 | + return glsr( OptionManager::class )->getBool( 'settings.general.rebusify' ); |
|
| 77 | 77 | } |
| 78 | 78 | } |