@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | public function __construct() |
| 38 | 38 | { |
| 39 | - if( $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE )) { |
|
| 40 | - $cookie = explode( static::DELIMITER, stripslashes( $cookieId )); |
|
| 39 | + if( $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE ) ) { |
|
| 40 | + $cookie = explode( static::DELIMITER, stripslashes( $cookieId ) ); |
|
| 41 | 41 | $this->sessionId = preg_replace( '/[^A-Za-z0-9_]/', '', $cookie[0] ); |
| 42 | 42 | $this->expiryTimestamp = absint( $cookie[1] ); |
| 43 | 43 | $this->expiryTimestampReset = absint( $cookie[2] ); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function deleteExpiredSessions( $limit = 1000 ) |
| 78 | 78 | { |
| 79 | - if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ))) { |
|
| 79 | + if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ) ) ) { |
|
| 80 | 80 | glsr( SqlQueries::class )->deleteExpiredSessions( $expiredSessions ); |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -90,11 +90,11 @@ discard block |
||
| 90 | 90 | public function get( $key, $fallback = '', $unset = false ) |
| 91 | 91 | { |
| 92 | 92 | $key = sanitize_key( $key ); |
| 93 | - $value = isset( $this->sessionData[$key] ) |
|
| 93 | + $value = isset($this->sessionData[$key]) |
|
| 94 | 94 | ? maybe_unserialize( $this->sessionData[$key] ) |
| 95 | 95 | : $fallback; |
| 96 | - if( isset( $this->sessionData[$key] ) && $unset ) { |
|
| 97 | - unset( $this->sessionData[$key] ); |
|
| 96 | + if( isset($this->sessionData[$key]) && $unset ) { |
|
| 97 | + unset($this->sessionData[$key]); |
|
| 98 | 98 | $this->updateSession(); |
| 99 | 99 | } |
| 100 | 100 | return $value; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | protected function deleteSession() |
| 129 | 129 | { |
| 130 | 130 | delete_option( $this->getSessionId() ); |
| 131 | - delete_option( $this->getSessionId( 'expires' )); |
|
| 131 | + delete_option( $this->getSessionId( 'expires' ) ); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | protected function generateSessionId() |
| 138 | 138 | { |
| 139 | - return md5(( new PasswordHash( 8, false ))->get_random_bytes( 32 )); |
|
| 139 | + return md5( (new PasswordHash( 8, false ))->get_random_bytes( 32 ) ); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | protected function getExpiredSessions( $limit ) |
| 147 | 147 | { |
| 148 | 148 | $expiredSessions = []; |
| 149 | - $sessions = glsr( SqlQueries::class )->getExpiredSessions( static::SESSION_COOKIE, absint( $limit )); |
|
| 150 | - if( !empty( $sessions )) { |
|
| 149 | + $sessions = glsr( SqlQueries::class )->getExpiredSessions( static::SESSION_COOKIE, absint( $limit ) ); |
|
| 150 | + if( !empty($sessions) ) { |
|
| 151 | 151 | $now = time(); |
| 152 | 152 | foreach( $sessions as $session ) { |
| 153 | 153 | if( $now <= $session->expiration )continue; |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | protected function getSessionId( $separator = '' ) |
| 166 | 166 | { |
| 167 | - return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] )); |
|
| 167 | + return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] ) ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | { |
| 196 | 196 | if( headers_sent() )return; |
| 197 | 197 | $cookie = $this->sessionId.static::DELIMITER.$this->expiryTimestamp.static::DELIMITER.$this->expiryTimestampReset; |
| 198 | - $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ))); |
|
| 198 | + $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ) ) ); |
|
| 199 | 199 | setcookie( static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath ); |
| 200 | 200 | } |
| 201 | 201 | |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | protected function updateSession() |
| 215 | 215 | { |
| 216 | - if( false === get_option( $this->getSessionId() )) { |
|
| 216 | + if( false === get_option( $this->getSessionId() ) ) { |
|
| 217 | 217 | return $this->createSession(); |
| 218 | 218 | } |
| 219 | 219 | update_option( $this->getSessionId(), $this->sessionData, false ); |
@@ -150,7 +150,9 @@ discard block |
||
| 150 | 150 | if( !empty( $sessions )) { |
| 151 | 151 | $now = time(); |
| 152 | 152 | foreach( $sessions as $session ) { |
| 153 | - if( $now <= $session->expiration )continue; |
|
| 153 | + if( $now <= $session->expiration ) { |
|
| 154 | + continue; |
|
| 155 | + } |
|
| 154 | 156 | $expiredSessions[] = $session->name; |
| 155 | 157 | $expiredSessions[] = str_replace( '_expires_', '_', $session->name ); |
| 156 | 158 | } |
@@ -193,7 +195,9 @@ discard block |
||
| 193 | 195 | */ |
| 194 | 196 | protected function setCookie() |
| 195 | 197 | { |
| 196 | - if( headers_sent() )return; |
|
| 198 | + if( headers_sent() ) { |
|
| 199 | + return; |
|
| 200 | + } |
|
| 197 | 201 | $cookie = $this->sessionId.static::DELIMITER.$this->expiryTimestamp.static::DELIMITER.$this->expiryTimestampReset; |
| 198 | 202 | $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ))); |
| 199 | 203 | setcookie( static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath ); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | public function __construct() |
| 34 | 34 | { |
| 35 | 35 | $types = glsr( OptionManager::class )->get( 'settings.general.notifications', [] ); |
| 36 | - $this->email = count( array_intersect( ['admin', 'custom'], $types )) > 0; |
|
| 36 | + $this->email = count( array_intersect( ['admin', 'custom'], $types ) ) > 0; |
|
| 37 | 37 | $this->slack = in_array( 'slack', $types ); |
| 38 | 38 | $this->types = $types; |
| 39 | 39 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function send( Review $review ) |
| 45 | 45 | { |
| 46 | - if( empty( $this->types ))return; |
|
| 46 | + if( empty($this->types) )return; |
|
| 47 | 47 | $this->review = $review; |
| 48 | 48 | $args = [ |
| 49 | 49 | 'link' => $this->getLink(), |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | protected function buildEmail( array $args ) |
| 60 | 60 | { |
| 61 | - return glsr( Email::class )->compose([ |
|
| 61 | + return glsr( Email::class )->compose( [ |
|
| 62 | 62 | 'to' => $this->getEmailAddresses(), |
| 63 | 63 | 'subject' => $args['title'], |
| 64 | 64 | 'template' => 'email-notification', |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | 'review_rating' => $this->review->rating, |
| 72 | 72 | 'review_title' => $this->review->title, |
| 73 | 73 | ], |
| 74 | - ]); |
|
| 74 | + ] ); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | 'button_url' => $args['link'], |
| 84 | 84 | 'fallback' => $this->buildEmail( $args )->read( 'plaintext' ), |
| 85 | 85 | 'pretext' => $args['title'], |
| 86 | - ]); |
|
| 86 | + ] ); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -92,23 +92,23 @@ discard block |
||
| 92 | 92 | protected function getEmailAddresses() |
| 93 | 93 | { |
| 94 | 94 | $emails = []; |
| 95 | - if( in_array( 'admin', $this->types )) { |
|
| 95 | + if( in_array( 'admin', $this->types ) ) { |
|
| 96 | 96 | $emails[] = get_option( 'admin_email' ); |
| 97 | 97 | } |
| 98 | - if( in_array( 'author', $this->types )) { |
|
| 99 | - $assignedPost = get_post( intval( $this->review->assigned_to )); |
|
| 98 | + if( in_array( 'author', $this->types ) ) { |
|
| 99 | + $assignedPost = get_post( intval( $this->review->assigned_to ) ); |
|
| 100 | 100 | if( $assignedPost instanceof WP_Post ) { |
| 101 | 101 | $this->email = true; |
| 102 | - $emails[] = get_the_author_meta( 'user_email', intval( $assignedPost->post_author )); |
|
| 102 | + $emails[] = get_the_author_meta( 'user_email', intval( $assignedPost->post_author ) ); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | - if( in_array( 'custom', $this->types )) { |
|
| 105 | + if( in_array( 'custom', $this->types ) ) { |
|
| 106 | 106 | $customEmails = glsr( OptionManager::class )->get( 'settings.general.notification_email' ); |
| 107 | 107 | $customEmails = str_replace( [' ', ',', ';'], ',', $customEmails ); |
| 108 | 108 | $customEmails = explode( ',', $customEmails ); |
| 109 | 109 | $emails = array_merge( $emails, $customEmails ); |
| 110 | 110 | } |
| 111 | - $emails = array_filter( array_keys( array_flip( $emails ))); |
|
| 111 | + $emails = array_filter( array_keys( array_flip( $emails ) ) ); |
|
| 112 | 112 | return apply_filters( 'site-reviews/notification/emails', $emails, $this->review ); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -125,16 +125,16 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | protected function getTitle() |
| 127 | 127 | { |
| 128 | - $assignedTitle = get_the_title( intval( $this->review->assigned_to )); |
|
| 128 | + $assignedTitle = get_the_title( intval( $this->review->assigned_to ) ); |
|
| 129 | 129 | $title = _nx( |
| 130 | 130 | 'New %s-star review', |
| 131 | 131 | 'New %s-star review of: %s', |
| 132 | - intval( empty( $assignedTitle )), |
|
| 132 | + intval( empty($assignedTitle) ), |
|
| 133 | 133 | 'This string differs depending on whether or not the review has been assigned to a post.', |
| 134 | 134 | 'site-reviews' |
| 135 | 135 | ); |
| 136 | 136 | $title = sprintf( '[%s] %s', |
| 137 | - wp_specialchars_decode( strval( get_option( 'blogname' )), ENT_QUOTES ), |
|
| 137 | + wp_specialchars_decode( strval( get_option( 'blogname' ) ), ENT_QUOTES ), |
|
| 138 | 138 | sprintf( $title, $this->review->rating, $assignedTitle ) |
| 139 | 139 | ); |
| 140 | 140 | return apply_filters( 'site-reviews/notification/title', $title, $this->review ); |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | { |
| 148 | 148 | $email = $this->buildEmail( $args ); |
| 149 | 149 | if( !$this->email )return; |
| 150 | - if( empty( $email->to )) { |
|
| 150 | + if( empty($email->to) ) { |
|
| 151 | 151 | glsr_log()->error( 'Email notification was not sent (missing email address)' ); |
| 152 | 152 | return; |
| 153 | 153 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | if( !$this->slack )return; |
| 165 | 165 | $notification = $this->buildSlackNotification( $args ); |
| 166 | 166 | $result = $notification->send(); |
| 167 | - if( is_wp_error( $result )) { |
|
| 167 | + if( is_wp_error( $result ) ) { |
|
| 168 | 168 | $notification->review = null; |
| 169 | 169 | glsr_log()->error( $result->get_error_message() )->debug( $notification ); |
| 170 | 170 | } |
@@ -43,7 +43,9 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function send( Review $review ) |
| 45 | 45 | { |
| 46 | - if( empty( $this->types ))return; |
|
| 46 | + if( empty( $this->types )) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 47 | 49 | $this->review = $review; |
| 48 | 50 | $args = [ |
| 49 | 51 | 'link' => $this->getLink(), |
@@ -146,7 +148,9 @@ discard block |
||
| 146 | 148 | protected function sendToEmail( array $args ) |
| 147 | 149 | { |
| 148 | 150 | $email = $this->buildEmail( $args ); |
| 149 | - if( !$this->email )return; |
|
| 151 | + if( !$this->email ) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 150 | 154 | if( empty( $email->to )) { |
| 151 | 155 | glsr_log()->error( 'Email notification was not sent (missing email address)' ); |
| 152 | 156 | return; |
@@ -161,7 +165,9 @@ discard block |
||
| 161 | 165 | */ |
| 162 | 166 | protected function sendToSlack( array $args ) |
| 163 | 167 | { |
| 164 | - if( !$this->slack )return; |
|
| 168 | + if( !$this->slack ) { |
|
| 169 | + return; |
|
| 170 | + } |
|
| 165 | 171 | $notification = $this->buildSlackNotification( $args ); |
| 166 | 172 | $result = $notification->send(); |
| 167 | 173 | if( is_wp_error( $result )) { |