1<?php 2 3namespace dokuwiki; 4 5use dokuwiki\Extension\Event; 6 7class Manifest 8{ 9 public function sendManifest() 10 { 11 $manifest = retrieveConfig('manifest', 'jsonToArray'); 12 13 global $conf; 14 15 $manifest['scope'] = DOKU_REL; 16 17 if (empty($manifest['name'])) { 18 $manifest['name'] = html_entity_decode( 19 strip_tags($conf['title']), 20 ENT_QUOTES | ENT_HTML5, 21 'UTF-8' 22 ); 23 } 24 25 if (empty($manifest['short_name'])) { 26 $manifest['short_name'] = html_entity_decode( 27 strip_tags($conf['title']), 28 ENT_QUOTES | ENT_HTML5, 29 'UTF-8' 30 ); 31 } 32 33 if (empty($manifest['description'])) { 34 $manifest['description'] = html_entity_decode( 35 strip_tags($conf['tagline']), 36 ENT_QUOTES | ENT_HTML5, 37 'UTF-8' 38 ); 39 } 40 41 if (empty($manifest['start_url'])) { 42 $manifest['start_url'] = DOKU_REL; 43 } 44 45 $styleUtil = new StyleUtils(); 46 $styleIni = $styleUtil->cssStyleini(); 47 $replacements = $styleIni['replacements']; 48 49 if (empty($manifest['background_color'])) { 50 $manifest['background_color'] = $replacements['__background__']; 51 } 52 53 if (empty($manifest['theme_color'])) { 54 $manifest['theme_color'] = empty($replacements['__theme_color__']) 55 ? $replacements['__background_alt__'] 56 : $replacements['__theme_color__']; 57 } 58 59 if (empty($manifest['icons'])) { 60 $manifest['icons'] = []; 61 if (file_exists(mediaFN(':wiki:favicon.ico'))) { 62 $url = ml(':wiki:favicon.ico', '', true, '', true); 63 $manifest['icons'][] = [ 64 'src' => $url, 65 'sizes' => '16x16', 66 ]; 67 } 68 69 $look = [ 70 ':wiki:logo.svg', 71 ':logo.svg', 72 ':wiki:dokuwiki.svg' 73 ]; 74 75 foreach ($look as $svgLogo) { 76 $svgLogoFN = mediaFN($svgLogo); 77 78 if (file_exists($svgLogoFN)) { 79 $url = ml($svgLogo, '', true, '', true); 80 $manifest['icons'][] = [ 81 'src' => $url, 82 'sizes' => '17x17 512x512', 83 'type' => 'image/svg+xml', 84 ]; 85 break; 86 }; 87 } 88 } 89 90 Event::createAndTrigger('MANIFEST_SEND', $manifest); 91 92 header('Content-Type: application/manifest+json'); 93 echo json_encode($manifest, JSON_THROW_ON_ERROR); 94 } 95} 96