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; 26ade503dfSGreg Roachuse Symfony\Component\HttpFoundation\Request; 27*1b40e7bcSGreg Roachuse function uasort; 28ade503dfSGreg Roach 29ade503dfSGreg Roach/** 30ade503dfSGreg Roach * The colors theme. 31ade503dfSGreg Roach */ 32ade503dfSGreg Roachclass ColorsTheme extends CloudsTheme 33ade503dfSGreg Roach{ 34ade503dfSGreg Roach protected const PERSON_BOX_CLASSES = [ 35ade503dfSGreg Roach 'M' => 'person_box', 36ade503dfSGreg Roach 'F' => 'person_boxF', 37ade503dfSGreg Roach 'U' => 'person_boxNN', 38ade503dfSGreg Roach ]; 39ade503dfSGreg Roach 40ade503dfSGreg Roach /** 41ade503dfSGreg Roach * How should this module be labelled on tabs, menus, etc.? 42ade503dfSGreg Roach * 43ade503dfSGreg Roach * @return string 44ade503dfSGreg Roach */ 45ade503dfSGreg Roach public function title(): string 46ade503dfSGreg Roach { 47ade503dfSGreg Roach /* I18N: Name of a theme. */ 48ade503dfSGreg Roach return I18N::translate('colors'); 49ade503dfSGreg Roach } 50ade503dfSGreg Roach 51ade503dfSGreg Roach /** 52ade503dfSGreg Roach * Generate a list of items for the user menu. 53ade503dfSGreg Roach * 54ade503dfSGreg Roach * @return Menu[] 55ade503dfSGreg Roach */ 56ade503dfSGreg Roach public function secondaryMenu(): array 57ade503dfSGreg Roach { 58ade503dfSGreg Roach return array_filter([ 59ade503dfSGreg Roach $this->menuPendingChanges(), 60ade503dfSGreg Roach $this->menuMyPages(), 61ade503dfSGreg Roach $this->menuThemes(), 62ade503dfSGreg Roach $this->menuPalette(), 63ade503dfSGreg Roach $this->menuLanguages(), 64ade503dfSGreg Roach $this->menuLogin(), 65ade503dfSGreg Roach $this->menuLogout(), 66ade503dfSGreg Roach ]); 67ade503dfSGreg Roach } 68ade503dfSGreg Roach 69ade503dfSGreg Roach /** 70ade503dfSGreg Roach * Create a menu of palette options 71ade503dfSGreg Roach * 7277a20107SGreg Roach * @return Menu 73ade503dfSGreg Roach */ 7477a20107SGreg Roach public function menuPalette(): Menu 75ade503dfSGreg Roach { 76ade503dfSGreg Roach /* I18N: A colour scheme */ 77ade503dfSGreg Roach $menu = new Menu(I18N::translate('Palette'), '#', 'menu-color'); 78ade503dfSGreg Roach 79*1b40e7bcSGreg Roach foreach ($this->palettes() as $palette_id => $palette_name) { 80ade503dfSGreg Roach $url = $this->request->getRequestUri(); 81ade503dfSGreg Roach $url = preg_replace('/&themecolor=[a-z]+/', '', $url); 82ade503dfSGreg Roach $url .= '&themecolor=' . $palette_id; 83ade503dfSGreg Roach 84ade503dfSGreg Roach $menu->addSubmenu(new Menu( 85ade503dfSGreg Roach $palette_name, 86ade503dfSGreg Roach '#', 87*1b40e7bcSGreg Roach 'menu-color-' . $palette_id . ($this->palette() === $palette_id ? ' active' : ''), 88ade503dfSGreg Roach [ 89ade503dfSGreg Roach 'onclick' => 'document.location=\'' . $url . '\'', 90ade503dfSGreg Roach ] 91ade503dfSGreg Roach )); 92ade503dfSGreg Roach } 93ade503dfSGreg Roach 94ade503dfSGreg Roach return $menu; 95ade503dfSGreg Roach } 96ade503dfSGreg Roach 97ade503dfSGreg Roach /** 98ade503dfSGreg Roach * A list of CSS files to include for this page. 99ade503dfSGreg Roach * 100ade503dfSGreg Roach * @return string[] 101ade503dfSGreg Roach */ 102ade503dfSGreg Roach public function stylesheets(): array 103ade503dfSGreg Roach { 104ade503dfSGreg Roach return [ 105e837ff07SGreg Roach asset('css/colors.min.css'), 106*1b40e7bcSGreg Roach asset('css/colors/' . $this->palette() . '.min.css'), 107ade503dfSGreg Roach ]; 108ade503dfSGreg Roach } 109*1b40e7bcSGreg Roach 110*1b40e7bcSGreg Roach /** 111*1b40e7bcSGreg Roach * @return string 112*1b40e7bcSGreg Roach */ 113*1b40e7bcSGreg Roach private function palette(): string { 114*1b40e7bcSGreg Roach $palettes = $this->palettes(); 115*1b40e7bcSGreg Roach 116*1b40e7bcSGreg Roach // If we've selected a new palette, and we are logged in, set this value as a default. 117*1b40e7bcSGreg Roach if (isset($_GET['themecolor'])) { 118*1b40e7bcSGreg Roach // Request to change color 119*1b40e7bcSGreg Roach $palette = $_GET['themecolor']; 120*1b40e7bcSGreg Roach Auth::user()->setPreference('themecolor', $palette); 121*1b40e7bcSGreg Roach if (Auth::isAdmin()) { 122*1b40e7bcSGreg Roach Site::setPreference('DEFAULT_COLOR_PALETTE', $palette); 123*1b40e7bcSGreg Roach } 124*1b40e7bcSGreg Roach unset($_GET['themecolor']); 125*1b40e7bcSGreg Roach // Rember that we have selected a value 126*1b40e7bcSGreg Roach Session::put('subColor', $palette); 127*1b40e7bcSGreg Roach } 128*1b40e7bcSGreg Roach 129*1b40e7bcSGreg Roach // If we are logged in, use our preference 130*1b40e7bcSGreg Roach $palette = Auth::user()->getPreference('themecolor'); 131*1b40e7bcSGreg Roach 132*1b40e7bcSGreg Roach // If not logged in or no preference, use one we selected earlier in the session? 133*1b40e7bcSGreg Roach if (!$palette) { 134*1b40e7bcSGreg Roach $palette = Session::get('subColor'); 135*1b40e7bcSGreg Roach } 136*1b40e7bcSGreg Roach 137*1b40e7bcSGreg Roach // We haven't selected one this session? Use the site default 138*1b40e7bcSGreg Roach if (!$palette) { 139*1b40e7bcSGreg Roach $palette = Site::getPreference('DEFAULT_COLOR_PALETTE'); 140*1b40e7bcSGreg Roach } 141*1b40e7bcSGreg Roach 142*1b40e7bcSGreg Roach // Make sure our selected palette actually exists 143*1b40e7bcSGreg Roach if (!array_key_exists($palette, $palettes)) { 144*1b40e7bcSGreg Roach $palette = 'ash'; 145*1b40e7bcSGreg Roach } 146*1b40e7bcSGreg Roach 147*1b40e7bcSGreg Roach return $palette; 148*1b40e7bcSGreg Roach } 149*1b40e7bcSGreg Roach 150*1b40e7bcSGreg Roach /** 151*1b40e7bcSGreg Roach * @return string[] 152*1b40e7bcSGreg Roach */ 153*1b40e7bcSGreg Roach private function palettes(): array { 154*1b40e7bcSGreg Roach $palettes = [ 155*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 156*1b40e7bcSGreg Roach 'aquamarine' => I18N::translate('Aqua Marine'), 157*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 158*1b40e7bcSGreg Roach 'ash' => I18N::translate('Ash'), 159*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 160*1b40e7bcSGreg Roach 'belgianchocolate' => I18N::translate('Belgian Chocolate'), 161*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 162*1b40e7bcSGreg Roach 'bluelagoon' => I18N::translate('Blue Lagoon'), 163*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 164*1b40e7bcSGreg Roach 'bluemarine' => I18N::translate('Blue Marine'), 165*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 166*1b40e7bcSGreg Roach 'coffeeandcream' => I18N::translate('Coffee and Cream'), 167*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 168*1b40e7bcSGreg Roach 'coldday' => I18N::translate('Cold Day'), 169*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 170*1b40e7bcSGreg Roach 'greenbeam' => I18N::translate('Green Beam'), 171*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 172*1b40e7bcSGreg Roach 'mediterranio' => I18N::translate('Mediterranio'), 173*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 174*1b40e7bcSGreg Roach 'mercury' => I18N::translate('Mercury'), 175*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 176*1b40e7bcSGreg Roach 'nocturnal' => I18N::translate('Nocturnal'), 177*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 178*1b40e7bcSGreg Roach 'olivia' => I18N::translate('Olivia'), 179*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 180*1b40e7bcSGreg Roach 'pinkplastic' => I18N::translate('Pink Plastic'), 181*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 182*1b40e7bcSGreg Roach 'sage' => I18N::translate('Sage'), 183*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 184*1b40e7bcSGreg Roach 'shinytomato' => I18N::translate('Shiny Tomato'), 185*1b40e7bcSGreg Roach /* I18N: The name of a colour-scheme */ 186*1b40e7bcSGreg Roach 'tealtop' => I18N::translate('Teal Top'), 187*1b40e7bcSGreg Roach ]; 188*1b40e7bcSGreg Roach 189*1b40e7bcSGreg Roach uasort($palettes, '\Fisharebest\Webtrees\I18N::strcasecmp'); 190*1b40e7bcSGreg Roach 191*1b40e7bcSGreg Roach return $palettes; 192*1b40e7bcSGreg Roach } 193ade503dfSGreg Roach} 194