dolibarr 24.0.0-beta
webPortalTheme.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2023-2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2023-2024 Lionel Vessiller <lvessiller@easya.solutions>
4 * Copyright (C) 2023-2024 John Botella <john.botella@atm-consulting.fr>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025 Charlene Benke <charlene@patas-monkey.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22
29require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php'; // used for color functions
30require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
31require_once DOL_DOCUMENT_ROOT . '/webportal/class/context.class.php';
32
33
38{
42 public $primaryColorHex = '#263c5c';
43
47 public $primaryColorHsl = array(
48 'h' => 216, // Hue
49 'l' => 42, // lightness
50 's' => 25, // Saturation
51 'a' => 1 // Alfa
52 );
53
57 public $loginLogoUrl;
58
62 public $menuLogoUrl;
63
67 public $loginBackground;
68
72 public $bannerBackground;
73
77 public $bannerUseDarkTheme;
78
79
84 public function __construct($init = true)
85 {
86 if ($init) {
87 $this->init();
88 }
89 }
90
96 public function init()
97 {
98 global $db, $conf;
99
100 $mysoc = new Societe($db);
101 $mysoc->setMysoc($conf);
102
103 $this->loadPrimaryColor();
104
106
107 $urllogo = Context::getRootConfigUrl() . 'img/login_logo.svg';
108 if ($context->userIsLog()) {
109 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_small)) {
110 $urllogo = $context->getControllerUrl('viewimage') . '&modulepart=mycompany&entity=' . $conf->entity . '&file=' . urlencode('logos/thumbs/' . $mysoc->logo_small);
111 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output . '/logos/' . $mysoc->logo)) {
112 $urllogo = $context->getControllerUrl('viewimage') . '&modulepart=mycompany&entity=' . $conf->entity . '&file=' . urlencode('logos/' . $mysoc->logo);
113 } elseif (is_readable(DOL_DOCUMENT_ROOT . '/public/webportal/img/dolibarr_logo.svg')) {
114 $urllogo = Context::getRootConfigUrl() . 'img/dolibarr_logo.svg';
115 }
116 }
117
118 $this->loginLogoUrl = getDolGlobalString('WEBPORTAL_LOGIN_LOGO_URL', $urllogo);
119 $this->menuLogoUrl = getDolGlobalString('WEBPORTAL_MENU_LOGO_URL', $this->loginLogoUrl);
120 $this->loginBackground = getDolGlobalString('WEBPORTAL_LOGIN_BACKGROUND');
121 $this->bannerBackground = getDolGlobalString('WEBPORTAL_BANNER_BACKGROUND');
122 $this->bannerUseDarkTheme = getDolGlobalInt('WEBPORTAL_BANNER_BACKGROUND_IS_DARK');
123 }
124
130 public function loadPrimaryColor()
131 {
132 $outColor = '';
133
134 if (getDolGlobalString('WEBPORTAL_PRIMARY_COLOR')) {
135 $outColor = getDolGlobalString('WEBPORTAL_PRIMARY_COLOR');
136 } elseif (getDolGlobalString('THEME_ELDY_TOPMENU_BACK1')) {
137 $outColor = colorArrayToHex(colorStringToArray(getDolGlobalString('THEME_ELDY_TOPMENU_BACK1')));
138 }
139 if (strpos($outColor, '#') !== 0) {
140 $outColor = '#'.$outColor;
141 }
142
143 // If custom color is valid, w e use it
144 if (!empty($outColor) && colorValidateHex($outColor)) {
145 $this->primaryColorHex = $outColor;
146 $this->primaryColorHsl = colorHexToHsl($outColor, 1, true);
147 }
148 }
149
155 static public function getIconImagesUrl()
156 {
157 // TODO : add hook Or const override
158 return Context::getInstance()->getControllerUrl().'/img/icons/';
159 }
160
166 static public function getIconImagesPath()
167 {
168 // TODO : add hook Or const override
169 return DOL_DOCUMENT_ROOT . '/public/webportal/img/icons';
170 }
171}
static getInstance()
Singleton method to create one instance of this object.
static getRootConfigUrl()
Get WebPortal root url.
Class to manage third parties objects (customers, suppliers, prospects...)
Class WebPortalTheme.
static getIconImagesPath()
return current icons folder path
__construct($init=true)
Constructor.
loadPrimaryColor()
Load hex of primary theme color.
static getIconImagesUrl()
return current icons folder url
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
colorArrayToHex($arraycolor, $colorifnotfound='888888')
Convert an array with RGB value into hex RGB value.
colorStringToArray($stringcolor, $colorifnotfound=array(88, 88, 88))
Convert a string RGB value ('FFFFFF', '255,255,255') into an array RGB array(255,255,...
colorHexToHsl($hex, $alpha=false, $returnArray=false)
Color Hex to Hsl (used for style)
colorValidateHex($color, $allow_white=true)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition logout.php:42