예제 #1
0
 // toss out those @$%^&* newlines
 if ($pl["body"] == "") {
     break;
 }
 $log->debug("[{$section}] XMPP message recieved! \"" . $pl["body"] . "\"");
 // check gateway health - if unhealthy, we are not going to be able to send
 if (!$gateway->health_check($force = true)) {
     $conn->message($config[$section]["xmpp_reciever"], $body = "Message undeliverable, gateway is currently unhealthy.");
     break;
 }
 // TODO: input validation here!
 // fetch number & message then send
 if (preg_match("/^([+0-9]*)[:]*\\s([\\S\\s]*)\$/", $pl["body"], $matches)) {
     $phone = $matches[1];
     $body = $matches[2];
     if ($gateway->message_send($phone, $body)) {
         $log->debug("[{$section}] Message delivered successfully");
     } else {
         $log->warning("[{$section}] Unable to deliver message from XMPP to gateway.");
         $conn->message($config[$section]["xmpp_reciever"], $body = "Message undeliverable, gateway is currently unhealthy.");
     }
     // save number as current chat destinatoin
     $conn->message($config[$section]["xmpp_reciever"], $body = "Chat target has changed, you are now talking to {$phone}, all unaddressed replies will go to this recipient.", $subject = $phone);
     $current_chat = $phone;
 } else {
     if (!$current_chat) {
         $conn->message($pl["from"], $body = "Unable to send - please specify destination phone number using syntax \"+XXXXXXX my message\"");
     } else {
         // we know the current chat name, so just send the string to them
         $gateway->message_send($current_chat, $pl["body"]);
     }