Don't serve Safari XHTML because of a bug in <picture> elements causing multiple images to be downloaded

This commit is contained in:
Alex Cabal 2022-09-26 20:18:04 -05:00
parent f1352ec215
commit 733b52c581
5 changed files with 16 additions and 9 deletions

View file

@ -5,7 +5,6 @@ if($view == ''){
} }
$collection = $collection ?? null; $collection = $collection ?? null;
$ebooks = $ebooks ?? []; $ebooks = $ebooks ?? [];
?> ?>
<ol class="ebooks-list<? if($view == VIEW_LIST){ ?> list<? }else{ ?> grid<? } ?>"<? if($collection !== null){ ?> typeof="schema:BookSeries" about="<?= $collection->Url ?>"<? } ?>> <ol class="ebooks-list<? if($view == VIEW_LIST){ ?> list<? }else{ ?> grid<? } ?>"<? if($collection !== null){ ?> typeof="schema:BookSeries" about="<?= $collection->Url ?>"<? } ?>>

View file

@ -5,15 +5,23 @@ $highlight = $highlight ?? '';
$description = $description ?? ''; $description = $description ?? '';
$manual = $manual ?? false; $manual = $manual ?? false;
$colorScheme = $_COOKIE['color-scheme'] ?? 'auto'; $colorScheme = $_COOKIE['color-scheme'] ?? 'auto';
$xmlDeclaration = $xmlDeclaration ?? true; $isXslt = $isXslt ?? false;
$feedUrl = $feedUrl ?? null; $feedUrl = $feedUrl ?? null;
$feedTitle = $feedTitle ?? ''; $feedTitle = $feedTitle ?? '';
$is404 = $is404 ?? false; $is404 = $is404 ?? false;
if($xmlDeclaration){ // As of Sep 2022, all versions of Safari have a bug where if the page is served as XHTML,
header('content-type: application/xhtml+xml; charset=utf-8'); // then <picture> elements download all <source>s instead of the first supported match.
print('<?xml version="1.0" encoding="utf-8"?>'); // So, we try to detect Safari here, and don't use multiple <source> if we find Safari.
print("\n"); // See https://bugs.webkit.org/show_bug.cgi?id=245411
$isSafari = stripos($_SERVER['HTTP_USER_AGENT'] ?? '', 'safari') !== false;
if(!$isXslt){
if(!$isSafari){
header('content-type: application/xhtml+xml; charset=utf-8');
print('<?xml version="1.0" encoding="utf-8"?>');
print("\n");
}
print("<!DOCTYPE html>\n"); print("<!DOCTYPE html>\n");
} }
?> ?>

View file

@ -8,7 +8,7 @@ print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"> <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
<xsl:output method="html" html-version="5.0" encoding="utf-8" indent="yes" doctype-system="about:legacy-compat"/> <? /* doctype-system outputs the HTML5 doctype */ ?> <xsl:output method="html" html-version="5.0" encoding="utf-8" indent="yes" doctype-system="about:legacy-compat"/> <? /* doctype-system outputs the HTML5 doctype */ ?>
<xsl:template match="/"> <xsl:template match="/">
<?= Template::Header(['xmlDeclaration' => false]) ?> <?= Template::Header(['isXslt' => true]) ?>
<main class="opds"> <main class="opds">
<xsl:choose> <xsl:choose>
<xsl:when test="contains(/atom:feed/atom:title, 'Standard Ebooks - ')"> <xsl:when test="contains(/atom:feed/atom:title, 'Standard Ebooks - ')">

View file

@ -8,7 +8,7 @@ print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom"> <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom">
<xsl:output method="html" html-version="5.0" encoding="utf-8" indent="yes" doctype-system="about:legacy-compat"/> <? /* doctype-system outputs the HTML5 doctype */ ?> <xsl:output method="html" html-version="5.0" encoding="utf-8" indent="yes" doctype-system="about:legacy-compat"/> <? /* doctype-system outputs the HTML5 doctype */ ?>
<xsl:template match="/"> <xsl:template match="/">
<?= Template::Header(['xmlDeclaration' => false]) ?> <?= Template::Header(['isXslt' => true]) ?>
<main class="opds"> <main class="opds">
<xsl:choose> <xsl:choose>
<xsl:when test="contains(/atom:feed/atom:title, 'Standard Ebooks - ')"> <xsl:when test="contains(/atom:feed/atom:title, 'Standard Ebooks - ')">

View file

@ -8,7 +8,7 @@ print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"> <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
<xsl:output method="html" html-version="5.0" encoding="utf-8" indent="yes" doctype-system="about:legacy-compat"/> <? /* doctype-system outputs the HTML5 doctype */ ?> <xsl:output method="html" html-version="5.0" encoding="utf-8" indent="yes" doctype-system="about:legacy-compat"/> <? /* doctype-system outputs the HTML5 doctype */ ?>
<xsl:template match="/"> <xsl:template match="/">
<?= Template::Header(['xmlDeclaration' => false]) ?> <?= Template::Header(['isXslt' => true]) ?>
<main class="opds"> <main class="opds">
<xsl:choose> <xsl:choose>
<xsl:when test="contains(/rss/channel/title, 'Standard Ebooks - ')"> <xsl:when test="contains(/rss/channel/title, 'Standard Ebooks - ')">