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]);
|
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,8 +179,7 @@ class View
|
||||||
|
|
||||||
public static function safeExternalLinks(string $html, string $domain): string
|
public static function safeExternalLinks(string $html, string $domain): string
|
||||||
{
|
{
|
||||||
return $html;
|
try {
|
||||||
|
|
||||||
$parser = new Masterminds\HTML5();
|
$parser = new Masterminds\HTML5();
|
||||||
$dom = $parser->loadHTML($html);
|
$dom = $parser->loadHTML($html);
|
||||||
$links = $dom->getElementsByTagName('body') ?
|
$links = $dom->getElementsByTagName('body') ?
|
||||||
|
@ -195,6 +194,11 @@ class View
|
||||||
|
|
||||||
return $parser->saveHTML($dom);
|
return $parser->saveHTML($dom);
|
||||||
}
|
}
|
||||||
|
catch (Error $e) {
|
||||||
|
Slack::slackGrin();
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function isLinkExternal(string $url, string $domain): bool
|
public static function isLinkExternal(string $url, string $domain): bool
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue