Editing a SMS
Code
Take a look at the file filtersms.php in the folder library:
- function filtersms($s) {
- $charset7bit = "@£\$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà";
- $charset7bitext = "\f^{}\\[~]|€";
- $s = preg_replace('/\R/', "\r\n", trimsms($s));
- if (preg_match('/[^' . preg_quote($charset7bit . $charset7bitext, '/') . ']/', $s)) {
- $coding='16bit';
- $maxlen=70;
- $extlen=67;
- }
- else {
- $coding='7bit';
- $maxlen=160;
- $extlen=153;
- $s = preg_replace('/([' . preg_quote($charset7bitext, '/') . '])/u', "\e\\1", $s);
- }
- $msglen = mb_strlen($s, 'UTF-8');
- if ($msglen > $maxlen) {
- $count = 1 + floor($msglen / $extlen);
- $len = $count * $extlen;
- }
- else {
- $count = 1;
- $len = $maxlen;
- }
- return array($s, $coding, $msglen, $count, $len);
- }
- function trimsms($s) {
- return preg_replace('/ *(\R)+/', '\1', preg_replace('/^ /m', '', preg_replace('/[ \t]+/', ' ', trim($s))));
- }
filtersms returns an array containing the text $s normalized for sending by SMS, the character encoding, the text length, the number of SMS messages required and the maximum number of characters available before an additional SMS message is required.
Edit the file views/nodecontent.phtml:
- case 'sms':
- $text = $c['text'];
- if ($text) {
- require_once 'filtersms.php';
- list(, $coding, $msglen, $count, $len)=filtersms($text);
- echo '<div class="sms">', PHP_EOL;
- echo '<p id="sms_params">', PHP_EOL;
- echo "$msglen / $len -  $count SMS $coding", PHP_EOL;
- echo '</p>', PHP_EOL;
- echo '<p>', nl2br(htmlspecialchars($text, ENT_COMPAT, 'UTF-8')), '</p>', PHP_EOL;
- echo '</div>', PHP_EOL;
- }
- break;
Modify the view smseditor in English and in French in the files views/en/smseditor.phtml and views/fr/smseditor.phtml:
- <textarea id="sms_text" name="sms_text" cols="80" rows="5" title="SMS" placeholder="" onkeyup="return filtersms()"><?php if ($sms_text): ?><?php echo htmlspecialchars($sms_text, ENT_COMPAT, 'UTF-8'); ?><?php endif; ?></textarea>
- <p id="sms_params">
- <span id="sms_msglen"><?php echo $sms_msglen; ?></span>
- /
- <span id="sms_len"><?php echo $sms_len; ?></span>
- -
- <span id="sms_count"><?php echo $sms_count; ?></span>
- SMS
- <span id="sms_coding"><?php echo $sms_coding; ?></span>
- </p>
- <?php require VIEWS_DIR . DIRECTORY_SEPARATOR . 'filtersms.phtml'; ?>
Create the file filtersms.phtml in the folder views:
The modification to the version in French is identical:
Edit the file blocks/smseditor.php:
- require_once 'filtersms.php';
- if (isset($_POST['sms_text'])) {
- $sms_text=trimsms(readarg($_POST['sms_text'], false, false)); // don't trim and DON'T strip!
- }
- list(, $sms_coding, $sms_msglen, $sms_count, $sms_len)=filtersms($sms_text);
- $output = view('smseditor', $lang, compact('clang', 'inlanguages', 'sms_modified', 'sms_title', 'sms_cloud', 'sms_subject', 'sms_text', 'sms_msg', 'sms_coding', 'sms_msglen', 'sms_count', 'sms_len', 'errors'));
Add the CSS for the display of the SMS properties at the end of the file css/theme.css:
Test
Connect
with the identifier barfoo.
Display
the campaign The web engine.
Message
98 / 160 - 1 SMS 7bit
Create your multimedia website in a few minutes with iZend - The web engine: https://www.izend.org
Edit
the campaign.
Message:
98 / 160 - 1 SMS 7bit
Click in the input area of the SMS at the end of the line. The counter is at 98. Press Enter twice to add a blank line. The counter doesn't change.
Type Make.
As soon as you have typed the M, the counter jumped to 101, 98 + 2 x the 2 characters CR (CARRIAGE RETURN) and LF (LINEFEED) for the two end of lines + 1 for the M. The counter is at 104.
Type a space. The counter doesn't change.
Enter a $ (DOLLAR). The counter jumps to 106, 1 for the space + 1 for the $.
Replace the $ with a € (EURO). The counter jumps to 107. 1 € takes 2 characters.
Add spaces between words, at the beginning or at the end of lines. The counter doesn't change.
Add the line Привет, мир!.
The SMS switches to 16bit encoding. Sending the message will take 2 SMS of 67 characters maximum each.
Press Configure to check that the code in PHP does the same calculations.
Display
the campaign.
Git
- /izendsms.com
- blocks
- smseditor.php
- css
- theme.css
- views
- filtersms.phtml
- nodecontent.phtml
- en
- smseditor.phtml
- fr
- smseditor.phtml
- blocks
Commit this version:
$ git status
$ git add blocks css/theme.css views
$ git commit -m'Shows message properties when editing or displaying a SMS'
Comments