20 lines
790 B
PHP
20 lines
790 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
final class ResourceArticlePresentation
|
|
{
|
|
/** Remove legacy follow prompts only from the two daily resource columns. */
|
|
public static function body(string $html, ?string $category): string
|
|
{
|
|
if (! in_array($category, ['freenode', 'shadowrocketids'], true)) return $html;
|
|
|
|
return preg_replace_callback('~<p\b[^>]*>.*?</p>(?:\s*<p\b[^>]*>\s*</p>)*~si', static function (array $match): string {
|
|
$text = html_entity_decode(strip_tags($match[0]), ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
|
$text = preg_replace('/\s+/u', '', $text);
|
|
if (preg_match('/点击加入我们的(?:tg|telegram)频道|点击关注我们的github仓库/iu', $text)) return '';
|
|
return $match[0];
|
|
}, $html);
|
|
}
|
|
}
|