dokuwiki/inc/Manifest.php

84 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace dokuwiki;
use dokuwiki\Extension\Event;
class Manifest
{
public function sendManifest()
{
$manifest = retrieveConfig('manifest', 'jsonToArray');
global $conf;
$manifest['scope'] = DOKU_REL;
if (empty($manifest['name'])) {
$manifest['name'] = $conf['title'];
}
if (empty($manifest['short_name'])) {
$manifest['short_name'] = $conf['title'];
}
if (empty($manifest['description'])) {
$manifest['description'] = $conf['tagline'];
}
if (empty($manifest['start_url'])) {
$manifest['start_url'] = DOKU_REL;
}
2023-08-29 19:42:15 +02:00
$styleUtil = new StyleUtils();
Use config cascade for style.ini files This simplifies style loading and allows the plugins like farmer to extend the the loading of style files. Also adds some first unit tests. Originally discussed in FS#2703 and #134 Squashed commit of the following: commit 5ed550f6ba61a1d475b7572cbff18f0d790c78c2 Merge: 0cefed65e cab1833b0 Author: Andreas Gohr <gohr@cosmocode.de> Date: Thu Feb 28 13:38:46 2019 +0100 Merge branch 'styleConfCascade' of https://github.com/annda/dokuwiki into annda-styleConfCascade * 'styleConfCascade' of https://github.com/annda/dokuwiki: Clean up StyleUtils Update StyleUtils test Fix array to boolean conversion Use better placeholder string in config cascade Calls to StyleUtils use the new constructor Add test for StyleUtils Refactor StyleUtils WIP add temporary test comparing two implementations of StyleUtils WIP add new style config cascade side by side with the old one commit cab1833b09a59331a5580fe0e3e6f36d743dea09 Author: Anna Dabrowska <dabrowska@cosmocode.de> Date: Thu Feb 21 17:54:27 2019 +0100 Clean up StyleUtils commit 766e3907cf7b234c3f2fa7bf86f205c1c8c7c6e1 Author: Anna Dabrowska <dabrowska@cosmocode.de> Date: Thu Feb 21 17:51:15 2019 +0100 Update StyleUtils test commit f5c08787ddf9db60e3429421e5c627d5c81d876a Author: Anna Dabrowska <dabrowska@cosmocode.de> Date: Thu Feb 21 12:51:53 2019 +0100 Fix array to boolean conversion commit c9671698992328d5671a43b2707ffc6c5b117423 Author: Anna Dabrowska <dabrowska@cosmocode.de> Date: Thu Feb 21 12:38:55 2019 +0100 Use better placeholder string in config cascade commit 4845eff54d227325476bb00b7c8402ce58cf72df Author: Anna Dabrowska <dabrowska@cosmocode.de> Date: Thu Feb 21 12:24:16 2019 +0100 Calls to StyleUtils use the new constructor commit 7a6337a8f8f2cc0cedbf54ae0b43e94033192cb8 Author: Anna Dabrowska <dabrowska@cosmocode.de> Date: Thu Feb 21 12:22:44 2019 +0100 Add test for StyleUtils commit 5ae9e8f69e076ab2a18b24aa178cca15fea6b000 Author: Anna Dabrowska <dabrowska@cosmocode.de> Date: Thu Feb 21 12:16:57 2019 +0100 Refactor StyleUtils commit a2adcc9f37be93f4bcf90fdba4089ea4b0d6436e Author: Anna Dabrowska <dabrowska@cosmocode.de> Date: Sat Feb 16 23:58:04 2019 +0100 WIP add temporary test comparing two implementations of StyleUtils commit 845c40c4faf379a65134e171514a09d47ffe95f1 Author: Anna Dabrowska <dabrowska@cosmocode.de> Date: Sat Feb 16 23:59:41 2019 +0100 WIP add new style config cascade side by side with the old one
2019-02-28 13:45:19 +01:00
$styleIni = $styleUtil->cssStyleini();
$replacements = $styleIni['replacements'];
if (empty($manifest['background_color'])) {
$manifest['background_color'] = $replacements['__background__'];
}
if (empty($manifest['theme_color'])) {
2023-08-29 19:42:15 +02:00
$manifest['theme_color'] = empty($replacements['__theme_color__'])
? $replacements['__background_alt__']
: $replacements['__theme_color__'];
}
if (empty($manifest['icons'])) {
$manifest['icons'] = [];
if (file_exists(mediaFN(':wiki:favicon.ico'))) {
$url = ml(':wiki:favicon.ico', '', true, '', true);
$manifest['icons'][] = [
'src' => $url,
'sizes' => '16x16',
];
}
$look = [
':wiki:logo.svg',
':logo.svg',
':wiki:dokuwiki.svg'
];
foreach ($look as $svgLogo) {
$svgLogoFN = mediaFN($svgLogo);
if (file_exists($svgLogoFN)) {
$url = ml($svgLogo, '', true, '', true);
$manifest['icons'][] = [
'src' => $url,
'sizes' => '17x17 512x512',
'type' => 'image/svg+xml',
];
break;
};
}
}
Event::createAndTrigger('MANIFEST_SEND', $manifest);
header('Content-Type: application/manifest+json');
2023-08-29 19:42:15 +02:00
echo json_encode($manifest, JSON_THROW_ON_ERROR);
}
}