74

Editing a SMS

Code

Take a look at the file filtersms.php in the folder library:

filtersms

  1. function filtersms($s) {
  2.     $charset7bit = "@£\$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà";
  3.     $charset7bitext = "\f^{}\\[~]|€";
  4.  
  5.     $s = preg_replace('/\R/', "\r\n", trimsms($s));
  6.  
  7.     if (preg_match('/[^' . preg_quote($charset7bit . $charset7bitext, '/') . ']/', $s)) {
  8.         $coding='16bit';
  9.         $maxlen=70;
  10.         $extlen=67;
  11.     }
  12.     else {
  13.         $coding='7bit';
  14.         $maxlen=160;
  15.         $extlen=153;
  16.  
  17.         $s = preg_replace('/([' . preg_quote($charset7bitext, '/') . '])/u', "\e\\1", $s);
  18.     }
  19.  
  20.     $msglen = mb_strlen($s, 'UTF-8');
  21.  
  22.     if ($msglen > $maxlen) {
  23.         $count = 1 + floor($msglen / $extlen);
  24.         $len = $count * $extlen;
  25.     }
  26.     else {
  27.         $count = 1;
  28.         $len = $maxlen;
  29.     }
  30.  
  31.     return array($s, $coding, $msglen, $count, $len);
  32. }
  33.  
  34. function trimsms($s) {
  35.     return preg_replace('/ *(\R)+/', '\1', preg_replace('/^ /m', '', preg_replace('/[ \t]+/', ' ', trim($s))));
  36. }

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:

  1.         case 'sms':
  2.             $text = $c['text'];
  3.             if ($text) {
  4.                 require_once 'filtersms.php';
  5.  
  6.                 list(, $coding, $msglen, $count, $len)=filtersms($text);
  7.  
  8.                 echo '<div class="sms">', PHP_EOL;
  9.                 echo '<p id="sms_params">', PHP_EOL;
  10.                 echo "$msglen / $len &nbsp;-&nbsp $count SMS $coding", PHP_EOL;
  11.                 echo '</p>', PHP_EOL;
  12.                 echo '<p>', nl2br(htmlspecialchars($text, ENT_COMPAT, 'UTF-8')), '</p>', PHP_EOL;
  13.                 echo '</div>', PHP_EOL;
  14.             }
  15.             break;

Modify the view smseditor in English and in French in the files views/en/smseditor.phtml and views/fr/smseditor.phtml:

  1. <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>
  2. <p id="sms_params">
  3. <span id="sms_msglen"><?php echo $sms_msglen; ?></span>
  4. /
  5. <span id="sms_len"><?php echo $sms_len; ?></span>
  6. &nbsp;-&nbsp;
  7. <span id="sms_count"><?php echo $sms_count; ?></span>
  8. SMS
  9. <span id="sms_coding"><?php echo $sms_coding; ?></span>
  10. </p>
  1. <?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:

  1. require_once 'filtersms.php';
  1.             if (isset($_POST['sms_text'])) {
  2.                 $sms_text=trimsms(readarg($_POST['sms_text'], false, false));   // don't trim and DON'T strip!
  3.             }
  1.     list(, $sms_coding, $sms_msglen, $sms_count, $sms_len)=filtersms($sms_text);
  1.     $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:

#sms_params {font-size:small;}
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
  1. /izendsms.com
    1. blocks
      1. smseditor.php
    2. css
      1. theme.css
    3. views
      1. filtersms.phtml
      2. nodecontent.phtml
      3. en
        1. smseditor.phtml
      4. fr
        1. smseditor.phtml

Commit this version:

$ git status
$ git add blocks css/theme.css views
$ git commit -m'Shows message properties when editing or displaying a SMS'

Managing the campaign thread, OVHcloud SMS API

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].