47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
class DocumentHelper
|
|
{
|
|
|
|
/**
|
|
* Extract the Issuu embed URL from an iframe or raw Issuu input.
|
|
*
|
|
* This helper is used when storing a document.
|
|
* It allows users to paste either:
|
|
* - a full Issuu iframe embed code, or
|
|
* - a direct Issuu embed URL
|
|
*
|
|
* The method normalizes the input by extracting and returning
|
|
* the usable Issuu embed URL (`https://e.issuu.com/embed.html?...`)
|
|
* that can safely be used on front-end pages.
|
|
*
|
|
* HTML entities (e.g. `&`) are automatically decoded.
|
|
*
|
|
* @param string|null $issuIframe Raw Issuu iframe HTML or embed URL
|
|
* @return string|null The normalized Issuu embed URL, or null if none is found
|
|
*/
|
|
public static function extractDocumentFromIssuIframe(?string $issuIframe): ?string
|
|
{
|
|
$content = trim((string) $issuIframe);
|
|
|
|
if ($content === '') {
|
|
return null;
|
|
}
|
|
|
|
if (str_starts_with($content, 'https://e.issuu.com/embed.html')) {
|
|
return html_entity_decode($content, ENT_QUOTES);
|
|
}
|
|
|
|
preg_match(
|
|
'/src="(https:\/\/e\.issuu\.com\/embed\.html\?[^"]+)"/',
|
|
$content,
|
|
$matches
|
|
);
|
|
|
|
return isset($matches[1])
|
|
? html_entity_decode($matches[1], ENT_QUOTES)
|
|
: null;
|
|
}
|
|
}
|