Changeset 11823
- Timestamp:
- 05/10/2022 04:03:43 AM (3 years ago)
- Location:
- sites/trunk/api.wordpress.org/public_html/dotorg/helpscout
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/dotorg/helpscout/common.php
r11636 r11823 1 1 <?php 2 use WordPressdotorg\API\HelpScout\API as Helpscout_API; 2 3 3 $wp_init_host = 'https:// wordpress.org/';4 $wp_init_host = 'https://api.wordpress.org/'; 4 5 $base_dir = dirname( dirname( __DIR__ ) ); 5 6 require( $base_dir . '/wp-init.php' ); 7 8 include_once __DIR__ . '/class-helpscout.php'; 6 9 7 10 // function to verify signature from HelpScout … … 14 17 15 18 return hash_equals( $signature, $calculated ); 19 } 20 21 function get_user_email_for_email( $request ) { 22 $email = $request->customer->email ?? false; 23 $subject = $request->ticket->subject ?? ''; 24 $user = get_user_by( 'email', $email ); 25 26 // Ignore @wordpress.org "users", unless it's literally the only match (The ?? $email fallback at the end). 27 if ( $user && str_ends_with( $user->user_email, '@wordpress.org' ) ) { 28 $user = false; 29 } 30 31 // If this is related to a slack user, fetch their details instead. 32 if ( 33 false !== stripos( $email, 'slack' ) && 34 preg_match( '/(\S+)@chat.wordpress.org/i', $subject, $m ) 35 ) { 36 $user = get_user_by( 'slug', $m[1] ); 37 } 38 39 // Determine if this is a bounce, and if so, find out who for. 40 if ( ! $user && $email && isset( $request->ticket->id ) ) { 41 $from = strtolower( $email . ' ' . ( $request->customer->fname ?? '' ) . ' ' . $request->customers->lname ); 42 if ( 43 str_contains( $from, 'mail delivery' ) || 44 str_contains( $from, 'postmaster' ) || 45 str_contains( strtolower( $subject ), 'undelivered mail' ) || 46 str_contains( strtolower( $subject ), 'returned to sender') 47 ) { 48 // Fetch the email. 49 $email_obj = Helpscout_API::api( '/v2/conversations/' . $request->ticket->id . '?embed=threads' ); 50 if ( ! empty( $email_obj->_embedded->threads ) ) { 51 foreach ( $email_obj->_embedded->threads as $thread ) { 52 if ( 'customer' !== $thread->type ) { 53 continue; 54 } 55 56 // Extract emails from the mailer-daemon. 57 $email_body = strip_tags( str_replace( '<br>', "\n", $thread->body ) ); 58 59 // Extract `To:`, `X-Orig-To:`, and fallback to all emails. 60 $emails = []; 61 if ( preg_match( '!^(x-orig-to:|to:)\s*(.+@.+)$!im', $email_body, $m ) ) { 62 $emails = [ trim( $m[2], '<> ' ) ]; 63 } else { 64 // Ugly regex for emails, but it's good for mailer-daemon emails. 65 if ( preg_match_all( '![^\s;"]+@[^\s;&"]+\.[^\s;&"]+!', $email_body, $m ) ) { 66 $emails = array_unique( array_diff( $m[0], [ $request->mailbox->email ] ) ); 67 } 68 } 69 70 foreach ( $emails as $maybe_email ) { 71 $user = get_user_by( 'email', $maybe_email ); 72 if ( $user ) { 73 break; 74 } 75 } 76 } 77 } 78 } 79 } 80 81 return $user->user_email ?? $email; 16 82 } 17 83 … … 31 97 32 98 // get the info from HS 33 $data = json_decode( $data ); 34 35 // If this is related to a slack user, fetch their details instead. 36 if ( 37 isset ( $data->customer->email, $data->ticket->subject ) && 38 false !== stripos( $data->customer->email, 'slack' ) && 39 preg_match( '/(\S+)@chat.wordpress.org/i', $data->ticket->subject, $m ) 40 ) { 41 $user = get_user_by( 'slug', $m[1] ); 42 if ( $user ) { 43 $data->customer->email = $user->user_email; 44 } 45 } 46 47 return $data; 99 return json_decode( $data ); -
sites/trunk/api.wordpress.org/public_html/dotorg/helpscout/dpo.php
r10957 r11823 14 14 // default empty output 15 15 $html = ''; 16 $email = $request->customer->email;16 $email = get_user_email_for_email( $request ); 17 17 18 18 $html .= sprintf( -
sites/trunk/api.wordpress.org/public_html/dotorg/helpscout/forums.php
r11296 r11823 6 6 7 7 // default empty output 8 $html = '';8 $html = ''; 9 9 // look up profile url by email 10 $user = get_user_by( 'email', $request->customer->email ); 10 $email = get_user_email_for_email( $request ); 11 $user = get_user_by( 'email', $email ); 11 12 12 13 // Include Notes -
sites/trunk/api.wordpress.org/public_html/dotorg/helpscout/plugins-themes.php
r11296 r11823 7 7 // default empty output 8 8 $html = ''; 9 9 10 // look up profile url by email 10 $user = get_user_by( 'email', $request->customer->email ); 11 $email = get_user_email_for_email( $request ); 12 $user = get_user_by( 'email', $email ); 13 11 14 if ( ! $user ) { 12 15 echo json_encode( array( 'html' => $html ) ); -
sites/trunk/api.wordpress.org/public_html/dotorg/helpscout/profile.php
r11296 r11823 8 8 $html = ''; 9 9 $user = false; 10 $email = get_user_email_for_email( $request ); 10 11 11 12 // Look up a user based on email address 12 if ( isset ( $request->customer->email )) {13 if ( $email ) { 13 14 14 15 // look up profile url by email 15 $user = get_user_by( 'email', $request->customer->email ); 16 $user = get_user_by( 'email', $email ); 17 16 18 if ( isset( $user->user_nicename ) ) { 17 19 $html .= '<p>Profile: <a href="https://profiles.wordpress.org/' . $user->user_nicename . '/">'. $user->user_nicename .'</a></p>';
Note: See TracChangeset
for help on using the changeset viewer.