Changeset 5446 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/clients/class-slack.php
- Timestamp:
- 04/30/2017 04:20:16 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/clients/class-slack.php
r4223 r5446 21 21 * @var array 22 22 */ 23 private $attachment = array();23 private $attachment = []; 24 24 25 25 /** … … 28 28 * @var array 29 29 */ 30 private $text = array(); 30 private $text = []; 31 32 /** 33 * Holds Emoji codes for success. 34 * 35 * @var array 36 */ 37 private $success_emoji = [ 38 ':green_heart:', ':white_check_mark:', ':smiley:', ':ok: ', 39 ]; 40 41 /** 42 * Holds Emoji codes for failure. 43 * 44 * @var array 45 */ 46 private $failure_emoji = [ 47 ':broken_heart:', ':umbrella_with_rain_drops:', ':cry:', ':sos:', 48 ]; 31 49 32 50 /** … … 63 81 * 64 82 * @param string $key Key of the attachment property. 65 * @param string$value Value of the attachment property.83 * @param mixed $value Value of the attachment property. 66 84 */ 67 85 public function add_attachment( $key, $value ) { … … 98 116 99 117 /** 118 * Returns a random emoji for a failure message. 119 * 120 * @return string Emoji code. 121 */ 122 public function get_failure_emoji() { 123 $index = array_rand( $this->failure_emoji, 1 ); 124 return $this->failure_emoji[ $index ]; 125 } 126 127 /** 128 * Returns a random emoji for a success message. 129 * 130 * @return string Emoji code. 131 */ 132 public function get_success_emoji() { 133 $index = array_rand( $this->success_emoji, 1 ); 134 return $this->success_emoji[ $index ]; 135 } 136 137 /** 100 138 * Publishes a Slack notifcation to a channel. 101 139 * … … 105 143 public function send( $channel ) { 106 144 $text = $this->get_text(); 107 if ( empty( $text ) ) {108 return false;145 if ( ! empty( $text ) ) { 146 $this->add_attachment( 'text', $text ); 109 147 } 110 148 111 $this->add_attachment( 'text', $text ); 112 $this->add_attachment( 'mrkdwn_in', array( 'text' ) ); 149 $this->add_attachment( 'mrkdwn_in', [ 'text', 'fields' ] ); 113 150 114 $payload = array(151 $payload = [ 115 152 'icon_emoji' => ':wordpress:', 116 153 'username' => 'Plugin Imports', 117 154 'channel' => $channel, 118 155 'attachments' => $this->get_attachments(), 119 );156 ]; 120 157 121 158 $payload = json_encode( $payload ); 122 159 $content = http_build_query( compact( 'payload' ) ); 123 160 124 $context = stream_context_create( array(125 'http' => array(161 $context = stream_context_create( [ 162 'http' => [ 126 163 'method' => 'POST', 127 164 'header' => 'Content-Type: application/x-www-form-urlencoded' . PHP_EOL, 128 165 'content' => $content, 129 ),130 ));166 ], 167 ] ); 131 168 132 169 $this->flush(); … … 139 176 */ 140 177 public function flush() { 141 $this->text = array();142 $this->attachment = array();178 $this->text = []; 179 $this->attachment = []; 143 180 } 144 181 }
Note: See TracChangeset
for help on using the changeset viewer.