dolibarr/htdocs/theme/md/manifest.json.php

166 lines
6.0 KiB
PHP
Raw Permalink Normal View History

2020-05-08 00:01:56 +02:00
<?php
/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2007-2017 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
2020-05-08 00:01:56 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FI8TNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2022-09-07 20:21:01 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2020-05-08 00:01:56 +02:00
*/
/**
* \file htdocs/theme/md/manifest.json.php
2023-11-27 13:26:44 +01:00
* \brief File for The Web App (PWA)
2020-05-08 00:01:56 +02:00
*/
2021-02-26 13:31:09 +01:00
if (!defined('NOREQUIREUSER')) {
define('NOREQUIREUSER', '1');
}
if (!defined('NOREQUIRESOC')) {
define('NOREQUIRESOC', '1');
}
if (!defined('NOREQUIRETRAN')) {
define('NOREQUIRETRAN', '1');
}
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1');
}
if (!defined('NOLOGIN')) {
define('NOLOGIN', '1');
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
2020-05-08 00:01:56 +02:00
require_once __DIR__.'/../../main.inc.php';
/**
* @var Conf $conf
*/
2020-09-24 16:19:24 +02:00
top_httphead('text/json');
// Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
2021-02-17 15:00:32 +01:00
if (empty($dolibarr_nocache)) {
header('Cache-Control: max-age=10800, public, must-revalidate');
// For a text/json, we must set an Expires to avoid to have it forced to an expired value by the web server
header('Expires: '.gmdate('D, d M Y H:i:s', dol_now('gmt') + 10800).' GMT');
2021-02-26 13:31:09 +01:00
} else {
2021-02-17 15:00:32 +01:00
header('Cache-Control: no-cache');
}
2020-09-24 16:19:24 +02:00
2023-08-15 11:53:44 +02:00
$manifest = new stdClass();
2023-12-05 10:08:16 +01:00
$manifest->manifest_version = 3;
2023-08-15 11:53:44 +02:00
$manifest->name = constant('DOL_APPLICATION_TITLE');
2023-11-27 12:08:48 +01:00
if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
2023-12-26 12:31:46 +01:00
$manifest->name = getDolGlobalString('MAIN_APPLICATION_TITLE');
2023-08-15 11:53:44 +02:00
}
$manifest->short_name = $manifest->name;
2023-12-26 12:31:46 +01:00
$manifest->theme_color = getDolGlobalString('MAIN_MANIFEST_APPLI_THEME_COLOR', getDolGlobalString('THEME_ELDY_TOPMENU_BACK1', '#F05F40'));
if (!preg_match('/#[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]$/', $manifest->theme_color)) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$manifest->theme_color = '#'.colorArrayToHex(colorStringToArray($manifest->theme_color));
}
2023-12-26 12:31:46 +01:00
$manifest->background_color = getDolGlobalString('MAIN_MANIFEST_APPLI_BG_COLOR', "#ffffff");
if (!preg_match('/#[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]$/', $manifest->background_color)) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$manifest->background_color = '#'.colorArrayToHex(colorStringToArray($manifest->background_color));
}
2023-12-26 12:31:46 +01:00
$manifest->display = getDolGlobalString('MAIN_MANIFEST_DISPLAY', "minimal-ui");
2023-08-15 11:53:44 +02:00
$manifest->splash_pages = null;
$manifest->icons = array();
$manifest->start_url = constant('DOL_MAIN_URL_ROOT');
$manifest->id = constant('DOL_MAIN_URL_ROOT');
2023-11-27 12:08:48 +01:00
if (getDolGlobalString('MAIN_MANIFEST_APPLI_LOGO_URL')) {
2023-08-15 11:53:44 +02:00
$icon = new stdClass();
2023-12-26 12:31:46 +01:00
$icon->src = getDolGlobalString('MAIN_MANIFEST_APPLI_LOGO_URL');
if (getDolGlobalString('MAIN_MANIFEST_APPLI_LOGO_URL_SIZE')) {
2023-10-15 18:41:39 +02:00
$icon->sizes = getDolGlobalString('MAIN_MANIFEST_APPLI_LOGO_URL_SIZE') . "x" . getDolGlobalString('MAIN_MANIFEST_APPLI_LOGO_URL_SIZE');
2023-08-15 11:53:44 +02:00
} else {
$icon->sizes = "512x512";
}
$icon->type = "image/png";
$manifest->icons[] = $icon;
2023-11-27 12:08:48 +01:00
} elseif (getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED')) {
if (getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI')) {
2023-10-15 18:41:39 +02:00
$iconRelativePath = 'logos/thumbs/' . getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI');
2023-08-15 11:53:44 +02:00
$iconPath = $conf->mycompany->dir_output.'/'.$iconRelativePath;
if (is_readable($iconPath)) {
$imgSize = getimagesize($iconPath);
if (!empty($imgSize)) {
$icon = new stdClass();
$icon->src = DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode($iconRelativePath);
$icon->sizes = $imgSize[0]."x".$imgSize[1];
$icon->type = "image/png";
$manifest->icons[] = $icon;
}
}
}
2023-11-27 12:08:48 +01:00
if (getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL')) {
2023-10-15 18:41:39 +02:00
$iconRelativePath = 'logos/thumbs/' . getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED_SMALL');
2023-08-15 11:53:44 +02:00
$iconPath = $conf->mycompany->dir_output.'/'.$iconRelativePath;
if (is_readable($iconPath)) {
$imgSize = getimagesize($iconPath);
if ($imgSize) {
$icon = new stdClass();
$icon->src = DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode($iconRelativePath);
$icon->sizes = $imgSize[0]."x".$imgSize[1];
$icon->type = "image/png";
$manifest->icons[] = $icon;
}
}
}
2023-11-27 12:08:48 +01:00
if (getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED')) {
2023-10-15 18:41:39 +02:00
$iconRelativePath = 'logos/' . getDolGlobalString('MAIN_INFO_SOCIETE_LOGO_SQUARRED');
2023-08-15 11:53:44 +02:00
$iconPath = $conf->mycompany->dir_output.'/'.$iconRelativePath;
if (is_readable($iconPath)) {
$imgSize = getimagesize($iconPath);
if ($imgSize) {
$icon = new stdClass();
$icon->src = DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode($iconRelativePath);
$icon->sizes = $imgSize[0]."x".$imgSize[1];
$icon->type = "image/png";
$manifest->icons[] = $icon;
}
2021-02-26 13:31:09 +01:00
}
2023-08-15 11:53:44 +02:00
}
}
// Add Dolibarr std icon
if (empty($manifest->icons)) {
$icon = new stdClass();
$icon->src = DOL_URL_ROOT.'/theme/dolibarr_256x256_color.png';
$icon->sizes = "256x256";
$icon->type = "image/png";
$manifest->icons[] = $icon;
}
print json_encode($manifest);