From 2a04787c98cedeb377b028975fd851b0b0d43619 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 16 Feb 2017 20:04:57 +0100 Subject: [PATCH] Switched to native html parser --- README.md | 2 +- composer.json | 1 - .../methods/messages_editInlineBotMessage.md | 2 +- docs/API_docs/methods/messages_editMessage.md | 2 +- docs/API_docs/methods/messages_saveDraft.md | 2 +- docs/API_docs/methods/messages_sendMessage.md | 2 +- docs/index.md | 9 +- .../methods/messages_sendMessage.md | 2 +- .../methods/messages_sendMessage.md | 2 +- .../methods/messages_sendMessage.md | 2 +- .../methods/messages_sendMessage.md | 2 +- .../methods/messages_sendMessage.md | 2 +- .../methods/messages_sendMessage.md | 2 +- .../methods/messages_sendMessage.md | 2 +- .../methods/messages_editInlineBotMessage.md | 2 +- .../methods/messages_editMessage.md | 2 +- .../methods/messages_sendMessage.md | 2 +- .../methods/messages_editInlineBotMessage.md | 2 +- .../methods/messages_editMessage.md | 2 +- .../methods/messages_saveDraft.md | 2 +- .../methods/messages_sendMessage.md | 2 +- .../methods/messages_editInlineBotMessage.md | 2 +- .../methods/messages_editMessage.md | 2 +- .../methods/messages_saveDraft.md | 2 +- .../methods/messages_sendMessage.md | 2 +- .../methods/messages_editInlineBotMessage.md | 2 +- .../methods/messages_editMessage.md | 2 +- .../methods/messages_saveDraft.md | 2 +- .../methods/messages_sendMessage.md | 2 +- src/danog/MadelineProto/DocsBuilder.php | 2 +- src/danog/MadelineProto/Serialization.php | 3 +- src/danog/MadelineProto/TL/TL.php | 130 ++++++++++-------- 32 files changed, 106 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index 4117245f..2a8fac20 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Logo created by [Matthew Hesketh](http://matthewhesketh.com) (thanks again!). PHP implementation of MTProto, based on [telepy](https://github.com/griganton/telepy_old). -This project can run on PHP 7 and HHVM, only 64 bit systems are supported ATM. +This project can run on PHP 7 and HHVM, only 64 bit systems are supported ATM. You must also install the mbstring, curl extensions. Also note that MadelineProto will perform better if python and a big math extension like gmp or bcmath are installed. diff --git a/composer.json b/composer.json index 9520b9c3..3a5acbe2 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ "phpseclib/phpseclib": "dev-ige", "vlucas/phpdotenv": "^2.4", "krakjoe/pthreads-polyfill": "dev-master", - "danog/php-html-parser": "dev-master", "erusev/parsedown": "^1.6" }, "require-dev": { diff --git a/docs/API_docs/methods/messages_editInlineBotMessage.md b/docs/API_docs/methods/messages_editInlineBotMessage.md index 79bda9f0..866c13dd 100644 --- a/docs/API_docs/methods/messages_editInlineBotMessage.md +++ b/docs/API_docs/methods/messages_editInlineBotMessage.md @@ -51,7 +51,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/docs/API_docs/methods/messages_editMessage.md b/docs/API_docs/methods/messages_editMessage.md index 583393e7..2faed00b 100644 --- a/docs/API_docs/methods/messages_editMessage.md +++ b/docs/API_docs/methods/messages_editMessage.md @@ -52,7 +52,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/docs/API_docs/methods/messages_saveDraft.md b/docs/API_docs/methods/messages_saveDraft.md index 94296d01..e38f61f0 100644 --- a/docs/API_docs/methods/messages_saveDraft.md +++ b/docs/API_docs/methods/messages_saveDraft.md @@ -51,7 +51,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/docs/API_docs/methods/messages_sendMessage.md b/docs/API_docs/methods/messages_sendMessage.md index 2341c307..5e22e679 100644 --- a/docs/API_docs/methods/messages_sendMessage.md +++ b/docs/API_docs/methods/messages_sendMessage.md @@ -55,7 +55,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/docs/index.md b/docs/index.md index 668e87d4..37d4e692 100644 --- a/docs/index.md +++ b/docs/index.md @@ -14,7 +14,7 @@ Logo created by [Matthew Hesketh](http://matthewhesketh.com) (thanks again!). PHP implementation of MTProto, based on [telepy](https://github.com/griganton/telepy_old). -This project can run on PHP 7 and HHVM, only 64 bit systems are supported ATM. +This project can run on PHP 7 and HHVM, only 64 bit systems are supported ATM. You must also install the mbstring, curl extensions. Also note that MadelineProto will perform better if python and a big math extension like gmp or bcmath are installed. @@ -240,7 +240,7 @@ To specify a custom callback change the correct value in the settings. The speci ### Uploading and downloading files -MadelineProto provides wrapper methods to upload and download files. +MadelineProto provides wrapper methods to upload and download files that support bot API file ids. Every method described in this section accepts a last optional paramater with a callable function that will be called during the upload/download using the first parameter to pass a floating point number indicating the upload/download status in percentage. @@ -253,12 +253,13 @@ $inputFile = $MadelineProto->upload('file', 'optional new file name.ext'); $MadelineProto->messages->sendMedia(['peer' => '@pwrtelegramgroup', 'media' => $inputMedia]); ``` +To convert the result of sendMedia to a bot API file id select the messageMedia object from the output of the method and pass it to `$MadelineProto->API->MTProto_to_botAPI()`. See tests/testing.php for more examples. There are multiple download methods that allow you to download a file to a directory, to a file or to a stream. -The first parameter of these functions must always be a [messageMediaPhoto](https://daniil.it/MadelineProto/API_docs/constructors/messageMediaPhoto.html) or a [messageMediaDocument](https://daniil.it/MadelineProto/API_docs/constructors/messageMediaDocument.html) object. These objects are usually received in updates, see `bot.php` for examples +The first parameter of these functions must always be either a [messageMediaPhoto](https://daniil.it/MadelineProto/API_docs/constructors/messageMediaPhoto.html) or a [messageMediaDocument](https://daniil.it/MadelineProto/API_docs/constructors/messageMediaDocument.html) object or a bot API file id. These objects are usually received in updates, see `bot.php` for examples ``` @@ -309,6 +310,8 @@ See tests/testing.php for more examples. Methods that allow sending message entities (messages.sendMessage for example) also have an additional parse_mode parameter that enables or disables html/markdown parsing of the message to be sent. See the method-specific documentation for more info. +To convert the results of methods to bot API objects you must provide a second parameter to method wrappers, containing an array with the `botAPI` key set to true. + Note that when you login as a bot, MadelineProto also logins using the [PWRTelegram](https://pwrtelegram.xyz) API, to allow persistant storage of peers, even after a logout and another login. ### Storing sessions diff --git a/old_docs/API_docs_v38/methods/messages_sendMessage.md b/old_docs/API_docs_v38/methods/messages_sendMessage.md index 1f79ab0f..2dd344af 100644 --- a/old_docs/API_docs_v38/methods/messages_sendMessage.md +++ b/old_docs/API_docs_v38/methods/messages_sendMessage.md @@ -51,7 +51,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v40/methods/messages_sendMessage.md b/old_docs/API_docs_v40/methods/messages_sendMessage.md index 1f79ab0f..2dd344af 100644 --- a/old_docs/API_docs_v40/methods/messages_sendMessage.md +++ b/old_docs/API_docs_v40/methods/messages_sendMessage.md @@ -51,7 +51,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v41/methods/messages_sendMessage.md b/old_docs/API_docs_v41/methods/messages_sendMessage.md index 0b9f4cfc..4e39a05f 100644 --- a/old_docs/API_docs_v41/methods/messages_sendMessage.md +++ b/old_docs/API_docs_v41/methods/messages_sendMessage.md @@ -53,7 +53,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v42/methods/messages_sendMessage.md b/old_docs/API_docs_v42/methods/messages_sendMessage.md index 0b9f4cfc..4e39a05f 100644 --- a/old_docs/API_docs_v42/methods/messages_sendMessage.md +++ b/old_docs/API_docs_v42/methods/messages_sendMessage.md @@ -53,7 +53,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v44/methods/messages_sendMessage.md b/old_docs/API_docs_v44/methods/messages_sendMessage.md index 0b9f4cfc..4e39a05f 100644 --- a/old_docs/API_docs_v44/methods/messages_sendMessage.md +++ b/old_docs/API_docs_v44/methods/messages_sendMessage.md @@ -53,7 +53,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v45/methods/messages_sendMessage.md b/old_docs/API_docs_v45/methods/messages_sendMessage.md index 0b9f4cfc..4e39a05f 100644 --- a/old_docs/API_docs_v45/methods/messages_sendMessage.md +++ b/old_docs/API_docs_v45/methods/messages_sendMessage.md @@ -53,7 +53,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v46/methods/messages_sendMessage.md b/old_docs/API_docs_v46/methods/messages_sendMessage.md index 0b9f4cfc..4e39a05f 100644 --- a/old_docs/API_docs_v46/methods/messages_sendMessage.md +++ b/old_docs/API_docs_v46/methods/messages_sendMessage.md @@ -53,7 +53,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v51/methods/messages_editInlineBotMessage.md b/old_docs/API_docs_v51/methods/messages_editInlineBotMessage.md index 79bda9f0..866c13dd 100644 --- a/old_docs/API_docs_v51/methods/messages_editInlineBotMessage.md +++ b/old_docs/API_docs_v51/methods/messages_editInlineBotMessage.md @@ -51,7 +51,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v51/methods/messages_editMessage.md b/old_docs/API_docs_v51/methods/messages_editMessage.md index 583393e7..2faed00b 100644 --- a/old_docs/API_docs_v51/methods/messages_editMessage.md +++ b/old_docs/API_docs_v51/methods/messages_editMessage.md @@ -52,7 +52,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v51/methods/messages_sendMessage.md b/old_docs/API_docs_v51/methods/messages_sendMessage.md index 5cbd5f33..87842769 100644 --- a/old_docs/API_docs_v51/methods/messages_sendMessage.md +++ b/old_docs/API_docs_v51/methods/messages_sendMessage.md @@ -55,7 +55,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v53/methods/messages_editInlineBotMessage.md b/old_docs/API_docs_v53/methods/messages_editInlineBotMessage.md index 79bda9f0..866c13dd 100644 --- a/old_docs/API_docs_v53/methods/messages_editInlineBotMessage.md +++ b/old_docs/API_docs_v53/methods/messages_editInlineBotMessage.md @@ -51,7 +51,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v53/methods/messages_editMessage.md b/old_docs/API_docs_v53/methods/messages_editMessage.md index 583393e7..2faed00b 100644 --- a/old_docs/API_docs_v53/methods/messages_editMessage.md +++ b/old_docs/API_docs_v53/methods/messages_editMessage.md @@ -52,7 +52,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v53/methods/messages_saveDraft.md b/old_docs/API_docs_v53/methods/messages_saveDraft.md index 94296d01..e38f61f0 100644 --- a/old_docs/API_docs_v53/methods/messages_saveDraft.md +++ b/old_docs/API_docs_v53/methods/messages_saveDraft.md @@ -51,7 +51,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v53/methods/messages_sendMessage.md b/old_docs/API_docs_v53/methods/messages_sendMessage.md index 2341c307..5e22e679 100644 --- a/old_docs/API_docs_v53/methods/messages_sendMessage.md +++ b/old_docs/API_docs_v53/methods/messages_sendMessage.md @@ -55,7 +55,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v55/methods/messages_editInlineBotMessage.md b/old_docs/API_docs_v55/methods/messages_editInlineBotMessage.md index 79bda9f0..866c13dd 100644 --- a/old_docs/API_docs_v55/methods/messages_editInlineBotMessage.md +++ b/old_docs/API_docs_v55/methods/messages_editInlineBotMessage.md @@ -51,7 +51,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v55/methods/messages_editMessage.md b/old_docs/API_docs_v55/methods/messages_editMessage.md index 583393e7..2faed00b 100644 --- a/old_docs/API_docs_v55/methods/messages_editMessage.md +++ b/old_docs/API_docs_v55/methods/messages_editMessage.md @@ -52,7 +52,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v55/methods/messages_saveDraft.md b/old_docs/API_docs_v55/methods/messages_saveDraft.md index 94296d01..e38f61f0 100644 --- a/old_docs/API_docs_v55/methods/messages_saveDraft.md +++ b/old_docs/API_docs_v55/methods/messages_saveDraft.md @@ -51,7 +51,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v55/methods/messages_sendMessage.md b/old_docs/API_docs_v55/methods/messages_sendMessage.md index 2341c307..5e22e679 100644 --- a/old_docs/API_docs_v55/methods/messages_sendMessage.md +++ b/old_docs/API_docs_v55/methods/messages_sendMessage.md @@ -55,7 +55,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v57/methods/messages_editInlineBotMessage.md b/old_docs/API_docs_v57/methods/messages_editInlineBotMessage.md index 79bda9f0..866c13dd 100644 --- a/old_docs/API_docs_v57/methods/messages_editInlineBotMessage.md +++ b/old_docs/API_docs_v57/methods/messages_editInlineBotMessage.md @@ -51,7 +51,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v57/methods/messages_editMessage.md b/old_docs/API_docs_v57/methods/messages_editMessage.md index 583393e7..2faed00b 100644 --- a/old_docs/API_docs_v57/methods/messages_editMessage.md +++ b/old_docs/API_docs_v57/methods/messages_editMessage.md @@ -52,7 +52,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v57/methods/messages_saveDraft.md b/old_docs/API_docs_v57/methods/messages_saveDraft.md index 94296d01..e38f61f0 100644 --- a/old_docs/API_docs_v57/methods/messages_saveDraft.md +++ b/old_docs/API_docs_v57/methods/messages_saveDraft.md @@ -51,7 +51,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/old_docs/API_docs_v57/methods/messages_sendMessage.md b/old_docs/API_docs_v57/methods/messages_sendMessage.md index 2341c307..5e22e679 100644 --- a/old_docs/API_docs_v57/methods/messages_sendMessage.md +++ b/old_docs/API_docs_v57/methods/messages_sendMessage.md @@ -55,7 +55,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren't parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/src/danog/MadelineProto/DocsBuilder.php b/src/danog/MadelineProto/DocsBuilder.php index 338d1481..a6594cf6 100755 --- a/src/danog/MadelineProto/DocsBuilder.php +++ b/src/danog/MadelineProto/DocsBuilder.php @@ -186,7 +186,7 @@ The following tags are currently supported: ```
a newline -bold works ok, internal tags aren\'t parsed and shown as is +bold works ok, internal tags are stripped bold italic italic diff --git a/src/danog/MadelineProto/Serialization.php b/src/danog/MadelineProto/Serialization.php index 9d21004b..4c256e0d 100644 --- a/src/danog/MadelineProto/Serialization.php +++ b/src/danog/MadelineProto/Serialization.php @@ -53,9 +53,10 @@ class Serialization if (file_exists($filename)) { $file = fopen($filename, 'r+'); flock($file, LOCK_EX); - $unserialized = unserialize(stream_get_contents($file)); + $unserialized = stream_get_contents($file); flock($file, LOCK_UN); fclose($file); + $unserialized = unserialize($unserialized); } else { throw new Exception('File does not exist'); } diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php index e36e4684..4537325d 100644 --- a/src/danog/MadelineProto/TL/TL.php +++ b/src/danog/MadelineProto/TL/TL.php @@ -573,7 +573,63 @@ trait TL return $arguments; } + public function parse_node($node, &$entities, &$nmessage, $recursive = true) { + switch ($node->nodeName) { + case 'br': + $nmessage .= "\n"; + break; + case 'b': + case 'strong': + $text = $this->html_entity_decode($node->textContent); + $entities[] = ['_' => 'messageEntityBold', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text)]; + $nmessage .= $text; + break; + case 'i': + case 'em': + $text = $this->html_entity_decode($node->textContent); + $entities[] = ['_' => 'messageEntityItalic', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text)]; + $nmessage .= $text; + break; + + case 'code': + $text = $this->html_entity_decode($node->textContent); + $entities[] = ['_' => 'messageEntityCode', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text)]; + $nmessage .= $text; + break; + + case 'pre': + $text = $this->html_entity_decode($node->textContent); + $language = $node->getAttribute('language'); + if ($language === null) { + $language = ''; + } + $entities[] = ['_' => 'messageEntityPre', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text), 'language' => $language]; + $nmessage .= $text; + break; + + case 'p': + foreach ($node->childNodes as $node) { + $this->parse_node($node, $entities, $nmessage); + } + break; + + case 'a': + $text = $this->html_entity_decode($node->textContent); + $href = $node->getAttribute('href'); + if (preg_match('|mention:|', $href)) { + $entities[] = ['_' => 'inputMessageEntityMentionName', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text), 'user_id' => $this->get_info(str_replace('mention:', '', $href))['InputUser']]; + } else { + $entities[] = ['_' => 'messageEntityTextUrl', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text), 'url' => $href]; + } + $nmessage .= $text; + break; + + default: + $nmessage .= $this->html_entity_decode($node->nodeValue); + break; + } + } public function parse_mode($arguments) { if (preg_match('/markdown/i', $arguments['parse_mode'])) { @@ -581,67 +637,21 @@ trait TL $arguments['parse_mode'] = 'HTML'; } if (preg_match('/html/i', $arguments['parse_mode'])) { - $dom = new \PHPHtmlParser\Dom(); - $dom->loadStr(str_replace("\n", '
', $arguments['message']), []); - $nmessage = ''; - if (!isset($arguments['entities'])) { - $arguments['entities'] = []; - } - foreach ($dom->find('') as $tag) { - switch ($tag->tag->name()) { - case 'br': - $nmessage .= "\n"; - break; - - case 'b': - case 'strong': - $text = $this->html_entity_decode($tag->innerHtml); - $arguments['entities'][] = ['_' => 'messageEntityBold', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text)]; - $nmessage .= $text; - break; - - case 'i': - case 'em': - $text = $this->html_entity_decode($tag->innerHtml); - $arguments['entities'][] = ['_' => 'messageEntityItalic', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text)]; - $nmessage .= $text; - break; - - case 'code': - $text = $this->html_entity_decode($tag->innerHtml); - $arguments['entities'][] = ['_' => 'messageEntityCode', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text)]; - $nmessage .= $text; - break; - - case 'pre': - $text = $this->html_entity_decode($tag->innerHtml); - $language = $tag->getAttribute('language'); - if ($language === null) { - $language = ''; - } - $arguments['entities'][] = ['_' => 'messageEntityPre', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text), 'language' => $language]; - $nmessage .= $text; - break; - - case 'a': - $text = $this->html_entity_decode($tag->innerHtml); - $href = $tag->getAttribute('href'); - if (preg_match('|mention:|', $href)) { - $arguments['entities'][] = ['_' => 'inputMessageEntityMentionName', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text), 'user_id' => $this->get_info(str_replace('mention:', '', $href))['InputUser']]; - } else { - $arguments['entities'][] = ['_' => 'messageEntityTextUrl', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text), 'url' => $href]; - } - $nmessage .= $text; - break; - - default: - $nmessage .= $this->html_entity_decode($tag->outerHtml); - break; - } - } - $arguments['message'] = $nmessage; - unset($arguments['parse_mode']); + try { + $dom = new \DOMDocument(); + $dom->loadHTML(str_replace("\n", '
', $arguments['message'])); + $nmessage = ''; + if (!isset($arguments['entities'])) { + $arguments['entities'] = []; + } + foreach ($dom->getElementsByTagName('body')->item(0)->childNodes as $node) { + $this->parse_node($node, $arguments['entities'], $nmessage); + } + unset($arguments['parse_mode']); + } catch (\DOMException $e) { + } catch (\danog\MadelineProto\Exception $e) { ; }; } + $arguments['message'] = $nmessage; return $arguments; }