mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-12-31 03:52:01 +08:00
Speedup \MailSo\Base\HtmlUtils::BuildHtml()
This commit is contained in:
parent
059b9eb322
commit
75766573e9
1 changed files with 22 additions and 41 deletions
|
@ -191,60 +191,33 @@ abstract class HtmlUtils
|
|||
return $sResult;
|
||||
}
|
||||
|
||||
private static function ClearTags(\DOMDocument $oDom, bool $bClearStyleAndHead = true) : void
|
||||
{
|
||||
$aRemoveTags = array(
|
||||
'svg', 'link', 'base', 'meta', 'title', 'x-script', 'script', 'bgsound', 'keygen', 'source',
|
||||
'object', 'embed', 'applet', 'mocha', 'iframe', 'frame', 'frameset', 'video', 'audio', 'area', 'map'
|
||||
);
|
||||
|
||||
if ($bClearStyleAndHead)
|
||||
{
|
||||
$aRemoveTags[] = 'head';
|
||||
$aRemoveTags[] = 'style';
|
||||
}
|
||||
|
||||
$aRemove = array();
|
||||
$aNodes = $oDom->getElementsByTagName('*');
|
||||
foreach ($aNodes as /* @var $oElement \DOMElement */ $oElement)
|
||||
{
|
||||
if ($oElement)
|
||||
{
|
||||
$sTagNameLower = \trim(\strtolower($oElement->tagName));
|
||||
if ('' !== $sTagNameLower)
|
||||
{
|
||||
if (\in_array($sTagNameLower, $aRemoveTags))
|
||||
{
|
||||
$aRemove[] = @$oElement;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($aRemove as /* @var $oElement \DOMElement */ $oElement)
|
||||
{
|
||||
if (isset($oElement->parentNode))
|
||||
{
|
||||
@$oElement->parentNode->removeChild($oElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by DoSaveMessage() and DoSendMessage()
|
||||
*/
|
||||
public static function BuildHtml(string $sHtml, array &$aFoundCids, array &$aFoundDataURL, array &$aFoundContentLocationUrls) : string
|
||||
{
|
||||
$oDom = static::GetDomFromText($sHtml);
|
||||
|
||||
static::ClearTags($oDom);
|
||||
unset($sHtml);
|
||||
|
||||
$aRemoveTags = array(
|
||||
'svg', 'link', 'base', 'meta', 'title', 'x-script', 'script', 'bgsound', 'keygen', 'source',
|
||||
'object', 'embed', 'applet', 'mocha', 'iframe', 'frame', 'frameset', 'video', 'audio', 'area', 'map',
|
||||
'head', 'style'
|
||||
);
|
||||
|
||||
$aRemove = array();
|
||||
|
||||
$aNodes = $oDom->getElementsByTagName('*');
|
||||
foreach ($aNodes as /* @var $oElement \DOMElement */ $oElement)
|
||||
{
|
||||
$sTagNameLower = \strtolower($oElement->tagName);
|
||||
|
||||
if (\in_array($sTagNameLower, $aRemoveTags))
|
||||
{
|
||||
$aRemove[] = @$oElement;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($oElement->hasAttribute('data-x-src-cid'))
|
||||
{
|
||||
$sCid = $oElement->getAttribute('data-x-src-cid');
|
||||
|
@ -361,6 +334,14 @@ abstract class HtmlUtils
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($aRemove as /* @var $oElement \DOMElement */ $oElement)
|
||||
{
|
||||
if (isset($oElement->parentNode))
|
||||
{
|
||||
@$oElement->parentNode->removeChild($oElement);
|
||||
}
|
||||
}
|
||||
|
||||
$sResult = static::GetTextFromDom($oDom, false);
|
||||
unset($oDom);
|
||||
|
||||
|
|
Loading…
Reference in a new issue