@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | protected function createWebhookNotification( Command $command, array $args ) |
| 64 | 64 | { |
| 65 | 65 | $fields = []; |
| 66 | - $fields[] = ['title' => str_repeat( ':star:', (int) $command->rating )]; |
|
| 66 | + $fields[] = ['title' => str_repeat( ':star:', (int)$command->rating )]; |
|
| 67 | 67 | if( $command->title ) { |
| 68 | 68 | $fields[] = ['title' => $command->title]; |
| 69 | 69 | } |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | if( $command->author ) { |
| 77 | 77 | $fields[] = ['value' => trim( $command->author.$command->email.' - '.$command->ipAddress )]; |
| 78 | 78 | } |
| 79 | - $fields[] = ['value' => sprintf( '<%s|%s>', $args['notification_link'], __( 'View Review', 'site-reviews' ))]; |
|
| 80 | - return json_encode([ |
|
| 79 | + $fields[] = ['value' => sprintf( '<%s|%s>', $args['notification_link'], __( 'View Review', 'site-reviews' ) )]; |
|
| 80 | + return json_encode( [ |
|
| 81 | 81 | 'icon_url' => glsr()->url.'assets/img/icon.png', |
| 82 | 82 | 'username' => glsr()->name, |
| 83 | 83 | 'attachments' => [[ |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | 'fallback' => $this->createEmailNotification( $command, $args )->read( 'plaintext' ), |
| 87 | 87 | 'fields' => $fields, |
| 88 | 88 | ]], |
| 89 | - ]); |
|
| 89 | + ] ); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -115,12 +115,12 @@ discard block |
||
| 115 | 115 | protected function sendNotification( $post_id, Command $command ) |
| 116 | 116 | { |
| 117 | 117 | $notificationType = glsr( OptionManager::class )->get( 'settings.general.notification' ); |
| 118 | - if( !in_array( $notificationType, ['default','custom','webhook'] ))return; |
|
| 119 | - $assignedToTitle = get_the_title( (int) $command->assignedTo ); |
|
| 118 | + if( !in_array( $notificationType, ['default', 'custom', 'webhook'] ) )return; |
|
| 119 | + $assignedToTitle = get_the_title( (int)$command->assignedTo ); |
|
| 120 | 120 | $notificationSubject = _nx( |
| 121 | 121 | 'New %s-star review', |
| 122 | 122 | 'New %s-star review of: %s', |
| 123 | - (int) empty( $assignedToTitle ), |
|
| 123 | + (int)empty($assignedToTitle), |
|
| 124 | 124 | 'The text is different depending on whether or not the review has been assigned to a post.', |
| 125 | 125 | 'site-reviews' |
| 126 | 126 | ); |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | sprintf( $notificationSubject, $command->rating, $assignedToTitle ) |
| 130 | 130 | ); |
| 131 | 131 | $args = [ |
| 132 | - 'notification_link' => esc_url( admin_url( sprintf( 'post.php?post=%s&action=edit', $post_id ))), |
|
| 132 | + 'notification_link' => esc_url( admin_url( sprintf( 'post.php?post=%s&action=edit', $post_id ) ) ), |
|
| 133 | 133 | 'notification_title' => $notificationTitle, |
| 134 | 134 | 'notification_type' => $notificationType, |
| 135 | 135 | ]; |
@@ -146,14 +146,14 @@ discard block |
||
| 146 | 146 | $args['recipient'] = $args['notification_type'] === 'default' |
| 147 | 147 | ? get_option( 'admin_email' ) |
| 148 | 148 | : glsr( OptionManager::class )->get( 'settings.general.notification_email' ); |
| 149 | - $result = !empty( $args['recipient'] ) |
|
| 149 | + $result = !empty($args['recipient']) |
|
| 150 | 150 | ? $this->createEmailNotification( $command, $args )->send() |
| 151 | 151 | : false; |
| 152 | 152 | if( $result === null ) { |
| 153 | - glsr_log()->error( __( 'Email notification was not sent: missing email, subject, or message.', 'site-reviews' )); |
|
| 153 | + glsr_log()->error( __( 'Email notification was not sent: missing email, subject, or message.', 'site-reviews' ) ); |
|
| 154 | 154 | } |
| 155 | 155 | if( $result === false ) { |
| 156 | - glsr_log()->error( __( 'Email notification was not sent: wp_mail() failed.', 'site-reviews' )); |
|
| 156 | + glsr_log()->error( __( 'Email notification was not sent: wp_mail() failed.', 'site-reviews' ) ); |
|
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | protected function sendWebhookNotification( Command $command, array $args ) |
| 164 | 164 | { |
| 165 | - if( !( $endpoint = glsr( OptionManager::class )->get( 'settings.general.webhook_url' )))return; |
|
| 165 | + if( !($endpoint = glsr( OptionManager::class )->get( 'settings.general.webhook_url' )) )return; |
|
| 166 | 166 | $notification = $this->createWebhookNotification( $command, $args ); |
| 167 | 167 | $result = wp_remote_post( $endpoint, [ |
| 168 | 168 | 'method' => 'POST', |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | 'sslverify' => false, |
| 174 | 174 | 'headers' => ['Content-Type' => 'application/json'], |
| 175 | 175 | 'body' => apply_filters( 'site-reviews/webhook/notification', $notification, $command ), |
| 176 | - ]); |
|
| 177 | - if( is_wp_error( $result )) { |
|
| 176 | + ] ); |
|
| 177 | + if( is_wp_error( $result ) ) { |
|
| 178 | 178 | glsr_log()->error( $result->get_error_message() ); |
| 179 | 179 | } |
| 180 | 180 | } |
@@ -115,7 +115,9 @@ discard block |
||
| 115 | 115 | protected function sendNotification( $post_id, Command $command ) |
| 116 | 116 | { |
| 117 | 117 | $notificationType = glsr( OptionManager::class )->get( 'settings.general.notification' ); |
| 118 | - if( !in_array( $notificationType, ['default','custom','webhook'] ))return; |
|
| 118 | + if( !in_array( $notificationType, ['default','custom','webhook'] )) { |
|
| 119 | + return; |
|
| 120 | + } |
|
| 119 | 121 | $assignedToTitle = get_the_title( (int) $command->assignedTo ); |
| 120 | 122 | $notificationSubject = _nx( |
| 121 | 123 | 'New %s-star review', |
@@ -162,7 +164,9 @@ discard block |
||
| 162 | 164 | */ |
| 163 | 165 | protected function sendWebhookNotification( Command $command, array $args ) |
| 164 | 166 | { |
| 165 | - if( !( $endpoint = glsr( OptionManager::class )->get( 'settings.general.webhook_url' )))return; |
|
| 167 | + if( !( $endpoint = glsr( OptionManager::class )->get( 'settings.general.webhook_url' ))) { |
|
| 168 | + return; |
|
| 169 | + } |
|
| 166 | 170 | $notification = $this->createWebhookNotification( $command, $args ); |
| 167 | 171 | $result = wp_remote_post( $endpoint, [ |
| 168 | 172 | 'method' => 'POST', |
@@ -12,11 +12,11 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | public function handle( Command $command ) |
| 14 | 14 | { |
| 15 | - $postId = wp_update_post([ |
|
| 15 | + $postId = wp_update_post( [ |
|
| 16 | 16 | 'ID' => $command->id, |
| 17 | 17 | 'post_status' => $command->status, |
| 18 | - ]); |
|
| 19 | - if( is_wp_error( $postId )) { |
|
| 18 | + ] ); |
|
| 19 | + if( is_wp_error( $postId ) ) { |
|
| 20 | 20 | glsr_log()->error( $postId->get_error_message() ); |
| 21 | 21 | return []; |
| 22 | 22 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | 'href' => get_edit_post_link( $postId ), |
| 38 | 38 | 'class' => 'row-title', |
| 39 | 39 | 'title' => __( 'Edit', 'site-reviews' ).' “'.esc_attr( $title ).'”', |
| 40 | - ]); |
|
| 40 | + ] ); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | protected function getPostState( $postId ) |
| 48 | 48 | { |
| 49 | 49 | ob_start(); |
| 50 | - _post_states( get_post( $postId )); |
|
| 50 | + _post_states( get_post( $postId ) ); |
|
| 51 | 51 | return ob_get_clean(); |
| 52 | 52 | } |
| 53 | 53 | } |
@@ -21,13 +21,13 @@ discard block |
||
| 21 | 21 | $this->dependencies = glsr( Html::class )->getDependencies(); |
| 22 | 22 | $ajaxNonce = wp_create_nonce( Application::ID.'-ajax-nonce' ); |
| 23 | 23 | $variables = [ |
| 24 | - 'action' => glsr()->prefix . '_action', |
|
| 25 | - 'ajaxurl' => add_query_arg( '_nonce', $ajaxNonce, admin_url( 'admin-ajax.php' )), |
|
| 24 | + 'action' => glsr()->prefix.'_action', |
|
| 25 | + 'ajaxurl' => add_query_arg( '_nonce', $ajaxNonce, admin_url( 'admin-ajax.php' ) ), |
|
| 26 | 26 | 'ajaxnonce' => $ajaxNonce, |
| 27 | - 'ajaxpagination' => ['#wpadminbar','.site-navigation-fixed'], |
|
| 27 | + 'ajaxpagination' => ['#wpadminbar', '.site-navigation-fixed'], |
|
| 28 | 28 | ]; |
| 29 | 29 | $this->enqueue(); |
| 30 | - wp_localize_script( Application::ID, 'site_reviews', apply_filters( 'site-reviews/enqueue/localize', $variables )); |
|
| 30 | + wp_localize_script( Application::ID, 'site_reviews', apply_filters( 'site-reviews/enqueue/localize', $variables ) ); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function enqueue() |
| 37 | 37 | { |
| 38 | - $currentTheme = sanitize_title( wp_get_theme()->get( 'Name' )); |
|
| 38 | + $currentTheme = sanitize_title( wp_get_theme()->get( 'Name' ) ); |
|
| 39 | 39 | $stylesheet = file_exists( glsr()->path.'assets/css/'.$currentTheme.'.css' ) |
| 40 | 40 | ? glsr()->url.'assets/css/'.$currentTheme.'.css' |
| 41 | 41 | : glsr()->url.'assets/css/'.Application::ID.'.css'; |
| 42 | - if( apply_filters( 'site-reviews/assets/css', true )) { |
|
| 42 | + if( apply_filters( 'site-reviews/assets/css', true ) ) { |
|
| 43 | 43 | wp_enqueue_style( |
| 44 | 44 | Application::ID, |
| 45 | 45 | $stylesheet, |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | glsr()->version |
| 48 | 48 | ); |
| 49 | 49 | } |
| 50 | - if( apply_filters( 'site-reviews/assets/js', true )) { |
|
| 50 | + if( apply_filters( 'site-reviews/assets/js', true ) ) { |
|
| 51 | 51 | wp_enqueue_script( |
| 52 | 52 | Application::ID, |
| 53 | 53 | glsr()->url.'assets/js/'.Application::ID.'.js', |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function enqueueRecaptchaScript() |
| 68 | 68 | { |
| 69 | - wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg([ |
|
| 69 | + wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg( [ |
|
| 70 | 70 | 'hl' => apply_filters( 'site-reviews/recaptcha/language', get_locale() ), |
| 71 | 71 | 'onload' => 'glsr_render_recaptcha', |
| 72 | 72 | 'render' => 'explicit', |
| 73 | - ], 'https://www.google.com/recaptcha/api.js' )); |
|
| 73 | + ], 'https://www.google.com/recaptcha/api.js' ) ); |
|
| 74 | 74 | $inlineScript = file_get_contents( glsr()->path.'js/recaptcha.js' ); |
| 75 | 75 | wp_add_inline_script( Application::ID.'/google-recaptcha', $inlineScript, 'before' ); |
| 76 | 76 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | 'label' => '['.$tag.']', |
| 48 | 48 | 'required' => $this->required, |
| 49 | 49 | 'title' => esc_html__( 'Shortcode', 'site-reviews' ), |
| 50 | - ]); |
|
| 50 | + ] ); |
|
| 51 | 51 | return $this; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | protected function generateFields( array $fields ) |
| 58 | 58 | { |
| 59 | 59 | $generatedFields = array_map( function( $field ) { |
| 60 | - if( empty( $field ))return; |
|
| 60 | + if( empty($field) )return; |
|
| 61 | 61 | $field = $this->normalize( $field ); |
| 62 | - if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] )))return; |
|
| 62 | + if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] ) ) )return; |
|
| 63 | 63 | return $this->$method( $field ); |
| 64 | 64 | }, $fields ); |
| 65 | - return array_values( array_filter( $generatedFields )); |
|
| 65 | + return array_values( array_filter( $generatedFields ) ); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -71,15 +71,15 @@ discard block |
||
| 71 | 71 | protected function getFields() |
| 72 | 72 | { |
| 73 | 73 | $fields = $this->generateFields( $this->fields() ); |
| 74 | - if( !empty( $this->errors )) { |
|
| 74 | + if( !empty($this->errors) ) { |
|
| 75 | 75 | $errors = []; |
| 76 | 76 | foreach( $this->required as $name => $alert ) { |
| 77 | - if( false !== array_search( $name, array_column( $fields, 'name' )))continue; |
|
| 77 | + if( false !== array_search( $name, array_column( $fields, 'name' ) ) )continue; |
|
| 78 | 78 | $errors[] = $this->errors[$name]; |
| 79 | 79 | } |
| 80 | 80 | $this->errors = $errors; |
| 81 | 81 | } |
| 82 | - return empty( $this->errors ) |
|
| 82 | + return empty($this->errors) |
|
| 83 | 83 | ? $fields |
| 84 | 84 | : $this->errors; |
| 85 | 85 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | return wp_parse_args( $field, [ |
| 93 | 93 | 'items' => [], |
| 94 | 94 | 'type' => '', |
| 95 | - ]); |
|
| 95 | + ] ); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | 'tooltip' => '', |
| 111 | 111 | 'type' => '', |
| 112 | 112 | 'value' => '', |
| 113 | - ]); |
|
| 113 | + ] ); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | protected function normalizeContainer( array $field ) |
| 120 | 120 | { |
| 121 | - if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field ))return; |
|
| 121 | + if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field ) )return; |
|
| 122 | 122 | $field['items'] = $this->generateFields( $field['items'] ); |
| 123 | 123 | return $field; |
| 124 | 124 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | protected function normalizeField( array $field, array $defaults ) |
| 130 | 130 | { |
| 131 | - if( !$this->validate( $field ))return; |
|
| 131 | + if( !$this->validate( $field ) )return; |
|
| 132 | 132 | return array_filter( shortcode_atts( $defaults, $field ), function( $value ) { |
| 133 | 133 | return $value !== ''; |
| 134 | 134 | }); |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | 'tooltip' => '', |
| 149 | 149 | 'type' => '', |
| 150 | 150 | 'value' => '', |
| 151 | - ]); |
|
| 152 | - if( !is_array( $listbox ))return; |
|
| 153 | - if( !array_key_exists( '', $listbox['options'] )) { |
|
| 151 | + ] ); |
|
| 152 | + if( !is_array( $listbox ) )return; |
|
| 153 | + if( !array_key_exists( '', $listbox['options'] ) ) { |
|
| 154 | 154 | $listbox['options'] = ['' => $listbox['placeholder']] + $listbox['options']; |
| 155 | 155 | } |
| 156 | 156 | foreach( $listbox['options'] as $value => $text ) { |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | protected function normalizePost( array $field ) |
| 169 | 169 | { |
| 170 | - if( !is_array( $field['query_args'] )) { |
|
| 170 | + if( !is_array( $field['query_args'] ) ) { |
|
| 171 | 171 | $field['query_args'] = []; |
| 172 | 172 | } |
| 173 | 173 | $posts = get_posts( wp_parse_args( $field['query_args'], [ |
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | 'orderby' => 'title', |
| 176 | 176 | 'post_type' => 'post', |
| 177 | 177 | 'posts_per_page' => 30, |
| 178 | - ])); |
|
| 179 | - if( !empty( $posts )) { |
|
| 178 | + ] ) ); |
|
| 179 | + if( !empty($posts) ) { |
|
| 180 | 180 | $options = []; |
| 181 | 181 | foreach( $posts as $post ) { |
| 182 | 182 | $options[$post->ID] = esc_html( $post->post_title ); |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | 'tooltip' => '', |
| 207 | 207 | 'type' => '', |
| 208 | 208 | 'value' => '', |
| 209 | - ]); |
|
| 209 | + ] ); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | protected function validate( array $field ) |
| 216 | 216 | { |
| 217 | - $args = shortcode_atts([ |
|
| 217 | + $args = shortcode_atts( [ |
|
| 218 | 218 | 'label' => '', |
| 219 | 219 | 'name' => false, |
| 220 | 220 | 'required' => false, |
@@ -230,13 +230,13 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | protected function validateErrors( array $args ) |
| 232 | 232 | { |
| 233 | - if( !isset( $args['required']['error'] )) { |
|
| 233 | + if( !isset($args['required']['error']) ) { |
|
| 234 | 234 | return true; |
| 235 | 235 | } |
| 236 | - $this->errors[$args['name']] = $this->normalizeContainer([ |
|
| 236 | + $this->errors[$args['name']] = $this->normalizeContainer( [ |
|
| 237 | 237 | 'html' => $args['required']['error'], |
| 238 | 238 | 'type' => 'container', |
| 239 | - ]); |
|
| 239 | + ] ); |
|
| 240 | 240 | return false; |
| 241 | 241 | } |
| 242 | 242 | |
@@ -249,10 +249,10 @@ discard block |
||
| 249 | 249 | return true; |
| 250 | 250 | } |
| 251 | 251 | $alert = esc_html__( 'Some of the shortcode options are required.', 'site-reviews' ); |
| 252 | - if( isset( $args['required']['alert'] )) { |
|
| 252 | + if( isset($args['required']['alert']) ) { |
|
| 253 | 253 | $alert = $args['required']['alert']; |
| 254 | 254 | } |
| 255 | - else if( !empty( $args['label'] )) { |
|
| 255 | + else if( !empty($args['label']) ) { |
|
| 256 | 256 | $alert = sprintf( |
| 257 | 257 | esc_html_x( 'The "%s" option is required.', 'the option label', 'site-reviews' ), |
| 258 | 258 | str_replace( ':', '', $args['label'] ) |
@@ -57,9 +57,13 @@ discard block |
||
| 57 | 57 | protected function generateFields( array $fields ) |
| 58 | 58 | { |
| 59 | 59 | $generatedFields = array_map( function( $field ) { |
| 60 | - if( empty( $field ))return; |
|
| 60 | + if( empty( $field )) { |
|
| 61 | + return; |
|
| 62 | + } |
|
| 61 | 63 | $field = $this->normalize( $field ); |
| 62 | - if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] )))return; |
|
| 64 | + if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] ))) { |
|
| 65 | + return; |
|
| 66 | + } |
|
| 63 | 67 | return $this->$method( $field ); |
| 64 | 68 | }, $fields ); |
| 65 | 69 | return array_values( array_filter( $generatedFields )); |
@@ -74,7 +78,9 @@ discard block |
||
| 74 | 78 | if( !empty( $this->errors )) { |
| 75 | 79 | $errors = []; |
| 76 | 80 | foreach( $this->required as $name => $alert ) { |
| 77 | - if( false !== array_search( $name, array_column( $fields, 'name' )))continue; |
|
| 81 | + if( false !== array_search( $name, array_column( $fields, 'name' ))) { |
|
| 82 | + continue; |
|
| 83 | + } |
|
| 78 | 84 | $errors[] = $this->errors[$name]; |
| 79 | 85 | } |
| 80 | 86 | $this->errors = $errors; |
@@ -118,7 +124,9 @@ discard block |
||
| 118 | 124 | */ |
| 119 | 125 | protected function normalizeContainer( array $field ) |
| 120 | 126 | { |
| 121 | - if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field ))return; |
|
| 127 | + if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field )) { |
|
| 128 | + return; |
|
| 129 | + } |
|
| 122 | 130 | $field['items'] = $this->generateFields( $field['items'] ); |
| 123 | 131 | return $field; |
| 124 | 132 | } |
@@ -128,7 +136,9 @@ discard block |
||
| 128 | 136 | */ |
| 129 | 137 | protected function normalizeField( array $field, array $defaults ) |
| 130 | 138 | { |
| 131 | - if( !$this->validate( $field ))return; |
|
| 139 | + if( !$this->validate( $field )) { |
|
| 140 | + return; |
|
| 141 | + } |
|
| 132 | 142 | return array_filter( shortcode_atts( $defaults, $field ), function( $value ) { |
| 133 | 143 | return $value !== ''; |
| 134 | 144 | }); |
@@ -149,7 +159,9 @@ discard block |
||
| 149 | 159 | 'type' => '', |
| 150 | 160 | 'value' => '', |
| 151 | 161 | ]); |
| 152 | - if( !is_array( $listbox ))return; |
|
| 162 | + if( !is_array( $listbox )) { |
|
| 163 | + return; |
|
| 164 | + } |
|
| 153 | 165 | if( !array_key_exists( '', $listbox['options'] )) { |
| 154 | 166 | $listbox['options'] = ['' => $listbox['placeholder']] + $listbox['options']; |
| 155 | 167 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | foreach( $this->rules as $attribute => $rules ) { |
| 74 | 74 | foreach( $rules as $rule ) { |
| 75 | 75 | $this->validateAttribute( $attribute, $rule ); |
| 76 | - if( $this->shouldStopValidating( $attribute ))break; |
|
| 76 | + if( $this->shouldStopValidating( $attribute ) )break; |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | return $this->errors; |
@@ -88,14 +88,14 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public function validateAttribute( $attribute, $rule ) |
| 90 | 90 | { |
| 91 | - list( $rule, $parameters ) = $this->parseRule( $rule ); |
|
| 91 | + list($rule, $parameters) = $this->parseRule( $rule ); |
|
| 92 | 92 | if( $rule == '' )return; |
| 93 | 93 | $value = $this->getValue( $attribute ); |
| 94 | 94 | $this->validateRequired( $attribute, $value ) || in_array( $rule, $this->implicitRules ); |
| 95 | - if( !method_exists( $this, $method = 'validate'.$rule )) { |
|
| 95 | + if( !method_exists( $this, $method = 'validate'.$rule ) ) { |
|
| 96 | 96 | throw new BadMethodCallException( "Method [$method] does not exist." ); |
| 97 | 97 | } |
| 98 | - if( !$this->$method( $attribute, $value, $parameters )) { |
|
| 98 | + if( !$this->$method( $attribute, $value, $parameters ) ) { |
|
| 99 | 99 | $this->addFailure( $attribute, $rule, $parameters ); |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | $message = $this->getMessage( $attribute, $rule, $parameters ); |
| 112 | 112 | $this->errors[$attribute]['errors'][] = $message; |
| 113 | - if( !isset( $this->errors[$attribute]['value'] )) { |
|
| 113 | + if( !isset($this->errors[$attribute]['value']) ) { |
|
| 114 | 114 | $this->errors[$attribute]['value'] = $this->getValue( $attribute ); |
| 115 | 115 | } |
| 116 | 116 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | protected function getMessage( $attribute, $rule, array $parameters ) |
| 149 | 149 | { |
| 150 | - if( in_array( $rule, $this->sizeRules )) { |
|
| 150 | + if( in_array( $rule, $this->sizeRules ) ) { |
|
| 151 | 151 | return $this->getSizeMessage( $attribute, $rule, $parameters ); |
| 152 | 152 | } |
| 153 | 153 | $lowerRule = glsr( Helper::class )->snakeCase( $rule ); |
@@ -162,11 +162,11 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | protected function getRule( $attribute, $rules ) |
| 164 | 164 | { |
| 165 | - if( !array_key_exists( $attribute, $this->rules ))return; |
|
| 166 | - $rules = (array) $rules; |
|
| 165 | + if( !array_key_exists( $attribute, $this->rules ) )return; |
|
| 166 | + $rules = (array)$rules; |
|
| 167 | 167 | foreach( $this->rules[$attribute] as $rule ) { |
| 168 | - list( $rule, $parameters ) = $this->parseRule( $rule ); |
|
| 169 | - if( in_array( $rule, $rules )) { |
|
| 168 | + list($rule, $parameters) = $this->parseRule( $rule ); |
|
| 169 | + if( in_array( $rule, $rules ) ) { |
|
| 170 | 170 | return [$rule, $parameters]; |
| 171 | 171 | } |
| 172 | 172 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | if( is_numeric( $value ) && $hasNumeric ) { |
| 185 | 185 | return $value; |
| 186 | 186 | } |
| 187 | - elseif( is_array( $value )) { |
|
| 187 | + elseif( is_array( $value ) ) { |
|
| 188 | 188 | return count( $value ); |
| 189 | 189 | } |
| 190 | 190 | return mb_strlen( $value ); |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | protected function getValue( $attribute ) |
| 213 | 213 | { |
| 214 | - if( isset( $this->data[$attribute] )) { |
|
| 214 | + if( isset($this->data[$attribute]) ) { |
|
| 215 | 215 | return $this->data[$attribute]; |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | protected function hasRule( $attribute, $rules ) |
| 226 | 226 | { |
| 227 | - return !is_null( $this->getRule( $attribute, $rules )); |
|
| 227 | + return !is_null( $this->getRule( $attribute, $rules ) ); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -264,11 +264,11 @@ discard block |
||
| 264 | 264 | $parameters = []; |
| 265 | 265 | // example: {rule}:{parameters} |
| 266 | 266 | if( strpos( $rule, ':' ) !== false ) { |
| 267 | - list( $rule, $parameter ) = explode( ':', $rule, 2 ); |
|
| 267 | + list($rule, $parameter) = explode( ':', $rule, 2 ); |
|
| 268 | 268 | // example: {parameter1,parameter2,...} |
| 269 | 269 | $parameters = $this->parseParameters( $rule, $parameter ); |
| 270 | 270 | } |
| 271 | - $rule = ucwords( str_replace( ['-', '_'], ' ', trim( $rule ))); |
|
| 271 | + $rule = ucwords( str_replace( ['-', '_'], ' ', trim( $rule ) ) ); |
|
| 272 | 272 | $rule = str_replace( ' ', '', $rule ); |
| 273 | 273 | return [$rule, $parameters]; |
| 274 | 274 | } |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | protected function shouldStopValidating( $attribute ) |
| 297 | 297 | { |
| 298 | 298 | return $this->hasRule( $attribute, $this->implicitRules ) |
| 299 | - && isset( $this->failedRules[$attribute] ) |
|
| 299 | + && isset($this->failedRules[$attribute]) |
|
| 300 | 300 | && array_intersect( array_keys( $this->failedRules[$attribute] ), $this->implicitRules ); |
| 301 | 301 | } |
| 302 | 302 | |
@@ -321,12 +321,12 @@ discard block |
||
| 321 | 321 | 'regex' => _x( 'The :attribute format is invalid.', ':attribute is a placeholder and should not be translated.', 'site-reviews' ), |
| 322 | 322 | 'required' => _x( 'The :attribute field is required.', ':attribute is a placeholder and should not be translated.', 'site-reviews' ), |
| 323 | 323 | ]; |
| 324 | - $message = isset( $strings[$key] ) |
|
| 324 | + $message = isset($strings[$key]) |
|
| 325 | 325 | ? $strings[$key] |
| 326 | 326 | : false; |
| 327 | 327 | if( !$message )return; |
| 328 | 328 | $message = str_replace( ':attribute', $attribute, $message ); |
| 329 | - if( method_exists( $this, $replacer = 'replace'.$rule )) { |
|
| 329 | + if( method_exists( $this, $replacer = 'replace'.$rule ) ) { |
|
| 330 | 330 | $message = $this->$replacer( $message, $parameters ); |
| 331 | 331 | } |
| 332 | 332 | return $message; |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | $diff = time() - strtotime( $date ); |
| 32 | 32 | foreach( static::$TIME_PERIODS as $i => $timePeriod ) { |
| 33 | 33 | if( $diff > $timePeriod[0] )continue; |
| 34 | - $unit = intval( floor( $diff / $timePeriod[1] )); |
|
| 34 | + $unit = intval( floor( $diff / $timePeriod[1] ) ); |
|
| 35 | 35 | $relativeDates = [ |
| 36 | 36 | _n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ), |
| 37 | 37 | _n( '%s minute ago', '%s minutes ago', $unit, 'site-reviews' ), |
@@ -30,7 +30,9 @@ |
||
| 30 | 30 | { |
| 31 | 31 | $diff = time() - strtotime( $date ); |
| 32 | 32 | foreach( static::$TIME_PERIODS as $i => $timePeriod ) { |
| 33 | - if( $diff > $timePeriod[0] )continue; |
|
| 33 | + if( $diff > $timePeriod[0] ) { |
|
| 34 | + continue; |
|
| 35 | + } |
|
| 34 | 36 | $unit = intval( floor( $diff / $timePeriod[1] )); |
| 35 | 37 | $relativeDates = [ |
| 36 | 38 | _n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ), |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | 'inactive-plugin' => 'Inactive Plugins', |
| 30 | 30 | 'setting' => 'Plugin Settings', |
| 31 | 31 | ]; |
| 32 | - $systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use( $details ) { |
|
| 32 | + $systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use($details) { |
|
| 33 | 33 | $methodName = glsr( Helper::class )->buildMethodName( 'get-'.$key.'-details' ); |
| 34 | 34 | if( method_exists( $this, $methodName ) && $systemDetails = $this->$methodName() ) { |
| 35 | 35 | return $carry.$this->implode( $details[$key], $systemDetails ); |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | { |
| 47 | 47 | $plugins = get_plugins(); |
| 48 | 48 | $activePlugins = (array)get_option( 'active_plugins', [] ); |
| 49 | - $inactive = array_diff_key( $plugins, array_flip( $activePlugins )); |
|
| 50 | - return $this->normalizePluginList( array_diff_key( $plugins, $inactive )); |
|
| 49 | + $inactive = array_diff_key( $plugins, array_flip( $activePlugins ) ); |
|
| 50 | + return $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | public function getInactivePluginDetails() |
| 72 | 72 | { |
| 73 | 73 | $activePlugins = (array)get_option( 'active_plugins', [] ); |
| 74 | - return $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ))); |
|
| 74 | + return $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ) ) ); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | $plugins = array_merge( |
| 83 | 83 | get_mu_plugins(), |
| 84 | - get_plugins( '/../'.basename( WPMU_PLUGIN_DIR )) |
|
| 84 | + get_plugins( '/../'.basename( WPMU_PLUGIN_DIR ) ) |
|
| 85 | 85 | ); |
| 86 | - if( empty( $plugins ))return; |
|
| 86 | + if( empty($plugins) )return; |
|
| 87 | 87 | return $this->normalizePluginList( $plugins ); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function getMultisitePluginDetails() |
| 94 | 94 | { |
| 95 | - if( !is_multisite() || empty( get_site_option( 'active_sitewide_plugins', [] )))return; |
|
| 95 | + if( !is_multisite() || empty(get_site_option( 'active_sitewide_plugins', [] )) )return; |
|
| 96 | 96 | return $this->normalizePluginList( wp_get_active_network_plugins() ); |
| 97 | 97 | } |
| 98 | 98 | |
@@ -114,11 +114,11 @@ discard block |
||
| 114 | 114 | 'Max Input Vars' => ini_get( 'max_input_vars' ), |
| 115 | 115 | 'Memory Limit' => ini_get( 'memory_limit' ), |
| 116 | 116 | 'Post Max Size' => ini_get( 'post_max_size' ), |
| 117 | - 'Session Cookie Path' => esc_html( ini_get( 'session.cookie_path' )), |
|
| 118 | - 'Session Name' => esc_html( ini_get( 'session.name' )), |
|
| 119 | - 'Session Save Path' => esc_html( ini_get( 'session.save_path' )), |
|
| 120 | - 'Session Use Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_cookies' )), true ), |
|
| 121 | - 'Session Use Only Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_only_cookies' )), true ), |
|
| 117 | + 'Session Cookie Path' => esc_html( ini_get( 'session.cookie_path' ) ), |
|
| 118 | + 'Session Name' => esc_html( ini_get( 'session.name' ) ), |
|
| 119 | + 'Session Save Path' => esc_html( ini_get( 'session.save_path' ) ), |
|
| 120 | + 'Session Use Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_cookies' ) ), true ), |
|
| 121 | + 'Session Use Only Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_only_cookies' ) ), true ), |
|
| 122 | 122 | 'Upload Max Filesize' => ini_get( 'upload_max_filesize' ), |
| 123 | 123 | ]; |
| 124 | 124 | } |
@@ -146,13 +146,13 @@ discard block |
||
| 146 | 146 | $settings = glsr( OptionManager::class )->get( 'settings' ); |
| 147 | 147 | $settings = $helper->flattenArray( $settings ); |
| 148 | 148 | foreach( ['submissions.recaptcha.key', 'submissions.recaptcha.secret'] as $key ) { |
| 149 | - if( empty( $settings[$key] ))continue; |
|
| 149 | + if( empty($settings[$key]) )continue; |
|
| 150 | 150 | $settings[$key] = str_repeat( '*', 10 ); |
| 151 | 151 | } |
| 152 | 152 | $details = []; |
| 153 | 153 | foreach( $settings as $key => $value ) { |
| 154 | - if( $helper->startsWith( 'translations', $key ) && $helper->endsWith( 'id', $key ))continue; |
|
| 155 | - $value = htmlspecialchars( trim( preg_replace('/\s\s+/', '\\n', $value )), ENT_QUOTES, 'UTF-8' ); |
|
| 154 | + if( $helper->startsWith( 'translations', $key ) && $helper->endsWith( 'id', $key ) )continue; |
|
| 155 | + $value = htmlspecialchars( trim( preg_replace( '/\s\s+/', '\\n', $value ) ), ENT_QUOTES, 'UTF-8' ); |
|
| 156 | 156 | $details[$key] = $value; |
| 157 | 157 | } |
| 158 | 158 | return $details; |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | return $value; |
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | - return implode( ',', array_filter( [DB_HOST, $serverName] )); |
|
| 235 | + return implode( ',', array_filter( [DB_HOST, $serverName] ) ); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | { |
| 254 | 254 | $plugins = get_plugins(); |
| 255 | 255 | $activePlugins = (array)get_option( 'active_plugins', [] ); |
| 256 | - $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ))); |
|
| 257 | - $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive )); |
|
| 256 | + $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ) ) ); |
|
| 257 | + $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
| 258 | 258 | return $active + $inactive; |
| 259 | 259 | } |
| 260 | 260 | |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | protected function implode( $title, array $details ) |
| 266 | 266 | { |
| 267 | 267 | $strings = ['['.$title.']']; |
| 268 | - $padding = max( array_map( 'strlen', array_keys( $details )) ); |
|
| 268 | + $padding = max( array_map( 'strlen', array_keys( $details ) ) ); |
|
| 269 | 269 | $padding = max( [$padding, static::PAD] ); |
| 270 | 270 | foreach( $details as $key => $value ) { |
| 271 | 271 | $strings[] = is_string( $key ) |
@@ -294,8 +294,8 @@ discard block |
||
| 294 | 294 | { |
| 295 | 295 | $response = wp_remote_post( static::WP_API_URL ); |
| 296 | 296 | return !is_wp_error( $response ) |
| 297 | - && !empty( $response['response']['code'] ) |
|
| 298 | - && in_array( $response['response']['code'], range( 200, 299 )) |
|
| 297 | + && !empty($response['response']['code']) |
|
| 298 | + && in_array( $response['response']['code'], range( 200, 299 ) ) |
|
| 299 | 299 | ? 'Works' |
| 300 | 300 | : 'Does not work'; |
| 301 | 301 | } |
@@ -33,8 +33,8 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | public function __construct() |
| 35 | 35 | { |
| 36 | - if( $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE )) { |
|
| 37 | - $cookie = explode( '||', stripslashes( $cookieId )); |
|
| 36 | + if( $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE ) ) { |
|
| 37 | + $cookie = explode( '||', stripslashes( $cookieId ) ); |
|
| 38 | 38 | $this->sessionId = preg_replace( '/[^A-Za-z0-9_]/', '', $cookie[0] ); |
| 39 | 39 | $this->expiryTimestamp = absint( $cookie[1] ); |
| 40 | 40 | $this->expiryTimestampReset = absint( $cookie[2] ); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | public function deleteExpiredSessions( $limit = 1000 ) |
| 79 | 79 | { |
| 80 | 80 | global $wpdb; |
| 81 | - if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ))) { |
|
| 81 | + if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ) ) ) { |
|
| 82 | 82 | $wpdb->query( |
| 83 | 83 | "DELETE FROM {$wpdb->options} WHERE option_name IN ('{$expiredSessions}')" |
| 84 | 84 | ); |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | public function get( $key, $fallback = '', $unset = false ) |
| 95 | 95 | { |
| 96 | 96 | $key = sanitize_key( $key ); |
| 97 | - $value = isset( $this->sessionData[$key] ) |
|
| 97 | + $value = isset($this->sessionData[$key]) |
|
| 98 | 98 | ? maybe_unserialize( $this->sessionData[$key] ) |
| 99 | 99 | : $fallback; |
| 100 | - if( isset( $this->sessionData[$key] ) && $unset ) { |
|
| 101 | - unset( $this->sessionData[$key] ); |
|
| 100 | + if( isset($this->sessionData[$key]) && $unset ) { |
|
| 101 | + unset($this->sessionData[$key]); |
|
| 102 | 102 | $this->updateSession(); |
| 103 | 103 | } |
| 104 | 104 | return $value; |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | protected function deleteSession() |
| 133 | 133 | { |
| 134 | 134 | delete_option( $this->getSessionId() ); |
| 135 | - delete_option( $this->getSessionId( 'expires' )); |
|
| 135 | + delete_option( $this->getSessionId( 'expires' ) ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | protected function generateSessionId() |
| 142 | 142 | { |
| 143 | - return md5(( new PasswordHash( 8, false ))->get_random_bytes( 32 )); |
|
| 143 | + return md5( (new PasswordHash( 8, false ))->get_random_bytes( 32 ) ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -152,13 +152,13 @@ discard block |
||
| 152 | 152 | global $wpdb; |
| 153 | 153 | $expiredSessions = []; |
| 154 | 154 | $sessions = $wpdb->get_results( |
| 155 | - "SELECT option_name AS name, option_value AS expiration " . |
|
| 156 | - "FROM {$wpdb->options} " . |
|
| 157 | - "WHERE option_name LIKE '".static::SESSION_COOKIE."_expires_%' " . |
|
| 158 | - "ORDER BY option_value ASC " . |
|
| 155 | + "SELECT option_name AS name, option_value AS expiration ". |
|
| 156 | + "FROM {$wpdb->options} ". |
|
| 157 | + "WHERE option_name LIKE '".static::SESSION_COOKIE."_expires_%' ". |
|
| 158 | + "ORDER BY option_value ASC ". |
|
| 159 | 159 | "LIMIT 0, ".absint( $limit ) |
| 160 | 160 | ); |
| 161 | - if( !empty( $sessions )) { |
|
| 161 | + if( !empty($sessions) ) { |
|
| 162 | 162 | $now = time(); |
| 163 | 163 | foreach( $sessions as $session ) { |
| 164 | 164 | if( $now <= $session->expiration )continue; |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | protected function getSessionId( $separator = '' ) |
| 177 | 177 | { |
| 178 | - return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] )); |
|
| 178 | + return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] ) ); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | { |
| 207 | 207 | if( headers_sent() )return; |
| 208 | 208 | $cookie = $this->sessionId.'||'.$this->expiryTimestamp.'||'.$this->expiryTimestampReset; |
| 209 | - $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ))); |
|
| 209 | + $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ) ) ); |
|
| 210 | 210 | setcookie( static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath ); |
| 211 | 211 | } |
| 212 | 212 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | protected function updateSession() |
| 226 | 226 | { |
| 227 | - if( false === get_option( $this->getSessionId() )) { |
|
| 227 | + if( false === get_option( $this->getSessionId() ) ) { |
|
| 228 | 228 | $this->createSession(); |
| 229 | 229 | } |
| 230 | 230 | else { |
@@ -161,7 +161,9 @@ discard block |
||
| 161 | 161 | if( !empty( $sessions )) { |
| 162 | 162 | $now = time(); |
| 163 | 163 | foreach( $sessions as $session ) { |
| 164 | - if( $now <= $session->expiration )continue; |
|
| 164 | + if( $now <= $session->expiration ) { |
|
| 165 | + continue; |
|
| 166 | + } |
|
| 165 | 167 | $expiredSessions[] = $session->name; |
| 166 | 168 | $expiredSessions[] = str_replace( '_expires_', '_', $session->name ); |
| 167 | 169 | } |
@@ -204,7 +206,9 @@ discard block |
||
| 204 | 206 | */ |
| 205 | 207 | protected function setCookie() |
| 206 | 208 | { |
| 207 | - if( headers_sent() )return; |
|
| 209 | + if( headers_sent() ) { |
|
| 210 | + return; |
|
| 211 | + } |
|
| 208 | 212 | $cookie = $this->sessionId.'||'.$this->expiryTimestamp.'||'.$this->expiryTimestampReset; |
| 209 | 213 | $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ))); |
| 210 | 214 | setcookie( static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath ); |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | { |
| 31 | 31 | $translations = $this->getSettings(); |
| 32 | 32 | $entries = $this->filter( $translations, $this->entries() )->results(); |
| 33 | - array_walk( $translations, function( &$entry ) use( $entries ) { |
|
| 33 | + array_walk( $translations, function( &$entry ) use($entries) { |
|
| 34 | 34 | $entry['desc'] = array_key_exists( $entry['id'], $entries ) |
| 35 | 35 | ? $this->getEntryString( $entries[$entry['id']], 'msgctxt' ) |
| 36 | 36 | : ''; |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function entries() |
| 45 | 45 | { |
| 46 | - if( !isset( $this->entries )) { |
|
| 46 | + if( !isset($this->entries) ) { |
|
| 47 | 47 | try { |
| 48 | 48 | $entries = $this->normalize( |
| 49 | - Parser::parseFile( glsr()->path( 'languages/site-reviews.pot' ))->getEntries() |
|
| 49 | + Parser::parseFile( glsr()->path( 'languages/site-reviews.pot' ) )->getEntries() |
|
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | catch( Exception $e ) { |
@@ -77,13 +77,13 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | public function filter( $filterWith = null, $entries = null, $intersect = true ) |
| 79 | 79 | { |
| 80 | - if( !is_array( $entries )) { |
|
| 80 | + if( !is_array( $entries ) ) { |
|
| 81 | 81 | $entries = $this->results; |
| 82 | 82 | } |
| 83 | - if( !is_array( $filterWith )) { |
|
| 83 | + if( !is_array( $filterWith ) ) { |
|
| 84 | 84 | $filterWith = $this->getSettings(); |
| 85 | 85 | } |
| 86 | - $keys = array_flip( array_column( $filterWith, 'id' )); |
|
| 86 | + $keys = array_flip( array_column( $filterWith, 'id' ) ); |
|
| 87 | 87 | $this->results = $intersect |
| 88 | 88 | ? array_intersect_key( $entries, $keys ) |
| 89 | 89 | : array_diff_key( $entries, $keys ); |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | return $this->translate( $translation, $domain, [ |
| 102 | 102 | 'single' => $text, |
| 103 | - ]); |
|
| 103 | + ] ); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | return $this->translate( $translation, $domain, [ |
| 116 | 116 | 'context' => $context, |
| 117 | 117 | 'single' => $text, |
| 118 | - ]); |
|
| 118 | + ] ); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | 'number' => $number, |
| 133 | 133 | 'plural' => $plural, |
| 134 | 134 | 'single' => $single, |
| 135 | - ]); |
|
| 135 | + ] ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | 'number' => $number, |
| 152 | 152 | 'plural' => $plural, |
| 153 | 153 | 'single' => $single, |
| 154 | - ]); |
|
| 154 | + ] ); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | public function render( $template, array $entry ) |
| 162 | 162 | { |
| 163 | 163 | $data = array_combine( |
| 164 | - array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry )), |
|
| 164 | + array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry ) ), |
|
| 165 | 165 | $entry |
| 166 | 166 | ); |
| 167 | 167 | ob_start(); |
@@ -198,13 +198,13 @@ discard block |
||
| 198 | 198 | 'p1' => $this->getEntryString( $entry, 'msgid_plural' ), |
| 199 | 199 | 's1' => $this->getEntryString( $entry, 'msgid' ), |
| 200 | 200 | ]; |
| 201 | - $text = !empty( $data['p1'] ) |
|
| 201 | + $text = !empty($data['p1']) |
|
| 202 | 202 | ? sprintf( '%s | %s', $data['s1'], $data['p1'] ) |
| 203 | 203 | : $data['s1']; |
| 204 | 204 | $rendered .= $this->render( 'result', [ |
| 205 | 205 | 'entry' => wp_json_encode( $data ), |
| 206 | 206 | 'text' => wp_strip_all_tags( $text ), |
| 207 | - ]); |
|
| 207 | + ] ); |
|
| 208 | 208 | } |
| 209 | 209 | if( $resetAfterRender ) { |
| 210 | 210 | $this->reset(); |
@@ -237,12 +237,12 @@ discard block |
||
| 237 | 237 | public function search( $needle = '' ) |
| 238 | 238 | { |
| 239 | 239 | $this->reset(); |
| 240 | - $needle = trim( strtolower( $needle )); |
|
| 240 | + $needle = trim( strtolower( $needle ) ); |
|
| 241 | 241 | foreach( $this->entries() as $key => $entry ) { |
| 242 | - $single = strtolower( $this->getEntryString( $entry, 'msgid' )); |
|
| 243 | - $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' )); |
|
| 242 | + $single = strtolower( $this->getEntryString( $entry, 'msgid' ) ); |
|
| 243 | + $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' ) ); |
|
| 244 | 244 | if( strlen( $needle ) < static::SEARCH_THRESHOLD ) { |
| 245 | - if( in_array( $needle, [$single, $plural] )) { |
|
| 245 | + if( in_array( $needle, [$single, $plural] ) ) { |
|
| 246 | 246 | $this->results[$key] = $entry; |
| 247 | 247 | } |
| 248 | 248 | } |
@@ -266,19 +266,19 @@ discard block |
||
| 266 | 266 | $args = $this->normalizeTranslationArgs( $args ); |
| 267 | 267 | extract( $args ); |
| 268 | 268 | $strings = $this->getSettings(); |
| 269 | - $strings = array_filter( $strings, function( $string ) use( $single, $plural ) { |
|
| 269 | + $strings = array_filter( $strings, function( $string ) use($single, $plural) { |
|
| 270 | 270 | return $string['s1'] == html_entity_decode( $single, ENT_COMPAT, 'UTF-8' ) |
| 271 | 271 | && $string['p1'] == html_entity_decode( $plural, ENT_COMPAT, 'UTF-8' ); |
| 272 | 272 | }); |
| 273 | - if( empty( $strings )) { |
|
| 273 | + if( empty($strings) ) { |
|
| 274 | 274 | return $original; |
| 275 | 275 | } |
| 276 | 276 | $string = current( $strings ); |
| 277 | 277 | $translations = get_translations_for_domain( $domain ); |
| 278 | - if( !empty( $string['s2'] )) { |
|
| 278 | + if( !empty($string['s2']) ) { |
|
| 279 | 279 | $single = $string['s2']; |
| 280 | 280 | } |
| 281 | - if( !empty( $string['p2'] )) { |
|
| 281 | + if( !empty($string['p2']) ) { |
|
| 282 | 282 | $plural = $string['p2']; |
| 283 | 283 | } |
| 284 | 284 | return $string['type'] == 'plural' |
@@ -292,8 +292,8 @@ discard block |
||
| 292 | 292 | */ |
| 293 | 293 | protected function getEntryString( array $entry, $key ) |
| 294 | 294 | { |
| 295 | - return isset( $entry[$key] ) |
|
| 296 | - ? implode( '', (array) $entry[$key] ) |
|
| 295 | + return isset($entry[$key]) |
|
| 296 | + ? implode( '', (array)$entry[$key] ) |
|
| 297 | 297 | : ''; |
| 298 | 298 | } |
| 299 | 299 | |
@@ -303,8 +303,8 @@ discard block |
||
| 303 | 303 | protected function getSettings() |
| 304 | 304 | { |
| 305 | 305 | $settings = glsr( OptionManager::class )->get( 'settings' ); |
| 306 | - return isset( $settings['strings'] ) |
|
| 307 | - ? $this->normalizeSettings( (array) $settings['strings'] ) |
|
| 306 | + return isset($settings['strings']) |
|
| 307 | + ? $this->normalizeSettings( (array)$settings['strings'] ) |
|
| 308 | 308 | : []; |
| 309 | 309 | } |
| 310 | 310 | |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | $keys = [ |
| 317 | 317 | 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
| 318 | 318 | ]; |
| 319 | - array_walk( $entries, function( &$entry ) use( $keys ) { |
|
| 319 | + array_walk( $entries, function( &$entry ) use($keys) { |
|
| 320 | 320 | foreach( $keys as $key ) { |
| 321 | 321 | $entry = $this->normalizeEntryString( $entry, $key ); |
| 322 | 322 | } |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | */ |
| 331 | 331 | protected function normalizeEntryString( array $entry, $key ) |
| 332 | 332 | { |
| 333 | - if( isset( $entry[$key] )) { |
|
| 333 | + if( isset($entry[$key]) ) { |
|
| 334 | 334 | $entry[$key] = $this->getEntryString( $entry, $key ); |
| 335 | 335 | } |
| 336 | 336 | return $entry; |
@@ -344,11 +344,11 @@ discard block |
||
| 344 | 344 | $defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' ); |
| 345 | 345 | $strings = array_filter( $strings, 'is_array' ); |
| 346 | 346 | foreach( $strings as &$string ) { |
| 347 | - $string['type'] = isset( $string['p1'] ) ? 'plural' : 'single'; |
|
| 347 | + $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
|
| 348 | 348 | $string = wp_parse_args( $string, $defaultString ); |
| 349 | 349 | } |
| 350 | 350 | return array_filter( $strings, function( $string ) { |
| 351 | - return !empty( $string['id'] ); |
|
| 351 | + return !empty($string['id']); |
|
| 352 | 352 | }); |
| 353 | 353 | } |
| 354 | 354 | |