diff --git a/modules/quant_api/src/EventSubscriber/QuantApi.php b/modules/quant_api/src/EventSubscriber/QuantApi.php index 750fd424..9938f46e 100644 --- a/modules/quant_api/src/EventSubscriber/QuantApi.php +++ b/modules/quant_api/src/EventSubscriber/QuantApi.php @@ -263,8 +263,13 @@ public function onOutput(QuantEvent $event) { /** @var \DOMElement $node */ foreach ($xpath->query('//iframe[contains(@src, "/media/oembed")]') as $node) { $oembed_url = $new_href = $node->getAttribute('src'); - $oembed_item = new RouteItem(['route' => $oembed_url]); - $oembed_item->send(); + // Only add if it's a relative URL to handle the case where the URL + // contains `/media/oembed` but is from another website. + if (str_starts_with($oembed_url, '/')) { + $oembed_item = new RouteItem(['route' => $oembed_url]); + $oembed_item->send(); + $this->logger->notice("[route_item] $oembed_url"); + } } // @todo Report on forms that need proxying (attachments.forms). diff --git a/src/Seed.php b/src/Seed.php index 6ea13498..d7daee31 100644 --- a/src/Seed.php +++ b/src/Seed.php @@ -639,17 +639,37 @@ public static function rewriteRelative($markup) { // Do not strip host domain unless configured. $strip = $config->get('host_domain_strip') ?: FALSE; if (!$strip) { + // Handle iframes even if `host_domain_strip` is disabled, so iframe + // renders correctly. + $markup = self::rewriteRelativeIframe($markup); + return $markup; } // Strip the host domain from everywhere in the content including header // metadata such as canonical links. - $hostname = $config->get('host_domain') ?: $_SERVER['SERVER_NAME']; - $port = $_SERVER['SERVER_PORT']; - $markup = preg_replace("/(https?:\/\/)?{$hostname}(\:{$port})?/i", '', $markup); + $markup = Utility::stripLocalHost($markup); - // Edge case: Replace http://default when run via drush without base_url. - $markup = preg_replace("/http:\/\/default/i", '', $markup); + return $markup; + } + + /** + * Replaces absolute iframe URLs with relative in markup. + * + * @param string $markup + * The markup to search and rewire relative iframe paths for. + * + * @return string + * Sanitized markup string. + */ + public static function rewriteRelativeIframe($markup) { + $pattern = '/