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'] = $conf['title']; 19 } 20 21 if (empty($manifest['short_name'])) { 22 $manifest['short_name'] = $conf['title']; 23 } 24 25 if (empty($manifest['description'])) { 26 $manifest['description'] = $conf['tagline']; 27 } 28 29 if (empty($manifest['start_url'])) { 30 $manifest['start_url'] = DOKU_REL; 31 } 32 33 $styleUtil = new StyleUtils(); 34 $styleIni = $styleUtil->cssStyleini(); 35 $replacements = $styleIni['replacements']; 36 37 if (empty($manifest['background_color'])) { 38 $manifest['background_color'] = $replacements['__background__']; 39 } 40 41 if (empty($manifest['theme_color'])) { 42 $manifest['theme_color'] = empty($replacements['__theme_color__']) 43 ? $replacements['__background_alt__'] 44 : $replacements['__theme_color__']; 45 } 46 47 if (empty($manifest['icons'])) { 48 $manifest['icons'] = []; 49 if (file_exists(mediaFN(':wiki:favicon.ico'))) { 50 $url = ml(':wiki:favicon.ico', '', true, '', true); 51 $manifest['icons'][] = [ 52 'src' => $url, 53 'sizes' => '16x16', 54 ]; 55 } 56 57 $look = [ 58 ':wiki:logo.svg', 59 ':logo.svg', 60 ':wiki:dokuwiki.svg' 61 ]; 62 63 foreach ($look as $svgLogo) { 64 $svgLogoFN = mediaFN($svgLogo); 65 66 if (file_exists($svgLogoFN)) { 67 $url = ml($svgLogo, '', true, '', true); 68 $manifest['icons'][] = [ 69 'src' => $url, 70 'sizes' => '17x17 512x512', 71 'type' => 'image/svg+xml', 72 ]; 73 break; 74 }; 75 } 76 } 77 78 Event::createAndTrigger('MANIFEST_SEND', $manifest); 79 80 header('Content-Type: application/manifest+json'); 81 echo json_encode($manifest, JSON_THROW_ON_ERROR); 82 } 83} 84