1ade503dfSGreg Roach<?php 2ade503dfSGreg Roach/** 3ade503dfSGreg Roach * webtrees: online genealogy 4ade503dfSGreg Roach * Copyright (C) 2019 webtrees development team 5ade503dfSGreg Roach * This program is free software: you can redistribute it and/or modify 6ade503dfSGreg Roach * it under the terms of the GNU General Public License as published by 7ade503dfSGreg Roach * the Free Software Foundation, either version 3 of the License, or 8ade503dfSGreg Roach * (at your option) any later version. 9ade503dfSGreg Roach * This program is distributed in the hope that it will be useful, 10ade503dfSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11ade503dfSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12ade503dfSGreg Roach * GNU General Public License for more details. 13ade503dfSGreg Roach * You should have received a copy of the GNU General Public License 14ade503dfSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15ade503dfSGreg Roach */ 16ade503dfSGreg Roachdeclare(strict_types=1); 17ade503dfSGreg Roach 18ade503dfSGreg Roachnamespace Fisharebest\Webtrees\Module; 19ade503dfSGreg Roach 20ade503dfSGreg Roachuse Fisharebest\Webtrees\Auth; 21ade503dfSGreg Roachuse Fisharebest\Webtrees\I18N; 22ade503dfSGreg Roachuse Fisharebest\Webtrees\Menu; 23ade503dfSGreg Roachuse Fisharebest\Webtrees\Session; 24ade503dfSGreg Roachuse Fisharebest\Webtrees\Site; 25ade503dfSGreg Roachuse Fisharebest\Webtrees\Tree; 26*e6bcfa02SGreg Roachuse Symfony\Component\HttpFoundation\Request; 271b40e7bcSGreg Roachuse function uasort; 28ade503dfSGreg Roach 29ade503dfSGreg Roach/** 30ade503dfSGreg Roach * The colors theme. 31ade503dfSGreg Roach */ 32ade503dfSGreg Roachclass ColorsTheme extends CloudsTheme 33ade503dfSGreg Roach{ 34ade503dfSGreg Roach /** 350cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 36ade503dfSGreg Roach * 37ade503dfSGreg Roach * @return string 38ade503dfSGreg Roach */ 39ade503dfSGreg Roach public function title(): string 40ade503dfSGreg Roach { 41ade503dfSGreg Roach /* I18N: Name of a theme. */ 42ade503dfSGreg Roach return I18N::translate('colors'); 43ade503dfSGreg Roach } 44ade503dfSGreg Roach 45ade503dfSGreg Roach /** 46ade503dfSGreg Roach * Generate a list of items for the user menu. 47ade503dfSGreg Roach * 480c8c69d4SGreg Roach * @param Tree|null $tree 490c8c69d4SGreg Roach * 50ade503dfSGreg Roach * @return Menu[] 51ade503dfSGreg Roach */ 520c8c69d4SGreg Roach public function userMenu(?Tree $tree): array 53ade503dfSGreg Roach { 54ade503dfSGreg Roach return array_filter([ 550c8c69d4SGreg Roach $this->menuPendingChanges($tree), 560c8c69d4SGreg Roach $this->menuMyPages($tree), 57ade503dfSGreg Roach $this->menuThemes(), 58ade503dfSGreg Roach $this->menuPalette(), 59ade503dfSGreg Roach $this->menuLanguages(), 60ade503dfSGreg Roach $this->menuLogin(), 61ade503dfSGreg Roach $this->menuLogout(), 62ade503dfSGreg Roach ]); 63ade503dfSGreg Roach } 64ade503dfSGreg Roach 65ade503dfSGreg Roach /** 66ade503dfSGreg Roach * Create a menu of palette options 67ade503dfSGreg Roach * 6877a20107SGreg Roach * @return Menu 69ade503dfSGreg Roach */ 7077a20107SGreg Roach public function menuPalette(): Menu 71ade503dfSGreg Roach { 72*e6bcfa02SGreg Roach $request = app(Request::class); 73*e6bcfa02SGreg Roach 74ade503dfSGreg Roach /* I18N: A colour scheme */ 75ade503dfSGreg Roach $menu = new Menu(I18N::translate('Palette'), '#', 'menu-color'); 76ade503dfSGreg Roach 771b40e7bcSGreg Roach foreach ($this->palettes() as $palette_id => $palette_name) { 78*e6bcfa02SGreg Roach $url = $request->getRequestUri(); 79ade503dfSGreg Roach $url = preg_replace('/&themecolor=[a-z]+/', '', $url); 80ade503dfSGreg Roach $url .= '&themecolor=' . $palette_id; 81ade503dfSGreg Roach 82ade503dfSGreg Roach $menu->addSubmenu(new Menu( 83ade503dfSGreg Roach $palette_name, 84ade503dfSGreg Roach '#', 851b40e7bcSGreg Roach 'menu-color-' . $palette_id . ($this->palette() === $palette_id ? ' active' : ''), 86ade503dfSGreg Roach [ 87ade503dfSGreg Roach 'onclick' => 'document.location=\'' . $url . '\'', 88ade503dfSGreg Roach ] 89ade503dfSGreg Roach )); 90ade503dfSGreg Roach } 91ade503dfSGreg Roach 92ade503dfSGreg Roach return $menu; 93ade503dfSGreg Roach } 94ade503dfSGreg Roach 95ade503dfSGreg Roach /** 96ade503dfSGreg Roach * A list of CSS files to include for this page. 97ade503dfSGreg Roach * 98ade503dfSGreg Roach * @return string[] 99ade503dfSGreg Roach */ 100ade503dfSGreg Roach public function stylesheets(): array 101ade503dfSGreg Roach { 102ade503dfSGreg Roach return [ 103e837ff07SGreg Roach asset('css/colors.min.css'), 1041b40e7bcSGreg Roach asset('css/colors/' . $this->palette() . '.min.css'), 105ade503dfSGreg Roach ]; 106ade503dfSGreg Roach } 1071b40e7bcSGreg Roach 1081b40e7bcSGreg Roach /** 1091b40e7bcSGreg Roach * @return string 1101b40e7bcSGreg Roach */ 111f6f7bcffSGreg Roach private function palette(): string 112f6f7bcffSGreg Roach { 1131b40e7bcSGreg Roach $palettes = $this->palettes(); 1141b40e7bcSGreg Roach 1151b40e7bcSGreg Roach // If we've selected a new palette, and we are logged in, set this value as a default. 1161b40e7bcSGreg Roach if (isset($_GET['themecolor'])) { 1171b40e7bcSGreg Roach // Request to change color 1181b40e7bcSGreg Roach $palette = $_GET['themecolor']; 1191b40e7bcSGreg Roach Auth::user()->setPreference('themecolor', $palette); 1201b40e7bcSGreg Roach if (Auth::isAdmin()) { 1211b40e7bcSGreg Roach Site::setPreference('DEFAULT_COLOR_PALETTE', $palette); 1221b40e7bcSGreg Roach } 1231b40e7bcSGreg Roach unset($_GET['themecolor']); 1241b40e7bcSGreg Roach // Rember that we have selected a value 1251b40e7bcSGreg Roach Session::put('subColor', $palette); 1261b40e7bcSGreg Roach } 1271b40e7bcSGreg Roach 1281b40e7bcSGreg Roach // If we are logged in, use our preference 1291b40e7bcSGreg Roach $palette = Auth::user()->getPreference('themecolor'); 1301b40e7bcSGreg Roach 1311b40e7bcSGreg Roach // If not logged in or no preference, use one we selected earlier in the session? 1321b40e7bcSGreg Roach if (!$palette) { 1331b40e7bcSGreg Roach $palette = Session::get('subColor'); 1341b40e7bcSGreg Roach } 1351b40e7bcSGreg Roach 1361b40e7bcSGreg Roach // We haven't selected one this session? Use the site default 1371b40e7bcSGreg Roach if (!$palette) { 1381b40e7bcSGreg Roach $palette = Site::getPreference('DEFAULT_COLOR_PALETTE'); 1391b40e7bcSGreg Roach } 1401b40e7bcSGreg Roach 1411b40e7bcSGreg Roach // Make sure our selected palette actually exists 1421b40e7bcSGreg Roach if (!array_key_exists($palette, $palettes)) { 1431b40e7bcSGreg Roach $palette = 'ash'; 1441b40e7bcSGreg Roach } 1451b40e7bcSGreg Roach 1461b40e7bcSGreg Roach return $palette; 1471b40e7bcSGreg Roach } 1481b40e7bcSGreg Roach 1491b40e7bcSGreg Roach /** 1501b40e7bcSGreg Roach * @return string[] 1511b40e7bcSGreg Roach */ 152f6f7bcffSGreg Roach private function palettes(): array 153f6f7bcffSGreg Roach { 1541b40e7bcSGreg Roach $palettes = [ 1551b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1561b40e7bcSGreg Roach 'aquamarine' => I18N::translate('Aqua Marine'), 1571b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1581b40e7bcSGreg Roach 'ash' => I18N::translate('Ash'), 1591b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1601b40e7bcSGreg Roach 'belgianchocolate' => I18N::translate('Belgian Chocolate'), 1611b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1621b40e7bcSGreg Roach 'bluelagoon' => I18N::translate('Blue Lagoon'), 1631b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1641b40e7bcSGreg Roach 'bluemarine' => I18N::translate('Blue Marine'), 1651b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1661b40e7bcSGreg Roach 'coffeeandcream' => I18N::translate('Coffee and Cream'), 1671b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1681b40e7bcSGreg Roach 'coldday' => I18N::translate('Cold Day'), 1691b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1701b40e7bcSGreg Roach 'greenbeam' => I18N::translate('Green Beam'), 1711b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1721b40e7bcSGreg Roach 'mediterranio' => I18N::translate('Mediterranio'), 1731b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1741b40e7bcSGreg Roach 'mercury' => I18N::translate('Mercury'), 1751b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1761b40e7bcSGreg Roach 'nocturnal' => I18N::translate('Nocturnal'), 1771b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1781b40e7bcSGreg Roach 'olivia' => I18N::translate('Olivia'), 1791b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1801b40e7bcSGreg Roach 'pinkplastic' => I18N::translate('Pink Plastic'), 1811b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1821b40e7bcSGreg Roach 'sage' => I18N::translate('Sage'), 1831b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1841b40e7bcSGreg Roach 'shinytomato' => I18N::translate('Shiny Tomato'), 1851b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 1861b40e7bcSGreg Roach 'tealtop' => I18N::translate('Teal Top'), 1871b40e7bcSGreg Roach ]; 1881b40e7bcSGreg Roach 1891b40e7bcSGreg Roach uasort($palettes, '\Fisharebest\Webtrees\I18N::strcasecmp'); 1901b40e7bcSGreg Roach 1911b40e7bcSGreg Roach return $palettes; 1921b40e7bcSGreg Roach } 193ade503dfSGreg Roach} 194