1<?php 2 3namespace dokuwiki; 4 5class Manifest 6{ 7 public function sendManifest() 8 { 9 $manifest = retrieveConfig('manifest', 'jsonToArray'); 10 11 global $conf; 12 13 $manifest['scope'] = DOKU_REL; 14 15 if (empty($manifest['name'])) { 16 $manifest['name'] = $conf['title']; 17 } 18 19 if (empty($manifest['short_name'])) { 20 $manifest['short_name'] = $conf['title']; 21 } 22 23 if (empty($manifest['description'])) { 24 $manifest['description'] = $conf['tagline']; 25 } 26 27 if (empty($manifest['start_url'])) { 28 $manifest['start_url'] = DOKU_REL; 29 } 30 31 $styleUtil = new \dokuwiki\StyleUtils(); 32 $styleIni = $styleUtil->cssStyleini($conf['template']); 33 $replacements = $styleIni['replacements']; 34 35 if (empty($manifest['background_color'])) { 36 $manifest['background_color'] = $replacements['__background__']; 37 } 38 39 if (empty($manifest['theme_color'])) { 40 $manifest['theme_color'] = !empty($replacements['__theme_color__']) ? $replacements['__theme_color__'] : $replacements['__background_alt__']; 41 } 42 43 if (empty($manifest['icons'])) { 44 $manifest['icons'] = []; 45 $look = [ 46 ':wiki:logo.png', 47 ':logo.png', 48 'images/logo.png', 49 ':wiki:apple-touch-icon.png', 50 ':apple-touch-icon.png', 51 'images/apple-touch-icon.png', 52 ':wiki:favicon.svg', 53 ':favicon.svg', 54 'images/favicon.svg', 55 ':wiki:favicon.ico', 56 ':favicon.ico', 57 'images/favicon.ico', 58 ':wiki:logo', 59 ]; 60 61 $abs = true; 62 foreach ($look as $img) { 63 if ($img[0] === ':') { 64 $file = mediaFN($img); 65 $ismedia = true; 66 } else { 67 $file = tpl_incdir() . $img; 68 $ismedia = false; 69 } 70 71 if (file_exists($file)) { 72 $imginfo = getimagesize($file); 73 if ($ismedia) { 74 $url = ml($img, '', true, '', $abs); 75 } else { 76 $url = tpl_basedir() . $img; 77 if ($abs) { 78 $url = DOKU_URL . substr($url, strlen(DOKU_REL)); 79 } 80 } 81 $manifest['icons'][] = [ 82 'src' => $url, 83 'sizes' => $imginfo[0] . 'x' . $imginfo[1], 84 'type' => $imginfo['mime'], 85 ]; 86 }; 87 } 88 } 89 90 trigger_event('MANIFEST_SEND', $manifest); 91 92 header('Content-Type: application/manifest+json'); 93 echo json_encode($manifest); 94 } 95} 96