mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-21 00:46:27 +02:00
fix utf8 chars in sms and add tool to quota to check if a text is gsm0338 compatible
This commit is contained in:
parent
a39c9577b1
commit
d826762e9d
2 changed files with 32 additions and 7 deletions
|
@ -108,14 +108,13 @@ class Quota extends StandardController
|
|||
}
|
||||
|
||||
/**
|
||||
* Compute how many credit a message represent
|
||||
* this function count 160 chars per SMS if it can be send as GSM 03.38 encoding and 70 chars per SMS if it can only be send as UTF8.
|
||||
* Check if a message can be encoded as gsm0338 or if it must be UTF8
|
||||
*
|
||||
* @param string $text : Message to send
|
||||
*
|
||||
* @return int : Number of credit to send this message
|
||||
* @return bool : True if gsm0338, false if UTF8
|
||||
*/
|
||||
public static function compute_credits_for_message($text)
|
||||
public static function is_gsm0338($text)
|
||||
{
|
||||
//Gsm 03.38 charset to detect if message is compatible or must use utf8
|
||||
$gsm0338 = [
|
||||
|
@ -144,12 +143,26 @@ class Quota extends StandardController
|
|||
{
|
||||
if (!in_array(mb_substr($text, $i, 1), $gsm0338))
|
||||
{
|
||||
$is_gsm0338 = false;
|
||||
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute how many credit a message represent
|
||||
* this function count 160 chars per SMS if it can be send as GSM 03.38 encoding and 70 chars per SMS if it can only be send as UTF8.
|
||||
*
|
||||
* @param string $text : Message to send
|
||||
*
|
||||
* @return int : Number of credit to send this message
|
||||
*/
|
||||
public static function compute_credits_for_message($text)
|
||||
{
|
||||
$len = mb_strlen($text);
|
||||
$is_gsm0338 = self::is_gsm0338($text);
|
||||
|
||||
return $is_gsm0338 ? ceil($len / 160) : ceil($len / 70);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue