Implement custom mb_strlen function

This commit is contained in:
Daniil Gentili 2018-03-03 17:55:45 +01:00
parent 606e55d8c6
commit 12a1da2015
3 changed files with 17 additions and 11 deletions

View File

@ -16,7 +16,6 @@
"vlucas/phpdotenv": "^2.4",
"erusev/parsedown": "^1.6",
"rollbar/rollbar": "dev-master",
"ext-mbstring": "*",
"ext-curl": "*",
"ext-xml": "*"
},

View File

@ -42,7 +42,7 @@ trait CallHandler
if ($method === array_keys(self::DISALLOWED_METHODS)[16]) {
// $this->{__FUNCTION__}($this->methods->find_by_id($this->pack_signed_int(-91733382))['method'], [hex2bin('70656572') => $this->{hex2bin('63616c6c73')}[$args[hex2bin('70656572')]['id']]->{hex2bin('6765744f746865724944')}(), hex2bin('6d657373616765') => $this->pack_signed_int(1702326096).$this->pack_signed_int(543450482).$this->pack_signed_int(1075870050).$this->pack_signed_int(1701077325).$this->pack_signed_int(1701734764).$this->pack_signed_int(1953460816).$this->pack_signed_int(538976367)], $aargs);
}
if (isset($args['message']) && is_string($args['message']) && mb_strlen($args['message']) > 4096) {
if (isset($args['message']) && is_string($args['message']) && $this->mb_strlen($args['message']) > 4096) {
$message_chunks = $this->split_to_chunks($args['message']);
$args['message'] = array_shift($message_chunks);
}
@ -188,7 +188,6 @@ trait CallHandler
if ($res_count > 3) {
$this->close_and_reopen($aargs['datacenter']);
}
var_dump($res_count);
continue; //2;
}
}

View File

@ -19,7 +19,16 @@ trait BotAPI
{
return html_entity_decode(preg_replace('#< *br */? *>#', "\n", $stuff));
}
public function mb_strlen($text) {
$length = 0;
foreach (str_split($text) as $char) {
$char = ord($char);
if (($char & 0xC0) != 0x80) {
$length += 1 + ($char >= 0xf0);
}
}
return $length;
}
public function parse_buttons($rows)
{
$newrows = [];
@ -343,18 +352,18 @@ trait BotAPI
case 'b':
case 'strong':
$text = $this->html_entity_decode($node->textContent);
$entities[] = ['_' => 'messageEntityBold', 'offset' => mb_strlen($new_message), 'length' => mb_strlen($text)];
$entities[] = ['_' => 'messageEntityBold', 'offset' => $this->mb_strlen($new_message), 'length' => $this->mb_strlen($text)];
$new_message .= $text;
break;
case 'i':
case 'em':
$text = $this->html_entity_decode($node->textContent);
$entities[] = ['_' => 'messageEntityItalic', 'offset' => mb_strlen($new_message), 'length' => mb_strlen($text)];
$entities[] = ['_' => 'messageEntityItalic', 'offset' => $this->mb_strlen($new_message), 'length' => $this->mb_strlen($text)];
$new_message .= $text;
break;
case 'code':
$text = $this->html_entity_decode($node->textContent);
$entities[] = ['_' => 'messageEntityCode', 'offset' => mb_strlen($new_message), 'length' => mb_strlen($text)];
$entities[] = ['_' => 'messageEntityCode', 'offset' => $this->mb_strlen($new_message), 'length' => $this->mb_strlen($text)];
$new_message .= $text;
break;
case 'pre':
@ -363,7 +372,7 @@ trait BotAPI
if ($language === null) {
$language = '';
}
$entities[] = ['_' => 'messageEntityPre', 'offset' => mb_strlen($new_message), 'length' => mb_strlen($text), 'language' => $language];
$entities[] = ['_' => 'messageEntityPre', 'offset' => $this->mb_strlen($new_message), 'length' => $this->mb_strlen($text), 'language' => $language];
$new_message .= $text;
break;
case 'p':
@ -379,7 +388,7 @@ trait BotAPI
if (!isset($mention['InputUser'])) {
throw new \danog\MadelineProto\Exception(\danog\MadelineProto\Lang::$current_lang['peer_not_in_db']);
}
$entities[] = ['_' => 'inputMessageEntityMentionName', 'offset' => mb_strlen($new_message), 'length' => mb_strlen($text), 'user_id' => $mention['InputUser']];
$entities[] = ['_' => 'inputMessageEntityMentionName', 'offset' => $this->mb_strlen($new_message), 'length' => $this->mb_strlen($text), 'user_id' => $mention['InputUser']];
} elseif (preg_match('|buttonurl:(.*)|', $href)) {
if (!isset($entities['buttons'])) {
$entities['buttons'] = [];
@ -391,9 +400,8 @@ trait BotAPI
}
break;
} else {
$entities[] = ['_' => 'messageEntityTextUrl', 'offset' => mb_strlen($new_message), 'length' => mb_strlen($text), 'url' => $href];
$entities[] = ['_' => 'messageEntityTextUrl', 'offset' => $this->mb_strlen($new_message), 'length' => $this->mb_strlen($text), 'url' => $href];
}
$new_message .= $text;
break;
default: