manifest.json.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  4. * Copyright (C) 2007-2017 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
  6. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FI8TNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/theme/md/manifest.json.php
  24. * \brief File for The Web App (PWA)
  25. */
  26. if (!defined('NOREQUIREUSER')) {
  27. define('NOREQUIREUSER', '1');
  28. }
  29. if (!defined('NOREQUIRESOC')) {
  30. define('NOREQUIRESOC', '1');
  31. }
  32. if (!defined('NOREQUIRETRAN')) {
  33. define('NOREQUIRETRAN', '1');
  34. }
  35. if (!defined('NOTOKENRENEWAL')) {
  36. define('NOTOKENRENEWAL', '1');
  37. }
  38. if (!defined('NOLOGIN')) {
  39. define('NOLOGIN', '1');
  40. }
  41. if (!defined('NOREQUIREMENU')) {
  42. define('NOREQUIREMENU', '1');
  43. }
  44. if (!defined('NOREQUIREHTML')) {
  45. define('NOREQUIREHTML', '1');
  46. }
  47. if (!defined('NOREQUIREAJAX')) {
  48. define('NOREQUIREAJAX', '1');
  49. }
  50. if (!defined('NOSESSION')) {
  51. define('NOSESSION', '1');
  52. }
  53. require_once __DIR__.'/../../main.inc.php';
  54. top_httphead('text/json');
  55. // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
  56. if (empty($dolibarr_nocache)) {
  57. header('Cache-Control: max-age=10800, public, must-revalidate');
  58. // For a text/json, we must set an Expires to avoid to have it forced to an expired value by the web server
  59. header('Expires: '.gmdate('D, d M Y H:i:s', dol_now('gmt') + 10800).' GMT');
  60. } else {
  61. header('Cache-Control: no-cache');
  62. }
  63. $manifest = new stdClass();
  64. $manifest->manifest_version = 3;
  65. $manifest->name = constant('DOL_APPLICATION_TITLE');
  66. if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
  67. $manifest->name = getDolGlobalString('MAIN_APPLICATION_TITLE');
  68. }
  69. $manifest->short_name = $manifest->name;
  70. $manifest->theme_color = getDolGlobalString('MAIN_MANIFEST_APPLI_THEME_COLOR', getDolGlobalString('THEME_ELDY_TOPMENU_BACK1', '#F05F40'));
  71. if (!preg_match('/#[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]$/', $manifest->theme_color)) {
  72. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  73. $manifest->theme_color = '#'.colorArrayToHex(colorStringToArray($manifest->theme_color));
  74. }
  75. $manifest->background_color = getDolGlobalString('MAIN_MANIFEST_APPLI_BG_COLOR', "#ffffff");
  76. if (!preg_match('/#[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]$/', $manifest->background_color)) {
  77. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  78. $manifest->background_color = '#'.colorArrayToHex(colorStringToArray($manifest->background_color));
  79. }
  80. $manifest->display = getDolGlobalString('MAIN_MANIFEST_DISPLAY', "minimal-ui");
  81. $manifest->splash_pages = null;
  82. $manifest->icons = array();
  83. $manifest->start_url = constant('DOL_MAIN_URL_ROOT');
  84. $manifest->id = constant('DOL_MAIN_URL_ROOT');
  85. if (getDolGlobalString('MAIN_MANIFEST_APPLI_LOGO_URL')) {
  86. $icon = new stdClass();
  87. $icon->src = getDolGlobalString('MAIN_MANIFEST_APPLI_LOGO_URL');
  88. if (getDolGlobalString('MAIN_MANIFEST_APPLI_LOGO_URL_SIZE')) {
  89. $icon->sizes = getDolGlobalString('MAIN_MANIFEST_APPLI_LOGO_URL_SIZE') . "x" . getDolGlobalString('MAIN_MANIFEST_APPLI_LOGO_URL_SIZE');
  90. } else {
  91. $icon->sizes = "512x512";
  92. }
  93. $icon->type = "image/png";
  94. $manifest->icons[] = $icon;
  95. } elseif (getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED')) {
  96. if (getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI')) {
  97. $iconRelativePath = 'logos/thumbs/' . getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI');
  98. $iconPath = $conf->mycompany->dir_output.'/'.$iconRelativePath;
  99. if (is_readable($iconPath)) {
  100. $imgSize = getimagesize($iconPath);
  101. if (!empty($imgSize)) {
  102. $icon = new stdClass();
  103. $icon->src = DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode($iconRelativePath);
  104. $icon->sizes = $imgSize[0]."x".$imgSize[1];
  105. $icon->type = "image/png";
  106. $manifest->icons[] = $icon;
  107. }
  108. }
  109. }
  110. if (getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL')) {
  111. $iconRelativePath = 'logos/thumbs/' . getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL');
  112. $iconPath = $conf->mycompany->dir_output.'/'.$iconRelativePath;
  113. if (is_readable($iconPath)) {
  114. $imgSize = getimagesize($iconPath);
  115. if ($imgSize) {
  116. $icon = new stdClass();
  117. $icon->src = DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode($iconRelativePath);
  118. $icon->sizes = $imgSize[0]."x".$imgSize[1];
  119. $icon->type = "image/png";
  120. $manifest->icons[] = $icon;
  121. }
  122. }
  123. }
  124. if (getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED')) {
  125. $iconRelativePath = 'logos/' . getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED');
  126. $iconPath = $conf->mycompany->dir_output.'/'.$iconRelativePath;
  127. if (is_readable($iconPath)) {
  128. $imgSize = getimagesize($iconPath);
  129. if ($imgSize) {
  130. $icon = new stdClass();
  131. $icon->src = DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode($iconRelativePath);
  132. $icon->sizes = $imgSize[0]."x".$imgSize[1];
  133. $icon->type = "image/png";
  134. $manifest->icons[] = $icon;
  135. }
  136. }
  137. }
  138. }
  139. // Add Dolibarr std icon
  140. if (empty($manifest->icons)) {
  141. $icon = new stdClass();
  142. $icon->src = DOL_URL_ROOT.'/theme/dolibarr_256x256_color.png';
  143. $icon->sizes = "256x256";
  144. $icon->type = "image/png";
  145. $manifest->icons[] = $icon;
  146. }
  147. print json_encode($manifest);