'SMS Framework', 'name' => t('SMS'), 'group' => 'sms', // Class of send method 'type' => MESSAGING_TYPE_SEND, 'glue' => ' ', 'description' => t('Send SMS using SMS Framework.'), 'render callback' => 'messaging_sms_render', 'send callback' => 'messaging_sms_send_msg', 'destination callback' => 'messaging_sms_user_destination', ); return $info; } } /** * Message Render callback */ function messaging_sms_render($message, $info) { // We need to apply filtering first or run through the render function $message = messaging_message_render($message, $info); // We can assume that we'll get max 110 characters for subject + body // Because from and data take up about 50 characters and total character limit // subject + from + date + body < 160 $message->subject = messaging_sms_truncate($message->subject, 40); $message->body = messaging_sms_truncate($message->body, (110 - drupal_strlen($message->subject))); return $message; } /** * Send mail message to user account */ function messaging_sms_user_destination($account, $message) { // Check for active mobile infomation. Simply return it so that the send // callback has a destination array and access everything. if (!empty($account->sms_user) && $account->sms_user[0]['status'] == 2) { return $account->sms_user[0]; } } /** * Send message to multiple destinations * * This is just a wrapper for sms_send() */ function messaging_sms_send_msg($destination, $message, $params = array()) { if (!empty($destination['number']) && !empty($destination['gateway'])) { $text = $message->subject; $text = !empty($text) && !empty($message->body) ? ' ' : ''; $text .= $message->body; return sms_send($destination['number'], $text, $destination['gateway']); } else { return FALSE; } } /** * Truncate messages to 160 Characters. Adapted from node_teaser() in node.module */ function messaging_sms_truncate($text, $length = 160) { // If we have a short message, return the message if (strlen($text) < $length) { return $text; } // Initial slice. $teaser = truncate_utf8($text, $length); $position = 0; // Cache the reverse of the message. $reversed = strrev($teaser); // split at paragraph boundaries. $breakpoints = array('
' => 0, '