public static function say($message = '', $color = "green")
{
if (!c('HipChat.Token') || !c('HipChat.Account')) {
return;
}
// Prepare our API endpoint.
$url = sprintf('https://%1$s.hipchat.com/v2/room/%2$s/notification?auth_token=%3$s', c('HipChat.Account'), c('HipChat.Room'), c('HipChat.Token'));
$data = ["color" => $color, "message" => $message, "notify" => false, "message_format" => "html"];
$data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_exec($ch);
curl_close($ch);
}
/** * Post every new registration to HipChat. * * @param UserModel $sender * @param array $args */ public function userModel_afterInsertUser_handler($sender, $args) { // Determine how to link their name. $name = val('Name', $args['InsertFields']); if (c('Garden.Registration.Method') == 'Approval') { $user = anchor($name, '/user/applicants', '', array('WithDomain' => true)); $reason = sliceParagraph(val('DiscoveryText', $args['InsertFields'])); $message = sprintf(t('New member: %1$s (%2$s)'), $user, $reason); } else { // Use conservative name linking structure. $user = anchor($name, '/profile/' . $args['InsertUserID'] . '/' . $name, '', array('WithDomain' => true)); $message = sprintf(t('New member: %1$s'), $user); } // Say it. HipChat::say($message); }