mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
dont die if html parsing fails. slack grin instead
This commit is contained in:
parent
c343d0c2b4
commit
a83245afbc
2 changed files with 24 additions and 12 deletions
8
lib/thirdparty/Slack.class.php
vendored
8
lib/thirdparty/Slack.class.php
vendored
|
@ -13,4 +13,12 @@ class Slack
|
|||
Curl::post($slackErrorNotificationUrl, ['text' => ($alert ? '<!channel> ' : '') . Request::getRelativeUri() . "\n" . $e], ['json_data' => true]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function slackGrin()
|
||||
{
|
||||
$slackErrorNotificationUrl = Config::get(Config::SLACK_ERROR_NOTIFICATION_URL);
|
||||
if ($slackErrorNotificationUrl) {
|
||||
Curl::post($slackErrorNotificationUrl, ['text' => '<@U1R0URBC1> Failed to parse html on ' . Request::getRelativeUri()], ['json_data' => true]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,21 +179,25 @@ class View
|
|||
|
||||
public static function safeExternalLinks(string $html, string $domain): string
|
||||
{
|
||||
return $html;
|
||||
try {
|
||||
$parser = new Masterminds\HTML5();
|
||||
$dom = $parser->loadHTML($html);
|
||||
$links = $dom->getElementsByTagName('body') ?
|
||||
$dom->getElementsByTagName('body')[0]->getElementsByTagName('a') :
|
||||
$dom->getElementsByTagName('a');
|
||||
|
||||
$parser = new Masterminds\HTML5();
|
||||
$dom = $parser->loadHTML($html);
|
||||
$links = $dom->getElementsByTagName('body') ?
|
||||
$dom->getElementsByTagName('body')[0]->getElementsByTagName('a') :
|
||||
$dom->getElementsByTagName('a');
|
||||
|
||||
foreach ($links as $link) {
|
||||
if ($link->getAttribute('href') && static::isLinkExternal($link->getAttribute('href'), $domain)) {
|
||||
$link->setAttribute('rel', "noopener noreferrer");
|
||||
foreach ($links as $link) {
|
||||
if ($link->getAttribute('href') && static::isLinkExternal($link->getAttribute('href'), $domain)) {
|
||||
$link->setAttribute('rel', "noopener noreferrer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $parser->saveHTML($dom);
|
||||
return $parser->saveHTML($dom);
|
||||
}
|
||||
catch (Error $e) {
|
||||
Slack::slackGrin();
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
public static function isLinkExternal(string $url, string $domain): bool
|
||||
|
|
Loading…
Add table
Reference in a new issue