Changeset 11952
- Timestamp:
- 07/08/2022 03:53:55 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/dotorg/slack/community-deputies-calendly-webhook.php
r11941 r11952 14 14 */ 15 15 function api_request( $url ) { 16 if ( ! $url ) { 17 return false; 18 } 19 16 20 $req = wp_remote_get( 17 21 $url, … … 22 26 ] 23 27 ); 28 24 29 return json_decode( wp_remote_retrieve_body( $req ) ); 25 30 } 26 31 27 32 // Check the request is valid. 28 if ( $_GET['secret'] !== COMMUNITY_CALENDLY_SECRET ) {33 if ( empty( $_GET['secret'] ) || $_GET['secret'] !== COMMUNITY_CALENDLY_SECRET ) { 29 34 die(); 30 35 } … … 42 47 43 48 // Check it's a valid and expected meeting type.. 49 $valid = false; 44 50 $valid_meeting_names = [ 45 'wordcamp orientation', 46 'wordcamp budget review', 51 'Meetup', 52 'WordCamp', 53 'do_action', 54 'Orientation', 55 'Budget Review', 47 56 ]; 48 if ( ! in_array( strtolower( $event_name ), $valid_meeting_names ) ) { 57 58 foreach ( $valid_meeting_names as $name ) { 59 if ( false !== stripos( $event_name, $name ) ) { 60 $valid = true; 61 break; 62 } 63 } 64 65 if ( ! $valid ) { 49 66 die(); 50 67 } … … 58 75 // Compile the questions.. 59 76 $questions_and_answers = array_merge( 60 wp_list_pluck( $routing_form_submission->questions_and_answers , 'answer', 'question' ),61 wp_list_pluck( $request_body_parsed->payload->questions_and_answers , 'answer', 'question' ),77 wp_list_pluck( $routing_form_submission->questions_and_answers ?? [], 'answer', 'question' ), 78 wp_list_pluck( $request_body_parsed->payload->questions_and_answers ?? [], 'answer', 'question' ), 62 79 ); 63 80 64 // Finally, localize the date and let Slack know.81 // Finally, compile some phrases needed, localised dates, event names, etc. 65 82 $timezone = $request_body_parsed->payload->timezone; 66 83 $date_time = new DateTime( "now", new DateTimeZone( $timezone ) ); 67 84 $date_time->setTimestamp( strtotime( $event_details->start_time ) ); 68 85 $localized_time = $date_time->format( 'g:ia l, F jS, Y' ); // 10:30am Thursday, July 7th, 2022. 86 87 // Suffix the timezone, as the localized time is timezone dependant. 88 $localized_time .= " ({$timezone})"; 89 90 $location = ''; 91 // Use the first question found that contains 'location' or 'WordCamp'. 92 // Forms use 'Location', 'Your WordCamp Location', and 'WordCamp Name'. 93 foreach ( $questions_and_answers as $question => $answer ) { 94 if ( 95 false !== stripos( $question, 'Location' ) || 96 false !== stripos( $question, 'WordCamp' ) 97 ) { 98 $location = $answer; 99 break; 100 } 101 } 102 103 // If the location isn't specified, use their Name instead, as it's likely an individual-specific meeting. 104 $location = $location ?: ( $questions_and_answers['Name'] ?? '' ); 105 $event_with_loc = $location ? "{$location} {$event_name}" : $event_name; 69 106 70 107 $send = new Send( SLACK_MESSAGE_WEBHOOK_URL ); … … 74 111 if ( 'invitee.created' === $event ) { 75 112 $send->set_text( 76 "*{$ questions_and_answers['Your WordCamp Location']} {$event_name} is scheduled!*\n" .77 "Assigned to {$assigned_to}. Starts at {$localized_time} ({$timezone})."113 "*{$event_with_loc} is scheduled!*\n" . 114 "Assigned to {$assigned_to}. Starts at {$localized_time}." 78 115 ); 79 116 } elseif ( 'invitee.canceled' === $event ) { 80 117 $reason_given = $request_body_parsed->payload->cancellation->reason ?: 'No reason provided'; 81 118 $send->set_text( 82 "*{$ questions_and_answers['Your WordCamp Location']} {$event_name} has been canceled.*\n" .83 "Canceled by {$request_body_parsed->payload->cancellation->canceled_by}: {$reason_given}, was scheduled for {$localized_time} ($timezone)."119 "*{$event_with_loc} has been canceled.*\n" . 120 "Canceled by {$request_body_parsed->payload->cancellation->canceled_by}: {$reason_given}, was scheduled for {$localized_time}." 84 121 ); 85 122 } else {
Note: See TracChangeset
for help on using the changeset viewer.