38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
|
|
if (! function_exists('setupPageMetadata')) {
|
|
function setupPageMetadata(array $page, string $requestUri): array
|
|
{
|
|
$globals = $page['globals'] ?? [];
|
|
|
|
$title = htmlspecialchars($page['metadata']['title'] ?? '', ENT_QUOTES, 'UTF-8');
|
|
$description = htmlspecialchars($page['metadata']['description'] ?? '', ENT_QUOTES, 'UTF-8');
|
|
$image = htmlspecialchars(
|
|
$page['metadata']['open_graph_image'] ?? $globals['metadata']['open_graph_image'] ?? '',
|
|
ENT_QUOTES,
|
|
'UTF-8'
|
|
);
|
|
$fullUrl = $globals['url'].$requestUri;
|
|
$oembedUrl = $globals['url'].'/oembed'.$requestUri;
|
|
|
|
return [
|
|
'pageTitle' => $title,
|
|
'pageDescription' => $description,
|
|
'ogImage' => $image,
|
|
'fullUrl' => $fullUrl,
|
|
'oembedUrl' => $oembedUrl,
|
|
'globals' => $globals,
|
|
];
|
|
}
|
|
}
|
|
|
|
if (! function_exists('cleanMeta')) {
|
|
function cleanMeta($value)
|
|
{
|
|
$value = trim($value ?? '');
|
|
$value = str_replace(["\r", "\n"], ' ', $value);
|
|
$value = preg_replace('/\s+/', ' ', $value);
|
|
|
|
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
}
|