mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-26 22:14:39 +01:00
Fix
This commit is contained in:
parent
6c75e08ee7
commit
2a0d9a22e7
2
docs
2
docs
@ -1 +1 @@
|
||||
Subproject commit 60e196b7ac6a67aa0a9192646d2153d530e33610
|
||||
Subproject commit e3b7940ee5f8cfd7bdcf347a202491394dd7e1d2
|
@ -12,6 +12,7 @@
|
||||
<directory name="vendor" />
|
||||
<file name="src/danog/MadelineProto/InternalDoc.php" />
|
||||
<file name="src/danog/MadelineProto/TON/InternalDoc.php" />
|
||||
<file name="src/danog/MadelineProto/Lua.php" />
|
||||
</ignoreFiles>
|
||||
</projectFiles>
|
||||
</psalm>
|
||||
|
@ -170,6 +170,14 @@ trait Constructors
|
||||
if ($param['name'] === 'reply_markup') {
|
||||
$hasreplymarkup = true;
|
||||
}
|
||||
if ($param['name'] === 'entities' && $ptype === 'InputSingleMedia') {
|
||||
$hasentities = true;
|
||||
$table .= '|parse\\_mode| [string](/API_docs/types/string.md) | Whether to parse HTML or Markdown markup in the message| Optional |
|
||||
';
|
||||
$params .= "parse_mode: 'string', ";
|
||||
$lua_params .= "parseMode='string', ";
|
||||
$pwr_params = "parseMode - string\n";
|
||||
}
|
||||
}
|
||||
$params = "['_' => '".$constructor."'".$params.']';
|
||||
$lua_params = "{_='".$constructor."'".$lua_params.'}';
|
||||
|
@ -7232,7 +7232,7 @@ class InternalDoc extends APIFactory
|
||||
/**
|
||||
* Refresh full peer cache for a certain peer.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param mixed $id The peer to refresh
|
||||
* @return \Amp\Promise
|
||||
*/
|
||||
public function refreshFullPeerCache($id, array $extra = [])
|
||||
@ -7242,7 +7242,7 @@ class InternalDoc extends APIFactory
|
||||
/**
|
||||
* Refresh peer cache for a certain peer.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param mixed $id The peer to refresh
|
||||
* @return \Amp\Promise
|
||||
*/
|
||||
public function refreshPeerCache($id, array $extra = [])
|
||||
|
@ -67,7 +67,6 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
use \danog\MadelineProto\SecretChats\ResponseHandler;
|
||||
use \danog\MadelineProto\SecretChats\SeqNoHandler;
|
||||
use \danog\MadelineProto\TL\Conversion\BotAPI;
|
||||
use \danog\MadelineProto\TL\Conversion\Entities;
|
||||
use \danog\MadelineProto\TL\Conversion\BotAPIFiles;
|
||||
use \danog\MadelineProto\TL\Conversion\TD;
|
||||
use \danog\MadelineProto\VoIP\AuthKeyHandler;
|
||||
@ -113,7 +112,7 @@ class MTProto extends AsyncConstruct implements TLCallback
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const V = 158;
|
||||
const V = 157;
|
||||
/**
|
||||
* Release version.
|
||||
*
|
||||
|
@ -816,7 +816,7 @@ trait PeerHandler
|
||||
/**
|
||||
* Refresh peer cache for a certain peer.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param mixed $id The peer to refresh
|
||||
* @return \Generator
|
||||
*/
|
||||
public function refreshPeerCache($id): \Generator
|
||||
@ -831,7 +831,7 @@ trait PeerHandler
|
||||
/**
|
||||
* Refresh full peer cache for a certain peer.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param mixed $id The peer to refresh
|
||||
* @return \Generator
|
||||
*/
|
||||
public function refreshFullPeerCache($id): \Generator
|
||||
|
@ -379,7 +379,7 @@ trait BotAPI
|
||||
[$arguments['message'],$arguments['entities']] = $this->parseText(($arguments['message']), 'html');
|
||||
|
||||
/**
|
||||
* deprecated future or you can fix it in future
|
||||
* deprecated future or you can fix it in future.
|
||||
* @deprecated
|
||||
*/
|
||||
/*
|
||||
@ -387,7 +387,6 @@ trait BotAPI
|
||||
$arguments['reply_markup'] = $this->buildRows($arguments['entities']['buttons']);
|
||||
unset($arguments['entities']['buttons']);
|
||||
} */
|
||||
|
||||
}
|
||||
/**
|
||||
* this is new future added! but for use must scape some special chars ...
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace danog\MadelineProto\TL\Conversion;
|
||||
|
||||
use danog\MadelineProto\API;
|
||||
|
||||
const BOLD = 0;
|
||||
const ITALIC = 1;
|
||||
const UNDERLINE = 2;
|
||||
@ -55,23 +53,23 @@ trait Entities
|
||||
string $string,
|
||||
mixed $separator = PHP_EOL
|
||||
): string|array|null {
|
||||
$separator = in_array($separator, [
|
||||
$separator = \in_array($separator, [
|
||||
"\n",
|
||||
"\r",
|
||||
"\r\n",
|
||||
"\n\r",
|
||||
chr(30),
|
||||
chr(155),
|
||||
\chr(30),
|
||||
\chr(155),
|
||||
PHP_EOL,
|
||||
])
|
||||
? $separator
|
||||
: PHP_EOL; // Checks if provided $separator is valid.
|
||||
return preg_replace("/\<br(\s*)?\/?\>/i", $separator, $string);
|
||||
return \preg_replace("/\<br(\s*)?\/?\>/i", $separator, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* getEntityName
|
||||
* get entity name by it codes
|
||||
* get entity name by it codes.
|
||||
*
|
||||
* @param int $code
|
||||
*
|
||||
@ -112,7 +110,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* getEntityCode
|
||||
* get entity name by it name
|
||||
* get entity name by it name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
@ -153,7 +151,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* getEntityNameFromTag
|
||||
* get entity name by it tag
|
||||
* get entity name by it tag.
|
||||
*
|
||||
* @param string $tag
|
||||
*
|
||||
@ -204,7 +202,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* setText
|
||||
* set text string and offset
|
||||
* set text string and offset.
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
@ -212,7 +210,7 @@ trait Entities
|
||||
*/
|
||||
private function setText(string $text)
|
||||
{
|
||||
$text = htmlspecialchars_decode($text);
|
||||
$text = \htmlspecialchars_decode($text);
|
||||
$l = $this->strlen($text);
|
||||
$this->text .= $text;
|
||||
$this->offset = $this->offset + $l;
|
||||
@ -220,7 +218,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* decode
|
||||
* decode text from UTF-8 to UTF-16LE to easily parse it tags
|
||||
* decode text from UTF-8 to UTF-16LE to easily parse it tags.
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
@ -228,11 +226,11 @@ trait Entities
|
||||
*/
|
||||
private function decode(string $str): array|string|false
|
||||
{
|
||||
return mb_convert_encoding($str, "UTF-8", "UTF-16LE");
|
||||
return \mb_convert_encoding($str, "UTF-8", "UTF-16LE");
|
||||
}
|
||||
|
||||
/**
|
||||
* encode
|
||||
* encode.
|
||||
*
|
||||
* encode parsed text from UTF-16LE to UTF-8
|
||||
* @param string $str
|
||||
@ -241,11 +239,11 @@ trait Entities
|
||||
*/
|
||||
private function encode(string $str): array|string|false
|
||||
{
|
||||
return mb_convert_encoding($str, "UTF-16LE", "UTF-8");
|
||||
return \mb_convert_encoding($str, "UTF-16LE", "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* strlen
|
||||
* strlen.
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
@ -253,11 +251,11 @@ trait Entities
|
||||
*/
|
||||
private function strlen(string $str): int|float
|
||||
{
|
||||
return strlen($this->encode($str)) / 2;
|
||||
return \strlen($this->encode($str)) / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* substr
|
||||
* substr.
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
@ -272,12 +270,12 @@ trait Entities
|
||||
int $offset,
|
||||
?int $length = null
|
||||
): array|string|false {
|
||||
return $this->decode(substr($string, $offset * 2, $length * 2));
|
||||
return $this->decode(\substr($string, $offset * 2, $length * 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* setOffset
|
||||
* setOffset for text
|
||||
* setOffset for text.
|
||||
*
|
||||
* @param string $start
|
||||
*
|
||||
@ -291,7 +289,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* setEntitie
|
||||
* setEntitie for text and parse special tags to entities
|
||||
* setEntitie for text and parse special tags to entities.
|
||||
*
|
||||
* @param int $type
|
||||
*
|
||||
@ -313,7 +311,7 @@ trait Entities
|
||||
if ($type == ATAG) {
|
||||
if (isset($array["href"])) {
|
||||
if (
|
||||
preg_match(
|
||||
\preg_match(
|
||||
'/^(?:tg:\/\/user\?id=|mention:)(.*)$/isu',
|
||||
$array["href"],
|
||||
$matches
|
||||
@ -321,7 +319,7 @@ trait Entities
|
||||
) {
|
||||
$userId = $matches[1];
|
||||
|
||||
if (!is_numeric($userId)) {
|
||||
if (!\is_numeric($userId)) {
|
||||
try {
|
||||
$userId ??= $this->api->getInfo($matches[1])['id'];
|
||||
} catch (\Throwable $e) {
|
||||
@ -342,7 +340,7 @@ trait Entities
|
||||
if (
|
||||
$intag === "pre" &&
|
||||
((isset($array["class"]) &&
|
||||
preg_match(
|
||||
\preg_match(
|
||||
'/^language\-(.*?)$/',
|
||||
$array["class"],
|
||||
$matches
|
||||
@ -357,7 +355,7 @@ trait Entities
|
||||
return $result;
|
||||
} elseif ($type == SPANTAG) {
|
||||
if (isset($array["class"])) {
|
||||
$array["class"] = strtolower($array["class"]);
|
||||
$array["class"] = \strtolower($array["class"]);
|
||||
switch ($array["class"]) {
|
||||
case "bold":
|
||||
$result["_"] = $this->getEntityName(BOLD);
|
||||
@ -403,7 +401,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* checkEntity
|
||||
* checkEntity in text and identify it
|
||||
* checkEntity in text and identify it.
|
||||
*
|
||||
* @param object|array $entity
|
||||
*
|
||||
@ -413,10 +411,10 @@ trait Entities
|
||||
*/
|
||||
private function checkEntity(object|array $entity, &$type): array
|
||||
{
|
||||
if (is_object($entity)) {
|
||||
if (\is_object($entity)) {
|
||||
$entity = (array) $entity;
|
||||
}
|
||||
if (is_array($entity)) {
|
||||
if (\is_array($entity)) {
|
||||
if (!isset($entity["offset"])) {
|
||||
throw new Exception('Can\'t find field "offset"');
|
||||
}
|
||||
@ -426,19 +424,19 @@ trait Entities
|
||||
if (!isset($entity["_"])) {
|
||||
throw new Exception('Can\'t find field "type"');
|
||||
}
|
||||
if (is_array($entity["_"]) || is_object($entity["_"])) {
|
||||
if (\is_array($entity["_"]) || \is_object($entity["_"])) {
|
||||
throw new Exception('Field "type" must be of type String');
|
||||
}
|
||||
if (
|
||||
is_array($entity["offset"]) ||
|
||||
is_object($entity["offset"]) ||
|
||||
\is_array($entity["offset"]) ||
|
||||
\is_object($entity["offset"]) ||
|
||||
(string) (int) $entity["offset"] !== (string) $entity["offset"]
|
||||
) {
|
||||
throw new Exception('Field "offset" must be of type Integer');
|
||||
}
|
||||
if (
|
||||
is_array($entity["length"]) ||
|
||||
is_object($entity["length"]) ||
|
||||
\is_array($entity["length"]) ||
|
||||
\is_object($entity["length"]) ||
|
||||
(string) (int) $entity["length"] !== (string) $entity["length"]
|
||||
) {
|
||||
throw new Exception('Field "length" must be of type Integer');
|
||||
@ -447,14 +445,13 @@ trait Entities
|
||||
$this->length = (int) $entity["length"];
|
||||
$type = $this->getEntityCode($entity["_"]);
|
||||
return $entity;
|
||||
} else {
|
||||
throw new Exception("expected an Object");
|
||||
}
|
||||
throw new Exception("expected an Object");
|
||||
}
|
||||
|
||||
/**
|
||||
* entitiesToHtml
|
||||
* Covert entities to html tags
|
||||
* Covert entities to html tags.
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
@ -511,8 +508,8 @@ trait Entities
|
||||
if (!isset($this->setOffset[$key])) {
|
||||
$this->setOffset[$key] = [];
|
||||
}
|
||||
$this->setOffset[$key] = array_merge(
|
||||
array_reverse($this->setOffset2[$key]),
|
||||
$this->setOffset[$key] = \array_merge(
|
||||
\array_reverse($this->setOffset2[$key]),
|
||||
$this->setOffset[$key]
|
||||
);
|
||||
}
|
||||
@ -527,15 +524,15 @@ trait Entities
|
||||
'/\\<\\000/',
|
||||
'/\\>\\000/',
|
||||
];
|
||||
for ($offset = 0; $offset < strlen($utf16) / 2; $offset++) {
|
||||
$t = substr($utf16, $offset * 2, 2);
|
||||
for ($offset = 0; $offset < \strlen($utf16) / 2; $offset++) {
|
||||
$t = \substr($utf16, $offset * 2, 2);
|
||||
if (isset($this->setOffset[$offset])) {
|
||||
foreach ($this->setOffset[$offset] as $tt) {
|
||||
$htmlext .= $this->encode($tt);
|
||||
}
|
||||
unset($this->setOffset[$offset]);
|
||||
}
|
||||
$htmlext .= $specialchars ? preg_replace($deltag2, $deltag, $t) : $t;
|
||||
$htmlext .= $specialchars ? \preg_replace($deltag2, $deltag, $t) : $t;
|
||||
}
|
||||
foreach ($this->setOffset as $off) {
|
||||
foreach ($off as $tt) {
|
||||
@ -547,7 +544,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* entitiesToMarkdownV1
|
||||
* Covert entities to html tags v1 (Telegram version)
|
||||
* Covert entities to html tags v1 (Telegram version).
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
@ -595,8 +592,8 @@ trait Entities
|
||||
if (!isset($this->setOffset[$key])) {
|
||||
$this->setOffset[$key] = [];
|
||||
}
|
||||
$this->setOffset[$key] = array_merge(
|
||||
array_reverse($this->setOffset2[$key]),
|
||||
$this->setOffset[$key] = \array_merge(
|
||||
\array_reverse($this->setOffset2[$key]),
|
||||
$this->setOffset[$key]
|
||||
);
|
||||
}
|
||||
@ -613,15 +610,15 @@ trait Entities
|
||||
'/`\\000/',
|
||||
'/\\[\\000/',
|
||||
];
|
||||
for ($offset = 0; $offset < strlen($utf16) / 2; $offset++) {
|
||||
$t = substr($utf16, $offset * 2, 2);
|
||||
for ($offset = 0; $offset < \strlen($utf16) / 2; $offset++) {
|
||||
$t = \substr($utf16, $offset * 2, 2);
|
||||
if (isset($this->setOffset[$offset])) {
|
||||
foreach ($this->setOffset[$offset] as $tt) {
|
||||
$htmlext .= $this->encode($tt);
|
||||
}
|
||||
unset($this->setOffset[$offset]);
|
||||
}
|
||||
$htmlext .= $slashmarkdown ? preg_replace($deltag2, $deltag, $t) : $t;
|
||||
$htmlext .= $slashmarkdown ? \preg_replace($deltag2, $deltag, $t) : $t;
|
||||
}
|
||||
foreach ($this->setOffset as $off) {
|
||||
foreach ($off as $tt) {
|
||||
@ -633,7 +630,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* entitiesToMarkdown
|
||||
* convert given entities to markdown
|
||||
* convert given entities to markdown.
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
@ -686,8 +683,8 @@ trait Entities
|
||||
if (!isset($this->setOffset[$key])) {
|
||||
$this->setOffset[$key] = [];
|
||||
}
|
||||
$this->setOffset[$key] = array_merge(
|
||||
array_reverse($this->setOffset2[$key]),
|
||||
$this->setOffset[$key] = \array_merge(
|
||||
\array_reverse($this->setOffset2[$key]),
|
||||
$this->setOffset[$key]
|
||||
);
|
||||
}
|
||||
@ -733,15 +730,15 @@ trait Entities
|
||||
'/\\.\\000/',
|
||||
'/\\!\\000/',
|
||||
];
|
||||
for ($offset = 0; $offset < strlen($utf16) / 2; $offset++) {
|
||||
$t = substr($utf16, $offset * 2, 2);
|
||||
for ($offset = 0; $offset < \strlen($utf16) / 2; $offset++) {
|
||||
$t = \substr($utf16, $offset * 2, 2);
|
||||
if (isset($this->setOffset[$offset])) {
|
||||
foreach ($this->setOffset[$offset] as $tt) {
|
||||
$htmlext .= $this->encode($tt);
|
||||
}
|
||||
unset($this->setOffset[$offset]);
|
||||
}
|
||||
$htmlext .= $slashmarkdown ? preg_replace($deltag2, $deltag, $t) : $t;
|
||||
$htmlext .= $slashmarkdown ? \preg_replace($deltag2, $deltag, $t) : $t;
|
||||
}
|
||||
foreach ($this->setOffset as $off) {
|
||||
foreach ($off as $tt) {
|
||||
@ -753,7 +750,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* markdownV1ToHtml
|
||||
* convert markdownv1 to html
|
||||
* convert markdownv1 to html.
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
@ -766,28 +763,28 @@ trait Entities
|
||||
if ($specialchars) {
|
||||
$str = $this->htmlSpecialChars($str);
|
||||
}
|
||||
$len = mb_strlen($str);
|
||||
$len = \mb_strlen($str);
|
||||
$backslash = ["_", "*", "`", "["];
|
||||
$marks = [];
|
||||
$marksi = -1;
|
||||
|
||||
$i = 0;
|
||||
$is = function ($string) use (&$i, &$str) {
|
||||
return mb_substr($str, $i, mb_strlen($string)) == $string;
|
||||
return \mb_substr($str, $i, \mb_strlen($string)) == $string;
|
||||
};
|
||||
$find = function ($str, $find, &$i) use ($backslash) {
|
||||
$findlen = mb_strlen($find);
|
||||
$findlen = \mb_strlen($find);
|
||||
$newstr = "";
|
||||
for ($i = 0; $i < mb_strlen($str); $i++) {
|
||||
$curchar = mb_substr($str, $i, 1);
|
||||
for ($i = 0; $i < \mb_strlen($str); $i++) {
|
||||
$curchar = \mb_substr($str, $i, 1);
|
||||
|
||||
if (
|
||||
$curchar == "\\" &&
|
||||
in_array(mb_substr($str, $i + 1, 1), $backslash)
|
||||
\in_array(\mb_substr($str, $i + 1, 1), $backslash)
|
||||
) {
|
||||
$newstr .= mb_substr($str, $i + 1, 1);
|
||||
$newstr .= \mb_substr($str, $i + 1, 1);
|
||||
$i++;
|
||||
} elseif (mb_substr($str, $i, $findlen) == $find) {
|
||||
} elseif (\mb_substr($str, $i, $findlen) == $find) {
|
||||
return $newstr;
|
||||
} else {
|
||||
$newstr .= $curchar;
|
||||
@ -799,7 +796,7 @@ trait Entities
|
||||
$htmli = 0;
|
||||
$setstr = function ($starttag) use (&$html, &$htmli) {
|
||||
$html .= $starttag;
|
||||
$htmli += mb_strlen($starttag);
|
||||
$htmli += \mb_strlen($starttag);
|
||||
};
|
||||
$i = 0;
|
||||
$setmark = function ($mark, &$currentmarki = 0, $fakemark = false) use (
|
||||
@ -816,12 +813,11 @@ trait Entities
|
||||
$i,
|
||||
];
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
$currentmarki = $marks[$marksi][1];
|
||||
unset($marks[$marksi]);
|
||||
$marksi--;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
$currentmarki = 0;
|
||||
$setstr2 = function ($endtag, $starttaglen) use (
|
||||
@ -834,16 +830,16 @@ trait Entities
|
||||
$setstr($endtag);
|
||||
} else {
|
||||
$htmli -= $starttaglen;
|
||||
$html = mb_substr($html, 0, $htmli);
|
||||
$html = \mb_substr($html, 0, $htmli);
|
||||
}
|
||||
};
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
$curchar = mb_substr($str, $i, 1);
|
||||
$curchar = \mb_substr($str, $i, 1);
|
||||
if (
|
||||
$curchar == "\\" &&
|
||||
in_array(mb_substr($str, $i + 1, 1), $backslash)
|
||||
\in_array(\mb_substr($str, $i + 1, 1), $backslash)
|
||||
) {
|
||||
$setstr(mb_substr($str, $i + 1, 1));
|
||||
$setstr(\mb_substr($str, $i + 1, 1));
|
||||
$i++;
|
||||
} elseif ($curchar == "*") {
|
||||
if ($setmark("*", $currentmarki)) {
|
||||
@ -861,47 +857,47 @@ trait Entities
|
||||
$setmark("[", $currentmarki, "]");
|
||||
} elseif ($curchar == "]") {
|
||||
if (!$setmark("]", $currentmarki, false) && $is("](")) {
|
||||
$txt = mb_substr(
|
||||
$txt = \mb_substr(
|
||||
$html,
|
||||
$currentmarki,
|
||||
$htmli - $currentmarki
|
||||
);
|
||||
if ($txt !== "") {
|
||||
$i++;
|
||||
$strfind = $find(mb_substr($str, $i + 1), ")", $pos);
|
||||
$strfind = $find(\mb_substr($str, $i + 1), ")", $pos);
|
||||
if ($strfind !== false) {
|
||||
$i += $pos + 1;
|
||||
$html =
|
||||
mb_substr($html, 0, $currentmarki) .
|
||||
\mb_substr($html, 0, $currentmarki) .
|
||||
'<a href="' .
|
||||
$strfind .
|
||||
'">' .
|
||||
$txt .
|
||||
"</a>";
|
||||
$htmli = mb_strlen($html);
|
||||
$htmli = \mb_strlen($html);
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($curchar == "`") {
|
||||
if ($is("```")) {
|
||||
$i += 2;
|
||||
$strfind = $find(mb_substr($str, $i + 1), "```", $pos);
|
||||
$strfind = $find(\mb_substr($str, $i + 1), "```", $pos);
|
||||
if ($strfind !== false) {
|
||||
$i += $pos + 3;
|
||||
if ($strfind !== "") {
|
||||
$lang = "";
|
||||
$ex = explode("\n", $f, 2);
|
||||
$ex = \explode("\n", $f, 2);
|
||||
if (isset($ex[1])) {
|
||||
$exx = explode(" ", $ex[0], 2);
|
||||
$exx = \explode(" ", $ex[0], 2);
|
||||
if (isset($exx[1])) {
|
||||
$ex[1] = " " . $exx[1];
|
||||
}
|
||||
$lang = trim($exx[0]);
|
||||
$lang = \trim($exx[0]);
|
||||
$strfind = $ex[1];
|
||||
}
|
||||
|
||||
if ($lang) {
|
||||
$strfind = trim($f);
|
||||
$strfind = \trim($f);
|
||||
if ($strfind !== "") {
|
||||
$setstr(
|
||||
'<pre><code class="language-' .
|
||||
@ -921,7 +917,7 @@ trait Entities
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$strfind = $find(mb_substr($str, $i + 1), "`", $pos);
|
||||
$strfind = $find(\mb_substr($str, $i + 1), "`", $pos);
|
||||
if ($strfind !== false) {
|
||||
if ($strfind !== "") {
|
||||
$setstr("<code>" . $strfind . "</code>");
|
||||
@ -934,7 +930,7 @@ trait Entities
|
||||
);
|
||||
}
|
||||
}
|
||||
} elseif (in_array($curchar, $backslash)) {
|
||||
} elseif (\in_array($curchar, $backslash)) {
|
||||
throw new Exception(
|
||||
"Character '$curchar' is reserved and must be escaped with the preceding '\'"
|
||||
);
|
||||
@ -960,7 +956,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* markdownToHtml
|
||||
* convert html tags to markdown format
|
||||
* convert html tags to markdown format.
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
@ -973,7 +969,7 @@ trait Entities
|
||||
if ($specialchars) {
|
||||
$str = $this->htmlSpecialChars($str);
|
||||
}
|
||||
$len = mb_strlen($str);
|
||||
$len = \mb_strlen($str);
|
||||
$backslash = [
|
||||
"_",
|
||||
"*",
|
||||
@ -999,21 +995,21 @@ trait Entities
|
||||
|
||||
$i = 0;
|
||||
$is = function ($string) use (&$i, &$str) {
|
||||
return mb_substr($str, $i, mb_strlen($string)) == $string;
|
||||
return \mb_substr($str, $i, \mb_strlen($string)) == $string;
|
||||
};
|
||||
$find = function ($str, $find, &$i) use ($backslash) {
|
||||
$findlen = mb_strlen($find);
|
||||
$findlen = \mb_strlen($find);
|
||||
$newstr = "";
|
||||
for ($i = 0; $i < mb_strlen($str); $i++) {
|
||||
$curchar = mb_substr($str, $i, 1);
|
||||
for ($i = 0; $i < \mb_strlen($str); $i++) {
|
||||
$curchar = \mb_substr($str, $i, 1);
|
||||
|
||||
if (
|
||||
$curchar == "\\" &&
|
||||
in_array(mb_substr($str, $i + 1, 1), $backslash)
|
||||
\in_array(\mb_substr($str, $i + 1, 1), $backslash)
|
||||
) {
|
||||
$newstr .= mb_substr($str, $i + 1, 1);
|
||||
$newstr .= \mb_substr($str, $i + 1, 1);
|
||||
$i++;
|
||||
} elseif (mb_substr($str, $i, $findlen) == $find) {
|
||||
} elseif (\mb_substr($str, $i, $findlen) == $find) {
|
||||
return $newstr;
|
||||
} else {
|
||||
$newstr .= $curchar;
|
||||
@ -1025,7 +1021,7 @@ trait Entities
|
||||
$htmli = 0;
|
||||
$setstr = function ($starttag) use (&$html, &$htmli) {
|
||||
$html .= $starttag;
|
||||
$htmli += mb_strlen($starttag);
|
||||
$htmli += \mb_strlen($starttag);
|
||||
};
|
||||
$i = 0;
|
||||
$setmark = function ($mark, &$currentmarki = 0, $fakemark = false) use (
|
||||
@ -1042,12 +1038,11 @@ trait Entities
|
||||
$i,
|
||||
];
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
$currentmarki = $marks[$marksi][1];
|
||||
unset($marks[$marksi]);
|
||||
$marksi--;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
$currentmarki = 0;
|
||||
$setstr2 = function ($endtag, $starttaglen) use (
|
||||
@ -1060,16 +1055,16 @@ trait Entities
|
||||
$setstr($endtag);
|
||||
} else {
|
||||
$htmli -= $starttaglen;
|
||||
$html = mb_substr($html, 0, $htmli);
|
||||
$html = \mb_substr($html, 0, $htmli);
|
||||
}
|
||||
};
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
$curchar = mb_substr($str, $i, 1);
|
||||
$curchar = \mb_substr($str, $i, 1);
|
||||
if (
|
||||
$curchar == "\\" &&
|
||||
in_array(mb_substr($str, $i + 1, 1), $backslash)
|
||||
\in_array(\mb_substr($str, $i + 1, 1), $backslash)
|
||||
) {
|
||||
$setstr(mb_substr($str, $i + 1, 1));
|
||||
$setstr(\mb_substr($str, $i + 1, 1));
|
||||
$i++;
|
||||
} elseif ($curchar == "*") {
|
||||
$tag = "i";
|
||||
@ -1119,47 +1114,47 @@ trait Entities
|
||||
$setmark("[", $currentmarki, "]");
|
||||
} elseif ($curchar == "]") {
|
||||
if (!$setmark("]", $currentmarki, false) && $is("](")) {
|
||||
$txt = mb_substr(
|
||||
$txt = \mb_substr(
|
||||
$html,
|
||||
$currentmarki,
|
||||
$htmli - $currentmarki
|
||||
);
|
||||
if ($txt !== "") {
|
||||
$i++;
|
||||
$strfind = $find(mb_substr($str, $i + 1), ")", $pos);
|
||||
$strfind = $find(\mb_substr($str, $i + 1), ")", $pos);
|
||||
if ($strfind !== false) {
|
||||
$i += $pos + 1;
|
||||
$html =
|
||||
mb_substr($html, 0, $currentmarki) .
|
||||
\mb_substr($html, 0, $currentmarki) .
|
||||
'<a href="' .
|
||||
$strfind .
|
||||
'">' .
|
||||
$txt .
|
||||
"</a>";
|
||||
$htmli = mb_strlen($html);
|
||||
$htmli = \mb_strlen($html);
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($curchar == "`") {
|
||||
if ($is("```")) {
|
||||
$i += 2;
|
||||
$strfind = $find(mb_substr($str, $i + 1), "```", $pos);
|
||||
$strfind = $find(\mb_substr($str, $i + 1), "```", $pos);
|
||||
if ($strfind !== false) {
|
||||
$i += $pos + 3;
|
||||
if ($strfind !== "") {
|
||||
$lang = "";
|
||||
$ex = explode("\n", $f, 2);
|
||||
$ex = \explode("\n", $f, 2);
|
||||
if (isset($ex[1])) {
|
||||
$exx = explode(" ", $ex[0], 2);
|
||||
$exx = \explode(" ", $ex[0], 2);
|
||||
if (isset($exx[1])) {
|
||||
$ex[1] = " " . $exx[1];
|
||||
}
|
||||
$lang = trim($exx[0]);
|
||||
$lang = \trim($exx[0]);
|
||||
$strfind = $ex[1];
|
||||
}
|
||||
|
||||
if ($lang) {
|
||||
$strfind = trim($f);
|
||||
$strfind = \trim($f);
|
||||
if ($strfind !== "") {
|
||||
$setstr(
|
||||
'<pre><code class="language-' .
|
||||
@ -1179,7 +1174,7 @@ trait Entities
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$strfind = $find(mb_substr($str, $i + 1), "`", $pos);
|
||||
$strfind = $find(\mb_substr($str, $i + 1), "`", $pos);
|
||||
if ($strfind !== false) {
|
||||
if ($strfind !== "") {
|
||||
$setstr("<code>" . $strfind . "</code>");
|
||||
@ -1192,7 +1187,7 @@ trait Entities
|
||||
);
|
||||
}
|
||||
}
|
||||
} elseif (in_array($curchar, $backslash)) {
|
||||
} elseif (\in_array($curchar, $backslash)) {
|
||||
throw new Exception(
|
||||
"Character '$curchar' is reserved and must be escaped with the preceding '\'"
|
||||
);
|
||||
@ -1221,7 +1216,7 @@ trait Entities
|
||||
}
|
||||
|
||||
/**
|
||||
* elementReader
|
||||
* elementReader.
|
||||
*
|
||||
* @param mixed $element
|
||||
*
|
||||
@ -1265,7 +1260,7 @@ trait Entities
|
||||
if ($entitie) {
|
||||
$entitie["length"] = $this->offset - $entitie["offset"];
|
||||
if ($entitie["length"] > 0) {
|
||||
$this->entities[$ident] = array_merge(
|
||||
$this->entities[$ident] = \array_merge(
|
||||
$entitie,
|
||||
$this->entities[$ident]
|
||||
);
|
||||
@ -1276,7 +1271,7 @@ trait Entities
|
||||
}
|
||||
/**
|
||||
* htmlToEntities
|
||||
* convert html tags to entities
|
||||
* convert html tags to entities.
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
@ -1292,13 +1287,13 @@ trait Entities
|
||||
$this->offset = 0;
|
||||
$this->text = "";
|
||||
$dom = new \DOMDocument();
|
||||
$internalErrors = libxml_use_internal_errors(true);
|
||||
$dom->loadxml("<body>" . str_replace(['&', ''', '"', '&'], ['&', '\'', "\"", '&'], $text) . "</body>");
|
||||
$ar = libxml_get_errors();
|
||||
$internalErrors = \libxml_use_internal_errors(true);
|
||||
$dom->loadxml("<body>" . \str_replace(['&', ''', '"', '&'], ['&', '\'', "\"", '&'], $text) . "</body>");
|
||||
$ar = \libxml_get_errors();
|
||||
if (!empty($ar)) {
|
||||
libxml_clear_errors();
|
||||
\libxml_clear_errors();
|
||||
foreach ($ar as $er) {
|
||||
$er->message = preg_replace(
|
||||
$er->message = \preg_replace(
|
||||
[
|
||||
"/: and body/",
|
||||
"/and body(.+)/isu",
|
||||
@ -1307,23 +1302,23 @@ trait Entities
|
||||
[": ", ""],
|
||||
$er->message
|
||||
);
|
||||
if (in_array($er->code, [76, 40, 801, 73, 800])) {
|
||||
if (\in_array($er->code, [76, 40, 801, 73, 800])) {
|
||||
if (
|
||||
$er->code == 801 &&
|
||||
$this->getEntityNameFromTag(
|
||||
explode(" ", $er->message, 3)[1]
|
||||
\explode(" ", $er->message, 3)[1]
|
||||
) !== false
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
libxml_use_internal_errors($internalErrors);
|
||||
\libxml_use_internal_errors($internalErrors);
|
||||
throw new Exception(
|
||||
$er->message . " in line " . $er->line . PHP_EOL
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
libxml_use_internal_errors($internalErrors);
|
||||
\libxml_use_internal_errors($internalErrors);
|
||||
$this->elementReader($dom->getElementsByTagName("body")[0]);
|
||||
$entities = $this->entities;
|
||||
return $this->text;
|
||||
@ -1331,7 +1326,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* markdownToEntities
|
||||
* convert markdown format to entities
|
||||
* convert markdown format to entities.
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
@ -1349,7 +1344,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* markdownV1ToEntities
|
||||
* convert markdownV1 to entities
|
||||
* convert markdownV1 to entities.
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
@ -1367,7 +1362,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* markdownhtmlToEntities
|
||||
* convert mixed format(with markdown and html) to entities
|
||||
* convert mixed format(with markdown and html) to entities.
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
@ -1385,7 +1380,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* markdownV1htmlToEntities
|
||||
* convert mixed format(with markdownv1 and html) to entities
|
||||
* convert mixed format(with markdownv1 and html) to entities.
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
@ -1403,7 +1398,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* htmlToMarkdown
|
||||
* convert html tags to markdown format
|
||||
* convert html tags to markdown format.
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
@ -1419,7 +1414,7 @@ trait Entities
|
||||
|
||||
/**
|
||||
* htmlToMarkdownv1
|
||||
* convert html tags to markdownv1 format
|
||||
* convert html tags to markdownv1 format.
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
@ -1434,7 +1429,7 @@ trait Entities
|
||||
}
|
||||
|
||||
/**
|
||||
* htmlSpecialChars
|
||||
* htmlSpecialChars.
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
@ -1442,12 +1437,12 @@ trait Entities
|
||||
*/
|
||||
private function htmlSpecialChars(string $str): string
|
||||
{
|
||||
return str_replace(["&", "<", ">"], ["&", "<", ">"], $str);
|
||||
return \str_replace(["&", "<", ">"], ["&", "<", ">"], $str);
|
||||
}
|
||||
|
||||
/**
|
||||
* parseText (main function)
|
||||
* function return formated text with entities or tags or format it to markdown & markdownv1
|
||||
* function return formated text with entities or tags or format it to markdown & markdownv1.
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
@ -1457,7 +1452,7 @@ trait Entities
|
||||
*/
|
||||
public function parseText(string $text, string $mode = "html"): string|array
|
||||
{
|
||||
$mode = strtolower($mode);
|
||||
$mode = \strtolower($mode);
|
||||
$entities = [];
|
||||
|
||||
$text = match ($mode) {
|
||||
|
@ -283,11 +283,20 @@ $MadelineProto->loop(function () use ($MadelineProto) {
|
||||
$mention = yield $MadelineProto->getInfo(\getenv('TEST_USERNAME')); // Returns an array with all of the constructors that can be extracted from a username or an id
|
||||
$mention = $mention['user_id']; // Selects only the numeric user id
|
||||
|
||||
foreach (\json_decode(\getenv('TEST_DESTINATION_GROUPS'), true) as $peer) {
|
||||
$peers = \json_decode(\getenv('TEST_DESTINATION_GROUPS'), true);
|
||||
if (!$peers) {
|
||||
die("No TEST_DESTINATION_GROUPS array was provided!");
|
||||
}
|
||||
foreach ($peers as $peer) {
|
||||
$sentMessage = yield $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => \mb_strlen($message), 'user_id' => $mention]]]);
|
||||
$MadelineProto->logger($sentMessage, \danog\MadelineProto\Logger::NOTICE);
|
||||
|
||||
foreach ($media as $type => $inputMedia) {
|
||||
$MadelineProto->logger("Sending multi $type");
|
||||
yield $MadelineProto->messages->sendMultiMedia(['peer' => $peer, 'multi_media' => [
|
||||
['_' => 'inputSingleMedia', 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown'],
|
||||
['_' => 'inputSingleMedia', 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown'],
|
||||
]]);
|
||||
$MadelineProto->logger("Sending $type");
|
||||
yield $MadelineProto->messages->sendMedia(['peer' => $peer, 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown']);
|
||||
$MadelineProto->logger("Uploading $type");
|
||||
|
Loading…
Reference in New Issue
Block a user