Manifest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace dokuwiki;
  3. use dokuwiki\Extension\Event;
  4. class Manifest
  5. {
  6. public function sendManifest()
  7. {
  8. $manifest = retrieveConfig('manifest', 'jsonToArray');
  9. global $conf;
  10. $manifest['scope'] = DOKU_REL;
  11. if (empty($manifest['name'])) {
  12. $manifest['name'] = $conf['title'];
  13. }
  14. if (empty($manifest['short_name'])) {
  15. $manifest['short_name'] = $conf['title'];
  16. }
  17. if (empty($manifest['description'])) {
  18. $manifest['description'] = $conf['tagline'];
  19. }
  20. if (empty($manifest['start_url'])) {
  21. $manifest['start_url'] = DOKU_REL;
  22. }
  23. $styleUtil = new \dokuwiki\StyleUtils();
  24. $styleIni = $styleUtil->cssStyleini();
  25. $replacements = $styleIni['replacements'];
  26. if (empty($manifest['background_color'])) {
  27. $manifest['background_color'] = $replacements['__background__'];
  28. }
  29. if (empty($manifest['theme_color'])) {
  30. $manifest['theme_color'] = !empty($replacements['__theme_color__'])
  31. ? $replacements['__theme_color__']
  32. : $replacements['__background_alt__'];
  33. }
  34. if (empty($manifest['icons'])) {
  35. $manifest['icons'] = [];
  36. if (file_exists(mediaFN(':wiki:favicon.ico'))) {
  37. $url = ml(':wiki:favicon.ico', '', true, '', true);
  38. $manifest['icons'][] = [
  39. 'src' => $url,
  40. 'sizes' => '16x16',
  41. ];
  42. }
  43. $look = [
  44. ':wiki:logo.svg',
  45. ':logo.svg',
  46. ':wiki:dokuwiki.svg'
  47. ];
  48. foreach ($look as $svgLogo) {
  49. $svgLogoFN = mediaFN($svgLogo);
  50. if (file_exists($svgLogoFN)) {
  51. $url = ml($svgLogo, '', true, '', true);
  52. $manifest['icons'][] = [
  53. 'src' => $url,
  54. 'sizes' => '17x17 512x512',
  55. 'type' => 'image/svg+xml',
  56. ];
  57. break;
  58. };
  59. }
  60. }
  61. Event::createAndTrigger('MANIFEST_SEND', $manifest);
  62. header('Content-Type: application/manifest+json');
  63. echo json_encode($manifest);
  64. }
  65. }