t('SMS'), 'send' => 'messaging_sms_send', 'type' => MESSAGING_TYPE_PUSH, 'render' => 'messaging_sms_render', 'glue' => "--", ); return $info; } } /** * Message Render callback */ function messaging_sms_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 $text = messaging_sms_truncate($message['subject'],40); $message['body'] = $text . $info['glue'] . messaging_sms_truncate("Learn More: " . $GLOBALS['base_url'],(110 - strlen($text))); return $message['body']; } /** * Send mail message to user account */ function messaging_sms_send($account, $message) { if ($account->sms_user['status'] == 2) { $destination->number = $account->sms_user['number']; foreach ($account->sms_user['gateway'] as $key => $field) { $destination->$key = $field; } $destinations[] = $destination; } return sms_send($destinations, $message); } /** * Truncate messages to 160 Characters. Adapted from node_teaser() in node.module */ function messaging_sms_truncate($message,$length = 160) { // If we have a short message, return the message if (strlen($message) < $length) { return $message; } // Initial slice. $teaser = truncate_utf8($message, $length); $position = 0; // Cache the reverse of the message. $reversed = strrev($teaser); // split at paragraph boundaries. $breakpoints = array('

' => 0, '
' => 6, '
' => 4, "\n" => 1); // We use strpos on the reversed needle and haystack for speed. foreach ($breakpoints as $point => $offset) { $length = strpos($reversed, strrev($point)); if ($length !== FALSE) { $position = - $length - $offset; return ($position == 0) ? $teaser : substr($teaser, 0, $position); } } // When even the first paragraph is too long, we try to split at the end of // the last full sentence. $breakpoints = array('. ' => 1, '! ' => 1, '? ' => 1, ' ' => 0); $min_length = strlen($reversed); foreach ($breakpoints as $point => $offset) { $length = strpos($reversed, strrev($point)); if ($length !== FALSE) { $min_length = min($length, $min_length); $position = 0 - $length - $offset; } } return ($position == 0) ? $teaser : substr($teaser, 0, $position); }