| Server IP : 139.59.63.204 / Your IP : 216.73.217.62 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ubuntu-s-1vcpu-1gb-blr1-01 6.8.0-110-generic #110-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 19 15:09:20 UTC 2026 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/abyogasms.com/vendor/league/commonmark/src/Extension/Embed/ |
Upload File : |
<?php
declare(strict_types=1);
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Extension\Embed;
class DomainFilteringAdapter implements EmbedAdapterInterface
{
private EmbedAdapterInterface $decorated;
/** @var string[] */
private array $allowedDomains;
/**
* @param string[] $allowedDomains
*/
public function __construct(EmbedAdapterInterface $decorated, array $allowedDomains)
{
$this->decorated = $decorated;
$this->allowedDomains = \array_map('strtolower', $allowedDomains);
}
/**
* {@inheritDoc}
*/
public function updateEmbeds(array $embeds): void
{
$this->decorated->updateEmbeds(\array_values(\array_filter($embeds, [$this, 'isAllowed'])));
}
private function isAllowed(Embed $embed): bool
{
$url = $embed->getUrl();
$scheme = \parse_url($url, \PHP_URL_SCHEME);
if ($scheme === null || $scheme === false) {
// Bare domain (no scheme) - assume https:// so parse_url can extract the host
$url = 'https://' . $url;
} elseif (\strtolower($scheme) !== 'http' && \strtolower($scheme) !== 'https') {
return false;
}
$host = \parse_url($url, \PHP_URL_HOST);
$host = \strtolower(\rtrim((string) $host, '.'));
foreach ($this->allowedDomains as $domain) {
if ($host === $domain || \str_ends_with($host, '.' . $domain)) {
return true;
}
}
return false;
}
}